:root {
  --ink: #142028;
  --ink-soft: #243440;
  --mist: #e7eef2;
  --panel: #f4f7f9;
  --teal: #0f766e;
  --teal-bright: #14b8a6;
  --amber: #f59e0b;
  --coral: #e85d4c;
  --line: rgba(20, 32, 40, 0.12);
  --shadow: 0 18px 40px rgba(20, 32, 40, 0.18);
  --radius: 18px;
  --font-display: "Syne", system-ui, sans-serif;
  --font-body: "DM Sans", system-ui, sans-serif;
}

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

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(20, 184, 166, 0.22), transparent 55%),
    radial-gradient(900px 500px at 100% 0%, rgba(245, 158, 11, 0.18), transparent 50%),
    linear-gradient(165deg, #dce7ec 0%, #c5d5dd 45%, #b7c8d2 100%);
}

body {
  min-height: 100dvh;
}

.page {
  width: min(520px, 100%);
  margin: 0 auto;
  padding: 1.25rem 1rem 2rem;
}

.top {
  margin-bottom: 0.85rem;
}

.site-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  font-size: 0.88rem;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.35rem 0.85rem;
}

.nav-back,
.nav-link {
  color: var(--teal);
  font-weight: 600;
  text-decoration: none;
}

.nav-back:hover,
.nav-link:hover {
  color: var(--teal-bright);
  text-decoration: underline;
}

/* —— Lobby —— */
.lobby-body {
  display: grid;
  align-items: center;
}

.lobby-page {
  width: min(560px, 100%);
  padding-top: 1.75rem;
  padding-bottom: 2.25rem;
}

.lobby-hero {
  margin-bottom: 1.35rem;
  animation: lobby-enter 0.55s ease both;
}

.lobby-brand h1 {
  font-size: clamp(2.15rem, 8vw, 3rem);
}

.lobby-tagline {
  max-width: 42ch;
  font-size: 1.02rem;
}

