@font-face {
  font-family: "Space Grotesk";
  src: url("assets/space-grotesk-latin-wght-normal.woff2") format("woff2");
  font-weight: 300 700;
  font-display: swap;
}

:root {
  color-scheme: dark;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  font-synthesis: none;
  --background: #0c0914;
  --surface: #141020;
  --stroke: #2b223c;
  --text: #f0eaf9;
  --muted: #afa4c1;
  --lavender: #c1a9ff;
  --lime: #d4ff6b;
  --seed: #ff8ed2;
  --mono: "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  min-width: 280px;
  min-height: 100vh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(ellipse 70% 48% at 47% 0%, #1b102c 0%, transparent 100%),
    var(--background);
}

button { font: inherit; cursor: pointer; }
button:disabled { cursor: wait; }
button:focus-visible { outline: 2px solid var(--lime); outline-offset: 4px; }

.shell {
  width: min(100%, 1440px);
  margin-inline: auto;
  padding: clamp(24px, 4vw, 56px) clamp(18px, 4.5vw, 64px) 36px;
}

.masthead {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 20px;
  margin-bottom: 28px;
}

.identity { display: flex; align-items: center; gap: 16px; }

.mark {
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  color: var(--lime);
  background: linear-gradient(145deg, #29321a, #151b13);
  border: 1px solid #56683a;
  border-radius: 14px;
  box-shadow: inset 0 1px #d4ff6b23, 0 0 24px #b2ff3620;
}

.mark svg { width: 42px; height: 42px; }
.brand h1 {
  font-size: clamp(2.25rem, 4.2vw, 3.3rem);
  line-height: 0.9;
  letter-spacing: -0.087em;
  margin: 0;
  font-weight: 700;
  text-transform: uppercase;
  white-space: nowrap;
}
.brand h1 span { color: var(--lime); margin-left: 0.035em; }
.brand p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.765rem;
  font-weight: 600;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.sound-toggle {
  min-height: 43px;
  padding: 0 13px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  justify-content: center;
  color: var(--text);
  background: #191224;
  border: 1px solid #392c4c;
  border-radius: 9px;
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
}

.sound-toggle:hover { background: #251a35; border-color: #59466f; }
.sound-toggle svg { width: 18px; height: 18px; color: var(--lavender); }
.sound-icon, .sound-toggle[aria-pressed="true"] .muted-icon { display: none; }
.sound-toggle[aria-pressed="true"] .sound-icon { display: inline; }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(242px, 21.5vw, 305px);
  grid-template-rows: auto auto 1fr;
  grid-template-areas: "arena telemetry" "arena actions" "arena instructions";
  gap: 16px 20px;
  align-items: start;
}

.arena {
  grid-area: arena;
  isolation: isolate;
  position: relative;
  width: 100%;
  height: clamp(510px, 70vh, 660px);
  overflow: hidden;
  touch-action: none;
  background:
    radial-gradient(ellipse at 50% 45%, #241637 0%, #120e20 60%, #0d0a17 100%);
  border: 1px solid #47355d;
  border-radius: 20px;
  box-shadow: inset 0 1px #b48afc23, 0 24px 80px #02010580;
}

.arena-atmosphere {
  position: absolute;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image:
    radial-gradient(ellipse at 50% 48%, transparent 34%, #0a061358 100%),
    linear-gradient(180deg, #130b2180, #150b290c 32%, #12091d44 67%, #0a0615b3),
    url("assets/terrarium.webp");
  background-size: cover;
  background-position: center;
}

#world { display: block; position: absolute; inset: 0; width: 100%; height: 100%; }

.arena-header {
  position: absolute;
  top: 23px;
  left: 24px;
  right: 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  gap: 12px;
}
.arena-label,
.data-label,
.level,
.arena-caption {
  font-family: var(--mono);
  font-size: 0.8125rem;
  letter-spacing: 0.065em;
  text-transform: uppercase;
}
.arena-label { color: #d3c4ec; }
.run-status {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 29px;
  padding: 0 10px;
  border: 1px solid #5a446e;
  border-radius: 6px;
  background: #151022eb;
  color: #e3d2fb;
  font-size: 0.8125rem;
  font-family: var(--mono);
}
.run-status i {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 8px currentColor;
}
.run-status[data-state="playing"], .run-status[data-state="won"] { color: var(--lime); border-color: #697f44; }
.run-status[data-state="over"] { color: #ffafd3; border-color: #83506d; }

.stage-corner {
  position: absolute;
  width: 34px;
  height: 34px;
  border: 0 solid #79629980;
  z-index: 1;
  pointer-events: none;
}
.top-left { top: 11px; left: 11px; border-top-width: 1px; border-left-width: 1px; border-top-left-radius: 10px; }
.top-right { top: 11px; right: 11px; border-top-width: 1px; border-right-width: 1px; border-top-right-radius: 10px; }
.bottom-left { bottom: 11px; left: 11px; border-bottom-width: 1px; border-left-width: 1px; border-bottom-left-radius: 10px; }
.bottom-right { bottom: 11px; right: 11px; border-bottom-width: 1px; border-right-width: 1px; border-bottom-right-radius: 10px; }

.arena-caption {
  position: absolute;
  left: 25px;
  bottom: 23px;
  color: #cfbcdf;
  display: inline-flex;
  gap: 9px;
  align-items: center;
  pointer-events: none;
}
.seed-icon {
  display: inline-block;
  width: 7px;
  height: 7px;
  background: var(--seed);
  border-radius: 1px;
  box-shadow: 0 0 9px #fa66bbaa;
  transform: rotate(45deg);
}

.run-summary {
  position: absolute;
  z-index: 2;
  top: 51%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(calc(100% - 38px), 350px);
  padding: 22px 18px;
  border: 1px solid #7b629e;
  border-radius: 14px;
  color: var(--text);
  text-align: center;
  background: linear-gradient(155deg, #201431f7, #110b1beF);
  box-shadow: 0 14px 50px #070411b8, inset 0 1px #c39bff35;
  pointer-events: none;
}
.summary-title { display: block; font-size: clamp(1.7rem, 3vw, 2.6rem); font-weight: 700; line-height: 1.05; letter-spacing: -0.055em; }
.run-summary p { margin: 9px 0 0; color: #d4c5e5; font-size: 0.94rem; }
.arena[data-state="won"] .run-summary { border-color: #a2bd6b; }
.arena[data-state="won"] .summary-title { color: var(--lime); }

.telemetry,
.instructions {
  border: 1px solid var(--stroke);
  border-radius: 15px;
  background: linear-gradient(145deg, #1b1329, var(--surface));
  box-shadow: inset 0 1px #b390ec1b, 0 12px 32px #05020d37;
}
.telemetry { grid-area: telemetry; padding: 21px 21px 23px; }
.scores { display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: start; }
.score { min-width: 0; display: grid; justify-items: start; }
.data-label { display: inline-flex; gap: 8px; align-items: center; color: var(--muted); }
.score strong {
  margin: 3px 0 2px;
  color: var(--lime);
  text-shadow: 0 0 24px #b8ff4352;
  font-size: clamp(3rem, 5vw, 4.4rem);
  letter-spacing: -0.085em;
  line-height: 1.04;
  font-variant-numeric: tabular-nums;
}
.best-score {
  padding-left: 15px;
  margin-left: 2px;
  border-left: 1px solid #382b49;
  align-self: center;
}
.best-score strong {
  margin-top: 6px;
  font-size: clamp(1.4rem, 2.7vw, 2.2rem);
  letter-spacing: -0.045em;
  color: #e4d8f3;
  text-shadow: none;
}
.seed-tracker { border-top: 1px solid #352944; padding-top: 17px; margin-top: 16px; }
.tracker-labels { display: flex; justify-content: space-between; align-items: center; gap: 6px; margin-bottom: 10px; }
.tracker-labels strong { color: #e8d9f4; font-weight: 600; }
.tracker-labels .seed-icon { margin-right: 2px; }
.level { color: var(--lavender); white-space: nowrap; }
.seed-meter { display: grid; gap: 5px; grid-template-columns: repeat(5, 1fr); }
.seed-meter span { display: block; height: 5px; border-radius: 3px; background: #392d4b; overflow: hidden; }
.seed-meter i { display: block; width: 0; height: 100%; background: linear-gradient(90deg, #b281ff, #f59bea); border-radius: inherit; transition: width 200ms ease-out; }

.actions { grid-area: actions; }
.run-action {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 56px;
  width: 100%;
  padding: 10px 16px;
  border: 1px solid #e5ffa9;
  border-radius: 12px;
  color: #151b0c;
  background: linear-gradient(170deg, #e5ff9d, #c3f457 80%);
  font-size: 1.125rem;
  font-weight: 700;
  box-shadow: 0 0 32px #b5ff3730, inset 0 1px #fff8, 0 4px 0 #648b31;
  transition: background 140ms, transform 140ms, box-shadow 140ms;
}
.run-action:disabled { opacity: 0.72; }
.run-action:not(:disabled):hover {
  background: linear-gradient(170deg, #f1ffc4, #d3ff74 80%);
  box-shadow: 0 0 37px #b5ff3757, inset 0 1px #fff8, 0 4px 0 #648b31;
}
.run-action:not(:disabled):active { transform: translateY(2px); box-shadow: 0 0 23px #b5ff3730, 0 2px 0 #648b31; }
.run-action svg { display: block; width: 20px; height: 20px; }
.keyboard-hint { margin: 13px 0 0; color: var(--muted); text-align: center; font-size: 0.8125rem; }
kbd { font-family: var(--mono); font-size: 0.75rem; padding: 1px 4px; border: 1px solid #463657; border-radius: 4px; color: #e2d4f2; background: #20162d; }

.instructions { grid-area: instructions; padding: 19px 21px 21px; }
.instructions h2 { margin: 0 0 5px; font-size: 1.125rem; letter-spacing: -0.03em; }
.instructions p { margin: 0; color: var(--muted); font-size: 0.938rem; line-height: 1.48; }
.movement { display: flex; align-items: end; gap: 12px; margin-top: 17px; }
.movement p { font-size: 0.8125rem; line-height: 1.35; padding-bottom: 3px; }
.movement strong { font-weight: 700; color: var(--text); }
.touch-movement { display: none; }
.direction-pad { display: grid; grid-template-columns: repeat(3, 36px); gap: 4px; flex: 0 0 auto; }
.direction-key {
  display: grid;
  place-items: center;
  padding: 0;
  width: 36px;
  height: 30px;
  border: 1px solid #544268;
  border-radius: 6px;
  color: #e9dcf8;
  background: linear-gradient(#30233f, #21182e);
  box-shadow: 0 2px 0 #0b0814;
  font-size: 1.0625rem;
  line-height: 1;
  touch-action: manipulation;
  user-select: none;
}
.direction-key[data-direction="up"] { grid-column: 2; }
.direction-key[data-direction="left"] { grid-column: 1; }
.direction-key:hover { background: #45335b; }
.direction-key:active, .direction-key[data-pressed] { background: #d5baff; border-color: #d5baff; color: #1b1028; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.load-note { color: var(--muted); }

@media (max-width: 780px) {
  .shell { max-width: 590px; padding-top: max(19px, env(safe-area-inset-top)); }
  .masthead { margin-bottom: 16px; }
  .identity { gap: 11px; }
  .mark { width: 43px; height: 43px; border-radius: 10px; }
  .mark svg { width: 32px; height: 32px; }
  .brand h1 { font-size: clamp(1.45rem, 6.3vw, 2.4rem); }
  .brand p { font-size: 0.625rem; letter-spacing: 0.12em; margin-top: 4px; }
  .sound-toggle { min-height: 40px; padding-inline: 9px; }
  .game-layout {
    grid-template-areas: "telemetry" "arena" "actions" "instructions";
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto;
    gap: 12px;
  }
  .arena { height: clamp(298px, 49vh, 470px); border-radius: 15px; }
  .arena-header { top: 15px; left: 16px; right: 16px; }
  .arena-caption { bottom: 15px; left: 16px; font-size: 0.7rem; }
  .arena-label { font-size: 0.7rem; }
  .stage-corner { width: 23px; height: 23px; }
  .top-left, .top-right { top: 7px; }
  .bottom-left, .bottom-right { bottom: 7px; }
  .top-left, .bottom-left { left: 7px; }
  .top-right, .bottom-right { right: 7px; }
  .telemetry { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: center; padding: 10px 13px 11px; }
  .scores { gap: 10px; }
  .data-label, .level { font-size: 0.6875rem; letter-spacing: 0.035em; }
  .score strong { margin: 3px 0 0; font-size: 2rem; line-height: 1; }
  .best-score { padding-left: 10px; }
  .best-score strong { font-size: 1.35rem; }
  .seed-tracker { margin: 0; padding: 0 0 0 12px; border: 0; border-left: 1px solid #382b49; }
  .tracker-labels { margin-bottom: 8px; }
  .tracker-labels .data-label { gap: 5px; }
  .tracker-labels .seed-icon { display: none; }
  .run-action { min-height: 48px; }
  .instructions { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 13px; }
  .instructions-copy { flex: 1; }
  .instructions h2 { font-size: 0.975rem; }
  .instructions p { font-size: 0.83rem; }
  .movement { display: grid; margin-top: 0; justify-items: end; gap: 6px; }
  .movement p { padding: 0; max-width: 142px; font-size: 0.73rem; text-align: right; }
}

@media (max-width: 375px) {
  .shell { padding-inline: 12px; }
  .masthead { gap: 8px; }
  .telemetry { gap: 9px; padding-inline: 10px; }
  .seed-tracker { padding-left: 9px; }
  .scores { gap: 6px; }
  .best-score { padding-left: 6px; }
  .tracker-labels { gap: 4px; }
}

@media (max-width: 340px) {
  .sound-toggle span { display: none; }
  .sound-toggle { min-width: 40px; }
}

@media (pointer: coarse) {
  .keyboard-hint, .desktop-movement { display: none; }
  .touch-movement { display: block; }
  .direction-pad { grid-template-columns: repeat(3, 44px); }
  .direction-key { width: 44px; height: 39px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}
