/* Questing design system (see design/ canvas).
   Three user-selectable themes, switched by <html data-theme="…"> (User.theme):
   - terminal   "Terminal Quest" (default): green-on-black, mono uppercase
                labels, sharp corners. Palette: bg #0c110e · panel #121a15 ·
                borders #24352b/#2c4436 · text #d3ded6 · dim #7c8f84 · accent
                #49d47e · anon #8f9fd4 · mod gold #d4b25c · live red #ff9d94.
   - hearthside "E · Hearthside": warm dim espresso, ember accent, rounded,
                Lora prose + Nunito Sans chrome.
   - storybook  "F · Storybook": linen light, terracotta accent, rounded
                cards with soft shadows, Crimson Pro prose + Quicksand chrome.
   Every themable value is a :root token overridden per theme below; rules
   never hardcode theme colors. Hacker-vs-plain label text is handled by the
   {% themed %} template tag (core/templatetags/themetags.py) + the .th-hack /
   .th-soft visibility rules at the end of the token section. */

@font-face {
    font-family: "JetBrains Mono";
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url("../fonts/jetbrains-mono-latin.b636a65da4f0.woff2") format("woff2");
}
@font-face {
    font-family: "IBM Plex Sans";
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url("../fonts/ibm-plex-sans-latin.b2c9031d9fd6.woff2") format("woff2");
}
/* Soft-theme faces: declared always, downloaded by the browser only when the
   active theme actually uses them. */
@font-face {
    font-family: "Lora";
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url("../fonts/lora-latin.9577af3ccda5.woff2") format("woff2");
}
@font-face {
    font-family: "Nunito Sans";
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url("../fonts/nunito-sans-latin.14ea133c476f.woff2") format("woff2");
}
@font-face {
    font-family: "Crimson Pro";
    font-style: normal;
    font-weight: 400 600;
    font-display: swap;
    src: url("../fonts/crimson-pro-latin.de9c1d8bbc46.woff2") format("woff2");
}
@font-face {
    font-family: "Quicksand";
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url("../fonts/quicksand-latin.9d503278216c.woff2") format("woff2");
}

:root {
    /* Terminal Quest — the default theme. */
    --bg: #0c110e;
    --panel: #121a15;
    --border: #24352b;
    --border-bright: #2c4436;
    --text: #d3ded6;
    --dim: #7c8f84;
    --dimmer: #5c6f64;
    --accent: #49d47e;
    --accent-hover: #7ce3a4;
    --accent-contrast: #06130b;  /* text on accent-filled controls */
    --accent-soft: #9db8a8;
    --primary-hover: #5fdd90;
    --hover-bg: #1a2820;
    --anon: #8f9fd4;
    --gold: #d4b25c;
    --live-fg: #ff9d94;
    --live-bg: #351b1b;
    --live-border: #63302c;
    --overlay: rgba(6, 10, 8, 0.75);

    --font-ui: "JetBrains Mono", ui-monospace, "Cascadia Mono", monospace;
    --font-body: "IBM Plex Sans", system-ui, sans-serif;
    --font-prose: var(--font-body);   /* story text */
    --font-display: var(--font-body); /* big headings */
    --font-brand: var(--font-ui);     /* the nav wordmark */
    --prose-size: 16px;
    --brand-size: 15px;
    --nav-size: 12px;

    /* Label affect: mono + uppercase + tracking in terminal, plain
       semibold sans in the soft themes. */
    --label-case: uppercase;
    --label-track: .08em;
    --label-track-sm: .06em;
    --ui-weight: 400;
    --yours-label: "✓ YOURS";

    --radius: 0px;        /* panels, cards */
    --radius-sm: 0px;     /* inputs, option rows */
    --radius-pill: 0px;   /* buttons, badges, tags */
    --radius-avatar: 0px;
    --shadow: none;
}

