* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  --hue: 220;
  background:
    radial-gradient(circle at 20% 15%, hsla(calc(var(--hue) + 40), 90%, 55%, 0.2), transparent 45%),
    radial-gradient(circle at 85% 80%, hsla(calc(var(--hue) - 50), 90%, 55%, 0.17), transparent 50%),
    linear-gradient(160deg, hsl(var(--hue), 45%, 9%), hsl(calc(var(--hue) + 30), 50%, 5%));
  background-size: 160% 160%, 160% 160%, 100% 100%;
  background-attachment: fixed;
  animation: bg-drift 20s ease-in-out infinite alternate;
  color: #fff;
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  overflow-x: hidden;
  touch-action: pan-y;
  user-select: none;
}

#game-container {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 16px;
}

/* ── Side panels ── */
#side-left, #side-right { padding-top: 50px; }

.panel {
  background: rgba(255, 255, 255, 0.05);
  border-radius: 12px;
  padding: 10px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 8px 30px rgba(0, 0, 0, 0.35);
}

.panel.flash { animation: panel-flash 0.35s ease-out; }

.panel-label {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #9aa6c6;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.panel canvas {
  display: block;
  background: rgba(4, 7, 18, 0.55);
  border-radius: 8px;
}

/* ── Center ── */
#center { position: relative; }

#hud {
  display: flex;
  justify-content: space-between;
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.06);
  box-shadow: inset 1px 1px 0 rgba(255, 255, 255, 0.1), inset -1px 0 0 rgba(255, 255, 255, 0.1);
  border-radius: 12px 12px 0 0;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 1px;
}

.stat { display: inline-flex; align-items: baseline; gap: 6px; white-space: nowrap; }
.stat-label { font-size: 10px; font-weight: 700; letter-spacing: 1.5px; text-transform: uppercase; color: #8f9bbd; }
.stat-value { font-weight: 800; font-variant-numeric: tabular-nums; }
.stat-score .stat-value { color: #5ff3ff; text-shadow: 0 0 12px rgba(95, 243, 255, 0.55); }
.stat-level .stat-value { color: #ffd34d; text-shadow: 0 0 12px rgba(255, 211, 77, 0.5); }
.stat-lines .stat-value { color: #7cf9a6; text-shadow: 0 0 12px rgba(124, 249, 166, 0.5); }
.stat.bump .stat-value { display: inline-block; animation: stat-bump 0.35s ease-out; }

#gameCanvas {
  display: block;
  width: min(304px, max(124px, calc((100vh - var(--gp-header-h, 80px) - 56px) / 2 + 3px)));
  width: min(304px, max(124px, calc((100dvh - var(--gp-header-h, 80px) - 56px) / 2 + 3px)));
  height: auto;
  background: #070a16;
  border-radius: 0 0 12px 12px;
  border: 2px solid rgba(255, 255, 255, 0.1);
  border-top: none;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5), 0 0 60px hsla(var(--hue), 90%, 60%, 0.18);
  touch-action: none;
}

/* ── Overlay ── */
#overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background: rgba(6, 9, 22, 0.8);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-radius: 12px;
  z-index: 10;
  cursor: pointer;
}

#overlay.hidden { display: none; }
.hidden { display: none !important; }

#overlay h1 {
  font-size: 52px;
  letter-spacing: 12px;
  background: linear-gradient(90deg, #5ff3ff, #b18cff 50%, #ff6bff);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  filter: drop-shadow(0 0 18px rgba(177, 140, 255, 0.55));
  margin-bottom: 12px;
}

#overlay-sub { color: #aab4d0; font-size: 16px; margin-bottom: 20px; }

.how-to { max-width: 340px; text-align: left; margin: 16px 0; padding: 14px 18px; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.1); border-radius: 12px; font-size: 13px; line-height: 1.7; color: #c3cbe2; }
.how-to-title { font-size: 11px; font-weight: 700; letter-spacing: 2px; color: #8f9bbd; margin-bottom: 8px; text-transform: uppercase; }

#mode-selector { display: flex; gap: 10px; margin: 16px 0; }
.mode-btn { padding: 10px 20px; font-size: 14px; 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; letter-spacing: 1px; transition: all 0.2s; }
.mode-btn:hover { color: #dfe6fb; border-color: rgba(255, 255, 255, 0.35); }
.mode-btn.selected[data-mode="classic"] { color: #5ff3ff; border-color: #5ff3ff; background: rgba(95, 243, 255, 0.12); box-shadow: 0 0 18px rgba(95, 243, 255, 0.35); }
.mode-btn.selected[data-mode="arcade"] { color: #ff6bff; border-color: #ff6bff; background: rgba(255, 107, 255, 0.12); box-shadow: 0 0 18px rgba(255, 107, 255, 0.35); }
.mode-btn.selected[data-mode="sprint"] { color: #7cf9a6; border-color: #7cf9a6; background: rgba(124, 249, 166, 0.12); box-shadow: 0 0 18px rgba(124, 249, 166, 0.35); }

#highscores h2 { font-size: 18px; color: #ffd34d; margin-bottom: 8px; }

#score-list {
  list-style: none;
  padding: 0;
  text-align: center;
}

#score-list li { font-size: 14px; padding: 2px 0; color: #c3cbe2; }
#score-list li:first-child { color: #ffd34d; font-weight: 700; }
#score-list li:nth-child(2) { color: #c0c0c0; }
#score-list li:nth-child(3) { color: #cd7f32; }

/* ── Power-up Bar ── */
#powerup-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  min-height: 48px;
}

.pu-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 2px;
  color: #8f9bbd;
}

.pu-hint {
  font-size: 10px;
  color: #6c7699;
}

#pu-slots {
  display: flex;
  gap: 6px;
  flex: 1;
}

.pu-slot {
  width: 42px; height: 42px;
  border: 2px solid #333;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.5px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
  -webkit-tap-highlight-color: transparent;
}

.pu-slot:hover { transform: scale(1.1); }
.pu-slot:active { transform: scale(0.95); }

.pu-slot .pu-key {
  position: absolute;
  top: -6px; right: -4px;
  font-size: 9px;
  color: #666;
  background: #1a1a2e;
  padding: 0 3px;
  border-radius: 3px;
}

/* ── Color Picker ── */
#color-picker {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(8, 11, 26, 0.92);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 2px solid #ff6bff;
  box-shadow: 0 0 30px rgba(255, 107, 255, 0.35);
  border-radius: 14px;
  padding: 20px 24px;
  z-index: 30;
  text-align: center;
}

#color-picker p {
  font-size: 16px;
  margin-bottom: 14px;
  color: #ccc;
}

