/* BKun styles. Kept out of index.html so the Content-Security-Policy needs no inline scripts. */
:root {
  --bg: #f7f6f3; --surface: #ffffff; --text: #1f2328; --muted: #6a737d;
  --border: #e1e4e8; --accent: #2f6feb; --accent-text: #ffffff; --live: #d1242f; --star: #b7791f;
  --header-h: 52px;
  --footer-h: 28px;
  color-scheme: light;
}
/* Dark follows the system unless the reader forced a theme (data-theme on <html>: theme.js, the header toggle). */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #111418; --surface: #1a1f25; --text: #e6e8eb; --muted: #8b949e;
    --border: #2d333b; --accent: #4c8dff; --accent-text: #0b0d10; --live: #ff6b6b; --star: #f2b705;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #111418; --surface: #1a1f25; --text: #e6e8eb; --muted: #8b949e;
  --border: #2d333b; --accent: #4c8dff; --accent-text: #0b0d10; --live: #ff6b6b; --star: #f2b705;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; font: 15px/1.5 system-ui, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: .85em; }

/* ---- header ---- */
header.top { position: relative; height: var(--header-h); display: flex; align-items: center; gap: 1rem; padding: 0 1rem; border-bottom: 1px solid var(--border); background: var(--surface); }
header.top h1 { font-size: 1.15rem; margin: 0; }
header.top h1 a { color: var(--text); }
#session { display: flex; align-items: center; gap: .6rem; flex-wrap: nowrap; white-space: nowrap; }

/* ---- three-column shell: stories | story | chat ---- */
.shell { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; height: calc(100% - var(--header-h) - var(--footer-h)); }
.rail { display: flex; flex-direction: column; width: 270px; min-height: 0; background: var(--surface); border-right: 1px solid var(--border); transition: width .15s ease; }
.rail.right { width: 330px; border-right: none; border-left: 1px solid var(--border); }
.rail-head { display: flex; align-items: center; gap: .5rem; padding: .6rem .75rem; border-bottom: 1px solid var(--border); }
.rail-head h2 { font-size: .95rem; margin: 0; flex: 1; white-space: nowrap; }
.rail.right .rail-head { flex-direction: row-reverse; }
.rail-body { flex: 1; min-height: 0; overflow-y: auto; padding: .75rem; }
.rail.collapsed { width: 44px; }
.rail.collapsed .rail-body, .rail.collapsed .rail-head h2 { display: none; }
.rail.collapsed .rail-head { border-bottom: none; justify-content: center; padding: .6rem 0; }
.collapse-btn { background: none; border: 1px solid var(--border); color: var(--muted); padding: .1rem .45rem; line-height: 1.2; }
.collapse-btn .icon { display: inline-block; transition: transform .15s ease; }
.rail.collapsed .collapse-btn .icon { transform: rotate(180deg); }
main.primary { min-width: 0; overflow-y: auto; padding: 1.25rem 1.5rem 3rem; container-type: inline-size; }
main.primary > #main { max-width: 900px; margin: 0 auto; }

@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; height: auto; }
  .rail, .rail.right, .rail.collapsed { width: auto; border: none; border-bottom: 1px solid var(--border); }
  .rail.right { order: 3; border-top: 1px solid var(--border); }
  .rail.collapsed .rail-head { justify-content: flex-start; padding: .6rem .75rem; }
  .rail.collapsed .rail-head h2 { display: block; }
  .rail.right .rail-head { flex-direction: row; }
  .rail-body { max-height: 60vh; }
  .collapse-btn .icon { transform: rotate(90deg); }
  .rail.collapsed .collapse-btn .icon { transform: rotate(-90deg); }
  main.primary { padding: 1rem 16px 2rem; }
}