html[data-theme="hearthside"] {
    --bg: #221b16;
    --panel: #2b231d;
    --border: #3d332a;
    --border-bright: #55402b;
    --text: #e8ddd1;
    --dim: #a08d7b;
    --dimmer: #7d6f5f;
    --accent: #e2a26a;
    --accent-hover: #f0bd8d;
    --accent-contrast: #221b16;
    --accent-soft: #c9b39a;
    --primary-hover: #f0bd8d;
    --hover-bg: #362b22;
    --anon: #9d8fc4;
    --gold: #d8b45e;
    --live-fg: #f0bd8d;
    --live-bg: #3a2c1e;
    --live-border: #55402b;
    --overlay: rgba(16, 11, 7, 0.75);

    --font-ui: "Nunito Sans", "Segoe UI", system-ui, sans-serif;
    --font-body: "Nunito Sans", "Segoe UI", system-ui, sans-serif;
    --font-prose: "Lora", Georgia, serif;
    --font-display: "Lora", Georgia, serif;
    --font-brand: "Lora", Georgia, serif;
    --prose-size: 17px;
    --brand-size: 18px;
    --nav-size: 13.5px;

    --label-case: none;
    --label-track: 0;
    --label-track-sm: 0;
    --ui-weight: 600;
    --yours-label: "✓ yours";

    --radius: 12px;
    --radius-sm: 10px;
    --radius-pill: 999px;
    --radius-avatar: 999px;
    --shadow: none;
}

html[data-theme="storybook"] {
    --bg: #faf6ef;
    --panel: #fffdf8;
    --border: #e7dfd2;
    --border-bright: #d8cdb9;
    --text: #3d372e;
    --dim: #8d8272;
    --dimmer: #a89b85;
    --accent: #c26d5a;
    --accent-hover: #a6543f;
    --accent-contrast: #fffdf8;
    --accent-soft: #6f8a67;
    --primary-hover: #a6543f;
    --hover-bg: #f6efe2;
    --anon: #7a76a8;
    --gold: #b08a3e;
    --live-fg: #a6543f;
    --live-bg: #fbeae4;
    --live-border: #eccfc4;
    --overlay: rgba(61, 55, 46, 0.45);

    --font-ui: "Quicksand", "Trebuchet MS", system-ui, sans-serif;
    --font-body: "Quicksand", "Trebuchet MS", system-ui, sans-serif;
    --font-prose: "Crimson Pro", Georgia, serif;
    --font-display: "Crimson Pro", Georgia, serif;
    --font-brand: "Quicksand", "Trebuchet MS", system-ui, sans-serif;
    --prose-size: 19px;
    --brand-size: 18px;
    --nav-size: 13.5px;

    --label-case: none;
    --label-track: 0;
    --label-track-sm: 0;
    --ui-weight: 600;
    --yours-label: "✓ yours";

    --radius: 14px;
    --radius-sm: 12px;
    --radius-pill: 999px;
    --radius-avatar: 999px;
    --shadow: 0 2px 10px rgba(92, 66, 34, 0.06);
}

/* {% themed "Cast vote" %} renders both spellings; the active theme shows one. */
html[data-theme="terminal"] .th-soft { display: none; }
html:not([data-theme="terminal"]) .th-hack { display: none; }

* { box-sizing: border-box; }

/* Anchor jumps (resume link, chapter jumps, chat reply refs) land below
   the pinned header instead of hidden underneath it. */
html { scroll-padding-top: 64px; }

body {
    font-family: var(--font-body);
    background: var(--bg);
    color: var(--text);
    max-width: 76rem;
    margin: 0 auto;
    padding: 0 14px 14px 14px;
    font-size: 15px;
    line-height: 1.6;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

h1, h2, h3 { font-weight: 600; line-height: 1.25; }
h1 { font-size: 22px; font-family: var(--font-display); }
h2 { font-size: 17px; }
h3 { font-size: 15px; }

img, video { max-width: 100%; height: auto; border: 1px solid var(--border); }
audio { width: 100%; }

/* --- chrome --- */

/* The top bar stays pinned while the page scrolls. Opaque background so
   content doesn't show through; z-index below the dashboard overlay (40)
   but above sticky page elements like the chat column. */
header {
    position: sticky;
    top: 0;
    z-index: 30;
    background: var(--bg);
    margin-bottom: 14px;
}
header nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: var(--nav-size);
    font-weight: var(--ui-weight);
}
header nav a { color: var(--text); }
header nav a:first-child {
    font-weight: 600;
    font-family: var(--font-brand);
    font-size: var(--brand-size);
    color: var(--accent);
    margin-right: auto;
}
header nav a:hover { color: var(--accent); }

footer {
    margin-top: 40px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: 11px;
    color: var(--dimmer);
}
footer a { color: var(--dim); }

.messages {
    font-family: var(--font-ui);
    font-size: 12px;
    background: var(--panel);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-sm);
    color: var(--accent-soft);
    padding: 10px 14px;
    list-style: none;
    margin: 0 0 14px 0;
}

