:root { --bg: #faf8f4; --fg: #1f1d1a; --muted: #6b665e; --card: #fff; --line: #e4dfd6; --soft: #f3efe7; --danger: #b3261e; --ok: #2e7d4f; --note: #fff6d6; --note-line: #ecd98f; }
@media (prefers-color-scheme: dark) {
  :root { --bg: #16151a; --fg: #ebe7e0; --muted: #a39d93; --card: #201f25; --line: #34323a; --soft: #26252c; --danger: #f2b8b5; --ok: #7fd1a0; --note: #2c2819; --note-line: #5a4f25; }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--fg); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; padding-inline: 16px; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: var(--fg); }
input, select, textarea { padding: 8px 12px; border-radius: 8px; border: 1px solid var(--line); background: var(--card); width: 100%; }
textarea { resize: vertical; line-height: 1.55; }
button { cursor: pointer; }
.primary { background: var(--fg); color: var(--bg); border: 0; border-radius: 8px; padding: 8px 14px; font-weight: 600; white-space: nowrap; }
.primary:disabled { opacity: .5; cursor: default; }
.ghost { background: transparent; border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px; white-space: nowrap; }
.link { background: none; border: 0; padding: 0; color: var(--muted); text-decoration: underline; font-size: 13px; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; }

.topnav { max-width: 1400px; margin: 0 auto; padding-block: 14px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; font-size: 14px; }
.topnav a { color: var(--muted); text-decoration: none; }
.topnav a:hover { color: var(--fg); }
.pagehead { max-width: 1400px; margin: 0 auto; display: flex; flex-wrap: wrap; gap: 12px 20px; align-items: end; justify-content: space-between; padding-bottom: 14px; }
.pagehead h1 { margin: 0; font: 700 28px/1.2 Georgia, serif; }
.pagehead p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.chip { display: inline-block; background: var(--c, #5c6b73); color: #fff; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; text-decoration: none; }

/* ---------- list page ---------- */
.filters { max-width: 1400px; margin: 0 auto 14px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.filters input { width: min(300px, 100%); margin-right: 8px; }
.filters button { font-size: 12px; border: 1px solid var(--line); background: var(--card); border-radius: 99px; padding: 4px 10px 4px 8px; display: flex; align-items: center; gap: 6px; }
.filters button i { width: 10px; height: 10px; border-radius: 50%; background: var(--c); }
.filters button[aria-pressed=true] { border-color: var(--c); box-shadow: inset 0 0 0 1px var(--c); }
.grid { max-width: 1400px; margin: 0 auto; padding: 0 0 60px; list-style: none; display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.grid a { display: flex; flex-direction: column; gap: 8px; height: 100%; background: var(--card); border: 1px solid var(--line); border-top: 4px solid var(--c, var(--line)); border-radius: 10px; padding: 14px 16px; text-decoration: none; }
.grid a:hover { border-color: var(--c, var(--fg)); }
.grid h2 { margin: 0; font: 700 18px/1.3 Georgia, serif; }
.grid .excerpt { margin: 0; color: var(--muted); font-size: 14px; flex: 1; }
.badges { display: flex; flex-wrap: wrap; gap: 6px; font-size: 12px; }
.badge { border: 1px solid var(--line); border-radius: 99px; padding: 1px 8px; color: var(--muted); }
.badge.ok { color: var(--ok); border-color: currentColor; }
.empty { max-width: 1400px; margin: 40px auto; text-align: center; color: var(--muted); }

/* ---------- hypo page ---------- */
.split { max-width: 1400px; margin: 0 auto; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); gap: 20px; align-items: start; padding-bottom: 60px; }
@media (max-width: 900px) { .split { grid-template-columns: 1fr; } }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.panel > header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.panel > header h2 { margin: 0; font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.panel .body { padding: 16px 18px; }
.hypo-panel { position: sticky; top: 12px; max-height: calc(100vh - 24px); display: flex; flex-direction: column; border-top: 5px solid var(--c); }
@media (max-width: 900px) { .hypo-panel { position: static; max-height: none; } }
.hypo-panel .body { overflow-y: auto; font: 17px/1.7 Georgia, "Iowan Old Style", serif; }
.hypo-panel .body p:first-child { margin-top: 0; }
.hypo-panel .body blockquote { margin: 1em 0; padding: .5em 1em; border-left: 4px solid var(--c); background: var(--soft); border-radius: 0 8px 8px 0; }

.section { padding: 16px 18px; border-bottom: 1px solid var(--line); }
.section:last-child { border-bottom: 0; }
.section h3 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 14px; }
.section h3 b { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 6px; background: var(--c); color: #fff; font-size: 13px; }
.section h3 .count { margin-left: auto; font-weight: 400; font-size: 12px; color: var(--muted); }
.answer-text { font: 16px/1.65 Georgia, serif; }
.answer-text > :first-child { margin-top: 0; }
.answer-text > :last-child { margin-bottom: 0; }
.answer-text.blank { color: var(--muted); font: italic 14px system-ui, sans-serif; }

.comments { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.comment { background: var(--note); border: 1px solid var(--note-line); border-radius: 8px; padding: 8px 12px; font-size: 14px; }
.comment .who { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; font-size: 12px; margin-bottom: 2px; }
.comment .who strong { font-size: 13px; }
.comment .who .link { margin-left: auto; font-size: 12px; }
.comment .text { white-space: pre-wrap; overflow-wrap: anywhere; }
.comment-form { margin-top: 10px; display: grid; gap: 8px; }
.comment-form .row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; justify-content: flex-end; }
.comment-form .as { margin-right: auto; font-size: 13px; color: var(--muted); }
.add-comment { margin-top: 10px; }

.editor label { display: block; }
.editor textarea { margin-top: 6px; min-height: 90px; }
.editor .section h3 { margin-bottom: 0; }
.status { font-size: 13px; color: var(--muted); }
.status.dirty { color: var(--danger); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ---------- dialog ---------- */
dialog { width: min(720px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 1px solid var(--line); border-radius: 14px; background: var(--bg); color: var(--fg); box-shadow: 0 20px 60px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(10,10,15,.45); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 34px); }
dialog .dhead, dialog .dfoot { padding: 14px 20px; display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
dialog .dhead { border-bottom: 1px solid var(--line); }
dialog .dhead h2 { margin: 0; font: 700 20px Georgia, serif; }
dialog .dfoot { border-top: 1px solid var(--line); }
dialog .dbody { padding: 16px 20px; overflow-y: auto; display: grid; gap: 12px; }
dialog label { display: grid; gap: 4px; font-size: 13px; font-weight: 600; }
dialog label small { font-weight: 400; color: var(--muted); }
dialog textarea { min-height: 260px; font: 15px/1.6 Georgia, serif; }
/* ---------- hypo timer (timer.js) ---------- */
.timer-btn { display: inline-flex; align-items: center; gap: 6px; }
.timer-btn[hidden], .timer-pop[hidden], .timer-pill[hidden] { display: none; }
.timer-pop { position: absolute; z-index: 20; width: 300px; padding: 12px 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0,0,0,.18); font-size: 13px; }
.timer-pop .pop-title { margin: 0 0 8px; font-weight: 700; font-size: 14px; }
.timer-pop .presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.timer-pop .presets button { padding: 6px 0; border: 1px solid var(--line); border-radius: 8px; background: var(--card); }
.timer-pop .presets button:hover, .timer-pop .presets .on { border-color: var(--fg); }
.timer-pop .custom { display: flex; align-items: center; gap: 6px; margin-top: 10px; }
.timer-pop .custom label { display: flex; align-items: center; gap: 6px; }
.timer-pop .custom input { width: 72px; padding: 5px 8px; }
.timer-pop .custom .primary { margin-left: auto; }
.timer-pop .pop-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.timer-pill { position: fixed; right: 16px; bottom: 16px; z-index: 15; display: flex; align-items: center; gap: 10px; padding: 8px 10px 8px 16px; background: var(--fg); color: var(--bg); border-radius: 99px; box-shadow: 0 8px 24px rgba(0,0,0,.25); font-size: 13px; }
.timer-pill .t { font: 700 20px/1 ui-monospace, "Cascadia Mono", Consolas, monospace; font-variant-numeric: tabular-nums; }
.timer-pill .l { opacity: .75; }
.timer-pill button { background: transparent; color: inherit; border: 1px solid currentColor; border-radius: 99px; padding: 3px 10px; font-size: 12px; opacity: .85; }
.timer-pill button:hover { opacity: 1; }
.timer-pill.paused .t { opacity: .6; }
.timer-pill.over { background: var(--danger); color: #fff; animation: timer-pulse 1.6s ease-in-out 3; }
@keyframes timer-pulse { 50% { transform: scale(1.06); } }
.filters .auto-timer { display: flex; align-items: center; gap: 6px; margin-left: auto; font-size: 13px; color: var(--muted); }
.filters .auto-timer select { width: auto; padding: 4px 8px; font-size: 13px; }

/* ---------- Markdown extras: ==highlight==, - [ ] to-dos, > [!RULE] boxes ---------- */
mark { background: #ffe58a; color: inherit; padding: 0 .15em; border-radius: 3px; }
@media (prefers-color-scheme: dark) { mark { background: rgba(250, 204, 21, .3); } }
li.task { list-style: none; margin-left: -1.2em; }
li.task input { width: auto; padding: 0; margin: 0 .3em 0 0; }
.callout { margin: 1em 0; padding: 8px 14px; border: 1px solid var(--line); border-left: 4px solid var(--c, var(--muted)); border-radius: 8px; background: var(--soft); }
.callout-title { margin: 0 0 4px; font: 700 12px system-ui, sans-serif; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.callout > :last-child { margin-bottom: 0; }
#toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.25); max-width: calc(100vw - 32px); z-index: 10; }
