/* ============================================================================
   Chariot Jam: The Stolen Dawn
   Midnight marble, bronze inlay, one warm light.  Layout rule: the app is a
   fixed three-row column (hud / stage / dock) and the stage is the only row
   that flexes, so the canvas always gets a real box to measure — never `height`
   on a flex child that also has `flex:1`.
   ========================================================================= */

:root {
  --night: #05060f;
  --night-2: #0a0d1e;
  --panel: rgba(17, 21, 40, .94);
  --panel-2: rgba(24, 29, 52, .96);
  --line: rgba(216, 178, 115, .28);
  --line-soft: rgba(216, 178, 115, .13);
  --gold: #d8b273;
  --gold-hi: #ffe9b8;
  --ink: #ece6d8;
  --ink-soft: #b9b3a6;
  --ink-dim: #7d7a72;
  --dawn: #ffcf7d;
  --seal: #8b6bff;
  --hud: 58px;
  --dock: 66px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--night);
  color: var(--ink);
  font-family: var(--sans);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
body { overflow: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; }

#app {
  position: fixed; inset: 0;
  display: flex; flex-direction: column;
  background:
    radial-gradient(120% 80% at 50% 0%, #151b38 0%, #0a0d1e 45%, #05060f 100%);
}

/* ------------------------------------------------------------------- hud */
.hud {
  flex: 0 0 var(--hud);
  height: var(--hud);
  display: flex; align-items: center; gap: 10px;
  padding: 0 12px;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, rgba(10, 13, 30, .92), rgba(8, 10, 24, .72));
  backdrop-filter: blur(8px);
  z-index: 4;
}
.hud-btn {
  flex: 0 0 auto;
  width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid var(--line-soft);
  background: rgba(255, 255, 255, .03);
  color: var(--gold);
  font-size: 20px; line-height: 1; cursor: pointer;
  transition: background .15s, border-color .15s, transform .1s;
}
.hud-btn:hover { background: rgba(216, 178, 115, .12); border-color: var(--line); }
.hud-btn:active { transform: scale(.94); }
.hud-mid { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; line-height: 1.15; }
.hud-act {
  font-size: 9.5px; letter-spacing: .16em; text-transform: uppercase;
  color: var(--gold); opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hud-name {
  font-family: var(--serif); font-size: 16px; color: var(--ink);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.hud-right { flex: 0 0 auto; display: flex; gap: 14px; align-items: center; }
.hud-stat { display: flex; flex-direction: column; align-items: center; min-width: 38px; }
.hud-stat b { font-family: var(--serif); font-size: 17px; color: var(--gold-hi); font-weight: 600; }
.hud-stat span { font-size: 8.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim); }
.hud-stat.low b { color: #ff8f7a; }

/* ----------------------------------------------------------------- stage */
.stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  overflow: hidden;
}
#cv {
  display: block;
  position: absolute; inset: 0;
  touch-action: none;
  cursor: grab;
}
#cv.dragging { cursor: grabbing; }

.toast {
  position: absolute; left: 50%; bottom: 14px;
  transform: translate(-50%, 12px);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(10, 12, 26, .92);
  border: 1px solid var(--line);
  color: var(--gold-hi);
  font-size: 12.5px; letter-spacing: .02em;
  opacity: 0; pointer-events: none;
  transition: opacity .22s, transform .22s;
  white-space: nowrap;
  z-index: 3;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ------------------------------------------------------------------ dock */
.dock {
  flex: 0 0 var(--dock);
  height: var(--dock);
  display: grid; grid-template-columns: repeat(4, 1fr);
  border-top: 1px solid var(--line-soft);
  background: linear-gradient(0deg, rgba(8, 10, 24, .96), rgba(10, 13, 30, .78));
  backdrop-filter: blur(8px);
  z-index: 4;
}
.dock-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  background: none; border: 0; border-right: 1px solid rgba(255, 255, 255, .04);
  color: var(--ink-soft); cursor: pointer;
  transition: color .15s, background .15s;
}
.dock-btn:last-child { border-right: 0; }
.dock-btn:hover { color: var(--gold-hi); background: rgba(216, 178, 115, .06); }
.dock-btn:active { background: rgba(216, 178, 115, .12); }
.dock-btn.off { opacity: .38; }
.di { font-size: 16px; line-height: 1; color: var(--gold); }
.dl { font-size: 10px; letter-spacing: .08em; text-transform: uppercase; }
.dl i { font-style: normal; opacity: .7; }

