:root {
  color-scheme: light;
  font-family: "Arial Narrow", "PingFang SC", "Microsoft YaHei", sans-serif;
  --ink: #18211b;
  --paper: #f2eedf;
  --acid: #c9f04d;
  --coral: #ff654f;
  --board: #25352b;
  --grid: rgba(241, 236, 218, 0.09);
}

* { box-sizing: border-box; }

html { min-width: 320px; background: var(--ink); }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(90deg, transparent 49.75%, rgba(24, 33, 27, 0.05) 50%, transparent 50.25%) 0 0 / 36px 36px,
    var(--paper);
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.shell { width: min(1160px, calc(100% - 40px)); margin: 0 auto; padding: 34px 0 26px; }

.masthead {
  display: grid;
  grid-template-columns: 1fr minmax(280px, 440px);
  gap: 48px;
  align-items: end;
  border-top: 6px solid var(--ink);
  border-bottom: 2px solid var(--ink);
  padding: 18px 0 20px;
}

.eyebrow { margin: 0 0 3px; font: 700 12px/1.2 ui-monospace, monospace; letter-spacing: .14em; }
h1 { margin: 0; font-size: clamp(56px, 9vw, 106px); line-height: .9; letter-spacing: -.08em; }
h1 span { color: var(--coral); margin-left: .1em; }
.intro { margin: 0; font-size: 16px; line-height: 1.65; font-weight: 600; }

.game-layout {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  gap: 34px;
  padding: 34px 0 24px;
}

.scoreboard { display: flex; flex-direction: column; gap: 12px; }
.score-card { border: 2px solid var(--ink); padding: 14px 16px; background: rgba(255,255,255,.25); }
.score-card span { display: block; font: 700 12px/1 ui-monospace, monospace; letter-spacing: .08em; }
.score-card strong { display: block; margin-top: 7px; font-size: 52px; line-height: 1; }
.score-card.current { background: var(--acid); box-shadow: 6px 6px 0 var(--ink); margin-bottom: 6px; }
.score-card.best strong { color: var(--coral); }

.speed-row { display: grid; grid-template-columns: 1fr auto; gap: 7px 10px; padding: 10px 2px; font-size: 12px; font-weight: 800; }
.speed-meter { grid-column: 1 / -1; height: 7px; border: 1px solid var(--ink); background: transparent; }
.speed-meter i { display: block; height: 100%; width: 8%; background: var(--coral); transition: width .25s ease; }

