/* ============================================
   VINYL SNAKE - Retro Arcade Record Store
   ============================================ */

:root {
  --bg: #0a0a0a;
  --board: #1a1a2e;
  --panel: #12121f;
  --line: #2a2a3e;
  --snake: #e8a838;
  --accent: #ff6b35;
  --text: #e0d4b8;
  --text-dim: #9a8f7a;
  --neon-glow: #ff6b35;
  --red: #e63946;
  --gold: #ffd700;
  --blue: #4cc9f0;
  --green: #06d6a0;
  --splatter1: #e63946;
  --splatter2: #4cc9f0;
  --splatter3: #06d6a0;
  --pixel: 'Press Start 2P', monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: var(--pixel);
  color: var(--text);
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background: repeating-radial-gradient(circle at 50% 50%, transparent 0px, transparent 3px, rgba(255,255,255,0.008) 3px, rgba(255,255,255,0.008) 4px);
  pointer-events: none; z-index: 0;
}
body::after {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='0.03'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 0;
}

button { font-family: var(--pixel); cursor: pointer; -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:focus-visible, .speed-chip input:focus-visible + span { outline: 3px solid var(--gold); outline-offset: 3px; }

#game-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
  overflow-x: hidden;
  overflow-y: auto;
}

#crt-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 1000;
  background: repeating-linear-gradient(0deg, transparent 0px, transparent 2px, rgba(0,0,0,0.12) 2px, rgba(0,0,0,0.12) 4px);
  mix-blend-mode: multiply;
}
#crt-overlay::after {
  content: ''; position: absolute; inset: 0;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0,0,0,0.4) 100%);
}

#screen-container {
  position: relative;
  width: 100%;
  max-width: 680px;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
  margin: auto 0;
}

.screen { display: none; flex-direction: column; align-items: center; width: 100%; animation: fadeIn 0.4s ease; }
.screen.active { display: flex; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.glow-text { text-shadow: 0 0 4px var(--neon-glow), 0 0 12px rgba(255,107,53,0.5), 0 0 24px rgba(255,107,53,0.2); }

/* ========================
   TITLE SCREEN
   ======================== */
.title-vinyl-container { margin-bottom: 20px; }
.title-vinyl {
  width: 100px; height: 100px; border-radius: 50%; background: #111; position: relative;
  animation: spin 4s linear infinite; box-shadow: 0 0 20px rgba(232,168,56,0.2);
}
.vinyl-groove { position: absolute; border-radius: 50%; border: 1px solid rgba(255,255,255,0.06); top: 50%; left: 50%; transform: translate(-50%, -50%); }
.v1 { width: 90%; height: 90%; } .v2 { width: 72%; height: 72%; } .v3 { width: 56%; height: 56%; } .v4 { width: 40%; height: 40%; }
.vinyl-label {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 30%; height: 30%; border-radius: 50%; background: var(--accent);
  display: flex; align-items: center; justify-content: center;
}
.vinyl-label span { font-size: 8px; color: var(--bg); animation: spin 4s linear infinite reverse; }
@keyframes spin { to { transform: rotate(360deg); } }

.game-title { font-size: clamp(24px, 6vw, 42px); color: var(--accent); letter-spacing: 4px; text-align: center; margin-bottom: 10px; }
.subtitle { font-size: clamp(9px, 2vw, 11px); color: var(--text-dim); margin-bottom: 28px; letter-spacing: 2px; text-align: center; line-height: 1.6; }

.play-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 12px;
  min-height: 56px; padding: 14px 32px;
  background: var(--snake); border: 3px solid var(--accent); color: var(--bg);
  font-size: 14px; transition: transform 0.15s, background-color 0.15s, box-shadow 0.15s;
  margin-bottom: 24px;
}
.play-btn:hover { background: var(--accent); transform: scale(1.04); box-shadow: 0 0 20px rgba(255,107,53,0.5); }
.play-btn:active { transform: scale(0.97); }

