:root {
  --bg-top: #1a0533;
  --bg-bot: #0d0020;
  --panel: #2a1045;
  --border: rgba(255,255,255,0.12);
  --text: #f0e6ff;
  --accent: #f97316;
  --accent2: #a855f7;
  --good: #22c55e;
  --danger: #ef4444;
  --hud-bg: rgba(255,255,255,0.07);
  --radius: 18px;
  --shadow: 0 8px 32px rgba(0,0,0,0.5);
}

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

body {
  min-height: 100vh;
  font-family: 'Nunito', system-ui, sans-serif;
  background: linear-gradient(160deg, var(--bg-top) 0%, var(--bg-bot) 100%);
  color: var(--text);
  overflow-x: hidden;
}

/* ─── App Shell ─────────────────────────────────────── */
.app-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  max-width: 600px;
  margin: 0 auto;
  padding: 14px 14px 6px;
  gap: 10px;
}

/* ─── Header ─────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255,255,255,0.05);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
}

.title {
  font-family: 'Fredoka One', cursive;
  font-size: 1.35rem;
  background: linear-gradient(90deg, #f97316, #f472b6, #a855f7);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  white-space: nowrap;
  flex-shrink: 0;
}

.hud {
  display: flex;
  gap: 6px;
  flex: 1;
  justify-content: center;
  flex-wrap: wrap;
}

.hud-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  background: var(--hud-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 5px 10px;
  min-width: 52px;
}

.hud-label {
  font-size: 0.58rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #9ca3af;
  text-transform: uppercase;
}

.hud-val {
  font-family: 'Fredoka One', cursive;
  font-size: 1.1rem;
  line-height: 1.1;
  color: #fff;
}

.hud-target .hud-val { color: #facc15; }
.hud-moves .hud-val { color: #4ade80; }

.header-controls {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(255,255,255,0.08);
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, transform 0.15s;
  color: #fff;
  padding: 0;
}
.icon-btn:hover { background: rgba(255,255,255,0.16); transform: scale(1.08); }

/* ─── Progress Bar ───────────────────────────────────── */
.progress-bar-wrap {
  height: 8px;
  background: rgba(255,255,255,0.08);
  border-radius: 99px;
  overflow: hidden;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #a855f7, #f97316);
  border-radius: 99px;
  transition: width 0.4s ease;
}

