:root {
  --void: #070b14;
  --indigo: #121a2e;
  --indigo-mid: #1c2744;
  --parchment: #ebe2d2;
  --parchment-dim: #c9bea8;
  --jade: #3d8fb8;
  --jade-deep: #1e4a6e;
  --gold: #c9a54a;
  --gold-soft: #e6c97a;
  --seal: #c23b22;
  --mist: #8fa3b8;
  --ink: #0e1016;
  --line: rgba(201, 165, 74, 0.35);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --font-display: "Cormorant Garamond", "Times New Roman", serif;
  --font-brush: "IBM Plex Sans", system-ui, sans-serif;
  --font-ui: "IBM Plex Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--void);
  color: var(--parchment);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}
body {
  min-height: 100dvh;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(40, 160, 220, 0.10), transparent 55%),
    radial-gradient(80% 50% at 100% 80%, rgba(255, 140, 40, 0.07), transparent 50%),
    linear-gradient(180deg, #0a1020 0%, var(--void) 40%, #05080f 100%);
}

#app {
  width: 100%;
  max-width: 430px;
  margin: 0 auto;
  padding: 12px 14px calc(20px + var(--safe-b));
}

.top { padding: 8px 2px 12px; }
.eyebrow {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--jade);
  font-weight: 600;
}
.title-en {
  margin: 4px 0 6px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 28px;
  letter-spacing: 0.02em;
  color: var(--parchment);
}
.sub {
  margin: 0;
  color: var(--parchment-dim);
  font-size: 13.5px;
}

.chapters {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 8px 0 14px;
}
.chapters button {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--indigo);
  color: var(--parchment-dim);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  min-height: 44px;
  min-width: 44px;
  border-radius: 6px;
  padding: 0 4px;
  cursor: pointer;
  touch-action: manipulation;
}
.chapters button[aria-current="step"] {
  background: linear-gradient(160deg, var(--jade-deep), var(--indigo-mid));
  border-color: var(--jade);
  color: var(--parchment);
  box-shadow: 0 0 0 1px rgba(58, 143, 124, 0.4);
}
.chapters button.done {
  color: var(--gold-soft);
  border-color: rgba(201, 165, 74, 0.55);
}

.stage-wrap {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(18, 26, 46, 0.9), rgba(7, 11, 20, 0.95)),
    var(--indigo);
  box-shadow: inset 0 1px 0 rgba(230, 201, 122, 0.08);
}

.calligraphy-banner {
  position: absolute;
  z-index: 4;
  top: 10px;
  left: 12px;
  right: 12px;
  pointer-events: none;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.calligraphy-banner .brush {
  font-family: var(--font-brush);
  font-size: 42px;
  line-height: 1;
  color: rgba(235, 226, 210, 0.92);
  text-shadow: 0 2px 12px rgba(0,0,0,0.45);
}
.calligraphy-banner .seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  margin-top: 4px;
  font-family: var(--font-brush);
  font-size: 20px;
  color: #f5e6d8;
  background: var(--seal);
  border-radius: 3px;
  box-shadow: 0 2px 0 rgba(90, 20, 12, 0.6);
  transform: rotate(-6deg);
}
.banner-note {
  margin-left: auto;
  margin-top: 8px;
  font-size: 10px;
  letter-spacing: 0.04em;
  color: rgba(235, 226, 210, 0.7);
  background: rgba(7, 11, 20, 0.55);
  padding: 4px 8px;
  border-radius: 4px;
  max-width: 140px;
  text-align: right;
}

.viewport { position: relative; }
.split {
  display: grid;
  grid-template-columns: 1fr;
}
.split[data-active="1"] {
  grid-template-columns: 1fr 1fr;
}
.pane {
  position: relative;
  min-height: 200px;
  background: #05070e;
  overflow: hidden;
}
.pane-label {
  position: absolute;
  z-index: 3;
  top: 6px;
  left: 6px;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold-soft);
  background: rgba(7, 11, 20, 0.65);
  padding: 3px 6px;
  border-radius: 3px;
}
.ref-pane { display: none; }
.split[data-active="1"] .ref-pane { display: block; }
.ref-pane img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  min-height: 200px;
  filter: saturate(0.95) contrast(1.05);
}
.render-pane { position: relative; }
#stage {
  display: block;
  width: 100%;
  height: auto;
  min-height: 200px;
  vertical-align: top;
  background: #05070e;
}
.split[data-active="1"] #stage { min-height: 200px; }

.wipe {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}
.wipe-bar {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 2px;
  background: var(--gold);
  box-shadow: 0 0 8px rgba(201, 165, 74, 0.7);
  left: 50%;
}
.wipe-a, .wipe-b {
  position: absolute;
  bottom: 8px;
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--parchment);
  background: rgba(7,11,20,0.6);
  padding: 2px 6px;
  border-radius: 3px;
}
.wipe-a { left: 8px; }
.wipe-b { right: 8px; }

