:root {
  --paper: #efe7da;
  --paper-deep: #e4d9c8;
  --card: #faf6ef;
  --ink: #231e19;
  --muted: #655c52;
  --line: #d9cebd;
  --cel: #c24b2e;
  --cel-deep: #8e311c;
  --teal: #1d655f;
  --teal-soft: #d7ebe6;
  --gold: #8d6230;
  --warn: #8a4b12;
  --warn-bg: #f8e7cf;
  --dock: #261f1b;
  --dock-text: #f6f0e6;
  --shadow: 0 18px 40px rgba(48, 32, 18, 0.08);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: "Segoe UI", "Avenir Next", "Trebuchet MS", sans-serif;
  --mono: "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  color-scheme: light;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  background:
    radial-gradient(1200px 500px at 10% -10%, rgba(194, 75, 46, 0.08), transparent 50%),
    radial-gradient(900px 400px at 100% 0%, rgba(29, 101, 95, 0.08), transparent 46%),
    var(--paper);
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.28;
  background-image: radial-gradient(rgba(35, 30, 25, 0.045) 0.7px, transparent 0.7px);
  background-size: 3px 3px;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3, p { margin: 0; }

.skip {
  position: absolute;
  left: 12px;
  top: -40px;
  background: var(--ink);
  color: white;
  padding: 8px 12px;
  z-index: 50;
}
.skip:focus { top: 12px; }

.wrap {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  position: relative;
}

.top {
  display: flex;
  gap: 28px;
  justify-content: space-between;
  align-items: flex-end;
  padding: 36px 0 22px;
}
.brand { display: flex; gap: 14px; align-items: center; }
.mark {
  width: 54px;
  height: 54px;
  flex: none;
}
.eyebrow {
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--cel-deep);
  font-weight: 650;
}
h1 {
  font-family: var(--serif);
  font-size: 46px;
  font-weight: 560;
  letter-spacing: -0.03em;
  line-height: 0.95;
}
.lede {
  max-width: 460px;
  color: var(--muted);
  font-size: 15px;
}
.node-link {
  margin-top: 6px;
  font-size: 13px;
}
.node-link a { color: var(--teal); }

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 22px;
  align-items: start;
  padding-bottom: 64px;
}

.stack { display: flex; flex-direction: column; gap: 14px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px 18px 16px;
}
.card.start {
  background:
    linear-gradient(180deg, rgba(215, 235, 230, 0.65), rgba(250, 246, 239, 0.2) 70%),
    var(--card);
}

.sec-head, .card-head {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}
.num {
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--ink);
  color: #f6f0e6;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.num.quiet { background: var(--teal); }
h2 {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 560;
  letter-spacing: -0.02em;
}
.explain { color: var(--muted); font-size: 14.5px; margin-top: 3px; max-width: 62ch; }
.explain strong { color: var(--ink); font-weight: 650; }

.templates {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.template {
  text-align: left;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.45);
  border-radius: 12px;
  padding: 10px 12px;
}
.template:hover, .template[aria-pressed="true"] {
  border-color: var(--ink);
  background: white;
}
.template b { display: block; font-size: 14px; }
.template span { display: block; color: var(--muted); font-size: 12.5px; margin-top: 2px; }

.field { position: relative; }
.field input[type="search"],
.field input[type="text"],
.text-input,
.sentence {
  width: 100%;
  border: 1px solid var(--line);
  background: white;
  border-radius: 12px;
  padding: 11px 12px;
  outline: none;
}
.field input:focus, .text-input:focus, .sentence:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(29, 101, 95, 0.15);
}
.combo-menu {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  margin: 0;
  padding: 6px;
  list-style: none;
  background: white;
  border: 1px solid var(--ink);
  border-radius: 12px;
  max-height: 280px;
  overflow: auto;
  box-shadow: var(--shadow);
}
.combo-menu[hidden] { display: none; }
.combo-menu li { border-radius: 8px; padding: 8px 8px; }
.combo-menu li[role="option"] { cursor: pointer; }
.combo-menu li.active, .combo-menu li[role="option"]:hover { background: var(--teal-soft); }
.combo-empty { color: var(--muted); }
.opt-title { font-weight: 650; }
.opt-sub { color: var(--muted); font-size: 12.5px; }

