/*
 * News web app (igno2k/mcp-server#208, ADR-001 decision 2): one token-driven
 * stylesheet per standards/UI_PATTERNS.md. Components read var(--…) only.
 * Dark is the baseline; light is a drop-in, chosen by prefers-color-scheme
 * unless the page sets data-theme (manual toggle, js/theme.js).
 * Desktop: three panes (sections, list, reader). Phone (< 900px): one column,
 * the reader slides over the list, a bottom tab bar, safe-area aware.
 */

:root {
    --bg: #111318;
    --panel: #181b21;
    --panel2: #20242c;
    --line: #2b303a;
    --txt: #ece8e1;
    --muted: #a39e95;
    --accent: #ef6a45;
    --accent-soft: rgba(239, 106, 69, 0.16);
    --on-accent: #111318;
    --focus: #ffb38f;
    --ok: #3fb950;
    --warn: #d29922;
    --err: #f85149;
    --info: #5cc8ff;
    --ok-rgb: 63, 185, 80;
    --warn-rgb: 210, 153, 34;
    --err-rgb: 248, 81, 73;
    --info-rgb: 92, 200, 255;
    --bar-bg: rgba(24, 27, 33, 0.9);
    --scrim: rgba(0, 0, 0, 0.5);
    --shadow: 0 10px 28px rgba(0, 0, 0, 0.45);
    --radius: 14px;
    --radius-sm: 8px;
    --side-w: 232px;
    --list-w: 400px;
    --tabbar-h: 56px;
    --font: -apple-system, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --serif: "Iowan Old Style", "Charter", "Georgia", "Times New Roman", serif;
    color-scheme: dark;
}

@media (prefers-color-scheme: light) {
    :root:not([data-theme="dark"]) {
        --bg: #f7f4ee;
        --panel: #fffdf8;
        --panel2: #efebe3;
        --line: #ddd6ca;
        --txt: #1d1b18;
        --muted: #5f5a52;
        --accent: #b13d1c;
        --accent-soft: rgba(177, 61, 28, 0.12);
        --on-accent: #ffffff;
        --focus: #b13d1c;
        --ok: #1a7f37;
        --warn: #8a5c00;
        --err: #cf222e;
        --info: #0969da;
        --ok-rgb: 26, 127, 55;
        --warn-rgb: 138, 92, 0;
        --err-rgb: 207, 34, 46;
        --info-rgb: 9, 105, 218;
        --bar-bg: rgba(255, 253, 248, 0.9);
        --scrim: rgba(0, 0, 0, 0.3);
        --shadow: 0 8px 24px rgba(40, 30, 10, 0.14);
        color-scheme: light;
    }
}

:root[data-theme="light"] {
    --bg: #f7f4ee;
    --panel: #fffdf8;
    --panel2: #efebe3;
    --line: #ddd6ca;
    --txt: #1d1b18;
    --muted: #5f5a52;
    --accent: #b13d1c;
    --accent-soft: rgba(177, 61, 28, 0.12);
    --on-accent: #ffffff;
    --focus: #b13d1c;
    --ok: #1a7f37;
    --warn: #8a5c00;
    --err: #cf222e;
    --info: #0969da;
    --ok-rgb: 26, 127, 55;
    --warn-rgb: 138, 92, 0;
    --err-rgb: 207, 34, 46;
    --info-rgb: 9, 105, 218;
    --bar-bg: rgba(255, 253, 248, 0.9);
    --scrim: rgba(0, 0, 0, 0.3);
    --shadow: 0 8px 24px rgba(40, 30, 10, 0.14);
    color-scheme: light;
}

/* ─── Base ─── */

*,
*::before,
*::after {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--txt);
    font: 16px/1.5 var(--font);
    -webkit-tap-highlight-color: transparent;
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

a {
    color: var(--accent);
}

h1,
h2,
h3 {
    margin: 0;
}

:focus-visible {
    outline: 2px solid var(--focus);
    outline-offset: 2px;
    border-radius: 4px;
}

.skip-link {
    position: absolute;
    left: 8px;
    top: -60px;
    z-index: 20;
    padding: 10px 14px;
    background: var(--panel);
    color: var(--txt);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.skip-link:focus {
    top: calc(env(safe-area-inset-top) + 8px);
}

.icon {
    width: 22px;
    height: 22px;
    flex: none;
}

.muted {
    color: var(--muted);
}

/* ─── Controls ─── */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line);
    background: var(--panel2);
    color: var(--txt);
    font: inherit;
    font-size: 15px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.1s ease, opacity 0.1s ease;
}

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
}

.btn.ghost {
    background: transparent;
    border-color: transparent;
    color: var(--muted);
}

.btn.sm {
    padding: 0 12px;
    font-size: 14px;
}

.btn.block {
    width: 100%;
    justify-content: center;
}