.hud {
  position: absolute;
  z-index: 5;
  left: 8px;
  right: 8px;
  bottom: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: flex-end;
  pointer-events: none;
}
.seed-hud {
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  letter-spacing: 0.14em;
  color: var(--gold-soft);
  background: rgba(7, 11, 20, 0.72);
  border: 1px solid var(--line);
  padding: 6px 10px;
  border-radius: 6px;
  min-height: 32px;
}
.score-hud {
  margin-left: auto;
  background: rgba(7, 11, 20, 0.78);
  border: 1px solid rgba(58, 143, 124, 0.45);
  border-radius: 10px;
  padding: 8px 10px;
  min-width: 148px;
}
.score-big {
  font-family: var(--font-display);
  font-size: 36px;
  font-weight: 700;
  line-height: 1;
  color: var(--parchment);
}
.score-unit {
  font-size: 14px;
  margin-left: 2px;
  color: var(--parchment-dim);
  font-weight: 500;
}
.score-delta {
  font-size: 12px;
  font-weight: 600;
  margin-top: 2px;
  color: var(--jade);
}
.score-delta.down { color: var(--seal); }
.bars { margin-top: 6px; display: grid; gap: 3px; }
.bar {
  display: grid;
  grid-template-columns: 58px 1fr;
  align-items: center;
  gap: 6px;
  font-size: 10px;
  color: var(--mist);
}
.bar i {
  display: block;
  height: 6px;
  border-radius: 3px;
  background: linear-gradient(90deg, var(--jade-deep), var(--jade));
  width: 0%;
  transition: width 0.45s ease;
}

.change-banner {
  position: absolute;
  z-index: 6;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(18, 26, 46, 0.92);
  border: 1px solid var(--gold);
  color: var(--gold-soft);
  font-family: var(--font-display);
  font-size: 18px;
  letter-spacing: 0.04em;
  padding: 10px 16px;
  border-radius: 8px;
  white-space: nowrap;
  box-shadow: 0 8px 28px rgba(0,0,0,0.45);
}

.panel {
  margin-top: 14px;
  padding: 14px 12px 12px;
  background: linear-gradient(165deg, rgba(28, 39, 68, 0.85), rgba(12, 18, 34, 0.95));
  border: 1px solid var(--line);
  border-radius: 12px;
}
.step-title {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
  color: var(--parchment);
}
.step-copy {
  margin: 0 0 12px;
  color: var(--parchment-dim);
  font-size: 13.5px;
}

.controls {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}
.knob {
  display: grid;
  gap: 6px;
}
.knob label {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
  color: var(--mist);
}
.knob label strong {
  color: var(--gold-soft);
  font-variant-numeric: tabular-nums;
}
.knob input[type="range"] {
  width: 100%;
  height: 44px;
  margin: 0;
  accent-color: var(--jade);
  cursor: pointer;
}
.knob.locked {
  opacity: 0.45;
  pointer-events: none;
}
.knob.locked::after {
  content: "Locked until scene phase done";
  display: block;
  font-size: 11px;
  color: var(--seal);
  margin-top: -2px;
}
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--indigo);
  color: var(--parchment);
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 500;
  min-height: 44px;
  padding: 0 14px;
  border-radius: 999px;
  cursor: pointer;
  touch-action: manipulation;
}
.chip.active {
  border-color: var(--jade);
  background: rgba(58, 143, 124, 0.25);
  color: var(--gold-soft);
}
.mat-spotlight {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.mat-ball {
  aspect-ratio: 1;
  border-radius: 50%;
  border: 1px solid var(--line);
  min-height: 56px;
  position: relative;
  overflow: hidden;
}
.mat-ball span {
  position: absolute;
  inset: auto 0 4px;
  text-align: center;
  font-size: 10px;
  color: var(--parchment);
  text-shadow: 0 1px 2px #000;
}

.nav-row {
  display: grid;
  grid-template-columns: 1fr 1.2fr 1fr;
  gap: 8px;
}
.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: var(--indigo-mid);
  color: var(--parchment);
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  min-height: 48px;
  border-radius: 10px;
  padding: 0 10px;
  cursor: pointer;
  touch-action: manipulation;
}
.btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.btn-primary {
  background: linear-gradient(180deg, var(--jade), var(--jade-deep));
  border-color: rgba(230, 201, 122, 0.35);
  color: #f4f7f5;
}
.btn-accent {
  background: transparent;
  border-color: var(--gold);
  color: var(--gold-soft);
}
.btn-ghost {
  background: transparent;
}

.foot {
  margin-top: 16px;
  padding: 8px 4px 4px;
  font-size: 11.5px;
  color: var(--mist);
  text-align: center;
}
.foot a {
  color: var(--gold-soft);
  text-decoration: underline;
  text-underline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .bar i { transition: none; }
}

[hidden] { display: none !important; }
