/* ─────────────────────────────────────────────
   Snake  ·  style.css
   ───────────────────────────────────────────── */

/* ── Reset ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base ───────────────────────────────────── */
:root {
  --phone-body:    #1c2951;
  --phone-body2:   #16203f;
  --phone-silver:  #b0b8c8;
  --phone-dark:    #0d1428;

  --lcd-bg:        #8bac0f;
  --lcd-bg2:       #7ea00d;
  --lcd-dark:      #0f380f;
  --lcd-mid:       #306230;
  --lcd-light:     #9bbc0f;

  --phone-w:       606px;
}

html, body {
  height: 100%;
  overflow-x: hidden;
}

body {
  background: #0a0e1a;
  background-image:
    radial-gradient(ellipse 80% 60% at 50% 0%, #1a2347 0%, transparent 70%),
    radial-gradient(ellipse 50% 40% at 80% 100%, #0f1f3a 0%, transparent 60%);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  font-family: 'Press Start 2P', 'Courier New', monospace;
  color: var(--lcd-dark);
  user-select: none;
}

/* ── Page layout ────────────────────────────── */
.page {
  display: flex;
  align-items: flex-start;
  gap: 32px;
  padding: 24px 16px;
}

/* ─────────────────────────────────────────────
   PHONE BODY
   ───────────────────────────────────────────── */
.phone {
  width: var(--phone-w);
  background: linear-gradient(160deg, #263a70 0%, var(--phone-body) 30%, var(--phone-body2) 100%);
  border-radius: 28px 28px 52px 52px;
  padding: 14px 14px 28px;
  box-shadow:
    0 30px 80px rgba(0,0,0,0.7),
    0 0 0 1px rgba(255,255,255,0.06),
    inset 0 1px 0 rgba(255,255,255,0.12),
    inset 0 -4px 12px rgba(0,0,0,0.4);
  position: relative;
  flex-shrink: 0;
}

/* ── Top section (camera + speaker) ─────────── */
.phone-top {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 36px;
  margin-bottom: 10px;
}

.camera {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #3a4a70, #0a0e1a);
  box-shadow: 0 0 0 1px rgba(255,255,255,0.15), inset 0 0 4px rgba(0,0,0,0.8);
}

.speaker {
  display: flex;
  gap: 3px;
  align-items: center;
}
.speaker::before {
  content: '';
  display: block;
  width: 26px;
  height: 5px;
  border-radius: 3px;
  background: repeating-linear-gradient(
    90deg,
    rgba(0,0,0,0.5) 0px, rgba(0,0,0,0.5) 2px,
    transparent 2px, transparent 4px
  );
  box-shadow: 0 1px 0 rgba(255,255,255,0.05);
}

/* ── Screen bezel ───────────────────────────── */
.screen-bezel {
  background: #090d1a;
  border-radius: 8px;
  padding: 8px;
  box-shadow:
    inset 0 2px 8px rgba(0,0,0,0.8),
    inset 0 0 0 1px rgba(0,0,0,0.9),
    0 1px 0 rgba(255,255,255,0.06);
}

/* ── LCD display ────────────────────────────── */
.lcd {
  background: var(--lcd-bg);
  border-radius: 3px;
  overflow: hidden;
  position: relative;
  /* Subtle scanline effect */
  background-image:
    repeating-linear-gradient(
      0deg,
      rgba(0,0,0,0.03) 0px,
      rgba(0,0,0,0.03) 1px,
      transparent 1px,
      transparent 3px
    );
  box-shadow:
    inset 0 0 20px rgba(0,0,0,0.15),
    inset 0 0 0 1px rgba(0,0,0,0.2);
}

/* pixel-font lcd glow */
.lcd::after {
  content: '';
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 30%, rgba(155,188,15,0.2) 0%, transparent 70%);
  pointer-events: none;
}

/* ── LCD screens (swappable views) ──────────── */
.lcd-screen {
  display: none;
  flex-direction: column;
  align-items: center;
  width: 100%;
  padding: 8px 10px;
  min-height: 252px;
}
.lcd-screen.active { display: flex; }

/* ─────────────────────────────────────────────
   WELCOME SCREEN
   ───────────────────────────────────────────── */
.welcome-logo {
  font-size: 22px;
  color: var(--lcd-dark);
  letter-spacing: 4px;
  margin-top: 6px;
  text-shadow: 1px 1px 0 rgba(0,0,0,0.2);
  animation: blink-border 2s step-end infinite;
}

@keyframes blink-border {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.6; }
}

.welcome-sub {
  font-size: 5px;
  color: var(--lcd-mid);
  letter-spacing: 2px;
  margin-top: 2px;
  margin-bottom: 10px;
}

/* ── Always-on player counter bar ───────────── */
.online-bar {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  background: var(--lcd-dark);
  color: var(--lcd-light);
  font-size: 9px;
  letter-spacing: 1px;
  text-align: center;
  padding: 5px 6px;
  pointer-events: none;
}

/* Push screen content below the bar */
.lcd-screen { padding-top: 26px; }

.welcome-form {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.input-label {
  font-size: 5px;
  color: var(--lcd-mid);
  align-self: flex-start;
  letter-spacing: 1px;
}

.lcd-input {
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 8px;
  width: 100%;
  background: var(--lcd-bg2);
  border: none;
  border-bottom: 2px solid var(--lcd-dark);
  color: var(--lcd-dark);
  padding: 5px 4px;
  outline: none;
  letter-spacing: 1px;
}
.lcd-input::placeholder { color: var(--lcd-mid); opacity: 0.7; }
.lcd-input:focus { border-bottom-color: var(--lcd-mid); background: #96b80e; }
.lcd-input.shake {
  animation: shake 0.4s ease;
}
@keyframes shake {
  0%,100% { transform: translateX(0); }
  20%     { transform: translateX(-6px); }
  40%     { transform: translateX(6px); }
  60%     { transform: translateX(-4px); }
  80%     { transform: translateX(4px); }
}

/* ── Personal best banner ────────────────────── */
.personal-best {
  width: 100%;
  margin-top: 8px;
  font-size: 7px;
  color: var(--lcd-mid);
  text-align: center;
  letter-spacing: 1px;
  min-height: 12px;
  line-height: 1.6;
}
.personal-best .pb-score { color: var(--lcd-dark); }
.personal-best .pb-rank  { color: var(--lcd-dark); }

/* ── Buttons ─────────────────────────────────── */
.lcd-btn {
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 7px;
  background: var(--lcd-dark);
  color: var(--lcd-bg);
  border: none;
  padding: 7px 16px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.1s, transform 0.1s;
  margin-top: 2px;
}
.lcd-btn:hover  { background: var(--lcd-mid); }
.lcd-btn:active { transform: scale(0.96); }
.lcd-btn.small  { font-size: 6px; padding: 6px 10px; }
.lcd-btn.outline {
  background: transparent;
  color: var(--lcd-dark);
  border: 1px solid var(--lcd-dark);
}
.lcd-btn.outline:hover { background: var(--lcd-mid); color: var(--lcd-bg); }

/* ── Welcome score list ──────────────────────── */
.welcome-scores-title {
  font-size: 10px;
  color: var(--lcd-mid);
  margin-top: 14px;
  letter-spacing: 1px;
}
.welcome-scores { width: 100%; margin-top: 8px; }
.score-row {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  padding: 8px 2px;
  color: var(--lcd-dark);
  border-bottom: 1px dashed rgba(15,56,15,0.25);
}
.score-row .srank { color: var(--lcd-mid); min-width: 26px; }
.score-row .sname { flex: 1; padding: 0 8px; }
.score-row .sval  { text-align: right; }
.score-row.gold   { color: var(--lcd-dark); font-weight: bold; }
.no-scores { font-size: 10px; color: var(--lcd-mid); text-align: center; padding: 10px 0; }

/* ─────────────────────────────────────────────
   GAME SCREEN
   ───────────────────────────────────────────── */
#screen-game { padding: 4px 4px 4px; }

.hud {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  padding: 0 4px 3px;
  border-bottom: 1px solid rgba(15,56,15,0.3);
  margin-bottom: 3px;
}
.hud-name  { font-size: 5px; color: var(--lcd-mid); max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-score { font-size: 7px; color: var(--lcd-dark); }

#game-canvas {
  display: block;
  image-rendering: pixelated;
}

/* ─────────────────────────────────────────────
   GAME OVER SCREEN
   ───────────────────────────────────────────── */
.go-title {
  font-size: 11px;
  color: var(--lcd-dark);
  letter-spacing: 2px;
  margin-top: 8px;
  animation: go-flash 0.6s step-end 3;
}
@keyframes go-flash {
  0%,100% { opacity:1; } 50% { opacity:0; }
}

.go-name        { font-size: 8px; color: var(--lcd-mid); margin-top: 6px; }
.go-score-label { font-size: 7px; color: var(--lcd-mid); margin-top: 8px; }
.go-score       { font-size: 18px; color: var(--lcd-dark); margin-top: 2px; }
.go-rank        { font-size: 7px; color: var(--lcd-mid); margin-top: 4px; min-height: 12px; }
.go-buttons     { display: flex; gap: 8px; margin-top: 10px; }

.go-scores-title {
  font-size: 10px;
  color: var(--lcd-mid);
  margin-top: 10px;
  letter-spacing: 1px;
}
.go-scores { width: 100%; margin-top: 6px; }

/* ─────────────────────────────────────────────
   SOUND TOGGLES
   ───────────────────────────────────────────── */
.phone-sounds {
  display: flex;
  justify-content: center;
  gap: 12px;
  margin: 8px 0 6px;
}

.sound-btn {
  font-family: 'Press Start 2P', 'Courier New', monospace;
  font-size: 6px;
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.75);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 4px;
  padding: 5px 10px;
  cursor: pointer;
  letter-spacing: 1px;
  transition: background 0.1s, color 0.1s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.sound-btn:hover  { background: rgba(255,255,255,0.18); }
.sound-btn:active { transform: scale(0.93); }
.sound-btn.sound-off {
  color: rgba(255,255,255,0.28);
  background: rgba(0,0,0,0.25);
  border-color: rgba(255,255,255,0.08);
}

/* ── NAV ─────────────────────────────────────── */

/* ── Nav section ─────────────────────────────── */
.nav-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

/* ── D-pad ───────────────────────────────────── */
.nav-pad {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
}

.nav-middle-row {
  display: flex;
  align-items: center;
  gap: 1px;
}

.nav-btn {
  font-family: inherit;
  font-size: 14px;
  cursor: pointer;
  border: none;
  background: linear-gradient(160deg, #3a3f52 0%, #252838 100%);
  color: rgba(255,255,255,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.08s, transform 0.08s, box-shadow 0.08s;
  box-shadow:
    0 4px 8px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.18),
    inset 0 -2px 0 rgba(0,0,0,0.3);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.nav-btn:hover { background: linear-gradient(160deg, #474c62 0%, #2e3248 100%); }
.nav-btn:active {
  transform: scale(0.91);
  background: linear-gradient(160deg, #1e2130 0%, #1a1d2a 100%);
  box-shadow: 0 1px 3px rgba(0,0,0,0.6), inset 0 2px 4px rgba(0,0,0,0.4);
}

.nav-up, .nav-down {
  width: 44px;
  height: 26px;
  border-radius: 6px 6px 3px 3px;
}
.nav-down { border-radius: 3px 3px 6px 6px; }
.nav-left, .nav-right {
  width: 26px;
  height: 44px;
  border-radius: 6px 3px 3px 6px;
}
.nav-right { border-radius: 3px 6px 6px 3px; }
.nav-ok {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-size: 10px;
  letter-spacing: 0;
  background: linear-gradient(135deg, #4a6fa5 0%, #2a4a7a 100%);
  color: rgba(255,255,255,0.95);
  box-shadow:
    0 4px 10px rgba(0,0,0,0.55),
    inset 0 1px 0 rgba(255,255,255,0.25),
    inset 0 -2px 0 rgba(0,0,0,0.3);
}
.nav-ok:hover { background: linear-gradient(135deg, #5a80b8 0%, #3a5a8a 100%); }
.nav-ok:active {
  transform: scale(0.91);
  background: linear-gradient(135deg, #1e3a62 0%, #162d52 100%);
}

/* ── Soft keys ───────────────────────────────── */
.soft-keys {
  display: flex;
  gap: 80px;
}
.soft-key {
  font-family: inherit;
  font-size: 9px;
  width: 34px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: linear-gradient(180deg, #3a4f80 0%, #263870 100%);
  color: rgba(255,255,255,0.8);
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.15);
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.soft-key:active { background: linear-gradient(180deg, #2a3f70 0%, #1a2860 100%); }

/* ── Phone bottom ────────────────────────────── */
.phone-bottom {
  height: 20px;
}

/* ─────────────────────────────────────────────
   SIDEBAR (desktop only)
   ───────────────────────────────────────────── */
.sidebar {
  display: none;
  flex-direction: column;
  gap: 20px;
  min-width: 200px;
  padding-top: 10px;
}

.sidebar-title {
  font-size: 10px;
  color: rgba(155,188,15,0.8);
  letter-spacing: 2px;
  border-bottom: 1px solid rgba(155,188,15,0.2);
  padding-bottom: 8px;
}

.sidebar-scores { display: flex; flex-direction: column; gap: 1px; }

.sidebar .score-row {
  color: rgba(155,188,15,0.7);
  border-bottom-color: rgba(155,188,15,0.1);
  font-size: 11px;
  padding: 8px 0;
}
.sidebar .score-row .srank { color: rgba(155,188,15,0.4); }
.sidebar .score-row .sval  { color: rgba(155,188,15,0.9); }
.sidebar .score-row.gold   { color: #c8e040; }
.sidebar .no-scores { color: rgba(155,188,15,0.3); font-size: 10px; }

.sidebar-controls h3 {
  font-size: 7px;
  color: rgba(155,188,15,0.6);
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.controls-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 12px;
  font-size: 5px;
  color: rgba(155,188,15,0.5);
}
.controls-grid span:nth-child(odd)  { color: rgba(155,188,15,0.7); white-space: nowrap; }

/* ─────────────────────────────────────────────
   RESPONSIVE
   ───────────────────────────────────────────── */
@media (min-width: 600px) {
  .sidebar { display: flex; }
}

@media (max-width: 620px) {
  :root { --phone-w: calc(100vw - 8px); }

  body { align-items: flex-start; }
  .page { padding: 4px; }

  .welcome-logo { font-size: 18px; }

  /* Canvas fills full width with no side padding */
  #screen-game { padding: 4px 0 0; }
  #game-canvas { width: 100% !important; height: auto !important; display: block; }

  /* Bigger d-pad buttons for touch */
  .nav-up, .nav-down {
    width: 72px;
    height: 54px;
    font-size: 20px;
  }
  .nav-left, .nav-right {
    width: 54px;
    height: 72px;
    font-size: 20px;
  }
  .nav-ok {
    width: 64px;
    height: 64px;
    font-size: 13px;
  }
  .nav-pad { gap: 2px; }
  .nav-middle-row { gap: 2px; }

  /* Bigger soft keys */
  .soft-keys { gap: 60px; }
  .soft-key {
    width: 56px;
    height: 40px;
    font-size: 14px;
  }

  /* Sound buttons a touch bigger */
  .sound-btn { font-size: 7px; padding: 7px 14px; }
}

/* Pause overlay text rendered on canvas — no extra CSS needed */