#color-options {
  display: flex;
  gap: 10px;
  justify-content: center;
}

.color-opt {
  width: 44px; height: 44px;
  border: 3px solid #444;
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.15s;
}

.color-opt:hover {
  transform: scale(1.2);
  border-color: #fff;
  box-shadow: 0 0 12px currentColor;
}

/* ── Screen flash for power-ups ── */
#flash-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  border-radius: 8px;
  z-index: 5;
  opacity: 0;
  transition: opacity 0.3s;
}

/* ── Touch Controls ── */
#touch-controls {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  width: 100%;
  max-width: 340px;
}

.touch-row {
  display: flex;
  gap: 8px;
  width: 100%;
  justify-content: center;
}

.t-btn {
  height: 56px;
  min-width: 70px;
  flex: 1;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 1px;
  border: 2px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  background: linear-gradient(180deg, rgba(255,255,255,0.09), rgba(255,255,255,0.03));
  color: #c3cbe2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.1s, border-color 0.1s, box-shadow 0.1s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.t-btn:active, .t-btn.pressed {
  background: rgba(95, 243, 255, 0.2);
  border-color: #5ff3ff;
  color: #5ff3ff;
  box-shadow: 0 0 16px rgba(95, 243, 255, 0.4);
}

.t-btn.arrow { font-size: 22px; max-width: 80px; }

.t-btn.accent {
  border-color: rgba(255, 107, 255, 0.6);
  color: #ff6bff;
}
.t-btn.accent:active, .t-btn.accent.pressed {
  background: rgba(255, 107, 255, 0.2);
  border-color: #ff6bff;
  color: #ff6bff;
  box-shadow: 0 0 16px rgba(255, 107, 255, 0.4);
}

.t-btn.drop {
  border-color: rgba(124, 249, 166, 0.6);
  color: #7cf9a6;
}
.t-btn.drop:active, .t-btn.drop.pressed {
  background: rgba(124, 249, 166, 0.2);
  border-color: #7cf9a6;
  color: #7cf9a6;
  box-shadow: 0 0 16px rgba(124, 249, 166, 0.4);
}

@keyframes bg-drift {
  from { background-position: 0% 0%, 100% 100%, 0 0; }
  to { background-position: 100% 60%, 0% 30%, 0 0; }
}

