:root {
  color-scheme: dark;
  --ink: #eee7ce;
  --muted: #a9a486;
  --mud: #171a12;
  --panel: #1d2116;
  --line: rgb(233 224 184 / 16%);
  --lamp: #ffe491;
  --acid: #d8ef72;
  --danger: #ff5f49;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
}

body {
  overflow: hidden;
  overscroll-behavior: none;
  background: #0c0e09;
  color: var(--ink);
  font-family: "Arial Narrow", "Roboto Condensed", "Franklin Gothic Medium", ui-sans-serif, system-ui, sans-serif;
}

button { color: inherit; font: inherit; }

.game-shell {
  width: 100vw;
  height: 100vh;
  height: 100svh;
  display: grid;
  grid-template-rows: 48px 58px minmax(0, 1fr);
  background: #10130d;
}

.topbar {
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 10px;
  padding: 0 clamp(10px, 2vw, 22px);
  border-bottom: 1px solid var(--line);
  background: #11140edb;
  backdrop-filter: blur(12px);
}

.back-link {
  justify-self: start;
  color: var(--muted);
  font-size: .68rem;
  font-weight: 900;
  letter-spacing: .1em;
  text-decoration: none;
  text-transform: uppercase;
}

.back-link:hover { color: var(--lamp); }

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: clamp(.7rem, 2.3vw, .9rem);
  font-weight: 950;
  letter-spacing: .095em;
  white-space: nowrap;
}

.brand i { color: var(--muted); font-size: .7em; font-style: normal; }

.brand-lamp {
  position: relative;
  width: 13px;
  height: 18px;
  display: block;
  border: 2px solid #4a4c39;
  border-radius: 6px 6px 4px 4px;
  background: var(--lamp);
  box-shadow: 0 0 13px #ffe49188;
}

.brand-lamp::before {
  content: "";
  position: absolute;
  width: 8px;
  height: 4px;
  left: 1px;
  top: -6px;
  border: 2px solid #727258;
  border-bottom: 0;
  border-radius: 6px 6px 0 0;
}

.top-actions { justify-self: end; display: flex; gap: 6px; }

.icon-button {
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #22261a;
  color: var(--ink);
  font-weight: 900;
  cursor: pointer;
}