/* --- panels & labels --- */

.panel, .poll, .dice, .writein {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 20px;
    margin-bottom: 14px;
}
/* Interaction blocks nested inside a post panel: inset, slightly darker */
.post .poll, .post .dice, .post .writein {
    background: var(--bg);
    box-shadow: none;
    margin-bottom: 0;
}

article > section > h2 {
    font-family: var(--font-ui);
    font-size: 12px;
    letter-spacing: var(--label-track);
    text-transform: var(--label-case);
    color: var(--accent-soft);
    margin: 22px 0 10px 0;
}

.label, .smallhead, main h2 {
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: var(--ui-weight);
    letter-spacing: var(--label-track);
    text-transform: var(--label-case);
    color: var(--dim);
}
main h2 { color: var(--text); font-weight: 600; font-size: 13px; }

small, .muted { color: var(--dim); }

mark {
    font-family: var(--font-ui);
    font-size: 11px;
    background: var(--live-bg);
    border: 1px solid var(--live-border);
    border-radius: var(--radius-pill);
    color: var(--live-fg);
    padding: 3px 8px;
}
mark:empty { display: none; }

/* --- controls --- */

button, input[type="submit"] {
    font-family: var(--font-ui);
    font-size: 12px;
    font-weight: var(--ui-weight);
    background: var(--panel);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-pill);
    color: var(--accent);
    padding: 10px 16px;
    cursor: pointer;
    min-height: 40px;
}
button:hover { background: var(--hover-bg); }
button.primary, form button[type="submit"]:only-of-type {
    background: var(--accent);
    color: var(--accent-contrast);
    font-weight: 600;
    border-color: var(--accent);
}
button.primary:hover, form button[type="submit"]:only-of-type:hover { background: var(--primary-hover); }

input, textarea, select {
    font-family: var(--font-ui);
    font-size: 13px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 12px;
    max-width: 100%;
    min-height: 40px;
}
textarea { width: 100%; font-family: var(--font-body); font-size: 14px; }
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--accent);
}
input::placeholder, textarea::placeholder { color: var(--dimmer); }
label { font-size: 13.5px; }
form p { margin: 0 0 12px 0; display: flex; flex-direction: column; gap: 5px; }
form p label { font-family: var(--font-ui); font-size: 11px; text-transform: var(--label-case); letter-spacing: var(--label-track-sm); color: var(--dim); }
.helptext { font-size: 12px; color: var(--dimmer); }
.errorlist { color: var(--live-fg); font-size: 12.5px; list-style: none; padding: 0; margin: 4px 0; }

details > summary {
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: var(--ui-weight);
    text-transform: var(--label-case);
    letter-spacing: var(--label-track-sm);
    color: var(--accent-soft);
    cursor: pointer;
    padding: 6px 0;
}

table { border-collapse: collapse; width: 100%; overflow-x: auto; display: block; font-size: 13.5px; }
th { font-family: var(--font-ui); font-size: 11px; text-transform: var(--label-case); letter-spacing: var(--label-track-sm); color: var(--dim); font-weight: var(--ui-weight); }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }

/* --- story list --- */

.list-controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px 14px;
    margin-bottom: 14px;
}
.list-controls input[type="search"] { flex-grow: 1; min-width: 200px; }
/* Sort options are plain text ("Sort: updated") — <option> can't carry the
   {% themed %} spans, so terminal uppercases them here instead. */
.list-controls select { text-transform: var(--label-case); }
.list-controls label { font-family: var(--font-ui); font-size: 11px; color: var(--dim); display: flex; align-items: center; gap: 6px; }
.list-controls details { width: 100%; }
.list-controls details p { display: flex; flex-direction: row; align-items: center; gap: 10px; margin: 8px 0; }
.list-controls details label { flex: 0 0 13rem; }
.list-controls details input { flex-grow: 1; }
.list-controls details input[type="number"] { flex: 0 0 8em; min-width: 0; }

.section-head {
    font-family: var(--font-ui);
    font-size: 11px;
    font-weight: var(--ui-weight);
    letter-spacing: var(--label-track);
    margin: 4px 0 10px 0;
    color: var(--dim);
}
.section-head.live { color: var(--live-fg); }

