:root {
  --ink: #2a1d14;
  --text: #2b2420;
  --muted: #7a6d62;
  --bg-top: #c9e2ee;
  --bg-bottom: #f1efe2;
  --panel: #ffffff;
  --panel-2: #f6f3ec;
  --line: #ddd4c6;
  --blue: #1185fe;
  --blue-dark: #0a63c2;
  --orange: #c2410c;
  --hot-bg: #fff1e6;
  --shadow: 0 2px 0 rgba(42, 29, 20, 0.08), 0 10px 30px rgba(42, 29, 20, 0.12);
  --radius: 14px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ink: #f2e6d8;
    --text: #ece4da;
    --muted: #a99c90;
    --bg-top: #1b2530;
    --bg-bottom: #14110f;
    --panel: #221d1a;
    --panel-2: #2b2522;
    --line: #3d3530;
    --hot-bg: #3a2418;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  background: linear-gradient(180deg, var(--bg-top) 0, var(--bg-bottom) 520px) no-repeat, var(--bg-bottom);
  font: 15px/1.5 Verdana, Geneva, Tahoma, sans-serif;
}

a { color: var(--blue); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.muted { color: var(--muted); font-size: 0.85em; font-weight: normal; }

/* ---------- masthead */

.masthead {
  max-width: 1040px;
  margin: 0 auto;
  padding: 22px 16px 6px;
  display: flex;
  align-items: center;
  gap: 14px;
}
#logo {
  width: 84px; height: 84px;
  border-radius: 50%;
  border: 3px solid var(--ink);
  background: #cfe3ee;
  flex: none;
}
.masthead h1 {
  margin: 0;
  font-family: "Arial Black", "Arial Bold", Gadget, Arial, sans-serif;
  font-size: clamp(26px, 5vw, 44px);
  line-height: 1.05;
  letter-spacing: -0.5px;
  color: var(--ink);
  text-shadow: 0 2px 0 rgba(255, 255, 255, 0.55);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .masthead h1 { text-shadow: 0 2px 0 rgba(0, 0, 0, 0.6); }
}
.tagline { margin: 4px 0 0; color: var(--muted); }

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 10px 16px 30px;
}

/* ---------- buttons and inputs */

