:root {
  --bg: #faf8ef;
  --bg-grad: radial-gradient(circle at 20% 0%, #fff8e7 0%, transparent 50%),
             radial-gradient(circle at 80% 100%, #f0e8da 0%, transparent 50%),
             #faf8ef;
  --text: #6b6259;
  --text-strong: #44403c;
  --text-muted: #948781;
  --surface: #ffffff;
  --surface-hover: #faf6ed;
  --board-bg: #bbada0;
  --cell-bg: #cdc1b4;
  --btn-bg: #8f7a66;
  --btn-bg-hover: #76624f;
  --btn-disabled: #c4b8a8;
  --select-bg: #f3ebe1;
  --score-label: #eee4da;
  --overlay-bg: rgba(238, 228, 218, 0.86);
  --accent: #edc22e;
  --accent-soft: #f5d758;
  --danger: #f65e3b;
  --border: rgba(119, 110, 101, 0.12);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.03);
  --shadow-md: 0 4px 12px rgba(60, 50, 40, 0.08), 0 2px 4px rgba(60, 50, 40, 0.05);
  --shadow-lg: 0 12px 32px rgba(60, 50, 40, 0.12), 0 4px 12px rgba(60, 50, 40, 0.06);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
}

body.dark {
  --bg: #15110e;
  --bg-grad: radial-gradient(circle at 20% 0%, #1f1813 0%, transparent 50%),
             radial-gradient(circle at 80% 100%, #1a1410 0%, transparent 50%),
             #15110e;
  --text: #d4c8b8;
  --text-strong: #f5ece0;
  --text-muted: #948876;
  --surface: #221b15;
  --surface-hover: #2c241c;
  --board-bg: #3a302a;
  --cell-bg: #50443c;
  --btn-bg: #6a554a;
  --btn-bg-hover: #856b5d;
  --btn-disabled: #4a3f37;
  --select-bg: #2c2520;
  --score-label: #c8b8a8;
  --overlay-bg: rgba(28, 22, 18, 0.88);
  --border: rgba(240, 230, 220, 0.08);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4), 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.5);
}

* { box-sizing: border-box; }

/* html doesn't inherit body.dark variables — set background explicitly */
html.dark { background: #15110e; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  background-image: var(--bg-grad);
  background-attachment: fixed;
  color: var(--text);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue",
    "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background-color .25s ease, color .25s ease;
}

a { color: inherit; text-decoration: none; }

/* ========== Header ========== */
.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 1080px;
  margin: 0 auto;
  padding: 16px 20px 8px;
}

.site-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.3px;
  color: var(--text-strong);
}
.site-brand:hover { opacity: 0.78; }

.site-game-title {
  flex: 1;
  text-align: center;
  margin: 0 12px;
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

/* ===== Per-game title themes ===== */
/* Electric neon arcade — Snake / Tetris / Breakout / Pong / Asteroids / Space Invaders / Cubesmash / Stairs / Stick Hero / Tanks / Platformer */
.site-game-title.theme-neon {
  font-family: 'Courier New', 'Consolas', monospace;
  color: #5cf;
  text-shadow: 0 0 8px rgba(80, 210, 255, 0.85), 0 0 18px rgba(0, 140, 220, 0.55);
  letter-spacing: 3px;
  font-weight: 700;
}
/* Retro 8-bit arcade — Pac-Man / Frogger / Flappy / Simon / Whack / Typing / Tower */
.site-game-title.theme-pixel {
  font-family: 'Courier New', monospace;
  color: #ff9933;
  text-shadow: 2px 2px 0 #cc4400, 0 0 8px rgba(255, 153, 51, 0.45);
  letter-spacing: 2px;
  font-weight: 800;
}
/* Vibrant pink arcade — Bubble / Candy / Gems / Fruit / DDR / Slot */
.site-game-title.theme-arcade-pink {
  font-family: 'Trebuchet MS', sans-serif;
  color: #ff66cc;
  text-shadow: 0 0 8px rgba(255, 102, 204, 0.75), 0 2px 0 rgba(140, 40, 120, 0.6);
  letter-spacing: 2px;
  font-weight: 800;
}
/* Elegant serif — 2048 / Threes / Mahjong / Kakuro / Sudoku / Chess / Reversi / Xiangqi / Gomoku / UTTT / Dots & Boxes / Battleship / Connect4 / Puzzle15 */
.site-game-title.theme-elegant {
  font-family: Georgia, 'Times New Roman', 'Noto Serif TC', serif;
  color: #c8a040;
  font-style: italic;
  letter-spacing: 2px;
  font-weight: 700;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
}
/* Casual warm — Memory / Solitaire / Spider / Fishing / Croc / Blackjack / RPS / Darts / Screw / FloodIt */
.site-game-title.theme-casual {
  font-family: 'Trebuchet MS', 'Comic Sans MS', sans-serif;
  color: #7c5fd6;
  letter-spacing: 1px;
  font-weight: 700;
  text-shadow: 0 2px 4px rgba(100, 80, 200, 0.3);
}
/* Bold sans — Wordle / Hangman / Boggle / Wordsearch */
.site-game-title.theme-bold {
  font-family: 'Arial Black', Helvetica, sans-serif;
  color: var(--text-strong);
  letter-spacing: 4px;
  font-weight: 900;
  text-transform: uppercase;
}
/* Minimal mono — Minesweeper / Nonogram / Lights Out */
.site-game-title.theme-minimal {
  font-family: 'Consolas', 'Courier New', monospace;
  color: var(--text-strong);
  letter-spacing: 3px;
  font-weight: 600;
}

.site-version {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0;
  opacity: 0.7;
  align-self: flex-end;
  padding-bottom: 1px;
}

.site-brand-logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  flex-shrink: 0;
}