/* --------------------------------------------------------------- screens */
.screen {
  position: absolute; inset: 0;
  display: none;
  align-items: center; justify-content: center;
  padding: 18px;
  background: radial-gradient(90% 70% at 50% 20%, rgba(12, 16, 36, .72), rgba(3, 4, 12, .93));
  backdrop-filter: blur(7px);
  z-index: 10;
  overflow: auto;
}
.screen.on { display: flex; }

.panel {
  width: min(560px, 100%);
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 24px 24px 20px;
  border-radius: 18px;
  border: 1px solid var(--line);
  background:
    linear-gradient(180deg, rgba(30, 36, 64, .96), rgba(14, 17, 34, .98));
  box-shadow: 0 30px 80px rgba(0, 0, 0, .6), inset 0 1px 0 rgba(255, 255, 255, .06);
  position: relative;
  animation: panel-in .32s cubic-bezier(.2, .9, .25, 1) both;
}
.panel::before {
  content: ""; position: absolute; inset: 6px; border-radius: 13px;
  border: 1px solid rgba(216, 178, 115, .10); pointer-events: none;
}
@keyframes panel-in {
  from { opacity: 0; transform: translateY(10px) scale(.985); }
  to { opacity: 1; transform: none; }
}
.panel-wide { width: min(760px, 100%); }
.panel-small { width: min(420px, 100%); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.panel-title { font-family: var(--serif); font-size: 26px; margin: 2px 0 0; font-weight: 500; letter-spacing: .01em; }
.panel-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.panel-note { font-size: 12px; color: var(--ink-dim); margin: 12px 0 0; line-height: 1.6; }

.kicker {
  margin: 0; font-size: 9.5px; letter-spacing: .2em; text-transform: uppercase;
  color: var(--gold); opacity: .9; font-weight: 600;
}

/* --------------------------------------------------------------- buttons */
.btn {
  appearance: none;
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid rgba(216, 178, 115, .30);
  background: linear-gradient(180deg, rgba(255, 255, 255, .07), rgba(255, 255, 255, .015));
  color: var(--ink);
  font-size: 13.5px; letter-spacing: .02em;
  cursor: pointer;
  transition: transform .1s, border-color .15s, background .18s, color .15s;
}
.btn:hover { border-color: rgba(216, 178, 115, .65); background: rgba(216, 178, 115, .10); color: var(--gold-hi); }
.btn:active { transform: translateY(1px) scale(.99); }
.btn-primary {
  border-color: rgba(255, 214, 150, .6);
  background: linear-gradient(180deg, #e8c284, #b98a45);
  color: #1d1408;
  font-weight: 700;
  box-shadow: 0 6px 22px rgba(220, 170, 90, .25);
}
.btn-primary:hover { background: linear-gradient(180deg, #ffd79a, #c9974f); color: #1a1206; }
.btn-ghost { background: transparent; border-color: rgba(255, 255, 255, .12); color: var(--ink-soft); }
.linkbtn {
  background: none; border: 0; padding: 0; color: var(--gold);
  text-decoration: underline; text-underline-offset: 3px; cursor: pointer; font-size: 12.5px;
}

/* ------------------------------------------------------------ title page */
#sTitle {
  background:
    radial-gradient(90% 70% at 50% 12%, rgba(40, 28, 18, .55), rgba(6, 7, 18, .96) 60%, #04050d 100%);
  backdrop-filter: none;
}
.title-art { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.sun-ring {
  position: absolute; left: 50%; top: -14vmin; width: 78vmin; height: 78vmin;
  transform: translateX(-50%);
  border-radius: 50%;
  border: 1px solid rgba(255, 205, 130, .14);
  box-shadow: inset 0 0 80px rgba(255, 170, 80, .10);
  animation: spin 90s linear infinite;
}
.sun-ring::before, .sun-ring::after {
  content: ""; position: absolute; inset: 8%; border-radius: 50%;
  border: 1px dashed rgba(255, 205, 130, .10);
}
.sun-ring::after { inset: 18%; border-style: solid; border-color: rgba(255, 205, 130, .07); }
.sun-core {
  position: absolute; left: 50%; top: -30vmin; width: 46vmin; height: 46vmin;
  transform: translateX(-50%);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 226, 170, .30), rgba(255, 160, 70, .10) 45%, rgba(255, 140, 50, 0) 70%);
  filter: blur(6px);
}
@keyframes spin { to { transform: translateX(-50%) rotate(360deg); } }

.title-inner {
  position: relative; text-align: center; max-width: 520px; padding: 10px 8px;
  animation: panel-in .5s cubic-bezier(.2, .9, .25, 1) both;
}
.logo {
  font-family: var(--serif);
  font-size: clamp(44px, 12vw, 78px);
  font-weight: 500; letter-spacing: .02em; line-height: .95;
  margin: 10px 0 2px;
  color: #f3e7cc;
  text-shadow: 0 4px 30px rgba(255, 180, 90, .28);
}
.logo span { color: var(--gold); font-style: italic; margin-left: .08em; }
.subtitle {
  font-family: var(--serif); font-style: italic; font-size: clamp(15px, 4vw, 20px);
  color: var(--gold); letter-spacing: .16em; text-transform: uppercase;
  margin: 0 0 18px;
}
.lede { font-size: 14px; line-height: 1.65; color: var(--ink-soft); margin: 0 auto 26px; max-width: 400px; }
.title-actions { display: flex; flex-direction: column; gap: 9px; align-items: center; }
.title-actions .btn { width: min(300px, 82vw); }
.title-meta {
  margin-top: 22px; font-size: 12px; color: var(--ink-dim);
  display: flex; gap: 8px; justify-content: center; align-items: center; flex-wrap: wrap;
}
.title-meta .dot { opacity: .5; }

/* ---------------------------------------------------------------- acts */
.acts { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.act-tab {
  padding: 7px 12px; border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, .10);
  background: rgba(255, 255, 255, .02);
  font-size: 11px; letter-spacing: .06em; text-transform: uppercase;
  color: var(--ink-soft); cursor: pointer; transition: .15s;
}
.act-tab:hover { color: var(--gold-hi); border-color: var(--line); }
.act-tab.on { background: rgba(216, 178, 115, .16); border-color: var(--line); color: var(--gold-hi); }

.chapter-grid { display: grid; grid-template-columns: repeat(6, 1fr); gap: 8px; }
.ch {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 11px;
  border: 1px solid rgba(255, 255, 255, .09);
  background: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .01));
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  cursor: pointer; transition: .15s; gap: 2px;
  padding: 2px;
}
.ch:hover { border-color: rgba(216, 178, 115, .55); background: rgba(216, 178, 115, .09); }
.ch b { font-family: var(--serif); font-size: 17px; font-weight: 500; color: var(--ink); }
.ch .ch-stars { font-size: 8px; letter-spacing: 1px; color: rgba(255, 255, 255, .16); line-height: 1; }
.ch .ch-stars i { font-style: normal; }
.ch.done .ch-stars i.on { color: var(--gold); }
.ch.locked { cursor: not-allowed; opacity: .34; }
.ch.locked b { color: var(--ink-dim); }
.ch.act-2 { background: linear-gradient(180deg, rgba(120, 160, 220, .10), rgba(255, 255, 255, .01)); }
.ch.act-3 { background: linear-gradient(180deg, rgba(139, 107, 255, .10), rgba(255, 255, 255, .01)); }
.ch.act-4 { background: linear-gradient(180deg, rgba(255, 110, 90, .09), rgba(255, 255, 255, .01)); }

/* ---------------------------------------------------------------- brief */
.brief-title { font-family: var(--serif); font-size: clamp(26px, 6vw, 34px); font-weight: 500; margin: 6px 0 12px; }
.brief-story { font-size: 14.5px; line-height: 1.7; color: var(--ink-soft); margin: 0 0 18px; }
.objectives { list-style: none; padding: 0; margin: 0 0 18px; display: flex; flex-direction: column; gap: 8px; }
.objectives li {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 13px; color: var(--ink-soft); line-height: 1.5;
}
.objectives li .ob {
  flex: 0 0 auto; width: 20px; height: 20px; border-radius: 50%;
  border: 1px solid var(--line); color: var(--gold);
  display: flex; align-items: center; justify-content: center; font-size: 10px;
}
.brief-row { display: flex; gap: 10px; }
.brief-stat {
  flex: 1; padding: 10px 6px; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .07);
  background: rgba(0, 0, 0, .18);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.brief-stat b { font-family: var(--serif); font-size: 20px; color: var(--gold-hi); font-weight: 500; }
.brief-stat span { font-size: 9px; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-dim); }

