@font-face {
  font-family: "Press Start 2P";
  src: url("/fonts/press-start-2p-v16-latin-regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0A0E0A;
  --panel: #12181A;
  --grid: #1E2A22;
  --dim: #7A8A80;
  --neon: #39FF14;
  --cyan: #00E5FF;
  --gold: #FFC400;
  --alert: #FF3B3B;
  --ink: #2A332B;
  --pixel: "Press Start 2P", monospace;
  --body-stack: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

::selection {
  background-color: var(--neon);
  color: var(--bg);
}

html,
body {
  background-color: var(--bg);
  color: var(--dim);
  font-family: var(--body-stack);
}

body {
  position: relative;
  min-height: 100vh;
  background-image: radial-gradient(
    ellipse at top center,
    rgba(57, 255, 20, 0.05) 0,
    var(--bg) 60%
  );
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 10;
  background: repeating-linear-gradient(
    to bottom,
    rgba(57, 255, 20, 0.035) 0,
    rgba(57, 255, 20, 0.035) 1px,
    transparent 1px,
    transparent 3px
  );
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 11;
  background: radial-gradient(
    ellipse at center,
    transparent 55%,
    rgba(0, 0, 0, 0.55) 100%
  );
}

#content {
  position: relative;
  z-index: 2;
}

.arcade-title {
  font-family: var(--pixel);
  font-size: clamp(18px, 5.5vw, 40px);
  line-height: 1.2;
  letter-spacing: 0.05em;
  color: var(--neon);
  text-shadow: 0 0 8px rgba(57, 255, 20, 0.6), 0 0 16px rgba(57, 255, 20, 0.3);
}

.hud > div {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.hud-label {
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 0.12em;
  color: var(--dim);
}

.hud-num {
  font-family: var(--pixel);
  font-size: 20px;
  line-height: 1.2;
  color: var(--neon);
  text-shadow: 0 0 8px rgba(57, 255, 20, 0.5);
}

#snake-best {
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(0, 229, 255, 0.5);
}

.hud-hiscore-num {
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255, 196, 0, 0.5);
}

@media (max-width: 360px) {
  .hud-label {
    font-size: 8px;
    letter-spacing: 0.04em;
  }
  .hud.gap-4 {
    gap: 0.75rem !important;
  }
}

.canvas-wrap {
  background-color: var(--panel);
  border: 2px solid var(--grid);
  border-radius: 8px;
  overflow: hidden;
  box-shadow:
    inset 0 0 0 2px rgba(0, 0, 0, 0.6),
    inset 0 0 12px rgba(0, 0, 0, 0.8),
    0 0 16px rgba(57, 255, 20, 0.15);
  max-width: 100%;
}

#snake-canvas {
  display: block;
  image-rendering: pixelated;
  background-color: var(--bg);
  max-width: 100%;
  position: relative;
  z-index: 1;
}

.inkblot-layer {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transition: opacity 200ms ease-out;
  display: block;
}

.snake-overlay {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  background-color: rgba(10, 14, 10, 0.78);
}

.snake-overlay[hidden] {
  display: none;
}

.overlay-prompt {
  font-family: var(--pixel);
  font-size: 14px;
  color: var(--neon);
  text-shadow: 0 0 10px rgba(57, 255, 20, 0.5);
  margin: 0;
}

.overlay-body {
  font-family: var(--pixel);
  font-size: 14px;
  color: var(--cyan);
  margin: 0;
}

#snake-overlay-gameover {
  overflow-y: auto;
  max-height: 100%;
  padding: 12px;
  justify-content: flex-start;
}

#snake-overlay-gameover .overlay-prompt {
  color: var(--alert);
  text-shadow: 0 0 10px rgba(255, 59, 59, 0.5);
}

#snake-entry[hidden],
#snake-leaderboard[hidden] {
  display: none;
}

#snake-entry {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.initials-row {
  display: flex;
  flex-direction: row;
  justify-content: center;
  gap: 12px;
}