@keyframes panel-flash {
  from { box-shadow: inset 0 0 0 2px rgba(95, 243, 255, 0.9), 0 0 30px rgba(95, 243, 255, 0.6); }
  to { box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1), 0 8px 30px rgba(0, 0, 0, 0.35); }
}

@keyframes stat-bump {
  30% { transform: scale(1.25); }
  to { transform: scale(1); }
}

@media (prefers-reduced-motion: reduce) {
  body { animation: none; }
}

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

/* ── Touch device layout ── */
@media (pointer: coarse) {
  #touch-controls { display: flex; }
  body {
    align-items: flex-start;
    padding: 12px 12px 0;
    overflow-y: auto;
  }
  #game-container {
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;
    gap: 6px;
  }
  #touch-controls, #powerup-bar { flex-basis: 100%; }
  #touch-controls { max-width: 420px; }
}

/* ── Small phones ── */
@media (pointer: coarse) and (max-width: 699px) {
  #center { width: min-content; }
  #side-left, #side-right { padding-top: 46px; }
  .panel { padding: 6px; }
  .panel-label { font-size: 10px; letter-spacing: 1px; margin-bottom: 4px; }
  .panel canvas { width: 64px; height: auto; }
  #hud { flex-wrap: wrap; justify-content: center; gap: 0 10px; font-size: 12px; padding: 6px 8px; }
  .stat { gap: 4px; }
  .stat-label { font-size: 9px; letter-spacing: 1px; }
  #gameCanvas {
    width: min(304px, calc(100vw - 188px), max(124px, calc((100vh - var(--gp-header-h, 48px) - 138px) / 2 + 3px)));
    width: min(304px, calc(100vw - 188px), max(124px, calc((100dvh - var(--gp-header-h, 48px) - 138px) / 2 + 3px)));
  }
  #touch-controls { flex-direction: row; gap: 6px; padding: 6px 0 10px; }
  .touch-row { display: contents; }
  .t-btn, .t-btn.arrow { flex: 1 1 0; min-width: 0; max-width: none; height: 52px; font-size: 12px; letter-spacing: 0; }
  .t-btn.arrow { font-size: 18px; }
  .t-btn[data-action="left"] { order: 1; }
  .t-btn[data-action="down"] { order: 2; }
  .t-btn[data-action="right"] { order: 3; }
  .t-btn[data-action="hold"] { order: 4; }
  .t-btn[data-action="rotate"] { order: 5; }
  .t-btn[data-action="drop"] { order: 6; }
}

/* ── iPad / tablets ── */
@media (pointer: coarse) and (min-width: 700px) {
  #game-container { gap: 16px; }
  #side-left, #side-right { padding-top: 50px; }
  #touch-controls { max-width: 400px; }
  .t-btn { height: 64px; font-size: 16px; }
  .t-btn.arrow { font-size: 26px; max-width: 90px; }
  #gameCanvas {
    width: min(404px, max(124px, calc((100vh - var(--gp-header-h, 80px) - 250px) / 2 + 3px)));
    width: min(404px, max(124px, calc((100dvh - var(--gp-header-h, 80px) - 250px) / 2 + 3px)));
  }
}

@media (pointer: coarse) and (min-width: 700px) and (orientation: landscape) and (min-height: 501px) {
  #touch-controls { flex-basis: auto; width: 340px; align-self: center; }
  #gameCanvas {
    width: min(404px, max(124px, calc((100vh - var(--gp-header-h, 80px) - 72px) / 2 + 3px)));
    width: min(404px, max(124px, calc((100dvh - var(--gp-header-h, 80px) - 72px) / 2 + 3px)));
  }
}

@media (pointer: coarse) and (max-height: 500px) {
  body { padding: 4px 8px 0; }
  #side-left, #side-right { padding-top: 40px; }
  .panel { padding: 6px; }
  .panel-label { font-size: 10px; letter-spacing: 1px; margin-bottom: 4px; }
  .panel canvas { width: 64px; height: auto; }
  #center { width: min-content; }
  #hud { flex-wrap: wrap; justify-content: center; gap: 0 8px; font-size: 11px; padding: 4px 6px; }
  .stat { gap: 4px; }
  .stat-label { font-size: 9px; letter-spacing: 1px; }
  #gameCanvas {
    width: min(304px, max(100px, calc((100vh - var(--gp-header-h, 48px) - 48px) / 2 + 3px)));
    width: min(304px, max(100px, calc((100dvh - var(--gp-header-h, 48px) - 48px) / 2 + 3px)));
  }
  #touch-controls {
    position: fixed;
    left: 0;
    right: 0;
    top: calc(50% + var(--gp-header-h, 48px) / 2);
    transform: translateY(-50%);
    flex-direction: row;
    max-width: none;
    padding: 0 12px;
    gap: 8px;
    pointer-events: none;
    z-index: 50;
  }
  .touch-row { display: contents; }
  .t-btn, .t-btn.arrow { pointer-events: auto; flex: 0 0 auto; width: 58px; min-width: 0; max-width: none; height: 54px; font-size: 11px; letter-spacing: 0; }
  .t-btn.arrow { font-size: 18px; }
  .t-btn[data-action="left"] { order: 1; }
  .t-btn[data-action="down"] { order: 2; }
  .t-btn[data-action="right"] { order: 3; margin-right: auto; }
  .t-btn[data-action="hold"] { order: 4; }
  .t-btn[data-action="rotate"] { order: 5; }
  .t-btn[data-action="drop"] { order: 6; }
}

