:root {
  color-scheme: dark;
  --bg: #141414;
  --panel: #202020;
  --panel-2: #292722;
  --ink: #f2f0e8;
  --muted: #b9b4a8;
  --green: #a7db65;
  --teal: #52c7b8;
  --amber: #f2b84b;
  --coral: #f26f63;
  --violet: #b99cff;
  --line: #3f3a32;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  margin: 0;
  background:
    linear-gradient(135deg, rgba(82, 199, 184, 0.12), transparent 42%),
    linear-gradient(210deg, rgba(242, 184, 75, 0.1), transparent 48%),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.site-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 18px 0 0;
}

.back-home {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 42px;
  padding: 9px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(32, 32, 32, 0.86);
  color: var(--ink);
  font-weight: 900;
}

.back-home:hover,
.back-home:focus-visible,
.game-footer a:hover,
.game-footer a:focus-visible {
  border-color: var(--green);
  color: var(--green);
  outline: none;
}

.site-bar-label,
.game-footer {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.74rem;
}

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

.game-footer {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 6px 0 30px;
  border-top: 1px solid var(--line);
}

.game-footer a {
  border-bottom: 1px solid transparent;
}

.hud {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--green);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 0;
  font-size: 3.8rem;
  line-height: 0.94;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 2.35rem;
  line-height: 1.05;
  letter-spacing: 0;
}

.meters {
  display: grid;
  grid-template-columns: repeat(3, minmax(84px, 1fr));
  gap: 10px;
  min-width: min(380px, 100%);
}

.meter {
  min-height: 74px;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(32, 32, 32, 0.86);
  box-shadow: var(--shadow);
}

.meter span {
  display: block;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.meter strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 1.6rem;
  line-height: 1;
}

.progress-strip {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 16px;
}