.initials-slot {
  font-family: var(--pixel);
  font-size: 22px;
  line-height: 1.2;
  color: var(--neon);
  display: inline-block;
  min-width: 24px;
  text-align: center;
  border-bottom: 3px solid rgba(57, 255, 20, 0.35);
}

.initials-slot.active {
  color: var(--gold);
  border-bottom-color: var(--gold);
}

.hiscore-title {
  font-family: var(--pixel);
  font-size: 14px;
  color: var(--gold);
  text-align: center;
  text-shadow: 0 0 8px rgba(255, 196, 0, 0.4);
  margin: 0 0 8px;
}

#snake-leaderboard {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.hiscore-rows {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.hiscore-row {
  font-family: var(--pixel);
  font-size: 10px;
  line-height: 1.4;
  color: var(--neon);
  display: flex;
  flex-direction: row;
  gap: 10px;
  white-space: pre;
}

.hiscore-rank {
  min-width: 2ch;
  text-align: right;
  color: var(--dim);
}

.hiscore-score {
  min-width: 5ch;
  text-align: right;
}

.hiscore-initials {
  min-width: 3ch;
  text-align: left;
}

.hiscore-row-new {
  color: var(--gold);
  text-shadow: 0 0 8px rgba(255, 196, 0, 0.4);
}

.hiscore-row-new .hiscore-rank {
  color: var(--gold);
}

.hiscore-row-empty {
  color: var(--dim);
}

@media (min-width: 768px) {
  .overlay-prompt {
    font-size: 18px;
  }
  .overlay-body {
    font-size: 16px;
  }
}

@keyframes attract-blink {
  0%, 50% {
    opacity: 1;
  }
  50.01%, 100% {
    opacity: 0;
  }
}

@keyframes neon-flicker {
  0%, 92%, 96%, 100% {
    opacity: 1;
  }
  94% {
    opacity: 0.72;
  }
}

@keyframes caret-blink {
  0%, 50% {
    border-bottom-color: var(--gold);
  }
  50.01%, 100% {
    border-bottom-color: transparent;
  }
}

@media (prefers-reduced-motion: no-preference) {
  #snake-overlay-idle .overlay-prompt {
    animation: attract-blink 1.1s step-end infinite;
  }
  .arcade-title {
    animation: neon-flicker 6s step-end infinite;
  }
  .initials-slot.active {
    animation: caret-blink 0.9s steps(1, end) infinite;
  }
}

.arcade-btn {
  font-family: var(--pixel);
  font-size: 14px;
  color: var(--neon);
  background-color: transparent;
  border: 2px solid var(--neon);
  padding: 16px 24px;
  cursor: pointer;
  transition: background-color 120ms ease-out, box-shadow 120ms ease-out, color 120ms ease-out, transform 120ms ease-out;
}

.arcade-btn:hover {
  background-color: rgba(57, 255, 20, 0.12);
  box-shadow: 0 0 12px rgba(57, 255, 20, 0.5);
}

.arcade-btn:active {
  transform: translateY(2px);
  box-shadow: 0 0 6px rgba(57, 255, 20, 0.4);
}

.arcade-btn:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.controls-hint {
  font-family: var(--pixel);
  font-size: 10px;
  line-height: 1.4;
  letter-spacing: 0.02em;
  color: var(--dim);
}

@media (min-width: 768px) {
  .controls-hint {
    font-size: 12px;
  }
}

.signup-panel {
  border: 1px solid var(--grid);
  border-top: 2px solid var(--cyan);
  background-color: var(--panel);
  box-shadow: 0 0 16px rgba(0, 229, 255, 0.12);
  padding: 24px;
  margin-top: 32px;
  max-width: 480px;
  width: 100%;
  text-align: left;
}

.signup-heading {
  font-family: var(--pixel);
  font-size: 14px;
  letter-spacing: 0.08em;
  color: var(--cyan);
  text-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
  margin-bottom: 16px;
}

.signup-field {
  margin-bottom: 16px;
}

.signup-input {
  font-family: var(--pixel);
  font-size: 16px;
  min-height: 44px;
  color: var(--cyan);
  background-color: var(--bg);
  border: 1px solid var(--grid);
  transition: border-color 120ms ease-out, box-shadow 120ms ease-out;
}