.menu-btn {
  min-height: 48px; padding: 12px 22px;
  background: transparent; border: 3px solid var(--line); color: var(--text);
  font-size: 11px; letter-spacing: 1px; transition: border-color 0.15s, color 0.15s, background-color 0.15s;
}
.menu-btn:hover { border-color: var(--snake); color: var(--snake); background: rgba(232,168,56,0.06); }
.menu-btn.primary { background: var(--snake); border-color: var(--accent); color: var(--bg); }
.menu-btn.primary:hover { background: var(--accent); color: var(--bg); }

.speed-pick { border: 0; margin-bottom: 22px; text-align: center; }
.speed-pick legend { font-size: 9px; color: var(--text-dim); letter-spacing: 2px; margin: 0 auto 10px; }
.speed-options { display: flex; gap: 8px; justify-content: center; }
.speed-chip { position: relative; cursor: pointer; }
.speed-chip input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.speed-chip span {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; min-width: 88px; padding: 0 12px;
  font-size: 9px; letter-spacing: 1px; color: var(--text-dim); border: 2px solid var(--line); background: rgba(255,255,255,0.02);
  transition: border-color 0.15s, color 0.15s;
}
.speed-chip:hover span { border-color: #4a4a64; color: var(--text); }
.speed-chip input:checked + span { border-color: var(--snake); color: var(--snake); background: rgba(232,168,56,0.08); }

.controls-info { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; text-align: center; }
.control-row { font-size: 9px; color: var(--text-dim); letter-spacing: 1px; line-height: 2.2; }
.key { color: var(--snake); padding: 3px 6px; border: 1px solid var(--snake); font-size: 8px; white-space: nowrap; }
.touch-hint { display: none; }

.record-legend { list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 10px 20px; font-size: 9px; color: var(--text-dim); }
.legend-item { display: flex; align-items: center; gap: 8px; }
.legend-dot { width: 12px; height: 12px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
.black-vinyl { background: #333; border: 1px solid #666; }
.red-vinyl { background: var(--red); }
.gold-vinyl { background: var(--gold); }
.splatter-vinyl { background: conic-gradient(var(--splatter1) 0deg, var(--splatter2) 120deg, var(--splatter3) 240deg, var(--splatter1) 360deg); }
.title-best { margin-top: 22px; font-size: 9px; color: var(--gold); letter-spacing: 1px; }

/* ========================
   GAME SCREEN
   ======================== */
.board-col { display: flex; flex-direction: column; align-items: center; min-width: 0; }

#hud { display: flex; align-items: center; justify-content: center; gap: 16px; margin-bottom: 10px; width: 100%; max-width: 600px; }
.hud-item { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.hud-label { font-size: 8px; color: var(--text-dim); letter-spacing: 1px; }
.hud-value { font-size: 14px; color: var(--snake); font-variant-numeric: tabular-nums; }
.combo-display { transition: opacity 0.3s; opacity: 0.25; }
.combo-display.on { opacity: 1; }
.combo-display .hud-value { color: var(--accent); }
.hud-pause {
  width: 44px; height: 44px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  background: transparent; border: 2px solid var(--line); color: var(--text);
  transition: border-color 0.15s, color 0.15s;
}
.hud-pause:hover { border-color: var(--snake); color: var(--snake); }

#canvas-wrapper {
  position: relative; border: 3px solid var(--line);
  box-shadow: 0 0 10px rgba(232,168,56,0.1), inset 0 0 30px rgba(0,0,0,0.5);
  background: var(--board); line-height: 0;
}
#game-canvas { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }

.collection-popup {
  position: absolute; pointer-events: none; font-size: 9px; color: var(--snake);
  text-shadow: 0 0 6px var(--neon-glow); opacity: 0; white-space: nowrap; z-index: 10; line-height: 1.2;
  transform: translateX(-50%);
}
.collection-popup.show { animation: popFloat 1s ease forwards; }
@keyframes popFloat {
  0% { opacity: 1; transform: translate(-50%, 0) scale(1.2); }
  30% { opacity: 1; transform: translate(-50%, -10px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -30px) scale(0.8); }
}

.pause-panel {
  position: absolute; inset: 0; z-index: 20; line-height: 1.2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: rgba(10,10,20,0.82); backdrop-filter: blur(2px);
}
.pause-panel .menu-btn { min-width: 200px; }
.pause-title { font-size: 22px; color: var(--snake); margin-bottom: 10px; letter-spacing: 3px; }
.countdown {
  position: absolute; inset: 0; z-index: 15; display: flex; align-items: center; justify-content: center;
  font-size: 48px; color: var(--snake); line-height: 1; pointer-events: none;
  text-shadow: 0 0 10px var(--neon-glow), 0 0 30px rgba(255,107,53,0.4);
}

/* On-screen pad (touch screens) */
.dpad {
  display: none;
  grid-template-columns: repeat(3, 64px); grid-template-rows: repeat(2, 56px);
  grid-template-areas: ". up ." "left down right";
  gap: 8px; margin-top: 14px;
}
.dpad-btn {
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.03); border: 2px solid var(--line); color: var(--snake);
  transition: background-color 0.1s, border-color 0.1s, transform 0.1s;
}
.dpad-btn svg { width: 24px; height: 24px; }
.dpad-btn.up { grid-area: up; } .dpad-btn.left { grid-area: left; } .dpad-btn.right { grid-area: right; } .dpad-btn.down { grid-area: down; }
.dpad-btn:active, .dpad-btn.hit { background: rgba(232,168,56,0.18); border-color: var(--snake); transform: scale(0.95); }

/* Side panels (wide screens) */
.side { display: none; }
.side-title { font-size: 9px; color: var(--text-dim); letter-spacing: 2px; margin: 0 0 14px; font-weight: normal; }
.side-title:not(:first-child) { margin-top: 26px; }
.side-legend { list-style: none; display: flex; flex-direction: column; gap: 12px; font-size: 9px; }
.side-legend li { display: grid; grid-template-columns: 14px 1fr auto; gap: 10px; align-items: center; }
.side-legend b { color: var(--snake); font-weight: normal; }
.side-text { font-size: 8px; line-height: 2.2; color: var(--text-dim); letter-spacing: 0.5px; }
.side-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.side-stats dt { font-size: 8px; color: var(--text-dim); letter-spacing: 1px; margin-bottom: 6px; }
.side-stats dd { font-size: 12px; color: var(--snake); }

.runs-list { list-style: none; display: flex; flex-direction: column; gap: 8px; font-size: 9px; counter-reset: run; }
.runs-list li { display: grid; grid-template-columns: 26px 1fr auto; gap: 8px; align-items: center; padding: 8px 10px; border: 1px solid rgba(255,255,255,0.06); background: rgba(255,255,255,0.02); counter-increment: run; }
.runs-list li::before { content: counter(run); color: var(--text-dim); }
.runs-list li .r-score { color: var(--snake); }
.runs-list li .r-meta { color: var(--text-dim); font-size: 8px; text-align: right; }
.runs-list li.latest { border-color: rgba(232,168,56,0.5); }
.runs-list li.runs-empty { display: block; color: var(--text-dim); font-size: 8px; line-height: 2; border-style: dashed; }
.runs-list li.runs-empty::before { content: none; }

/* ========================
   GAME OVER SCREEN
   ======================== */
.gameover-title { font-size: clamp(20px, 5vw, 32px); color: var(--red); margin-bottom: 12px; text-shadow: 0 0 4px var(--red), 0 0 12px rgba(230,57,70,0.5); text-align: center; }
.gameover-cause { font-size: 9px; color: var(--text-dim); margin-bottom: 16px; letter-spacing: 1px; }
.new-hs { font-size: clamp(10px, 2.5vw, 14px); color: var(--gold); margin-bottom: 16px; animation: hsFlash 0.6s ease infinite alternate; text-shadow: 0 0 10px rgba(255,215,0,0.6); }
.new-hs.hidden { display: none; }
@keyframes hsFlash { from { opacity: 0.6; transform: scale(0.97); } to { opacity: 1; transform: scale(1.03); } }

.stats-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 24px; width: 100%; max-width: 420px; }
.stat-item { display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 14px 8px; background: rgba(255,255,255,0.03); border: 1px solid rgba(255,255,255,0.08); }
.stat-label { font-size: 8px; color: var(--text-dim); letter-spacing: 1px; text-align: center; }
.stat-value { font-size: 16px; color: var(--snake); }
.gameover-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; align-items: center; margin-bottom: 24px; }
.gameover-actions .play-btn { margin-bottom: 0; }
.runs-board { width: 100%; max-width: 420px; }
.runs-title { font-size: 9px; color: var(--text-dim); letter-spacing: 2px; margin-bottom: 12px; font-weight: normal; text-align: center; }