.site-game-count {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  align-self: flex-end;
  padding-bottom: 3px;
  margin-left: 2px;
}

.site-brand-icon {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #f59563);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 900;
  font-size: 14px;
  letter-spacing: -1px;
  box-shadow: var(--shadow-sm);
  transition: background .15s ease, border-color .15s ease, transform .12s ease;
}
.site-brand-icon.is-back {
  background: var(--surface);
  background-image: none;
  border: 1px solid var(--border);
  color: var(--text-strong);
  font-size: 16px;
  font-weight: 700;
  line-height: 1;
}
.site-brand:hover .site-brand-icon.is-back {
  background: var(--surface-hover);
  border-color: var(--accent-soft);
  transform: translateX(-2px);
}

.site-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.site-theme-btn {
  background: var(--surface);
  color: var(--text-strong);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  /* Consistent minimum width so icon-only buttons (🌙 / 🔊 / 📳 / 📊
     etc.) don't shrink narrower than text buttons like "EN". Wider
     text buttons grow naturally beyond this floor. */
  min-width: 44px;
  box-sizing: border-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.2;
  transition: background .15s ease, border-color .15s ease;
  box-shadow: var(--shadow-sm);
}
.site-theme-btn:hover { background: var(--surface-hover); }

/* Audio popover — speaker button + collapsible panel beneath it. The
   panel holds the volume slider + haptics toggle. Hidden by default;
   shown when the speaker button is clicked. */
.site-audio-popover { position: relative; display: inline-flex; }
.site-audio-panel {
  position: absolute;
  top: calc(100% + 6px);
  /* Centre under the speaker button on desktop. */
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md, 10px);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: stretch;
  box-shadow: var(--shadow-md);
  z-index: 1000;
  white-space: nowrap;
  /* Hard ceiling so the panel can never exceed the viewport width. */
  max-width: calc(100vw - 16px);
  animation: site-audio-panel-pop 0.16s cubic-bezier(.16,1.3,.4,1);
}
.site-vol-row {
  display: flex; align-items: center; gap: 10px;
  cursor: pointer; user-select: none;
}
.site-vol-label {
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  min-width: 38px; letter-spacing: .5px;
}
.site-audio-panel[hidden] { display: none; }
@keyframes site-audio-panel-pop {
  from { transform: translate(-50%, -4px) scale(0.96); opacity: 0; }
  to   { transform: translate(-50%, 0)    scale(1);    opacity: 1; }
}

/* On phones the speaker may live inside the collapsible kebab menu —
   anchoring the popover to the button would let the actions panel
   clip it. Detach to viewport-fixed centring instead so the popover
   is ALWAYS fully on screen regardless of the speaker's location. */
