:root {
  color-scheme: light;
  --paper: #f2f0e8;
  --ink: #20241f;
  --muted: #686c62;
  --accent: #db5a36;
  --accent-dark: #a93a20;
  --console: #c9d0b9;
  --screen: #dfe6ce;
  --screen-grid: rgba(54, 66, 48, 0.09);
  --snake: #344c37;
  --snake-head: #203428;
  --line: #b9b9ad;
  --shadow: rgba(38, 45, 34, 0.2);
  font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  min-height: 100dvh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 12%, rgba(219, 90, 54, 0.08), transparent 25rem),
    var(--paper);
}

button { font: inherit; }

.game-shell {
  width: min(1120px, calc(100% - 48px));
  min-height: 100dvh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(280px, 0.8fr) minmax(480px, 1.2fr);
  align-items: center;
  gap: clamp(48px, 8vw, 120px);
  padding: 48px 0;
}

.intro { padding-bottom: 5vh; }

.eyebrow {
  margin: 0 0 24px;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.22em;
}

h1 {
  margin: 0;
  font-size: clamp(64px, 8vw, 112px);
  font-weight: 800;
  letter-spacing: -0.075em;
  line-height: 0.78;
}

h1 em {
  display: inline-block;
  padding: 0 0.08em 0.08em 0;
  color: var(--accent);
  font-style: italic;
  line-height: 1.1;
}

.intro-copy {
  max-width: 28rem;
  margin: 32px 0 0;
  color: var(--muted);
  font-size: 17px;
  line-height: 1.7;
}

.scoreboard {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  width: min(360px, 100%);
  margin: 38px 0 30px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.scoreboard div { padding: 18px 0; }
.scoreboard div + div { padding-left: 24px; border-left: 1px solid var(--line); }
.scoreboard span { display: block; color: var(--muted); font-size: 12px; font-weight: 700; }
.scoreboard strong { display: block; margin-top: 4px; font: 700 32px/1 ui-monospace, monospace; }

.desktop-actions, .mobile-actions { display: flex; gap: 10px; }
.mobile-actions { display: none; width: 100%; }

.button {
  min-height: 48px;
  padding: 0 22px;
  border: 1px solid var(--ink);
  border-radius: 12px;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
  transition: transform 160ms ease, background-color 160ms ease;
}

.button:active:not(:disabled) { transform: translateY(1px) scale(0.98); }
.button:focus-visible, .dpad button:focus-visible { outline: 3px solid rgba(219, 90, 54, 0.45); outline-offset: 3px; }
.button-primary { color: #fbfaf5; background: var(--ink); }
.button-primary:hover { background: #343a32; }
.button-secondary { color: var(--ink); background: transparent; }
.button-secondary:hover:not(:disabled) { background: rgba(32, 36, 31, 0.07); }
.button:disabled { cursor: not-allowed; opacity: 0.38; }

.keyboard-help { margin: 18px 0 0; color: var(--muted); font-size: 12px; }

.console {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 20px 28px;
  border: 1px solid rgba(51, 60, 45, 0.35);
  border-radius: 28px;
  background: var(--console);
  box-shadow: 0 28px 70px var(--shadow), inset 0 1px rgba(255,255,255,0.7);
}

.console-topbar {
  display: flex;
  justify-content: space-between;
  width: 100%;
  padding: 0 4px 14px;
  color: #53604c;
  font: 800 10px/1 ui-monospace, monospace;
  letter-spacing: 0.12em;
}

.screen-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  overflow: hidden;
  border: 9px solid #566050;
  border-radius: 18px;
  background: var(--screen);
  box-shadow: inset 0 0 24px rgba(38, 50, 33, 0.28);
}

canvas { display: block; width: 100%; height: 100%; }

.game-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px;
  text-align: center;
  background: rgba(223, 230, 206, 0.9);
  transition: opacity 180ms ease, visibility 180ms ease;
}

.game-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.overlay-mark {
  display: grid;
  place-items: center;
  width: 70px;
  height: 70px;
  margin-bottom: 18px;
  border: 5px solid var(--snake);
  border-radius: 18px;
  color: var(--snake);
  font-size: 42px;
  font-weight: 900;
  line-height: 1;
  transform: rotate(-6deg);
}
.game-overlay p { margin: 0; font-size: 24px; font-weight: 900; }
.game-overlay span { margin-top: 8px; color: #5c6755; font-size: 13px; }

.dpad {
  display: none;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(2, 52px);
  gap: 7px;
  margin-top: 20px;
}
.dpad button {
  border: 0;
  border-radius: 12px;
  color: #eef0e7;
  background: #4c5548;
  box-shadow: inset 0 -3px rgba(0,0,0,0.16);
  font-size: 22px;
  cursor: pointer;
  touch-action: manipulation;
}
.dpad button:active { transform: translateY(2px); box-shadow: none; }
.dpad [data-direction="up"] { grid-column: 2; }
.dpad [data-direction="left"] { grid-column: 1; grid-row: 2; }
.dpad [data-direction="down"] { grid-column: 2; grid-row: 2; }
.dpad [data-direction="right"] { grid-column: 3; grid-row: 2; }

@media (max-width: 820px) {
  .game-shell { width: min(560px, calc(100% - 28px)); grid-template-columns: 1fr; gap: 28px; padding: 36px 0; }
  .intro { padding: 0; }
  h1 { font-size: clamp(60px, 20vw, 92px); }
  .intro-copy { margin-top: 22px; }
  .scoreboard { width: 100%; margin: 26px 0 0; }
  .desktop-actions, .keyboard-help { display: none; }
  .console { padding: 14px 14px 22px; border-radius: 22px; }
  .mobile-actions { display: flex; margin-top: 16px; }
  .mobile-actions .button { flex: 1; }
  .dpad { display: grid; }
}

@media (max-height: 720px) and (min-width: 821px) {
  .game-shell { padding: 24px 0; }
  h1 { font-size: 72px; }
  .intro-copy { margin-top: 20px; }
  .scoreboard { margin: 24px 0 20px; }
  .console { max-width: 520px; justify-self: end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: 0.01ms !important; }
}