.choice {
  margin-top: 10px;
  border: 1px dashed var(--line);
  border-radius: 14px;
  padding: 12px;
  background: rgba(255, 255, 255, 0.55);
}
.choice h3 { font-size: 18px; font-family: var(--serif); font-weight: 560; }
.meta { color: var(--muted); font-size: 13.5px; margin-top: 4px; }
.token {
  font-family: var(--mono);
  font-size: 12.5px;
  background: #f3ecdf;
  border-radius: 999px;
  padding: 2px 8px;
}
.warn {
  margin-top: 8px;
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 10px;
  padding: 8px 10px;
  font-size: 13.5px;
}
.row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.row + .row, .choice .row, .controls { margin-top: 10px; }
.inline-check { display: flex; gap: 8px; align-items: center; color: var(--muted); font-size: 14px; }

.btn, .chip, .tag, .source-btn {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 6px 11px;
  font-size: 14px;
}
.btn.primary, #copy-btn {
  background: var(--cel);
  border-color: var(--cel-deep);
  color: white;
  font-weight: 650;
}
.btn.primary:hover, #copy-btn:hover { background: var(--cel-deep); }
.btn.ghost { background: transparent; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.chip {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  background: #f6e4dc;
  border-color: #e4c4b8;
}
.chip button {
  border: 0;
  background: transparent;
  padding: 0 2px;
  font-size: 16px;
  line-height: 1;
}
.badge {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--teal);
}
.badge.manual { color: var(--cel-deep); }
.badge.none { color: var(--muted); }