@media (max-width: 600px) {
  .site-audio-panel {
    position: fixed;
    top: 64px;             /* just below the site header */
    right: 12px;
    left: auto;
    transform: none;
    /* Avoid clipping; the panel is small (slider + padding ≈ 180 px) */
    max-width: calc(100vw - 24px);
    animation-name: site-audio-panel-pop-mobile;
  }
  .site-volume-slider { width: 160px; }
}
@keyframes site-audio-panel-pop-mobile {
  from { transform: translateY(-6px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}

/* Compact horizontal volume slider. */
.site-volume-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 4px;
  margin: 0;
  background: var(--border);
  border-radius: 999px;
  outline: none;
  cursor: pointer;
  vertical-align: middle;
}
.site-volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  box-shadow: 0 0 0 2px var(--surface);
}
.site-volume-slider::-moz-range-thumb {
  width: 14px; height: 14px; border-radius: 50%;
  background: var(--accent); cursor: pointer; border: 2px solid var(--surface);
}

/* Standalone haptics button — shares .site-theme-btn base styling.
   States:
     default          enabled & active — full opacity, accent border
     .is-off          enabled but user toggled off — dimmed
     .is-unsupported  iOS / browsers without navigator.vibrate — heavy
                      dim + diagonal strike-through hint that this
                      browser can't do haptics regardless of toggle */
.site-haptics-btn { transition: opacity .15s ease, border-color .15s ease; }
.site-haptics-btn.is-off { opacity: 0.42; }
.site-haptics-btn[aria-pressed="true"] { border-color: var(--accent); }
.site-haptics-btn.is-unsupported {
  opacity: 0.45;
  cursor: help;
  position: relative;
}
.site-haptics-btn.is-unsupported::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(
    to top right,
    transparent calc(50% - 1px),
    rgba(180, 60, 50, 0.65) calc(50% - 1px),
    rgba(180, 60, 50, 0.65) calc(50% + 1px),
    transparent calc(50% + 1px)
  );
  border-radius: inherit;
  pointer-events: none;
}

/* ========== Lobby ========== */
.lobby {
  max-width: 1080px;
  margin: 0 auto;
  padding: 12px 20px 60px;
}

.lobby-title-row {
  display: flex;
  align-items: flex-end;
  gap: 20px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.lobby-title {
  font-size: clamp(40px, 8vmin, 64px);
  font-weight: 800;
  margin: 24px 0 0;
  letter-spacing: -2px;
  color: var(--text-strong);
  flex-shrink: 0;
}
.lobby-sub {
  color: var(--text-muted);
  margin: 0 0 32px;
  font-size: 15px;
  line-height: 1.5;
}

.game-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.game-card {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  position: relative;
  transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
  box-shadow: var(--shadow-sm);
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  animation: card-in .5s ease forwards;
  /* `--card-i` is set by lobby.js per card so every card staggers in,
     not just the first 9. min() caps the cascade so cards beyond #30
     don't take forever to show up. */
  animation-delay: min(calc(var(--card-i, 0) * 40ms), 1200ms);
}
@keyframes card-in {
  to { opacity: 1; transform: translateY(0) scale(1); }
}
@keyframes bounce-in {
  0%   { transform: scale(0); opacity: 0; }
  60%  { transform: scale(1.15); opacity: 1; }
  80%  { transform: scale(0.92); }
  100% { transform: scale(1); }
}
.game-card:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent-soft);
}
.game-card:active { transform: translateY(-1px); }

.game-card-thumb {
  height: 130px;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}
.game-card-thumb svg { width: 100%; height: 100%; display: block; }