@keyframes lobby-enter {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.game-pick {
  display: grid;
  gap: 0.85rem;
}

.game-card {
  display: grid;
  grid-template-columns: 5.5rem 1fr;
  gap: 0.9rem;
  align-items: center;
  padding: 0.85rem;
  text-decoration: none;
  color: inherit;
  background: rgba(244, 247, 249, 0.78);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 10px 28px rgba(20, 32, 40, 0.1);
  backdrop-filter: blur(6px);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  animation: lobby-enter 0.55s ease both;
}

.game-card:nth-child(2) {
  animation-delay: 0.08s;
}

.game-card:nth-child(3) {
  animation-delay: 0.16s;
}

.game-card:hover {
  transform: translateY(-3px);
  border-color: rgba(20, 184, 166, 0.45);
  box-shadow: 0 16px 34px rgba(20, 32, 40, 0.16);
}

.game-card:active {
  transform: translateY(-1px);
}

.game-card-visual {
  display: block;
  width: 5.5rem;
  height: 5.5rem;
  border-radius: 14px;
  position: relative;
  overflow: hidden;
}

.spark-visual {
  background:
    radial-gradient(circle at 35% 40%, #fff7ed 0 10%, transparent 11%),
    radial-gradient(circle at 68% 62%, rgba(245, 158, 11, 0.95) 0 14%, transparent 15%),
    radial-gradient(circle at 42% 72%, rgba(20, 184, 166, 0.9) 0 11%, transparent 12%),
    linear-gradient(160deg, #1a2a33, #0d161c);
}

.spark-visual::after {
  content: "";
  position: absolute;
  inset: 18% 40% auto;
  height: 42%;
  width: 3px;
  margin: 0 auto;
  background: linear-gradient(180deg, transparent, rgba(245, 158, 11, 0.7));
  animation: spark-fall 1.8s ease-in-out infinite;
}

@keyframes spark-fall {
  0%,
  100% {
    transform: translateY(-20%);
    opacity: 0.35;
  }
  50% {
    transform: translateY(40%);
    opacity: 1;
  }
}

.snake-visual {
  background:
    linear-gradient(160deg, #1a2a33, #0d161c);
}

.snake-visual::before {
  content: "";
  position: absolute;
  inset: 28% 18%;
  border-radius: 8px;
  background:
    linear-gradient(90deg, transparent 0 8%, #14b8a6 8% 28%, #5eead4 28% 48%, transparent 48%),
    radial-gradient(circle at 72% 50%, #f59e0b 0 10%, transparent 11%);
  background-repeat: no-repeat;
  animation: snake-shimmy 2.2s ease-in-out infinite;
}

@keyframes snake-shimmy {
  0%,
  100% {
    transform: translateX(-4%);
  }
  50% {
    transform: translateX(6%);
  }
}

.lane-visual {
  background:
    radial-gradient(circle at 50% 24%, rgba(232, 93, 76, 0.95) 0 9%, transparent 10%),
    linear-gradient(90deg, transparent 31%, rgba(94, 234, 212, 0.55) 31% 32.5%, transparent 32.5% 67.5%, rgba(94, 234, 212, 0.55) 67.5% 69%, transparent 69%),
    linear-gradient(165deg, #1a2a33, #0d161c);
}

.lane-visual::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 16%;
  width: 16px;
  height: 16px;
  margin-left: -8px;
  background: #5eead4;
  clip-path: polygon(50% 0%, 100% 100%, 50% 72%, 0% 100%);
  filter: drop-shadow(0 0 6px rgba(20, 184, 166, 0.9));
  animation: lane-weave 2.1s ease-in-out infinite;
}

@keyframes lane-weave {
  0%,
  100% {
    transform: translateX(0);
  }
  45% {
    transform: translateX(-20px);
  }
  72% {
    transform: translateX(20px);
  }
}

.game-card-body {
  display: grid;
  gap: 0.2rem;
  min-width: 0;
}

.game-card-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.35rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.game-card-blurb {
  color: var(--ink-soft);
  font-size: 0.92rem;
  line-height: 1.4;
}

.game-card-cta {
  margin-top: 0.25rem;
  color: var(--teal);
  font-weight: 700;
  font-size: 0.9rem;
}

.dpad {
  display: grid;
  justify-items: center;
  gap: 0.35rem;
  margin-top: 0.85rem;
  user-select: none;
}

.dpad-mid {
  display: grid;
  grid-template-columns: repeat(3, 3.1rem);
  gap: 0.35rem;
}

.dpad-btn {
  width: 3.1rem;
  height: 3.1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(244, 247, 249, 0.85);
  color: var(--ink);
  font-size: 1.15rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.15s ease, transform 0.15s ease;
}

.dpad-btn:hover {
  background: #fff;
}

.dpad-btn:active {
  transform: scale(0.96);
  background: rgba(20, 184, 166, 0.18);
}

.snake-stage #game {
  cursor: default;
}

.lane-stage .overlay {
  z-index: 3;
}

.lane-pad {
  position: absolute;
  left: 0.55rem;
  right: 0.55rem;
  bottom: 0.55rem;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  user-select: none;
}

.lane-btn {
  height: 2.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(244, 247, 249, 0.9);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  backdrop-filter: blur(8px);
  transition: background 0.15s ease, transform 0.15s ease;
}

.lane-btn:hover {
  background: #fff;
}

.lane-btn:active {
  transform: scale(0.98);
  background: rgba(20, 184, 166, 0.18);
}

.lane-stage #game {
  cursor: pointer;
}

@media (min-width: 720px) {
  .dpad {
    display: none;
  }
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

.brand-mark {
  width: 2rem;
  height: 2rem;
  border-radius: 0.65rem;
  background:
    conic-gradient(from 210deg, var(--teal-bright), var(--amber), var(--coral), var(--teal-bright));
  box-shadow: 0 0 0 3px rgba(20, 32, 40, 0.08);
  animation: spin-slow 12s linear infinite;
}

@keyframes spin-slow {
  to {
    transform: rotate(360deg);
  }
}

h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 6vw, 2.35rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1;
}

.tagline {
  margin: 0.45rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.4;
  max-width: 36ch;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.stat {
  background: rgba(244, 247, 249, 0.72);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.65rem;
  backdrop-filter: blur(6px);
}

.stat-label {
  display: block;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--ink-soft);
}

.stat-value {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.25rem;
}

.stage-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 1px solid rgba(20, 32, 40, 0.16);
  background: var(--ink);
  touch-action: none;
}

#game {
  display: block;
  width: 100%;
  height: auto;
  vertical-align: middle;
  cursor: crosshair;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: safe center;
  gap: 0.75rem;
  padding: 1.5rem;
  text-align: center;
  overflow: auto;
  background: linear-gradient(180deg, rgba(20, 32, 40, 0.55), rgba(20, 32, 40, 0.82));
  color: var(--mist);
}

.overlay.hidden {
  display: none;
}

.overlay h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.75rem;
}

.overlay p {
  margin: 0;
  max-width: 28ch;
  justify-self: center;
  color: rgba(231, 238, 242, 0.88);
  line-height: 1.45;
}

.start-overlay.has-board {
  gap: 0.55rem;
}

.overlay .front-board {
  width: min(100%, 18rem);
  justify-self: center;
  text-align: left;
}

.overlay .front-board[hidden] {
  display: none;
}

.overlay .front-board h2 {
  margin: 0.15rem 0 0.2rem;
  font-size: 0.95rem;
  text-align: center;
}

.overlay .leaderboard-list {
  margin: 0;
  max-height: 8.25rem;
  color: var(--mist);
}

.overlay .leaderboard-list li {
  border-bottom-color: rgba(231, 238, 242, 0.18);
}

.overlay .leaderboard-list .lb-rank,
.overlay .leaderboard-list .lb-empty {
  color: rgba(231, 238, 242, 0.72);
}

.overlay .leaderboard-list .lb-score {
  color: #5eead4;
}

.btn {
  appearance: none;
  border: none;
  border-radius: 999px;
  padding: 0.8rem 1.35rem;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease, color 0.15s ease;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  cursor: default;
  opacity: 0.55;
}

.btn.primary {
  background: var(--amber);
  color: var(--ink);
}

.btn.primary:hover {
  background: #ffb020;
}

.btn.ghost {
  background: transparent;
  color: var(--mist);
  border: 1px solid rgba(231, 238, 242, 0.35);
}

.btn.ghost:hover {
  background: rgba(231, 238, 242, 0.08);
}

.foot {
  margin-top: 1rem;
  font-size: 0.82rem;
  color: var(--ink-soft);
  line-height: 1.45;
}

.foot a {
  color: var(--teal);
  font-weight: 600;
}

.content-page .content-card {
  background: rgba(244, 247, 249, 0.82);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.15rem 1.2rem;
  backdrop-filter: blur(6px);
  box-shadow: var(--shadow);
}

.content-card h2 {
  margin: 1.15rem 0 0.4rem;
  font-family: var(--font-display);
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.content-card h2:first-of-type {
  margin-top: 0.85rem;
}

.content-card p {
  margin: 0 0 0.75rem;
  line-height: 1.55;
  color: var(--ink-soft);
}

.content-card p:last-child {
  margin-bottom: 0;
}

.content-card strong {
  color: var(--ink);
}

.content-card a {
  color: var(--teal);
  font-weight: 600;
}

.content-card code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85em;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: rgba(20, 32, 40, 0.06);
}

.content-card em {
  font-style: italic;
  font-size: 0.9em;
}

/* In-flow game-over panel. Not a modal: it never covers the canvas, so a
   death tap cannot land on the name field or the action buttons. */
.interstitial {
  margin-top: 0.85rem;
  animation: fade-in 0.25s ease;
}

.interstitial.hidden {
  display: none;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

.interstitial-card {
  width: 100%;
  background: var(--panel);
  border-radius: 22px;
  padding: 1.25rem;
  box-shadow: var(--shadow);
  animation: rise 0.3s ease;
  touch-action: manipulation;
}

@keyframes rise {
  from {
    transform: translateY(12px);
    opacity: 0.6;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.interstitial-card h2 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.6rem;
}

.over-score {
  margin: 0.35rem 0 0.85rem;
  font-size: 1.05rem;
  color: var(--ink-soft);
}

.score-form {
  margin: 0 0 0.65rem;
}

.score-label {
  display: block;
  margin-bottom: 0.3rem;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.score-row {
  display: flex;
  gap: 0.45rem;
}

.score-row input {
  flex: 1;
  min-width: 0;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  font: inherit;
  font-size: 16px;
  color: var(--ink);
  background: #fff;
  touch-action: manipulation;
}

.score-row .btn {
  flex-shrink: 0;
}

.score-row .btn.ghost {
  color: var(--ink);
  border-color: var(--line);
  background: #fff;
  padding: 0.55rem 0.85rem;
  font-size: 0.92rem;
}

.score-row .btn.ghost:hover {
  background: rgba(20, 32, 40, 0.04);
}

.score-row input:disabled {
  color: var(--ink-soft);
  background: rgba(255, 255, 255, 0.72);
}

.score-hint {
  margin: 0.4rem 0 0;
  font-size: 0.78rem;
  line-height: 1.35;
  color: var(--ink-soft);
}

.score-status {
  min-height: 1.1em;
  margin: 0.28rem 0 0;
  font-size: 0.82rem;
  color: var(--teal);
}

.score-status.is-error {
  color: var(--coral);
}

.leaderboard-list {
  margin: 0 0 0.85rem;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
  max-height: 9.5rem;
  overflow: auto;
}

.leaderboard-list li {
  display: flex;
  gap: 0.4rem;
  align-items: baseline;
  padding: 0.2rem 0;
  border-bottom: 1px solid var(--line);
}

.leaderboard-list .lb-rank {
  width: 1.6rem;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
}

.leaderboard-list .lb-name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.leaderboard-list .lb-score {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--teal);
}

.leaderboard-list .lb-empty {
  border: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.over-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.55rem;
  margin-top: 1rem;
}

.over-actions .btn.primary {
  flex: 1;
}

.over-actions .btn.ghost {
  color: var(--ink);
  border-color: var(--line);
}

@media (max-width: 420px) {
  .page {
    padding-inline: 0.75rem;
  }

  .stat-value {
    font-size: 1.1rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .brand-mark,
  .interstitial,
  .interstitial-card,
  .btn,
  .lobby-hero,
  .game-card,
  .spark-visual::after,
  .snake-visual::before,
  .lane-visual::after,
  .lane-btn {
    animation: none;
    transition: none;
  }
}