.btn {
  font: bold 15px/1 Verdana, Geneva, Tahoma, sans-serif;
  color: var(--ink);
  padding: 11px 16px;
  border-radius: 999px;
  border: 1px solid #b9ab98;
  background: linear-gradient(#ffffff, #ece4d6);
  box-shadow: inset 0 1px 0 #fff, 0 1px 1px rgba(0, 0, 0, 0.08);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: linear-gradient(#ffffff, #e3d8c6); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-primary {
  color: #fff;
  border-color: var(--blue-dark);
  background: linear-gradient(#45a3ff, var(--blue) 55%, #0b72de);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.45), 0 1px 2px rgba(0, 0, 0, 0.2);
  text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25);
}
.btn-primary:hover { background: linear-gradient(#5aaeff, #1a8cff 55%, #0a69cc); }
.btn-small { padding: 8px 12px; font-size: 13px; }
.btn.is-on { color: #fff; border-color: #9b1c1c; background: linear-gradient(#ef4444, #b91c1c); text-shadow: none; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .btn:not(.btn-primary):not(.is-on) {
    color: var(--text);
    border-color: #4a403a;
    background: linear-gradient(#3a322d, #2a2420);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  }
}

input[type="text"], input[type="password"], select {
  font: 15px Verdana, Geneva, Tahoma, sans-serif;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  width: 100%;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .ctl:focus-visible, summary:focus-visible {
  outline: 3px solid rgba(17, 133, 254, 0.45);
  outline-offset: 2px;
}

/* ---------- ask form */

.ask {
  display: flex;
  gap: 8px;
  background: var(--panel);
  padding: 8px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  border: 1px solid var(--line);
}
.ask input {
  border: 0;
  border-radius: 999px;
  padding: 10px 14px;
  font-size: 16px;
  min-width: 0;
  flex: 1;
  background: transparent;
}
.ask input:focus-visible { outline-offset: -2px; }

.status { min-height: 1.5em; margin: 10px 6px 4px; color: var(--muted); }
.status.error { color: #b91c1c; }

/* ---------- thread finder */

.finder {
  background: var(--panel);
  border: 2px solid var(--blue);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin: 6px 0 16px;
  box-shadow: var(--shadow);
}
.finder h2 { margin: 0 0 8px; font-size: 17px; color: var(--ink); }
.finder-steps { list-style: none; margin: 0 0 6px; padding: 0; display: grid; gap: 6px; }
.finder-steps li { display: grid; grid-template-columns: 22px minmax(0, 1fr); gap: 8px; align-items: start; }
.finder-steps li::before { content: ""; width: 16px; height: 16px; margin-top: 2px; border-radius: 50%; box-sizing: border-box; }
.finder-steps li.doing::before { border: 3px solid rgba(17, 133, 254, 0.25); border-top-color: var(--blue); animation: spin 0.8s linear infinite; }
.finder-steps li.done::before { content: "✓"; color: #15803d; font-weight: bold; width: auto; height: auto; margin: 0; }
.finder-steps li.fail::before { content: "!"; color: #b91c1c; font-weight: bold; width: auto; height: auto; margin: 0; }
.finder-steps li.wait::before { content: "⏳"; width: auto; height: auto; margin: 0; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .finder-steps li.doing::before { animation: none; border-color: var(--blue); } }
.finder-list { list-style: none; margin: 0 0 8px; padding: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; }
.finder-list li { min-width: 0; }
.finder-list button {
  width: 100%;
  text-align: left;
  font: 14px/1.4 Verdana, Geneva, Tahoma, sans-serif;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  cursor: pointer;
  display: block;
  overflow: hidden;
}
.finder-list button:hover { border-color: var(--blue); }
.finder-list .snip { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.finder-list .meta { display: block; font-size: 12px; color: var(--muted); }

.generic { font-size: 13px; color: var(--muted); margin: 0 6px 12px; display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.generic code { font-size: 12.5px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 2px 6px; word-break: break-all; }

/* ---------- options */

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 6px 0 16px;
  box-shadow: var(--shadow);
}
.panel > summary {
  cursor: pointer;
  padding: 10px 16px;
  font-weight: bold;
  color: var(--ink);
  list-style: none;
}
.panel > summary::-webkit-details-marker { display: none; }
.panel > summary::before { content: "▸ "; color: var(--muted); }
.panel[open] > summary::before { content: "▾ "; }

.opt-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  padding: 4px 16px 16px;
}
.opt-grid h3 { margin: 4px 0 8px; font-size: 15px; color: var(--ink); }
.opt-grid label { display: block; margin: 8px 0; font-size: 14px; }
.opt-grid label > input[type="text"], .opt-grid label > input[type="password"], .opt-grid label > select { margin-top: 4px; }
.opt-grid .check { display: flex; gap: 8px; align-items: baseline; }
.help { font-size: 12.5px; color: var(--muted); margin: 6px 0; }
fieldset.radios { border: 0; padding: 0; margin: 0 0 6px; }
fieldset.radios legend { font-size: 14px; padding: 0; margin-bottom: 2px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 8px; }
.row.end { justify-content: flex-end; }
#model-row[hidden] { display: none; }
.subhead { font-size: 14px; margin: 12px 0 4px; }

/* ---------- player */

.player { margin-top: 6px; }
.screen {
  position: relative;
  border: 4px solid var(--ink);
  border-radius: 12px 12px 0 0;
  overflow: hidden;
  background: #bcd9e8;
  line-height: 0;
}
#stage { width: 100%; height: auto; display: block; aspect-ratio: 16 / 9; }

.big-play {
  position: absolute;
  left: 50%; top: 42%;
  width: 96px; height: 96px;
  margin: -48px 0 0 -48px;
  border-radius: 50%;
  border: 4px solid var(--ink);
  background: linear-gradient(#45a3ff, var(--blue) 55%, #0b72de);
  box-shadow: 0 6px 0 rgba(42, 29, 20, 0.35);
  cursor: pointer;
  display: grid;
  place-items: center;
}
.big-play svg { width: 54px; height: 54px; fill: #fff; margin-left: 6px; }
.big-play:hover { transform: scale(1.05); }
.big-play[hidden] { display: none; }

.rec-badge {
  position: absolute; top: 10px; right: 12px;
  font: bold 14px/1 Arial, sans-serif;
  color: #fff; background: #dc2626;
  padding: 6px 10px; border-radius: 6px;
  animation: blink 1s steps(2, start) infinite;
}
@keyframes blink { to { visibility: hidden; } }
.rec-badge[hidden] { display: none; }

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 4px solid var(--ink);
  border-top: 0;
  border-radius: 0 0 12px 12px;
  background: linear-gradient(#f7f4ee, #e2dacd);
  flex-wrap: wrap;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .controls { background: linear-gradient(#332b27, #241f1c); border-color: #0d0a08; }
  :root:not([data-theme="light"]) .screen { border-color: #0d0a08; }
}
.ctl {
  width: 40px; height: 40px;
  border-radius: 50%;
  border: 1px solid #b9ab98;
  background: linear-gradient(#ffffff, #e6ddce);
  display: grid; place-items: center;
  cursor: pointer;
  padding: 0;
  flex: none;
}
.ctl svg { width: 22px; height: 22px; fill: var(--ink); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .ctl { background: linear-gradient(#433a34, #2c2622); border-color: #4a403a; }
  :root:not([data-theme="light"]) .ctl svg { fill: #f2e6d8; }
}
.ctl-main { width: 48px; height: 48px; }
.ctl-main svg { width: 28px; height: 28px; }
.ctl .i-pause, .ctl.is-playing .i-play { display: none; }
.ctl.is-playing .i-pause { display: block; }
.ctl .i-muted, .ctl.is-muted .i-sound { display: none; }
.ctl.is-muted .i-muted { display: block; }

#scrub { flex: 1; min-width: 120px; accent-color: var(--blue); }
.counter { font: bold 13px Verdana, sans-serif; color: var(--muted); min-width: 64px; text-align: center; }

/* ---------- thread map and cast */

.below { display: grid; gap: 18px; margin-top: 20px; }
.below h2 { font-size: 17px; margin: 0 0 10px; color: var(--ink); }
.map-wrap, .cast-wrap {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.map {
  overflow: auto;
  max-height: 560px;
  border-radius: 10px;
  background: var(--panel-2);
  line-height: 0;
  text-align: center;
  overscroll-behavior: contain;
}
.map svg { display: inline-block; text-align: left; }
.tm-edge { fill: none; stroke: #a8a29e; stroke-width: 2.5; transition: stroke 0.2s, opacity 0.2s; }
.tm-edge.attack { stroke: var(--orange); stroke-width: 3.5; }
.tm-edge.current { stroke: var(--blue); stroke-width: 4; }
.tm-edge.upcoming { opacity: 0.45; }
.tm-node { cursor: pointer; outline: none; }
.tm-node image, .tm-node .tm-ring, .tm-node .tm-label { transition: opacity 0.2s; }
.tm-node.upcoming image, .tm-node.upcoming .tm-ring, .tm-node.upcoming .tm-label { opacity: 0.55; }
.tm-ring { fill: none; stroke: var(--ink); stroke-width: 2.5; }
.tm-node.attacked .tm-ring { stroke: var(--orange); stroke-width: 4; }
.tm-halo { fill: none; stroke: transparent; stroke-width: 5; }
.tm-node.current .tm-halo { stroke: var(--blue); animation: halo 1.2s ease-in-out infinite; }
.tm-node:hover .tm-halo, .tm-node:focus-visible .tm-halo { stroke: rgba(17, 133, 254, 0.5); }
.tm-node.current:hover .tm-halo { stroke: var(--blue); }
@keyframes halo { 50% { stroke-width: 8; stroke-opacity: 0.6; } }
@media (prefers-reduced-motion: reduce) { .tm-node.current .tm-halo { animation: none; } }
.tm-label { font: bold 11px Verdana, Geneva, Tahoma, sans-serif; fill: var(--muted); text-anchor: middle; paint-order: stroke; stroke: var(--panel-2); stroke-width: 4px; stroke-linejoin: round; }
.tm-node.current .tm-label { fill: var(--blue); }

.map-key { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 10px 2px 0; font-size: 12.5px; color: var(--muted); }
.map-key span { display: inline-flex; align-items: center; gap: 6px; }
.map-key i { display: inline-block; flex: none; }
.map-key .k-now { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--blue); }
.map-key .k-attack { width: 18px; height: 0; border-top: 3.5px solid var(--orange); }
.map-key .k-target { width: 14px; height: 14px; border-radius: 50%; border: 3px solid var(--orange); }
.map-key .k-next { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink); opacity: 0.4; }

.cast {
  list-style: none; margin: 0; padding: 0;
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  max-height: 420px; overflow: auto;
}
.cast li {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 6px;
  border-radius: 10px;
  background: var(--panel-2);
}
.cast canvas { width: 56px; height: 56px; border-radius: 10px; border: 2px solid var(--ink); }
.cast .who { min-width: 0; }
.cast .name { font-weight: bold; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cast .handle { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badges { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 3px; }
.badge {
  font-size: 11px; font-weight: bold;
  padding: 2px 7px; border-radius: 999px;
  background: #e2e8f0; color: #334155;
}
.badge.hot { background: #fed7aa; color: #9a3412; }
.badge.mob { background: #e7e5e4; color: #44403c; }
.badge.you { background: #facc15; color: #1c1917; }

dialog {
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  max-width: min(460px, calc(100vw - 32px));
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: rgba(20, 14, 10, 0.45); }
dialog h3 { margin-top: 0; }

.reply-preview {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: var(--panel-2);
}
.reply-text { margin: 0 0 10px; font: 16px/1.4 Arial, Helvetica, sans-serif; color: var(--blue); }
.reply-card { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: var(--panel); }
.reply-card img { display: block; width: 100%; height: auto; }
.reply-card-text { display: grid; gap: 2px; padding: 8px 10px; font: 13px/1.35 Arial, Helvetica, sans-serif; }
.reply-card-text small { color: var(--muted); }

.foot {
  max-width: 1040px;
  margin: 0 auto;
  padding: 10px 16px 40px;
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- small screens */

@media (max-width: 820px) {
  .opt-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .masthead { padding-top: 14px; }
  #logo { width: 60px; height: 60px; }
  .ask { flex-wrap: wrap; border-radius: 18px; }
  .ask input { flex-basis: 100%; }
  .ask .btn { flex: 1; }
  .big-play { width: 72px; height: 72px; margin: -36px 0 0 -36px; }
  .big-play svg { width: 40px; height: 40px; }
  .controls { gap: 6px; }
  #scrub { order: 10; flex-basis: 100%; }
}