.story-list { list-style: none; padding: 0; margin: 0; }
.story-row {
    display: flex;
    align-items: center;
    gap: 16px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 12px 16px;
    margin-bottom: 10px;
}
.story-row.live { border-color: var(--live-border); }
.story-row .cover {
    width: 56px;
    height: 56px;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}
.story-row .info { flex-grow: 1; min-width: 0; }
.story-row .title-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 10px; }
.story-row .title-line strong { font-size: 16px; }
.story-row .hook { color: var(--dim); font-size: 13px; margin: 3px 0 0 0; }
.story-row .stats {
    font-family: var(--font-ui);
    font-size: 11px;
    color: var(--dim);
    text-align: right;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.story-row .stats .reading { color: var(--accent); }

.tag {
    font-family: var(--font-ui);
    font-size: 10px;
    color: var(--accent-soft);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 2px 7px;
}

.pagination {
    font-family: var(--font-ui);
    font-size: 12px;
    text-transform: var(--label-case);
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 18px;
    padding: 10px 0;
    color: var(--dim);
}
.pagination a { border: 1px solid var(--border-bright); border-radius: var(--radius-pill); padding: 9px 16px; }

/* Figures come from the editor's image wrapper: no browser default indent. */
.post figure { margin: 0; }

/* --- story page --- */

.story-layout { display: block; }
@media (min-width: 62rem) {
    .story-layout {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 390px;
        gap: 14px;
        align-items: start;
    }
    .side-col { position: sticky; top: 62px; } /* clears the pinned header */
}

.story-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 14px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 18px;
    margin-bottom: 14px;
}
.story-head h1 { margin: 0; }
/* Full-size cover above the story header (natural size, capped at column width). */
.story-cover { display: block; max-width: 100%; margin: 0 auto 14px auto; border-radius: var(--radius); }

.story-meta { font-family: var(--font-ui); font-size: 11px; color: var(--dim); }

article section h2 small { font-family: var(--font-ui); text-transform: none; letter-spacing: 0; }

.post { margin-bottom: 18px; }
.post p { font-family: var(--font-prose); font-size: var(--prose-size); line-height: 1.7; }
.post .post-meta { font-family: var(--font-ui); font-size: 10px; color: var(--dimmer); }
.post img { display: block; margin: 12px 0 4px 0; }

/* polls / dice / write-ins */
.poll ul, .writein ul { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.poll li, .writein li {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    font-size: 14px;
}
.poll li.struck, .writein li.removed { border-style: dashed; color: var(--dimmer); }
.poll li:has(input:checked) { border-color: var(--accent); }
.poll li:has(input:checked) > label::after {
    content: var(--yours-label);
    font-family: var(--font-ui);
    font-size: 10px;
    font-weight: var(--ui-weight);
    color: var(--accent);
}
.poll .votes { font-family: var(--font-ui); font-size: 12px; color: var(--accent); }
.poll .votes .muted { color: var(--dim); }
.dice ol { font-family: var(--font-ui); font-size: 12.5px; padding-left: 20px; }
.writein .who { font-family: var(--font-ui); font-size: 12px; color: var(--accent); }
.writein .who.anon { color: var(--anon); }

/* --- sidebar: topics + chat --- */

#chat,
#topics {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    padding: 0;
    margin-bottom: 14px;
}
#chat h2,
#topics h2 {
    display: flex;
    justify-content: space-between;
    margin: 0;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-family: var(--font-ui);
    font-size: 11px;
    color: var(--accent);
}
#chat h2 .presence,
#topics h2 .presence { color: var(--dim); font-weight: var(--ui-weight); }