.game-card-body {
  padding: 14px 16px 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.game-card-title {
  font-size: 18px;
  font-weight: 800;
  margin: 0;
  color: var(--text-strong);
  letter-spacing: -0.3px;
}
.game-card-desc {
  margin: 0;
  font-size: 13px;
  color: var(--text-muted);
  line-height: 1.55;
  /* Compact by default — show 2 lines, expand to full on hover. Keeps
     the lobby scannable when there are 60+ cards. */
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: -webkit-line-clamp .2s ease;
}
.game-card:hover .game-card-desc,
.game-card.kb-focus .game-card-desc {
  -webkit-line-clamp: unset;
}
.game-card-tag {
  display: inline-block;
  margin-top: 8px;
  padding: 2px 9px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1px;
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  color: #fff;
  border-radius: 999px;
  align-self: flex-start;
  text-transform: uppercase;
  box-shadow: 0 1px 4px rgba(237,194,46,0.35);
}
.game-card[aria-disabled="true"] {
  pointer-events: none;
  opacity: 0.6;
}
.game-card[aria-disabled="true"] .game-card-tag {
  background: var(--btn-disabled);
}

/* ========== Common buttons (used in games) ========== */
.btn {
  background: var(--btn-bg);
  color: #f9f6f2;
  border: 0;
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 36px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  touch-action: manipulation;
  transition: background .15s ease, opacity .15s ease, transform .08s ease;
  box-shadow: 0 2px 8px rgba(0,0,0,0.15), inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn:hover:not(:disabled) { background: var(--btn-bg-hover); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled {
  background: var(--btn-disabled);
  color: rgba(255, 255, 255, 0.6);
  cursor: not-allowed;
}
.btn-toggle[aria-pressed="false"] { opacity: 0.5; }

/* ========== Help modal ========== */
.help-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 12, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: help-fadein .2s ease;
}
.help-overlay[hidden] { display: none; }
@keyframes help-fadein { from { opacity: 0; } to { opacity: 1; } }

.help-modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  max-width: 460px;
  width: 100%;
  max-height: 86vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: help-pop .25s cubic-bezier(.5, -0.1, .3, 1.3);
}
@keyframes help-pop {
  from { transform: translateY(16px) scale(0.96); opacity: 0; }
  to   { transform: translateY(0) scale(1); opacity: 1; }
}

.help-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 20px 14px;
  border-bottom: 1px solid var(--border);
}
.help-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-strong);
  margin: 0;
  letter-spacing: -0.3px;
}
.help-close {
  background: transparent;
  border: 0;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  line-height: 1;
  transition: background .12s ease, color .12s ease;
}
.help-close:hover {
  background: var(--surface-hover);
  color: var(--text-strong);
}

.help-body {
  padding: 18px 20px 22px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
  overflow-y: auto;
}
.help-body h3 {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-muted);
  margin: 18px 0 8px;
  letter-spacing: 1.5px;
  text-transform: uppercase;
}
.help-body h3:first-child { margin-top: 0; }
.help-body p { margin: 0 0 10px; color: var(--text-strong); }
.help-body ul {
  margin: 0 0 12px;
  padding-left: 20px;
  color: var(--text-strong);
}
.help-body li { margin-bottom: 5px; }
.help-body kbd {
  background: var(--surface-hover);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  color: var(--text-strong);
  margin: 0 1px;
}
.help-body .swatch {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  font-size: 10px;
  font-weight: 800;
  color: #fff;
  margin: 0 4px 0 0;
  vertical-align: -3px;
}

#help-content { display: none; }

/* ========== Game page common layout ==========
   Each game's HTML uses <main class="app">; these rules unify the look.
   Games can still override individual properties in their own style.css. */
.app {
  max-width: 540px;
  margin: 0 auto;
  padding: 8px 16px 40px;
}

.app .header {
  display: flex;
  /* The title now lives only in the site header (.site-game-title); the
     in-app .header is just the score row, right-aligned. */
  justify-content: flex-end;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.app .scores {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.app .score-box {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-strong);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
  min-width: 64px;
  text-align: center;
  box-shadow: var(--shadow-sm);
  transition: transform .12s ease;
}

.app .score-label {
  font-size: 10px;
  letter-spacing: 1.2px;
  color: var(--text-muted);
  font-weight: 700;
  text-transform: uppercase;
}

.app .score-value {
  font-size: 18px;
  font-weight: 800;
  line-height: 1.2;
  margin-top: 2px;
}

.app .toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-bottom: 18px;
}

.app .select {
  background: var(--select-bg);
  color: var(--text-strong);
  border: 0;
  border-radius: var(--radius-sm);
  padding: 8px 28px 8px 14px;
  font-weight: 700;
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  appearance: none;
  -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--text-strong) 50%),
                    linear-gradient(-45deg, transparent 50%, var(--text-strong) 50%);
  background-position: right 12px top 50%, right 8px top 50%;
  background-size: 4px 4px;
  background-repeat: no-repeat;
  transition: background-color .15s ease;
}
.app .select:hover { background-color: var(--surface-hover); }

