/* DQW site chrome in the DS BIOS style. Reference: DESIGN-ds-theme.md.
   Quest stylesheets never reach this file's elements; post bodies live in shadow roots
   styled by content.css plus the quest's own sheet. */

/* Every character the font has but its ellipsis (U+2026), which it draws mid-line, Japanese style. The fallback
   font draws that one on the baseline. */
@font-face {
  font-family: 'DotGothic16';
  src: url("../fonts/DotGothic16-latin.532999ec5859.woff2") format('woff2');
  font-display: swap;
  unicode-range: U+20-7E, U+A0-FF, U+2018-201A, U+201C-201E, U+2022, U+2190-2193, U+25A0-25A2, U+25B2-25B3, U+25B7,
    U+25BC-25BD, U+25C1, U+25C6-25C7, U+25C9, U+25CB, U+25CE-25CF, U+25E2-25E5, U+25EF;
}

/* Tokens. Every theme defines every token (spec section 9). The favorite color (--fav-*)
   is lavender by default; readers will be able to pick any of the DS colors. */
[hidden] { display: none !important; }

:root,
:root[data-theme="light"] {
  --table-head-bg: var(--fav-100);
  --table-head-text: #232323;
  --bg: #f3f3f3;
  --bg-surface: #ffffff;
  --bg-elevated: #fbfbfb;
  --bg-input: #ffffff;
  --text: #292929;
  --text-muted: #525252;
  --border: #000000;
  --grid-s: #e3e3e3;
  --grid-l: #d3d3d3;
  --rule: #e3e3eb;
  --msgbox: #292929;
  --msgbox-text: #fbfbfb;
  --accent: var(--fav-main);
  --accent-hover: var(--fav-border);
  --accent-text: #ffffff;
  --error: #b31b1b;
  --success: #1b6b1b;
  --warning: #8b4b03;
  --live: #a3131b;
  --n-red: #b31b23;
  --n-blue: #0b3bc3;
  --n-green: #1b6b23;
  --n-orange: #9b4303;
  --n-purple: #6b2ba3;
  --n-gray: #525252;
  --greentext: #2b6b13;
  --link: var(--fav-border);
  --shadow-key: #4a4a4a;
}

:root[data-theme="dark"] {
  --table-head-bg: var(--fav-main);
  --table-head-text: #ffffff;
  --bg: #292929;
  --bg-surface: #313131;
  --bg-elevated: #3b3b3b;
  --bg-input: #232323;
  --text: #efefef;
  --text-muted: #b5b5b5;
  --border: #7b7b7b;
  --grid-s: #313131;
  --grid-l: #3b3b3b;
  --rule: #3b3b43;
  --msgbox: #131313;
  --msgbox-text: #efefef;
  --accent-text: #ffffff;
  --error: #ff737b;
  --success: #7bd37b;
  --warning: #fbb34b;
  --live: #ff6b73;
  --n-red: #ff7b83;
  --n-blue: #93b3fb;
  --n-green: #73d37b;
  --n-orange: #fbab4b;
  --n-purple: #c3a3fb;
  --n-gray: #b5b5b5;
  --greentext: #93d36b;
  --link: var(--fav-300);
  --shadow-key: #131313;
}
/* A reader who never picked a theme gets their device's: these are the dark tokens above, word for word
   (tests/test_theme_contrast.py holds them to it). */
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] {
    --table-head-bg: var(--fav-main);
    --table-head-text: #ffffff;
    --bg: #292929;
    --bg-surface: #313131;
    --bg-elevated: #3b3b3b;
    --bg-input: #232323;
    --text: #efefef;
    --text-muted: #b5b5b5;
    --border: #7b7b7b;
    --grid-s: #313131;
    --grid-l: #3b3b3b;
    --rule: #3b3b43;
    --msgbox: #131313;
    --msgbox-text: #efefef;
    --accent-text: #ffffff;
    --error: #ff737b;
    --success: #7bd37b;
    --warning: #fbb34b;
    --live: #ff6b73;
    --n-red: #ff7b83;
    --n-blue: #93b3fb;
    --n-green: #73d37b;
    --n-orange: #fbab4b;
    --n-purple: #c3a3fb;
    --n-gray: #b5b5b5;
    --greentext: #93d36b;
    --link: var(--fav-300);
    --shadow-key: #131313;
  }
}


:root[data-theme="hc-light"] {
  --bg: #ffffff;
  --bg-surface: #ffffff;
  --bg-elevated: #ffffff;
  --bg-input: #ffffff;
  --text: #000000;
  --text-muted: #232323;
  --border: #000000;
  --grid-s: #ffffff;
  --grid-l: #ffffff;
  --rule: #ffffff;
  --msgbox: #000000;
  --msgbox-text: #ffffff;
  --accent-text: #ffffff;
  --error: #8b0303;
  --success: #034b03;
  --warning: #633303;
  --live: #8b0303;
  --n-red: #8b0303;
  --n-blue: #03238b;
  --n-green: #034b03;
  --n-orange: #6b2b03;
  --n-purple: #4b0383;
  --n-gray: #232323;
  --greentext: #034b03;
  --link: #03238b;
  --shadow-key: #000000;
}

:root[data-theme="hc-dark"] {
  --table-head-bg: #000000;
  --table-head-text: #ffffff;
  --bg: #000000;
  --bg-surface: #000000;
  --bg-elevated: #000000;
  --bg-input: #000000;
  --text: #ffffff;
  --text-muted: #e3e3e3;
  --border: #ffffff;
  --grid-s: #000000;
  --grid-l: #000000;
  --rule: #000000;
  --msgbox: #000000;
  --msgbox-text: #ffffff;
  --accent-text: #000000;
  --error: #ff9ba3;
  --success: #9bfb9b;
  --warning: #fbd36b;
  --live: #ff9ba3;
  --n-red: #ff9ba3;
  --n-blue: #b3cbfb;
  --n-green: #9bfb9b;
  --n-orange: #fbcb83;
  --n-purple: #dbc3fb;
  --n-gray: #e3e3e3;
  --greentext: #b3fb8b;
  --link: #b3cbfb;
  --shadow-key: #ffffff;
}

/* Favorite colors: the DS ramp shape (main, border, 100 to 500). Lavender is DQW's own. */
:root,
[data-fav="lavender"] {
  --fav-main: #8b7bdb; --fav-border: #5b4bb3;
  --fav-100: #ebebfb; --fav-200: #d3cbfb; --fav-300: #c3bbf3; --fav-400: #ab9bf3; --fav-500: #9b8beb;
}
[data-fav="sky"] {
  --fav-main: #30baf3; --fav-border: #1871a2;
  --fav-100: #e3f3fb; --fav-200: #c3ebfb; --fav-300: #a2e3fb; --fav-400: #82dbfb; --fav-500: #61d3fb;
}
[data-fav="purple"] {
  --fav-main: #8a00d3; --fav-border: #710092;
  --fav-100: #ebbafb; --fav-200: #dea5ff; --fav-300: #d382fb; --fav-400: #cb61fb; --fav-500: #c341fb;
}
[data-fav="red"] {
  --fav-main: #ff0018; --fav-border: #cb0000;
  --fav-100: #fbbaba; --fav-200: #fba2aa; --fav-300: #fb929a; --fav-400: #fb7982; --fav-500: #fb6971;
}
[data-fav="green"] {
  --fav-main: #34b356; --fav-border: #1e7a3a;
  --fav-100: #e3f7e8; --fav-200: #c3efcf; --fav-300: #a2e3b4; --fav-400: #7fd698; --fav-500: #5cc77c;
}
[data-fav="slate"] {
  --fav-main: #61829a; --fav-border: #42637b;
  --fav-100: #ebebf3; --fav-200: #d3dbe3; --fav-300: #bacbd3; --fav-400: #a2bac3; --fav-500: #8aa2b2;
}

/* Base */
:root { --indent: 24px; }
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid-l) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-l) 1px, transparent 1px),
    linear-gradient(var(--grid-s) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-s) 1px, transparent 1px);
  background-size: 64px 64px, 64px 64px, 16px 16px, 16px 16px;
  font: 16px/1.6 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
