:root {
  color-scheme: dark;
  --bg: #090b0d;
  --panel: #15191d;
  --line: #303941;
  --text: #f4f0e8;
  --muted: #a9b3ba;
  --accent: #31c48d;
  --warning: #f2b84b;
  --danger: #e25d5d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 18% 12%, rgba(49, 196, 141, 0.12), transparent 28%),
    radial-gradient(circle at 82% 16%, rgba(226, 93, 93, 0.13), transparent 30%),
    var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

body.playing {
  overflow: auto;
}

button {
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #202a31;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

button:hover {
  border-color: var(--accent);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.game-select-screen,
.start-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  min-height: 100vh;
  overflow: hidden;
  padding: 28px;
  background:
    linear-gradient(180deg, rgba(9, 11, 13, 0.72), rgba(9, 11, 13, 0.94)),
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 88px),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 70px),
    #090b0d;
}

.game-select-screen {
  grid-template-columns: 1fr 1fr;
  padding: 0;
  background: #090b0d;
}

.app.hidden,
.game-select-screen.hidden,
.start-screen.hidden,
.mathecraft-screen.hidden,
.mathecraft-game.hidden {
  display: none;
}

.formula-wall {
  position: absolute;
  inset: 0;
  color: rgba(244, 240, 232, 0.13);
  font-size: clamp(26px, 5vw, 78px);
  font-weight: 700;
  pointer-events: none;
}

.formula-wall span {
  position: absolute;
}

.formula-wall span:nth-child(1) { left: 8%; top: 12%; }
.formula-wall span:nth-child(2) { right: 8%; top: 18%; }
.formula-wall span:nth-child(3) { left: 14%; bottom: 18%; }
.formula-wall span:nth-child(4) { right: 18%; bottom: 12%; }
.formula-wall span:nth-child(5) { left: 42%; top: 8%; }
.formula-wall span:nth-child(6) { right: 42%; bottom: 24%; }

.mech-bg {
  position: absolute;
  bottom: 4%;
  width: min(260px, 24vw);
  aspect-ratio: 1 / 1.25;
  opacity: 0.5;
  filter: drop-shadow(0 20px 30px rgba(0, 0, 0, 0.35));
}

.mech-left {
  left: 5%;
}

.mech-right {
  right: 5%;
  transform: scaleX(-1);
}

.mech-bg::before,
.mech-bg::after {
  content: "";
  position: absolute;
  background: #8f98a3;
}

.mech-bg::before {
  left: 22%;
  top: 8%;
  width: 56%;
  height: 38%;
  border: 8px solid #202832;
  border-radius: 8px;
  box-shadow:
    -74px 42px 0 -16px #56616d,
    74px 42px 0 -16px #56616d,
    -98px 90px 0 -22px #8f98a3,
    98px 90px 0 -22px #8f98a3,
    -42px 142px 0 -12px #6b7480,
    42px 142px 0 -12px #6b7480;
}

.mech-bg::after {
  left: 33%;
  bottom: 3%;
  width: 18%;
  height: 42%;
  box-shadow:
    56px 0 0 #8f98a3,
    -12px 102px 0 14px #56616d,
    70px 102px 0 14px #56616d,
    20px -104px 0 -3px #202832;
}

.select-panel,
.start-panel {
  position: relative;
  z-index: 1;
  width: min(860px, 100%);
  border: 1px solid rgba(169, 179, 186, 0.28);
  border-radius: 8px;
  background: rgba(15, 20, 24, 0.9);
  padding: clamp(24px, 5vw, 48px);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
  text-align: center;
}

.game-choice {
  width: 100%;
  height: 100vh;
  border: 0;
  border-radius: 0;
  background: #13191d;
  color: var(--text);
  font-size: clamp(34px, 7vw, 96px);
  letter-spacing: 0;
}

.game-choice:hover {
  background: #1f2a30;
}

.game-choice-craft {
  border-right: 1px solid rgba(244, 240, 232, 0.18);
  background: #172019;
}

.game-choice-craft:hover {
  background: #203326;
}

.game-choice-stein {
  background: #161b22;
}

.game-choice-stein:hover {
  background: #242b34;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(42px, 8vw, 92px);
  line-height: 0.95;
}

.intro {
  max-width: 560px;
  margin: 14px auto 24px;
  color: var(--muted);
  font-size: 18px;
}

.primary-action {
  min-width: min(280px, 100%);
  min-height: 56px;
  border-color: rgba(49, 196, 141, 0.75);
  background: var(--accent);
  color: #06120e;
  font-size: 20px;
}

.start-actions {
  display: grid;
  grid-template-columns: minmax(120px, 180px) minmax(220px, 1fr);
  gap: 12px;
  max-width: 520px;
  margin: 0 auto;
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-top: 24px;
  text-align: left;
}

.mathecraft-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  min-height: 100vh;
  overflow: hidden;
  background:
    linear-gradient(180deg, #15202a 0%, #10212c 42%, #0b1114 43%, #0b1114 100%);
}

.mathecraft-home {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 28px;
}