@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; width: auto; height: auto; overflow-y: auto; justify-content: safe center; }
  #overlay h1 { font-size: 40px; letter-spacing: 8px; }
}

@media (orientation: landscape) and (max-height: 500px) {
  #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)); }
  #overlay:not(.hidden) > * { grid-column: 2; }
  #overlay:not(.hidden) > div:not([id]) { grid-column: 1; grid-row: 1 / span 6; margin: 0; max-width: 340px; width: 100%; }
  #overlay h1 { font-size: 34px; }
}

[data-theme="light"] body { background: var(--gp-page-grad) fixed; animation: none; color: var(--gp-ink); }
[data-theme="light"] .panel, [data-theme="light"] #hud, [data-theme="light"] #powerup-bar { background: var(--gp-surface); box-shadow: inset 0 0 0 1px var(--gp-line), var(--gp-shadow); }
[data-theme="light"] .panel-label, [data-theme="light"] .stat-label, [data-theme="light"] .pu-label, [data-theme="light"] .how-to-title { color: var(--gp-ink-3); }
[data-theme="light"] .stat-score .stat-value { color: #0a84b8; text-shadow: none; }
[data-theme="light"] .stat-level .stat-value { color: #b7791f; text-shadow: none; }
[data-theme="light"] .stat-lines .stat-value { color: #15803d; text-shadow: none; }
[data-theme="light"] #overlay { background: var(--gp-overlay); }
[data-theme="light"] #overlay h1 { filter: none; }
[data-theme="light"] #overlay-sub { 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"] .mode-btn { color: var(--gp-ink-2); border-color: var(--gp-line); background: var(--gp-surface); }
[data-theme="light"] .mode-btn:hover { color: var(--gp-ink); }
[data-theme="light"] .mode-btn.selected[data-mode="classic"] { color: #0a84b8; border-color: #0a84b8; background: #e0f2fe; box-shadow: none; }
[data-theme="light"] .mode-btn.selected[data-mode="arcade"] { color: #9333ea; border-color: #9333ea; background: #f3e8ff; box-shadow: none; }
[data-theme="light"] .mode-btn.selected[data-mode="sprint"] { color: #15803d; border-color: #15803d; background: #dcfce7; box-shadow: none; }
[data-theme="light"] #highscores h2, [data-theme="light"] #score-list li:first-child { color: #b7791f; }
[data-theme="light"] #score-list li { color: var(--gp-ink-2); }
[data-theme="light"] .pu-hint { color: var(--gp-ink-3); }
[data-theme="light"] .pu-slot .pu-key { background: var(--gp-surface); color: var(--gp-ink-3); }
[data-theme="light"] #color-picker { background: rgba(255, 255, 255, 0.96); }
[data-theme="light"] #color-picker p { color: var(--gp-ink-2); }
[data-theme="light"] .t-btn { background: var(--gp-surface); color: var(--gp-ink-2); border-color: var(--gp-line); box-shadow: 0 3px 10px rgba(31, 27, 69, 0.08); }
[data-theme="light"] .t-btn.accent { color: #9333ea; border-color: rgba(147, 51, 234, 0.4); }
[data-theme="light"] .t-btn.drop { color: #15803d; border-color: rgba(21, 128, 61, 0.4); }
[data-theme="light"] .t-btn:active, [data-theme="light"] .t-btn.pressed { background: #e0f2fe; color: #0a84b8; }
[data-theme="light"] html { background: var(--gp-page); }
[data-theme="light"] #overlay h1 { background: linear-gradient(90deg, #0891b2, #7c3aed 50%, #db2777); -webkit-background-clip: text; background-clip: text; }
