/* ============ Pocket Games — shared styles ============ */
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg1: #2b1e66;
  --bg2: #5b4cdb;
  --card: rgba(255, 255, 255, 0.10);
  --card-border: rgba(255, 255, 255, 0.18);
  --text: #ffffff;
  --text-dim: rgba(255, 255, 255, 0.72);
  --accent: #ffd166;
  --pop: #ff6b9d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(160deg, var(--bg1) 0%, var(--bg2) 100%) fixed;
  color: var(--text);
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  overscroll-behavior: none;
}

button {
  font-family: inherit;
  border: none;
  cursor: pointer;
  color: inherit;
  background: none;
}

/* ============ Hub ============ */
.hub {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  padding: calc(var(--safe-top) + 16px) 16px calc(var(--safe-bottom) + 16px);
  max-width: 520px;
  margin: 0 auto;
}

.hub-header { text-align: center; margin-bottom: 10px; }
.hub-header h1 {
  margin: 8px 0 2px;
  font-size: 2rem;
  letter-spacing: 0.5px;
  text-shadow: 0 3px 12px rgba(0,0,0,0.35);
}
.tagline { margin: 0 0 6px; color: var(--text-dim); font-size: 0.95rem; }

.player-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 4px 0 14px;
}
.player-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
  backdrop-filter: blur(6px);
}
.player-chip .avatar { font-size: 1.3rem; }
.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--card-border);
  font-size: 1.25rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { transform: scale(0.92); }

.game-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  flex: 1;
  align-content: start;
}

.game-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  border-radius: 22px;
  padding: 22px 10px 18px;
  text-decoration: none;
  color: #fff;
  text-align: center;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25), inset 0 1px 0 rgba(255,255,255,0.25);
  transition: transform 0.12s ease;
  position: relative;
  overflow: hidden;
}
.game-card:active { transform: scale(0.96); }
.card-emoji { font-size: 2.6rem; filter: drop-shadow(0 3px 4px rgba(0,0,0,0.3)); }
.card-title { font-size: 1.15rem; font-weight: 800; }
.card-sub { font-size: 0.78rem; opacity: 0.85; }
.card-best { font-size: 0.75rem; margin-top: 4px; background: rgba(0,0,0,0.22); border-radius: 999px; padding: 3px 10px; }