:root[data-theme^="hc"] body { background-image: none; }
a { color: var(--link); }
.px, .form label[for], .choices legend, .choice, .folder-tabs, .site-links, .sort-links, .pager, .tools, .jump,
.desk-tabs, .mod-menu, .poll-tools, .meta-line, .card-status { font-family: 'DotGothic16', ui-monospace, monospace; letter-spacing: 0.02em; }
.sr-only { position: absolute; left: 0; width: 1px; height: 1px; padding: 0; margin: -1px; border: 0; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
main { width: 100%; max-width: 860px; margin: 0 auto; padding: 16px 16px 120px; flex: 1; }

/* Frame bars: the theme-colored gradient bars at the top and bottom of the DS screens. */
.bar {
  background: linear-gradient(var(--fav-300), var(--fav-main));
  color: #ffffff;
  border-bottom: 2px solid var(--fav-border);
  text-shadow: 0 1px 0 var(--fav-border);
}
:root[data-theme^="hc"] .bar { background: var(--text); color: var(--bg); text-shadow: none; border-color: var(--text); }
/* The top bar is pinned on every page. Whatever hangs under it, or scrolls to an anchor, reads its height from
   --topbar-h, which the page script keeps at the bar's measured height. The bar's own least height is a separate
   value: if the bar read back what was measured from it, it could grow and never shrink. */
:root { --topbar-min: 34px; --topbar-h: var(--topbar-min); }
@media (pointer: coarse) { :root { --topbar-min: 44px; } }
html { scroll-padding-top: var(--topbar-h); }
.topbar { display: flex; align-items: stretch; min-height: var(--topbar-min); font-size: 15px; position: sticky; top: 0; z-index: 10; }
.topbar > * { display: flex; align-items: center; padding: 0 12px; }
.topbar .cell { border-left: 2px dotted rgba(255, 255, 255, 0.6); }
.topbar .jump-cell { gap: 10px; }
.topbar .jump-cell button { color: inherit; font: inherit; text-decoration: none; padding: 0 4px; }
/* Under a password box. Two classes, to stand over .linklike's reset. */
.linklike.reveal { justify-self: end; margin-top: -4px; font-size: 13px; }
.topbar .grow { flex: 1; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.topbar .online, .topbar .reading { gap: 0.4em; white-space: nowrap; }
.topbar .bell a { display: inline-flex; align-items: center; gap: 4px; color: inherit; text-decoration: none; }
.topbar .bell .icon { width: 16px; height: 16px; }
.unread-badge { min-width: 1.3em; padding: 0 4px; font-size: 12px; line-height: 16px; text-align: center; background: var(--live); color: #fff; text-shadow: none; }
.notification-list { list-style: none; margin: 0; padding: 0; }
.notification { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 8px 4px; border-bottom: 1px dotted var(--border); }
.notification.unread { border-left: 3px solid var(--fav-main); padding-left: 8px; background: var(--bg-elevated); }
.channel-table td:last-child, .channel-table th:last-child { text-align: center; width: 5em; }
.push-device { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; font-size: 14px; }
.follow-box { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 12px; margin: 0 0 10px; font-size: 13px; }
.follow-options { display: inline-flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; }
.topbar a { color: inherit; text-decoration: none; }
.brand { font-size: 17px; }
/* Indicators: live, rating, tag. One shape everywhere, so they line up wherever they sit together. */
.live-dot, .rating-badge, .tag {
  display: inline-flex; align-items: center; box-sizing: border-box; height: 20px; padding: 0 6px; vertical-align: middle;
  font: 12px/1 'DotGothic16', ui-monospace, monospace; letter-spacing: 0.02em; border: 1px solid; border-radius: 2px; text-shadow: none;
}
.live-dot { color: #fff; background: var(--live); border-color: var(--live); }

/* Breadcrumbs: one horizontal trail, each level after a ">". Long titles wrap rather than widen the page. */
.stack {
  list-style: none;
  margin: 0 0 16px;
  padding: 3px 10px;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0 8px;
  background: linear-gradient(var(--bg-elevated), var(--bg-surface));
  border: 2px solid var(--border);
  font-size: 14px;
  color: var(--text-muted);
}
.stack li { min-width: 0; overflow-wrap: anywhere; }
.stack li + li::before { content: ">" / ""; margin-right: 8px; color: var(--text-muted); }
.stack li:last-child { color: var(--text); }
.stack a { color: inherit; }

/* The bot builders' guide */
.guide { display: grid; gap: 10px; }
.guide h1 { margin: 0; font-size: 24px; }
.guide h2 { margin: 12px 0 0; font-size: 18px; }
.guide p, .guide ul { margin: 0; }
.guide pre, .ref-example { margin: 0; padding: 8px 10px; background: var(--bg-input); border: 2px solid var(--border); overflow-x: auto; font: 13px/1.5 ui-monospace, monospace; }
.guide code { font-family: ui-monospace, monospace; font-size: 0.92em; overflow-wrap: anywhere; }
.guide pre code, .ref-example code { overflow-wrap: normal; }
.guide-table { border-collapse: collapse; font-size: 14px; }
.guide-table th, .guide-table td { border: 2px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }

/* Account page bots */
.bot-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.bot-list li { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.bot-detail { font-size: 13px; color: var(--text-muted); overflow-wrap: anywhere; }
.token-box { border: 2px solid var(--fav-border); background: var(--bg-input); padding: 8px 10px; display: grid; gap: 6px; }
.token-box p { margin: 0; font-size: 13px; }
.token-box code { font: 14px ui-monospace, monospace; overflow-wrap: anywhere; user-select: all; }

/* Rules and privacy pages, and the footer links to them */
.page-body { max-width: none; }
.page-body h1 { margin-top: 0; }
.page-meta { font-size: 13px; color: var(--text-muted); }
.folder-tabs { display: flex; flex-wrap: wrap; gap: 2px 4px; border-bottom: 2px solid var(--fav-border); margin: 0 0 12px; }
.folder-tabs a { padding: 5px 12px; font-size: 14px; text-decoration: none; color: var(--text); background: var(--bg-elevated);
  border: 2px solid var(--border); border-bottom: 0; margin-bottom: -2px; }
.folder-tabs a[aria-selected="true"] { background: var(--fav-main); color: #fff; border-color: var(--fav-border); }
.folder-tabs a[data-dirty]::after { content: " \2022"; }
/* A quest's tabs hang from its breadcrumb as one block; the settings sections sit apart from Title and Latest. */
.stack:has(+ .quest-tabs) { margin-bottom: 0; border-bottom: 0; }
.quest-tabs { padding: 6px 8px 0; background: var(--bg-surface); border: 2px solid var(--border); border-bottom-color: var(--fav-border); margin-bottom: 16px; }
.folder-tabs a[aria-current="page"] { background: var(--fav-main); color: #fff; border-color: var(--fav-border); }
.quest-tabs .settings-start { margin-left: 12px; }
/* Phones get one Settings tab instead of every section, except on the settings page itself. */
.quest-tabs .settings-fold { display: none; }
@media (max-width: 640px) {
  .quest-tabs .settings-fold { display: inline-flex; }
  .quest-tabs .settings-tab { display: none; }
  .quest-tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: thin; }
  .quest-tabs a { flex: none; }
  .quest-tabs .settings-start { margin-left: 6px; }
}
.help-btn { min-width: 34px; justify-content: center; }
.ref-table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 8px 0 12px; }
.ref-table th, .ref-table td { border: 1px solid var(--border); padding: 4px 8px; text-align: left; vertical-align: top; }
.ref-table td:first-child { white-space: nowrap; }
.reference h3 { margin: 18px 0 6px; font-size: 16px; }
.host-list { list-style: none; padding: 0; columns: 3 160px; column-gap: 16px; font-size: 13px; }
.host-list li { break-inside: avoid; padding: 1px 0; }
/* The icon sits in the top right corner and the rest of the title page wraps around it. */
.title-page { display: flow-root; }
.title-page h1 { margin: 0 0 6px; }
.title-icon { float: right; width: 180px; height: 180px; object-fit: cover; border: 2px solid var(--fav-border); margin: 0 0 12px 16px; background: var(--bg-elevated); }
@media (max-width: 640px) { .title-icon { width: 104px; height: 104px; margin-left: 12px; } }
.long-tools { margin: 6px 0 0; font-size: 13px; }
.draft-banner { margin: 0 0 12px; padding: 8px 14px; border-color: var(--warning); }
.draft-banner p { margin: 4px 0; }
.draft-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.live-toggle { margin: 0 0 8px; font-size: 13px; display: flex; align-items: center; gap: 8px; }
.desk-live .live-dot { margin-right: 2px; }
.form.long-edit { max-width: none; margin: 8px 0 0; }
.long-edit textarea { width: 100%; box-sizing: border-box; font: 15px/1.45 system-ui, sans-serif; padding: 8px 10px; border: 2px solid var(--fav-border); background: var(--bg-input); color: var(--text); resize: vertical; }
.long-preview:not(:empty) { border: 2px dashed var(--border); padding: 4px 12px; margin-top: 8px; }
.title-badges { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0 0 10px; }
.title-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.title-blurb { font-size: 17px; }
.title-page .tags { display: flex; flex-wrap: wrap; gap: 4px; }
.title-page .tags a.tag { text-decoration: none; }
.long-description { border-top: 2px dotted var(--border); margin-top: 12px; padding-top: 4px; }
.long-description [data-long-view]:empty { display: none; }
.qst-steps { margin: 0 0 16px; padding-left: 24px; }
.qst-steps li { padding: 3px 0; }
.qst-steps li.done { color: var(--text-muted); }
.step-done { color: var(--text); font-weight: bold; }
.page-toc { font-size: 14px; border: 2px dotted var(--border); padding: 8px 12px; margin: 0 0 16px; }
.page-toc ol { margin: 0; padding-left: 20px; columns: 2 220px; column-gap: 24px; }
.page-toc li { break-inside: avoid; padding: 2px 0; }
.page-body h2 { scroll-margin-top: 12px; }
.site-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 16px; font-size: 13px; margin: 4px 0 16px; }

/* Rating and tag picker */
.choice-row { display: flex; gap: 8px; align-items: baseline; padding: 2px 0; }
.choice-row .hint, .tag-group .hint { font-size: 13px; color: var(--text-muted); }
.tag-group { border: 2px solid var(--border); padding: 4px 10px; margin-top: 6px; }
.tag-group summary { cursor: pointer; }
.tag-group-count { font-size: 12px; color: var(--fav-main); }
/* Each tag shows its meaning under its name, so QMs pick without hovering. */
.tag-boxes { display: grid; grid-template-columns: repeat(auto-fill, minmax(15em, 1fr)); gap: 6px 14px; padding: 6px 0; }
.tag-sub { grid-column: 1 / -1; margin: 6px 0 0; font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.tag-box { display: flex; gap: 6px; align-items: baseline; font-size: 14px; }
.tag-box[hidden] { display: none; }
.tag-desc { display: block; font-size: 12px; line-height: 1.35; color: var(--text-muted); }
.tag-box.tag-too-high { opacity: 0.45; }
.rating-badge { border-color: currentColor; }
.rating-badge.r-plain { color: var(--text-muted); }
.rating-badge.r-nsfw { color: #b07a00; }
.quest-warnings { margin: 4px 0 0; font-size: 14px; }
.rating-badge.r-taboo { color: #b03a8a; }
.rating-badge.r-extreme { color: #c03030; }
:root[data-theme="dark"] .rating-badge.r-nsfw { color: #e3b34f; }
:root[data-theme="dark"] .rating-badge.r-taboo { color: #e486c3; }
:root[data-theme="dark"] .rating-badge.r-extreme { color: #f08585; }
@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .rating-badge.r-nsfw { color: #e3b34f; }
  :root[data-theme="auto"] .rating-badge.r-taboo { color: #e486c3; }
  :root[data-theme="auto"] .rating-badge.r-extreme { color: #f08585; }
}
.tag.tag-warning { border-color: var(--live); }
.quest-card.fogged > div > :not(h2):not(.fog-line):not(.card-by) { display: none; }
.fog-line { font-size: 13px; color: var(--text-muted); }
.pref-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.pref-list li, .pref-add { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; }
.pref-list select, .pref-add select, .pref-add input { font: inherit; padding: 2px 6px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); }
.pref-add input { flex: 1; min-width: 12em; }

/* Moderation: the act dialog, warnings shown to their reader, and the active list */
.mod-dialog { max-width: 520px; width: calc(100% - 32px); color: var(--text); }
.mod-dialog form { display: grid; gap: 8px; }
.mod-dialog h2 { margin: 0; font-size: 18px; }
.mod-field { display: grid; gap: 2px; font-size: 14px; }
.mod-field select, .mod-field input, .mod-field textarea { font: inherit; padding: 3px 6px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); }
.mod-warning { border-color: var(--live); margin-bottom: 12px; display: grid; gap: 6px; }
.mod-warning p, .mod-warning blockquote { margin: 0; }
.mod-warning .ds-btn { justify-self: start; }
.mod-active { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.mod-active-row { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; }
.mod-detail { font-size: 13px; color: var(--text-muted); overflow-wrap: anywhere; }

/* Panels and tabs */
.panel { background: var(--bg-surface); border: 2px solid var(--border); padding: 12px 14px; }
.tab {
  display: inline-block;
  background: var(--msgbox);
  color: var(--msgbox-text);
  font-size: 13px;
  padding: 1px 10px;
  border: 2px solid var(--border);
  border-bottom: 0;
}
.tab.fav { background: var(--fav-main); border-color: var(--fav-border); color: #fff; }
.tab + .panel { border-top-left-radius: 0; }

/* Selection brackets: four theme-colored corners around the selected thing.
   Used for keyboard focus, the voted option, and a >>N target. */
.brackets, :focus-visible, :target { position: relative; }
.brackets::after,
.card:focus-visible::after, .ds-btn:focus-visible::after, .msg:target::after, .update:target::after {
  content: '';
  position: absolute;
  inset: -6px;
  pointer-events: none;
  --c: var(--fav-border);
  --l: 12px;
  --t: 3px;
  background:
    linear-gradient(var(--c), var(--c)) top left / var(--l) var(--t),
    linear-gradient(var(--c), var(--c)) top left / var(--t) var(--l),
    linear-gradient(var(--c), var(--c)) top right / var(--l) var(--t),
    linear-gradient(var(--c), var(--c)) top right / var(--t) var(--l),
    linear-gradient(var(--c), var(--c)) bottom left / var(--l) var(--t),
    linear-gradient(var(--c), var(--c)) bottom left / var(--t) var(--l),
    linear-gradient(var(--c), var(--c)) bottom right / var(--l) var(--t),
    linear-gradient(var(--c), var(--c)) bottom right / var(--t) var(--l);
  background-repeat: no-repeat;
}
:focus-visible { outline: none; }
a:focus-visible, textarea:focus-visible, input:focus-visible { outline: 3px solid var(--fav-border); outline-offset: 2px; }

/* DS primary button: notched 1px border, white bevel, stepped dithered gradient
   through the favorite ramp. One DS pixel is --p. */
.ds-btn {
  --p: 2px;
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: calc(4 * var(--p));
  min-height: calc(17 * var(--p));
  padding: 0 calc(7 * var(--p));
  font: 15px/1 'DotGothic16', ui-monospace, monospace;
  color: #000;
  background: var(--fav-border);
  border: 0;
  cursor: pointer;
  clip-path: polygon(var(--p) 0, calc(100% - var(--p)) 0, 100% var(--p), 100% calc(100% - var(--p)), calc(100% - var(--p)) 100%, var(--p) 100%, 0 calc(100% - var(--p)), 0 var(--p));
  isolation: isolate;
}
.ds-btn::before {
  content: '';
  position: absolute;
  inset: var(--p);
  z-index: -1;
  background:
    linear-gradient(90deg, var(--fav-500) 50%, var(--fav-400) 50%) 0 calc(3 * var(--p)) / calc(2 * var(--p)) var(--p) repeat-x,
    linear-gradient(90deg, var(--fav-400) 50%, var(--fav-300) 50%) 0 calc(6 * var(--p)) / calc(2 * var(--p)) var(--p) repeat-x,
    linear-gradient(90deg, var(--fav-300) 50%, var(--fav-200) 50%) 0 calc(9 * var(--p)) / calc(2 * var(--p)) var(--p) repeat-x,
    linear-gradient(90deg, var(--fav-200) 50%, var(--fav-100) 50%) 0 calc(12 * var(--p)) / calc(2 * var(--p)) var(--p) repeat-x,
    linear-gradient(var(--fav-500) 0 calc(3 * var(--p)), var(--fav-400) 0 calc(6 * var(--p)), var(--fav-300) 0 calc(9 * var(--p)), var(--fav-200) 0 calc(12 * var(--p)), var(--fav-100) 0 calc(14 * var(--p)), #fff 0);
  box-shadow: 0 0 0 var(--p) #fff inset;
}
/* B buttons back out: cancel, close, decline. They reuse the A button's ramp with greys in place of the fav colour. */
.ds-btn.b { --fav-100: #f4f4f4; --fav-200: #e4e4e4; --fav-300: #d2d2d2; --fav-400: #bebebe; --fav-500: #a9a9a9; --fav-border: #5f5f5f; }
a.ds-btn { text-decoration: none; }
.ds-btn:active::before, .ds-btn[aria-pressed="true"]::before { transform: scaleY(-1); }
.ds-btn:active > *, .ds-btn[aria-pressed="true"] > * { position: relative; top: var(--p); }
.ds-btn[disabled] { filter: grayscale(1); opacity: 0.6; cursor: default; }
:root[data-theme^="hc"] .ds-btn { background: var(--text); clip-path: none; }
:root[data-theme^="hc"] .ds-btn::before { background: var(--bg-surface); box-shadow: none; }
:root[data-theme="hc-dark"] .ds-btn { color: var(--text); }
.glyph {
  display: inline-grid; place-items: center;
  width: 1.2em; height: 1.2em; border-radius: 50%;
  background: #000; color: #fff; font-size: 0.8em; line-height: 1;
}

/* The thread: QM updates full width; reader posts with chrome outside the shadow root. */
.thread { display: flex; flex-direction: column; gap: 14px; }

.update { scroll-margin-top: 16px; }
.update .head { display: flex; align-items: flex-end; justify-content: space-between; gap: 8px; }
.update .head-right { display: flex; align-items: flex-end; gap: 14px; }
.update .jump { font-size: 13px; display: flex; gap: 10px; padding-bottom: 2px; }
.update .tools { font-size: 12px; display: flex; gap: 10px; padding-bottom: 2px; }
.update .tools button { all: unset; cursor: pointer; color: var(--text-muted); text-decoration: underline; }
.update .jump a { color: var(--text-muted); text-decoration: underline; }
/* Every shadow host. Nothing a quest stylesheet writes inside a body can paint outside this box. */
.body-host { display: block; contain: paint; overflow: clip; }
.update .body-host, .desk-preview .body-host { background: var(--bg-surface); border: 2px solid var(--fav-border); padding: 14px 16px; }
.via { font-size: 12px; color: var(--text-muted); padding: 2px 0 0 2px; }

/* Pictochat-style reader post: name tab in the favorite color, ruled notebook lines. */
.msg { scroll-margin-top: 16px; display: grid; grid-template-columns: 1fr; }
.msg .chrome { display: flex; align-items: flex-end; gap: 8px; flex-wrap: wrap; }
.stamp { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.update .head .stamp { margin-left: 8px; align-self: center; }
.msg .name {
  background: var(--fav-200);
  color: #232323;
  border: 2px solid var(--fav-border);
  border-bottom: 0;
  padding: 0 8px;
  font-size: 13px;
}
.msg .name.bot { background: var(--msgbox); color: var(--msgbox-text); border-color: var(--border); }
.msg .num { font-size: 12px; color: var(--text-muted); text-decoration: none; }
.msg .backlinks { font-size: 12px; color: var(--text-muted); display: flex; gap: 6px; align-items: baseline; flex-wrap: wrap; }
.msg .backlinks a { color: inherit; }
.msg .reply-count { cursor: pointer; list-style: none; padding: 0 6px; border: 1px solid var(--fav-border); background: var(--bg-elevated); color: var(--text); }
.msg .reply-count::-webkit-details-marker { display: none; }
.msg .backlinks[open] .reply-count { background: var(--fav-main); color: #fff; }
.msg .backlinks:not([open]) .reply-links { display: none; }
/* The start of the message a reply answers, as a strip on top of the reply's box. */
.msg .reply-quote {
  display: block; font-size: 13px; color: var(--text-muted); text-decoration: none; padding: 3px 12px;
  background: var(--bg-elevated); border: 2px solid var(--fav-border); border-bottom: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.msg .reply-quote:hover, .msg .reply-quote:focus-visible { color: var(--text); text-decoration: underline; }
.msg .tools { margin-left: auto; font-size: 12px; display: flex; gap: 10px; }
.mod-menu { position: relative; }
.mod-menu-items { position: absolute; right: 0; top: 100%; z-index: 20; display: grid; min-width: 150px; padding: 4px 0;
  background: var(--bg-surface); border: 2px solid var(--fav-border); box-shadow: 2px 2px 0 var(--border); }
.msg .tools .mod-menu-items button { padding: 6px 12px; text-decoration: none; color: var(--text); white-space: nowrap; }
.msg .tools .mod-menu-items button:hover, .msg .tools .mod-menu-items button:focus-visible { background: var(--bg-elevated); }
.msg .tools button { all: unset; cursor: pointer; color: var(--text-muted); text-decoration: underline; }
.msg .flag { font-size: 12px; color: var(--warning); }
.msg .body-host {
  background-color: var(--bg-surface);
  background-image: repeating-linear-gradient(transparent 0 25px, var(--rule) 25px 26px);
  background-position: 0 9px;
  border: 2px solid var(--fav-border);
  padding: 8px 12px;
}
.msg .roll { font-size: 13px; padding: 4px 0 0; }
.msg[data-held="true"] .body-host, .msg[data-hidden="true"] .body-host { border-style: dashed; }

/* Polls: DS selection cards. Strip on top, tally and status in the body, brackets on your vote. */
.poll { padding-left: var(--indent); }
.poll .cards { display: grid; gap: 10px; margin: 10px 0 0; }
.poll .group + .group { margin-top: 14px; }
.poll .option > .group { margin: 8px 0 4px var(--indent); }
.group-head { font-size: 13px; color: var(--text-muted); margin-top: 10px; }
.group-head .label { color: var(--text); }
.group.locked > .cards .card, .group.locked > .writein { opacity: 0.55; }
.group.locked > .cards .card:hover { opacity: 0.8; }
.poll[data-open="false"] .group.locked > .cards .card { opacity: 1; }
.card { background: var(--bg-surface); border: 2px solid var(--fav-border); padding: 0; text-align: left; font: inherit; color: inherit; width: 100%; cursor: pointer; }
.card[disabled] { cursor: default; }
.card .strip { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; background: linear-gradient(var(--fav-200), var(--fav-300)); color: #232323; padding: 3px 10px; font-size: 15px; }
.card .detail { display: block; padding: 4px 10px 6px; font-size: 13px; color: var(--text-muted); }
.card .detail:empty { display: none; }
.card-reading { color: var(--fav-border); }
/* Struck strips use a pair the contrast test checks in every theme, so struck text stays readable. */
.card.struck .strip { text-decoration: line-through; background: var(--bg-surface); color: var(--text-muted); }
.card.winner .strip { background: linear-gradient(var(--fav-400), var(--fav-main)); color: #fff; }
.poll .meta { font-size: 13px; color: var(--text-muted); margin-top: 8px; }
.poll-note { font-size: 13px; color: var(--error); margin: 6px 0 0; }
.poll .writein { display: flex; gap: 8px; margin-top: 10px; }
.poll .writein input { flex: 1; min-width: 0; font: inherit; padding: 4px 8px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); }
/* A posts box: readers' posts as a plain list, each roll marked by a bar on its left. */
.poll.entries .cards { gap: 0; border-top: 1px solid var(--border); }
.card.entry { cursor: default; border: 0; border-bottom: 1px solid var(--border); background: none; padding: 8px 2px; }
.card.entry .entry-who { display: block; font-size: 12px; color: var(--text-muted); }
.card.entry .entry-text { margin: 2px 0 0; overflow-wrap: anywhere; }
.card.entry .entry-roll { margin: 6px 0 0; padding: 1px 8px; border-left: 3px solid var(--fav-main); font-size: 14px; }
.card.entry .roll-label { color: var(--text-muted); }
.card.entry.struck .entry-text, .card.entry.struck .entry-roll { text-decoration: line-through; color: var(--text-muted); }
.card.entry .detail { padding: 4px 0 0; }
.poll .entry-form { flex-direction: column; }
.poll .entry-form textarea { font: inherit; padding: 4px 8px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); resize: vertical; }
.entry-actions { display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }

/* Alert: black box, orange border. System notices in the thread. */
.alert { background: var(--msgbox); color: var(--msgbox-text); border: 3px solid #e36300; border-radius: 6px; padding: 8px 12px; font-size: 14px; }
.notice { text-align: center; font-size: 13px; color: var(--text-muted); }
.place-note { margin: 0 0 10px; }

/* Bottom frame bar with the composer and the Cancel/Confirm buttons set into it. */
.bottombar { position: fixed; left: 0; right: 0; bottom: 0; border-top: 2px solid var(--fav-border); border-bottom: 0; padding: 8px 16px; }
/* Below the docking width an open QM desk takes much of the bar, so the bar drops the coloured fill for the page's own ground. */
@media (max-width: 1199px) {
  .bottombar:has(#desk:not([hidden])) { background: var(--bg); color: var(--text); text-shadow: none; border-top: 2px solid var(--fav-main); }
  body:not([data-desk-page]):has(#desk:not([hidden])) main { padding-bottom: calc(70vh + 110px); }
}
@media (max-width: 640px) {
  .desk { max-height: 55vh; }
  body:not([data-desk-page]):has(#desk:not([hidden])) main { padding-bottom: calc(55vh + 110px); }
}
.composer { max-width: 828px; margin: 0 auto; display: flex; gap: 8px; align-items: flex-end; }
.composer textarea { flex: 1; min-width: 0; min-height: 2.6em; max-height: 40vh; field-sizing: content; resize: none; overflow-y: auto; font: 15px/1.4 system-ui, sans-serif; padding: 8px 10px; border: 2px solid var(--fav-border); background: var(--bg-input); color: var(--text); }
.composer .status { font-size: 12px; color: #fff; min-height: 1em; }
.composer-wrap { max-width: 828px; margin: 0 auto; }
/* A narrow bar, such as chat's column beside a docked desk, puts the buttons under the box so the box keeps its width. */
.composer { container: composer / inline-size; flex-wrap: wrap; justify-content: flex-end; }
.composer textarea { flex-basis: 0; }
@container composer (max-width: 460px) { .composer textarea { flex-basis: 100%; } }

/* The QM desk opens above the composer, inside the bottom bar. */
.desk { max-width: 860px; margin: 0 auto 8px; max-height: 70vh; overflow-y: auto; color: var(--text); text-shadow: none; }
.desk-tabs { display: flex; gap: 4px; align-items: flex-end; }
.desk-tabs .tab { cursor: pointer; font: inherit; font-size: 13px; }
/* The tabs, this link and the chat row sit on the coloured bar, so each carries its own surface. */
.desk-settings { margin-left: auto; font-size: 13px; background: var(--bg-surface); color: var(--text); border: 2px solid var(--border); border-bottom: 0; padding: 1px 8px; }
.desk-pane { display: grid; gap: 10px; }
.desk textarea { width: 100%; box-sizing: border-box; resize: vertical; font: 15px/1.4 system-ui, sans-serif; padding: 8px 10px; border: 2px solid var(--fav-border); background: var(--bg-input); color: var(--text); }
#desk-text { font: 15px/1.45 system-ui, sans-serif; min-height: 12em; max-height: 75vh; field-sizing: content; }
.desk-split { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.editor-toolbar { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 4px; }
.editor-toolbar .tool { font: inherit; font-size: 13px; min-width: 30px; min-height: 28px; padding: 2px 8px; cursor: pointer;
  color: var(--text); background: var(--bg-elevated); border: 2px solid var(--border); }
.editor-toolbar .tool:hover, .editor-toolbar .tool:focus-visible { border-color: var(--fav-border); }
.editor-toolbar .tool-gap { flex: 0 0 6px; }
.editor-toolbar .tool { display: inline-grid; place-items: center; }
.editor-toolbar .tool[data-tool] { min-width: 28px; padding: 2px 4px; }
.editor-toolbar .tool .icon { display: block; }
.editor-toolbar .tool[aria-expanded="true"] { border-color: var(--fav-border); background: var(--fav-main); color: #fff; }
.editor-help { margin: 0 0 6px; padding: 6px 10px; font-size: 13px; color: var(--text); text-shadow: none; }
.editor-help .ref-table { margin: 0 0 6px; }
.editor-help p { margin: 0; }
.editor-pop { display: grid; gap: 6px; margin: 0 0 6px; padding: 8px 10px; font-size: 13px; color: var(--text); text-shadow: none; }
.editor-pop-row { display: grid; grid-template-columns: 9em 1fr; align-items: center; gap: 8px; }
.editor-pop-row input { font: inherit; padding: 4px 6px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); min-width: 0; }
.editor-pop .form-actions { margin: 0; }
.table-pick { justify-items: start; }
.table-grid { display: grid; grid-template-columns: repeat(8, 16px); gap: 2px; }
.table-cell { all: unset; width: 16px; height: 16px; border: 1px solid var(--border); background: var(--bg-input); cursor: pointer; }
.table-cell.on { background: var(--fav-main); border-color: var(--fav-border); }
.table-cell:focus-visible { outline: 2px solid var(--fav-border); }
.table-size { margin: 0; font-size: 13px; color: var(--text-muted); }
.editor-swatches { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
.editor-swatches input[type="color"] { width: 32px; height: 24px; padding: 0; border: 2px solid var(--border); background: none; }
.editor-swatches .swatch { width: 22px; height: 22px; border: 2px solid var(--border); cursor: pointer; padding: 0; }
.editor-preview { border: 2px dashed var(--border); padding: 4px 12px; margin: 0 0 6px; max-height: 40vh; overflow-y: auto; color: var(--text); text-shadow: none; background: var(--bg-surface); }
.chat-editor { padding-bottom: 0; }
.chat-editor .editor-toolbar { margin-bottom: 4px; }
@media (max-width: 640px) { .editor-pop-row { grid-template-columns: 1fr; gap: 2px; } }
.desk-preview { min-width: 0; }
.desk-preview .poll { padding-left: 0; }
.slate-errors { margin: 0 0 8px; padding-left: 18px; font-size: 13px; color: var(--error); }
.slate-help { font-size: 13px; color: var(--text-muted); margin-top: 6px; }
.slate-help summary { cursor: pointer; }
.slate-help ul { margin: 4px 0 0; padding-left: 18px; }
.slate-help p { margin: 4px 0; }
.command-list { margin: 4px 0 0; display: grid; gap: 2px; }
.command-list dt { margin-top: 6px; color: var(--text); font-weight: 600; }
.command-list dd { margin: 0 0 0 12px; }
.command-list .linklike { font: 12px/1.4 ui-monospace, monospace; color: var(--text); }
.command-list kbd { font: 12px ui-monospace, monospace; padding: 0 4px; border: 1px solid var(--border); border-radius: 2px; }
.compose-summary { margin: 0 0 8px; padding-left: 18px; font-size: 13px; color: var(--text-muted); }
.desk-chat-row { margin: 0 0 6px; font-size: 13px; color: var(--text-muted); background: var(--bg-surface); border: 2px solid var(--border); padding: 3px 10px; }
.desk-chat-row .linklike { color: var(--text); }
.chat-note { margin: 0 auto 4px; max-width: 860px; font-size: 13px; color: #fff; text-shadow: none; }
.desk-when { font-size: 13px; display: flex; align-items: center; gap: 6px; }
.desk-when input, .desk-when select { font: inherit; padding: 1px 4px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); }
.desk-when select { max-width: 16em; }
.desk-actions { flex-wrap: wrap; }
.draft-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.draft-head { font-size: 13px; color: var(--text-muted); margin-bottom: 4px; }
.draft-card { max-height: 14em; overflow-y: auto; border: 2px dashed var(--border); padding: 4px; }
.draft-card .update { pointer-events: none; }
.draft-actions { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 12px; margin-top: 4px; }
.draft-actions .linklike { color: var(--text-muted); }
.draft-when { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; }
.draft-when input { font: inherit; padding: 1px 4px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); }
.desk-editing { margin: 0; font-size: 13px; color: var(--warning); }
.desk-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; }
.desk-actions .desk-status { margin-right: auto; }
.desk-actions .desk-when { flex-basis: 100%; text-align: right; }
.desk-status { font-size: 13px; color: var(--text-muted); }
.desk-status.error { color: var(--error); }
@media (max-width: 640px) { .desk-split { grid-template-columns: 1fr; } }

.desk-grip { display: none; }

/* Docked desk. From 1200px an open desk leaves the bottom bar for a column on the left, where the eye starts, from under the top bar
   to the bottom of the screen. The thread, and the bar with the reader composer, keep the rest of the width. */
@media (min-width: 1200px) {
  body:not([data-desk-page]):has(#desk:not([hidden])) {
    --desk-w: min(var(--desk-w-pick, clamp(420px, 38vw, 600px)), calc(100vw - var(--chat-w, 0px) - 440px));
  }
  body:not([data-desk-page]):has(#desk:not([hidden])) main {
    width: calc(100% - var(--desk-w));
    margin-left: calc(var(--desk-w) + max(0px, calc((100% - var(--desk-w) - 860px) / 2)));
    margin-right: auto;
  }
  body:not([data-desk-page]):has(#desk:not([hidden])) .bottombar { left: var(--desk-w); }
  body:not([data-desk-page]) .desk:not([hidden]) {
    position: fixed; top: var(--topbar-h); left: 0; bottom: 0; width: var(--desk-w);
    max-width: none; max-height: none; margin: 0; padding: 12px 16px;
    background: var(--bg); border-right: 2px solid var(--fav-main);
  }
  body:not([data-desk-page]) .desk .desk-split { grid-template-columns: 1fr; }
  .desk-grip { display: block; position: fixed; top: var(--topbar-h); bottom: 0; left: calc(var(--desk-w) - 4px); width: 8px; cursor: col-resize; z-index: 6; touch-action: none; }
  .desk-grip:hover, .desk-grip:focus-visible, .desk-resizing .desk-grip { background: var(--fav-main); outline: none; }
  .desk-resizing { user-select: none; cursor: col-resize; }
}

/* QM controls on each poll, added by desk.js. Option tools show only while managing. */
.poll-tools { display: flex; gap: 12px; font-size: 12px; margin-top: 8px; }
.poll-tools button, .opt-tools button { all: unset; cursor: pointer; color: var(--text-muted); text-decoration: underline; }
.opt-tools { display: none; gap: 12px; font-size: 12px; padding: 2px 0 0 2px; }
.poll.managing .opt-tools { display: flex; }

/* Account forms */
.linklike { all: unset; cursor: pointer; text-decoration: underline; }
.topbar .linklike { color: inherit; }
.form { display: grid; gap: 8px; max-width: 460px; margin: 0 auto 16px; }
.form label:not(.choice):not(.swatch):not(.check) { font-size: 14px; }
.form input:not([type="radio"]):not([type="checkbox"]) { font: inherit; padding: 6px 8px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); width: 100%; box-sizing: border-box; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 4px; }
.form-status { font-size: 13px; color: var(--text-muted); }
.form-status.error { color: var(--error); }
.form-note { margin: 0; font-size: 13px; color: var(--text-muted); }
.optional-tag { color: var(--text-muted); }
.form .section-title { margin: 6px 0 0; }
.choices { border: 0; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.choices legend { font-size: 14px; padding: 0; margin-bottom: 4px; width: 100%; }
.choice { display: flex; align-items: center; gap: 6px; font-size: 14px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.swatch { display: grid; justify-items: center; gap: 2px; font-size: 12px; cursor: pointer; position: relative; padding: 4px; }
.swatch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.swatch .chip { width: 36px; height: 36px; border: 2px solid var(--fav-border); background: linear-gradient(var(--fav-300), var(--fav-main)); }
.swatch:has(input:checked) { outline: 2px dotted var(--fav-border); outline-offset: 1px; }
.swatch:has(input:focus-visible) { outline: 3px solid var(--text); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.form.wide { max-width: 640px; }
.age-note { margin: 28px 0 0; text-align: center; font-size: 12px; color: var(--text-muted); }
.form .form { max-width: none; margin: 0; padding: 0; border: 0; background: none; }
.form textarea, .form select { font: inherit; padding: 6px 8px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); width: 100%; box-sizing: border-box; }
.form select { width: auto; justify-self: start; }
.chapter-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.chapter-list li { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.chapter-list input { flex: 1; min-width: 0; }
.chapter-list .kind { color: var(--text-muted); min-width: 4.5em; text-align: right; }
.chapter-list .form-status:empty { display: none; }
.chapter-add { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.chapter-add input { flex: 1; min-width: 10em; }
.grant-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.grant-list li { display: flex; flex-wrap: wrap; gap: 4px 12px; align-items: baseline; font-size: 14px; }
.grant-list .scopes { color: var(--text-muted); font-size: 13px; flex: 1; min-width: 12em; }
.form textarea.code { font: 13px/1.5 ui-monospace, monospace; tab-size: 2; white-space: pre; overflow-x: auto; }
.form h3 { font-size: 14px; font-weight: normal; margin: 10px 0 0; }
.style-removed ul { margin: 4px 0 0; padding-left: 1.2em; font-size: 13px; display: grid; gap: 4px; }
.style-removed code { overflow-wrap: anywhere; background: var(--bg-input); padding: 0 3px; }
.style-removed .px { color: var(--warning); }
.style-preview { display: grid; gap: 12px; }
.style-revisions { margin: 0; padding-left: 1.2em; font-size: 13px; display: grid; gap: 4px; }
.style-revisions .px { color: var(--text-muted); }
.plain-toggle { margin: 0; }

/* Catalog */
.catalog { display: grid; gap: 14px; }
@media (min-width: 700px) { .catalog { grid-template-columns: 1fr 1fr; align-items: start; } }
/* The icon sits in the card's top right corner and the card's text wraps around it. */
/* The title link covers the whole card; tag links sit above it, so a tag click searches the tag. */
.quest-card { display: flow-root; position: relative; }
.quest-card .card-link { color: inherit; text-decoration: none; }
.quest-card .card-link::after { content: ""; position: absolute; inset: 0; }
/* The card's own link covers the whole card, so every other link in it sits above that cover or can't be clicked. */
.quest-card a:not(.card-link) { position: relative; z-index: 1; }
.quest-card .tags a { z-index: 2; }
.quest-card .card-link:focus-visible { outline: none; }
.quest-card:has(.card-link:focus-visible) { outline: 2px solid var(--fav-border); outline-offset: 2px; }
.quest-card .tags a.tag { text-decoration: none; color: inherit; }
.quest-card .card-by { margin: 2px 0 6px; font-size: 13px; color: var(--text-muted); }
.quest-card .card-by a { color: inherit; }
.quest-card .tags a.tag:hover { border-color: var(--fav-border); }
.quest-card img.tile { object-fit: cover; padding: 0; background: var(--bg-elevated); }
.quest-card .tile { float: right; box-sizing: border-box; width: 96px; height: 96px; margin: 0 0 8px 12px; border: 2px solid var(--fav-border); background: repeating-conic-gradient(var(--fav-400) 0 25%, var(--fav-500) 0 50%) 0 0 / 4px 4px; display: grid; place-items: center; color: #fff; font-size: 38px; }
@media (max-width: 640px) { .quest-card .tile { width: 72px; height: 72px; font-size: 28px; } }
.quest-card h2 { margin: 0; font-size: 18px; }
.quest-card p { margin: 2px 0 0; font-size: 14px; color: var(--text-muted); }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag { border-color: var(--border); background: var(--bg-elevated); color: var(--text); }

/* Table of contents */
.toc { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.toc a { display: block; text-decoration: none; color: inherit; }
.toc > li > a > .px { color: var(--link); text-decoration: underline; text-underline-offset: 3px; }
.toc .appendix { color: var(--text-muted); }

.pager { display: flex; justify-content: space-between; gap: 10px; margin: 16px 0; font-size: 14px; }

@media (max-width: 520px) {
  :root { --indent: 14px; }
  main { padding: 12px 12px 140px; }
  .topbar .optional { display: none; }
  /* A phone's bar stays one line: cells close up, nothing in it wraps, and what gives way is the quest's title,
     which the breadcrumb under the bar also shows, and then the reader's name. */
  .topbar { overflow-x: clip; }
  .topbar > * { padding: 0 6px; white-space: nowrap; }
  .topbar .grow { padding: 0; }
  .brand { font-size: 15px; }
  .topbar .wide { display: none; }
  .topbar .jump-cell { gap: 4px; }
  .topbar .me { min-width: 2.5em; flex: 0 1 auto; }
  .topbar .me a { min-width: 0; }
  .topbar .me a > span { overflow: hidden; text-overflow: ellipsis; }
}

/* Touch screens: every control a thumb hits is at least about 40px tall, without changing the desktop layout. */
@media (pointer: coarse) {
  .topbar .cell > a, .topbar .cell > .linklike, .brand { display: flex; align-items: center; align-self: stretch; min-height: 44px; }
  .stack { padding: 6px 10px; }
  .stack a { display: inline-block; padding: 8px 0; }
  .msg .tools, .update .tools { gap: 4px; }
  .msg .tools button, .update .tools button, .update .jump a, .msg .num, .msg .backlinks a,
  .poll-tools button, .opt-tools button { display: inline-block; padding: 10px 6px; }
  select { min-height: 40px; }
  .toc a { padding: 6px 0; }
  .site-links a, .pager a { display: inline-block; padding: 10px 4px; }
  .choice, .check { min-height: 40px; }
  input[type="radio"], input[type="checkbox"] { width: 20px; height: 20px; }
  .editor-toolbar .tool, .desk-tabs .tab, .desk-settings { min-height: 40px; min-width: 40px; }
  .linklike { padding: 8px 2px; }
  /* In the top bar the cell already gives the height; padding on top of it made the whole bar taller. */
  .topbar .linklike { padding-top: 0; padding-bottom: 0; }
  .topbar .jump-cell button { min-width: 26px; text-align: center; }
}

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

/* Small page pieces */
.search { display: flex; gap: 8px; margin-bottom: 16px; }
.sort-links { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 14px; margin: -6px 0 14px; color: var(--text-muted); }
/* Sorting on the left, what the list includes on the right; on phones the toggles drop under the sort links. */
.list-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; margin: -6px 0 14px; }
.list-controls .sort-links { margin: 0; }
.list-pick { display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; font-size: 14px; color: var(--text-muted); }
.list-pick select { font: inherit; padding: 1px 4px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); }
.rating-toggles { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; font-size: 14px; margin: 0 0 0 auto; color: var(--text-muted); }
@media (max-width: 640px) { .rating-toggles { margin-left: 0; } }
.rating-toggle { display: inline-flex; align-items: center; gap: 6px; font: inherit; cursor: pointer; padding: 3px 10px 3px 6px; border: 2px solid var(--border); background: var(--bg-elevated); color: var(--text); }
.rating-toggle .box { display: inline-grid; place-items: center; width: 14px; height: 14px; border: 2px solid var(--fav-border); background: var(--bg-input); font-size: 12px; line-height: 1; }
.rating-toggle[aria-pressed="true"] { border-color: var(--fav-border); background: var(--fav-main); color: #fff; }
.rating-toggle[aria-pressed="true"] .box { color: var(--text); }
.notice.rating-hint { text-align: left; margin: -8px 0 14px; font-size: 13px; }
.sort-links strong { color: var(--text); font-weight: normal; text-decoration: underline 2px; text-underline-offset: 4px; }
.catalog-head { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; }
.catalog-head .stack { flex: 1; margin: 0; }
.card-status { font-size: 13px; color: var(--text-muted); }
/* A miss lands on the card's cover and opens the title page, so the word is padded out without moving anything. */
.card-jump { display: inline-block; padding: 8px 6px; margin: -8px -6px; }
.search input { flex: 1; min-width: 0; font: inherit; padding: 4px 8px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); }
.meta-line { font-size: 14px; color: var(--text-muted); }
.section-title { font-size: 16px; font-weight: normal; margin: 18px 0 8px; }
.preview { position: absolute; z-index: 20; max-width: min(480px, calc(100vw - 32px)); box-shadow: 4px 4px 0 var(--shadow-key); pointer-events: none; }
.fresh { animation: fresh 1.2s ease-out; }
@keyframes fresh { from { outline: 3px solid var(--fav-400); outline-offset: 2px; } to { outline: 3px solid transparent; outline-offset: 2px; } }
.turnstile-slot { display: flex; justify-content: center; }

/* Reports: the readers' dialog, and the list on the QM desk and the site moderators' page. */
.report-dialog { max-width: min(520px, calc(100vw - 32px)); color: var(--text); padding: 14px 16px; }
.report-dialog::backdrop { background: rgb(0 0 0 / 0.45); }
.report-dialog h2 { margin: 0 0 8px; font-size: 16px; }
.report-dialog fieldset { border: 0; padding: 0; margin: 0 0 10px; display: grid; gap: 6px; }
.report-dialog legend { font-size: 13px; color: var(--text-muted); padding: 0; margin-bottom: 4px; }
.report-reason { display: flex; gap: 8px; align-items: flex-start; font-size: 14px; cursor: pointer; }
.report-reason input { margin-top: 3px; }
.report-reason .hint { display: block; font-size: 12px; color: var(--text-muted); }
.report-reason.disabled { opacity: 0.5; cursor: default; }
.report-text { display: grid; gap: 4px; font-size: 13px; }
.report-text textarea { font: 14px/1.4 system-ui, sans-serif; padding: 6px 8px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); resize: vertical; }
.report-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }
.report-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.report { border-left: 3px solid var(--fav-main); padding-left: 10px; }
.report-head, .report-meta { font-size: 13px; color: var(--text-muted); }
.report-head strong { color: var(--text); }
.report-said { margin: 4px 0; font-size: 14px; }
.report-evidence { font-size: 13px; color: var(--text-muted); }
.report-evidence pre { margin: 2px 0; white-space: pre-wrap; word-break: break-word; font: 13px/1.4 ui-monospace, monospace; color: var(--text); background: var(--bg-elevated); border: 1px dashed var(--border); padding: 4px 6px; max-height: 12em; overflow-y: auto; }
.report-tools { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; font-size: 12px; margin-top: 4px; }
.report-tools input { font: inherit; padding: 1px 4px; border: 2px solid var(--border); background: var(--bg-input); color: var(--text); min-width: 12em; flex: 1; }
.report-tools .linklike { color: var(--text-muted); }
.report-filter { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; }
.desk-hint { margin: 0; font-size: 12px; color: var(--text-muted); }

/* Importing from fiction.live */
.import-page { display: grid; gap: 12px; }
.akun-list { margin: 0; padding-left: 20px; }
.akun-code { display: grid; gap: 6px; border-color: var(--fav-main); }
.akun-code p { margin: 0; }
.akun-imports { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.akun-imports li { display: grid; gap: 4px; }
.akun-imports .error { color: var(--error); }
.akun-code-text code { font-size: 20px; letter-spacing: 0.08em; padding: 2px 8px; background: var(--bg-elevated); border: 2px solid var(--border); }

/* Reviewing a /qst/ thread */
.qst-posts { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.qst-post { display: grid; gap: 4px; padding: 8px 10px; border: 2px solid var(--border); background: var(--bg-elevated); }
.qst-post.is-update { border-color: var(--fav-main); }
.qst-posts[data-show="some"] .qst-post:not(.is-update):not(.is-flagged) { display: none; }
.qst-post p { margin: 0; }
.qst-tick { justify-self: start; font-size: 13px; }
.qst-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
.qst-trip { color: var(--text-muted); }
.qst-badge { font-size: 11px; padding: 0 4px; border: 1px solid var(--fav-main); }
.qst-reasons { display: flex; flex-wrap: wrap; gap: 4px; font-size: 11px; }
.qst-reasons span { padding: 0 4px; border: 1px dashed var(--border); color: var(--text-muted); }
.qst-text { white-space: pre-wrap; overflow-wrap: anywhere; }

/* Chat view. The story keeps the page; one chat runs in a column on the right, from under the pinned top bar to
   the bottom of the screen, with the composer at its foot. The desk still docks on the left from 1200px. */
body[data-view="chat"] { --chat-w: clamp(320px, 32vw, 460px); --switch-h: 44px; }
.chat-log { display: flex; flex-direction: column; gap: 10px; padding: 8px 12px; }
.chat-pane .bottombar { position: static; padding: 8px 12px; }
.chat-pane .composer, .chat-pane .composer-wrap, .chat-pane .chat-note { max-width: none; }
.chat-divider { display: flex; align-items: center; gap: 8px; margin: 6px 0 0; font-size: 12px; color: var(--text-muted); }
.chat-divider::before, .chat-divider::after { content: ""; flex: 1; border-top: 2px dotted var(--border); }
.chat-divider a { color: inherit; }
.chat-line.writein { margin: 0; padding: 2px 8px; font-size: 13px; color: var(--text-muted); border-left: 3px solid var(--fav-main); }
.chat-line.writein .name { color: var(--text); }
.chat-pager { display: block; padding: 6px; font-size: 13px; text-align: center; }
.pane-switch { display: none; }
@media (min-width: 761px) {
  body[data-view="chat"] main {
    width: calc(100% - var(--chat-w));
    margin-left: max(0px, calc((100% - var(--chat-w) - 860px) / 2));
    margin-right: var(--chat-w);
    padding-bottom: 32px;
  }
  .chat-pane {
    position: fixed; top: var(--topbar-h); right: 0; bottom: 0; width: var(--chat-w); z-index: 5;
    display: flex; flex-direction: column; background: var(--bg); border-left: 2px solid var(--fav-main);
  }
  .chat-pane .chat-log { flex: 1; min-height: 0; overflow-y: auto; }
}
@media (min-width: 1200px) {
  /* With the desk docked too, the chat narrows so the story keeps a readable width between them. */
  body[data-view="chat"]:not([data-desk-page]):has(#desk:not([hidden])) { --chat-w: clamp(280px, 24vw, 400px); }
  body[data-view="chat"]:not([data-desk-page]):has(#desk:not([hidden])) main {
    width: calc(100% - var(--desk-w) - var(--chat-w));
    margin-left: var(--desk-w);
    margin-right: var(--chat-w);
  }
}
@media (max-width: 1199px) {
  body[data-view="chat"]:not([data-desk-page]):has(#desk:not([hidden])) main { padding-bottom: 32px; }
}
/* The desk's own page: the desk takes the story's place, at full width, beside chat's strip, which can be put away.
   The preview stays in view beside the box while a long update scrolls. */
body[data-desk-page] { --chat-w: clamp(280px, 24vw, 380px); }
body[data-desk-page] main { max-width: none; }
body[data-desk-page] .desk-grip { display: none; }
body[data-desk-page] .desk { max-width: none; max-height: none; margin: 0; overflow: visible; }
body[data-desk-page] #desk-text { min-height: 55vh; }
body[data-desk-page] .desk-preview { position: sticky; top: calc(var(--topbar-h) + 8px); max-height: calc(100vh - var(--topbar-h) - 16px); overflow-y: auto; }
.desk-page-head { display: flex; gap: 12px; align-items: baseline; margin: 0 0 10px; font-size: 13px; }
.desk-page-where { margin-right: auto; color: var(--text-muted); }
.desk-tabs .desk-full { margin-left: 4px; }
@media (min-width: 761px) {
  body[data-desk-page] main { margin-left: 0; }
  body[data-desk-page][data-chat-off] main { width: 100%; margin-right: 0; }
  body[data-desk-page][data-chat-off] .chat-pane { display: none; }
}
@media (max-width: 1000px) { body[data-desk-page] .desk-split { grid-template-columns: 1fr; } }
@media (max-width: 760px) {
  body[data-desk-page] [data-chat-strip] { display: none; }
  body[data-desk-page] .desk-preview { position: static; max-height: none; }
}
/* Phones: a Story / Chat switch under the top bar; the chat fills the screen when chosen. Without the script both
   show, the chat after the story. */
@media (max-width: 760px) {
  body[data-view="chat"] .pane-switch {
    display: flex; position: sticky; top: var(--topbar-h); z-index: 9; height: var(--switch-h); margin: 0 -16px 12px;
    background: var(--bg); border-bottom: 2px solid var(--fav-main);
  }
  .pane-switch button { flex: 1; font: inherit; font-size: 15px; cursor: pointer; background: none; color: var(--text); border: 0; }
  .pane-switch button[aria-pressed="true"] { background: var(--fav-main); color: #fff; }
  .pane-switch .unread { display: inline-block; min-width: 1.4em; padding: 0 4px; margin-left: 4px; font-size: 12px; background: var(--live); color: #fff; }
  body[data-pane="story"] .chat-pane { display: none; }
  body[data-pane="chat"] main > :not(.pane-switch) { display: none; }
  /* With the chat up nothing scrolls the page, so the switch is put where sticking would have left it. */
  body[data-pane="chat"] .pane-switch { position: fixed; top: var(--topbar-h); left: 0; right: 0; margin: 0; }
  body[data-pane="chat"] .chat-pane {
    position: fixed; top: calc(var(--topbar-h) + var(--switch-h)); left: 0; right: 0; bottom: 0; z-index: 5;
    display: flex; flex-direction: column; background: var(--bg);
  }
  body[data-pane="chat"] .chat-pane .chat-log { flex: 1; min-height: 0; overflow-y: auto; }
}

/* A tag's definition, opened by holding the tag on a touch screen. */
.tag[title], .tag-box[title] { -webkit-touch-callout: none; }
.tag-tip {
  position: absolute; z-index: 30; box-sizing: border-box; display: grid; gap: 2px; padding: 6px 10px;
  font-size: 13px; line-height: 1.4; color: var(--text); background: var(--bg-surface);
  border: 2px solid var(--fav-border); box-shadow: 2px 2px 0 var(--fav-border);
}
.tag-tip strong { font-weight: normal; }

/* {left}, {center}, {right} in posts. */
.align-left { text-align: left; }
.align-center { text-align: center; }
.align-right { text-align: right; }
