/* SERPENT — The Lab level chrome plus canvas snake surface. Neon on dark. */

@font-face { font-family: "Press Start 2P"; font-style: normal; font-weight: 400; font-display: swap; src: url("/press-start-2p.woff2") format("woff2"); }
@font-face { font-family: "Press Start 2P Fallback"; src: local("Courier New"); size-adjust: 166.64%; ascent-override: 60%; descent-override: 0%; line-gap-override: 0%; }

:root {
  --bg: #0a0a12;
  --surface: #12121d;
  --surface-2: #1a1a2a;
  --line: #28283c;
  --text: #e9e9f2;
  --dim: #9aa0b5;
  --cyan: #45f0ff;
  --magenta: #ff3d8b;
  --gold: #ffc857;
  --green: #41ff8b;
  --red: #ff5560;
  --pixel: "Press Start 2P", "Press Start 2P Fallback", "Courier New", monospace;
  --body: -apple-system, "Segoe UI", system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, monospace;
  --radius: 8px;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --glow-cyan: 0 0 14px rgba(69, 240, 255, 0.35);
  --space-gutter: clamp(16px, 4vw, 48px);
}

*, *::before, *::after { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(1200px 500px at 50% -10%, rgba(65, 255, 139, 0.06), transparent 70%),
    radial-gradient(900px 400px at 80% 110%, rgba(69, 240, 255, 0.05), transparent 70%),
    var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(65, 255, 139, 0.3); }
[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  margin: -1px; padding: 0; border: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: 12px; top: -48px;
  z-index: 200;
  background: var(--cyan);
  color: #05050d;
  padding: 10px 16px;
  border-radius: 6px;
  font-family: var(--mono);
  font-weight: 700;
  text-decoration: none;
  transition: transform 0.2s var(--ease-out);
}
.skip-link:focus-visible { transform: translateY(60px); }

:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
  box-shadow: 0 0 0 5px rgba(69, 240, 255, 0.15);
}

a { color: var(--cyan); }

/* ---------- header ---------- */

.site-header {
  padding: 26px var(--space-gutter) 10px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.lab-link {
  align-self: flex-start;
  font-family: var(--pixel);
  font-size: 10px;
  color: var(--dim);
  text-decoration: none;
  padding: 6px 2px;
  transition: color 0.15s, text-shadow 0.15s;
}
.lab-link:hover { color: var(--cyan); text-shadow: var(--glow-cyan); }

.level {
  margin: 0;
  font-family: var(--pixel);
  font-size: 9px;
  letter-spacing: 3px;
  color: var(--gold);
}

.wordmark {
  margin: 6px 0 4px;
  font-family: var(--pixel);
  font-size: clamp(22px, 4.5vw, 34px);
  letter-spacing: 3px;
  color: var(--text);
  text-shadow: 0 0 16px rgba(65, 255, 139, 0.5), 3px 3px 0 var(--magenta);
}

/* glitch wordmark — color-fringe layers driven by clip animation */
.glitch { position: relative; display: inline-block; }
.glitch::before, .glitch::after {
  content: attr(data-text);
  position: absolute;
  left: 0; top: 0;
  width: 100%;
  pointer-events: none;
}
.glitch::before { color: var(--cyan); text-shadow: 0 0 8px rgba(69, 240, 255, 0.6); animation: glitch-a 2.6s steps(2, end) infinite; }
.glitch::after { color: var(--magenta); text-shadow: 0 0 8px rgba(255, 61, 139, 0.6); animation: glitch-b 3.1s steps(2, end) infinite; }

@keyframes glitch-a {
  0%, 92%, 100% { clip-path: inset(0 0 100% 0); transform: translate(0, 0); }
  93% { clip-path: inset(0 0 55% 0); transform: translate(-2px, -1px); }
  96% { clip-path: inset(40% 0 20% 0); transform: translate(2px, 1px); }
}
@keyframes glitch-b {
  0%, 90%, 100% { clip-path: inset(100% 0 0 0); transform: translate(0, 0); }
  91% { clip-path: inset(60% 0 10% 0); transform: translate(2px, 1px); }
  95% { clip-path: inset(20% 0 50% 0); transform: translate(-2px, -1px); }
}

.tagline {
  margin: 0;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}

.cursor { color: var(--green); animation: blink 1.1s steps(1) infinite; }
@keyframes blink { 50% { opacity: 0; } }

/* ---------- layout ---------- */

main {
  flex: 1;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 20px var(--space-gutter) 72px;
}

.game-panel { display: flex; flex-direction: column; gap: 14px; }

.topbar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.action-row, .chip-row { display: flex; flex-wrap: wrap; gap: 8px; }

.btn, .chip {
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 6px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s var(--ease-out), border-color 0.12s, box-shadow 0.12s, color 0.12s;
}

.btn {
  gap: 8px;
  padding: 10px 14px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12.5px;
  font-weight: 700;
}
.btn:hover, .chip:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(69, 240, 255, 0.22); transform: translateY(-1px); }
.btn:active, .chip:active { transform: translateY(1px); }
.btn:disabled, .chip:disabled { opacity: 0.5; cursor: not-allowed; transform: none; box-shadow: none; }