@media (min-width: 768px) {
  .signup-input {
    font-size: 13px;
  }
}

.signup-input::placeholder {
  color: rgba(0, 229, 255, 0.4);
}

.signup-input:focus {
  border-color: var(--cyan);
  background-color: var(--bg);
  color: var(--cyan);
  box-shadow: 0 0 8px rgba(0, 229, 255, 0.4);
}

.signup-input:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.signup-send {
  min-height: 44px;
  margin-top: 8px;
}

.signup-send:hover:not(:disabled) {
  background-color: var(--neon);
  color: var(--bg);
  text-shadow: none;
  box-shadow: 0 0 14px rgba(57, 255, 20, 0.6);
}

.signup-send:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.signup-send:disabled {
  color: var(--dim);
  border-color: var(--grid);
  cursor: default;
}

.signup-decoy {
  position: absolute;
  left: -9999px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}

.signup-message {
  margin-top: 16px;
}

.signup-alert {
  font-family: var(--pixel);
  font-size: 11px;
  line-height: 1.8;
  letter-spacing: 0.04em;
  color: #E6ECE8;
  background-color: var(--panel);
  border-radius: 0;
  text-shadow: none;
  box-shadow: none;
}

.signup-alert.alert-success {
  border: 1px solid var(--grid);
  border-left: 4px solid var(--neon);
}

.signup-alert.alert-warning {
  border: 1px solid var(--grid);
  border-left: 4px solid var(--alert);
}

.signup-alert.alert-danger {
  border: 1px solid var(--grid);
  border-left: 4px solid var(--alert);
}

.page-footer {
  margin-top: 40px;
}

.footer-line {
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--dim);
  margin: 0;
}

.footer-credit {
  font-family: var(--pixel);
  font-size: 10px;
  letter-spacing: 0.1em;
  color: var(--dim);
  text-decoration: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  transition: color 150ms ease-out;
}

.footer-credit:hover {
  color: var(--cyan);
}

.footer-credit:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.footer-credit img {
  display: inline-block;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 48px);
  grid-template-rows: repeat(3, 48px);
  gap: 8px;
  justify-content: center;
}

.dpad-up {
  grid-column: 2;
  grid-row: 1;
}

.dpad-left {
  grid-column: 1;
  grid-row: 2;
}

.dpad-right {
  grid-column: 3;
  grid-row: 2;
}

.dpad-down {
  grid-column: 2;
  grid-row: 3;
}

#snake-dpad button,
.dpad-btn {
  touch-action: none;
  min-width: 44px;
  min-height: 44px;
  color: var(--neon);
  background-color: var(--panel);
  border: 1px solid var(--grid);
  cursor: pointer;
}

#snake-dpad button:active {
  box-shadow: 0 0 8px rgba(57, 255, 20, 0.6);
  border-color: var(--neon);
}

#snake-dpad button:focus-visible {
  outline: 2px solid var(--cyan);
  outline-offset: 2px;
}

.dpad,
.hint-touch,
.overlay-prompt-touch {
  display: none;
}

.hint-key {
  display: inline;
}

@media (hover: none) and (pointer: coarse) {
  .dpad {
    display: grid;
  }
  .hint-key,
  .overlay-prompt-key {
    display: none;
  }
  .hint-touch {
    display: inline;
  }
  .overlay-prompt-touch {
    display: block;
  }
}

@media (prefers-reduced-motion: reduce) {
  .arcade-title {
    text-shadow: none;
    animation: none;
  }
  #snake-overlay-idle .overlay-prompt {
    animation: none;
  }
  .initials-slot.active {
    animation: none;
    border-bottom-color: var(--gold);
  }
  .arcade-btn {
    transition: none;
  }
  .arcade-btn:hover,
  .arcade-btn:active,
  #snake-dpad button:active {
    box-shadow: none;
    transform: none;
  }
  .signup-input {
    transition: none;
  }
  .inkblot-layer {
    transition: none;
  }
}
