:root {
  color-scheme: dark;
  --ink: #f9f0d8;
  --muted: #b99a70;
  --black: #120c1a;
  --night: #0d0b18;
  --stone: #3a2d42;
  --sand: #b86d3e;
  --gold: #f2c94c;
  --teal: #20c6b7;
  --blue: #367cf6;
  --pink: #f04872;
  --green: #58d66d;
  --red: #ff4a4a;
  --panel: #181320;
  --panel-2: #24182d;
  --line: #f0c35f;
  --shadow: rgba(0, 0, 0, 0.45);
  --pixel: 4px;
  --font-ui: "Trebuchet MS", Verdana, system-ui, sans-serif;
  --font-pixel: "Courier New", ui-monospace, SFMono-Regular, Menlo, monospace;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: auto;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 50% -10%, rgba(240, 72, 114, 0.18), transparent 32%),
    linear-gradient(180deg, #060610 0%, #0d0b18 42%, #191122 72%, #24131d 100%);
  font-family: var(--font-ui);
  line-height: 1.45;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -3;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px) 0 0 / 32px 32px,
    linear-gradient(0deg, rgba(255,255,255,0.02) 1px, transparent 1px) 0 0 / 32px 32px,
    radial-gradient(circle at 14% 82%, rgba(255, 138, 61, 0.12), transparent 18%),
    radial-gradient(circle at 88% 70%, rgba(255, 74, 74, 0.12), transparent 20%);
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

a {
  color: inherit;
}

.scanlines {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: 20;
  opacity: 0.18;
  background: repeating-linear-gradient(
    to bottom,
    rgba(255, 255, 255, 0.05) 0,
    rgba(255, 255, 255, 0.05) 1px,
    transparent 1px,
    transparent 4px
  );
  mix-blend-mode: screen;
}

.stars {
  pointer-events: none;
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 12% 18%, rgba(255,255,255,0.8) 0 1px, transparent 2px),
    radial-gradient(circle at 30% 8%, rgba(255,255,255,0.55) 0 1px, transparent 2px),
    radial-gradient(circle at 72% 16%, rgba(255,255,255,0.7) 0 1px, transparent 2px),
    radial-gradient(circle at 89% 30%, rgba(255,255,255,0.55) 0 1px, transparent 2px);
}

.game-shell {
  width: min(1320px, calc(100vw - 28px));
  margin: 0 auto 44px;
}

.coin-popup {
  position: fixed;
  inset: 0;
  z-index: 45;
  display: grid;
  place-items: center;
  padding: 8px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.24), transparent 34%),
    rgba(6, 5, 10, 0.48);
  backdrop-filter: blur(1.5px);
  color: #111;
}

.coin-popup.hidden {
  display: none;
}

.coin-paper {
  position: relative;
  width: min(1180px, calc(100vw - 18px));
  height: auto;
  max-height: calc(100vh - 16px);
  overflow: hidden;
  display: grid;
  grid-template-rows: auto auto auto auto auto;
  gap: 8px;
  padding: 10px;
  border: 3px solid #111;
  border-radius: 10px;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.045) 1px, transparent 1px) 0 0 / 74px 74px,
    linear-gradient(0deg, rgba(0,0,0,0.035) 1px, transparent 1px) 0 0 / 74px 74px,
    #fff;
  box-shadow: 0 22px 70px rgba(0, 0, 0, 0.36), 7px 7px 0 rgba(0, 0, 0, 0.85);
  font-family: Georgia, "Times New Roman", serif;
}

.coin-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  z-index: 3;
  border: 2px solid #111;
  border-radius: 999px;
  background: #fff;
  color: #111;
  cursor: pointer;
  font: 700 18px/1 Arial, sans-serif;
  box-shadow: 3px 3px 0 #111;
  transition: left 130ms ease, top 130ms ease, transform 130ms ease;
}

.coin-close-hint {
  position: absolute;
  top: 16px;
  right: 50px;
  z-index: 2;
  padding: 4px 7px;
  border: 1px solid #111;
  border-radius: 999px;
  background: #fff7d8;
  color: #111;
  font: 800 10px/1 Arial, sans-serif;
  white-space: nowrap;
  box-shadow: 2px 2px 0 rgba(0, 0, 0, 0.22);
  transition: left 130ms ease, top 130ms ease;
}

.coin-close.evading {
  transform: rotate(12deg);
}

.coin-close.catchable {
  background: #111;
  color: #fff;
}

.coin-header {
  width: min(920px, 100%);
  margin: 0 auto;
  text-align: center;
}

.coin-kicker {
  margin: 0 0 1px;
  color: #ca422c;
  font: 700 11px/1.2 Arial, sans-serif;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.coin-header h1 {
  margin: 0;
  color: #111;
  font-size: clamp(22px, 2.35vw, 32px);
  font-weight: 800;
  letter-spacing: 0;
  text-shadow: none;
}

.coin-header p {
  margin: 3px auto 0;
  max-width: 900px;
  color: #222;
  font-size: clamp(12px, 0.98vw, 15px);
  line-height: 1.16;
  font-weight: 650;
}

.coin-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.68fr) minmax(520px, 1.32fr);
  gap: 18px;
  align-items: stretch;
}

.coin-components,
.coin-component-row,
.coin-main-grid,
.coin-mini-plot,
.coin-equation-card,
.coin-graft-strip,
.coin-plot,
.coin-shared,
.coin-card,
.coin-proof {
  border: 2px solid #111;
  background: rgba(255, 255, 255, 0.86);
}

.coin-component-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 7px;
  min-height: 108px;
  overflow: visible;
}

.coin-main-grid {
  display: grid;
  grid-template-columns: minmax(230px, 0.52fr) minmax(620px, 1.48fr);
  gap: 8px;
  min-height: 0;
  overflow: hidden;
  align-items: start;
  padding: 0;
  border: 0;
  background: transparent;
}

.coin-mini-plot {
  min-height: 0;
  padding: 7px 8px;
  overflow: hidden;
}

.coin-mini-plot h2 {
  margin: 0;
  color: #111;
  font-size: clamp(14px, 1.08vw, 18px);
  font-weight: 900;
  text-align: center;
  letter-spacing: 0;
  text-shadow: none;
}

.coin-mini-plot svg {
  display: block;
  width: 100%;
  max-height: 172px;
  margin-top: 2px;
}

.coin-mini-plot p {
  margin: 5px 0 0;
  color: #222;
  font: 800 11px/1.15 Arial, sans-serif;
}

.coin-components {
  padding: 14px;
}

.coin-components h2 {
  margin: 0 0 12px;
  color: #111;
  font-size: clamp(18px, 1.55vw, 24px);
  font-weight: 900;
  letter-spacing: 0;
  text-shadow: none;
}

.component-stack {
  display: grid;
  gap: 12px;
}

.component-card {
  position: relative;
  min-height: 0;
  padding: 9px 10px 8px 13px;
  border: 2px solid #111;
  background: #fff;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.18);
}

.component-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 7px;
}

.momentum-slot::before {
  background: #2777b5;
}

.precondition-slot::before {
  background: #27864f;
}

.graft-slot::before {
  background: #d98b25;
}