.mode-switch { display: grid; grid-template-columns: 1fr 45px; align-items: center; gap: 10px; border-top: 2px solid var(--ink); border-bottom: 2px solid var(--ink); padding: 16px 2px; cursor: pointer; }
.mode-switch b, .mode-switch small { display: block; }
.mode-switch b { font-size: 14px; }
.mode-switch small { margin-top: 4px; line-height: 1.35; opacity: .66; }
.mode-switch input { position: absolute; opacity: 0; pointer-events: none; }
.mode-switch > i { position: relative; width: 45px; height: 24px; border: 2px solid var(--ink); border-radius: 14px; background: #d6d1c1; transition: background .2s; }
.mode-switch > i::after { content: ""; position: absolute; width: 16px; height: 16px; left: 2px; top: 2px; border-radius: 50%; background: var(--ink); transition: transform .2s; }
.mode-switch input:checked + i { background: var(--coral); }
.mode-switch input:checked + i::after { transform: translateX(21px); }
.mode-switch input:focus-visible + i { outline: 3px solid var(--acid); outline-offset: 3px; }

.desktop-help { margin-top: auto; border-left: 4px solid var(--coral); padding-left: 12px; }
.desktop-help p { margin: 0 0 8px; font: 700 11px/1 ui-monospace, monospace; letter-spacing: .08em; }
.desktop-help small { display: block; margin-top: 8px; opacity: .64; }
.key-grid { display: grid; grid-template-columns: repeat(3, 28px); gap: 4px; width: max-content; }
.key-grid kbd { width: 28px; height: 25px; display: grid; place-items: center; border: 1px solid var(--ink); border-bottom-width: 3px; background: white; font-family: inherit; }
.key-grid kbd:first-child { grid-column: 2; }

.play-column { min-width: 0; }
.canvas-frame { position: relative; width: min(100%, 680px); margin-inline: auto; border: 10px solid var(--ink); background: var(--board); box-shadow: 12px 12px 0 rgba(24,33,27,.17); }
canvas { display: block; width: 100%; aspect-ratio: 1; touch-action: none; }

.game-overlay { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 26px; text-align: center; color: #f7f2df; background: rgba(24,33,27,.87); backdrop-filter: blur(2px); transition: opacity .2s, visibility .2s; }
.game-overlay.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.overlay-kicker { margin: 0 0 10px; color: var(--acid); font: 700 12px/1 ui-monospace, monospace; letter-spacing: .14em; }
.game-overlay h2 { margin: 0; font-size: clamp(28px, 5vw, 52px); letter-spacing: -.04em; }
.game-overlay > p:not(.overlay-kicker) { max-width: 390px; margin: 14px 0 24px; line-height: 1.6; color: rgba(247,242,223,.76); }
.game-overlay button { min-width: 150px; border: 0; padding: 13px 22px; color: var(--ink); background: var(--acid); font-weight: 900; box-shadow: 5px 5px 0 var(--coral); cursor: pointer; }
.game-overlay button:hover { transform: translate(-1px,-1px); box-shadow: 7px 7px 0 var(--coral); }
.game-overlay button:active { transform: translate(3px,3px); box-shadow: 2px 2px 0 var(--coral); }
.live-message { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); color: var(--ink); background: var(--acid); padding: 5px 10px; font: 800 11px/1 ui-monospace, monospace; opacity: 0; pointer-events: none; transition: opacity .15s; }
.live-message.show { opacity: 1; }

.game-actions { display: flex; justify-content: center; gap: 10px; margin-top: 20px; }
.secondary { border: 2px solid var(--ink); padding: 10px 18px; background: transparent; font-weight: 800; cursor: pointer; }
.secondary:hover:not(:disabled) { background: var(--ink); color: var(--paper); }
.secondary:disabled { opacity: .35; cursor: not-allowed; }

.touch-pad { display: none; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(2, 52px); justify-content: center; gap: 7px; margin: 18px auto 0; }
.touch-pad button { border: 2px solid var(--ink); background: white; color: var(--ink); font-size: 22px; font-weight: 900; box-shadow: 0 3px 0 var(--ink); cursor: pointer; }
.touch-pad button:active { transform: translateY(3px); box-shadow: none; background: var(--acid); }
.touch-pad .up { grid-column: 2; }
.touch-pad .left { grid-row: 2; grid-column: 1; }
.touch-center { grid-row: 2; grid-column: 2; border-radius: 50%; background: var(--coral); transform: scale(.3); }
.touch-pad .right { grid-row: 2; grid-column: 3; }
.touch-pad .down { grid-row: 2; grid-column: 2; transform: translateY(59px); }
.touch-pad .down:active { transform: translateY(62px); }

footer { display: flex; flex-wrap: wrap; gap: 18px; align-items: center; border-top: 2px solid var(--ink); padding-top: 16px; font: 700 11px/1.2 ui-monospace, monospace; }
footer span { display: flex; gap: 6px; align-items: center; }
footer em { margin-left: auto; font-style: normal; opacity: .55; }
.legend { width: 11px; height: 11px; display: inline-block; }
.legend.food { border-radius: 50%; background: var(--coral); }
.legend.snake { background: var(--acid); }
.legend.rock { background: #9b917b; }

@media (max-width: 760px) {
  .shell { width: min(100% - 24px, 620px); padding-top: 18px; }
  .masthead { grid-template-columns: 1fr; gap: 12px; padding-top: 12px; }
  .intro { font-size: 14px; }
  .game-layout { grid-template-columns: 1fr; gap: 18px; padding-top: 22px; }
  .scoreboard { display: grid; grid-template-columns: 1fr 1fr; }
  .score-card strong { font-size: 36px; }
  .speed-row, .mode-switch { grid-column: 1 / -1; }
  .desktop-help { display: none; }
  .canvas-frame { border-width: 7px; box-shadow: 7px 7px 0 rgba(24,33,27,.17); }
  .touch-pad { display: grid; margin-bottom: 60px; }
  footer { margin-top: 6px; }
  footer em { flex-basis: 100%; margin-left: 0; }
}

@media (max-width: 400px) {
  h1 { font-size: 58px; }
  .game-overlay { padding: 18px; }
  .game-overlay > p:not(.overlay-kicker) { font-size: 13px; margin: 9px 0 17px; }
  .game-overlay button { padding: 10px 18px; }
}

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