.app .board-wrapper {
  display: flex;
  justify-content: center;
}

/* ========== Mobile tuning ========== */
/* Mobile actions toggle button — hidden on desktop */
.site-actions-toggle { display: none; }

@media (max-width: 600px) {
  .game-grid { grid-template-columns: 1fr; gap: 14px; }
  .lobby { padding-left: 12px; padding-right: 12px; }
  .lobby-title { margin-top: 12px; }
  .app { padding-left: 10px; padding-right: 10px; }
  .app .score-box { padding: 5px 8px; min-width: 52px; }
  .app .score-value { font-size: 16px; }
  .site-header { padding-left: 12px; padding-right: 12px; }
  .site-game-title { font-size: 1rem; margin: 0 6px; }
  /* Show the ⋯ toggle button on every phone/tablet-portrait viewport.
     Unified at 600 px to match the audio-popover breakpoint above so
     the header collapses and the popover anchors identically. */
  .site-actions-toggle { display: flex; align-items: center; justify-content: center; }

  /* Hide the actions bar from normal flow; show as compact 2-column grid when open */
  .site-header-actions {
    display: none;
    position: fixed;
    top: 52px;
    right: 12px;
    z-index: 1000;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 5px;
  }
  .site-header-actions.open { display: grid; }
  .site-header-actions .site-theme-btn,
  .site-header-actions a.site-theme-btn {
    box-sizing: border-box;
    text-align: center;
    padding: 8px 6px;
    border-radius: var(--radius-sm);
    font-size: 14px;
  }
  /* Audio popover positioning is handled globally in the 600px block
     above (position: fixed, top: 64px, right: 12px) — no further
     overrides needed inside the actions-panel context. */
}

/* ========== Filter bar ========== */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 20px;
}
.filter-btn {
  background: var(--surface);
  color: var(--text-strong);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  min-height: 36px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: 0.3px;
  transition: background .15s, border-color .15s, color .15s;
}
.filter-btn:hover { background: var(--surface-hover); }
.filter-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-soft));
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 2px 8px rgba(237,194,46,0.35);
}

/* Mobile filter dropdown (≤480px replaces filter-bar) */
.filter-select {
  display: none;
}
@media (max-width: 480px) {
  .filter-bar { display: none; }
  .filter-select {
    display: block;
    width: 100%;
    padding: 10px 14px;
    margin-bottom: 16px;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-strong);
    font-size: 14px;
    font-family: inherit;
    cursor: pointer;
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
  }
}

/* ========== Sort bar ========== */
.sort-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}

.sort-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.5px;
  margin-right: 2px;
}

.sort-btn {
  padding: 4px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.78rem;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s;
}