/* Screen shake / flash */
@keyframes screenShake {
  0%, 100% { transform: translate(0, 0); } 10% { transform: translate(-4px, 2px); } 20% { transform: translate(4px, -2px); }
  30% { transform: translate(-3px, -3px); } 40% { transform: translate(3px, 3px); } 50% { transform: translate(-2px, 1px); }
  60% { transform: translate(2px, -1px); } 70% { transform: translate(-1px, 2px); } 80% { transform: translate(1px, -1px); } 90% { transform: translate(0, 1px); }
}
.screen-shake { animation: screenShake 0.4s ease; }
@keyframes screenFlash { 0% { opacity: 0.8; } 50%, 100% { opacity: 0; } }
.screen-flash { position: fixed; inset: 0; background: #fff; pointer-events: none; z-index: 999; animation: screenFlash 0.3s ease forwards; }

/* ========================
   RESPONSIVE
   ======================== */
@media (pointer: coarse) {
  .touch-hint { display: block; }
  .desk-hint { display: none; }
  .dpad { display: grid; }
}

@media (max-width: 480px) {
  #screen-container { padding: 10px 8px; }
  #hud { gap: 10px; justify-content: space-between; padding: 0 2px; }
  .hud-value { font-size: 11px; }
  .hud-label { font-size: 7px; }
  .game-title { letter-spacing: 2px; }
  .stats-grid { gap: 8px; }
  .stat-item { padding: 10px 4px; }
  .stat-value { font-size: 13px; }
  .speed-chip span { min-width: 0; padding: 0 12px; }
  .record-legend { gap: 10px 14px; font-size: 8px; }
  .gameover-actions { flex-direction: column; width: 100%; max-width: 320px; }
  .gameover-actions > * { width: 100%; }
}

/* Wide screens: rules on the left, this visit's runs on the right */
@media (min-width: 1100px) and (min-height: 640px) {
  #screen-container { max-width: 1240px; }
  #game-screen.active { display: grid; grid-template-columns: 240px auto 240px; gap: 40px; align-items: start; justify-content: center; }
  .side { display: block; padding: 22px 20px; border: 2px solid var(--line); background: rgba(18,18,31,0.7); margin-top: 54px; }
}
@media (min-width: 1600px) and (min-height: 640px) {
  #game-screen.active { grid-template-columns: 280px auto 280px; gap: 56px; }
  #hud { max-width: 760px; }
  #screen-container { max-width: 1500px; }
}

@media (prefers-reduced-motion: reduce) {
  .title-vinyl, .vinyl-label span, .new-hs { animation: none; }
}

/* Big screens: give the title and game-over screens more presence */
@media (min-width: 1024px) and (min-height: 760px) {
  .title-vinyl { width: 140px; height: 140px; }
  .vinyl-label span { font-size: 10px; }
  .game-title { font-size: 52px; letter-spacing: 6px; margin-bottom: 14px; }
  .subtitle { font-size: 12px; margin-bottom: 34px; }
  .play-btn { font-size: 16px; padding: 18px 40px; min-height: 64px; }
  .speed-pick legend { font-size: 10px; }
  .speed-chip span { font-size: 10px; min-width: 110px; min-height: 48px; }
  .control-row { font-size: 10px; }
  .key { font-size: 9px; }
  .record-legend { font-size: 10px; gap: 14px 36px; }
  .title-best { font-size: 10px; }
  .gameover-title { font-size: 44px; margin-bottom: 16px; }
  .gameover-cause { font-size: 11px; margin-bottom: 22px; }
  .stats-grid { max-width: 540px; gap: 14px; }
  .stat-item { padding: 18px 10px; gap: 10px; }
  .stat-label { font-size: 9px; }
  .stat-value { font-size: 22px; }
  .menu-btn { font-size: 12px; min-height: 56px; }
  .runs-board { max-width: 540px; }
  .runs-list { font-size: 10px; }
}