/* ─── Board ──────────────────────────────────────────── */
main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.board-wrap {
  width: 100%;
  max-width: 520px;
  background: linear-gradient(180deg, #1e0a3c 0%, #0f0022 100%);
  border-radius: 24px;
  border: 2px solid rgba(168,85,247,0.3);
  box-shadow: 0 0 40px rgba(168,85,247,0.2), var(--shadow);
  padding: 10px;
  position: relative;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 16px;
  touch-action: none;
  cursor: pointer;
}

/* ─── Controls ───────────────────────────────────────── */
.controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.ctrl-btn {
  border: none;
  border-radius: 14px;
  padding: 11px 20px;
  font-family: 'Nunito', sans-serif;
  font-weight: 800;
  font-size: 0.95rem;
  cursor: pointer;
  color: #fff;
  background: linear-gradient(135deg, #f97316, #ea580c);
  box-shadow: 0 4px 15px rgba(249,115,22,0.4);
  transition: transform 0.15s, filter 0.15s;
  white-space: nowrap;
}
.ctrl-btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.ctrl-btn:active { transform: translateY(0); }

.best-score {
  margin-left: auto;
  padding: 8px 14px;
  background: rgba(250,204,21,0.12);
  border: 1px solid rgba(250,204,21,0.4);
  border-radius: 12px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #facc15;
  white-space: nowrap;
}

/* ─── Footer ─────────────────────────────────────────── */
footer {
  text-align: center;
  padding-bottom: 8px;
}

.status-text {
  font-size: 0.9rem;
  font-weight: 600;
  color: #c4b5fd;
  margin-bottom: 8px;
}

.legend {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: #9ca3af;
}

.leg-item {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 8px;
  padding: 3px 8px;
}

/* ─── Overlays ───────────────────────────────────────── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: none;
  place-items: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}
.overlay.active { display: grid; }

.overlay-box {
  background: linear-gradient(135deg, #4c1d95, #1e0a3c);
  border: 2px solid rgba(168,85,247,0.5);
  border-radius: 28px;
  padding: 40px 36px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  animation: popIn 0.35s cubic-bezier(0.34,1.56,0.64,1);
  max-width: 340px;
  width: 90%;
}

.over-fail {
  background: linear-gradient(135deg, #7f1d1d, #1a0533);
  border-color: rgba(239,68,68,0.5);
}

.overlay-emoji { font-size: 3rem; margin-bottom: 10px; }
.overlay-title {
  font-family: 'Fredoka One', cursive;
  font-size: 2rem;
  color: #fff;
  margin-bottom: 6px;
}
.overlay-sub { font-size: 1.05rem; color: rgba(255,255,255,0.8); }

@keyframes popIn {
  from { transform: scale(0.7); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

/* ─── Settings Modal ─────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.8);
  display: none;
  place-items: center;
  z-index: 2000;
  backdrop-filter: blur(4px);
}
.modal-backdrop.active { display: grid; }

.modal-box {
  background: linear-gradient(160deg, #2a1045, #12003a);
  border: 1px solid rgba(168,85,247,0.35);
  border-radius: 24px;
  padding: 28px;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.7);
  animation: popIn 0.3s ease;
}

.modal-title {
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  margin-bottom: 20px;
  color: #e9d5ff;
}

.modal-section { margin-bottom: 18px; }
.modal-label {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #9ca3af;
  margin-bottom: 8px;
}

.diff-row { display: flex; gap: 8px; }
.diff-btn {
  flex: 1;
  padding: 9px 12px;
  border: 2px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  background: rgba(255,255,255,0.06);
  color: #e2e8f0;
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.2s;
}
.diff-btn:hover { background: rgba(255,255,255,0.12); transform: translateY(-2px); }
.diff-btn.active {
  background: linear-gradient(135deg, #a855f7, #7c3aed);
  border-color: #a855f7;
  color: #fff;
  box-shadow: 0 4px 15px rgba(168,85,247,0.4);
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-weight: 600;
  color: #e2e8f0;
  font-size: 0.95rem;
}
.toggle-row input { width: 18px; height: 18px; cursor: pointer; }

.score-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 10px;
  background: rgba(255,255,255,0.04);
  border-radius: 8px;
  margin-bottom: 5px;
  font-size: 0.88rem;
}
.score-diff { font-weight: 800; color: #a855f7; }
.score-val  { font-family: 'Fredoka One', cursive; color: #facc15; }

/* ─── Light Theme ────────────────────────────────────── */
body.light {
  --bg-top: #f0e6ff;
  --bg-bot: #e0ccff;
  --text: #1a0533;
  background: linear-gradient(160deg, #f0e6ff 0%, #d8b4fe 100%);
}
body.light header,
body.light .board-wrap { background: rgba(255,255,255,0.7); }
body.light .hud-item { background: rgba(255,255,255,0.5); }
body.light .title { background: linear-gradient(90deg, #ea580c, #c026d3, #7c3aed); -webkit-background-clip:text; background-clip:text; }
body.light .hud-val { color: #1a0533; }
body.light .status-text { color: #6b21a8; }
body.light .leg-item { color: #374151; }

/* ─── Responsive ─────────────────────────────────────── */
@media (max-width: 480px) {
  .app-shell { padding: 10px 10px 4px; gap: 8px; }
  header { padding: 8px 10px; }
  .title { font-size: 1.1rem; }
  .hud-item { min-width: 44px; padding: 4px 7px; }
  .hud-val { font-size: 0.95rem; }
  .ctrl-btn { padding: 9px 14px; font-size: 0.85rem; }
}