.mathecraft-home-panel {
  width: min(760px, 100%);
  border: 1px solid rgba(169, 179, 186, 0.28);
  border-radius: 8px;
  background: rgba(15, 20, 24, 0.92);
  padding: clamp(24px, 5vw, 48px);
  text-align: center;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
}

.mathecraft-game {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  height: 100vh;
  padding: 14px;
}

.mathecraft-topbar {
  display: grid;
  grid-template-columns: 1fr auto 120px;
  gap: 12px;
  align-items: center;
  border: 1px solid rgba(169, 179, 186, 0.24);
  border-radius: 8px;
  background: rgba(15, 20, 24, 0.9);
  padding: 12px 14px;
}

.mathecraft-topbar h1 {
  font-size: clamp(30px, 4vw, 52px);
}

.mathecraft-stats {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.mathecraft-stats span {
  border: 1px solid rgba(169, 179, 186, 0.24);
  border-radius: 8px;
  background: rgba(32, 42, 49, 0.72);
  padding: 8px 12px;
  font-weight: 700;
}

#mathecraftCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
}

.craft-question {
  position: absolute;
  left: 50%;
  bottom: 70px;
  width: min(420px, calc(100% - 32px));
  transform: translateX(-50%);
  border: 1px solid rgba(242, 184, 75, 0.7);
  border-radius: 8px;
  background: rgba(12, 15, 17, 0.94);
  padding: 14px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}

.craft-question.hidden {
  display: none;
}

#craftQuestionText {
  margin: 2px 0 12px;
  font-size: 28px;
  font-weight: 700;
}

.craft-answer-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
}

.craft-answer-row input {
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10161b;
  color: var(--text);
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  padding: 0 12px;
}

.mathecraft-help {
  margin: 0;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.menu-box {
  min-height: 134px;
  border: 1px solid rgba(169, 179, 186, 0.22);
  border-radius: 8px;
  background: rgba(32, 42, 49, 0.68);
  padding: 14px;
}

.menu-box p {
  margin: 0;
}

.menu-box .label {
  margin-bottom: 8px;
}

.score-list {
  margin: 0;
  padding-left: 22px;
}

.score-list li {
  margin: 5px 0;
  font-weight: 700;
}

.app {
  width: min(1160px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 18px 0;
}

.hud {
  display: grid;
  gap: 10px;
}

.hud {
  grid-template-columns: 86px 92px 92px minmax(220px, 1fr) 120px;
  margin-bottom: 10px;
}

.hud > div {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(21, 25, 29, 0.96);
  padding: 10px 12px;
}

.question-box {
  min-width: 0;
}

.label {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.value {
  margin: 0;
  overflow: hidden;
  font-size: 22px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stage {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #000;
  overflow: hidden;
  box-shadow: 0 20px 70px rgba(0, 0, 0, 0.35);
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
}

.door-panel {
  position: absolute;
  left: 50%;
  bottom: 28px;
  width: min(420px, calc(100% - 32px));
  transform: translateX(-50%);
  border: 1px solid rgba(242, 184, 75, 0.58);
  border-radius: 8px;
  background: rgba(12, 15, 17, 0.92);
  padding: 14px;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.5);
}

.door-panel.hidden {
  display: none;
}

.door-question {
  margin: 2px 0 12px;
  font-size: 28px;
  font-weight: 700;
}

.door-timer {
  position: absolute;
  top: 12px;
  right: 14px;
  min-width: 46px;
  margin: 0;
  border: 1px solid rgba(242, 184, 75, 0.58);
  border-radius: 8px;
  background: rgba(242, 184, 75, 0.14);
  color: #f2b84b;
  font-size: 24px;
  font-weight: 700;
  line-height: 42px;
  text-align: center;
}

.door-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 120px;
  gap: 10px;
}

.door-row input {
  min-width: 0;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10161b;
  color: var(--text);
  font: inherit;
  font-size: 20px;
  font-weight: 700;
  padding: 0 12px;
}

.end-screen {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.72);
  padding: 24px;
}

.end-screen.hidden {
  display: none;
}

.end-panel {
  width: min(520px, 100%);
  border: 1px solid rgba(169, 179, 186, 0.28);
  border-radius: 8px;
  background: rgba(15, 20, 24, 0.96);
  padding: 30px;
  text-align: center;
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.5);
}

.end-panel h2 {
  margin: 0;
  font-size: clamp(34px, 6vw, 60px);
}

#endText {
  margin: 12px 0 22px;
  color: var(--muted);
  font-size: 20px;
  font-weight: 700;
}

.end-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 780px) {
  .hud {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .question-box,
  #homeButton {
    grid-column: 1 / -1;
  }

  .door-row {
    grid-template-columns: 1fr;
  }

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

  .start-actions,
  .mathecraft-topbar {
    grid-template-columns: 1fr;
  }

  .game-select-screen {
    grid-template-columns: 1fr;
  }

  .game-choice {
    height: 50vh;
  }

  .mech-bg {
    display: none;
  }
}