.component-label,
.coin-tag,
.coin-pill {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  border-radius: 999px;
  font-family: Arial, sans-serif;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

.component-label {
  margin-bottom: 3px;
  padding: 2px 6px;
  color: #fff;
  background: #111;
  font-size: 9px;
}

.component-card strong {
  display: block;
  color: #111;
  font-size: 14px;
  line-height: 1.15;
}

.component-card p {
  margin: 4px 0 0;
  color: #222;
  font: 750 11.5px/1.18 Arial, sans-serif;
}

.nesterov-bubble {
  position: relative;
  margin-top: 4px;
  padding: 6px 7px 4px;
  border: 2px solid #2777b5;
  border-radius: 10px;
  background: #edf7ff;
  color: #111;
}

.nesterov-bubble::after {
  content: "";
  position: absolute;
  left: 22px;
  top: -8px;
  width: 13px;
  height: 13px;
  border-left: 2px solid #2777b5;
  border-top: 2px solid #2777b5;
  background: #edf7ff;
  transform: rotate(45deg);
}

.nesterov-bubble span {
  position: relative;
  z-index: 1;
  display: block;
  margin-bottom: 2px;
  color: #155f9a;
  font: 900 9px/1.1 Arial, sans-serif;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.nesterov-bubble .MathJax {
  position: relative;
  z-index: 1;
}

.nesterov-bubble mjx-container[display="true"] {
  position: relative;
  z-index: 1;
  margin: 1px 0 0 !important;
  font-size: 84% !important;
  text-align: left !important;
}

.coin-plot {
  min-height: 300px;
  padding: 14px 14px 10px;
}

.coin-plot h2,
.coin-shared h2,
.coin-card h2,
.coin-proof h2,
.coin-equality h3,
.coin-scale-box h3 {
  margin: 0;
  color: #111;
  font-weight: 800;
  letter-spacing: 0;
  text-shadow: none;
}

.coin-plot h2 {
  text-align: center;
  font-size: clamp(18px, 1.55vw, 24px);
}

.coin-plot svg {
  display: block;
  width: 100%;
  height: auto;
  margin-top: 8px;
}

.grid-lines path {
  fill: none;
  stroke: #d8d8d8;
  stroke-width: 1.4;
}

.axis {
  fill: none;
  stroke: #222;
  stroke-width: 1.8;
}

.curve {
  fill: none;
  stroke-width: 4;
  stroke-linecap: round;
}

.curve.adam,
.legend .adam {
  stroke: #1f77b4;
}

.curve.shampoo,
.legend .shampoo {
  stroke: #3ca25f;
}

.curve.muon,
.legend .muon {
  stroke: #c9472f;
}

.legend text,
.axis-label {
  fill: #111;
  font: 13px Georgia, "Times New Roman", serif;
}

.axis-label.rotate {
  transform: rotate(-90deg);
}

.coin-derivation {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

.coin-equation-grid {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
  gap: 8px;
  min-height: 0;
  overflow: hidden;
  align-items: start;
}

.coin-equation-card {
  min-height: 0;
  padding: 10px;
  overflow: hidden;
  align-self: start;
}

.coin-equation-card h2 {
  display: flex;
  gap: 5px;
  align-items: center;
  margin: 0;
  color: #111;
  font-size: clamp(15px, 1.15vw, 19px);
  font-weight: 900;
  letter-spacing: 0;
  text-shadow: none;
}

.coin-shared {
  grid-column: 1 / -1;
  padding: 14px 18px;
  background:
    linear-gradient(90deg, rgba(39, 119, 181, 0.17), rgba(60, 162, 95, 0.10)),
    #fff;
}

.coin-shared h2 {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: clamp(18px, 1.45vw, 24px);
}

.coin-shared .coin-math {
  margin-top: 2px;
}

.coin-card {
  min-height: 260px;
  padding: clamp(14px, 1.25vw, 19px);
}

.coin-card h2 {
  display: flex;
  gap: 9px;
  align-items: center;
  font-size: clamp(18px, 1.55vw, 25px);
}

.coin-card h2 span {
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 999px;
  background: #111;
  color: #fff;
  font: 800 15px/1 Arial, sans-serif;
}

.coin-tag {
  margin: 8px 0 0;
  padding: 5px 9px;
  color: #fff;
  font-size: 10px;
}

.green-bg {
  background: #27864f;
}

.coin-pill {
  padding: 4px 6px;
  color: #fff;
  font-size: 9px;
  line-height: 1;
}

.coin-pill.blue {
  background: #2777b5;
}

.coin-pill.green {
  background: #27864f;
}

.coin-pill.orange {
  background: #d98b25;
}

.coin-card p {
  margin: 8px 0 0;
  color: #333;
  font-size: 15px;
  line-height: 1.4;
  font-weight: 600;
}

.coin-equation-card p {
  margin: 5px 0 0;
  color: #333;
  font: 750 13px/1.22 Arial, sans-serif;
}

.coin-math {
  margin-top: 2px;
  color: #111;
  font-size: clamp(14px, 1.08vw, 17.5px);
  line-height: 1.06;
}

.coin-equation-card .coin-math {
  font-size: clamp(18px, 1.38vw, 23px);
  line-height: 1.15;
}

.shampoo-math {
  font-size: clamp(15.5px, 1.18vw, 19.5px);
}

.coin-paper mjx-container[display="true"] {
  margin: 0.08em 0 !important;
}

.coin-paper mjx-container {
  max-width: 100%;
  font-size: 104% !important;
}

.shampoo-math mjx-container {
  font-size: 98% !important;
}

.coin-proof {
  margin-top: 16px;
  padding: clamp(14px, 1.45vw, 22px);
}

.coin-proof h2 {
  font-size: clamp(22px, 2vw, 32px);
}

.coin-proof-grid {
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(300px, 0.78fr);
  gap: 18px;
  align-items: center;
  margin-top: 8px;
}

.coin-equality {
  color: #111;
}

.coin-equality h3 {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 5px;
  font-size: 20px;
}

.coin-equality p {
  margin: 8px 0 0;
  color: #333;
  font: 700 15px/1.35 Arial, sans-serif;
}

.coin-scale-box {
  border-left: 4px solid #111;
  padding-left: 18px;
  color: #111;
}

.coin-scale-box h3 {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 20px;
}

.coin-scale-box p {
  margin: 8px 0 0;
  font-size: 16px;
  line-height: 1.38;
  font-weight: 650;
}

.coin-graft-strip {
  display: grid;
  grid-template-columns: minmax(260px, 0.9fr) minmax(190px, 0.52fr) minmax(300px, 1fr);
  gap: 8px;
  align-items: center;
  padding: 8px 10px;
  overflow: hidden;
}

.coin-graft-strip h2 {
  display: flex;
  gap: 5px;
  align-items: center;
  margin: 0 0 3px;
  color: #111;
  font-size: clamp(12px, 0.95vw, 16px);
  font-weight: 900;
  letter-spacing: 0;
  text-shadow: none;
}

.coin-graft-strip .coin-equality,
.coin-graft-strip .coin-scale-box,
.coin-graft-choice {
  min-width: 0;
}

.coin-graft-strip .coin-equality {
  color: #111;
}

.coin-graft-strip .coin-scale-box {
  border-left: 3px solid #d98b25;
  padding-left: 9px;
}

.coin-graft-choice {
  display: grid;
  gap: 4px;
}

.coin-graft-choice p {
  margin: 0;
  padding: 5px 7px;
  border: 1px solid #111;
  background: #fff;
  color: #222;
  font: 800 10.5px/1.1 Arial, sans-serif;
}

.green-text {
  color: #27864f;
}

.red-text {
  color: #c9472f;
}

.blue-text {
  color: #2777b5;
}

.orange-text {
  color: #d98b25;
}

.coin-update-rule {
  width: fit-content;
  margin: 0;
  padding: 4px 7px;
  border: 2px solid #111;
  background: #fff7d8;
  box-shadow: 3px 3px 0 rgba(217, 139, 37, 0.35);
  font-size: 15px;
}

.coin-bottom-line {
  display: inline-block;
  padding: 8px 10px;
  border: 2px solid #111;
  background: #fff4b8;
}

.coin-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
  margin-top: 0;
  font-family: Arial, sans-serif;
}

.coin-continue {
  border: 2px solid #111;
  border-radius: 999px;
  padding: 6px 12px;
  background: #111;
  color: #fff;
  cursor: pointer;
  font: 700 12px/1 Arial, sans-serif;
  text-transform: uppercase;
  box-shadow: 3px 3px 0 #999;
}

.coin-actions span {
  color: #555;
  font-size: 10.5px;
}

.story-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 22px;
  background:
    radial-gradient(circle at 50% 12%, rgba(240, 72, 114, 0.18), transparent 35%),
    rgba(8, 7, 17, 0.94);
}

.story-overlay.hidden {
  display: none;
}

.story-frame {
  width: min(1180px, calc(100vw - 32px));
  min-height: min(720px, calc(100vh - 44px));
  display: grid;
  grid-template-columns: minmax(320px, 0.92fr) minmax(360px, 1.08fr);
  gap: 22px;
  padding: 22px;
  border: 4px solid #080711;
  outline: 3px solid var(--line);
  background:
    radial-gradient(circle at 28% 18%, rgba(255, 138, 61, 0.13), transparent 23%),
    linear-gradient(90deg, rgba(255,255,255,0.035) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(0deg, rgba(255,255,255,0.03) 1px, transparent 1px) 0 0 / 24px 24px,
    #18101f;
  box-shadow: 10px 10px 0 #080711;
}

.story-scene {
  position: relative;
  min-height: 520px;
  border: 4px solid #080711;
  outline: 2px solid #6b4f68;
  overflow: hidden;
  background:
    radial-gradient(circle at 24% 14%, rgba(255, 231, 110, 0.16), transparent 12%),
    linear-gradient(180deg, #070811 0 38%, #191024 38% 70%, #3b1b25 70% 100%);
}

.story-copy {
  display: grid;
  align-content: center;
  gap: 18px;
}

.story-copy h1 {
  font-size: clamp(34px, 5vw, 66px);
}

#storyText {
  min-height: 190px;
  color: #fff0c2;
  font-size: clamp(20px, 2.4vw, 29px);
  font-weight: 700;
}

.story-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.story-progress {
  display: flex;
  gap: 8px;
}

.story-progress span {
  width: 18px;
  height: 18px;
  border: 3px solid #080711;
  background: #4b3655;
  outline: 1px solid #6b4f68;
}

.story-progress span.active {
  background: var(--teal);
}

.audio-status {
  min-height: 24px;
  color: var(--teal);
  font: 700 12px/1.35 var(--font-pixel);
  text-transform: uppercase;
}

.slop-cloud {
  position: absolute;
  width: 120px;
  height: 48px;
  background:
    linear-gradient(#9d3661, #9d3661) 0 14px / 120px 24px no-repeat,
    linear-gradient(#c34a76, #c34a76) 18px 0 / 34px 48px no-repeat,
    linear-gradient(#c34a76, #c34a76) 58px 0 / 34px 48px no-repeat;
  border: 4px solid #080711;
  animation: slopDrift 2.5s steps(4, end) infinite;
  filter: drop-shadow(0 0 18px rgba(240, 72, 114, 0.4));
}

.cloud-a {
  top: 54px;
  left: 42px;
}

.cloud-b {
  top: 112px;
  right: 54px;
  animation-delay: 0.6s;
}

.sorcerer {
  position: absolute;
  right: 88px;
  bottom: 90px;
  width: 84px;
  height: 150px;
  background:
    linear-gradient(#ffe0aa, #ffe0aa) 26px 12px / 32px 26px no-repeat,
    linear-gradient(#4d2a77, #4d2a77) 14px 40px / 56px 86px no-repeat,
    linear-gradient(#f04872, #f04872) 4px 54px / 18px 52px no-repeat,
    linear-gradient(#f04872, #f04872) 62px 54px / 18px 52px no-repeat,
    linear-gradient(#f2c94c, #f2c94c) 30px 0 / 24px 14px no-repeat;
  filter: drop-shadow(8px 8px 0 #080711);
  animation: sorcererFloat 1s steps(2, end) infinite;
}

.prison {
  position: absolute;
  left: 76px;
  bottom: 72px;
  width: 210px;
  height: 220px;
  border: 5px solid #080711;
  background: #181324;
  box-shadow: inset 0 0 0 6px rgba(255,255,255,0.05), 8px 8px 0 #080711;
}

.prison-bars {
  position: absolute;
  inset: 16px 20px 0;
  background: repeating-linear-gradient(90deg, var(--gold) 0 9px, transparent 9px 31px);
}

.optimizer-orb {
  position: absolute;
  left: 78px;
  top: 88px;
  width: 54px;
  height: 54px;
  background:
    linear-gradient(var(--teal), var(--teal)) 20px 7px / 14px 40px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 7px 20px / 40px 14px no-repeat,
    #fff4c6;
  border: 4px solid #080711;
  animation: orbPulse 0.9s steps(2, end) infinite;
}

.story-floor {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 74px;
  border-top: 4px solid #080711;
  background: repeating-linear-gradient(90deg, #6f372c 0 52px, #9e5738 52px 104px);
}

.story-scene::before,
.story-scene::after,
.palace-scene::before,
.palace-scene::after {
  content: "";
  position: absolute;
  z-index: 4;
  bottom: 74px;
  width: 34px;
  height: 72px;
  background:
    linear-gradient(#2b1928, #2b1928) 8px 30px / 18px 42px no-repeat,
    linear-gradient(#fff06a, #fff06a) 8px 0 / 18px 18px no-repeat,
    linear-gradient(#ff8a3d, #ff8a3d) 4px 12px / 26px 22px no-repeat,
    linear-gradient(#e5354f, #e5354f) 10px 22px / 14px 18px no-repeat;
  border-bottom: 3px solid #080711;
  animation: flame 0.42s steps(2, end) infinite;
  filter: drop-shadow(0 0 14px rgba(255, 138, 61, 0.72));
}

.story-scene::before,
.palace-scene::before {
  left: 24px;
}

.story-scene::after,
.palace-scene::after {
  right: 24px;
  animation-delay: 0.18s;
}

@keyframes slopDrift {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(18px); }
}

@keyframes sorcererFloat {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes orbPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}

.hud {
  position: sticky;
  top: 0;
  z-index: 15;
  display: grid;
  grid-template-columns: minmax(190px, 1fr) auto auto;
  gap: 14px;
  align-items: center;
  padding: 12px 0;
  background: linear-gradient(180deg, rgba(18,12,26,0.98), rgba(18,12,26,0.86));
  border-bottom: 4px solid #080711;
}

.room-nav {
  position: sticky;
  top: 88px;
  z-index: 14;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 10px 0 4px;
  background: linear-gradient(180deg, rgba(18,12,26,0.88), rgba(18,12,26,0));
}

.room-dots {
  display: flex;
  justify-content: center;
  gap: 9px;
}

.room-dots button {
  width: 18px;
  height: 18px;
  padding: 0;
  border: 3px solid #080711;
  outline: 1px solid var(--line);
  background: #46314c;
  box-shadow: 2px 2px 0 #080711;
  cursor: pointer;
}

.room-dots button.active {
  background: var(--teal);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  font: 700 16px/1 var(--font-pixel);
  text-transform: uppercase;
  text-decoration: none;
  color: var(--gold);
  min-width: 0;
}

.brand span:last-child {
  overflow-wrap: anywhere;
}

.brand-mark {
  width: 22px;
  height: 22px;
  flex: 0 0 22px;
  background:
    linear-gradient(var(--gold), var(--gold)) 7px 2px / 8px 18px no-repeat,
    linear-gradient(var(--teal), var(--teal)) 2px 7px / 18px 8px no-repeat,
    #3a253e;
  border: 3px solid #0b0a12;
  box-shadow: 0 0 0 2px var(--line);
}

.hud-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
}

.meter {
  min-width: 116px;
  padding: 7px 10px;
  border: 3px solid #0b0a12;
  outline: 2px solid var(--line);
  background: #20162b;
  box-shadow: 4px 4px 0 #080711;
}

.meter-label {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font: 700 10px/1 var(--font-pixel);
  text-transform: uppercase;
}

.meter strong {
  font: 700 16px/1 var(--font-pixel);
  color: var(--teal);
}

.hud-actions,
.quick-actions,
.sim-toolbar,
.legend-row,
.sim-legend,
.lesson-controls,
.forge-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.pixel-button,
.mode-button,
.quiz-options button {
  appearance: none;
  min-height: 40px;
  border: 3px solid #080711;
  outline: 2px solid var(--line);
  background: var(--pink);
  color: #fff9df;
  padding: 9px 13px;
  box-shadow: 4px 4px 0 #080711;
  cursor: pointer;
  font: 700 12px/1 var(--font-pixel);
  text-transform: uppercase;
  letter-spacing: 0;
}

.pixel-button:hover,
.mode-button:hover,
.quiz-options button:hover,
.rune:hover,
.slot:hover {
  transform: translate(-1px, -1px);
  box-shadow: 5px 5px 0 #080711;
}

.pixel-button:active,
.mode-button:active,
.quiz-options button:active,
.rune:active,
.slot:active {
  transform: translate(2px, 2px);
  box-shadow: 2px 2px 0 #080711;
}

.pixel-button.secondary,
.mode-button {
  background: var(--blue);
}

.pixel-button.link {
  display: inline-flex;
  align-items: center;
  text-decoration: none;
}

.mode-button.active {
  background: var(--teal);
  color: #08121c;
}

.room-band {
  position: relative;
  margin: 18px 0;
  padding: clamp(18px, 3vw, 30px);
  border: 4px solid #080711;
  outline: 3px solid var(--line);
  background:
    radial-gradient(circle at 9% 4%, rgba(255, 138, 61, 0.11), transparent 12%),
    radial-gradient(circle at 92% 8%, rgba(240, 72, 114, 0.08), transparent 16%),
    linear-gradient(90deg, rgba(255,255,255,0.03) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(0deg, rgba(255,255,255,0.025) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--panel);
  box-shadow: 8px 8px 0 var(--shadow);
}

.room-band > * {
  position: relative;
  z-index: 1;
}

.room-band:not(.hero)::before,
.room-band:not(.hero)::after {
  content: "";
  position: absolute;
  z-index: 0;
  top: 18px;
  width: 30px;
  height: 58px;
  pointer-events: none;
  background:
    linear-gradient(#2b1928, #2b1928) 8px 26px / 14px 32px no-repeat,
    linear-gradient(#fff06a, #fff06a) 8px 0 / 14px 16px no-repeat,
    linear-gradient(#ff8a3d, #ff8a3d) 4px 10px / 22px 20px no-repeat,
    linear-gradient(#e5354f, #e5354f) 10px 20px / 10px 16px no-repeat;
  animation: flame 0.42s steps(2, end) infinite;
  filter: drop-shadow(0 0 14px rgba(255, 138, 61, 0.68));
}

.room-band:not(.hero)::before {
  left: 16px;
}

.room-band:not(.hero)::after {
  right: 16px;
  animation-delay: 0.18s;
}

.room-screen {
  display: none;
  min-height: calc(100vh - 160px);
}

.room-screen.active {
  display: block;
}

.hero.room-screen.active {
  display: grid;
}

.room-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  justify-content: flex-end;
  align-items: center;
  margin-top: 24px;
}

.hero {
  min-height: calc(100vh - 96px);
  display: grid;
  grid-template-columns: minmax(0, 0.9fr) minmax(420px, 1.1fr);
  gap: clamp(20px, 5vw, 58px);
  align-items: center;
  overflow: hidden;
}

.hero::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 10px;
  background: repeating-linear-gradient(90deg, var(--sand) 0 20px, #8b513e 20px 40px);
}

.hero-copy {
  position: relative;
  z-index: 2;
}

.eyebrow {
  margin: 0 0 9px;
  color: var(--teal);
  font: 700 12px/1 var(--font-pixel);
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  color: var(--gold);
  font: 700 clamp(42px, 8vw, 96px)/0.92 var(--font-pixel);
  text-shadow: 5px 5px 0 #080711, 9px 9px 0 #702443;
  letter-spacing: 0;
  max-width: 780px;
}

h2 {
  color: #fff4c6;
  font: 700 clamp(26px, 4vw, 44px)/1.05 var(--font-pixel);
  text-shadow: 3px 3px 0 #080711;
  letter-spacing: 0;
}

h3 {
  color: var(--gold);
  font: 700 15px/1.2 var(--font-pixel);
  text-transform: uppercase;
  letter-spacing: 0;
}

.lede {
  margin: 20px 0 24px;
  max-width: 660px;
  color: #fff4d0;
  font-size: clamp(18px, 2.2vw, 24px);
}

.section-head {
  display: grid;
  gap: 9px;
  max-width: 990px;
  margin-bottom: 22px;
}

.section-head p:not(.eyebrow) {
  color: #f3dfba;
  font-size: 17px;
}

.palace-scene {
  position: relative;
  min-height: 470px;
  border: 4px solid #080711;
  outline: 3px solid #58354b;
  overflow: hidden;
  background:
    radial-gradient(circle at 72% 19%, rgba(255, 231, 110, 0.16), transparent 11%),
    linear-gradient(180deg, #060711 0 34%, #151022 34% 64%, #3e1d27 64% 100%);
  box-shadow: inset 0 0 0 8px rgba(255,255,255,0.04), 8px 8px 0 #080711;
}

.moon {
  position: absolute;
  top: 38px;
  right: 68px;
  width: 54px;
  height: 54px;
  background: #ffe8a5;
  box-shadow: 0 0 0 6px #b07556, 0 0 0 12px #4a3150;
}

.tower,
.gate,
.floor {
  position: absolute;
  bottom: 52px;
  background: #8d4e39;
  border: 4px solid #080711;
  box-shadow: inset 0 0 0 5px rgba(255,255,255,0.12);
}

.tower {
  width: 88px;
  height: 260px;
}

.tower::before {
  content: "";
  position: absolute;
  left: -8px;
  right: -8px;
  top: -28px;
  height: 28px;
  background: repeating-linear-gradient(90deg, #b86d3e 0 18px, #5b2b2d 18px 36px);
  border: 4px solid #080711;
}

.tower-left {
  left: 54px;
}

.tower-right {
  right: 54px;
}

.gate {
  left: 50%;
  transform: translateX(-50%);
  width: 230px;
  height: 212px;
  background: #5f3542;
}

.gate::before {
  content: "";
  position: absolute;
  left: 22px;
  right: 22px;
  bottom: 0;
  height: 150px;
  background: #21182a;
  border: 4px solid #080711;
  border-bottom: 0;
}

.gate-bars {
  position: absolute;
  left: 44px;
  right: 44px;
  bottom: 0;
  height: 146px;
  background: repeating-linear-gradient(90deg, #f2c94c 0 7px, transparent 7px 22px);
  z-index: 2;
}

.floor {
  left: 0;
  right: 0;
  bottom: 0;
  height: 64px;
  border-left: 0;
  border-right: 0;
  background: repeating-linear-gradient(90deg, #6f372c 0 54px, #a15a38 54px 108px);
}

.torch {
  position: absolute;
  bottom: 152px;
  width: 18px;
  height: 48px;
  background: #2b1928;
  border: 3px solid #080711;
}

.torch::before {
  content: "";
  position: absolute;
  top: -28px;
  left: -8px;
  width: 28px;
  height: 30px;
  background:
    linear-gradient(180deg, #fff06a 0 35%, #ff8a3d 35% 70%, #e5354f 70%);
  animation: flame 0.5s steps(2, end) infinite;
}

.torch-left {
  left: 34%;
}

.torch-right {
  right: 34%;
}

.hero-runner {
  position: absolute;
  left: 18%;
  bottom: 68px;
  width: 26px;
  height: 48px;
  background:
    linear-gradient(#f7c59b, #f7c59b) 7px 0 / 12px 12px no-repeat,
    linear-gradient(#ece6c2, #ece6c2) 4px 12px / 18px 18px no-repeat,
    linear-gradient(#23b6a8, #23b6a8) 1px 30px / 10px 18px no-repeat,
    linear-gradient(#23b6a8, #23b6a8) 15px 30px / 10px 18px no-repeat;
  image-rendering: pixelated;
  animation: runner 2.2s steps(6, end) infinite;
}

@keyframes runner {
  0% { transform: translateX(0); }
  50% { transform: translateX(260px); }
  100% { transform: translateX(0); }
}

@keyframes flame {
  0%, 100% { transform: translateY(0) scaleX(1); }
  50% { transform: translateY(2px) scaleX(0.8); }
}

.momentum-layout,
.rate-scroll,
.graft-grid,
.forge-layout,
.quiz-layout,
.decay-grid {
  display: grid;
  gap: 20px;
}

.momentum-layout {
  grid-template-columns: minmax(360px, 0.95fr) minmax(360px, 1.05fr);
}

.rate-scroll {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 20px;
}

.sim-panel,
.rate-card,
.viz-panel,
.graft-controls,
.rule-console,
.quiz-panel,
.decay-tile,
.rate-scroll article,
.math-tile,
.quiz-slots,
.slots,
.rune-bank {
  border: 4px solid #080711;
  outline: 2px solid #6b4f68;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.025), transparent 26%),
    #120f1b;
  box-shadow: 5px 5px 0 #080711;
}

.sim-panel,
.rate-card,
.viz-panel,
.graft-controls,
.rule-console,
.quiz-panel,
.decay-tile,
.rate-scroll article,
.math-tile {
  padding: 16px;
}

.rate-card {
  margin-top: 18px;
  display: grid;
  gap: 12px;
}

.rate-topline {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

.rate-topline .eyebrow {
  margin-bottom: 5px;
}

.rate-topline h3 {
  margin: 0;
  font-size: clamp(24px, 2.4vw, 36px);
}

.rate-topline strong {
  padding: 8px 10px;
  border: 3px solid #080711;
  outline: 2px solid var(--line);
  color: var(--teal);
  background: #21182a;
  box-shadow: 3px 3px 0 #080711;
  font: 700 14px/1 var(--font-pixel);
  white-space: nowrap;
}

.kappa-control {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto;
  gap: 12px;
  align-items: center;
  color: #fff0c2;
  font: 700 12px/1.2 var(--font-pixel);
  text-transform: uppercase;
}

.kappa-control input {
  min-width: 0;
}

.kappa-control strong {
  color: var(--gold);
}

.rate-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.rate-chip {
  min-width: 0;
  padding: 7px 8px;
  border: 3px solid #080711;
  color: #fff4c6;
  background: #1c1628;
  font: 700 10px/1.2 var(--font-pixel);
  text-transform: uppercase;
  overflow-wrap: anywhere;
}

.rate-chip.gd {
  box-shadow: inset 6px 0 0 var(--blue);
}

.rate-chip.nag {
  box-shadow: inset 6px 0 0 var(--teal);
}

.rate-chip.hb {
  box-shadow: inset 6px 0 0 var(--pink);
}

.rate-chip.ema {
  box-shadow: inset 6px 0 0 var(--green);
}

.rate-readout {
  color: #f3dfba;
  font-weight: 800;
}

canvas {
  width: 100%;
  height: auto;
  display: block;
  margin-top: 14px;
  border: 3px solid #080711;
  background: #090914;
  image-rendering: pixelated;
}

.sim-readout,
.legend-row,
.sim-legend {
  margin-top: 12px;
  color: var(--muted);
  font: 700 12px/1.25 var(--font-pixel);
  text-transform: uppercase;
}

.sim-readout {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.sim-readout span {
  min-width: 0;
  overflow-wrap: anywhere;
}

.math-stack {
  display: grid;
  gap: 14px;
}

.teacher-card,
.target-scroll,
.forge-choice-board,
.choice-group,
.forge-status-card,
.credits-scroll {
  border: 4px solid #080711;
  outline: 2px solid #6b4f68;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.025), transparent 26%),
    #120f1b;
  box-shadow: 5px 5px 0 #080711;
  padding: 16px;
}

.teacher-card {
  display: grid;
  gap: 14px;
  align-content: start;
  min-height: 100%;
}

.teacher-topline {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.teacher-topline span,
.target-label {
  color: var(--muted);
  font: 700 11px/1 var(--font-pixel);
  text-transform: uppercase;
}

.lesson-note {
  color: var(--teal);
  font-weight: 700;
}

.math-tile {
  display: none;
  color: #f5e5bd;
}

.math-tile.active {
  display: block;
}

.math-tile p + p,
.decay-tile p + p,
.source-note {
  margin-top: 12px;
}

.mjx-container {
  overflow-x: auto;
  overflow-y: hidden;
  max-width: 100%;
  padding: 3px 0;
}

.graft-grid {
  grid-template-columns: minmax(360px, 1fr) minmax(310px, 0.72fr);
}

.swatch {
  display: inline-block;
  width: 14px;
  height: 14px;
  margin-right: 6px;
  vertical-align: -2px;
  border: 2px solid #080711;
}

.swatch.current {
  background: #fff4c6;
}

.swatch.lookahead {
  background: var(--blue);
}

.swatch.update {
  background: var(--gold);
}

.swatch.direction {
  background: var(--blue);
}

.swatch.magnitude {
  background: var(--pink);
}

.swatch.final {
  background: var(--green);
}

.graft-controls {
  display: grid;
  gap: 14px;
  align-content: start;
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font: 700 12px/1.25 var(--font-pixel);
  text-transform: uppercase;
}

select,
input[type="text"],
input[type="range"] {
  width: 100%;
}

select,
input[type="text"] {
  border: 3px solid #080711;
  outline: 2px solid #6b4f68;
  background: #090914;
  color: var(--ink);
  padding: 10px;
  min-height: 42px;
}

input[type="range"] {
  accent-color: var(--teal);
}

.formula-box {
  min-height: 70px;
  padding: 13px;
  border: 3px solid #080711;
  background: #090914;
  color: #fff0c2;
  font-size: 15px;
  overflow-x: auto;
}

.source-note,
.feedback,
.graft-readout {
  color: #f2d8a9;
}

.graft-readout {
  border: 3px solid #080711;
  background: #0c0b13;
  padding: 12px;
  font-weight: 700;
}

.decay-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.forge-layout,
.forge-challenge {
  grid-template-columns: minmax(300px, 0.7fr) minmax(420px, 1.3fr);
}

.slots {
  display: grid;
  gap: 13px;
  padding: 16px;
}

.slot {
  appearance: none;
  display: grid;
  gap: 8px;
  width: 100%;
  min-height: 92px;
  padding: 13px;
  border: 3px solid #080711;
  outline: 2px solid #6b4f68;
  background: #0c0b13;
  cursor: pointer;
  text-align: left;
  box-shadow: 4px 4px 0 #080711;
}

.slot.ready {
  outline-color: var(--teal);
}

.slot.drop-target {
  background: #1f2d36;
  outline-color: var(--gold);
}

.slot span,
.rune span,
.quiz-slots span {
  color: var(--muted);
  font: 700 11px/1 var(--font-pixel);
  text-transform: uppercase;
}

.slot strong,
.quiz-slots strong {
  color: #fff3be;
  font: 700 18px/1.15 var(--font-pixel);
  overflow-wrap: anywhere;
}

.rune-bank {
  display: grid;
  grid-template-columns: repeat(4, minmax(112px, 1fr));
  gap: 12px;
  padding: 16px;
}

.rune {
  appearance: none;
  display: grid;
  gap: 7px;
  min-height: 82px;
  padding: 11px;
  border: 3px solid #080711;
  outline: 2px solid #6b4f68;
  background: #21172d;
  cursor: grab;
  text-align: left;
  box-shadow: 4px 4px 0 #080711;
}

.rune.selected {
  outline-color: var(--gold);
  background: #45304c;
}

.rune strong {
  color: #fff0c2;
  font: 700 14px/1.15 var(--font-pixel);
  overflow-wrap: anywhere;
}

.forge-challenge {
  display: grid;
  gap: 20px;
}

.forge-stage {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(280px, 0.55fr);
  gap: 20px;
}

.forge-machine {
  position: relative;
  min-height: 280px;
  border: 4px solid #080711;
  outline: 2px solid #6b4f68;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px) 0 0 / 22px 22px,
    linear-gradient(0deg, rgba(255,255,255,0.02) 1px, transparent 1px) 0 0 / 22px 22px,
    #0c0a14;
  box-shadow: 5px 5px 0 #080711;
}

.forge-backdrop {
  position: absolute;
  inset: 0;
}

.forge-flame {
  position: absolute;
  left: 11%;
  bottom: 46px;
  width: 112px;
  height: 132px;
  background:
    linear-gradient(#fff06a, #fff06a) 44px 12px / 28px 60px no-repeat,
    linear-gradient(#ff8a3d, #ff8a3d) 24px 42px / 68px 70px no-repeat,
    linear-gradient(#e5354f, #e5354f) 10px 76px / 94px 56px no-repeat;
  border-bottom: 5px solid #080711;
  filter: drop-shadow(0 0 24px rgba(255, 138, 61, 0.75));
  animation: forgeFlame 0.38s steps(2, end) infinite;
}

.forge-anvil {
  position: absolute;
  left: 34%;
  bottom: 58px;
  width: 190px;
  height: 82px;
  background:
    linear-gradient(#67445a, #67445a) 24px 0 / 142px 24px no-repeat,
    linear-gradient(#9c5d58, #9c5d58) 0 24px / 190px 38px no-repeat,
    linear-gradient(#412a3d, #412a3d) 66px 62px / 58px 20px no-repeat;
  border: 4px solid #080711;
  box-shadow: 7px 7px 0 #080711;
}

.forge-crystal {
  position: absolute;
  right: 13%;
  bottom: 86px;
  width: 84px;
  height: 84px;
  background:
    linear-gradient(var(--teal), var(--teal)) 34px 8px / 16px 68px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 8px 34px / 68px 16px no-repeat,
    #fff4c6;
  border: 4px solid #080711;
  box-shadow: 0 0 0 6px rgba(32, 198, 183, 0.22), 0 0 28px rgba(32, 198, 183, 0.5);
  animation: forgeCrystal 1s steps(4, end) infinite;
}

.forge-spark {
  position: absolute;
  width: 12px;
  height: 12px;
  background: var(--gold);
  border: 2px solid #080711;
  animation: forgeSpark 1.2s steps(4, end) infinite;
}

.spark-a {
  left: 27%;
  bottom: 174px;
}

.spark-b {
  left: 57%;
  bottom: 178px;
  animation-delay: 0.28s;
}

.spark-c {
  right: 28%;
  bottom: 198px;
  animation-delay: 0.56s;
}

.forge-sockets {
  position: absolute;
  left: 22px;
  right: 22px;
  top: 18px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.forge-socket {
  min-height: 76px;
  padding: 10px;
  border: 3px solid #080711;
  outline: 2px solid #6b4f68;
  background: rgba(18, 15, 27, 0.86);
  box-shadow: 4px 4px 0 #080711;
}

.forge-socket span {
  display: block;
  color: var(--muted);
  font: 700 10px/1 var(--font-pixel);
  text-transform: uppercase;
}

.forge-socket strong {
  display: block;
  margin-top: 10px;
  color: #fff0c2;
  font: 700 17px/1 var(--font-pixel);
  overflow-wrap: anywhere;
}

.forge-socket.filled {
  outline-color: var(--gold);
}

.forge-socket.correct {
  outline-color: var(--green);
  background: rgba(29, 91, 53, 0.82);
}

.forge-socket.wrong {
  outline-color: var(--red);
  background: rgba(100, 32, 48, 0.88);
  animation: socketAlarm 0.25s steps(2, end) 4;
}

.forge-machine.forged {
  outline-color: var(--green);
  box-shadow: 5px 5px 0 #080711, 0 0 34px rgba(88, 214, 109, 0.24);
}

.forge-machine.alarm {
  outline-color: var(--red);
}

.forge-status-card {
  display: grid;
  gap: 12px;
  align-content: center;
}

.forge-status-card p {
  color: #f2d8a9;
  font-weight: 700;
}

.forge-charge {
  height: 22px;
  border: 3px solid #080711;
  outline: 2px solid #6b4f68;
  background: #090914;
  overflow: hidden;
}

.forge-charge span {
  display: block;
  width: 0;
  height: 100%;
  background: repeating-linear-gradient(90deg, var(--teal) 0 18px, var(--gold) 18px 28px);
  transition: width 0.18s steps(4, end);
}

.target-scroll {
  display: grid;
  gap: 12px;
  align-content: start;
}

.target-scroll p {
  color: #f2d8a9;
  font-weight: 700;
}

.forge-choice-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.choice-group {
  box-shadow: none;
}

.choice-buttons {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.forge-choice {
  appearance: none;
  min-height: 40px;
  border: 3px solid #080711;
  outline: 2px solid #6b4f68;
  background: #21172d;
  color: #fff0c2;
  padding: 8px 10px;
  cursor: pointer;
  text-align: left;
  box-shadow: 3px 3px 0 #080711;
  font: 700 12px/1.15 var(--font-pixel);
}

.forge-choice.selected {
  outline-color: var(--gold);
  background: #45304c;
}

.forge-choice.correct {
  outline-color: var(--green);
  background: #1d5b35;
}

.forge-choice.wrong {
  outline-color: var(--red);
  background: #642030;
}

.rule-console {
  display: grid;
  grid-template-columns: minmax(330px, 1fr) minmax(260px, 0.48fr);
  gap: 16px;
  align-items: start;
  margin-top: 20px;
  padding: 16px;
}

.feedback {
  grid-column: 1 / -1;
  min-height: 24px;
  font: 700 13px/1.4 var(--font-pixel);
}

.feedback.good {
  color: var(--green);
}

.feedback.bad {
  color: var(--red);
}

.quiz-layout {
  grid-template-columns: minmax(280px, 0.65fr) minmax(380px, 1fr);
}

.quiz-slots {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.quiz-slots div {
  display: grid;
  gap: 6px;
  min-height: 78px;
  padding: 13px;
  border: 3px solid #080711;
  background: #151322;
}

.quiz-options {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin: 16px 0;
}

.quiz-rule {
  min-height: 56px;
  margin-top: 14px;
  font-size: 14px;
}

.quiz-options button {
  min-height: 58px;
  background: #5b3fc7;
  text-align: left;
}

.quiz-options button.correct {
  background: var(--green);
  color: #08120c;
}

.quiz-options button.wrong {
  background: var(--red);
}

.sources ul {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 22px;
  color: #f0d9aa;
}

.credits-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.9fr) minmax(360px, 1.1fr);
  gap: 20px;
}

.final-scene {
  position: relative;
  min-height: 430px;
  border: 4px solid #080711;
  outline: 2px solid #6b4f68;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 18%, rgba(32, 198, 183, 0.16), transparent 16%),
    linear-gradient(180deg, #070811 0 38%, #151022 38% 70%, #3b1b25 70% 100%);
}

.freed-orb {
  position: absolute;
  left: 50%;
  top: 72px;
  width: 70px;
  height: 70px;
  transform: translateX(-50%);
  background:
    linear-gradient(var(--teal), var(--teal)) 28px 8px / 14px 54px no-repeat,
    linear-gradient(var(--gold), var(--gold)) 8px 28px / 54px 14px no-repeat,
    #fff4c6;
  border: 5px solid #080711;
  box-shadow: 0 0 0 7px rgba(32, 198, 183, 0.28), 0 0 34px rgba(32, 198, 183, 0.48);
  animation: freedOrb 1.1s steps(4, end) infinite;
}

.broken-prison {
  position: absolute;
  left: 50%;
  bottom: 74px;
  width: 260px;
  height: 190px;
  transform: translateX(-50%);
  border: 5px solid #080711;
  background:
    repeating-linear-gradient(90deg, transparent 0 34px, var(--gold) 34px 43px, transparent 43px 58px),
    #181324;
  box-shadow: inset 0 0 0 6px rgba(255,255,255,0.05), 8px 8px 0 #080711;
}

.broken-prison::before,
.broken-prison::after {
  content: "";
  position: absolute;
  top: 24px;
  width: 70px;
  height: 10px;
  background: var(--gold);
  border: 3px solid #080711;
}

.broken-prison::before {
  left: 46px;
  transform: rotate(-24deg);
}

.broken-prison::after {
  right: 46px;
  transform: rotate(28deg);
}

.final-runner {
  position: absolute;
  left: 20px;
  bottom: 84px;
  width: 26px;
  height: 48px;
  background:
    linear-gradient(#f7c59b, #f7c59b) 7px 0 / 12px 12px no-repeat,
    linear-gradient(#ece6c2, #ece6c2) 4px 12px / 18px 18px no-repeat,
    linear-gradient(#23b6a8, #23b6a8) 1px 30px / 10px 18px no-repeat,
    linear-gradient(#23b6a8, #23b6a8) 15px 30px / 10px 18px no-repeat;
  animation: finalRunner 3s steps(8, end) infinite;
}

.retreat {
  animation: slopRetreat 2.2s steps(5, end) infinite;
}

.credits-scroll {
  display: grid;
  gap: 14px;
  align-content: center;
}

.credits-scroll p {
  color: #f2d8a9;
  font-weight: 700;
}

.victory-text {
  color: var(--teal) !important;
  font: 700 16px/1.35 var(--font-pixel);
}

@keyframes freedOrb {
  0%, 100% { transform: translateX(-50%) translateY(0); }
  50% { transform: translateX(-50%) translateY(-10px); }
}

@keyframes finalRunner {
  0% { transform: translateX(0); }
  100% { transform: translateX(360px); }
}

@keyframes slopRetreat {
  0% { transform: translateX(0); opacity: 0.9; }
  100% { transform: translateX(-120px); opacity: 0.2; }
}

@keyframes forgeFlame {
  0%, 100% { transform: translateY(0) scaleX(1); }
  50% { transform: translateY(4px) scaleX(0.82); }
}

@keyframes forgeCrystal {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes forgeSpark {
  0% { transform: translateY(0); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translateY(-58px); opacity: 0; }
}

@keyframes socketAlarm {
  0%, 100% { transform: translateX(0); }
  50% { transform: translateX(4px); }
}

@media (max-width: 980px) {
  .coin-paper {
    height: min(94vh, 900px);
    overflow: auto;
  }

  .coin-component-row,
  .coin-main-grid,
  .coin-equation-grid,
  .coin-graft-strip {
    grid-template-columns: 1fr;
  }

  .coin-layout,
  .coin-derivation,
  .coin-proof-grid {
    grid-template-columns: 1fr;
  }

  .coin-scale-box {
    border-left: 0;
    border-top: 3px solid #111;
    padding: 16px 0 0;
  }

  .story-frame {
    grid-template-columns: 1fr;
  }

  .story-scene {
    min-height: 320px;
  }

  .hud {
    grid-template-columns: 1fr;
  }

  .room-nav {
    position: static;
    grid-template-columns: 1fr;
  }

  .kappa-control,
  .rate-legend {
    grid-template-columns: 1fr;
  }

  .hud-stats,
  .hud-actions {
    justify-content: flex-start;
  }

  .hero,
  .momentum-layout,
  .rate-scroll,
  .graft-grid,
  .forge-layout,
  .forge-challenge,
  .forge-stage,
  .rule-console,
  .quiz-layout,
  .decay-grid,
  .credits-layout {
    grid-template-columns: 1fr;
  }

  .hero {
    min-height: auto;
  }

  .palace-scene {
    min-height: 360px;
  }

  .rune-bank,
  .forge-choice-board,
  .forge-sockets {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 560px) {
  .coin-popup {
    align-items: stretch;
    justify-items: stretch;
    padding: 6px;
  }

  .coin-paper {
    display: block;
    width: calc(100vw - 12px);
    height: calc(100svh - 12px);
    height: calc(100dvh - 12px);
    max-height: none;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 54px 10px 14px;
    border-width: 2px;
    border-radius: 8px;
    box-shadow: 4px 4px 0 rgba(0, 0, 0, 0.85);
    -webkit-overflow-scrolling: touch;
  }

  .coin-close {
    position: fixed;
    top: 10px;
    right: 10px;
    left: auto;
    width: 36px;
    height: 36px;
    font-size: 18px;
    box-shadow: 2px 2px 0 #111;
  }

  .coin-close-hint {
    position: fixed;
    top: 16px;
    right: 54px;
    left: auto;
    max-width: calc(100% - 108px);
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 9px;
  }

  .coin-header {
    padding: 0 4px 10px;
  }

  .coin-header h1 {
    font-size: clamp(25px, 8.4vw, 34px);
    line-height: 0.98;
  }

  .coin-header h1 mjx-container {
    font-size: 82% !important;
  }

  .coin-header p {
    margin-top: 7px;
    font-size: 14px;
    line-height: 1.16;
  }

  .coin-component-row,
  .coin-main-grid,
  .coin-equation-grid,
  .coin-graft-strip {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    min-height: 0;
    overflow: visible;
  }

  .component-card {
    padding: 10px 10px 10px 13px;
    overflow: visible;
  }

  .component-card strong {
    font-size: 20px;
    line-height: 1.12;
  }

  .component-card p {
    font-size: 13px;
    line-height: 1.25;
  }

  .nesterov-bubble {
    margin-top: 8px;
    overflow-x: auto;
  }

  .nesterov-bubble mjx-container {
    font-size: 88% !important;
  }

  .coin-plot,
  .coin-mini-plot,
  .coin-equation-card,
  .coin-graft-strip,
  .coin-card,
  .coin-proof {
    padding: 10px;
    overflow-x: auto;
    overflow-y: visible;
  }

  .coin-mini-plot h2,
  .coin-equation-card h2,
  .coin-graft-strip h2 {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 5px;
    font-size: 18px;
    line-height: 1.12;
  }

  .coin-mini-plot svg {
    max-height: 190px;
  }

  .coin-mini-plot p,
  .coin-equation-card p {
    font-size: 12px;
    line-height: 1.24;
  }

  .coin-math,
  .coin-equation-card .coin-math {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    font-size: clamp(13px, 4vw, 16px);
    line-height: 1.12;
  }

  .shampoo-math {
    font-size: clamp(11.5px, 3.45vw, 14px);
  }

  .coin-paper mjx-container {
    max-width: none;
    font-size: 92% !important;
  }

  .shampoo-math mjx-container {
    font-size: 86% !important;
  }

  .coin-graft-strip .coin-scale-box {
    border-left: 0;
    border-top: 3px solid #d98b25;
    padding: 10px 0 0;
  }

  .coin-update-rule {
    max-width: 100%;
    overflow-x: auto;
    font-size: 13px;
  }

  .coin-graft-choice p {
    font-size: 11px;
    line-height: 1.18;
  }

  .coin-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 10px;
  }

  .coin-continue {
    width: 100%;
    padding: 12px 14px;
  }

  .coin-actions span {
    font-size: 12px;
    line-height: 1.25;
  }

  .rate-topline {
    display: grid;
  }

  .kappa-control {
    gap: 8px;
  }

  .story-overlay {
    padding: 12px;
  }

  .story-frame {
    width: 100%;
    padding: 14px;
  }

  .story-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .game-shell {
    width: min(100% - 16px, 1320px);
  }

  .room-band {
    margin: 14px 0;
    padding: 14px;
  }

  .pixel-button,
  .mode-button,
  .quiz-options button {
    width: 100%;
  }

  .quick-actions,
  .sim-toolbar,
  .hud-actions,
  .lesson-controls,
  .forge-actions,
  .room-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .sim-readout,
  .quiz-options,
  .rune-bank,
  .forge-choice-board,
  .forge-sockets {
    grid-template-columns: 1fr;
  }

  .palace-scene {
    min-height: 300px;
  }

  .forge-machine {
    min-height: 480px;
  }

  .forge-sockets {
    left: 14px;
    right: 14px;
  }

  .tower {
    width: 64px;
    height: 198px;
  }

  .gate {
    width: 170px;
    height: 170px;
  }

  .torch-left {
    left: 27%;
  }

  .torch-right {
    right: 27%;
  }
}

@media (min-width: 981px) and (max-height: 760px) {
  .coin-popup {
    padding: 10px;
  }

  .coin-paper {
    width: min(1220px, calc(100vw - 24px));
    height: calc(100vh - 20px);
    gap: 6px;
    padding: 10px;
  }

  .coin-kicker,
  .coin-mini-plot p,
  .coin-equation-card p,
  .component-card p,
  .coin-actions span {
    display: none;
  }

  .coin-header h1 {
    font-size: clamp(22px, 2.35vw, 32px);
  }

  .coin-header p {
    margin-top: 3px;
    font-size: 13px;
  }

  .component-card {
    padding: 7px 8px 6px 12px;
  }

  .nesterov-bubble {
    margin-top: 4px;
    padding: 5px 6px 2px;
  }

  .coin-mini-plot svg {
    max-height: 210px;
  }

  .coin-math {
    font-size: clamp(12px, 0.92vw, 15px);
  }

  .coin-equation-card .coin-math {
    font-size: clamp(14px, 1.05vw, 17px);
  }

  .shampoo-math {
    font-size: clamp(12.5px, 0.96vw, 15.5px);
  }

  .coin-graft-choice p {
    padding: 4px 6px;
    font-size: 11px;
  }

  .coin-continue {
    padding: 7px 12px;
  }
}
