:root {
  color-scheme: dark;
  --bg: #11110f;
  --surface: #181714;
  --surface-raised: #201e1a;
  --text: #e8e1d5;
  --muted: #9d978d;
  --line: #302e29;
  --accent: #9e3d36;
  --accent-light: #c95d54;
  --content: 700px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "PingFang SC", sans-serif;
}
body.drawer-open { overflow: hidden; }
button, input { font: inherit; }
textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
a:hover { color: #fff; }
:focus-visible { outline: 2px solid var(--accent-light); outline-offset: 4px; }

.site-header {
  position: sticky;
  z-index: 10;
  top: 0;
  display: flex;
  height: 64px;
  align-items: center;
  justify-content: space-between;
  padding: 0 max(24px, calc((100vw - 1120px) / 2));
  border-bottom: 1px solid color-mix(in srgb, var(--line) 65%, transparent);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px);
}
.brand { display: flex; align-items: center; }
.brand img { display: block; width: 152px; height: 32px; }
.brand span { margin-left: 12px; color: var(--muted); font-family: ui-sans-serif, system-ui, sans-serif; font-size: 12px; letter-spacing: 0; }
nav { display: flex; align-items: center; gap: 28px; color: var(--muted); font-size: 14px; }
.menu-button { display: none; border: 1px solid transparent; border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; font-weight: 600; }
.account-button { display: flex; min-height: 38px; align-items: center; gap: 9px; padding: 0 14px 0 9px; border: 1px solid var(--line); border-radius: 999px; background: var(--surface); color: var(--text); cursor: pointer; font-weight: 600; transition: border-color 160ms, background 160ms; }
.account-button:hover { border-color: #5a554b; background: var(--surface-raised); }
.account-icon { display: grid; width: 24px; height: 24px; place-items: center; border-radius: 50%; background: var(--line); color: var(--muted); }
.account-icon svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
.account-button[data-authenticated="true"] { border-color: color-mix(in srgb, var(--accent) 65%, var(--line)); background: color-mix(in srgb, var(--accent) 10%, var(--surface)); }
.account-button[data-authenticated="true"] .account-icon { background: var(--accent); color: #fff; }
.reading-progress { position: fixed; z-index: 20; top: 63px; width: 100%; height: 2px; }
.reading-progress span { display: block; width: 0; height: 100%; background: var(--accent); }

.chapter { width: min(var(--content), calc(100% - 40px)); margin: 0 auto; padding: 104px 0 88px; }
.chapter-header { margin-bottom: 72px; text-align: center; }
.eyebrow { margin: 0 0 16px; color: var(--accent-light); font-size: 13px; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; }
.chapter-number { margin: 32px 0 8px; color: var(--muted); font-family: ui-serif, "Songti SC", serif; font-size: 15px; letter-spacing: .12em; }
h1, h2 { font-family: ui-serif, "Songti SC", "STSong", serif; font-weight: 600; }
h1 { margin: 0; font-size: clamp(32px, 5vw, 44px); letter-spacing: .08em; }
.chapter-meta { display: flex; justify-content: center; gap: 24px; margin: 24px 0 0; color: var(--muted); font-size: 13px; }
.prose { font-family: ui-serif, "Songti SC", "STSong", serif; font-size: 18px; line-height: 1.95; letter-spacing: .025em; }
.prose p { margin: 0 0 1.65em; }
blockquote { margin: 40px 0; padding: 4px 0 4px 28px; border-left: 2px solid var(--accent); color: #f3eade; font-size: 20px; }
.cliffhanger { margin: 72px 0; text-align: left; font-family: ui-serif, "Songti SC", serif; font-size: 22px; letter-spacing: .08em; }

.vote-card { padding: 40px; border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 6px; background: var(--surface); }
.vote-card h2 { margin: 0; font-size: 28px; }
.incubation .chapter { padding-top: 128px; }
.incubation .chapter-header { margin-bottom: 56px; }
.incubation #vote-options { grid-template-columns: repeat(2, 1fr); }
.vote-intro { margin: 12px 0 28px; color: var(--muted); font-size: 14px; }
fieldset, #vote-options { display: grid; gap: 12px; margin: 0; padding: 0; border: 0; }
fieldset { margin-bottom: 24px; }
.option { display: flex; min-height: 72px; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; transition: border-color 160ms, background 160ms; }
.option:hover { border-color: #5a554b; background: var(--surface-raised); }
.option:has(input:checked) { border-color: var(--accent-light); background: color-mix(in srgb, var(--accent) 12%, var(--surface)); }
.option input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent-light); }
.option span { display: grid; gap: 5px; }
.option strong { font-size: 15px; }
.option small { color: var(--muted); font-size: 13px; }
.primary-button { min-height: 46px; padding: 0 24px; border: 1px solid var(--accent); border-radius: 6px; background: var(--accent); color: #fff; cursor: pointer; font-weight: 600; }
.primary-button:hover { background: #ae4941; }
.primary-button:disabled { cursor: not-allowed; opacity: .55; }
.form-error { min-height: 20px; margin: -8px 0 12px; color: #e48379; font-size: 13px; }
.vote-success { margin-top: 10px; display: flex; align-items: center; gap: 16px; padding: 20px; border-radius: 6px; background: color-mix(in srgb, var(--accent) 13%, var(--surface-raised)); }
.vote-success > span { display: grid; width: 32px; height: 32px; place-items: center; border-radius: 50%; background: var(--accent); }
.vote-success p { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.loading { margin: 0; color: var(--muted); }
.vote-results { display: grid; gap: 18px; }
.result-row { display: grid; grid-template-columns: 1fr auto; gap: 8px 16px; }
.result-row strong { font-size: 14px; }
.result-row span { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.result-row i { grid-column: 1 / -1; height: 5px; overflow: hidden; border-radius: 3px; background: var(--line); }
.result-row i::after { display: block; width: var(--result); height: 100%; background: var(--muted); content: ""; }
.result-row.winner i::after { background: var(--accent-light); }
.resolution-note { margin: 8px 0 0; color: var(--accent-light); font-size: 13px; }
.type-suggestion { display: grid; gap: 12px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--line); }
.type-suggestion label, .type-suggestion legend { color: var(--muted); font-size: 13px; }
.type-suggestion-row { display: flex; gap: 10px; }
.type-suggestion-row input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
.type-suggestion-row button { flex: 0 0 auto; white-space: nowrap; }
.pitch-categories { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.pitch-categories .option {
  position: relative;
  min-height: 64px;
  padding-left: 56px;
}
.pitch-categories .option::before {
  position: absolute;
  left: 18px;
  width: 22px;
  height: 22px;
  border: 1px solid var(--muted);
  border-radius: 6px;
  background: var(--bg);
  content: "";
}
.pitch-categories .option:has(input:checked)::before {
  border-color: var(--accent-light);
  background: var(--accent);
  box-shadow: inset 0 0 0 3px var(--bg);
}
.pitch-categories .option input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}
.type-suggestion textarea {
  width: 100%;
  min-height: 46px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}
.type-suggestion textarea { min-height: 150px; padding: 12px; resize: vertical; line-height: 1.6; }
.type-suggestion p { margin: 0; font-size: 13px; }
#type-suggestion-hint { color: var(--muted); }
.success-note { color: var(--accent-light); }
.pitch-board { display: grid; gap: 16px; margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.pitch-board-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; }
.pitch-board h3 { margin: 0; font-size: 22px; }
.pitch-count { color: var(--muted); font-size: 13px; }
.pitch-list { display: grid; gap: 12px; max-height: 420px; overflow: auto; padding-right: 4px; }
.pitch-item { display: grid; gap: 8px; padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.pitch-item-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px 12px; align-items: baseline; }
.pitch-item-head strong { font-size: 15px; }
.pitch-item-head span, .pitch-item p { color: var(--muted); font-size: 13px; line-height: 1.6; }
.pitch-item p { margin: 0; color: var(--text); }
.next-chapter {
  display: grid;
  justify-items: center;
  gap: 10px;
  padding: 56px 18px 0;
  color: var(--muted);
  text-align: center;
}
.next-chapter p { margin: 0; }
.next-chapter strong {
  color: var(--text);
  font-variant-numeric: tabular-nums;
  font-size: clamp(26px, 6.2vw, 38px);
  line-height: 1;
  letter-spacing: .12em;
}
.next-chapter.generating {
  margin-top: 44px;
  padding: 26px 20px 24px;
  border: 1px solid color-mix(in srgb, var(--line) 90%, transparent);
  border-radius: 20px;
  background:
    radial-gradient(circle at top, color-mix(in srgb, var(--accent-light) 10%, transparent), transparent 58%),
    linear-gradient(180deg, color-mix(in srgb, var(--surface) 92%, transparent), var(--surface));
  box-shadow: 0 18px 40px rgb(0 0 0 / 20%);
}
.next-chapter.generating p:first-child {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-family: ui-serif, "Songti SC", serif;
  font-size: 16px;
  letter-spacing: .04em;
}
.next-chapter.generating p:first-child::before {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-light);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-light) 45%, transparent);
  animation: generating-pulse 1.6s ease-out infinite;
  content: "";
}
.next-chapter.generating strong {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--accent-light);
  font-size: clamp(30px, 8vw, 44px);
  letter-spacing: .1em;
}
.next-chapter.generating strong::before {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent-light) 45%, transparent);
  animation: generating-pulse 1.6s ease-out infinite;
  content: "";
}
.next-chapter.generating p:last-child {
  max-width: 22em;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

@keyframes generating-pulse { 70%, 100% { box-shadow: 0 0 0 9px transparent; } }

.timeline { width: min(800px, calc(100% - 40px)); margin: 0 auto; padding: 96px 0 120px; border-top: 1px solid var(--line); }
.timeline-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.timeline h2 { margin: 0; font-size: 32px; }
.timeline-toggle { display: block; margin: 34px 15px 0; padding: 0; border: 0; background: transparent; color: var(--accent-light); font-size: 14px; cursor: pointer; }
.timeline-hint { margin: 10px 0 34px; color: var(--muted); font-size: 13px; }
.timeline ol { margin: 0; padding: 0; list-style: none; }
.timeline li { position: relative; display: grid; gap: 7px; min-height: 88px; margin-left: 8px; padding: 0 0 32px 34px; border-left: 1px solid var(--line); }
.timeline li::before { position: absolute; top: 2px; left: -5px; width: 9px; height: 9px; border-radius: 50%; background: var(--muted); content: ""; }
.timeline li.fate::before { background: var(--accent-light); box-shadow: 0 0 0 5px color-mix(in srgb, var(--accent) 20%, transparent); }
.timeline-entry { display: grid; gap: 7px; width: 100%; padding: 0; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.timeline-entry span { color: var(--muted); font-size: 12px; }
.timeline-entry strong { font-family: ui-serif, "Songti SC", serif; font-size: 17px; font-weight: 500; }
.timeline-entry[data-active="true"] strong { color: var(--accent-light); }
.timeline-entry:hover strong { color: #fff; }

.chapter-drawer { position: fixed; inset: 0; z-index: 40; display: grid; justify-items: end; background: rgb(0 0 0 / 0%); }
.chapter-drawer-backdrop { position: absolute; inset: 0; border: 0; background: rgb(0 0 0 / 66%); cursor: pointer; }
.chapter-drawer-panel { position: relative; width: min(640px, 100vw); height: 100vh; padding: 0 28px 32px; border-left: 1px solid var(--line); background: linear-gradient(180deg, var(--surface), var(--bg)); box-shadow: -20px 0 40px rgb(0 0 0 / 35%); overflow: auto; overscroll-behavior: contain; }
.chapter-drawer-header { position: sticky; top: 0; z-index: 1; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 20px; border-bottom: 1px solid color-mix(in srgb, var(--line) 80%, transparent); background: linear-gradient(180deg, var(--surface), color-mix(in srgb, var(--surface) 92%, transparent)); }
.chapter-drawer-heading { display: grid; gap: 10px; min-width: 0; }
.chapter-drawer-close { flex: 0 0 auto; background: color-mix(in srgb, var(--accent-light) 72%, var(--bg)); color: #111; }
.chapter-drawer-body { padding-top: 22px; }
.chapter-drawer-number { margin: 0; color: var(--muted); font-size: 14px; }
.chapter-drawer-header h3 { margin: 0; font-family: ui-serif, "Songti SC", serif; font-size: 20px; }
.chapter-drawer .prose { font-size: 17px; line-height: 1.9; }
.chapter-drawer .cliffhanger {
  margin: 56px 0 0;
  padding: 36px 0 0;
  border-top: 1px solid var(--line);
  color: var(--text);
  text-align: left;
  font-family: ui-serif, "Songti SC", "STSong", serif;
  font-size: 18px;
  letter-spacing: .02em;
}

footer { padding: 48px 20px; border-top: 1px solid var(--line); color: var(--muted); text-align: center; font-family: ui-serif, "Songti SC", serif; }

.admin-page { width: min(960px, calc(100% - 40px)); margin: 0 auto; padding: 80px 0 120px; }
.admin-title h1 { margin: 0; font-size: 36px; }
.admin-title > p:last-child, .admin-status { color: var(--muted); }
.admin-toolbar { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; margin-top: 48px; padding: 24px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.admin-toolbar label { grid-column: 1 / -1; font-size: 13px; }
.admin-toolbar input, .field input, .field textarea, .choice-edit-row input { width: 100%; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); }
.admin-toolbar input, .field input, .choice-edit-row input { min-height: 46px; padding: 0 12px; }
.secondary-button { min-height: 46px; padding: 0 20px; border: 1px solid var(--line); border-radius: 6px; background: transparent; color: var(--text); cursor: pointer; }
.secondary-button:hover { border-color: var(--muted); }
.secondary-button:disabled { cursor: not-allowed; opacity: .55; }
.admin-status { min-height: 24px; margin: 18px 0 40px; }
.admin-suggestions { margin-bottom: 48px; padding: 24px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.admin-suggestions-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 18px; }
.admin-suggestions h2 { margin: 0; font-size: 24px; }
.suggestion-list { display: grid; gap: 12px; }
.suggestion-item { display: grid; gap: 6px; padding: 16px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); }
.suggestion-item strong { font-size: 15px; }
.suggestion-item span, .suggestion-item time { color: var(--muted); font-size: 13px; }
.draft-form { display: grid; gap: 28px; }
.field { display: grid; gap: 9px; }
.field label, .choice-editor legend { font-size: 13px; font-weight: 600; }
.field textarea { resize: vertical; min-height: 480px; padding: 16px; line-height: 1.8; }
.choice-editor { display: grid; gap: 14px; margin: 0; padding: 24px; border: 1px solid var(--line); border-radius: 6px; }
#draft-choices { display: grid; gap: 12px; }
.choice-edit-row { display: grid; grid-template-columns: 1fr 2fr; gap: 12px; }

dialog { width: min(420px, calc(100% - 40px)); padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); }
dialog::backdrop { background: rgb(0 0 0 / 72%); backdrop-filter: blur(3px); }
dialog form { position: relative; display: grid; padding: 40px; }
dialog h2 { margin: 0; font-size: 28px; }
dialog p:not(.eyebrow):not(.form-error) { margin: 12px 0 28px; color: var(--muted); }
dialog label { margin-bottom: 8px; font-size: 13px; }
dialog input { height: 46px; margin-bottom: 20px; padding: 0 12px; border: 1px solid var(--line); border-radius: 6px; background: var(--bg); color: var(--text); }
.dialog-close { position: absolute; top: 12px; right: 12px; width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 24px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

@media (max-width: 767px) {
  .site-header { padding: 0 20px; }
  .brand span { display: none; }
  .menu-button { display: block; min-width: 56px; min-height: 40px; }
  .menu-button[aria-expanded="true"] { border-color: var(--line); background: var(--surface-raised); }
  #site-nav { position: absolute; top: 64px; right: 0; left: 0; display: none; padding: 12px 20px 20px; border-bottom: 1px solid var(--line); background: var(--bg); box-shadow: 0 20px 32px rgb(0 0 0 / 24%); }
  #site-nav.open { display: flex; flex-direction: column; align-items: stretch; gap: 4px; }
  #site-nav a { display: flex; min-height: 48px; align-items: center; padding: 0 12px; border-radius: 6px; font-weight: 600; }
  #site-nav a:hover { background: var(--surface); }
  #site-nav .account-button { width: 100%; min-height: 56px; justify-content: flex-start; margin-top: 10px; padding: 0 14px; border-radius: 6px; }
  .chapter { padding-top: 72px; }
  .chapter-header { margin-bottom: 56px; }
  .chapter-meta { gap: 14px; }
  .prose { font-size: 17px; line-height: 1.85; }
  .vote-card { padding: 28px 20px; }
  .vote-card h2 { font-size: 24px; }
  .incubation #vote-options { grid-template-columns: 1fr; }
  .pitch-categories { grid-template-columns: 1fr; }
  .type-suggestion-row, .pitch-top-row { flex-direction: column; }
  .type-suggestion-row button { width: 100%; }
  .primary-button { width: 100%; min-height: 48px; }
  .next-chapter { flex-wrap: wrap; }
  .next-chapter { padding-top: 44px; }
  .next-chapter.generating { margin-top: 34px; padding: 22px 16px 20px; border-radius: 18px; }
  .next-chapter.generating p:first-child { font-size: 15px; }
  .next-chapter.generating p:last-child { max-width: 16rem; }
  .timeline { padding: 72px 0 88px; }
  .timeline-head { align-items: flex-start; }
  .chapter-drawer-panel { width: 100vw; padding: 0px 18px 28px; }
  .chapter-drawer-header { padding-bottom: 16px; gap: 14px; }
  .chapter-drawer-header h3 { font-size: 18px; }
  dialog form { padding: 32px 24px 24px; }
  .admin-page { padding-top: 56px; }
  .admin-toolbar, .choice-edit-row { grid-template-columns: 1fr; }
  .admin-toolbar button { width: 100%; }
  .admin-suggestions-head { align-items: flex-start; }
  .field textarea { min-height: 360px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
  .next-chapter.generating strong::before { animation: none; }
}