.sort-btn:hover { background: var(--btn-bg); color: #fff; }
.sort-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ========== Card badges (NEW / HOT) ========== */
.card-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 5;
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: 0.6px;
  padding: 3px 8px;
  border-radius: 999px;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
  pointer-events: none;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
}
.card-badge-new {
  background: linear-gradient(135deg, #2ecc71, #27ae60);
}
.card-badge-hot {
  background: linear-gradient(135deg, #ff6b35, #e74c3c);
  left: auto;
  right: 8px;
}
.card-badge-new + .card-badge-hot { right: 8px; left: auto; }
.card-badge-3d {
  background: linear-gradient(135deg, #6c5ce7, #8e44ad);
  /* sits next to / instead of NEW, top-left */
}
.card-badge-new + .card-badge-3d { left: 56px; }

/* ========== Difficulty dot (bottom-left of thumb) ========== */
.diff-dot {
  position: absolute;
  bottom: 6px;
  left: 6px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  z-index: 4;
  border: 2px solid rgba(0, 0, 0, 0.35);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}
.diff-dot[data-d="easy"]   { background: #2ecc71; }
.diff-dot[data-d="medium"] { background: #f1c40f; }
.diff-dot[data-d="hard"]   { background: #e74c3c; }

/* ========== Player progress pills (PB / Daily / 未玩, in card body) ========== */
.card-stats-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 4px;
  align-items: center;
}
.stat-pill {
  display: inline-flex;
  align-items: center;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.4px;
  padding: 2px 8px;
  border-radius: 999px;
  text-transform: uppercase;
  line-height: 1.4;
}
.stat-pill-pb       { background: rgba(237,194,46,0.18); color: #b88706; }
.stat-pill-daily    { background: rgba(46,204,113,0.20); color: #1f8848; }
.stat-pill-unplayed { background: rgba(127,127,127,0.18); color: var(--text-muted); }
body.dark .stat-pill-pb    { color: #ffd34d; }
body.dark .stat-pill-daily { color: #6edb96; }

/* ========== Continue last game (hero) ========== */
.continue-card {
  display: flex;
  align-items: center;
  gap: 16px;
  max-width: 1080px;
  margin: 12px auto 0;
  padding: 14px 18px;
  background: linear-gradient(135deg, var(--accent), #f59563);
  color: #fff;
  border-radius: var(--radius-md);
  text-decoration: none;
  box-shadow: var(--shadow-md);
  transition: transform .15s ease-out, box-shadow .15s ease-out;
}
.continue-card[hidden] { display: none; }
.continue-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.continue-card:active { transform: translateY(0); }
.continue-card-arrow {
  font-size: 22px;
  background: rgba(255,255,255,0.25);
  width: 44px; height: 44px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.continue-card-body { flex: 1; min-width: 0; }
.continue-card-label {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 1.6px;
  text-transform: uppercase;
  opacity: 0.85;
}
.continue-card-title {
  font-size: 22px;
  font-weight: 800;
  margin-top: 2px;
  text-shadow: 0 2px 4px rgba(0,0,0,0.2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.continue-card-meta {
  font-size: 12px;
  opacity: 0.85;
  margin-top: 2px;
  font-variant-numeric: tabular-nums;
}
.continue-card-chev {
  font-size: 28px;
  opacity: 0.7;
  flex-shrink: 0;
}
@media (max-width: 480px) {
  .continue-card { margin: 8px 12px 0; padding: 12px 14px; gap: 12px; }
  .continue-card-arrow { width: 38px; height: 38px; font-size: 18px; }
  .continue-card-title { font-size: 18px; }
}

/* ========== Recently played ========== */
.recent-bar {
  max-width: 1080px;
  margin: 0 auto;
  padding: 8px 20px 0;
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.recent-bar[hidden] { display: none; }
.recent-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  white-space: nowrap;
}
.recent-row { display: flex; gap: 8px; flex-wrap: wrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
@media (max-width: 480px) {
  .recent-bar { padding: 6px 12px 0; gap: 8px; }
  .recent-row { flex-wrap: nowrap; padding-bottom: 4px; }
  .recent-row::-webkit-scrollbar { display: none; }
  .recent-chip { font-size: 11px; padding: 4px 10px 4px 5px; gap: 5px; white-space: nowrap; }
  .recent-dot { width: 16px; height: 16px; }
}
.recent-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 5px 12px 5px 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-strong);
  transition: background .15s, border-color .15s;
  cursor: pointer;
}
.recent-chip:hover { background: var(--surface-hover); border-color: var(--accent-soft); }
.recent-dot {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* ========== Search bar ========== */
.search-bar {
  position: relative;
  flex: 1;
  min-width: 180px;
  max-width: 360px;
  margin: 0 0 4px;
}
.search-bar input {
  width: 100%;
  padding: 10px 36px 10px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text-strong);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  box-sizing: border-box;
  transition: border-color .15s;
}
.search-bar input:focus { border-color: var(--accent); }
.search-clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  font-size: 18px;
  color: var(--text-muted);
  padding: 8px;
  line-height: 1;
}
.search-clear-btn:hover { color: var(--text-strong); }

/* ========== Keyboard focus ring ========== */
.game-card.kb-focus {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
}

/* ========== Favorites (star) button ========== */
.fav-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  background: rgba(0, 0, 0, 0.25);
  border: none;
  border-radius: 999px;
  font-size: 18px;
  cursor: pointer;
  /* Visible at low opacity by default — full on hover / pinned / mobile.
     Previously `opacity:0` meant touch users could never see the
     button (no hover state). */
  opacity: 0.55;
  transition: opacity 0.2s, background 0.2s, transform 0.12s;
  color: #fff;
  line-height: 1;
  padding: 6px;
  min-width: 34px;
  min-height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 6;
}
.game-card:hover .fav-btn { opacity: 1; background: rgba(0, 0, 0, 0.45); }
.game-card .fav-btn:active { transform: scale(0.88); }
.game-card.pinned .fav-btn { opacity: 1; color: #ffd84a; background: rgba(0, 0, 0, 0.45); }
@media (pointer: coarse) {
  /* Touch devices have no hover — always show the button at full
     visibility so favoriting is one-tap. */
  .fav-btn { opacity: 1; }
}

/* ========== Daily challenge lobby banner ========== */
.daily-section {
  margin-bottom: 22px;
}
.daily-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.daily-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.daily-row::-webkit-scrollbar { height: 4px; }
.daily-row::-webkit-scrollbar-track { background: transparent; }
.daily-row::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
.daily-mini-card {
  flex-shrink: 0;
  width: 90px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: pointer;
  transition: transform .18s ease, box-shadow .18s ease, border-color .18s ease;
  box-shadow: var(--shadow-sm);
  text-decoration: none;
  color: inherit;
  position: relative;
  display: flex;
  flex-direction: column;
}
.daily-mini-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-md);
  border-color: var(--accent-soft);
}
.daily-mini-thumb {
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.daily-mini-thumb svg { width: 100%; height: 100%; display: block; }
.daily-mini-name {
  font-size: 10px;
  font-weight: 700;
  padding: 4px 6px 5px;
  text-align: center;
  color: var(--text-strong);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.done-badge {
  position: absolute;
  top: 4px;
  right: 4px;
  background: #27ae60;
  color: #fff;
  font-size: 9px;
  font-weight: 800;
  border-radius: 999px;
  width: 16px;
  height: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}

/* ========== Pause overlay ========== */
.pause-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 14, 10, 0.7);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 150;
  gap: 10px;
  backdrop-filter: blur(2px);
}
.pause-overlay[hidden] { display: none; }
.pause-overlay-text {
  font-size: 32px;
  font-weight: 800;
  color: #fff;
  letter-spacing: -0.5px;
}
.pause-overlay-hint {
  font-size: 14px;
  color: rgba(255,255,255,0.65);
}
.pause-overlay-hint kbd {
  background: rgba(255,255,255,0.18);
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: 4px;
  padding: 2px 7px;
  font-family: ui-monospace, monospace;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
}

/* ========== Achievement toast ========== */
.achievement-toast {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 999;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 12px 16px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  max-width: 280px;
  opacity: 0;
  transform: translateX(120%);
  transition: opacity .3s ease, transform .3s ease;
  pointer-events: none;
}
.achievement-toast.achievement-toast-show {
  opacity: 1;
  transform: translateX(0);
}
.achievement-toast.achievement-toast-hide {
  opacity: 0;
  transform: translateX(120%);
}
.achievement-toast-icon {
  font-size: 28px;
  line-height: 1;
  flex-shrink: 0;
}
.achievement-toast-body { display: flex; flex-direction: column; gap: 2px; }
.achievement-toast-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--accent);
}
.achievement-toast-name {
  font-size: 15px;
  font-weight: 800;
  color: var(--text-strong);
}
.achievement-toast-desc {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.4;
}

/* ========== Reduced motion ========== */
@media (prefers-reduced-motion: reduce) {
  .game-card { transition: none; animation: none; }
  .game-card:hover { transform: none; }
  .achievement-toast, .achievement-toast.achievement-toast-hide { transition: none; }
}

/* ── Pause overlay (shared/pause.js) ───────────────────────────────────── */
.site-pause-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  display: flex; align-items: center; justify-content: center;
  z-index: 9000;
  animation: site-pause-fade 0.15s ease-out;
}
.site-pause-overlay[hidden] { display: none; }
@keyframes site-pause-fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
.site-pause-card {
  background: var(--surface);
  border: 2px solid var(--accent);
  border-radius: var(--radius-lg, 14px);
  padding: 28px 36px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  min-width: 220px;
}
.site-pause-title {
  font-size: 28px; font-weight: 900;
  color: var(--accent);
  letter-spacing: 4px;
  margin-bottom: 6px;
}
.site-pause-sub {
  font-size: 13px; color: var(--text-muted);
  margin-bottom: 18px;
}
.site-pause-btn-resume {
  background: var(--accent); color: #fff;
  border: none; border-radius: var(--radius-md, 10px);
  padding: 8px 28px; font-size: 15px; font-weight: 700;
  cursor: pointer;
  transition: opacity .15s ease;
}
.site-pause-btn-resume:hover { opacity: 0.88; }
/* Header pause button — inherits .site-theme-btn base; only the icon
   needs a slightly larger glyph + a visible state when paused. */
.site-pause-btn[hidden] { display: none !important; }

/* ──────────────────────────────────────────────────────────────────────────
   Profile / XP system — lobby pill, level-up toast, accent variants
   ────────────────────────────────────────────────────────────────────────── */

/* Accent overrides — set on body when SiteProfile.activeAccent is unlocked.
   Each variant overrides --accent + --accent-soft so the entire UI re-tints. */
body.accent-gold        { --accent: #f5b400; --accent-soft: #ffd34d; }
body.dark.accent-gold   { --accent: #ffcb33; --accent-soft: #ffd966; }
body.accent-neon        { --accent: #00e0ff; --accent-soft: #66f0ff; }
body.dark.accent-neon   { --accent: #00e0ff; --accent-soft: #66f0ff; }
body.accent-magenta     { --accent: #e040b8; --accent-soft: #f471d4; }
body.dark.accent-magenta{ --accent: #ff5fc8; --accent-soft: #ff8cd9; }
/* Rainbow uses a slow hue rotation so the accent shimmers across the UI. */
body.accent-rainbow     { --accent: #ff4d4d; --accent-soft: #ff8a8a; animation: profile-rainbow 8s linear infinite; }
body.dark.accent-rainbow{ --accent: #ff6666; --accent-soft: #ff9c9c; animation: profile-rainbow 8s linear infinite; }
@keyframes profile-rainbow {
  0%   { filter: hue-rotate(0deg); }
  100% { filter: hue-rotate(360deg); }
}

/* Lobby profile pill — lives in site-header next to the version pill. */
.profile-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 5px;
  background: var(--surface);
  border: 1.5px solid var(--accent);
  border-radius: 999px;
  font-size: 12px;
  line-height: 1;
  color: var(--text-strong);
  cursor: pointer;
  text-decoration: none;
  transition: transform .12s ease, box-shadow .12s ease, background .15s ease;
  box-shadow: var(--shadow-sm, 0 2px 4px rgba(0,0,0,0.08));
}
/* On mobile dropdown grid (≤600px), the pill spans both columns so the
   level bar isn't squashed into a 1-col slot wider than other icons. */
@media (max-width: 600px) {
  .site-header-actions .profile-pill {
    grid-column: 1 / -1;
    justify-content: center;
    padding: 6px 14px 6px 6px;
  }
}
.profile-pill:hover { transform: translateY(-1px); box-shadow: var(--shadow-md, 0 4px 8px rgba(0,0,0,0.15)); }
.profile-pill-avatar {
  display: inline-flex;
  width: 22px; height: 22px;
  align-items: center; justify-content: center;
  background: var(--accent-soft);
  border-radius: 50%;
  font-size: 13px;
}
.profile-pill-level { font-weight: 800; }
.profile-pill-bar {
  position: relative;
  width: 56px; height: 6px;
  background: rgba(0,0,0,0.12);
  border-radius: 3px;
  overflow: hidden;
}
body.dark .profile-pill-bar { background: rgba(255,255,255,0.18); }
.profile-pill-bar-fill {
  position: absolute; left: 0; top: 0; bottom: 0;
  background: var(--accent);
  border-radius: 3px;
  transition: width .3s ease;
}

/* Level-up toast — own slot so it can stack with achievements without
   collision. Slides in from the right. */
.profile-toast {
  position: fixed;
  bottom: 80px;          /* sits above achievement toast (40px) */
  right: 16px;
  background: var(--accent);
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-weight: 700;
  z-index: 10001;
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  opacity: 0;
  transform: translateX(120%);
  transition: opacity .25s ease, transform .25s ease;
  max-width: 320px;
  cursor: pointer;
}
.profile-toast.profile-toast-show { opacity: 1; transform: translateX(0); }
.profile-toast.profile-toast-hide { opacity: 0; transform: translateX(120%); }
.profile-toast-main { font-size: 15px; }
.profile-toast-sub  { font-size: 12px; opacity: .92; margin-top: 4px; font-weight: 500; }
