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

body {
  background:
    radial-gradient(circle at 50% 30%, rgba(40, 200, 150, 0.12), transparent 55%),
    linear-gradient(160deg, #0b1226 0%, #070b18 60%, #04060e 100%) fixed;
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
  color: #e0e0e0;
  overflow-x: hidden;
  touch-action: pan-y;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Game wrapper ── */
#game-wrapper {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

/* ── HUD ── */
#hud {
  width: min(600px, calc(100vw - 16px), max(200px, calc(100vh - var(--gp-header-h, 80px) - 66px)));
  width: min(600px, calc(100vw - 16px), max(200px, calc(100dvh - var(--gp-header-h, 80px) - 66px)));
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.08), inset -1px 0 0 rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-radius: 14px 14px 0 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 2px;
  text-transform: uppercase;
}

#score-label { color: #7dffb0; text-shadow: 0 0 12px rgba(80, 255, 170, 0.5); }
#high-label  { color: #ffd34d; text-shadow: 0 0 12px rgba(255, 211, 77, 0.45); }
#score, #high-score { font-variant-numeric: tabular-nums; }

/* ── Canvas container ── */
#canvas-container {
  position: relative;
  width: min(600px, calc(100vw - 16px), max(200px, calc(100vh - var(--gp-header-h, 80px) - 66px)));
  width: min(600px, calc(100vw - 16px), max(200px, calc(100dvh - var(--gp-header-h, 80px) - 66px)));
  aspect-ratio: 1 / 1;
  border: 2px solid rgba(120, 220, 255, 0.14);
  border-radius: 0 0 14px 14px;
  overflow: hidden;
  box-shadow:
    0 18px 50px rgba(0, 0, 0, .55),
    0 0 60px rgba(40, 220, 160, .14);
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: #070c1d;
  touch-action: none;
}

/* ── Screen-shake ── */
#canvas-container.shake {
  animation: shake .4s ease-out;
}
@keyframes shake {
  0%   { transform: translate( 0,  0); }
  10%  { transform: translate(-6px,  4px); }
  20%  { transform: translate( 6px, -4px); }
  30%  { transform: translate(-4px,  6px); }
  40%  { transform: translate( 4px, -6px); }
  50%  { transform: translate(-2px,  2px); }
  60%  { transform: translate( 2px, -2px); }
  80%  { transform: translate( 1px,  1px); }
  100% { transform: translate( 0,  0); }
}

/* ── Overlays ── */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  justify-content: safe center;
  align-items: center;
  overflow-y: auto;
  background: rgba(5, 10, 24, .78);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 10;
  gap: 12px;
  padding: 30px;
  transition: opacity .3s ease;
}
.overlay.hidden {
  display: none;
}