.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: var(--accent);
    cursor: pointer;
    transition: transform 0.1s ease, opacity 0.1s ease;
}

.btn:active,
.icon-btn:active,
.row-link:active,
.source-link:active,
.tabbar a:active {
    transform: scale(0.98);
    opacity: 0.8;
}

.pill {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    border: 1px solid;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    vertical-align: middle;
}

.pill-warn {
    color: var(--warn);
    background: rgba(var(--warn-rgb), 0.1);
    border-color: rgba(var(--warn-rgb), 0.45);
}

.notice {
    margin: 12px 16px;
    padding: 10px 14px;
    border: 1px solid rgba(var(--info-rgb), 0.45);
    border-radius: var(--radius-sm);
    background: rgba(var(--info-rgb), 0.1);
    font-size: 14px;
    overflow-wrap: anywhere;
}

.notice-warn {
    border-color: rgba(var(--warn-rgb), 0.45);
    background: rgba(var(--warn-rgb), 0.1);
}

.notice-err {
    border-color: rgba(var(--err-rgb), 0.45);
    background: rgba(var(--err-rgb), 0.1);
}

.reader .notice {
    margin: 16px 0;
}

/* ─── App shell: desktop, three panes ─── */

body.app {
    display: grid;
    grid-template-columns: var(--side-w) var(--list-w) minmax(0, 1fr);
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

.sidebar {
    display: flex;
    flex-direction: column;
    min-width: 0;
    overflow-y: auto;
    padding: max(16px, env(safe-area-inset-top)) 12px 16px max(12px, env(safe-area-inset-left));
    background: var(--panel);
    border-right: 1px solid var(--line);
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 4px 10px 16px;
    color: var(--txt);
    font-size: 21px;
    font-weight: 800;
    letter-spacing: -0.01em;
    text-decoration: none;
}

.brand .icon {
    width: 28px;
    height: 28px;
    color: var(--accent);
}

.nav,
.editions {
    margin: 0;
    padding: 0;
    list-style: none;
}

.nav a,
.editions a {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 44px;
    padding: 0 10px;
    border-radius: var(--radius-sm);
    color: var(--muted);
    font-weight: 600;
    text-decoration: none;
}

.editions a {
    min-height: 36px;
    font-size: 14px;
    font-weight: 500;
}

.nav a:hover,
.editions a:hover {
    background: var(--panel2);
}

.nav a[aria-current="page"],
.editions a[aria-current="page"] {
    color: var(--txt);
    background: var(--accent-soft);
}

.nav a[aria-current="page"] .icon {
    color: var(--accent);
}

.nav-head {
    margin: 20px 10px 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.sidebar-foot {
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin-top: auto;
    padding-top: 12px;
    border-top: 1px solid var(--line);
}

.sidebar-foot .btn {
    width: 100%;
    justify-content: flex-start;
    padding: 0 10px;
}

.logout-form {
    margin: 0;
}

.pane {
    min-width: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    background: var(--bg);
}

.pane:focus {
    outline: none;
}

.pane-list {
    border-right: 1px solid var(--line);
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 8px;
    padding: 16px 16px 10px;
    background: var(--bar-bg);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
}

.large-title {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.15;
}

.topbar-actions {
    display: none;
}

.tabbar {
    display: none;
}

/* ─── List pane ─── */

.list {
    padding-bottom: 32px;
}

.list-head {
    padding: 16px 16px 4px;
}

.kicker {
    margin: 0 0 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.headline {
    font-family: var(--serif);
    font-size: 23px;
    font-weight: 700;
    line-height: 1.25;
    overflow-wrap: anywhere;
}

.summary {
    margin: 10px 0 0;
    font-size: 15px;
    overflow-wrap: anywhere;
}

.group {
    padding: 22px 16px 6px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    border-bottom: 1px solid var(--line);
}

.group-count {
    margin-left: 4px;
    font-weight: 600;
}

.rows {
    margin: 0;
    padding: 0;
    list-style: none;
}

.row {
    position: relative;
    border-bottom: 1px solid var(--line);
}

.row-link {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    min-height: 44px;
    padding: 12px 16px 12px 30px;
    color: inherit;
    text-decoration: none;
    transition: background-color 0.15s ease;
}

.row-link:hover {
    background: var(--panel2);
}

.row-link:focus-visible {
    outline-offset: -2px;
}

.row.is-selected > .row-link {
    background: var(--accent-soft);
}

.row-dot {
    position: absolute;
    top: 19px;
    left: 13px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.row.is-opened .row-dot {
    visibility: hidden;
}

.row-body {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 3px;
    min-width: 0;
}

.row-meta {
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.row-title {
    font-size: 16px;
    font-weight: 650;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.row.is-opened .row-title {
    color: var(--muted);
    font-weight: 500;
}

.row-excerpt {
    display: -webkit-box;
    overflow: hidden;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.4;
    overflow-wrap: anywhere;
    -webkit-line-clamp: 3;
    line-clamp: 3;
    -webkit-box-orient: vertical;
}

.row-feeds {
    overflow: hidden;
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.rows-compact .row-link {
    padding-top: 10px;
    padding-bottom: 10px;
}

.rows-compact .row-dot {
    top: 17px;
}

.thumb {
    display: block;
    flex: none;
    width: 72px;
    height: 72px;
    overflow: hidden;
    border-radius: var(--radius-sm);
    background: var(--panel2);
}

.thumb img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.row-earlier {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    margin: -14px 0 0 30px;
    font-size: 13px;
    font-weight: 600;
}

.open-items {
    margin: 0;
    padding: 10px 16px 0 36px;
    font-size: 15px;
}

.open-items li {
    margin-bottom: 8px;
    overflow-wrap: anywhere;
}

.list-foot {
    margin: 0;
    padding: 16px;
    color: var(--muted);
    font-size: 14px;
}

.list-foot a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    font-weight: 600;
}

.empty {
    margin: 0;
    padding: 32px 16px;
    color: var(--muted);
    text-align: center;
}

/* ─── Reader pane ─── */

.reader-bar {
    position: sticky;
    top: 0;
    z-index: 3;
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: 52px;
    padding: 4px 12px;
    background: var(--bar-bg);
    -webkit-backdrop-filter: blur(16px);
    backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--line);
}

.spacer {
    flex: 1;
}

.back-link {
    display: none;
    align-items: center;
    gap: 2px;
    min-height: 44px;
    padding: 0 8px 0 0;
    font-size: 17px;
    text-decoration: none;
}

.reader-inner {
    max-width: 720px;
    margin: 0 auto;
    padding: 20px 24px 64px;
}

.reader-title {
    margin: 0 0 12px;
    font-family: var(--serif);
    font-size: clamp(25px, 2.4vw + 12px, 36px);
    line-height: 1.18;
    letter-spacing: -0.01em;
    overflow-wrap: anywhere;
}

.earlier-note {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 14px;
}

.hero {
    display: block;
    aspect-ratio: 16 / 9;
    margin: 16px 0 24px;
    overflow: hidden;
    border-radius: var(--radius);
    background: var(--panel2);
}

.hero img {
    display: block;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.detail,
.body {
    font-family: var(--serif);
    font-size: 19px;
    line-height: 1.6;
}

.detail p,
.body p {
    margin: 0 0 1em;
    overflow-wrap: anywhere;
}

.body {
    margin-top: 8px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.detail + .body {
    margin-top: 24px;
}

.body-source {
    color: var(--muted);
    font-family: var(--font);
    font-size: 12px !important;
    font-weight: 700;
    letter-spacing: 0.06em;
    line-height: 1.4;
    text-transform: uppercase;
}

.body-title {
    margin: 0 0 12px;
    font-size: 21px;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.body .muted {
    font-family: var(--font);
    font-size: 14px;
}

.primary-link {
    margin: 24px 0;
}

.primary-link .btn {
    max-width: 100%;
}

.primary-link .btn span {
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.sources h2 {
    margin: 32px 0 4px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.sources ul {
    margin: 0;
    padding: 0;
    list-style: none;
}

.source {
    display: flex;
    align-items: center;
    gap: 8px;
    border-bottom: 1px solid var(--line);
}

.source-link {
    display: flex;
    flex: 1;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
    min-height: 44px;
    padding: 10px 0;
    color: inherit;
    text-decoration: none;
}

.source-title {
    font-weight: 600;
    line-height: 1.3;
    overflow-wrap: anywhere;
}

.source-meta {
    color: var(--muted);
    font-size: 13px;
}

.reader-actions {
    margin: 32px 0 0;
}

.reader-empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 100%;
    min-height: 240px;
    color: var(--muted);
}

.reader-empty .icon {
    width: 48px;
    height: 48px;
    opacity: 0.6;
}

/* ─── Edition picker (phone only: the sidebar holds the editions on the desktop) ─── */

.edition-picker {
    display: none;
    margin-top: 12px;
    font-size: 15px;
}

.edition-picker summary {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    color: var(--accent);
    font-weight: 600;
    cursor: pointer;
}

.edition-picker ul {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 4px 0 0;
    padding: 0;
    list-style: none;
}

.edition-picker a {
    display: inline-flex;
    align-items: center;
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--panel);
    color: var(--txt);
    text-decoration: none;
}

.edition-picker a[aria-current="page"] {
    border-color: var(--accent);
    background: var(--accent-soft);
    font-weight: 700;
}

/* ─── Loading ─── */

.loading-bar {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 8px);
    left: 50%;
    z-index: 12;
    padding: 6px 14px;
    transform: translateX(-50%);
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: 999px;
    box-shadow: var(--shadow);
    color: var(--muted);
    font-size: 14px;
    font-weight: 600;
}

.pane[aria-busy="true"] .pane-body {
    opacity: 0.55;
    transition: opacity 0.2s ease;
}

/* ─── Toast and banner ─── */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: calc(100vw - 32px);
    padding: 6px 6px 6px 16px;
    transform: translateX(-50%);
    background: var(--panel2);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    font-size: 15px;
}

.toast [data-toast-text] {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.toast .btn {
    flex: none;
}

.banner {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 8px);
    right: 12px;
    left: 12px;
    z-index: 11;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    max-width: 640px;
    margin: 0 auto;
    padding: 6px 6px 6px 14px;
    background: var(--panel);
    border: 1px solid rgba(var(--warn-rgb), 0.6);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow);
    font-size: 14px;
}

/* ─── Login and message pages ─── */

body.solo {
    display: grid;
    min-height: 100vh;
    min-height: 100dvh;
    place-items: center;
    padding: max(24px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom))
        max(16px, env(safe-area-inset-left));
}

.solo-card {
    width: 100%;
    max-width: 380px;
    padding: 28px 24px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    text-align: center;
}

.solo-card h1 {
    margin-bottom: 8px;
    font-size: 26px;
    font-weight: 800;
}

.solo-card .notice {
    margin: 12px 0;
    text-align: left;
}

.solo-icon {
    color: var(--accent);
}

.solo-icon .icon {
    width: 56px;
    height: 56px;
}

.login-form {
    margin-top: 8px;
    text-align: left;
}

.login-form label {
    display: block;
    margin: 14px 0 6px;
    font-size: 14px;
    font-weight: 600;
}

.login-form input {
    width: 100%;
    min-height: 44px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--bg);
    color: var(--txt);
    font: inherit;
    font-size: 16px;
}

.login-form .btn {
    margin-top: 22px;
}

/* ─── Mid widths ─── */

@media (max-width: 1199px) and (min-width: 900px) {
    :root {
        --side-w: 196px;
        --list-w: 340px;
    }
}

@media (min-width: 1800px) {
    :root {
        --side-w: 256px;
        --list-w: 460px;
    }

    .reader-inner {
        max-width: 760px;
    }
}

/* ─── Phone: one column, the reader slides over the list ─── */

@media (max-width: 899px) {
    body.app {
        display: block;
        height: auto;
        overflow: visible;
    }

    .sidebar {
        display: none;
    }

    .edition-picker {
        display: block;
    }

    .pane {
        position: fixed;
        inset: 0;
        padding-bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
        padding-left: env(safe-area-inset-left);
        padding-right: env(safe-area-inset-right);
    }

    .pane-list {
        border-right: 0;
        transition: visibility 0s linear 0s;
    }

    .pane-reader {
        z-index: 2;
        visibility: hidden;
        transform: translateX(100%);
        box-shadow: var(--shadow);
        transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0.32s;
    }

    body[data-view="reader"] .pane-reader {
        visibility: visible;
        transform: none;
        transition: transform 0.32s cubic-bezier(0.2, 0.8, 0.2, 1), visibility 0s linear 0s;
    }

    body[data-view="reader"] .pane-list {
        visibility: hidden;
        transition: visibility 0s linear 0.32s;
    }

    .topbar {
        padding: calc(env(safe-area-inset-top) + 10px) 8px 8px 16px;
    }

    .large-title {
        font-size: 32px;
    }

    .topbar-actions {
        display: flex;
        gap: 2px;
    }

    .reader-bar {
        padding: calc(env(safe-area-inset-top) + 4px) 8px 4px;
    }

    .back-link {
        display: inline-flex;
    }

    .reader-inner {
        padding: 16px 16px 48px;
    }

    .detail,
    .body {
        font-size: 18px;
    }

    .tabbar {
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: 5;
        display: flex;
        height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
        padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
        background: var(--panel);
        border-top: 1px solid var(--line);
    }

    .tabbar a {
        display: flex;
        flex: 1;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 2px;
        min-height: 44px;
        color: var(--muted);
        font-size: 11px;
        font-weight: 500;
        text-decoration: none;
    }

    .tabbar a[aria-current="page"] {
        color: var(--accent);
        font-weight: 700;
    }

    .tabbar .icon {
        width: 24px;
        height: 24px;
    }

    .toast {
        bottom: calc(var(--tabbar-h) + env(safe-area-inset-bottom) + 12px);
    }

    .thumb {
        width: 64px;
        height: 64px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        transition-duration: 0s !important;
        transition-delay: 0s !important;
        animation: none !important;
    }
}