.btn-primary { background: var(--green); border-color: var(--green); color: #05140b; }
.btn-primary:hover { box-shadow: 0 0 18px rgba(65, 255, 139, 0.5); }
.btn-ghost { background: transparent; }
.btn-big { font-family: var(--pixel); font-size: 11px; padding: 14px 20px; }

.chip {
  padding: 8px 14px;
  background: var(--bg);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.chip.is-active {
  border-color: var(--green);
  color: var(--green);
  background: rgba(65, 255, 139, 0.08);
  box-shadow: inset 0 0 0 1px rgba(65, 255, 139, 0.35);
}

/* ---------- HUD ---------- */

.hud { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.hud div {
  min-width: 0;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.hud span { display: block; margin-bottom: 6px; font-family: var(--pixel); font-size: 8px; color: var(--dim); letter-spacing: 1px; }
.hud strong { display: block; font-family: var(--mono); font-size: 1.25rem; color: var(--gold); }

/* ---------- stage / canvas ---------- */

.stage { display: flex; flex-direction: column; gap: 14px; }

.canvas-wrap {
  position: relative;
  width: 100%;
  padding: 8px;
  background: linear-gradient(180deg, var(--surface), rgba(18, 18, 29, 0.5));
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: inset 0 0 32px rgba(65, 255, 139, 0.04);
}

#gameCanvas {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  min-height: 240px;
  background: var(--bg);
  border-radius: 6px;
  touch-action: none;
  image-rendering: pixelated;
}

/* ---------- overlay ---------- */

.overlay {
  position: absolute;
  inset: 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 24px;
  border-radius: 6px;
  background: rgba(10, 10, 18, 0.82);
  backdrop-filter: blur(2px);
}

.overlay-title {
  margin: 0;
  font-family: var(--pixel);
  font-size: clamp(16px, 5vw, 28px);
  letter-spacing: 3px;
  color: var(--green);
  text-shadow: 0 0 16px rgba(65, 255, 139, 0.55), 2px 2px 0 var(--magenta);
}
.overlay[data-phase="paused"] .overlay-title { color: var(--cyan); text-shadow: 0 0 16px rgba(69, 240, 255, 0.55), 2px 2px 0 var(--magenta); }
.overlay[data-phase="over"] .overlay-title { color: var(--red); text-shadow: 0 0 16px rgba(255, 85, 96, 0.55), 2px 2px 0 var(--magenta); }

.overlay-sub {
  margin: 0;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--dim);
}

.overlay-final {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  color: var(--text);
  line-height: 1.7;
}
.final-badge { color: var(--gold); font-family: var(--pixel); font-size: 11px; letter-spacing: 1px; }

/* ---------- dpad ---------- */

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 64px);
  grid-template-rows: repeat(2, 64px);
  grid-template-areas:
    ".    up    ."
    "left down right";
  gap: 8px;
  justify-content: center;
}

.pad-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px; height: 64px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  color: var(--cyan);
  font-size: 18px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.1s var(--ease-out), border-color 0.12s, box-shadow 0.12s, background 0.12s;
}
.pad-btn:hover { border-color: var(--cyan); box-shadow: 0 0 12px rgba(69, 240, 255, 0.22); }
.pad-btn:active { transform: scale(0.94); background: rgba(69, 240, 255, 0.12); }
.pad-up { grid-area: up; }
.pad-down { grid-area: down; }
.pad-left { grid-area: left; }
.pad-right { grid-area: right; }

.status {
  min-height: 24px;
  margin: 0;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 13px;
  text-align: center;
}

/* ---------- footer ---------- */

.site-footer {
  border-top: 1px solid var(--line);
  padding: 22px var(--space-gutter);
  text-align: center;
  color: var(--dim);
  font-size: 13px;
}
.site-footer p { margin: 0 0 8px; }
.site-footer p:last-child { margin-bottom: 0; }
.site-footer a { color: var(--cyan); text-decoration: none; }
.site-footer a:hover { text-decoration: underline; text-shadow: var(--glow-cyan); }

/* ---------- toasts ---------- */

.toasts {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--red);
  color: var(--text);
  padding: 12px 14px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in 0.22s var(--ease-out) both;
}
.toast-info { border-left-color: var(--cyan); }
.toast-success { border-left-color: var(--green); }
.toast.out { opacity: 0; transform: translateY(6px); transition: opacity 0.25s, transform 0.25s; }

@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

/* ---------- responsive ---------- */

@media (min-width: 600px) {
  .hud { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .topbar { flex-direction: row; align-items: center; justify-content: space-between; }
}

@media (max-width: 360px) {
  .dpad { grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(2, 56px); }
  .pad-btn { width: 56px; height: 56px; }
  .wordmark { letter-spacing: 1px; }
}

/* ---------- reduced motion: kill looping/decorative motion ---------- */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
  .cursor { animation: none; }
  .glitch::before, .glitch::after { animation: none; opacity: 0; }
}
