/* ============================================================
   Snake · Fruit Frenzy — styles
   Themes are driven by CSS variables on <body data-theme="...">
   ============================================================ */

:root { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: radial-gradient(120% 90% at 50% -10%, var(--bg2) 0%, var(--bg1) 62%) fixed;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

/* ---------- themes ---------- */
body[data-theme="emerald"] {
  --bg1: #04231f; --bg2: #0b4a3c;
  --panel: #0b352d; --panel2: #10453a;
  --board: #0a3d33;
  --accent: #d4af37; --accent2: #35bfc0;
  --text: #f8f1df; --muted: #9fc4b5;
  --btn-grad: linear-gradient(135deg, #eccb64, #c19a2e);
  --btn-text: #241b05;
  --shadow: rgba(0, 0, 0, .42);
  --overlay: rgba(3, 24, 20, .76);
  --line: rgba(255, 255, 255, .09);
}
body[data-theme="sunset"] {
  --bg1: #2a0d18; --bg2: #5c1f2e;
  --panel: #3a1420; --panel2: #4a1a29;
  --board: #471a29;
  --accent: #ff9e42; --accent2: #ff5d73;
  --text: #ffe8d6; --muted: #d8a08c;
  --btn-grad: linear-gradient(135deg, #ffb45e, #ff5d73);
  --btn-text: #3a1005;
  --shadow: rgba(0, 0, 0, .45);
  --overlay: rgba(26, 8, 14, .78);
  --line: rgba(255, 255, 255, .10);
}
body[data-theme="neon"] {
  --bg1: #08080f; --bg2: #16162e;
  --panel: #12121f; --panel2: #1a1a2e;
  --board: #12121f;
  --accent: #ff2ec4; --accent2: #22d3ee;
  --text: #eef2ff; --muted: #8b90b5;
  --btn-grad: linear-gradient(135deg, #ff2ec4, #7c3aed);
  --btn-text: #ffffff;
  --shadow: rgba(0, 0, 0, .6);
  --overlay: rgba(5, 5, 12, .8);
  --line: rgba(255, 255, 255, .12);
}

/* ---------- layout ---------- */
.app {
  width: min(560px, 100%);
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom, 0px));
}
.screen { display: flex; flex-direction: column; gap: 14px; }
.hidden { display: none !important; }

button { font-family: inherit; }
button:focus-visible, summary:focus-visible {
  outline: 3px solid var(--accent2);
  outline-offset: 2px;
}

/* ---------- menu ---------- */
.menu-header { text-align: center; padding-top: 6px; }
.logo {
  font-size: 56px;
  line-height: 1;
  display: inline-block;
  animation: floaty 3.2s ease-in-out infinite;
  filter: drop-shadow(0 6px 14px var(--shadow));
}
.menu-header h1 {
  margin: 6px 0 0;
  font-size: 40px;
  font-weight: 900;
  letter-spacing: .04em;
  color: var(--text);
  text-shadow: 0 2px 18px var(--shadow);
}
.tagline {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 14px;
  letter-spacing: .06em;
}

.stats-strip { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 6px;
  text-align: center;
}
.stat-card .v { display: block; font-size: 20px; font-weight: 900; color: var(--accent); }
.stat-card .l {
  font-size: 10.5px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.menu-grid { display: flex; flex-direction: column; gap: 10px; }
.option-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
}
.option-label {
  display: block;
  font-size: 11.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .09em;
  color: var(--muted);
  margin-bottom: 8px;
}
.sound-card { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.sound-card .option-label { margin-bottom: 0; }
.sound-btn {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  touch-action: manipulation;
}
.sound-btn:active { transform: scale(.97); }

.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button {
  flex: 1 1 auto;
  min-width: 64px;
  padding: 9px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .06s ease, background .15s ease, color .15s ease;
}
.seg button:active { transform: scale(.96); }
.seg button.active {
  background: var(--accent);
  border-color: transparent;
  color: var(--btn-text);
  box-shadow: 0 2px 10px var(--shadow);
}

.btn {
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .06);
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .06s ease;
}
.btn:active { transform: scale(.97); }
.btn.primary {
  background: var(--btn-grad);
  color: var(--btn-text);
  border: none;
  box-shadow: 0 6px 18px var(--shadow);
}
.btn.big { width: 100%; padding: 16px; font-size: 20px; font-weight: 800; letter-spacing: .02em; border-radius: 16px; }

.howto {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 14px;
}
.howto summary { cursor: pointer; font-weight: 700; font-size: 15px; padding: 4px 0; }
.howto-body { padding: 8px 2px 4px; }
.howto-body p { margin: 8px 0; font-size: 14.5px; line-height: 1.5; color: var(--text); }
.howto-body b { color: var(--accent); }

.menu-footer { text-align: center; color: var(--muted); font-size: 12px; padding-bottom: 4px; }

/* ---------- HUD ---------- */
.hud {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.hud-left { display: flex; gap: 18px; }
.hud-item .label {
  display: block;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--muted);
}
.hud-item span:last-child { font-size: 21px; font-weight: 900; }
#hud-score { color: var(--accent); }
.hud-mid { display: flex; align-items: center; gap: 8px; }
.level-pill {
  padding: 4px 12px;
  border-radius: 999px;
  border: 1px solid var(--accent);
  color: var(--accent);
  font-weight: 700;
  font-size: 13px;
}
.streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 12px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent2), var(--accent));
  color: var(--btn-text);
  font-weight: 800;
  font-size: 13px;
  animation: streakPulse 1s ease-in-out infinite;
}
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  touch-action: manipulation;
}
.icon-btn:active { transform: scale(.94); }