.overlay h1 {
  font-size: 52px;
  letter-spacing: 6px;
  text-transform: uppercase;
  background: linear-gradient(90deg, #7dffb0, #3be0c8 55%, #5fb8ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  filter: drop-shadow(0 0 16px rgba(80, 255, 180, 0.45));
  margin-bottom: 4px;
}

#gameover-overlay h1 {
  background: linear-gradient(90deg, #ff7a8a, #ffb36b);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 16px rgba(255, 110, 120, 0.45));
}

.overlay .subtitle {
  font-size: 14px;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #7a8ba6;
  margin-bottom: 8px;
}

.how-to {
  max-width: 340px;
  text-align: left;
  margin: 16px 0;
  padding: 14px 18px;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.7;
  color: #c3cbe2;
}

.mode-legend { display: inline-block; margin-top: 4px; font-size: 11px; color: #8f9bbd; }
.m-classic { color: #53d769; }
.m-obstacle { color: #e8a030; }
.m-portal { color: #60b0ff; }

.how-to-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #8f9bbd;
  margin-bottom: 8px;
  text-transform: uppercase;
}

#snake-modes {
  display: flex;
  gap: 8px;
  margin: 12px 0;
  justify-content: center;
}

.smode-btn {
  padding: 8px 16px;
  font-size: 13px;
  font-weight: 700;
  border: 2px solid rgba(255, 255, 255, 0.16);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: #8f9bbd;
  cursor: pointer;
  transition: all 0.2s;
}
.smode-btn:hover { color: #dfe6fb; border-color: rgba(255, 255, 255, 0.35); }
.smode-btn.active[data-mode="classic"] { color: #53d769; border-color: #53d769; background: rgba(83, 215, 105, 0.12); box-shadow: 0 0 16px rgba(83, 215, 105, 0.35); }
.smode-btn.active[data-mode="obstacle"] { color: #e8a030; border-color: #e8a030; background: rgba(232, 160, 48, 0.12); box-shadow: 0 0 16px rgba(232, 160, 48, 0.35); }
.smode-btn.active[data-mode="portal"] { color: #60b0ff; border-color: #60b0ff; background: rgba(96, 176, 255, 0.12); box-shadow: 0 0 16px rgba(96, 176, 255, 0.35); }

#final-mode-text { font-size: 12px; letter-spacing: 2px; color: #888; margin: 0 0 4px; text-transform: uppercase; }

.overlay .controls-hint {
  font-size: 12px;
  color: #6c7699;
  letter-spacing: 1px;
  margin-top: 10px;
}

#final-score-text {
  font-size: 22px;
  color: #ffd34d;
  letter-spacing: 2px;
  margin-bottom: 4px;
}

/* ── Button ── */
.btn {
  padding: 14px 48px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 3px;
  text-transform: uppercase;
  color: #04150f;
  background: linear-gradient(90deg, #7dffb0, #3be0c8);
  border: 0;
  border-radius: 999px;
  cursor: pointer;
  transition: all .2s ease;
  outline: none;
  margin-top: 6px;
  box-shadow: 0 6px 24px rgba(60, 230, 170, .4);
}
.btn:hover, .btn:focus-visible {
  box-shadow: 0 10px 30px rgba(60, 230, 170, .55);
  transform: translateY(-2px) scale(1.03);
}

/* ── Leaderboard ── */
#leaderboard {
  margin-top: 18px;
  text-align: center;
  width: 260px;
}
#leaderboard h2 {
  font-size: 16px;
  letter-spacing: 3px;
  color: #ffd34d;
  margin-bottom: 8px;
}
#score-list {
  list-style: none;
  padding: 0;
}
#score-list li {
  padding: 5px 0;
  font-size: 15px;
  letter-spacing: 1px;
  color: #c3cbe2;
  border-bottom: 1px solid rgba(255,255,255,.07);
  display: flex;
  justify-content: space-between;
}
#score-list li .rank { color: #7dffb0; min-width: 28px; text-align: left; }
#score-list li .pts  { color: #ffd34d; }
#score-list li.empty { justify-content: center; color: #6c7699; }

/* ── Responsive ── */
@media (max-width: 640px) {
  .overlay h1 { font-size: 32px; }
}
@media (max-width: 640px), (max-height: 760px) {
  .overlay { padding: 12px; gap: 6px; }
  .overlay .subtitle, .overlay .controls-hint { display: none; }
  .how-to { margin: 4px 0; padding: 10px 14px; line-height: 1.5; }
  #snake-modes { margin: 4px 0; }
  .btn { padding: 10px 36px; font-size: 16px; }
}

@media (max-width: 500px), (max-height: 500px) {
  .overlay { position: fixed; top: var(--gp-header-h, 48px); right: 0; bottom: 0; left: 0; z-index: 900; border-radius: 0; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #start-overlay:not(.hidden) { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); column-gap: 24px; align-items: center; align-content: center; justify-items: center; width: auto; padding-left: max(12px, calc((100% - 780px) / 2)); padding-right: max(12px, calc((100% - 780px) / 2)); }
  #start-overlay:not(.hidden) > * { grid-column: 2; }
  #start-overlay:not(.hidden) > .how-to { grid-column: 1; grid-row: 1 / span 6; margin: 0; max-width: 340px; width: 100%; }
  #start-overlay h1 { font-size: 34px; }
}

@media (pointer: coarse) and (min-width: 700px) and (min-height: 700px) {
  #hud, #canvas-container {
    width: min(760px, calc(100vw - 16px), max(200px, calc(100vh - var(--gp-header-h, 80px) - 66px)));
    width: min(760px, calc(100vw - 16px), max(200px, calc(100dvh - var(--gp-header-h, 80px) - 66px)));
  }
}

[data-theme="light"] html,
[data-theme="light"] body { background: var(--gp-page-grad) fixed; color: var(--gp-ink); }
[data-theme="light"] #hud { background: var(--gp-surface); color: var(--gp-ink); box-shadow: inset 0 0 0 1px var(--gp-line), var(--gp-shadow); }
[data-theme="light"] #score-label { color: #15803d; }
[data-theme="light"] #high-label { color: #b7791f; }
[data-theme="light"] .overlay { background: var(--gp-overlay); }
[data-theme="light"] .overlay h1 { background: linear-gradient(90deg, #15803d, #0d9488 55%, #2563eb); -webkit-background-clip: text; background-clip: text; filter: none; }
[data-theme="light"] #gameover-overlay h1 { background: linear-gradient(90deg, #e11d48, #c2410c); -webkit-background-clip: text; background-clip: text; }
[data-theme="light"] .smode-btn { background: var(--gp-surface); border-color: var(--gp-line); }
[data-theme="light"] .mode-legend { color: var(--gp-ink-3); }
[data-theme="light"] .btn { color: #04150f; }
[data-theme="light"] .overlay .subtitle { color: var(--gp-ink-2); }
[data-theme="light"] .how-to { background: rgba(31, 27, 69, 0.05); border-color: var(--gp-line); color: var(--gp-ink-2); }
[data-theme="light"] #final-score-text, [data-theme="light"] #leaderboard h2, [data-theme="light"] #score-list li .pts { color: #b7791f; }
[data-theme="light"] #score-list li { color: var(--gp-ink-2); }
[data-theme="light"] #score-list li .rank { color: #15803d; }
[data-theme="light"] .smode-btn, [data-theme="light"] #final-mode-text { filter: brightness(0.72) saturate(1.3); }
[data-theme="light"] .how-to span { filter: brightness(0.72) saturate(1.3); }

.gp-btn-music.off { opacity: .4; }
