/* =====================================================================
   Slowpapa Game Shell — shared chrome & theme for every game.
   Each game links this file and only adds a small inline <style> for
   its own board. Keeps the whole site visually consistent.
   ===================================================================== */

:root {
  --bg-1: #0f1020;
  --bg-2: #1b1340;
  --surface: rgba(255, 255, 255, 0.06);
  --surface-2: rgba(255, 255, 255, 0.10);
  --border: rgba(255, 255, 255, 0.12);
  --text: #f4f3ff;
  --text-dim: #b9b6d8;
  --text-mute: #8a86ad;
  --accent: #8b5cf6;
  --accent-2: #ec4899;
  --accent-3: #38bdf8;
  --good: #34d399;
  --bad: #f87171;
  --warn: #fbbf24;
  --grad: linear-gradient(135deg, var(--accent) 0%, var(--accent-2) 100%);
  --grad-soft: linear-gradient(135deg, rgba(139,92,246,.18), rgba(236,72,153,.18));
  --shadow: 0 12px 30px -8px rgba(0, 0, 0, .55);
  --shadow-soft: 0 6px 20px -10px rgba(0, 0, 0, .5);
  --radius: 16px;
  --radius-sm: 10px;
  --tap: 44px;       /* min touch target */
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

:root[data-theme="light"] {
  --bg-1: #f6f4ff;
  --bg-2: #ece8ff;
  --surface: rgba(255, 255, 255, .75);
  --surface-2: rgba(255, 255, 255, .9);
  --border: rgba(80, 60, 160, .14);
  --text: #1c1635;
  --text-dim: #56507a;
  --text-mute: #8b85a8;
  --shadow: 0 12px 30px -10px rgba(90, 70, 160, .25);
  --shadow-soft: 0 6px 18px -10px rgba(90, 70, 160, .25);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color: var(--text);
  background: radial-gradient(120% 100% at 80% -10%, var(--bg-2) 0%, var(--bg-1) 55%) fixed;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}

/* ---------- Shell layout ---------- */
.game-shell {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.game-topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px));
  background: var(--surface);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.game-topbar .back {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 20px;
  text-decoration: none;
  transition: transform .15s ease, background .2s ease;
}
.game-topbar .back:active { transform: scale(.92); }
.game-topbar .title {
  font-weight: 800;
  font-size: 17px;
  letter-spacing: .3px;
  margin: 0;
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.game-topbar .title small {
  display: block;
  font-weight: 500;
  font-size: 11px;
  color: var(--text-mute);
  letter-spacing: 0;
}
.game-topbar .stats {
  display: flex;
  gap: 8px;
  align-items: center;
}
.stat {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.1;
}
.stat .k { font-size: 10px; color: var(--text-mute); text-transform: uppercase; letter-spacing: .06em; }
.stat .v { font-size: 15px; font-weight: 800; font-variant-numeric: tabular-nums; }
.stat .v.accent { color: var(--accent-2); }

.game-topbar .icon-btn {
  display: inline-grid;
  place-items: center;
  width: var(--tap);
  height: var(--tap);
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 18px;
  cursor: pointer;
  transition: transform .15s ease, background .2s ease;
}
.game-topbar .icon-btn:active { transform: scale(.92); }

/* ---------- Stage / board ---------- */
.game-stage {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
}
.game-board {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  width: min(94vw, 460px);
}
.game-board canvas { display: block; width: 100%; height: auto; touch-action: none; }

/* ---------- Buttons & chips ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: var(--tap);
  padding: 0 20px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  transition: transform .14s ease, background .2s ease, box-shadow .2s ease;
  user-select: none;
}
.btn:hover { background: var(--surface); }
.btn:active { transform: scale(.96); }
.btn.primary { background: var(--grad); border: none; color: #fff; box-shadow: var(--shadow-soft); }
.btn.ghost { background: transparent; }
.btn.block { width: 100%; }
.btn.sm { height: 36px; padding: 0 14px; font-size: 13px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 28px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--text-dim);
}

/* ---------- On-screen touch controls ---------- */
.touch-pad {
  display: grid;
  gap: 8px;
  width: min(72vw, 240px);
  margin: 14px auto 0;
  user-select: none;
}
.touch-pad.dir {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  aspect-ratio: 3 / 2;
}
.touch-pad .pad-btn {
  display: grid;
  place-items: center;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  transition: transform .1s ease, background .2s ease;
  touch-action: manipulation;
}
.touch-pad .pad-btn:active { transform: scale(.9); background: var(--grad-soft); }
.touch-pad .pad-btn.up    { grid-area: 1 / 2; }
.touch-pad .pad-btn.left  { grid-area: 2 / 1; }
.touch-pad .pad-btn.right { grid-area: 2 / 3; }
.touch-pad .pad-btn.down  { grid-area: 3 / 2; }
.touch-pad .pad-blank { grid-area: 2 / 2; }

.action-row {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 14px;
}

/* ---------- Modal / overlay ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(8, 6, 20, .6);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
}
.overlay.show { opacity: 1; pointer-events: auto; }
.dialog {
  width: min(92vw, 380px);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 22px calc(22px + var(--safe-bottom));
  text-align: center;
  transform: translateY(10px) scale(.98);
  transition: transform .22s ease;
}
.overlay.show .dialog { transform: none; }
.dialog h2 { margin: 0 0 6px; font-size: 22px; }
.dialog p { margin: 0 0 18px; color: var(--text-dim); font-size: 14px; line-height: 1.5; }
.dialog .big-score { font-size: 40px; font-weight: 900; background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.dialog .actions { display: flex; gap: 10px; }
.dialog .actions .btn { flex: 1; }

/* small helper text */
.hint { text-align: center; color: var(--text-mute); font-size: 12px; margin-top: 12px; }

/* segmented control (difficulty etc.) */
.segment {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.segment button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  cursor: pointer;
  transition: background .2s ease, color .2s ease;
}
.segment button[aria-pressed="true"] {
  background: var(--grad);
  color: #fff;
}

/* keyboard hint for desktop */
.kbd {
  display: inline-block;
  min-width: 22px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 6px;
}

@media (max-width: 560px) {
  .game-board { width: 94vw; padding: 10px; }
  .game-topbar .title { font-size: 15px; }
}

/* respect reduced motion */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}