.icon-button:hover { border-color: #ffe49188; background: #2a2e1f; }
.icon-button[aria-pressed="true"] { color: #77755f; }

.hud {
  z-index: 15;
  display: grid;
  grid-template-columns: minmax(56px, .65fr) minmax(104px, 1.2fr) minmax(80px, 1fr) minmax(92px, 1.1fr);
  align-items: stretch;
  border-bottom: 1px solid var(--line);
  background: #181b12;
}

.hud-stat,
.seed-button {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 7px clamp(8px, 2vw, 20px);
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  text-align: left;
}

.hud-stat span,
.seed-button span {
  overflow: hidden;
  color: #8f9072;
  font-size: clamp(.46rem, 1.7vw, .58rem);
  font-weight: 900;
  letter-spacing: .13em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-stat strong,
.seed-button strong {
  overflow: hidden;
  color: var(--ink);
  font-size: clamp(.92rem, 3vw, 1.2rem);
  font-weight: 950;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-main { background: #202417; }
.hud-main strong { color: var(--lamp); }
.seed-button { border-right: 0; cursor: pointer; }
.seed-button:hover { background: #24281b; }
.seed-button.copied strong { color: var(--acid); }

.stage { position: relative; min-height: 0; overflow: hidden; background: var(--mud); touch-action: none; }

#game-canvas {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.vignette {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 2;
  box-shadow: inset 0 0 clamp(60px, 15vw, 180px) rgb(0 0 0 / 70%);
  background: radial-gradient(circle at center, transparent 48%, rgb(4 7 3 / 30%) 100%);
}

.toast {
  pointer-events: none;
  position: absolute;
  z-index: 6;
  top: clamp(15px, 5vh, 44px);
  left: 50%;
  padding: 7px 13px 6px;
  border: 1px solid rgb(255 228 145 / 34%);
  border-radius: 3px;
  opacity: 0;
  background: rgb(17 20 13 / 84%);
  color: var(--lamp);
  font-size: clamp(.68rem, 2vw, .85rem);
  font-weight: 950;
  letter-spacing: .16em;
  transform: translate(-50%, -8px);
  transition: opacity 150ms ease, transform 150ms ease;
  white-space: nowrap;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.danger { border-color: #ff604977; color: #ff8c76; }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  opacity: 0;
  visibility: hidden;
  background: rgb(8 10 6 / 62%);
  backdrop-filter: blur(5px);
  transition: opacity 220ms ease, visibility 220ms ease;
}

.overlay.visible { opacity: 1; visibility: visible; }

.briefing {
  width: min(94vw, 520px);
  max-height: calc(100svh - 130px);
  overflow: auto;
  padding: clamp(22px, 5vw, 38px);
  border: 1px solid #8d8d654f;
  border-radius: 4px;
  background:
    linear-gradient(rgb(255 255 255 / 2%), transparent),
    repeating-linear-gradient(0deg, transparent 0 22px, rgb(255 255 255 / 1.4%) 23px),
    #1a1e14;
  box-shadow: 0 24px 80px rgb(0 0 0 / 56%), inset 0 0 70px rgb(0 0 0 / 22%);
  text-align: center;
}

.insignia {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  margin: 0 auto 12px;
  border: 2px solid #77785b;
  border-radius: 50%;
  transform: rotate(45deg);
}

.insignia span { width: 14px; height: 14px; display: block; background: var(--lamp); box-shadow: 0 0 15px #ffe49188; }

.eyebrow {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: .63rem;
  font-weight: 900;
  letter-spacing: .21em;
}

.briefing h1 {
  margin: 0;
  color: #f2ecd8;
  font-size: clamp(2rem, 8vw, 3.5rem);
  font-weight: 950;
  letter-spacing: -.045em;
  line-height: .83;
}

.briefing h1 em { color: var(--lamp); font-style: normal; }

.briefing-copy {
  max-width: 410px;
  margin: 18px auto 17px;
  color: #b8b59b;
  font-size: clamp(.78rem, 2vw, .9rem);
  line-height: 1.55;
}

.legend {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  margin: 0 0 15px;
}

.legend span {
  min-width: 0;
  display: grid;
  place-items: center;
  gap: 7px;
  padding: 10px 5px;
  border: 1px solid var(--line);
  color: #a6a38a;
  font-size: .5rem;
  font-weight: 900;
  letter-spacing: .08em;
}

.legend i { width: 24px; height: 18px; display: block; }
.legend-cone { clip-path: polygon(50% 100%, 0 0, 100% 0); background: #ffe49199; }
.legend-switch { border: 3px solid #2a2d1f; border-radius: 50%; background: var(--acid); box-shadow: 0 0 8px #d8ef7277; }
.legend-noise { border: 2px solid #d9dac0; border-radius: 50%; box-shadow: 0 0 0 4px #d9dac033; }

.controls-copy {
  display: flex;
  justify-content: center;
  gap: 20px;
  color: #85866d;
  font-size: .59rem;
  font-weight: 800;
  letter-spacing: .08em;
}

.controls-copy b { color: #cbc7aa; }

.overlay-actions { display: flex; gap: 8px; margin-top: 20px; }

.primary-button,
.secondary-button {
  min-height: 44px;
  border: 0;
  border-radius: 2px;
  font-size: .67rem;
  font-weight: 950;
  letter-spacing: .12em;
  cursor: pointer;
}

.primary-button { flex: 1.7; background: var(--lamp); color: #242317; }
.primary-button:hover { background: #fff0bd; }
.secondary-button { flex: 1; border: 1px solid var(--line); background: #262a1d; color: #b8b59c; }
.secondary-button:hover { border-color: #ffe49166; color: var(--ink); }

.best-score { margin: 13px 0 0; color: #70715d; font-size: .55rem; font-weight: 900; letter-spacing: .14em; }

.joystick {
  pointer-events: none;
  position: absolute;
  z-index: 7;
  left: 22px;
  bottom: 22px;
  width: 104px;
  height: 104px;
  display: none;
  place-items: center;
  opacity: .72;
}

.joystick-ring {
  position: absolute;
  inset: 0;
  border: 2px solid rgb(239 232 204 / 28%);
  border-radius: 50%;
  background: rgb(12 14 9 / 42%);
  box-shadow: inset 0 0 20px rgb(0 0 0 / 35%);
}

.joystick-ring::before,
.joystick-ring::after { content: ""; position: absolute; background: rgb(239 232 204 / 12%); }
.joystick-ring::before { width: 1px; height: 70%; left: 50%; top: 15%; }
.joystick-ring::after { height: 1px; width: 70%; top: 50%; left: 15%; }

.joystick-knob {
  position: relative;
  width: 42px;
  height: 42px;
  border: 2px solid rgb(255 239 188 / 52%);
  border-radius: 50%;
  background: rgb(75 77 53 / 88%);
  box-shadow: 0 5px 15px rgb(0 0 0 / 35%);
}

.desktop-hint {
  position: absolute;
  z-index: 5;
  right: 13px;
  bottom: 10px;
  color: rgb(227 220 190 / 36%);
  font-size: .52rem;
  font-weight: 900;
  letter-spacing: .11em;
}

@media (pointer: coarse), (max-width: 720px) {
  .game-shell { grid-template-rows: 46px 52px minmax(0, 1fr); }
  .joystick { display: grid; }
  .desktop-hint { display: none; }
  .hud-stat, .seed-button { padding-inline: 8px; }
  .briefing { max-height: calc(100svh - 112px); }
}

@media (max-width: 460px) {
  .back-link { font-size: 0; }
  .back-link::before { content: "←"; font-size: 1rem; }
  .brand { letter-spacing: .06em; }
  .brand-lamp { display: none; }
  .icon-button { width: 32px; height: 32px; }
  .legend span { font-size: .44rem; }
  .controls-copy { gap: 10px; font-size: .52rem; }
  .overlay-actions { flex-direction: column; }
  .primary-button, .secondary-button { min-height: 41px; }
}

@media (max-height: 610px) {
  .briefing { padding-block: 17px; }
  .insignia { display: none; }
  .briefing-copy { margin-block: 12px; }
  .legend { margin-bottom: 10px; }
  .overlay-actions { margin-top: 12px; }
  .best-score { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .overlay, .toast { transition: none; }
}