.designer-picks { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.year-grid {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  align-items: center;
}

.mode-switch { display: flex; gap: 6px; margin-bottom: 10px; }
.mode-switch button, .designer-picks button {
  border: 1px solid var(--line);
  background: white;
  border-radius: 999px;
  padding: 6px 11px;
}
.mode-switch button[aria-pressed="true"],
.designer-picks button[aria-pressed="true"] {
  background: var(--ink);
  color: white;
  border-color: var(--ink);
}
.dock summary { cursor: pointer; color: #d9cfc3; margin-top: 10px; }
#token-count { color: #cbbbaa; font-size: 13px; margin-left: auto; }
.sentence { min-height: 88px; resize: vertical; }
.sentence:disabled, .tag:disabled { opacity: 0.45; }

.tag-board { display: flex; flex-direction: column; gap: 12px; margin-top: 12px; }
.tag-group h3 { font-size: 15px; margin-bottom: 2px; }
.tag-group p { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag[aria-pressed="true"] {
  background: #e7dff3;
  border-color: #b9a6d4;
}
.tag.dim { opacity: 0.55; }
.tag.conflict { box-shadow: inset 0 0 0 1px var(--warn); }
.source-btn[aria-pressed="true"] {
  background: #e4efd4;
  border-color: #8eaa62;
}
.quality-grid { display: flex; flex-direction: column; gap: 12px; }
.quality-grid h3 { font-size: 15px; margin-bottom: 6px; }

.dock {
  position: sticky;
  top: 16px;
  background: var(--dock);
  color: var(--dock-text);
  border-radius: 20px;
  padding: 16px;
  box-shadow: 0 20px 50px rgba(38, 31, 27, 0.25);
}
.dock h2 { color: white; font-size: 28px; }
.dock .explain { color: #d9cfc3; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0; min-height: 28px; }
.chips button {
  border: 0;
  border-radius: 999px;
  padding: 4px 8px;
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink);
  cursor: pointer;
}
.k-prefix { background: #efe6d6; }
.k-year, .k-decade { background: #f0e0bc; }
.k-character { background: #f3d2c6; }
.k-series { background: #d5e6e2; }
.k-description { background: #e3dced; }
.k-source { background: #dbe6c4; }
.k-designer { background: #f4ddb4; }
.k-quality { background: #f0cfc0; }
#caption-text {
  width: 100%;
  min-height: 132px;
  resize: vertical;
  border: 0;
  border-radius: 12px;
  padding: 12px;
  background: #140f0d;
  color: #f7f1e7;
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.55;
}
.dock-actions { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
#copy-status { color: #efc7b8; font-size: 13px; }
.why {
  margin-top: 10px;
  color: #efe4d6;
  font-size: 13.5px;
  min-height: 2.6em;
}
.slots { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 13px; }
.slots th, .slots td { text-align: left; padding: 5px 0; vertical-align: top; border-top: 1px solid rgba(246, 240, 230, 0.12); }
.slots th { color: #cbbbaa; font-weight: 600; width: 34%; }
.slots td { font-family: var(--mono); font-size: 12px; }
.slots td.empty { color: #9c8f83; font-family: var(--sans); font-style: italic; }

.foot {
  color: var(--muted);
  font-size: 13px;
  padding: 0 0 28px;
}
.foot a { color: var(--teal); }
.error {
  background: #f8d7cc;
  border: 1px solid #e0a08e;
  padding: 12px 14px;
  border-radius: 12px;
}

@media (max-width: 980px) {
  .top { flex-direction: column; align-items: flex-start; }
  h1 { font-size: 38px; }
  .layout { grid-template-columns: 1fr; padding-bottom: 268px; }
  .card, .field input, .text-input { scroll-margin-bottom: 268px; }
  .dock {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 10px;
    top: auto;
    z-index: 30;
    max-height: 248px;
    overflow: auto;
    padding: 12px 14px;
  }
  .dock h2 { font-size: 20px; }
  .dock .explain { display: none; }
  .chips { margin: 8px 0; }
  #caption-text {
    min-height: 0;
    height: calc(1.55em * 3 + 16px);
    resize: none;
  }
  .why { min-height: 0; margin-top: 8px; }
  .templates { grid-template-columns: 1fr; }
  .year-grid { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .templates { grid-template-columns: 1fr; }
  .wrap { width: min(1180px, calc(100% - 20px)); }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
}
:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

.views {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 auto 16px;
}
.views button {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.55);
  border-radius: 999px;
  padding: 8px 14px;
  font-weight: 650;
}
.views button[aria-pressed="true"] {
  background: var(--ink);
  color: #f6f0e6;
  border-color: var(--ink);
}
#form-stack, #index-panel, #cast-panel, #cast-dock, .dock { min-width: 0; }
.quick-only { display: none; }
#tag-filter { margin-top: 4px; }
.extra-label { display: block; margin-top: 12px; }

body[data-view="quick"] #form-stack {
  display: block;
  column-count: 2;
  column-gap: 12px;
  column-fill: balance;
}
body[data-view="quick"] #form-stack > * {
  break-inside: avoid;
  page-break-inside: avoid;
  margin: 0 0 8px;
}
body[data-view="quick"] #sec-start {
  column-span: all;
  margin-bottom: 8px;
}
body[data-view="quick"] #form-stack .explain,
body[data-view="quick"] #form-stack .num,
body[data-view="quick"] #form-stack .step-only,
body[data-view="quick"] .template span { display: none; }
body[data-view="quick"] .quick-only { display: block; }
body[data-view="quick"] .quick-only[hidden] { display: none; }
body[data-view="quick"] #sec-start { padding: 12px 14px; }
body[data-view="quick"] #sec-start h2 { font-size: 22px; }
body[data-view="quick"] .card.slot {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  align-items: start;
  padding: 8px 12px;
  border-radius: 14px;
}
body[data-view="quick"] .card.slot .sec-head { margin: 0; }
body[data-view="quick"] .card.slot h2 {
  font-family: var(--sans);
  font-size: 13px;
  font-weight: 680;
  letter-spacing: 0;
  padding-top: 0;
}
body[data-view="quick"] #series-card .meta,
body[data-view="quick"] #series-card .warn,
body[data-view="quick"] #series-card .badge,
body[data-view="quick"] #designer-card .meta,
body[data-view="quick"] #designer-card .badge { display: none; }
body[data-view="quick"] #series-card .choice,
body[data-view="quick"] #designer-card .choice {
  margin-top: 6px;
  padding: 0;
  border: 0;
  background: transparent;
}
body[data-view="quick"] #series-card h3,
body[data-view="quick"] #designer-card h3 { font-size: 16px; }
body[data-view="quick"] #quality-board h3 { font-size: 13px; margin: 0 0 4px; }
body[data-view="quick"] #quality-board .meta { display: none; }
body[data-view="quick"] .quality-grid { gap: 8px; }
body[data-view="quick"] .year-grid { grid-template-columns: 92px minmax(0, 1fr); }

#index-filter { margin: 10px 0 12px; }
.az {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  position: sticky;
  top: 0;
  z-index: 3;
  background: var(--card);
  padding: 2px 0 8px;
}
.az button, .index-hit {
  border: 1px solid var(--line);
  background: white;
}
.az button {
  min-width: 28px;
  height: 28px;
  border-radius: 8px;
  padding: 0 6px;
  font-size: 13px;
  font-weight: 700;
}
.az button:disabled { opacity: 0.35; cursor: default; }
.letter-block h3 {
  font-family: var(--serif);
  font-size: 22px;
  margin: 16px 0 6px;
  scroll-margin-top: 46px;
}
.index-hit {
  width: 100%;
  text-align: left;
  border-color: transparent;
  background: transparent;
  border-radius: 10px;
  padding: 7px 8px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}
.index-hit b { font-weight: 650; }
.index-hit span { color: var(--muted); font-size: 13px; white-space: nowrap; }
.index-hit:hover, .index-hit[aria-pressed="true"] {
  background: white;
  border-color: var(--ink);
}
.cast-fold { margin: 2px 8px 10px 18px; }
.cast-fold-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 14px;
}
.cast-fold-list li { display: flex; gap: 8px; align-items: center; min-width: 0; }
.cast-fold-list img, .cast-ph {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  object-fit: cover;
  flex: none;
  background: #e7dccb;
}
.cast-ph {
  display: grid;
  place-items: center;
  font-weight: 700;
  color: var(--muted);
}
.cast-id { min-width: 0; }
.cast-fold-list a, .cast-name, .cast-row a { color: var(--ink); font-weight: 650; }
.cast-fold .sub, .cast-row .sub { color: var(--muted); font-size: 12px; }
.shot-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex: none;
}
.opt-sub .shot-dot { margin-right: 6px; }
.shot-count {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 12px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  line-height: 1.4;
}
.cast-fold-list .shot-count { margin-left: auto; }
#cast-filter { margin: 10px 0 4px; }
#cast-status { min-height: 1.2em; }
#cast-list { margin-top: 8px; }
.cast-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  padding: 8px 4px 8px 10px;
  border-bottom: 1px solid var(--line);
  border-left: 4px solid #2b6cb8;
  scroll-margin-top: 96px;
}
.cast-row img, .cast-row .cast-ph {
  width: 56px;
  height: 56px;
  border-radius: 10px;
  object-fit: cover;
  background: #e7dccb;
}
.cast-row .who {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 8px;
  align-items: center;
  justify-content: space-between;
}
.cast-row .cast-add { font-size: 13px; padding: 4px 10px; }
.cast-rail {
  position: sticky;
  top: 12px;
  align-self: start;
}
.cast-rail h2 { font-size: 22px; }
.timeline-end {
  margin-top: 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: center;
}
.timeline-track {
  position: relative;
  height: clamp(200px, calc(100vh - 430px), 480px);
  width: 28px;
  margin: 10px auto;
  border-radius: 999px;
  background: linear-gradient(to top, #2b6cb8 0%, #e2b03a 50%, #c23b2e 100%);
  touch-action: none;
  cursor: pointer;
}
.timeline-thumb {
  position: absolute;
  left: 50%;
  top: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid white;
  box-shadow: 0 1px 4px rgba(35, 30, 25, 0.35);
  background: #c23b2e;
  transform: translate(-50%, -50%);
  pointer-events: none;
}
#cast-readout { text-align: center; }
#info-dock { max-height: calc(100vh - 28px); overflow: auto; }
#info-dock .meta, #info-dock .people .sub { color: #d9cfc3; }
#info-dock .warn { background: transparent; color: #f0d2b0; padding: 8px 0; }
.dock a { color: #f6c7b6; }
.dock a:hover { color: white; }
.people { list-style: none; margin: 8px 0 0; padding: 0; }
.people li {
  padding: 8px 0;
  border-top: 1px solid rgba(246, 240, 230, 0.12);
}
.people .who { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.people .sub { font-size: 12.5px; }
#info-dock .btn.primary {
  background: var(--cel);
  border-color: var(--cel-deep);
  color: white;
  font-weight: 650;
  margin-top: 12px;
}
#info-dock h3 {
  margin-top: 16px;
  font-family: var(--serif);
  font-weight: 560;
  font-size: 20px;
}

@media (max-width: 980px) {
  body[data-view="index"] .layout,
  body[data-view="characters"] .layout { padding-bottom: 28px; }
  body[data-view="index"] #info-dock {
    position: static;
    max-height: none;
    margin-top: 12px;
  }
  body[data-view="characters"] #cast-dock {
    order: -1;
    position: sticky;
    top: 0;
    z-index: 4;
  }
  body[data-view="characters"] .timeline-track {
    height: 28px;
    width: 100%;
    background: linear-gradient(to right, #2b6cb8 0%, #e2b03a 50%, #c23b2e 100%);
  }
  body[data-view="quick"] .templates { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 760px) {
  body[data-view="quick"] #form-stack { column-count: 1; }
  .cast-fold-list { grid-template-columns: 1fr; }
}