/* ---------- board ---------- */
#board-wrap {
  position: relative;
  width: min(100%, 540px, calc(100vh - 180px));
  min-width: 240px;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 18px;
  overflow: hidden;
  background: var(--board);
  box-shadow: 0 12px 40px var(--shadow), 0 0 0 1px var(--line);
  touch-action: none;
}
@supports (height: 100dvh) {
  #board-wrap { width: min(100%, 540px, calc(100dvh - 180px)); }
}
body.touch #board-wrap { width: min(100%, 540px, calc(100vh - 340px)); }
@supports (height: 100dvh) {
  body.touch #board-wrap { width: min(100%, 540px, calc(100dvh - 340px)); }
}

#board { display: block; width: 100%; height: 100%; }
#swipe-layer { position: absolute; inset: 0; touch-action: none; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: var(--overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.overlay-card {
  width: 100%;
  max-width: 340px;
  background: var(--panel2);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 20px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 16px 50px var(--shadow);
  animation: popIn .22s ease;
}
.overlay-card h2 { margin: 0; font-size: 22px; }
.overlay-card .sub { color: var(--muted); font-size: 13.5px; margin: 0; line-height: 1.5; }
.overlay-card .sub b { color: var(--text); }
.big-score { font-size: 46px; font-weight: 900; color: var(--accent); line-height: 1; }
.overlay-card .btns { display: flex; flex-direction: column; gap: 8px; }

.record {
  display: inline-block;
  align-self: center;
  padding: 6px 16px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffe08a, #e6c15a);
  color: #3a2c05;
  font-weight: 800;
  font-size: 14px;
  animation: glowPulse 1.6s ease-in-out infinite;
}

/* ---------- D-pad (touch devices) ---------- */
.dpad {
  display: none;
  grid-template-areas:
    ".    up    ."
    "left mid   right"
    ".    down  .";
  grid-template-columns: repeat(3, 74px);
  grid-template-rows: repeat(3, 58px);
  gap: 8px;
  justify-content: center;
  margin-top: 2px;
}
body.touch .dpad { display: grid; }
.dpad button {
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, .07);
  color: var(--text);
  font-size: 19px;
  font-weight: 800;
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.dpad button:active { background: var(--accent); color: var(--btn-text); transform: scale(.94); }
.dpad [data-dir="up"] { grid-area: up; }
.dpad [data-dir="left"] { grid-area: left; }
.dpad [data-dir="right"] { grid-area: right; }
.dpad [data-dir="down"] { grid-area: down; }
#dpad-mid { grid-area: mid; font-size: 17px; }

/* ---------- animations ---------- */
@keyframes floaty {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}
@keyframes popIn {
  from { transform: scale(.82); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
@keyframes streakPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.07); }
}
@keyframes glowPulse {
  0%, 100% { box-shadow: 0 0 6px rgba(255, 215, 94, .35); }
  50% { box-shadow: 0 0 18px rgba(255, 215, 94, .8); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}

/* ---------- small screens ---------- */
@media (max-width: 380px) {
  .menu-header h1 { font-size: 32px; }
  .logo { font-size: 46px; }
  .seg button { min-width: 56px; font-size: 13px; }
  .hud-left { gap: 12px; }
  .hud-item span:last-child { font-size: 18px; }
}