#topic-list {
    list-style: none;
    margin: 0;
    padding: 10px 16px;
    font-family: var(--font-ui);
    font-size: 12px;
    display: flex;
    flex-direction: column;
    gap: 7px;
    max-height: 22vh;
    overflow-y: auto;
}
#topic-list li { display: flex; justify-content: space-between; gap: 10px; }
#topic-list a { color: var(--text); }
#topic-list a:hover { color: var(--accent); }
#chat-log {
    list-style: none;
    margin: 0;
    padding: 12px 16px;
    font-family: var(--font-ui);
    font-size: 12px;
    line-height: 1.5;
    display: flex;
    flex-direction: column;
    gap: 9px;
    max-height: 60vh;
    overflow-y: auto;
}
#chat-log strong { color: var(--accent); font-weight: 600; }
#chat-log .chat-time { color: var(--dimmer); font-size: 10px; }
/* Header row: avatar · name · timestamp, vertically centered; message below. */
#chat-log .chat-head { display: flex; align-items: center; gap: 6px; }
#chat-log .chat-body { margin-top: 2px; overflow-wrap: anywhere; white-space: pre-wrap; }
#chat-log .chat-body .greentext { color: var(--accent); }
#chat-log .chat-reply-ref {
    display: block;
    max-width: 100%;
    margin-top: 2px;
    padding-left: 6px;
    border-left: 2px solid var(--border-bright);
    color: var(--dim);
    font-size: 11px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#chat-log .chat-reply-btn {
    margin-left: auto;
    min-height: 0;
    padding: 0 5px;
    border: none;
    background: transparent;
    color: var(--dimmer);
    font-size: 12px;
}
#chat-log .chat-reply-btn:hover { color: var(--accent); background: transparent; }
#chat-log li:target { background: var(--hover-bg); outline: 1px solid var(--border-bright); }
#chat-reply-state { padding: 0 16px 6px 16px; }
#chat-reply-state span { color: var(--accent); }
#chat-reply-state button { min-height: 0; padding: 0 6px; border: none; background: transparent; color: var(--live-fg); }

/* Small avatars (chat lines, topic bylines). */
.avatar-sm {
    width: 18px;
    height: 18px;
    object-fit: cover;
    border: 1px solid var(--border);
    border-radius: var(--radius-avatar);
    vertical-align: -4px;
}
.chat-head .avatar-sm { vertical-align: 0; }
#chat-log .anon strong { color: var(--anon); }
#chat-error { font-family: var(--font-ui); font-size: 11px; color: var(--live-fg); padding: 0 16px; }
#chat-error:empty { display: none; }
#chat-form { display: flex; gap: 8px; padding: 12px 16px; border-top: 1px solid var(--border); }
#chat-form textarea {
    flex-grow: 1;
    min-width: 0;
    min-height: 40px;
    max-height: 10rem; /* beyond this it scrolls */
    resize: none;
    overflow-y: auto;
    font-family: var(--font-ui);
    font-size: 13px;
}
#chat-form button { align-self: flex-end; }
#chat-form { align-items: flex-start; }
/* Author dashboard overlay: story admin floats over the live page. */
#dashboard-overlay {
    position: fixed;
    inset: 0;
    z-index: 40;
    background: var(--overlay);
    overflow-y: auto;
    padding: 48px 16px;
}
#dashboard-panel { max-width: 40rem; margin: 0 auto; }

/* In-chat images stay thumbnail-sized; click opens the full file. */
#chat-log img { display: block; max-height: 160px; width: auto; margin: 4px 0; }
#chat-img-form { padding: 0 16px 12px 16px; }
#chat-img-form button { font-size: 11px; padding: 3px 8px; }

@media (max-width: 62rem) {
    #chat-log { max-height: 40vh; }
}

/* --- account settings: theme picker --- */

.theme-picker { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 14px 0; }
.theme-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    cursor: pointer;
}
.theme-card:has(input:checked) { border-color: var(--accent); }
.theme-card input { min-height: 0; }
.theme-card .swatches { display: flex; align-items: center; }
.theme-card .swatches span {
    width: 16px;
    height: 16px;
    border-radius: 999px;
    border: 1px solid rgba(128, 128, 128, 0.45);
    margin-left: -5px;
}
.theme-card .swatches span:first-child { margin-left: 0; }
.theme-card .name { display: flex; flex-direction: column; }
.theme-card .name small { font-size: 11.5px; }
/* Swatch colors are the theme's own, not the active theme's tokens. */
.theme-card.terminal .swatches span:nth-child(1) { background: #0c110e; }
.theme-card.terminal .swatches span:nth-child(2) { background: #121a15; }
.theme-card.terminal .swatches span:nth-child(3) { background: #49d47e; }
.theme-card.hearthside .swatches span:nth-child(1) { background: #221b16; }
.theme-card.hearthside .swatches span:nth-child(2) { background: #2b231d; }
.theme-card.hearthside .swatches span:nth-child(3) { background: #e2a26a; }
.theme-card.storybook .swatches span:nth-child(1) { background: #faf6ef; }
.theme-card.storybook .swatches span:nth-child(2) { background: #fffdf8; }
.theme-card.storybook .swatches span:nth-child(3) { background: #c26d5a; }