.level-chip {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(32, 32, 32, 0.74);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.level-chip.current {
  border-color: var(--green);
  color: var(--ink);
  box-shadow: inset 0 -3px 0 var(--green);
}

.level-chip.done {
  border-color: rgba(82, 199, 184, 0.7);
  color: var(--teal);
}

.arena {
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(360px, 1.05fr);
  gap: 16px;
  align-items: stretch;
}

.scene,
.challenge {
  min-height: 520px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(32, 32, 32, 0.9);
  box-shadow: var(--shadow);
}

.scene {
  position: relative;
  overflow: hidden;
  padding: 22px;
}

.scene-title {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 800;
  text-transform: uppercase;
}

.challenge {
  display: flex;
  flex-direction: column;
  padding: 24px;
}

.challenge-head {
  margin-bottom: 18px;
}

.prompt {
  min-height: 58px;
  margin: 0 0 18px;
  color: var(--ink);
  font-size: 1.12rem;
  line-height: 1.5;
}

.answer-zone {
  display: grid;
  gap: 10px;
}

.lesson-panel,
.code-panel,
.task-panel {
  display: grid;
  gap: 10px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

.lesson-panel h3,
.code-panel h3,
.task-panel h3 {
  margin: 0;
  color: var(--green);
  font-size: 0.95rem;
}

.lesson-panel p {
  margin: 0;
  color: var(--ink);
  line-height: 1.55;
}

.code-row {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(120px, 0.8fr);
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.code-row:first-of-type {
  border-top: 0;
}

.code-row code {
  display: block;
  color: var(--teal);
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.code-row span {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.answer-button,
.snippet-button,
.slot-button,
.primary-button,
.ghost-button {
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel-2);
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.answer-button,
.snippet-button,
.slot-button {
  width: 100%;
  padding: 12px 14px;
  text-align: left;
  overflow-wrap: anywhere;
}

.answer-button:hover,
.answer-button:focus-visible,
.snippet-button:hover,
.snippet-button:focus-visible,
.slot-button:hover,
.slot-button:focus-visible,
.primary-button:hover,
.primary-button:focus-visible,
.ghost-button:hover,
.ghost-button:focus-visible {
  transform: translateY(-1px);
  border-color: var(--green);
  outline: none;
}

.answer-button[disabled],
.snippet-button[disabled] {
  cursor: default;
  opacity: 0.58;
  transform: none;
}

.answer-button.correct {
  border-color: var(--teal);
  background: rgba(82, 199, 184, 0.18);
}

.answer-button.wrong {
  border-color: var(--coral);
  background: rgba(242, 111, 99, 0.18);
}

.feedback {
  min-height: 70px;
  margin-top: auto;
  padding-top: 18px;
  color: var(--muted);
  line-height: 1.5;
}

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

.feedback.bad {
  color: #ffaaa2;
}

.feedback.coach-note {
  color: var(--amber);
}

.controls {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.primary-button,
.ghost-button {
  min-width: 116px;
  padding: 0 18px;
  text-align: center;
  font-weight: 900;
}

.primary-button {
  border-color: var(--green);
  background: var(--green);
  color: #16200d;
}

.primary-button[disabled] {
  cursor: default;
  opacity: 0.54;
  transform: none;
}

.ghost-button {
  background: transparent;
  color: var(--muted);
}

.ghost-button[disabled] {
  cursor: default;
  opacity: 0.42;
  transform: none;
}

.memory-stack {
  display: grid;
  grid-template-rows: 1fr 1fr 1fr;
  gap: 12px;
  height: 420px;
}

.memory-stack.compact {
  height: 250px;
}

.memory-lane {
  position: relative;
  display: grid;
  align-content: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.memory-lane strong {
  font-size: 1.25rem;
}

.memory-lane span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.86rem;
}

.memory-lane::after {
  content: "";
  position: absolute;
  inset: auto 12px 12px auto;
  width: 84px;
  height: 28px;
  border-radius: 4px;
  opacity: 0.8;
}

.memory-lane.stack {
  background: rgba(167, 219, 101, 0.08);
}

.memory-lane.stack::after {
  background: repeating-linear-gradient(90deg, var(--green) 0 12px, transparent 12px 18px);
}

.memory-lane.heap {
  background: rgba(82, 199, 184, 0.08);
}

.memory-lane.heap::after {
  background: radial-gradient(circle, var(--teal) 35%, transparent 38%) 0 0 / 18px 18px;
}

.memory-lane.static {
  background: rgba(242, 184, 75, 0.08);
}

.memory-lane.static::after {
  background: linear-gradient(90deg, var(--amber), var(--coral));
}

.address-label {
  position: absolute;
  right: 20px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
}

.address-label.high {
  top: 22px;
}

.address-label.low {
  bottom: 20px;
}

.terminal-art {
  display: grid;
  gap: 10px;
  margin-top: 22px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111;
  font-family: "SFMono-Regular", Consolas, monospace;
  color: var(--green);
}

.toolbelt {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 24px;
}

.toolbelt div {
  min-height: 104px;
  display: grid;
  align-content: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(82, 199, 184, 0.08);
}

.toolbelt strong {
  color: var(--teal);
  font-size: 1.15rem;
}

.toolbelt span {
  margin-top: 6px;
  color: var(--muted);
}

.terminal-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 28px;
}

.terminal-line span:last-child {
  color: var(--teal);
}

.array-art {
  display: grid;
  gap: 18px;
  margin-top: 30px;
}

.array-row {
  display: grid;
  grid-template-columns: 74px repeat(8, minmax(0, 1fr));
  gap: 6px;
  align-items: center;
}

.array-row span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.cell {
  aspect-ratio: 1 / 1;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
  font-size: 0.82rem;
}

.cell.used {
  border-color: var(--teal);
  background: rgba(82, 199, 184, 0.16);
  color: var(--ink);
}

.pipeline {
  display: grid;
  gap: 22px;
  margin-top: 30px;
}

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

.pipe-node {
  min-height: 76px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(242, 184, 75, 0.09);
  color: var(--ink);
  text-align: center;
  font-weight: 900;
}

.pipe-node.hot {
  border-color: var(--amber);
}

.pipe-arrow {
  align-self: center;
  color: var(--muted);
  text-align: center;
  font-weight: 900;
}

.file-art {
  display: grid;
  grid-template-columns: 1fr 90px 1fr;
  gap: 12px;
  align-items: center;
  margin-top: 44px;
}

.file-box {
  min-height: 190px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(82, 199, 184, 0.08);
}

.file-box strong {
  display: block;
  margin-bottom: 10px;
  color: var(--teal);
}

.file-box code {
  display: block;
  color: var(--ink);
  line-height: 1.8;
}

.stream-arrow {
  color: var(--amber);
  font-size: 1.3rem;
  font-weight: 900;
  text-align: center;
}

.sequence-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.snippet-list,
.slot-list {
  display: grid;
  gap: 8px;
  align-content: start;
}

.slot-button {
  min-height: 66px;
  background: rgba(255, 255, 255, 0.035);
  color: var(--muted);
}

.slot-button.filled {
  border-color: var(--teal);
  color: var(--ink);
}

.snippet-button code,
.slot-button code {
  display: block;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.35;
}

.complete-panel {
  display: grid;
  gap: 14px;
}

.complete-panel h3 {
  margin: 0;
  font-size: 1.45rem;
}

.complete-panel p {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.topic-list {
  display: grid;
  gap: 8px;
  margin: 6px 0 0;
  padding: 0;
  list-style: none;
}

.topic-list li {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.035);
}

@media (max-width: 860px) {
  .site-bar,
  .game-footer {
    width: min(100% - 20px, 680px);
  }

  .game-shell {
    width: min(100% - 20px, 680px);
    padding: 18px 0;
  }

  .hud {
    align-items: stretch;
    flex-direction: column;
  }

  h1 {
    font-size: 3rem;
  }

  h2 {
    font-size: 2rem;
  }

  .meters,
  .progress-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .scene,
  .challenge {
    min-height: auto;
  }

  .memory-stack {
    height: auto;
    min-height: 360px;
  }

  .memory-stack.compact {
    min-height: 250px;
  }

  .sequence-board {
    grid-template-columns: 1fr;
  }

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

  .file-art {
    grid-template-columns: 1fr;
  }

  .stream-arrow {
    transform: rotate(90deg);
  }
}

@media (max-width: 520px) {
  .site-bar-label {
    display: none;
  }

  .game-footer {
    flex-direction: column;
  }

  h1 {
    font-size: 2.2rem;
  }

  h2 {
    font-size: 1.55rem;
  }

  .prompt {
    font-size: 1rem;
  }

  .meters,
  .progress-strip {
    grid-template-columns: 1fr;
  }

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

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

  .array-row {
    grid-template-columns: 44px repeat(8, minmax(18px, 1fr));
    gap: 4px;
  }

  .controls {
    flex-direction: column;
  }

  .primary-button,
  .ghost-button {
    width: 100%;
  }
}