/* --------------------------------------------------------------- result */
.res-title { font-family: var(--serif); font-size: clamp(24px, 6vw, 32px); font-weight: 500; margin: 6px 0 6px; }
.stars { display: flex; gap: 8px; justify-content: center; margin: 14px 0 8px; }
.stars i {
  font-style: normal; font-size: 34px; color: rgba(255, 255, 255, .12);
  transition: color .3s, transform .3s, text-shadow .3s;
}
.stars i.on { color: var(--gold); text-shadow: 0 0 18px rgba(255, 200, 110, .55); transform: translateY(-2px); }
.res-note { font-size: 13px; color: var(--ink-soft); text-align: center; margin: 4px 0 16px; line-height: 1.6; }
.res-story {
  font-family: var(--serif); font-size: 13.5px; font-style: italic; line-height: 1.7;
  color: var(--ink-soft); text-align: center; margin: 16px 0 0;
  padding-top: 14px; border-top: 1px solid var(--line-soft);
}
.res-story:empty { display: none; }
.panel-result { text-align: center; }
.panel-result .panel-foot { justify-content: center; }
.panel-result .brief-row { text-align: center; }
.pause-list { display: flex; flex-direction: column; gap: 8px; margin-top: 16px; }
.panel-small { text-align: center; }
.panel-small .kicker { text-align: center; }