.card-blocks  { background: linear-gradient(145deg, #ff6b6b, #d63a5f); }
.card-bubbles { background: linear-gradient(145deg, #4facfe, #0b6fd8); }
.card-memory  { background: linear-gradient(145deg, #43e97b, #1a9e57); }
.card-snake   { background: linear-gradient(145deg, #fa9600, #d95b00); }
.card-colorsort { background: linear-gradient(145deg, #c471f5, #8e2de2); }
.card-flappy  { background: linear-gradient(145deg, #ffd166, #e8930c); }
.card-skyace  { background: linear-gradient(145deg, #4facfe, #0d47a1); }
.card-lemmings { background: linear-gradient(145deg, #26c6da, #00838f); }
.card-toppler { background: linear-gradient(145deg, #8bc34a, #33691e); }
.card-sparkquest { background: linear-gradient(145deg, #ffb347, #d84315); }
.card-chess    { background: linear-gradient(145deg, #808fa6, #3f4c63); }
.card-checkers { background: linear-gradient(145deg, #e0566b, #8f1d3d); }
.card-solitaire { background: linear-gradient(145deg, #2e9e63, #14603c); }
.card-connect4 { background: linear-gradient(145deg, #5468ff, #2c39a2); }
.card-tictactoe { background: linear-gradient(145deg, #ff6b9d, #c2255c); }
.card-war      { background: linear-gradient(145deg, #38ada9, #1e5f74); }
.card-quickmath { background: linear-gradient(145deg, #f77f00, #c1440e); }
.card-tables    { background: linear-gradient(145deg, #2dd4bf, #0f766e); }
.card-target    { background: linear-gradient(145deg, #f87171, #b91c1c); }
.card-mathinvaders { background: linear-gradient(145deg, #a78bfa, #4c1d95); }
.card-scramble  { background: linear-gradient(145deg, #fb7185, #be185d); }
.card-wordguess { background: linear-gradient(145deg, #4ade80, #166534); }
.card-balloonword { background: linear-gradient(145deg, #38bdf8, #0369a1); }
.card-wordsearch { background: linear-gradient(145deg, #a3e635, #3f6212); }
.card-minesweeper { background: linear-gradient(145deg, #94a3b8, #1e293b); }
.card-minigolf { background: linear-gradient(145deg, #34d399, #065f46); }
.card-circuits { background: linear-gradient(145deg, #38bdf8, #f59e0b); }
.card-empire { background: linear-gradient(145deg, #c9a227, #7a4a21); }

.hub-footer {
  text-align: center;
  color: var(--text-dim);
  font-size: 0.82rem;
  margin-top: 18px;
  min-height: 1.2em;
}

/* ============ Game page chrome ============ */
.game-page {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  height: var(--app-height, 100dvh);
  padding: calc(var(--safe-top) + 8px) 10px calc(var(--safe-bottom) + 8px);
  max-width: 560px;
  margin: 0 auto;
  overflow: hidden;
}

.game-topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}
.game-topbar .title {
  flex: 1;
  text-align: center;
  font-weight: 800;
  font-size: 1.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Crowded topbar (5+ items, e.g. help + pause + music + sound): compact
   buttons so the title keeps room on narrow phones. */
.game-topbar:has(> :nth-child(5)) { gap: 6px; }
.game-topbar:has(> :nth-child(5)) .icon-btn {
  width: 40px;
  height: 40px;
  font-size: 1.15rem;
}
.game-topbar:has(> :nth-child(5)) .title { font-size: 1rem; }

.hud {
  display: flex;
  justify-content: center;
  gap: 10px;
  margin-bottom: 6px;
  flex-wrap: wrap;
}
.hud .stat {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 12px;
  padding: 5px 12px;
  font-size: 0.85rem;
  font-weight: 700;
}
.hud .stat small { display: block; font-weight: 400; font-size: 0.68rem; color: var(--text-dim); }

/* ============ Overlay / modal ============ */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 12, 60, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
  backdrop-filter: blur(4px);
}
.overlay.hidden { display: none; }
.panel {
  background: linear-gradient(160deg, #3d2f8f, #2b1e66);
  border: 1px solid var(--card-border);
  border-radius: 24px;
  padding: 26px 22px;
  width: 100%;
  max-width: 340px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.panel h2 { margin: 0 0 6px; font-size: 1.5rem; }
.panel.help-panel {
  max-height: calc(var(--app-height, 100dvh) - 40px);
  overflow-y: auto;
}
.help-rows {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  margin: 12px 0 16px;
}
.help-row { display: flex; align-items: center; gap: 12px; }
.help-ico { flex: none; width: 2.1rem; text-align: center; font-size: 1.45rem; }
.help-txt { font-size: 0.92rem; line-height: 1.35; }
.panel p { margin: 4px 0 14px; color: var(--text-dim); }
.panel .big-emoji { font-size: 3rem; display: block; margin-bottom: 6px; }

.btn {
  display: inline-block;
  border-radius: 999px;
  padding: 13px 26px;
  font-size: 1.05rem;
  font-weight: 800;
  margin: 5px 4px;
  min-width: 120px;
  box-shadow: 0 5px 14px rgba(0,0,0,0.3);
}
.btn:active { transform: scale(0.95); }
.btn-primary { background: linear-gradient(145deg, #ffd166, #ff9f43); color: #4a2c00; }
.btn-secondary { background: var(--card); border: 1px solid var(--card-border); color: var(--text); }

.diff-row { display: flex; gap: 8px; justify-content: center; margin: 10px 0 4px; }
.diff-btn {
  flex: 1;
  max-width: 140px;
  border-radius: 16px;
  padding: 12px 4px;
  font-weight: 800;
  font-size: 0.95rem;
  background: var(--card);
  border: 2px solid var(--card-border);
  color: var(--text);
}
.diff-btn.selected { border-color: var(--accent); background: rgba(255, 209, 102, 0.18); }
.diff-btn small { display: block; font-weight: 400; font-size: 0.72rem; color: var(--text-dim); margin-top: 3px; }

/* ============ Profile picker ============ */
.profile-list { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin: 12px 0; }
.profile-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 2px solid var(--card-border);
  border-radius: 18px;
  padding: 12px 14px;
  min-width: 84px;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
}
.profile-item .avatar { font-size: 2rem; }
.profile-item.selected { border-color: var(--accent); background: rgba(255, 209, 102, 0.18); }
.avatar-grid { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 10px 0; }
.avatar-choice {
  font-size: 1.7rem;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--card);
  border: 2px solid var(--card-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.avatar-choice.selected { border-color: var(--accent); background: rgba(255, 209, 102, 0.2); }
.name-input {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--card-border);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  font-size: 1.1rem;
  padding: 12px 14px;
  text-align: center;
  font-family: inherit;
  outline: none;
}

/* ============ Touch controls ============ */
.controls-row {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 8px 0 2px;
}
.ctl-btn {
  width: 64px;
  height: 64px;
  border-radius: 20px;
  background: var(--card);
  border: 1px solid var(--card-border);
  font-size: 1.7rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  box-shadow: 0 4px 10px rgba(0,0,0,0.25);
}
.ctl-btn:active { transform: scale(0.9); background: rgba(255,255,255,0.22); }

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 60px);
  grid-template-rows: repeat(2, 60px);
  gap: 8px;
  justify-content: center;
  padding: 8px 0 2px;
}
.dpad .ctl-btn { width: 60px; height: 60px; }
.dpad .up    { grid-column: 2; grid-row: 1; }
.dpad .left  { grid-column: 1; grid-row: 2; }
.dpad .down  { grid-column: 2; grid-row: 2; }
.dpad .right { grid-column: 3; grid-row: 2; }

/* canvas container */
.canvas-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  position: relative;
}
canvas.game-canvas {
  border-radius: 16px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.35);
  background: rgba(10, 6, 40, 0.55);
  max-width: 100%;
  max-height: 100%;
  touch-action: none;
}

/* ============ Lemming Rescue ============ */
.skill-bar {
  display: flex;
  justify-content: center;
  gap: 6px;
  padding: 6px 0 2px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.skill-btn {
  position: relative;
  flex: 0 0 auto;
  width: 48px;
  height: 54px;
  border-radius: 14px;
  background: var(--card);
  border: 2px solid var(--card-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.skill-btn .sk-emoji { font-size: 1.4rem; }
.skill-btn .sk-count {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--accent);
  color: #4a2c00;
  font-size: 0.72rem;
  font-weight: 900;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}
.skill-btn.selected { border-color: var(--accent); background: rgba(255, 209, 102, 0.25); }
.skill-btn.empty { opacity: 0.35; }
.skill-btn.empty .sk-count { background: rgba(255,255,255,0.35); }
.skill-btn:active { transform: scale(0.92); }

.lem-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  padding: 4px 0 2px;
}
.lem-ctl {
  width: 46px;
  height: 44px;
  border-radius: 12px;
  background: var(--card);
  border: 1px solid var(--card-border);
  font-size: 1.15rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
}
.lem-ctl:active { transform: scale(0.92); }
.lem-ctl.active { border-color: var(--accent); background: rgba(255, 209, 102, 0.25); }
.lem-ctl.armed { border-color: #ff6b6b; background: rgba(255, 107, 107, 0.3); }

/* translucent pause banner — canvas stays visible and tappable */
.pause-banner {
  position: absolute;
  left: 50%;
  top: 12px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20, 12, 60, 0.92);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 8px 12px;
  font-size: 0.85rem;
  font-weight: 700;
  z-index: 30;
  max-width: 94%;
  flex-wrap: wrap;
  justify-content: center;
}
.pause-banner.hidden { display: none; }
.pause-banner .btn { padding: 8px 14px; min-width: 0; font-size: 0.85rem; margin: 0; }

.tier-badge {
  display: inline-block;
  background: rgba(0,0,0,0.25);
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 0.78rem;
  font-weight: 700;
}
.lvl-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}
.lvl-arrow {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--card-border);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text);
  flex-shrink: 0;
}
.lvl-arrow:active { transform: scale(0.9); }
.intro-star { min-height: 1.1em; color: var(--accent); font-weight: 800; font-size: 0.85rem; }
.skill-preview {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin: 8px 0 2px;
}
.skill-chip {
  background: rgba(0,0,0,0.25);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 0.85rem;
  font-weight: 700;
}

/* ============ Playing cards (js/cards.js — War, Solitaire) ============ */
.pcard {
  position: relative;
  width: var(--card-w, 70px);
  aspect-ratio: 5 / 7;
  border-radius: calc(var(--card-w, 70px) * 0.1);
  background: #fdfdf6;
  box-shadow: 0 2px 6px rgba(0,0,0,0.35);
  color: #1d2733;
  flex-shrink: 0;
}
.pcard.red { color: #d21f3c; }
.pcard .pc-corner {
  position: absolute;
  top: 3%;
  left: 6%;
  font-size: calc(var(--card-w, 70px) * 0.17);
  font-weight: 800;
  line-height: 1.05;
  text-align: center;
}
.pcard .pc-corner.br {
  top: auto;
  left: auto;
  bottom: 3%;
  right: 6%;
  transform: rotate(180deg);
}
.pcard .pc-center {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w, 70px) * 0.5);
}
.pcard .pc-plate {
  width: 58%;
  aspect-ratio: 1;
  border-radius: 50%;
  background: rgba(91, 76, 219, 0.14);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--card-w, 70px) * 0.34);
  font-weight: 900;
}
.pcard.down {
  background: repeating-linear-gradient(45deg, #5b4cdb 0 7px, #483bb8 7px 14px);
  border: calc(var(--card-w, 70px) * 0.05) solid #fdfdf6;
}

#confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
}

/* ============ Toasts ============ */
#pg-toasts {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(var(--safe-bottom) + 14px);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(20, 12, 60, 0.95);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 12px 14px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toast-in 0.25s ease;
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}
.toast span { flex: 1; }
.toast-out { opacity: 0; transform: translateY(10px); transition: all 0.25s ease; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
.toast-btn {
  background: linear-gradient(145deg, #ffd166, #ff9f43);
  color: #4a2c00;
  font-weight: 800;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 0.85rem;
  flex-shrink: 0;
}
.toast-x {
  color: var(--text-dim);
  font-size: 0.85rem;
  padding: 4px 6px;
  flex-shrink: 0;
}

/* ============ Stats page ============ */
.stats-page {
  max-width: 520px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 24px);
}
.stats-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.stats-header h1 {
  flex: 1;
  font-size: 1.25rem;
  margin: 0;
  text-align: center;
}
.stats-player {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 16px;
  font-size: 1.1rem;
  font-weight: 800;
}
.stats-player .avatar { font-size: 2.2rem; }
.stats-summary {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 16px;
}
.summary-tile {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 16px;
  padding: 12px 6px;
  text-align: center;
}
.summary-tile .num { font-size: 1.35rem; font-weight: 900; display: block; }
.summary-tile .lbl { font-size: 0.7rem; color: var(--text-dim); }
.stat-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: 18px;
  padding: 14px 16px;
  margin-bottom: 12px;
}
.stat-card h3 {
  margin: 0 0 8px;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.stat-rows {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
}
.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  border-bottom: 1px dashed rgba(255,255,255,0.12);
  padding: 3px 0;
}
.stat-row .lbl { color: var(--text-dim); }
.stat-row .val { font-weight: 800; }
.stats-actions { text-align: center; margin-top: 18px; }
