:root {
    --bg: #ffffff; --fg: #1a1a1a; --muted: #666; --line: #e3e3e3; --card: #fafafa;
    --accent: #F26522; --accent-fg: #fff; --err: #b00020;
}
@media (prefers-color-scheme: dark) {
    :root[data-theme="system"] { --bg: #121212; --fg: #eee; --muted: #aaa; --line: #2c2c2c; --card: #1c1c1c; --err: #ff6b6b; color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #121212; --fg: #eee; --muted: #aaa; --line: #2c2c2c; --card: #1c1c1c; --err: #ff6b6b; color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.5 system-ui, -apple-system, sans-serif; }
.topbar {
    position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
    padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: var(--bg); border-bottom: 1px solid var(--line);
}
.topbar .brand-logo { display: block; flex: 0 0 32px; object-fit: contain; }
.topbar h1 { flex: 1; margin: 0; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.icon-btn { background: none; border: 0; color: var(--fg); font-size: 1.4rem; min-width: 44px; min-height: 44px; cursor: pointer; }
main { max-width: 760px; margin: 0 auto; padding: 16px; }
h2.section { margin: 28px 0 4px; font-size: 1.3rem; border-bottom: 2px solid var(--accent); padding-bottom: 4px; }
h3.subsection { margin: 18px 0 4px; font-size: 1rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.muted { color: var(--muted); font-size: .9rem; }
.error { color: var(--err); }
.hero { margin: 0 0 8px; }
.hero h2 { margin: 0; font-size: 1.6rem; }

.card {
    display: block; width: 100%; text-align: left; margin: 10px 0; padding: 12px; font: inherit; color: inherit;
    background: var(--card); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.card:hover, .card:focus-visible { border-color: var(--accent); outline: none; }
/* Fixed height so lazy-loaded images don't change the page height as they load (that made Contents jumps land short). */
.card img.thumb { display: block; width: 100%; height: 180px; object-fit: cover; border-radius: 6px; margin-bottom: 8px; }
.card .title { font-weight: 600; }
.card .meta { color: var(--muted); font-size: .85rem; margin-top: 2px; }
.card .summary { margin-top: 6px; }
.badge { display: inline-block; font-size: .7rem; padding: 1px 6px; border-radius: 9px; background: var(--line); color: var(--muted); margin-left: 6px; text-transform: uppercase; }

form.setup { display: grid; gap: 12px; margin-top: 8px; }
label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }
input, select { font: inherit; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); color: var(--fg); }
.btn { font: inherit; padding: 10px 16px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-fg); cursor: pointer; min-height: 44px; text-decoration: none; display: inline-block; }
.btn.secondary { background: var(--line); color: var(--fg); }
.btn:disabled { opacity: .6; cursor: default; }

.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 9; }
.sheet {
    position: fixed; z-index: 10; background: var(--bg); color: var(--fg); display: flex; flex-direction: column;
    left: 0; right: 0; bottom: 0; max-height: 88vh; border-radius: 16px 16px 0 0; box-shadow: 0 -4px 24px rgba(0,0,0,.3);
    padding-bottom: env(safe-area-inset-bottom);
}
.sheet[hidden], .backdrop[hidden], [hidden] { display: none !important; }
.sheet-head { display: flex; align-items: flex-start; gap: 8px; padding: 12px 8px 4px 16px; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 1.15rem; }
.sheet-body { overflow-y: auto; padding: 0 16px 20px; }
.sheet-body h3 { margin: 18px 0 4px; font-size: .85rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.sheet-body p { margin: 6px 0; }
.sheet-body ul { padding-left: 20px; }
.sheet-body a.link-row { display: block; padding: 10px 0; border-bottom: 1px solid var(--line); color: inherit; text-decoration: none; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; font: inherit; width: 100%; cursor: pointer; }
.actions { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }

.card { cursor: pointer; }
.card .summary-title { font-weight: 600; margin-top: 8px; }
.card .summary { margin-top: 6px; }
.card .story-sources { margin-top: 8px; font-size: .9rem; }
.card .story-sources ul { margin: 4px 0 0; padding-left: 20px; }
.card .src-line { margin-top: 8px; font-size: .9rem; }
.card .commentary { margin-top: 8px; padding: 8px 10px; border-left: 3px solid var(--accent); background: var(--bg); font-size: .9rem; }
.card a { color: var(--accent); }

.sheet-body .citation { display: flex; gap: 8px; align-items: flex-start; justify-content: space-between; margin: 8px 0 4px; padding: 8px 10px; border-left: 3px solid var(--accent); font-size: .9rem; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 6px 0; }
.chips .btn { min-height: 0; padding: 4px 12px; font-size: .9rem; }
.sheet.child { z-index: 11; }

.card.active { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* Desktop: contents margin, newsletter and open panels are laid out as one left-aligned row.
   --n is the number of side panels (0, 1 or 2); --offset is where the newsletter starts, which
   leaves room for the contents navigator when it is shown (body.toc-on). Nothing shifts sideways
   when panels open or close. */
@media (min-width: 900px) {
    .backdrop { display: none; } /* panels don't block the newsletter, so another card can be clicked */
    body { --panel-w: 460px; --n: 0; --offset: 16px; }
    body.toc-on { --offset: 280px; }
    body.sheet-open { --n: 1; }
    body.sheet-open.sheet-child-open { --n: 2; }
    body {
        --w: clamp(320px, calc(100vw - var(--offset) - var(--n) * var(--panel-w) - 16px), 760px);
    }
    main { width: var(--w); max-width: none; margin: 0 0 0 var(--offset); }
    .sheet {
        top: var(--topbar-h, 0px); bottom: 0; right: auto; left: calc(var(--offset, 0px) + var(--w, 0px));
        width: var(--panel-w); max-height: none; border-radius: 0; box-shadow: 0 0 24px rgba(0,0,0,.12);
        border-left: 1px solid var(--line); padding-bottom: 0;
    }
    .sheet.child { left: calc(var(--offset, 0px) + var(--w, 0px) + var(--panel-w)); }
}
/* Too narrow for three columns: the link panel covers the story panel instead of sitting beside it. */
@media (min-width: 900px) and (max-width: 1299px) {
    body.sheet-open.sheet-child-open { --n: 1; }
    .sheet.child { left: calc(var(--offset, 0px) + var(--w, 0px)); }
}

/* Story sources: plain orange links with the publisher underneath, no button chrome */
.sheet-body .link-row {
    display: block; width: 100%; margin: 0; padding: 8px 0; text-align: left; font: inherit;
    background: none; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; cursor: pointer; color: inherit;
}
.sheet-body .link-row .title { color: var(--accent); font-weight: 400; text-decoration: underline; }
.sheet-body .link-row:hover .title, .sheet-body .link-row:focus-visible .title { text-decoration-thickness: 2px; }
.sheet-body .link-row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sheet-body .link-row .meta { margin-top: 2px; }

.sheet-body a.src-link { color: var(--accent); }

.hero a.src-link { color: var(--accent); }

.copy-btn { flex: none; background: none; border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; font-size: 1rem; line-height: 1.4; cursor: pointer; color: var(--fg); }
.copy-btn:hover, .copy-btn:focus-visible { border-color: var(--accent); outline: none; }

/* Contents navigator (left margin) */
h2.section, h3.subsection { scroll-margin-top: calc(var(--topbar-h, 56px) + 12px); }
.toc {
    position: fixed; left: 16px; top: calc(var(--topbar-h, 56px) + 16px); max-height: calc(100vh - var(--topbar-h, 56px) - 32px);
    width: 240px; overflow-y: auto; font-size: .85rem; z-index: 4;
}
.toc h2 { margin: 0 0 6px; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.toc ul { list-style: none; margin: 0; padding: 0; }
.toc ul ul { margin: 0 0 4px 10px; }
.toc button {
    display: block; width: 100%; text-align: left; font: inherit; color: var(--muted); background: none; border: 0;
    border-left: 2px solid transparent; padding: 3px 0 3px 8px; cursor: pointer;
}
.toc button.toc-sec { font-weight: 600; margin-top: 4px; }
.toc button:hover, .toc button:focus-visible { color: var(--fg); outline: none; }
.toc button.current { color: var(--accent); border-left-color: var(--accent); }

.copy-md { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; text-decoration: underline; }

.toc input.toc-search { width: 100%; margin: 0 0 4px; padding: 6px 8px; font-size: .85rem; }
.toc .toc-status { margin: 0 0 8px; min-height: 1.2em; font-size: .75rem; color: var(--muted); }
mark.hit { background: rgba(242, 101, 34, .3); color: inherit; border-radius: 2px; padding: 0 1px; }

label.remember { display: flex; align-items: center; gap: 8px; }