/* ----------------------------------------------------------------- how */
.how-list { margin: 0 0 16px; padding-left: 20px; display: flex; flex-direction: column; gap: 9px; }
.how-list li { font-size: 13.5px; line-height: 1.6; color: var(--ink-soft); }
.how-list b { color: var(--ink); font-weight: 600; }
.keys { display: flex; flex-wrap: wrap; gap: 8px 16px; font-size: 11.5px; color: var(--ink-dim); }
kbd {
  font: 10.5px/1 var(--sans); padding: 3px 6px; border-radius: 5px;
  border: 1px solid rgba(255, 255, 255, .16); background: rgba(255, 255, 255, .05);
  color: var(--ink-soft); margin-right: 4px;
}

/* ------------------------------------------------------------- a11y/print */
.sr-only {
  position: absolute !important; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
@media (prefers-reduced-motion: reduce) {
  .sun-ring, .panel, .title-inner { animation: none !important; }
}

/* ----------------------------------------------------------------- small */
@media (max-width: 720px) {
  :root { --hud: 52px; --dock: 58px; }
  .hud { padding: 0 8px; gap: 8px; }
  .hud-name { font-size: 14px; }
  .hud-act { font-size: 8.5px; }
  .hud-right { gap: 10px; }
  .hud-stat b { font-size: 15px; }
  .screen { padding: 10px; }
  .panel { padding: 18px 16px 16px; border-radius: 15px; }
  .chapter-grid { grid-template-columns: repeat(5, 1fr); gap: 6px; }
  .ch b { font-size: 15px; }
  .brief-row { gap: 6px; }
  .brief-stat b { font-size: 17px; }
  .stars i { font-size: 28px; }
  .panel-foot { gap: 8px; }
  .panel-foot .btn { padding: 9px 14px; font-size: 12.5px; }
}
@media (max-height: 480px) {
  .panel { max-height: calc(100vh - 16px); padding: 14px 16px; }
  .title-meta { margin-top: 12px; }
  .lede { margin-bottom: 16px; }
}