/* ---- shared bits ---- */
.badge { font-size: .72em; border: 1px solid var(--border); border-radius: 999px; padding: 0 .45rem; color: var(--muted); white-space: nowrap; vertical-align: middle; }
.badge.live { color: #fff; background: var(--live); border-color: var(--live); font-weight: 700; letter-spacing: .04em; }
.live-dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; background: var(--live); margin-right: .45rem; animation: pulse 1.6s infinite; }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .live-dot { animation: none; } }
input, textarea, select, button { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .45rem .6rem; }
button { background: var(--accent); color: var(--accent-text); border-color: var(--accent); cursor: pointer; }
button.secondary { background: transparent; color: var(--accent); }
/* Links that look like buttons (navigation is done with real links so URLs work). */
a.button { display: inline-block; font: inherit; line-height: normal; background: var(--accent); color: var(--accent-text); border: 1px solid var(--accent); border-radius: 6px; padding: .45rem .6rem; }
a.button:hover { text-decoration: none; filter: brightness(1.08); }
a.button.secondary, header.top a.button { background: transparent; color: var(--accent); }
.user-link { color: inherit; text-decoration: none; border-bottom: 1px dotted currentColor; }
.user-link:hover { color: var(--accent); text-decoration: none; }
.chapter-list a.active { font-weight: 600; }
.register-form label { display: flex; flex-direction: column; gap: .25rem; }
.register-form .optional { font-weight: normal; }
.email-warning { display: none; margin: .35rem 0 0; padding: .45rem .6rem; border: 1px solid #d29922; border-radius: 6px; font-size: .85em; }
.email-warning strong { color: #d29922; }
/* Warn while the (optional) email field is empty. */
input[name=email]:placeholder-shown ~ .email-warning, .email-warning.shown { display: block; }
.profile h2 { margin-bottom: .2rem; }
button.small { font-size: .82em; padding: .2rem .6rem; }
button.link { background: none; border: none; color: var(--accent); padding: 0; font-size: .85em; }
.htmx-request button[type=submit] { opacity: .6; }
form.stack { display: flex; flex-direction: column; gap: .5rem; max-width: 520px; margin-top: 1rem; }
form.inline { display: flex; gap: .5rem; margin: .5rem 0 1rem; flex-wrap: wrap; }
form.inline input, form.inline select { flex: 1; min-width: 0; }
.notice { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .5rem .75rem; }
#flash:empty { display: none; }
#flash { max-width: 900px; margin: 0 auto 1rem; }
#flash .notice { border-color: #d29922; margin: 0; }

/* ---- story list ---- */
.story-list { list-style: none; padding: 0; margin: 0; }
.story-list li { padding: .45rem 0; border-bottom: 1px solid var(--border); }
.story-list li:last-child { border-bottom: none; }
.story-list span.muted { display: block; font-size: .82em; }

/* ---- front page ---- */
.hero { padding: 1.5rem 0 1rem; }
.hero h2 { font-size: 1.6rem; margin: 0 0 .25rem; }
.hero .actions { display: flex; gap: .5rem; margin-top: .75rem; }
.section-title { display: flex; align-items: center; margin: 1.5rem 0 .75rem; font-size: 1.05rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: .9rem; }
/* The title link stretches over the whole card; the author link sits above it. */
.card { position: relative; display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .9rem 1rem; color: var(--text); }
.card:hover { border-color: var(--accent); }
.card-link { color: var(--text); }
.card-link:hover { text-decoration: none; }
.card-link::after { content: ""; position: absolute; inset: 0; border-radius: 10px; }
/* The title link covers the whole card (::after above), so anything in the card with its own link or tooltip sits
   above that layer: otherwise it would get the story's link instead (a tag) or no hover at all (a tooltip). */
.card .user-link, .card .word-count, .card .rating-badge, .card a.tag { position: relative; z-index: 1; }
.card-title { font-weight: 600; font-size: 1.05rem; margin-bottom: .3rem; }
.card-summary { margin: 0 0 .5rem; color: var(--muted); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }

/* ---- story ---- */
.title-row { display: flex; align-items: center; gap: .6rem; flex-wrap: wrap; }
.title-row h2 { margin: 0; }
#story-header > p { margin: .35rem 0; }
.authors { margin: .5rem 0 1rem; }
.authors summary { cursor: pointer; font-weight: 600; }
.author-list { list-style: none; padding: 0; margin: .5rem 0; }
.author-list li { padding: .2rem 0; }
.story-body { display: grid; grid-template-columns: 220px minmax(0, 1fr); gap: 1.5rem; border-top: 1px solid var(--border); padding-top: 1rem; }
@container (max-width: 620px) { .story-body { grid-template-columns: 1fr; } }
.chapter-nav h3 { margin-top: 0; }
.chapter-list { padding-left: 1.2rem; margin: 0; }
.chapter-list li { margin-bottom: .45rem; }
.chapter-list span { display: block; font-size: .82em; }
#chapter-pane h3 { margin-top: 0; }
.post { border-left: 3px solid var(--border); padding: .25rem .75rem; margin: .75rem 0; }
.post-meta { font-size: .85em; color: var(--muted); }
.rich p, .rich h1, .rich h2, .rich h3, .rich h4, .rich ul, .rich ol, .rich pre, .rich blockquote { margin: .35rem 0; }
.rich img { max-width: 100%; height: auto; border-radius: 6px; }
.rich blockquote { border-left: 3px solid var(--accent); margin-left: 0; padding-left: .75rem; color: var(--muted); }
.rich pre { background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: .5rem .75rem; overflow-x: auto; }
.rich code { font-size: .9em; }
.rich ul.checklist { list-style: none; padding-left: 1.2rem; }
.rich li.checked::before { content: "☑ "; }
.rich li.unchecked::before { content: "☐ "; }

/* ---- editor (Quill snow theme, retinted) ---- */
.post-form { display: flex; flex-direction: column; gap: .5rem; margin-top: 1rem; }
.post-form button[type=submit] { align-self: flex-start; }
.post .post-actions { margin-left: .75rem; display: inline-flex; gap: .6rem; opacity: 0; transition: opacity .1s; }
.post:hover .post-actions, .post:focus-within .post-actions { opacity: 1; }
@media (hover: none) { .post .post-actions { opacity: 1; } }
button.link.danger { color: var(--live); }
.post.editing { border-left-color: var(--accent); }
.post.editing .post-form { margin-top: .4rem; }
.form-actions { display: flex; gap: .5rem; }
.tier-limits { max-width: 460px; margin-bottom: 1.5rem; }
.post .post-actions.always { opacity: 1; }
.post.history { border-left-color: var(--accent); }
.revisions { list-style: none; padding-left: 0; margin: .5rem 0 0; }
.revisions li { margin-bottom: .35rem; }
.revisions summary { cursor: pointer; font-size: .88em; }
.revisions .post-body { border-left: 2px solid var(--border); padding-left: .6rem; margin: .4rem 0; }
.revisions button { margin-bottom: .5rem; }
.deleted-posts { margin-top: 1.5rem; border-top: 1px solid var(--border); padding-top: .75rem; }
.deleted-posts summary { cursor: pointer; font-weight: 600; color: var(--muted); }
.deleted-post { border-left: 3px dashed var(--border); padding: .25rem .75rem; margin: .6rem 0; opacity: .85; }
.deleted-post .post-actions { opacity: 1; }
.deleted-post .excerpt { margin: .2rem 0; color: var(--muted); }
.deleted-stories { margin-top: 2rem; }

/* ---- revisions & diffs ---- */
.revision-actions { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .4rem; }
.compare-form { display: flex; align-items: center; gap: .4rem; flex-wrap: wrap; margin: .6rem 0; }
.compare-form select { padding: .15rem .35rem; }
.diff-slot:empty { display: none; }
.diff-result { border: 1px solid var(--border); border-radius: 6px; padding: .5rem .75rem; margin: .4rem 0 .6rem; background: var(--bg); }
.diff-heading { font-size: .85em; color: var(--muted); margin-bottom: .35rem; }
.diff-stat.added { color: #1a7f37; font-weight: 600; }
.diff-stat.removed { color: var(--live); font-weight: 600; }
.diff { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.diff ins { background: rgba(46, 160, 67, .22); color: inherit; text-decoration: none; border-radius: 2px; }
.diff del { background: rgba(248, 81, 73, .22); color: inherit; text-decoration: line-through; border-radius: 2px; }
.diff-field { margin-bottom: .4rem; }
.revision-snapshot { border-left: 2px solid var(--border); padding-left: .6rem; margin: .4rem 0; }
.revision-snapshot p { margin: .2rem 0; }

/* ---- story header ---- */
.story-actions { display: flex; gap: .9rem; margin: .2rem 0 .4rem; }
#story-header.history, #story-header.editing { border-left: 3px solid var(--accent); padding-left: .75rem; margin-bottom: 1rem; }
.danger-zone { border-top: 1px dashed var(--border); padding-top: .6rem; margin-top: .4rem; }
button.danger { background: transparent; color: var(--live); border-color: var(--live); }
.ql-toolbar.ql-snow, .ql-container.ql-snow { border-color: var(--border); }
.ql-toolbar.ql-snow { border-radius: 6px 6px 0 0; background: var(--surface); }
.ql-container.ql-snow { border-radius: 0 0 6px 6px; background: var(--bg); font: inherit; }
.ql-editor { min-height: 140px; max-height: 60vh; }
.ql-editor.ql-blank::before { color: var(--muted); font-style: normal; }
.ql-snow .ql-stroke { stroke: var(--text); }
.ql-snow .ql-fill { fill: var(--text); }
.ql-snow .ql-picker { color: var(--text); }
.ql-snow .ql-picker-options, .ql-snow .ql-tooltip { background: var(--surface); color: var(--text); border-color: var(--border); box-shadow: none; }
.ql-snow .ql-tooltip input[type=text] { background: var(--bg); color: var(--text); border-color: var(--border); }
.ql-snow.ql-toolbar button:hover .ql-stroke, .ql-snow.ql-toolbar button.ql-active .ql-stroke { stroke: var(--accent); }
.ql-snow.ql-toolbar button:hover .ql-fill, .ql-snow.ql-toolbar button.ql-active .ql-fill { fill: var(--accent); }
.ql-snow.ql-toolbar button.ql-active, .ql-snow .ql-picker-label.ql-active { color: var(--accent); }
.ql-editor img { max-width: 100%; }

/* ---- admin ---- */
.admin-search { width: 100%; max-width: 420px; margin: .5rem 0 1rem; }
.admin-table { width: 100%; border-collapse: collapse; }
.admin-table th, .admin-table td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table th { font-size: .82em; color: var(--muted); font-weight: 600; }
.admin-table td.actions { text-align: right; white-space: nowrap; }
.admin-table td.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.settings-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .75rem 1.25rem; align-items: end; margin-bottom: 1.5rem; }
.settings-form label { display: flex; flex-direction: column; gap: .25rem; font-size: .9em; }
.settings-form small { font-size: .8em; }
.settings-form button { justify-self: start; }
.badge.mod { color: var(--accent); border-color: var(--accent); }
.table-scroll { overflow-x: auto; }
@container (max-width: 760px) { .admin-table .email, .admin-table .posts { display: none; } }
@container (max-width: 600px) { .admin-table .uploads { display: none; } }
.badge.tier { cursor: help; }
.badge.tier[data-tier="fresh"] { color: #b08800; border-color: #b08800; }
.badge.tier[data-tier="established user"], .badge.tier[data-tier="venerable user"] { color: var(--text); }
.badge.tier[data-tier="trusted user"] { color: #1a7f37; border-color: #1a7f37; }

/* ---- chat ---- */
#chat-panel .rail-body { display: flex; flex-direction: column; padding: 0; }
.chat-body { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-body > p.muted { padding: .75rem; margin: 0; }
.chat-story { margin: 0; padding: .5rem .75rem; font-weight: 600; border-bottom: 1px solid var(--border); }
.messages { flex: 1; min-height: 200px; display: flex; flex-direction: column; overflow-y: auto; overflow-anchor: none; padding: .5rem .75rem; gap: .5rem; }
.msg { overflow-wrap: anywhere; }
.msg-meta { display: flex; gap: .5rem; align-items: baseline; font-size: .85em; }
.msg-meta .time { color: var(--muted); font-variant-numeric: tabular-nums; }
.chat-form { display: flex; gap: .4rem; padding: .6rem .75rem; border-top: 1px solid var(--border); }
.chat-form input { flex: 1; min-width: 0; }
/* Messages run oldest to newest; a short chat sits at the bottom, by the form. */
.messages > :first-child { margin-top: auto; }
.chat-log { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.chat-topic { display: flex; align-items: center; gap: .5rem; padding: .4rem .75rem; border-bottom: 1px solid var(--border); }
.chat-topic select { flex: 1; min-width: 0; }
.chat-topic[hidden] { display: none; }
.reader-count { float: right; font-weight: 400; font-size: .85em; color: var(--muted); font-variant-numeric: tabular-nums; }
.chat-pager { display: flex; flex-wrap: wrap; align-items: center; gap: .35rem; padding: .35rem .75rem; border-bottom: 1px solid var(--border); font-size: .85em; }
.chat-page-jump { display: flex; align-items: center; gap: .3rem; margin: 0; }
.chat-page-jump input { width: 4.5rem; }
/* Page controls under the admin page's users table and audit log. */
.list-pager { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; margin: .5rem 0 1rem; font-size: .9em; }
.list-page-jump { display: flex; align-items: center; gap: .3rem; margin: 0; }
.list-page-jump input { width: 5rem; }

/* ---- account, suspension, audit log ---- */
.badge.danger { color: var(--live); border-color: var(--live); }
.admin-table tr.suspended td:first-child { opacity: .7; }
details.suspend { display: inline-block; margin-left: .3rem; }
details.suspend > summary { list-style: none; cursor: pointer; display: inline-block; }
details.suspend > summary::-webkit-details-marker { display: none; }
details.suspend[open] form { margin: .4rem 0 0; }
summary.button.small.danger { font-size: .82em; padding: .2rem .6rem; border: 1px solid var(--live); color: var(--live); border-radius: 6px; }
label.checkbox { display: flex; align-items: center; gap: .4rem; }
.account-delete ul { margin: .2rem 0 .8rem; }
.audit-log td code { font-size: .85em; }
.audit-log td { vertical-align: top; }

/* ---- dialog ---- */
.dialog-backdrop { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, .45); }
.dialog-backdrop[hidden] { display: none; }
.dialog { width: min(460px, 100%); max-height: 100%; overflow: auto; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1rem 1.2rem; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.dialog h3 { margin-top: 0; overflow-wrap: anywhere; }
.report-categories { border: none; margin: 0; padding: 0; display: grid; gap: .25rem; }
.report-categories input { margin: 0; }

/* ---- reports ---- */
button.link.report-button { color: var(--muted); }
button.link.report-button:hover { color: var(--live); }
.msg-meta .report-button { margin-left: auto; opacity: 0; transition: opacity .1s; }
.msg:hover .report-button, .msg:focus-within .report-button { opacity: 1; }
@media (hover: none) { .msg-meta .report-button { opacity: 1; } }
.story-actions { display: flex; align-items: center; gap: .75rem; margin: -.4rem 0 .6rem; }
/* Ratings: the average (cards, lists, overview) and the reader's own stars. */
.rating-badge { white-space: nowrap; font-variant-numeric: tabular-nums; }
.rating-badge .fa-star { color: var(--star); }
.story-rating { margin: 0 0 .6rem; }
.rating-summary { margin: 0 0 .2rem; }
.rating-input { display: flex; flex-wrap: wrap; align-items: center; gap: .15rem; }
/* The label on its own line, so the 0 and the five stars always stay together in the narrow rail. */
.rating-input > .muted { flex-basis: 100%; }
.rating-input .rate-zero { padding: .1rem .45rem; margin-right: .2rem; }
.rating-input .rate-zero[aria-pressed="true"] { border-color: var(--star); color: var(--star); font-weight: 700; }
.rating-input .star { background: none; border: none; padding: .15rem; cursor: pointer; color: var(--border); font-size: 1.15rem; line-height: 1; }
.rating-input .star.on { color: var(--star); }
.rating-input .star:hover, .rating-input .star:focus-visible { color: var(--star); opacity: .8; }
.reports-link .count { display: inline-block; min-width: 1.3em; padding: 0 .35em; border-radius: 999px; background: var(--live); color: #fff; font-size: .8em; text-align: center; }
.reports { display: grid; gap: .8rem; }
.report-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .8rem 1rem; }
.report-card[data-status=open] { border-left: 3px solid var(--live); }
.report-card[data-status=dismissed], .report-card[data-status=resolved] { opacity: .8; }
.report-meta { font-size: .9em; color: var(--muted); }
.report-note, .report-target blockquote { margin: .5rem 0; padding: .3rem .7rem; border-left: 3px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }
.report-target .preview { max-height: 14rem; overflow: auto; border: 1px dashed var(--border); border-radius: 6px; padding: .4rem .7rem; }
.report-card .form-actions { flex-wrap: wrap; align-items: center; margin-top: .5rem; }
.report-card form.inline { display: flex; gap: .4rem; flex-wrap: wrap; }
.badge.danger { color: var(--live); border-color: var(--live); }
.badge.closed { text-transform: capitalize; }
/* Filled danger buttons; link-style ones (e.g. Delete on a post) stay plain red text. */
button.danger:not(.link) { background: var(--live); border-color: var(--live); color: #fff; }
.pow-status:empty { display: none; }

/* ---- follows ---- */
button.follow-button { white-space: nowrap; }
button.follow-button[aria-pressed=true]::before { content: "✓ "; }
.follow-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.follow-list li { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; padding: .4rem 0; border-bottom: 1px solid var(--border); }
.follow-list li .follow-button { margin-left: auto; }

/* ---- alerts ---- */
.alerts-button { position: relative; display: inline-flex; align-items: center; padding: .35rem .5rem; }
.alerts-button .icon { display: block; }
.alerts-button .count { position: absolute; top: -.35rem; right: -.4rem; min-width: 1.25em; padding: 0 .3em; border-radius: 999px; background: var(--live); color: #fff; font-size: .72em; line-height: 1.4; text-align: center; }
.dialog-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; }
.alerts-dialog { width: min(520px, 100%); }
.alerts { list-style: none; padding: 0; margin: .5rem 0 1rem; max-height: min(60vh, 32rem); overflow: auto; }
.alert { display: flex; align-items: flex-start; gap: .75rem; padding: .55rem .4rem; border-bottom: 1px solid var(--border); }
.alert-link { flex: 1; min-width: 0; color: var(--text); display: grid; gap: .1rem; }
.alert-link:hover .alert-title { color: var(--accent); }
.alert-title { overflow-wrap: anywhere; }
.alert.unread { background: color-mix(in srgb, var(--accent) 8%, transparent); border-radius: 6px; }
.alert.unread .alert-title { font-weight: 600; }
.alert.unread .alert-title::before { content: ""; display: inline-block; width: .5rem; height: .5rem; margin-right: .4rem; border-radius: 50%; background: var(--accent); vertical-align: middle; }
.alert-clear { flex: none; }
.alerts-dialog .form-actions { flex-wrap: wrap; }

/* ---- email ---- */
.badge.verified { color: #1a7f37; border-color: #1a7f37; }
.email-change { margin: .6rem 0; }
.email-change summary { cursor: pointer; color: var(--accent); }
.email-change form { margin-top: .6rem; max-width: 26rem; }

/* ---- moderation decisions and notices ---- */
details.decision { margin: .3rem 0; }
details.decision > summary { list-style: none; display: inline-block; cursor: pointer; }
details.decision form, form.suspend-form { margin-top: .5rem; max-width: 34rem; }
.decision-ground { border: none; margin: 0; padding: 0; display: flex; gap: 1rem; flex-wrap: wrap; }
.decision-ground legend { padding: 0; margin-bottom: .2rem; }
form.suspend-form textarea, details.decision textarea { width: 100%; }
a.button.danger { background: var(--live); border-color: var(--live); color: #fff; }
.notices { display: grid; gap: 1rem; }
.notice-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .9rem 1.1rem; }
.notice-card.unread { border-left: 3px solid var(--live); }
.notice-card h3 { margin: 0; }
.notice-card h4 { margin: .8rem 0 .2rem; font-size: .9rem; }
.notice-card p { margin: 0; overflow-wrap: anywhere; }
.notice-content { margin: 0; padding: .3rem .7rem; border-left: 3px solid var(--border); white-space: pre-wrap; overflow-wrap: anywhere; }

/* ---- appeals ---- */
.appeal-block { margin-top: .9rem; padding-top: .7rem; border-top: 1px dashed var(--border); }
.appeal-block textarea, .appeal-decision textarea { width: 100%; }
.appeal-form > summary { list-style: none; display: inline-block; cursor: pointer; }
.appeal-form form { margin-top: .5rem; }

/* ---- anonymous chat ---- */
.anon-name { font-style: italic; color: var(--muted); }
.chat-note { margin: .4rem 0; color: var(--muted); }
.chat-settings { margin: .4rem 0 .8rem; }
.chat-settings > summary { cursor: pointer; color: var(--accent); }
.chat-settings form { margin-top: .5rem; max-width: 30rem; }
.chat-settings label.check { display: flex; gap: .5rem; align-items: baseline; }
.chat-settings label.check input { margin: 0; }

/* ---- no-JavaScript pages (/static) ---- */
body.static-page { height: auto; }
.static-page header.top { position: static; }
.static-main { max-width: 52rem; margin: 0 auto; padding: 1rem 16px 2rem; }
.static-main #chat-body { margin-top: 2rem; padding-top: 1rem; border-top: 1px solid var(--border); }
.static-main #chat-body::before { content: "Story chat"; display: block; font-weight: 700; margin-bottom: .4rem; }
.static-main .messages { display: flex; flex-direction: column; gap: .4rem; }
.static-footer { max-width: 52rem; margin: 0 auto; padding: 1rem 16px 2rem; border-top: 1px solid var(--border); }

/* ---- story layout: overview rail, Read / Settings tabs ---- */
body:not(.story-open) .rail { display: none; }
/* With the rails hidden, the main column would be auto-placed into the first (auto-width) track and shrink to its
   content. Use a single full-width column instead. */
body:not(.story-open) .shell { grid-template-columns: minmax(0, 1fr); }
.story-overview h2.overview-title { margin: 0 0 .25rem; font-size: 1.15rem; }
.story-overview .story-summary { font-size: .92em; }
.story-overview .overview-heading { margin: 1rem 0 .35rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.story-overview .chapter-list { margin: 0; padding-left: 1.3rem; }
.story-overview .chapter-list li { margin: .2rem 0; }
.story-overview .chapter-list a.active { font-weight: 700; }
.story-overview .chapter-list .muted { font-size: .8em; margin-left: .35rem; }
.story-overview .add-chapter { margin-top: .5rem; }
.story-overview .add-chapter input { min-width: 0; flex: 1; }
.overview-authors { list-style: none; margin: 0; padding: 0; }
.overview-authors li { margin: .15rem 0; }
.story-overview .story-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .5rem 0; }
.story-tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; }
.story-tabs .tab { padding: .45rem .9rem; border: 1px solid transparent; border-bottom: none; border-radius: 6px 6px 0 0; color: var(--muted); margin-bottom: -1px; }
.story-tabs .tab.active { color: var(--text); border-color: var(--border); background: var(--surface); font-weight: 600; }
.story-settings .section-title { margin-top: 1.5rem; }
.story-settings details.authors { margin: 0; }
/* No-JavaScript pages: the overview comes first. */
.static-main { display: flex; flex-direction: column; }
.static-main #overview { order: -1; margin-bottom: 1.5rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }

/* ---- email preferences ---- */
#email-preferences label.check { display: flex; gap: .6rem; align-items: flex-start; }
#email-preferences label.check input { margin-top: .25rem; }

/* ---- following matrix, moderator email ---- */
.follow-matrix { width: 100%; border-collapse: collapse; margin-bottom: .5rem; }
.follow-matrix th, .follow-matrix td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); vertical-align: middle; }
.follow-matrix th { font-size: .8rem; color: var(--muted); font-weight: 600; }
.follow-matrix td:last-child { text-align: right; }
label.follow-email { display: inline-flex; align-items: center; gap: .35rem; cursor: pointer; }
label.follow-email input { margin: 0; }
details.moderator-email { margin-top: .5rem; }
details.moderator-email form { margin-top: .5rem; max-width: 34rem; }
details.moderator-email textarea { width: 100%; }

/* ---- private messages ---- */
.inbox { list-style: none; padding: 0; margin: 0; }
.inbox li { border-bottom: 1px solid var(--border); }
.inbox-link { display: grid; grid-template-columns: minmax(8rem, 12rem) 1fr auto; gap: .75rem; padding: .6rem .25rem; color: var(--text); align-items: baseline; }
.inbox li.unread .inbox-name { font-weight: 700; }
.inbox-last { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { .inbox-link { grid-template-columns: 1fr; gap: .1rem; } .inbox-last { white-space: normal; } }
.pm-thread { display: flex; flex-direction: column; gap: .5rem; margin: 1rem 0; max-height: 60vh; overflow-y: auto; }
.pm { max-width: 80%; padding: .45rem .7rem; border: 1px solid var(--border); border-radius: 10px; background: var(--surface); align-self: flex-start; }
.pm.mine { align-self: flex-end; border-color: var(--accent); }
.pm-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.pm .msg-meta .report-button { margin-left: auto; }
.pm-form { display: flex; gap: .5rem; align-items: flex-end; }
.pm-form textarea { flex: 1; }

/* ---- interactive posts ---- */
.post.interactive { border-left-color: var(--accent); }
.badge.post-type { color: var(--accent); border-color: var(--accent); }
.badge.closed-badge { text-transform: none; }
.interactive-body { margin-top: .6rem; padding-top: .6rem; border-top: 1px dashed var(--border); }
.poll-options { list-style: none; padding: 0; margin: 0 0 .4rem; display: grid; gap: .35rem; }
.poll-option { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; }
.poll-option form.vote { margin: 0; }
.poll-option.mine button, .poll-option.mine .option-label { font-weight: 700; }
.poll-option.winner .option-label { font-weight: 700; color: var(--accent); }
.tally { position: relative; display: inline-flex; align-items: center; min-width: 9rem; height: 1.3rem; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; overflow: hidden; }
.tally .bar { position: absolute; inset: 0 auto 0 0; background: color-mix(in srgb, var(--accent) 30%, transparent); }
.poll-option.winner .tally .bar { background: color-mix(in srgb, var(--accent) 60%, transparent); }
.tally .count-text { position: relative; padding: 0 .4rem; font-size: .8em; }
.badge.winner-badge { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
.suggestion-list, .roll-list { list-style: none; padding: 0; margin: 0 0 .5rem; display: grid; gap: .45rem; }
.suggestion-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.dice .die.dropped { text-decoration: line-through; color: var(--muted); }
.dice .die.exploded { color: var(--accent); }
form.suggest textarea { width: 100%; }
.post-type-picker { display: grid; gap: .4rem; margin-bottom: .5rem; }
.post-type-fields { border: 1px solid var(--border); border-radius: 6px; padding: .5rem .7rem; margin: 0; display: grid; gap: .4rem; }
.post-type-fields textarea, .post-type-fields input[type=text] { width: 100%; }
.post-type-fields[hidden] { display: none; }
.filter-interactive { display: inline-flex; gap: .35rem; align-items: center; margin-bottom: .5rem; }
.hidden-interactive-note { margin: .25rem 0 .75rem; padding: .3rem .6rem; border: 1px dashed var(--border); border-radius: 6px; }
.poll-option.struck .option-label, .suggestion-list li.struck .suggestion-body { text-decoration: line-through; color: var(--muted); }
.chapter-kicker { margin: 0; text-transform: uppercase; letter-spacing: .04em; }
.chapter-title { margin-top: .15rem; }
.chapter-category-form { margin-bottom: .6rem; }
.category-admin { list-style: none; padding: 0; margin: 0 0 .6rem; display: grid; gap: .4rem; }
.category-admin li { display: flex; flex-wrap: wrap; align-items: center; gap: .4rem; }
.category-admin input[type=text] { width: 14rem; max-width: 100%; }
.add-chapter label select { margin-left: .25rem; }
.poll-edit fieldset { border: 1px solid var(--border); border-radius: 6px; display: grid; gap: .35rem; }
.poll-edit fieldset input[type=text] { width: min(24rem, 100%); }
.option-edited { cursor: help; text-decoration: underline dotted; }
.chat-form { flex-wrap: wrap; }
.chat-image-pick { display: inline-flex; align-items: center; cursor: pointer; border: 1px solid var(--accent); color: var(--accent); border-radius: 6px; padding: .45rem .6rem; font-size: .9em; }
.chat-image-pick.busy { opacity: .5; pointer-events: none; }
.chat-image-preview { flex-basis: 100%; display: flex; align-items: center; gap: .5rem; }
.chat-image-preview[hidden] { display: none; }
.chat-image-preview img { max-height: 64px; max-width: 120px; border-radius: 4px; }
.chat-image img { display: block; max-width: 100%; max-height: 240px; border-radius: 6px; margin-top: .25rem; }
.search-box { display: flex; gap: .4rem; max-width: 36rem; margin: .5rem 0 1rem; }
.search-box input[type=search] { flex: 1; min-width: 0; }
header.top .search-box { margin: 0; max-width: 20rem; }
.search-hit { display: flex; flex-direction: column; gap: .25rem; }
.search-hit .card { flex: 1; }
.match-badge { align-self: flex-start; }
.cards.search-hits { grid-template-columns: minmax(0, 1fr); max-width: 48rem; }
/* The search button sits beside the app name; everything after it is pushed to the right. */
header.top .header-search, .static-page header.top .search-box { margin-right: auto; }
.icon-button { display: inline-flex; align-items: center; justify-content: center; min-width: 2.2rem; }

/* ---- header menu ----
   #session holds two groups. On a wide header both are `display: contents`, so their controls sit in one row, kept in
   the original order by `order`. When they don't fit (app.js measures), header.top gets .compact: #session-menu
   becomes a dropdown under the menu button (shown by .menu-open), while .session-pinned (the signed-in user and the
   alert bell) stays in the header, just left of the button. */
.session-menu, .session-pinned { display: contents; }
#alerts-widget { order: 2; }
.notices-link { order: 3; }
.session-user { order: 4; }
.session-menu > :not(.notices-link) { order: 5; }
.menu-toggle { position: relative; }
.menu-toggle[hidden], .menu-dot[hidden] { display: none; }
.menu-dot { position: absolute; top: .2rem; right: .2rem; width: .55rem; height: .55rem; border-radius: 50%; background: var(--live); }
header.top.compact { gap: .6rem; }
header.top.compact .session-pinned { display: flex; align-items: center; gap: .5rem; min-width: 0; }
/* The user, then the bell right next to the menu button (their markup order). */
header.top.compact .session-pinned > * { order: 0; }
header.top.compact #session { min-width: 0; }
/* Just the name (and tier) while compact; the user's name can shorten with an ellipsis on a very narrow screen. */
header.top.compact .signed-in-label { display: none; }
header.top.compact .session-user { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
header.top.compact .session-menu {
  display: none; position: absolute; top: calc(var(--header-h) - 4px); right: .5rem; z-index: 40;
  flex-direction: column; align-items: stretch; gap: .45rem; padding: .7rem; white-space: normal;
  min-width: 14rem; max-width: calc(100vw - 1rem); max-height: calc(100vh - var(--header-h) - var(--footer-h) - 1rem); overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 28px rgba(0, 0, 0, .3);
}
header.top.compact.menu-open .session-menu { display: flex; }
header.top.compact .session-menu .button, header.top.compact .session-menu button { width: 100%; justify-content: flex-start; text-align: left; }
header.top.compact .session-menu > span { display: block; }

/* Every control in the top bar is the same height, whether it holds text or an icon (the icon-only ones are square). */
:root { --control-h: 2.25rem; }
header.top .button, header.top button, header.top input[type=search] { box-sizing: border-box; height: var(--control-h); padding-top: 0; padding-bottom: 0; }
header.top .button, header.top button { display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
header.top .icon-button, header.top .alerts-button { min-width: var(--control-h); padding-left: 0; padding-right: 0; }

/* Story banner: the image fades to transparent at the bottom, into the story below it. */
.story-banner:empty { display: none; }
/* The strip itself fades and clips, so a zoomed image (scaled with transform) stays inside it and keeps the fade. */
.story-banner {
  margin: -.25rem 0 -1.25rem; overflow: hidden; border-radius: 8px 8px 0 0;
  -webkit-mask-image: linear-gradient(to bottom, #000 45%, transparent);
  mask-image: linear-gradient(to bottom, #000 45%, transparent);
}
.story-banner img { display: block; width: 100%; height: clamp(120px, 24vw, 240px); object-fit: cover; }
/* Framing controls (banner settings): a preview the shape of a wide banner, dragged to move the image. */
.banner-framing { margin-top: .8rem; max-width: 36rem; }
.banner-framing h4 { margin: 0; }
.banner-frame { overflow: hidden; border-radius: 8px; border: 1px solid var(--border); aspect-ratio: 10 / 3; cursor: grab; touch-action: none; }
.banner-frame.dragging { cursor: grabbing; }
.banner-frame img { display: block; width: 100%; height: 100%; object-fit: cover; user-select: none; pointer-events: none; }
.banner-sliders { display: grid; grid-template-columns: repeat(auto-fit, minmax(9rem, 1fr)); gap: .4rem 1rem; }
.banner-sliders label { display: flex; flex-direction: column; }
.story-banner + .story-tabs, .story-banner + section, .story-banner + div { position: relative; }
.banner-pick { display: inline-flex; align-items: center; cursor: pointer; border: 1px solid var(--accent); color: var(--accent); border-radius: 6px; padding: .45rem .6rem; }
.banner-pick.busy { opacity: .5; pointer-events: none; }

/* The full app's footer: a slim bar under the three columns (the shell's height leaves room for it). */
.site-footer {
  box-sizing: border-box; height: var(--footer-h); display: flex; align-items: center; justify-content: center;
  border-top: 1px solid var(--border); background: var(--surface); color: var(--muted); font-size: .78rem;
}

/* ---- story tags ---- */
.tags { display: inline-flex; flex-wrap: wrap; gap: .3rem; }
a.tag { padding: .05rem .45rem; border: 1px solid var(--border); border-radius: 999px; color: var(--muted); white-space: nowrap; }
a.tag:hover { color: var(--accent); border-color: var(--accent); text-decoration: none; }
.card-tags { margin-top: .35rem; }
.overview-tags { margin: -.2rem 0 .5rem; }
.story-tags input[type=text] { width: 24rem; max-width: 100%; }
.tag-heading { color: var(--accent); }
/* The word count's reading time shows on hover. */
.word-count { cursor: help; text-decoration: underline dotted; text-underline-offset: 2px; }
