/* ═══════════════════════════════════════════════════════════════
   LEXIKA — Multi-Theme Engine
   Themes: warm (default) · jungle · neon · midnight · rosegold
═══════════════════════════════════════════════════════════════ */
/* Fonts: Crimson Pro and DM Sans are loaded via Google Fonts CDN (external network request required).
   CDN URL: https://fonts.googleapis.com
   To bundle fonts locally instead: download the font files, place them in a /fonts/ folder,
   remove this @import, and replace with @font-face declarations pointing to the local files. */
@import url("https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@400;600&family=DM+Sans:wght@300;400;500&display=swap");

/* ── THEME: WARM PAPER (default) ─────────────────────────────── */
:root,
body[data-theme="warm"] {
  --paper: #f7f3ec;
  --paper2: #f0ead8;
  --paper3: #e8dfc8;
  --ink: #2a2520;
  --ink-mid: #5a5248;
  --ink-dim: #9a9088;
  --ink-faint: #ccc5b8;
  --accent: #c0522a;
  --accent-lt: #e87848;
  --accent-bg: rgba(192, 82, 42, 0.1);
  --blue: #2a4a7f;
  --blue-lt: rgba(42, 74, 127, 0.08);
  --row-hl: rgba(192, 82, 42, 0.06);
  --same-hl: rgba(42, 74, 127, 0.1);
  --error-bg: rgba(200, 40, 40, 0.12);
  --error-txt: #c02828;
  --success: #287840;
  --given-bg: rgba(42, 37, 32, 0.06);
  --grid-thin: #c8bfb0;
  --grid-thick: #7a6e60;
  --box-border: #2a2520;
  --cell-bg: #fefcf8;
  --grid-bg: #fefcf8;
  --shadow: 0 4px 20px rgba(42, 37, 32, 0.12);
  --radius: 8px;
  --screen-bg: transparent;
  --card-bg: rgba(255, 255, 255, 0.58);
  --card-border: var(--paper3);
  --btn-primary-bg: var(--ink);
  --btn-primary-color: var(--paper);
  --bg-overlay: linear-gradient(
    160deg,
    rgba(220, 195, 158, 0.55) 0%,
    rgba(180, 145, 100, 0.48) 100%
  );
  --grid-wrap-bg: linear-gradient(145deg, #ede0cc 0%, #d4c4a8 100%);
  --grid-wrap-shadow: 0 8px 32px rgba(42, 37, 32, 0.22);
  --grid-wrap-border: #b8a888;
}

/* ── THEME: JUNGLE ────────────────────────────────────────────── */
body[data-theme="jungle"] {
  --paper: #0d1f0e;
  --paper2: #142818;
  --paper3: #1c3320;
  --ink: #c8f0b0;
  --ink-mid: #88c870;
  --ink-dim: #507848;
  --ink-faint: #2a4830;
  --accent: #58d060;
  --accent-lt: #80e888;
  --accent-bg: rgba(88, 208, 96, 0.14);
  --blue: #40c898;
  --blue-lt: rgba(64, 200, 152, 0.12);
  --row-hl: rgba(88, 208, 96, 0.08);
  --same-hl: rgba(64, 200, 152, 0.14);
  --error-bg: rgba(240, 80, 60, 0.18);
  --error-txt: #f08070;
  --success: #58d060;
  --given-bg: rgba(200, 240, 176, 0.06);
  --grid-thin: #2a5030;
  --grid-thick: #3a7040;
  --box-border: #58d060;
  --cell-bg: #0f2412;
  --grid-bg: #0a1a0c;
  --shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  --radius: 4px;
  --screen-bg: transparent;
  --card-bg: rgba(20, 40, 22, 0.78);
  --card-border: #2a4830;
  --btn-primary-bg: #58d060;
  --btn-primary-color: #0a1a0c;
  --bg-overlay: linear-gradient(
    160deg,
    rgba(8, 28, 10, 0.72) 0%,
    rgba(4, 18, 6, 0.82) 100%
  );
  --grid-wrap-bg: linear-gradient(145deg, #1a4020 0%, #0c2410 100%);
  --grid-wrap-shadow:
    0 12px 48px rgba(0, 0, 0, 0.7), 0 0 0 2px rgba(88, 208, 96, 0.2);
  --grid-wrap-border: #3a7040;
}

/* ── THEME: NEON CITY ─────────────────────────────────────────── */
body[data-theme="neon"] {
  --paper: #08080f;
  --paper2: #0e0e1a;
  --paper3: #141424;
  --ink: #f0f0ff;
  --ink-mid: #a0a0e0;
  --ink-dim: #5050a0;
  --ink-faint: #1e1e3a;
  --accent: #ff2d78;
  --accent-lt: #ff70a8;
  --accent-bg: rgba(255, 45, 120, 0.14);
  --blue: #00d8ff;
  --blue-lt: rgba(0, 216, 255, 0.12);
  --row-hl: rgba(255, 45, 120, 0.07);
  --same-hl: rgba(0, 216, 255, 0.14);
  --error-bg: rgba(255, 45, 120, 0.2);
  --error-txt: #ff7070;
  --success: #00ffaa;
  --given-bg: rgba(240, 240, 255, 0.04);
  --grid-thin: #1e1e3a;
  --grid-thick: #3030a0;
  --box-border: #ff2d78;
  --cell-bg: #0c0c18;
  --grid-bg: #08080f;
  --shadow: 0 8px 40px rgba(255, 45, 120, 0.3);
  --radius: 0px;
  --screen-bg: transparent;
  --card-bg: rgba(14, 14, 26, 0.85);
  --card-border: #1e1e3a;
  --btn-primary-bg: #ff2d78;
  --btn-primary-color: #ffffff;
  --bg-overlay: linear-gradient(
    160deg,
    rgba(4, 4, 12, 0.85) 0%,
    rgba(8, 0, 18, 0.9) 100%
  );
  --grid-wrap-bg: linear-gradient(145deg, #120020 0%, #040008 100%);
  --grid-wrap-shadow:
    0 0 0 1px rgba(255, 45, 120, 0.5), 0 16px 48px rgba(255, 45, 120, 0.25),
    0 0 80px rgba(255, 45, 120, 0.1);
  --grid-wrap-border: transparent;
}

/* ── THEME: MIDNIGHT INK ─────────────────────────────────────── */
body[data-theme="midnight"] {
  --paper: #0e1120;
  --paper2: #161b2e;
  --paper3: #1e2438;
  --ink: #e8ecf8;
  --ink-mid: #a0a8c0;
  --ink-dim: #606880;
  --ink-faint: #2a3048;
  --accent: #7c5cbf;
  --accent-lt: #9c7ce0;
  --accent-bg: rgba(124, 92, 191, 0.14);
  --blue: #4870d8;
  --blue-lt: rgba(72, 112, 216, 0.12);
  --row-hl: rgba(124, 92, 191, 0.08);
  --same-hl: rgba(72, 112, 216, 0.12);
  --error-bg: rgba(220, 60, 80, 0.18);
  --error-txt: #f07080;
  --success: #48c890;
  --given-bg: rgba(232, 236, 248, 0.04);
  --grid-thin: #2a3048;
  --grid-thick: #4a5080;
  --box-border: #7c5cbf;
  --cell-bg: #161b2e;
  --grid-bg: #0e1120;
  --shadow: 0 8px 40px rgba(0, 0, 0, 0.6);
  --radius: 6px;
  --screen-bg: transparent;
  --card-bg: rgba(22, 27, 46, 0.72);
  --card-border: #2a3048;
  --btn-primary-bg: #7c5cbf;
  --btn-primary-color: #f0f0ff;
  --bg-overlay: linear-gradient(
    160deg,
    rgba(8, 10, 28, 0.78) 0%,
    rgba(4, 6, 18, 0.85) 100%
  );
  --grid-wrap-bg: linear-gradient(145deg, #1a1f38 0%, #0a0d1e 100%);
  --grid-wrap-shadow:
    0 0 0 1px rgba(124, 92, 191, 0.35), 0 16px 48px rgba(0, 0, 0, 0.5);
  --grid-wrap-border: transparent;
}

/* ════════════════════════════════════════════════
   THEME: ROSE GOLD (5th theme)
════════════════════════════════════════════════ */
body[data-theme="rosegold"] {
  --paper: #fdf0f0;
  --paper2: #f9e4e4;
  --paper3: #f0d0d0;
  --ink: #3a1a1a;
  --ink-mid: #7a4a4a;
  --ink-dim: #b08080;
  --ink-faint: #e0c0c0;
  --accent: #c0607a;
  --accent-lt: #e0809a;
  --accent-bg: rgba(192, 96, 122, 0.1);
  --blue: #8060a0;
  --blue-lt: rgba(128, 96, 160, 0.1);
  --row-hl: rgba(192, 96, 122, 0.06);
  --same-hl: rgba(128, 96, 160, 0.1);
  --error-bg: rgba(200, 40, 40, 0.1);
  --error-txt: #c04040;
  --success: #608060;
  --given-bg: rgba(58, 26, 26, 0.06);
  --grid-thin: #e0c0c0;
  --grid-thick: #c09090;
  --box-border: #8a4a5a;
  --cell-bg: #fefafa;
  --grid-bg: #fefafa;
  --shadow: 0 4px 20px rgba(120, 60, 70, 0.14);
  --radius: 10px;
  --screen-bg: transparent;
  --card-bg: rgba(255, 245, 245, 0.62);
  --card-border: var(--paper3);
  --btn-primary-bg: #c0607a;
  --btn-primary-color: #fff5f5;
  --bg-overlay: linear-gradient(
    160deg,
    rgba(240, 200, 200, 0.55) 0%,
    rgba(200, 150, 160, 0.5) 100%
  );
  --grid-wrap-bg: linear-gradient(145deg, #f5dada 0%, #e8c0c8 100%);
  --grid-wrap-shadow: 0 8px 32px rgba(120, 60, 70, 0.22);
  --grid-wrap-border: #d0a0a8;
}

/* Rose Gold brand glow */
body[data-theme="rosegold"] .brand,
body[data-theme="rosegold"] .loading-brand {
  text-shadow:
    0 0 24px rgba(192, 96, 122, 0.4),
    0 2px 12px rgba(0, 0, 0, 0.12);
}

/* Rose Gold popup rule line */
body[data-theme="rosegold"] .popup-rule-line {
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

/* Rose Gold theme preview */
.theme-preview--rosegold {
  background: linear-gradient(145deg, #fdf0f0, #f5dada);
  border: 1.5px solid #d0a0a8;
}
.theme-preview--rosegold .tp-grid {
  border-color: #8a4a5a;
  border-radius: 3px;
  overflow: hidden;
}
.theme-preview--rosegold .tp-cell {
  background: #fefafa;
  border-right: 1px solid #e0c0c0;
  border-bottom: 1px solid #e0c0c0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(9px, 2.5vw, 13px);
  font-weight: 600;
  color: #8060a0;
  aspect-ratio: 1;
}
.theme-preview--rosegold .tp-cell.tp-given {
  background: rgba(58, 26, 26, 0.06);
  color: #3a1a1a;
}
.theme-preview--rosegold .tp-cell.tp-sel {
  background: rgba(192, 96, 122, 0.14);
  color: #c0607a;
}
.theme-preview--rosegold .tp-cell.tp-br {
  border-right: 2px solid #c09090;
}
.theme-preview--rosegold .tp-cell.tp-bb {
  border-bottom: 2px solid #c09090;
}

/* ════════════════════════════════════════════════
   PARTICLES CANVAS
════════════════════════════════════════════════ */
#particles-canvas {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: -1;
  pointer-events: none;
}

/* ════════════════════════════════════════════════
   CONFETTI CANVAS (complete screen)
════════════════════════════════════════════════ */
#confetti-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 0;
}
#s-complete > *:not(#confetti-canvas) {
  position: relative;
  z-index: 1;
}

/* ════════════════════════════════════════════════
   XP / LEVEL BAR (lobby)
════════════════════════════════════════════════ */
.lobby-xp-bar {
  width: 100%;
  max-width: 340px;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.lobby-xp-level {
  font-size: 0.55rem;
  letter-spacing: 0.22em;
  color: var(--accent);
  text-transform: uppercase;
  white-space: nowrap;
  min-width: 70px;
}
.lobby-xp-track {
  flex: 1;
  height: 4px;
  background: var(--ink-faint);
  border-radius: 2px;
  overflow: hidden;
}
.lobby-xp-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.6s ease;
  width: 0%;
}
.lobby-xp-pts {
  font-size: 0.5rem;
  letter-spacing: 0.1em;
  color: var(--ink-dim);
  white-space: nowrap;
  min-width: 40px;
  text-align: right;
}

/* ════════════════════════════════════════════════
   ACHIEVEMENT BADGES (lobby)
════════════════════════════════════════════════ */
.lobby-badges {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 340px;
  margin-bottom: 16px;
  min-height: 0;
}
.lobby-badge {
  padding: 4px 10px;
  background: var(--card-bg);
  border: 1px solid var(--ink-faint);
  border-radius: 20px;
  font-size: 0.52rem;
  letter-spacing: 0.15em;
  color: var(--ink-dim);
  text-transform: uppercase;
  backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  gap: 5px;
  animation: badgePop 0.35s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
.lobby-badge.gold {
  border-color: var(--accent);
  color: var(--accent);
}
@keyframes badgePop {
  from {
    opacity: 0;
    transform: scale(0.7);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

/* Achievement banner on complete screen */
.achievement-banner {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 10px 0;
  max-width: 300px;
  width: 100%;
}
.achievement-item {
  padding: 8px 14px;
  background: var(--accent-bg);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  color: var(--accent);
  text-transform: uppercase;
  text-align: center;
  animation: badgePop 0.4s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}

/* ════════════════════════════════════════════════
   XP display on complete screen
════════════════════════════════════════════════ */
#comp-xp {
  color: var(--success) !important;
}

/* ════════════════════════════════════════════════
   HINTS REMAINING display
════════════════════════════════════════════════ */
#hints-remaining-wrap {
  display: none;
}
#hints-remaining-wrap.visible {
  display: flex;
}

/* ════════════════════════════════════════════════
   TIME ATTACK BAR
════════════════════════════════════════════════ */
.time-attack-bar {
  width: 100%;
  max-width: 520px;
  height: 3px;
  background: var(--ink-faint);
  display: none;
  margin-bottom: 4px;
  border-radius: 2px;
  overflow: hidden;
  align-self: center;
}
.time-attack-bar.visible {
  display: block;
}
.time-attack-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition:
    width 1s linear,
    background 0.5s;
  width: 100%;
}
.time-attack-fill.danger {
  background: var(--error-txt);
}

/* ════════════════════════════════════════════════
   CUSTOM PUZZLE IMPORT ROW
════════════════════════════════════════════════ */
.import-row {
  width: 100%;
  max-width: 360px;
  margin-bottom: 12px;
}
.import-toggle {
  background: none;
  border: none;
  color: var(--ink-dim);
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 0;
  transition: color 0.18s;
}
.import-toggle:hover {
  color: var(--accent);
}
.import-toggle svg {
  width: 14px;
  height: 14px;
  fill: currentColor;
}
.import-panel {
  display: none;
  gap: 8px;
  margin-top: 8px;
}
.import-panel.open {
  display: flex;
}
.import-input {
  flex: 1;
  padding: 8px 12px;
  background: var(--card-bg);
  border: 1px solid var(--ink-faint);
  border-radius: var(--radius);
  color: var(--ink);
  font-family: monospace;
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  outline: none;
  backdrop-filter: blur(8px);
  transition: border-color 0.18s;
}
.import-input:focus {
  border-color: var(--accent);
}
.import-btn {
  padding: 8px 16px;
  background: var(--btn-primary-bg);
  border: none;
  border-radius: var(--radius);
  color: var(--btn-primary-color);
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
  transition: background 0.18s;
  white-space: nowrap;
}
.import-btn:hover {
  background: var(--accent);
}

/* ════════════════════════════════════════════════
   LEADERBOARD SCREEN
════════════════════════════════════════════════ */
#s-leaderboard,
#s-achievements {
  justify-content: flex-start;
  align-items: stretch;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

#s-leaderboard .page-header,
#s-achievements .page-header {
  align-self: center;
  flex-shrink: 0;
  width: 100%;
  max-width: 460px;
}

#s-leaderboard .lb-tabs,
#s-leaderboard .lb-clear {
  align-self: center;
}

#s-leaderboard .lb-list,
#s-achievements .lb-list {
  align-self: center;
}
.lb-tabs {
  display: flex;
  gap: 0;
  max-width: 460px;
  align-self: center;
  width: 100%;
  padding: 12px clamp(18px, 5vw, 32px) 0;
}
.lb-tab {
  flex: 1;
  padding: 8px;
  background: none;
  border: none;
  border-bottom: 2px solid var(--ink-faint);
  color: var(--ink-dim);
  font-family: "DM Sans", sans-serif;
  font-size: 0.72rem;
  letter-spacing: 0.15em;
  text-transform: uppercase;
  cursor: pointer;
  transition: all 0.18s;
}
.lb-tab.active {
  border-bottom-color: var(--accent);
  color: var(--accent);
}
.lb-list {
  flex: 1;
  max-width: 460px;
  align-self: center;
  width: 100%;
  padding: clamp(14px, 3vw, 20px) clamp(18px, 5vw, 32px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
}
.lb-entry {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  animation: badgePop 0.3s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
.lb-rank {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--ink-dim);
  min-width: 24px;
  text-align: center;
}
.lb-entry:nth-child(1) .lb-rank {
  color: #d4a820;
}
.lb-entry:nth-child(2) .lb-rank {
  color: #a0a8b0;
}
.lb-entry:nth-child(3) .lb-rank {
  color: #c07840;
}
.lb-time {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--accent);
  flex: 1;
}
.lb-meta {
  font-size: 0.55rem;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
  text-transform: uppercase;
  text-align: right;
}
.lb-empty {
  text-align: center;
  color: var(--ink-dim);
  font-size: 0.75rem;
  padding: 40px 0;
  letter-spacing: 0.1em;
}
.lb-clear {
  align-self: center;
  background: none;
  border: 1px solid var(--ink-faint);
  border-radius: var(--radius);
  color: var(--ink-dim);
  font-size: 0.58rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  padding: 7px 16px;
  cursor: pointer;
  margin: 0 0 24px;
  transition: all 0.18s;
}
.lb-clear:hover {
  border-color: var(--error-txt);
  color: var(--error-txt);
}

/* ════════════════════════════════════════════════
   ACHIEVEMENTS PAGE (reuses .lb-list / .lb-entry)
════════════════════════════════════════════════ */
.lb-entry.locked {
  opacity: 0.45;
}
.lb-entry.locked .lb-rank {
  color: var(--ink-faint);
}
.lb-entry.locked .lb-time {
  color: var(--ink-dim);
}
.lb-entry.ach-entry .lb-rank svg {
  width: 1.3em;
  height: 1.3em;
  fill: currentColor;
}
.lb-entry:not(.locked).ach-entry .lb-rank {
  color: var(--accent);
}

/* "See More" pill in the lobby badges row */
.lobby-badge-more {
  cursor: pointer;
  font-family: "DM Sans", sans-serif;
  border-color: var(--accent);
  color: var(--accent);
}
.lobby-badge-more:hover {
  background: var(--accent-bg);
}

/* ════════════════════════════════════════════════
   AD POPUP SCREEN
════════════════════════════════════════════════ */

/* Ad popup — full-screen layout, no card wrapper */
.sponsor-card {
  max-width: 400px !important;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}

.sponsor-header {
  text-align: center;
  margin-bottom: 20px;
  width: 100%;
}
.sponsor-series-label {
  font-size: 0.55rem;
  letter-spacing: 0.5em;
  color: var(--ink-mid);
  text-transform: uppercase;
  margin-bottom: 6px;
}
.sponsor-title {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(2.2rem, 6.5vw, 3.2rem);
  font-weight: 600;
  color: var(--ink);
  line-height: 1.15;
  margin-bottom: 6px;
}
.sponsor-sub {
  font-size: 0.62rem;
  letter-spacing: 0.28em;
  color: var(--ink-mid);
  text-transform: uppercase;
}

.sponsor-slot-wrap {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
}
.sponsor-slot-label {
  font-size: 0.5rem;
  letter-spacing: 0.4em;
  color: var(--ink-mid);
  text-transform: uppercase;
  align-self: center;
  text-align: center;
}
.sponsor-iframe {
  width: 300px;
  height: 250px;
  border: 0;
  display: block;
}
.sponsor-slot {
  width: 300px;
  height: 250px;
  border: 1.5px dashed var(--accent);
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}
.sponsor-placeholder {
  text-align: center;
  color: var(--ink-dim);
  padding: 20px;
}
.sponsor-placeholder-size {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: 1.4rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 8px;
  letter-spacing: 0.04em;
}
.sponsor-placeholder-hint {
  font-size: 0.65rem;
  letter-spacing: 0.08em;
  line-height: 1.7;
  color: var(--ink-mid);
}

.sponsor-footer {
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: 100%;
}
.sponsor-thanks {
  font-size: 0.5rem;
  letter-spacing: 0.4em;
  color: var(--ink-mid);
  text-transform: uppercase;
}
.sponsor-skip-btn {
  padding: 0.75em 2em;
  background: var(--btn-primary-bg);
  border: none;
  border-radius: var(--radius);
  color: var(--btn-primary-color);
  font-family: "DM Sans", sans-serif;
  font-size: 0.75rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  cursor: pointer;
  transition:
    background 0.2s,
    opacity 0.2s;
  width: 100%;
}
.sponsor-skip-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
.sponsor-skip-btn:not(:disabled):hover {
  background: var(--accent);
}

/* ════════════════════════════════════════════════
   DAILY CHALLENGE DIFF CARD
════════════════════════════════════════════════ */
.diff-card[data-diff="daily"] {
  grid-column: 1 / -1;
}
.diff-card[data-diff="daily"] .diff-name {
  position: relative;
}
.daily-badge {
  display: inline-block;
  font-size: 0.38rem;
  letter-spacing: 0.18em;
  color: var(--btn-primary-color);
  background: var(--accent);
  padding: 2px 6px;
  border-radius: 10px;
  text-transform: uppercase;
  vertical-align: middle;
  margin-left: 4px;
}

/* Daily done state */
.diff-card[data-diff="daily"].daily-done {
  opacity: 0.6;
  cursor: not-allowed;
}
.diff-card[data-diff="daily"].daily-done::after {
  content: "\2713 Done today";
  display: block;
  font-size: 0.48rem;
  letter-spacing: 0.18em;
  color: var(--success);
  margin-top: 3px;
  text-transform: uppercase;
}

/* ════════════════════════════════════════════════
   STAT-TIME hidden state (when timer disabled)
════════════════════════════════════════════════ */
#stat-time-wrap.hidden {
  display: none;
}

/* ════════════════════════════════════════════════
   RESET & BASE
════════════════════════════════════════════════ */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  width: 100%;
  height: 100%;
  color: var(--ink);
  font-family: "DM Sans", system-ui, sans-serif;
  overflow: hidden;
  transition:
    background 0.4s,
    color 0.4s;
}

/* ── BACKGROUND: image + per-theme gradient overlay ─── */
body::after {
  content: "";
  position: fixed;
  inset: 0;
  background-image: url("../images/background.jpg");
  background-size: cover;
  background-position: center;
  z-index: -2;
}

body[data-bg="2"]::after {
  background-image: url("../images/background2.jpg");
}

body[data-bg="3"]::after {
  background-image: url("../images/background3.jpg");
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: var(--bg-overlay, rgba(212, 184, 150, 0.45));
  z-index: -1;
  transition: background 0.4s;
}

/* Jungle — overlay is so dark we simulate dense foliage atop the bg */
body[data-theme="jungle"]::before {
  background: var(--bg-overlay);
}

/* Neon — scanlines effect */
body[data-theme="neon"]::before {
  background: var(--bg-overlay);
}
body[data-theme="neon"]::after {
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255, 45, 120, 0.025) 2px,
      rgba(255, 45, 120, 0.025) 4px
    ),
    url("../images/background.jpg");
  background-size: auto, cover;
  background-position: auto, center;
}

body[data-theme="neon"][data-bg="2"]::after {
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255, 45, 120, 0.025) 2px,
      rgba(255, 45, 120, 0.025) 4px
    ),
    url("../images/background2.jpg");
  background-size: auto, cover;
  background-position: auto, center;
}

body[data-theme="neon"][data-bg="3"]::after {
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255, 45, 120, 0.025) 2px,
      rgba(255, 45, 120, 0.025) 4px
    ),
    url("../images/background3.jpg");
  background-size: auto, cover;
  background-position: auto, center;
}

/* ════════════════════════════════════════════════
   SCREENS
════════════════════════════════════════════════ */
.screen {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  transition:
    opacity 0.35s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  background: transparent;
}
.screen.out {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.97) translateY(10px);
}

#s-loading {
  background: transparent;
}

/* ════════════════════════════════════════════════
   SHARED BRAND
════════════════════════════════════════════════ */
.loading-brand,
.brand {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(3.6rem, 12vw, 7.2rem);
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1.05;
  text-align: center;
  white-space: nowrap;
  margin-bottom: clamp(18px, 3.5vh, 32px);
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.18);
}
.loading-brand-dot,
.brand-dot {
  color: var(--accent);
}

.loading-sub {
  font-size: clamp(0.65rem, 2.2vw, 0.85rem);
  letter-spacing: 0.55em;
  text-indent: 0.55em;
  text-align: center;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-bottom: clamp(24px, 5vh, 40px);
}
.brand-sub {
  font-size: clamp(0.65rem, 2.2vw, 0.85rem);
  letter-spacing: 0.55em;
  text-indent: 0.55em;
  text-align: center;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-bottom: 0;
  text-shadow: 0 1px 8px rgba(255, 255, 255, 0.4);
}

/* Light themes: boost slogan contrast over varied backgrounds */
body[data-theme="warm"] .brand-sub,
body[data-theme="rosegold"] .brand-sub {
  color: var(--ink-mid);
  text-shadow: 0 1px 6px rgba(255, 255, 255, 0.6);
}

/* Jungle brand glow */
body[data-theme="jungle"] .brand,
body[data-theme="jungle"] .loading-brand {
  text-shadow:
    0 0 30px rgba(88, 208, 96, 0.5),
    0 2px 16px rgba(0, 0, 0, 0.6);
}

/* Neon brand glow */
body[data-theme="neon"] .brand,
body[data-theme="neon"] .loading-brand {
  text-shadow:
    0 0 20px rgba(255, 45, 120, 0.8),
    0 0 60px rgba(255, 45, 120, 0.4);
}

/* Midnight brand glow */
body[data-theme="midnight"] .brand,
body[data-theme="midnight"] .loading-brand {
  text-shadow:
    0 0 24px rgba(124, 92, 191, 0.6),
    0 2px 12px rgba(0, 0, 0, 0.5);
}

/* ════════════════════════════════════════════════
   LOADING SCREEN
════════════════════════════════════════════════ */
#s-loading {
  gap: 0;
  z-index: 50;
}

.loading-bar-wrap {
  width: clamp(160px, 44vw, 240px);
  height: 2px;
  background: var(--ink-faint);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 16px;
}
.loading-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-lt));
  border-radius: 2px;
  transition: width 0.08s linear;
}
.loading-hint {
  font-size: 0.6rem;
  letter-spacing: 0.32em;
  text-indent: 0.32em;
  text-align: center;
  color: var(--ink-dim);
  text-transform: uppercase;
}

/* ════════════════════════════════════════════════
   LOBBY SCREEN
════════════════════════════════════════════════ */
#s-lobby {
  padding: clamp(40px, 7vh, 70px) clamp(20px, 5vw, 40px);
  gap: 0;
  justify-content: space-between;
  align-items: center;
}

/* ── Lobby top zone: brand + rule line ── */
.lobby-top {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  padding-top: clamp(8px, 2vh, 20px);
}

/* ── Lobby center zone: play button ── */
.lobby-center {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

/* ── Lobby bottom zone: XP, stats, badges, icons ── */
.lobby-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(10px, 2vh, 18px);
  width: 100%;
  max-width: 420px;
  padding-bottom: clamp(8px, 2vh, 16px);
}

.rule-line {
  width: clamp(140px, 40vw, 220px);
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--grid-thick),
    transparent
  );
  margin: clamp(14px, 3vh, 24px) auto 0;
}

/* Neon rule line */
body[data-theme="neon"] .rule-line {
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 8px var(--accent);
}

/* Jungle rule line */
body[data-theme="jungle"] .rule-line {
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

/* Big play button — modern fancy style with glow ring + pulse */
.lobby-center {
  position: relative;
}
.lobby-center::before {
  content: "";
  position: absolute;
  inset: 50%;
  width: clamp(160px, 34vw, 220px);
  height: clamp(160px, 34vw, 220px);
  transform: translate(-50%, -50%);
  border-radius: 28%;
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  opacity: 0.25;
  filter: blur(18px);
  animation: playGlowPulse 2.6s ease-in-out infinite;
  pointer-events: none;
  z-index: 0;
}
@keyframes playGlowPulse {
  0%,
  100% {
    transform: translate(-50%, -50%) scale(0.92);
    opacity: 0.2;
  }
  50% {
    transform: translate(-50%, -50%) scale(1.08);
    opacity: 0.4;
  }
}

.btn-play-big {
  width: clamp(130px, 26vw, 172px);
  height: clamp(130px, 26vw, 172px);
  margin: clamp(16px, 4vh, 32px) 0;
  border-radius: 28%;
  background: linear-gradient(
    145deg,
    var(--accent) 0%,
    var(--btn-primary-bg) 100%
  );
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
  transition:
    transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1),
    box-shadow 0.25s ease,
    border-radius 0.25s ease;
  box-shadow:
    0 16px 40px rgba(0, 0, 0, 0.35),
    0 0 0 6px var(--card-bg),
    0 0 0 8px color-mix(in srgb, var(--accent) 35%, transparent),
    inset 0 2px 6px rgba(255, 255, 255, 0.25),
    inset 0 -6px 14px rgba(0, 0, 0, 0.25);
  flex-shrink: 0;
  animation: playFloat 3.2s ease-in-out infinite;
}
@keyframes playFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-6px);
  }
}
.btn-play-big::after {
  content: "";
  position: absolute;
  inset: 8%;
  border-radius: 22%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  pointer-events: none;
}
.btn-play-big:hover {
  transform: translateY(-4px) scale(1.08);
  box-shadow:
    0 22px 56px rgba(0, 0, 0, 0.4),
    0 0 0 6px var(--card-bg),
    0 0 0 10px color-mix(in srgb, var(--accent) 55%, transparent),
    inset 0 2px 6px rgba(255, 255, 255, 0.3),
    inset 0 -6px 14px rgba(0, 0, 0, 0.25);
}
.btn-play-big:active {
  transform: translateY(-1px) scale(1.02);
}
/* The grid SVG icon */
.btn-play-icon {
  width: 56%;
  height: 56%;
  display: block;
  position: relative;
  z-index: 1;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.25));
}
/* Grid cells fill with primary color */
.btn-play-icon rect {
  fill: var(--btn-primary-color);
  opacity: 0.32;
  transition: opacity 0.2s;
}
.btn-play-big:hover .btn-play-icon rect {
  opacity: 0.42;
}
/* Center cell slightly brighter */
.btn-play-center-cell {
  opacity: 0.16 !important;
}
/* Play arrow on top */
.btn-play-arrow {
  fill: var(--btn-primary-color);
  opacity: 1;
  transform-origin: center;
  transition: transform 0.25s ease;
}
.btn-play-big:hover .btn-play-arrow {
  transform: scale(1.12);
}

/* Neon play button glow */
body[data-theme="neon"] .btn-play-big {
  background: linear-gradient(145deg, var(--accent) 0%, #1a0a14 100%);
  box-shadow:
    0 0 0 6px var(--card-bg),
    0 0 0 9px var(--accent),
    0 14px 50px rgba(255, 45, 120, 0.5),
    inset 0 2px 6px rgba(255, 255, 255, 0.2);
}
body[data-theme="neon"] .lobby-center::before {
  background: radial-gradient(circle, var(--accent) 0%, transparent 70%);
  opacity: 0.4;
}
body[data-theme="neon"] .btn-play-big:hover {
  box-shadow:
    0 0 0 6px var(--card-bg),
    0 0 0 10px var(--accent),
    0 18px 64px rgba(255, 45, 120, 0.7),
    inset 0 2px 6px rgba(255, 255, 255, 0.25);
}

/* Jungle play button glow */
body[data-theme="jungle"] .btn-play-big {
  background: linear-gradient(145deg, var(--accent) 0%, #1c3a22 100%);
  box-shadow:
    0 0 0 6px var(--card-bg),
    0 0 0 9px rgba(88, 208, 96, 0.45),
    0 14px 40px rgba(0, 0, 0, 0.6),
    inset 0 2px 6px rgba(255, 255, 255, 0.2);
}

/* Midnight play button glow */
body[data-theme="midnight"] .btn-play-big {
  background: linear-gradient(145deg, var(--accent) 0%, #1c1a30 100%);
  box-shadow:
    0 0 0 6px var(--card-bg),
    0 0 0 9px rgba(124, 92, 191, 0.4),
    0 14px 40px rgba(124, 92, 191, 0.3),
    inset 0 2px 6px rgba(255, 255, 255, 0.2);
}

/* Lobby stats strip */
.lobby-meta {
  width: 100%;
  max-width: 380px;
  margin-bottom: 0;
}
.lobby-stat-row {
  display: flex;
  align-items: stretch;
  justify-content: center;
  gap: 10px;
  background: none;
  border: none;
  padding: 0;
}
.lobby-stat {
  flex: 1;
  text-align: center;
  padding: 14px 10px 12px;
  background: var(--card-bg);
  border: 1px solid var(--ink-faint);
  border-radius: 14px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition:
    border-color 0.2s,
    transform 0.15s;
}
.lobby-stat:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.lobby-stat-val {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(1.3rem, 4.5vw, 1.8rem);
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.lobby-stat-lbl {
  font-size: 0.5rem;
  letter-spacing: 0.25em;
  color: var(--ink-dim);
  text-transform: uppercase;
}
.lobby-stat-divider {
  display: none;
}

/* Neon stat cards */
body[data-theme="neon"] .lobby-stat {
  border-color: #1e1e3a;
  border-radius: 0;
}
body[data-theme="neon"] .lobby-stat:hover {
  border-color: var(--accent);
  box-shadow: 0 0 12px rgba(255, 45, 120, 0.2);
}

/* Icon button row */
.lobby-icon-row {
  display: flex;
  gap: clamp(14px, 4vw, 22px);
  align-items: center;
  justify-content: center;
}
.icon-btn {
  width: clamp(52px, 13vw, 68px);
  height: clamp(52px, 13vw, 68px);
  border-radius: 50%;
  background: var(--card-bg);
  border: 1.5px solid var(--ink-faint);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    border-color 0.2s,
    color 0.2s,
    transform 0.15s,
    box-shadow 0.2s;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  color: var(--ink-mid);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.icon-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.icon-btn svg {
  width: 46%;
  height: 46%;
  fill: currentColor;
  display: block;
}
.icon-btn.sound-muted {
  color: var(--ink-faint);
}

/* Neon icon btns */
body[data-theme="neon"] .icon-btn {
  border-radius: 0;
}
body[data-theme="neon"] .icon-btn:hover {
  box-shadow: 0 0 16px rgba(255, 45, 120, 0.3);
}

/* ════════════════════════════════════════════════
   DIFFICULTY SCREEN
════════════════════════════════════════════════ */
#s-difficulty {
  gap: 0;
}

.diff-back-btn {
  position: absolute;
  top: clamp(14px, 3vw, 24px);
  left: clamp(14px, 3vw, 24px);
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 1.5px solid var(--ink-mid);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-mid);
  transition: all 0.18s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.diff-back-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--accent-bg);
}
.diff-back-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.diff-heading {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(3rem, 10vw, 6rem);
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1.05;
  margin-bottom: clamp(14px, 2.5vh, 24px);
  text-align: center;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.18);
}
.diff-heading.diff-heading-compact {
  font-size: clamp(1.9rem, 6.4vw, 3.6rem);
  white-space: nowrap;
}
.diff-heading-dot {
  color: var(--accent);
}

.diff-subheading {
  font-size: clamp(0.62rem, 2vw, 0.8rem);
  letter-spacing: 0.38em;
  text-indent: 0.38em;
  text-align: center;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-bottom: clamp(24px, 5vh, 40px);
}

.diff-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  width: 100%;
  max-width: 360px;
  margin-bottom: 24px;
}
.diff-card {
  background: var(--card-bg);
  border: 1.5px solid var(--card-border);
  border-radius: var(--radius);
  padding: clamp(14px, 3vw, 22px) 10px;
  cursor: pointer;
  text-align: center;
  transition:
    border-color 0.2s,
    transform 0.15s,
    box-shadow 0.2s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.diff-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.16);
}
.diff-card.selected {
  border-color: var(--accent);
  background: var(--accent-bg);
  box-shadow: 0 0 0 3px var(--accent-bg);
}
.diff-icon-wrap {
  width: 32px;
  height: 32px;
  margin: 0 auto 8px;
  color: var(--ink-dim);
  transition: color 0.2s;
}
.diff-card.selected .diff-icon-wrap,
.diff-card:hover .diff-icon-wrap {
  color: var(--accent);
}
.diff-icon-wrap svg {
  width: 100%;
  height: 100%;
}
.diff-name {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: 1rem;
  font-weight: 600;
  color: var(--ink);
  letter-spacing: 0.04em;
}
.diff-desc {
  font-size: 0.58rem;
  color: var(--ink-dim);
  margin-top: 3px;
}

/* Light themes: ensure card text stays readable over both backgrounds */
body[data-theme="warm"] .diff-name,
body[data-theme="rosegold"] .diff-name {
  color: var(--ink);
}
body[data-theme="warm"] .diff-desc,
body[data-theme="rosegold"] .diff-desc {
  color: var(--ink-mid);
}

.btn-begin {
  width: 100%;
  max-width: 360px;
  padding: 0.95em 2em;
  background: var(--btn-primary-bg);
  border: none;
  border-radius: var(--radius);
  color: var(--btn-primary-color);
  font-family: "DM Sans", sans-serif;
  font-size: 0.88rem;
  letter-spacing: 0.18em;
  cursor: pointer;
  text-transform: uppercase;
  transition:
    background 0.2s,
    transform 0.15s,
    box-shadow 0.2s;
}
.btn-begin:hover {
  background: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}

/* ════════════════════════════════════════════════
   THEME SELECT SCREEN
════════════════════════════════════════════════ */
#s-theme {
  gap: 0;
  overflow-y: auto;
}

/* Theme grid: 3-col same as diff-grid but allow 5th card full-width */
.theme-diff-grid {
  grid-template-columns: repeat(3, 1fr);
  max-width: 360px;
}

.theme-diff-card:last-child:nth-child(3n + 2) {
  grid-column: 2 / 4;
}
.theme-diff-card:last-child:nth-child(3n + 1) {
  grid-column: 1 / -1;
}

/* When there are exactly 5 cards, the 5th spans last 2 cols */
.theme-diff-grid .theme-diff-card:nth-child(4):last-child {
  grid-column: 1 / -1;
}
.theme-diff-grid .theme-diff-card:nth-child(5) {
  grid-column: 2 / 4;
}

/* Icon wrap holds the mini-preview */
.theme-icon-wrap {
  width: 100% !important;
  height: auto !important;
  margin-bottom: 8px !important;
  color: inherit !important;
}

.theme-icon-wrap .theme-preview {
  width: 100%;
  aspect-ratio: 1;
  border-radius: calc(var(--radius) - 4px);
  overflow: hidden;
  margin-bottom: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
}

/* Preview backgrounds */
.theme-preview--warm {
  background: linear-gradient(145deg, #f5f0e8, #ede4d0);
  border: 1.5px solid #b8a888;
}
.theme-preview--jungle {
  background: linear-gradient(145deg, #0d2010, #061008);
  border: 1.5px solid #3a7040;
  position: relative;
  overflow: hidden;
}
.theme-preview--jungle::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(
      circle at 20% 30%,
      rgba(88, 208, 96, 0.06) 0%,
      transparent 50%
    ),
    radial-gradient(
      circle at 80% 70%,
      rgba(64, 200, 152, 0.06) 0%,
      transparent 50%
    );
}
.theme-preview--neon {
  background: linear-gradient(145deg, #0c0c18, #060610);
  border: 1.5px solid #ff2d78;
  box-shadow: inset 0 0 20px rgba(255, 45, 120, 0.08);
  position: relative;
  overflow: hidden;
}
.theme-preview--neon::before {
  content: "";
  position: absolute;
  inset: 0;
  background: repeating-linear-gradient(
    0deg,
    transparent,
    transparent 3px,
    rgba(255, 45, 120, 0.03) 3px,
    rgba(255, 45, 120, 0.03) 4px
  );
}
.theme-preview--midnight {
  background: linear-gradient(145deg, #161b2e, #0a0d1e);
  border: 1.5px solid #7c5cbf;
}

/* Mini grid inside preview */
.tp-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0;
  width: 100%;
  height: 100%;
  border: 1.5px solid;
  position: relative;
  z-index: 1;
}

/* Warm mini cells */
.theme-preview--warm .tp-grid {
  border-color: #2a2520;
  border-radius: 2px;
  overflow: hidden;
}
.theme-preview--warm .tp-cell {
  background: #fefcf8;
  border-right: 1px solid #c8bfb0;
  border-bottom: 1px solid #c8bfb0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(7px, 2vw, 11px);
  font-weight: 600;
  color: #2a4a7f;
  aspect-ratio: 1;
}
.theme-preview--warm .tp-cell.tp-given {
  background: rgba(42, 37, 32, 0.06);
  color: #2a2520;
}
.theme-preview--warm .tp-cell.tp-sel {
  background: rgba(192, 82, 42, 0.14);
  color: #c0522a;
}
.theme-preview--warm .tp-cell.tp-br {
  border-right: 2px solid #7a6e60;
}
.theme-preview--warm .tp-cell.tp-bb {
  border-bottom: 2px solid #7a6e60;
}

/* Jungle mini cells */
.theme-preview--jungle .tp-grid {
  border-color: #58d060;
  border-radius: 1px;
  overflow: hidden;
}
.theme-preview--jungle .tp-cell {
  background: #0f2412;
  border-right: 1px solid #2a5030;
  border-bottom: 1px solid #2a5030;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(7px, 2vw, 11px);
  font-weight: 600;
  color: #40c898;
  aspect-ratio: 1;
}
.theme-preview--jungle .tp-cell.tp-given {
  background: rgba(200, 240, 176, 0.06);
  color: #c8f0b0;
}
.theme-preview--jungle .tp-cell.tp-sel {
  background: rgba(88, 208, 96, 0.2);
  color: #58d060;
}
.theme-preview--jungle .tp-cell.tp-br {
  border-right: 2px solid #3a7040;
}
.theme-preview--jungle .tp-cell.tp-bb {
  border-bottom: 2px solid #3a7040;
}

/* Neon mini cells */
.theme-preview--neon .tp-grid {
  border-color: #ff2d78;
  border-radius: 0;
  overflow: hidden;
}
.theme-preview--neon .tp-cell {
  background: #0c0c18;
  border-right: 1px solid #1e1e3a;
  border-bottom: 1px solid #1e1e3a;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(7px, 2vw, 11px);
  font-weight: 600;
  color: #00d8ff;
  aspect-ratio: 1;
}
.theme-preview--neon .tp-cell.tp-given {
  background: rgba(240, 240, 255, 0.04);
  color: #f0f0ff;
}
.theme-preview--neon .tp-cell.tp-sel {
  background: rgba(255, 45, 120, 0.22);
  color: #ff2d78;
}
.theme-preview--neon .tp-cell.tp-br {
  border-right: 2px solid #3030a0;
}
.theme-preview--neon .tp-cell.tp-bb {
  border-bottom: 2px solid #3030a0;
}

/* Midnight mini cells */
.theme-preview--midnight .tp-grid {
  border-color: #7c5cbf;
  border-radius: 2px;
  overflow: hidden;
}
.theme-preview--midnight .tp-cell {
  background: #161b2e;
  border-right: 1px solid #2a3048;
  border-bottom: 1px solid #2a3048;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(7px, 2vw, 11px);
  font-weight: 600;
  color: #4870d8;
  aspect-ratio: 1;
}
.theme-preview--midnight .tp-cell.tp-given {
  background: rgba(180, 190, 240, 0.06);
  color: #b4bef0;
}
.theme-preview--midnight .tp-cell.tp-sel {
  background: rgba(120, 90, 200, 0.22);
  color: #7c5cbf;
}
.theme-preview--midnight .tp-cell.tp-br {
  border-right: 2px solid #4848a0;
}
.theme-preview--midnight .tp-cell.tp-bb {
  border-bottom: 2px solid #4848a0;
}

.theme-new-icon {
  width: 11px;
  height: 11px;
  vertical-align: middle;
  color: var(--accent);
  display: inline-block;
  margin: 0 1px;
}

/* ════════════════════════════════════════════════
   PREPARING SCREEN
════════════════════════════════════════════════ */
#s-preparing {
  gap: 0;
}

.prep-spinner {
  width: clamp(52px, 13vw, 68px);
  height: clamp(52px, 13vw, 68px);
  margin-bottom: 22px;
  animation: spinCW 1.1s linear infinite;
}
.prep-spinner svg {
  width: 100%;
  height: 100%;
}

@keyframes spinCW {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}

.prep-title {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(1.5rem, 5.5vw, 2.2rem);
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.4em;
}
.prep-sub {
  font-size: 0.65rem;
  letter-spacing: 0.35em;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-bottom: clamp(24px, 5vh, 36px);
}
.prep-dots {
  display: flex;
  gap: 8px;
}
.prep-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
  animation: prepDot 1.2s ease-in-out infinite;
}
.prep-dot:nth-child(2) {
  animation-delay: 0.2s;
}
.prep-dot:nth-child(3) {
  animation-delay: 0.4s;
}
@keyframes prepDot {
  0%,
  80%,
  100% {
    background: var(--ink-faint);
    transform: scale(1);
  }
  40% {
    background: var(--accent);
    transform: scale(1.4);
  }
}

/* ════════════════════════════════════════════════
   GAME SCREEN
════════════════════════════════════════════════ */
#s-game {
  justify-content: flex-start;
  padding: 0;
  gap: 0;
  overflow-y: auto;
  align-items: stretch;
}

/* Full-width game topbar — mirrors .page-header style */
.game-page-header {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: clamp(14px, 3vw, 22px) clamp(18px, 5vw, 36px)
    clamp(12px, 2.5vw, 18px);
  border-bottom: 1px solid var(--paper3);
  flex-shrink: 0;
  background: var(--card-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.game-header-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

/* Main game body: board centered, sidebars flanking it in a flex row */
.game-body {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: clamp(12px, 2.5vw, 20px) clamp(12px, 3vw, 24px);
  gap: 0;
  position: relative;
  width: 100%;
  margin: 0 auto;
}
.game-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: clamp(8px, 1.5vw, 14px);
  flex: 0 0 auto;
  min-width: 0;
  width: auto;
}

/* Controls bar above board */
.game-above-board {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 22px;
  width: 100%;
  padding: 0 0 16px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--card-border);
  flex-wrap: wrap;
}

/* Left sidebar — vertical column of action buttons */
.game-action-sidebar {
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
  flex-shrink: 0;
  width: auto;
  padding-right: 12px;
}
.game-act-btn {
  width: clamp(48px, 6vw, 64px);
  height: clamp(48px, 6vw, 64px);
  border-radius: 50%;
  background: var(--card-bg);
  border: 1.5px solid var(--ink-faint);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  transition:
    border-color 0.2s,
    color 0.2s,
    transform 0.15s,
    box-shadow 0.2s;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
  color: var(--ink-mid);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.game-act-btn svg {
  width: 38%;
  height: 38%;
  fill: currentColor;
  display: block;
  flex-shrink: 0;
}
.game-act-btn span {
  font-family: "DM Sans", sans-serif;
  font-size: 0.42rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: inherit;
  line-height: 1;
}
.game-act-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.2);
}
.game-act-btn.primary {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
}
.game-act-btn.primary:hover {
  background: var(--accent);
  color: var(--btn-primary-color);
}
.game-act-btn.danger:hover {
  border-color: var(--error-txt);
  color: var(--error-txt);
}
body[data-theme="neon"] .game-act-btn {
  border-radius: 0;
}
body[data-theme="neon"] .game-act-btn:hover {
  box-shadow: 0 0 16px rgba(255, 45, 120, 0.3);
}

/* ── Responsive breakpoints ──────────────────────────────────── */

/* Medium screens: shrink side panels and tighten gaps so nothing
   overlaps the board before it has to wrap */
@media (max-width: 1100px) {
  .game-body {
    gap: 0;
  }
  .game-act-btn {
    width: clamp(40px, 5.5vw, 56px);
    height: clamp(40px, 5.5vw, 56px);
  }
  .game-act-btn span {
    font-size: 0.36rem;
  }
  .num-btn {
    width: clamp(38px, 6vw, 60px);
    height: clamp(38px, 6vw, 60px);
  }
}

/* Tablet / narrow: stack sidebar below board */
@media (max-width: 960px) {
  .game-body {
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: clamp(10px, 3vw, 20px) clamp(8px, 3vw, 16px);
    gap: clamp(8px, 2vw, 14px);
  }
  .game-action-sidebar {
    order: 2;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    width: 100%;
    padding-right: 0;
  }
  .game-center {
    order: 1;
    width: 100%;
    max-width: 100%;
    flex: 0 0 auto;
    align-items: center;
  }
  .game-above-board {
    justify-content: center;
    width: 100%;
  }
  .grid-wrap {
    margin: 0 auto;
  }
  .game-numpad-panel {
    width: 100%;
    align-items: center;
  }
  .numpad {
    width: 100%;
    justify-content: center;
  }
  .num-btn {
    flex: 1 1 0;
    height: auto;
    aspect-ratio: 1;
    min-width: 0;
    max-width: 52px;
  }
  .game-act-btn {
    width: clamp(48px, 13vw, 60px);
    height: clamp(48px, 13vw, 60px);
  }
  .game-act-btn span {
    font-size: 0.42rem;
  }
}

/* Tablet portrait: additional tightening */
@media (max-width: 768px) {
  .grid-wrap {
    width: min(380px, 88vw);
    max-width: 380px;
    padding: 8px;
  }
  .game-page-header {
    padding: clamp(10px, 2.5vw, 16px) clamp(12px, 3vw, 20px);
  }
  .top-title {
    font-size: clamp(1.1rem, 4vw, 1.5rem);
  }
  .diff-grid {
    max-width: 320px;
  }
  .btn-begin {
    max-width: 320px;
  }
  .popup-card {
    max-width: 300px;
  }
  .popup-brand {
    font-size: clamp(2.2rem, 8vw, 3.2rem);
  }
  .lb-tabs,
  .lb-list {
    max-width: 360px;
  }
  .lobby-bottom {
    max-width: 340px;
  }
  .lobby-stat-val {
    font-size: clamp(1.1rem, 4vw, 1.5rem);
  }
}

/* Small mobile: tighten everything further */
@media (max-width: 480px) {
  .game-act-btn {
    width: clamp(40px, 13vw, 50px);
    height: clamp(40px, 13vw, 50px);
    gap: 2px;
  }
  .game-act-btn span {
    font-size: 0.36rem;
  }
  .game-act-btn svg {
    width: 34%;
    height: 34%;
  }
  .num-btn {
    font-size: clamp(0.9rem, 4vw, 1.2rem);
  }
  .toggle-lbl {
    font-size: 0.56rem;
  }
}

.top-title {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(1.5rem, 5vw, 2rem);
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
}
.top-title-dot {
  color: var(--accent);
}
.top-diff-badge {
  font-size: 0.6rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--accent);
  background: var(--accent-bg);
  padding: 0.3em 0.75em;
  border-radius: 20px;
  border: 1px solid var(--accent-bg);
  display: inline-block;
  align-self: flex-start;
  margin-top: 3px;
}
/* Neon badge */
body[data-theme="neon"] .top-diff-badge {
  border-radius: 0;
  border-color: rgba(255, 45, 120, 0.5);
  box-shadow: 0 0 8px rgba(255, 45, 120, 0.2);
}
.top-stats {
  display: flex;
  gap: 16px;
  align-items: center;
}
.stat-item {
  text-align: right;
}
.stat-val {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
}
.stat-lbl {
  font-size: 0.52rem;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
  text-transform: uppercase;
}

/* Grid wrap — theme-specific backgrounds */
.grid-wrap {
  width: min(440px, 88vw);
  max-width: 440px;
  margin-bottom: clamp(10px, 2vw, 18px);
  padding: 10px;
  background: var(--grid-wrap-bg);
  border-radius: 8px;
  box-shadow: var(--grid-wrap-shadow);
  box-sizing: border-box;
}

/* Equation Match mode packs 4 small labels into every tile, so it
   needs a bigger board than the regular cage grid to stay readable */
.grid-wrap:has(#equation-grid.match-mode) {
  width: min(560px, 92vw);
  max-width: 560px;
}

/* Warm: subtle parchment frame */
body[data-theme="warm"] .grid-wrap {
  border: 1px solid var(--grid-wrap-border);
}

/* Jungle: dense forest floor, leafy border */
body[data-theme="jungle"] .grid-wrap {
  border: 1px solid var(--grid-wrap-border);
  position: relative;
  overflow: hidden;
}
body[data-theme="jungle"] .grid-wrap::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(
      ellipse at 10% 20%,
      rgba(88, 208, 96, 0.08) 0%,
      transparent 40%
    ),
    radial-gradient(
      ellipse at 90% 80%,
      rgba(64, 200, 152, 0.06) 0%,
      transparent 40%
    );
  pointer-events: none;
  z-index: 0;
}
body[data-theme="jungle"] #equation-grid {
  position: relative;
  z-index: 1;
}

/* Neon: electric grid frame */
body[data-theme="neon"] .grid-wrap {
  padding: 12px;
  border-radius: 0;
}

/* Midnight: deep space */
body[data-theme="midnight"] .grid-wrap {
  border-radius: 8px;
}

#equation-grid {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  border: 2.5px solid var(--box-border);
  border-radius: 3px;
  overflow: hidden;
  background: var(--grid-bg);
  box-shadow: var(--shadow);
  width: 100%;
  aspect-ratio: 1;
}

/* Neon grid — sharp corners, glowing border */
body[data-theme="neon"] #equation-grid {
  border-radius: 0;
  border-width: 2px;
  box-shadow:
    0 0 0 1px rgba(255, 45, 120, 0.4),
    0 0 30px rgba(255, 45, 120, 0.2);
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  background: var(--cell-bg);
  border-right: 1px solid var(--grid-thin);
  border-bottom: 1px solid var(--grid-thin);
  transition: background 0.1s;
  aspect-ratio: 1;
}

/* Neon cells get scanline inset */
body[data-theme="neon"] .cell {
  background: #0c0c18;
}
body[data-theme="neon"] .cell:nth-child(odd) {
  background: #0e0e1c;
}

/* Jungle cells — very slightly varied */
body[data-theme="jungle"] .cell {
  background: #0f2412;
}
body[data-theme="jungle"] .cell:nth-child(even) {
  background: #0d2010;
}

/* ── NUMBER CROSSWORD MODE ──────────────────────────────────────── */
.cell.cw-blocked {
  background: transparent !important;
  border-color: transparent !important;
  box-shadow: none !important;
  cursor: default;
}
.cell.cw-cell {
  cursor: pointer;
}
.cw-number {
  position: absolute;
  top: 2px;
  left: 3px;
  font-family: "DM Sans", sans-serif;
  font-weight: 700;
  color: var(--ink-dim);
  line-height: 1;
  pointer-events: none;
  user-select: none;
  z-index: 2;
}
.crossword-clues {
  display: none;
  width: 100%;
  max-width: 500px;
  gap: 18px;
  background: var(--card-bg);
  border-radius: 10px;
  padding: 14px 16px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.08);
}
.crossword-clues.visible {
  display: flex;
}
.cw-clue-col {
  flex: 1;
  min-width: 0;
}
.cw-clue-heading {
  font-family: "Crimson Pro", Georgia, serif;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--ink);
  margin-bottom: 6px;
  border-bottom: 1px solid var(--ink-faint);
  padding-bottom: 4px;
}
.cw-clue-list {
  display: flex;
  flex-direction: column;
  gap: 5px;
  max-height: 160px;
  overflow-y: auto;
}
.cw-clue-row {
  font-size: 0.78rem;
  color: var(--ink-mid);
  cursor: pointer;
  line-height: 1.35;
}
.cw-clue-row:hover {
  color: var(--accent);
}
.cw-clue-row.solved {
  color: var(--ink-faint);
  text-decoration: line-through;
}
.cw-clue-row b {
  color: var(--ink);
}
.cw-clue-row.solved b {
  color: var(--ink-faint);
}

/* ── EQUATION MATCH MODE — tile corner labels ───────────────────── */
#equation-grid.match-mode,
#equation-grid.crossword-mode {
  gap: 0;
}
.cell.match-tile {
  cursor: pointer;
  overflow: hidden;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  padding: 3px;
  box-sizing: border-box;
}
.match-edge {
  font-family: "Crimson Pro", Georgia, serif;
  font-weight: 700;
  font-size: 13px;
  line-height: 1.15;
  color: var(--cell-text, #333);
  pointer-events: none;
  user-select: none;
  white-space: normal;
  overflow-wrap: break-word;
  max-width: 100%;
}
.match-edge-top {
  grid-column: 1;
  grid-row: 1;
  align-self: start;
  justify-self: start;
  text-align: left;
}
.match-edge-right {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
  justify-self: end;
  text-align: right;
}
.match-edge-bottom {
  grid-column: 2;
  grid-row: 2;
  align-self: end;
  justify-self: end;
  text-align: right;
}
.match-edge-left {
  grid-column: 1;
  grid-row: 2;
  align-self: end;
  justify-self: start;
  text-align: left;
}
.match-edge-eq {
  color: var(--grid-thick);
}
.match-edge-ans {
  color: var(--accent, #4a7dff);
  font-style: italic;
}
.cell.match-tile.selected {
  outline: 3px solid var(--accent, #4a7dff);
  outline-offset: -3px;
  z-index: 3;
}

/* Cage borders — replace the classic 3x3-box lines with irregular
   equation-cage boundaries computed in JS (cage-edge-*) */
.cell.cage-edge-top {
  border-top: 2px solid var(--grid-thick);
}
.cell.cage-edge-right {
  border-right: 2px solid var(--grid-thick);
}
.cell.cage-edge-bottom {
  border-bottom: 2px solid var(--grid-thick);
}
.cell.cage-edge-left {
  border-left: 2px solid var(--grid-thick);
}
.cell:nth-child(9n) {
  border-right: none;
}
.cell:nth-child(n + 73) {
  border-bottom: none;
}
.cell.given {
  background: var(--given-bg);
}

/* Theme-specific given cells */
body[data-theme="warm"] .cell.given {
  background: rgba(42, 37, 32, 0.05);
}
body[data-theme="jungle"] .cell.given {
  background: rgba(88, 208, 96, 0.07);
}
body[data-theme="neon"] .cell.given {
  background: rgba(255, 45, 120, 0.06);
}
body[data-theme="midnight"] .cell.given {
  background: rgba(124, 92, 191, 0.06);
}

.cell.selected {
  background: rgba(192, 82, 42, 0.16) !important;
}
body[data-theme="jungle"] .cell.selected {
  background: rgba(88, 208, 96, 0.22) !important;
}
body[data-theme="neon"] .cell.selected {
  background: rgba(255, 45, 120, 0.28) !important;
}
body[data-theme="midnight"] .cell.selected {
  background: rgba(124, 92, 191, 0.28) !important;
}

.cell.row-hl {
  background: var(--row-hl);
}
.cell.same-num {
  background: var(--same-hl);
}
.cell.error {
  background: var(--error-bg);
}

/* Neon cage borders glow */
body[data-theme="neon"] .cell.cage-edge-top {
  border-top: 2px solid rgba(255, 45, 120, 0.6);
}
body[data-theme="neon"] .cell.cage-edge-right {
  border-right: 2px solid rgba(255, 45, 120, 0.6);
}
body[data-theme="neon"] .cell.cage-edge-bottom {
  border-bottom: 2px solid rgba(255, 45, 120, 0.6);
}
body[data-theme="neon"] .cell.cage-edge-left {
  border-left: 2px solid rgba(255, 45, 120, 0.6);
}

/* Jungle cage borders glow */
body[data-theme="jungle"] .cell.cage-edge-top {
  border-top: 2px solid rgba(88, 208, 96, 0.5);
}
body[data-theme="jungle"] .cell.cage-edge-right {
  border-right: 2px solid rgba(88, 208, 96, 0.5);
}
body[data-theme="jungle"] .cell.cage-edge-bottom {
  border-bottom: 2px solid rgba(88, 208, 96, 0.5);
}
body[data-theme="jungle"] .cell.cage-edge-left {
  border-left: 2px solid rgba(88, 208, 96, 0.5);
}

/* Equation clue label — sits in the top-left corner of a cage's anchor cell */
.cage-clue {
  position: absolute;
  top: 2px;
  left: 3px;
  font-family: "Crimson Pro", Georgia, serif;
  font-weight: 700;
  color: var(--grid-thick);
  line-height: 1;
  pointer-events: none;
  user-select: none;
  z-index: 2;
  letter-spacing: 0.2px;
}
body[data-theme="neon"] .cage-clue {
  color: #ff2d78;
  text-shadow: 0 0 6px rgba(255, 45, 120, 0.5);
}
body[data-theme="jungle"] .cage-clue {
  color: #58d060;
  text-shadow: 0 0 6px rgba(88, 208, 96, 0.4);
}
body[data-theme="midnight"] .cage-clue {
  color: #9a8de0;
}

.cell-num {
  font-family: "Crimson Pro", Georgia, serif;
  font-weight: 600;
  color: var(--ink);
  line-height: 1;
  pointer-events: none;
  user-select: none;
}
.cell.given .cell-num {
  color: var(--ink);
}
.cell:not(.given) .cell-num {
  color: var(--blue);
}
.cell.error .cell-num {
  color: var(--error-txt);
}

/* Jungle user numbers */
body[data-theme="jungle"] .cell:not(.given) .cell-num {
  color: #58d060;
  text-shadow: 0 0 8px rgba(88, 208, 96, 0.4);
}

/* Neon given numbers — pink; user numbers — cyan */
body[data-theme="neon"] .cell.given .cell-num {
  color: #f0f0ff;
}
body[data-theme="neon"] .cell:not(.given) .cell-num {
  color: #00d8ff;
  text-shadow: 0 0 8px rgba(0, 216, 255, 0.5);
}

/* Midnight user numbers */
body[data-theme="midnight"] .cell:not(.given) .cell-num {
  color: #6a90e8;
}

.pencil-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  width: 90%;
  height: 90%;
  pointer-events: none;
}
.pencil-mark {
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "DM Sans", sans-serif;
  color: var(--ink-mid);
  line-height: 1;
}

/* ── Numpad panel — below the board, horizontal row ── */
.game-numpad-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  align-items: center;
}

.numpad {
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
  gap: clamp(4px, 0.8vw, 8px);
  justify-content: center;
  width: 100%;
}
.num-btn {
  width: clamp(36px, 5vw, 52px);
  height: clamp(36px, 5vw, 52px);
  border: 1.5px solid var(--ink-faint);
  border-radius: 12px;
  background: var(--card-bg);
  color: var(--ink);
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(0.9rem, 1.8vw, 1.2rem);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  user-select: none;
}
.num-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-bg);
  transform: scale(1.05);
}
.num-btn:active {
  transform: scale(0.95);
}
.num-btn.erase-btn {
  font-size: clamp(0.9rem, 2vw, 1.2rem);
  color: var(--ink-mid);
  font-family: "DM Sans", sans-serif;
}
.num-btn.pencil-btn {
  font-size: clamp(0.85rem, 1.8vw, 1.1rem);
  font-family: "DM Sans", sans-serif;
  color: var(--ink-mid);
}
.num-btn.pencil-btn.active {
  border-color: var(--blue);
  background: var(--blue-lt);
  color: var(--blue);
}
.num-btn.complete {
  opacity: 0.25;
  pointer-events: none;
}

/* Neon numpad */
body[data-theme="neon"] .num-btn {
  border-radius: 0;
}
body[data-theme="neon"] .num-btn:hover {
  box-shadow: 0 0 10px rgba(255, 45, 120, 0.3);
}

/* Info row below numpad panel */
.numpad-info-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 2px 0;
  border-top: 1px solid var(--paper3);
}

.toggle-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.toggle-item {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  user-select: none;
}
.toggle-box {
  width: 16px;
  height: 16px;
  border: 1.5px solid var(--ink-faint);
  border-radius: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
  font-size: 0.7rem;
  color: white;
}
.toggle-item.on .toggle-box {
  background: var(--accent);
  border-color: var(--accent);
}
.toggle-lbl {
  font-size: 0.62rem;
  color: var(--ink-mid);
  letter-spacing: 0.08em;
}

.hint-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--ink-mid);
}
.mistake-dots {
  display: flex;
  gap: 6px;
}
.mistake-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--ink-faint);
  transition: background 0.3s;
}
.mistake-dot.used {
  background: var(--error-txt);
}
.mistake-overflow {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--error-txt);
  line-height: 1;
  margin-left: 1px;
}

/* ════════════════════════════════════════════════
   COMPLETE SCREEN
════════════════════════════════════════════════ */
#s-complete {
  gap: 0;
}

.complete-star {
  width: clamp(48px, 12vw, 64px);
  height: clamp(48px, 12vw, 64px);
  margin-bottom: 14px;
  animation: popIn 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.complete-star svg {
  width: 100%;
  height: 100%;
  fill: var(--accent);
}
body[data-theme="neon"] .complete-star svg {
  filter: drop-shadow(0 0 12px var(--accent));
}
body[data-theme="jungle"] .complete-star svg {
  filter: drop-shadow(0 0 10px rgba(88, 208, 96, 0.5));
}

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

.complete-title {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(2.2rem, 7vw, 3.4rem);
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 0.2em;
  text-align: center;
}
.complete-sub {
  font-size: 0.7rem;
  letter-spacing: 0.35em;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-bottom: clamp(20px, 4vh, 36px);
}
.complete-stats {
  display: flex;
  gap: 28px;
  margin-bottom: clamp(24px, 4vh, 40px);
}
.cstat {
  text-align: center;
}
.cstat-val {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(1.8rem, 6vw, 2.8rem);
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.cstat-lbl {
  font-size: 0.55rem;
  letter-spacing: 0.3em;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-top: 3px;
}
.complete-btns {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.btn-comp {
  padding: 0.75em 2em;
  border-radius: var(--radius);
  font-family: "DM Sans", sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.15em;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.2s;
}
.btn-comp.filled {
  background: var(--btn-primary-bg);
  border: none;
  color: var(--btn-primary-color);
}
.btn-comp.filled:hover {
  background: var(--accent);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
}
.btn-comp.outline {
  background: transparent;
  border: 1.5px solid var(--ink-faint);
  color: var(--ink-mid);
}
.btn-comp.outline:hover {
  border-color: var(--ink);
  color: var(--ink);
}

/* ════════════════════════════════════════════════
   PAGE CHROME (settings & info)
════════════════════════════════════════════════ */
.page-header {
  width: 100%;
  max-width: 460px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: clamp(18px, 4vw, 30px) clamp(18px, 5vw, 32px) clamp(16px, 3vw, 22px);
  border-bottom: 1px solid var(--paper3);
  flex-shrink: 0;
  align-self: center;
}
.page-back-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 1.5px solid var(--ink-mid);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-mid);
  transition: all 0.18s;
  flex-shrink: 0;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.page-back-btn:hover {
  border-color: var(--ink);
  color: var(--ink);
  background: var(--accent-bg);
}
.page-back-btn svg {
  width: 15px;
  height: 15px;
  fill: currentColor;
}
.page-title {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(1.5rem, 5.5vw, 2rem);
  font-weight: 600;
  color: var(--ink);
}

/* ════════════════════════════════════════════════
   SETTINGS PAGE
════════════════════════════════════════════════ */
#s-settings {
  justify-content: flex-start;
  align-items: stretch;
  padding: 0;
  overflow-y: auto;
}

#s-settings .page-header {
  align-self: center;
  flex-shrink: 0;
}

#s-settings .page-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 7px;
  align-self: center;
  width: 100%;
  max-width: 460px;
  padding: clamp(14px, 3vw, 24px) clamp(18px, 5vw, 32px);
}

.settings-section-label {
  font-size: 0.58rem;
  letter-spacing: 0.35em;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin: 14px 0 4px;
  padding-left: 2px;
}
.settings-section-label:first-child {
  margin-top: 0;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  gap: 12px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.settings-row--about {
  align-items: flex-start;
}
.settings-row-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}
.settings-row-icon {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  fill: var(--ink-dim);
}
.settings-row-info {
  flex: 1;
  min-width: 0;
}
.settings-row-label {
  font-size: 0.82rem;
  color: var(--ink);
  font-weight: 500;
  margin-bottom: 1px;
}
.settings-row-desc {
  font-size: 0.62rem;
  color: var(--ink-dim);
  letter-spacing: 0.01em;
}

/* Toggle switch */
.sw {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.sw input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.sw-track {
  position: absolute;
  inset: 0;
  background: var(--ink-faint);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}
.sw-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: white;
  transition: transform 0.2s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}
.sw input:checked + .sw-track {
  background: var(--accent);
}
.sw input:checked + .sw-track::after {
  transform: translateX(18px);
}

/* ── BACKGROUND PICKER ───────────────────────────────────────────── */
.bg-picker {
  display: flex;
  gap: 10px;
  padding: 4px 0 2px;
}

.bg-option {
  flex: 1;
  position: relative;
  border: 2px solid var(--card-border);
  border-radius: var(--radius);
  background: var(--card-bg);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  overflow: hidden;
  cursor: pointer;
  padding: 0;
  transition:
    border-color 0.18s,
    transform 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.bg-option:hover {
  transform: translateY(-1px);
  border-color: var(--ink-dim);
}

.bg-option.active {
  border-color: var(--accent);
}

.bg-option-thumb {
  width: 100%;
  height: 72px;
  background-size: cover;
  background-position: center;
  display: block;
}

.bg-thumb-1 {
  background-image: url("../images/background.jpg");
}

.bg-thumb-2 {
  background-image: url("../images/background2.jpg");
}

.bg-thumb-3 {
  background-image: url("../images/background3.jpg");
}

.bg-option-label {
  font-size: 0.6rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--ink-dim);
  text-align: center;
  padding: 6px 4px 8px;
  font-weight: 500;
}

.bg-option-check {
  position: absolute;
  top: 5px;
  right: 5px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--accent);
  display: none;
  align-items: center;
  justify-content: center;
}

.bg-option-check svg {
  width: 11px;
  height: 11px;
  fill: white;
}

.bg-option.active .bg-option-check {
  display: flex;
}

/* ════════════════════════════════════════════════
   INFO PAGE
════════════════════════════════════════════════ */
#s-info {
  justify-content: flex-start;
  align-items: stretch;
  padding: 0;
}

#s-info .page-header {
  align-self: center;
  flex-shrink: 0;
  padding-top: clamp(12px, 2.5vw, 18px);
  padding-bottom: clamp(10px, 2vw, 16px);
}

.info-body {
  flex: 1;
  width: 100%;
  max-width: 460px;
  padding: clamp(10px, 2.5vw, 18px) clamp(18px, 5vw, 32px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  align-self: center;
}

.info-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 12px 14px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.info-card-icon {
  width: 32px;
  height: 32px;
  flex-shrink: 0;
  background: var(--accent-bg);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.info-card-icon svg {
  width: 16px;
  height: 16px;
  fill: var(--accent);
}
.info-card-body {
  flex: 1;
  min-width: 0;
}
.info-card-title {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 3px;
}
.info-card-text {
  font-size: 0.72rem;
  color: var(--ink-mid);
  line-height: 1.55;
}

.info-three-col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
}
.info-mini-card {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  text-align: center;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.info-mini-card svg {
  width: 18px;
  height: 18px;
  fill: var(--accent);
}
.info-mini-card strong {
  font-size: 0.72rem;
  color: var(--ink);
  font-weight: 600;
  font-family: "Crimson Pro", Georgia, serif;
}
.info-mini-card span {
  font-size: 0.6rem;
  color: var(--ink-dim);
}

.info-shortcuts-grid {
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.info-sc-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.7rem;
  color: var(--ink-mid);
}
.kbd-inline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  height: 20px;
  padding: 0 5px;
  background: var(--paper2);
  border: 1px solid var(--ink-faint);
  border-bottom-width: 2px;
  border-radius: 4px;
  font-size: 0.62rem;
  color: var(--ink);
  font-family: monospace;
  flex-shrink: 0;
  white-space: nowrap;
}

/* ════════════════════════════════════════════════
   TOAST
════════════════════════════════════════════════ */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--ink);
  color: var(--paper);
  font-size: 0.72rem;
  letter-spacing: 0.1em;
  padding: 0.65em 1.6em;
  border-radius: 20px;
  z-index: 100;
  transition:
    transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1),
    opacity 0.3s;
  opacity: 0;
  white-space: nowrap;
  pointer-events: none;
}
#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}
#toast.success {
  background: var(--success);
  color: var(--paper);
}
#toast.error {
  background: var(--error-txt);
}

body[data-theme="neon"] #toast {
  border-radius: 0;
}
body[data-theme="jungle"] #toast.success {
  color: #0a1a0c;
}

/* ════════════════════════════════════════════════
   ANIMATIONS
════════════════════════════════════════════════ */
@keyframes cellPop {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(1.18);
  }
  100% {
    transform: scale(1);
  }
}
.cell-pop {
  animation: cellPop 0.15s ease;
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-4px);
  }
  40% {
    transform: translateX(4px);
  }
  60% {
    transform: translateX(-3px);
  }
  80% {
    transform: translateX(3px);
  }
}
.shake {
  animation: shake 0.3s ease;
}

@keyframes cellWin {
  0% {
    background: var(--cell-bg);
  }
  50% {
    background: var(--accent-bg);
  }
  100% {
    background: rgba(40, 120, 64, 0.1);
  }
}
.cell-win {
  animation: cellWin 0.6s ease forwards;
}

/* ════════════════════════════════════════════════
   IN-GAME POPUP SCREENS
   (Resume, New Game, Quit — full-screen lobby style)
════════════════════════════════════════════════ */

/* Overlay backdrop behind popup screen — solid lobby-style page */
.popup-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  /* Solid background matching the lobby: background image + theme overlay */
  background-image: url("../images/background.jpg");
  background-size: cover;
  background-position: center;
  transition:
    opacity 0.32s cubic-bezier(0.4, 0, 0.2, 1),
    transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
}

body[data-bg="2"] .popup-screen {
  background-image: url("../images/background2.jpg");
}

body[data-bg="3"] .popup-screen {
  background-image: url("../images/background3.jpg");
}
/* Theme overlay on top of the bg image — mirrors body::before */
.popup-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--bg-overlay, rgba(212, 184, 150, 0.45));
  transition: background 0.4s;
  pointer-events: none;
}
/* Neon scanlines on popup */
body[data-theme="neon"] .popup-screen {
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255, 45, 120, 0.025) 2px,
      rgba(255, 45, 120, 0.025) 4px
    ),
    url("../images/background.jpg");
  background-size: auto, cover;
  background-position: auto, center;
}
body[data-theme="neon"][data-bg="2"] .popup-screen {
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255, 45, 120, 0.025) 2px,
      rgba(255, 45, 120, 0.025) 4px
    ),
    url("../images/background2.jpg");
  background-size: auto, cover;
  background-position: auto, center;
}

body[data-theme="neon"][data-bg="3"] .popup-screen {
  background-image:
    repeating-linear-gradient(
      0deg,
      transparent,
      transparent 2px,
      rgba(255, 45, 120, 0.025) 2px,
      rgba(255, 45, 120, 0.025) 4px
    ),
    url("../images/background3.jpg");
  background-size: auto, cover;
  background-position: auto, center;
}
/* Ensure card sits above the pseudo-element overlay */
.popup-screen .popup-card {
  position: relative;
  z-index: 1;
}
.popup-screen.out {
  opacity: 0;
  pointer-events: none;
  transform: scale(1.02);
}

/* Central card — lobby style panel */
.popup-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  animation: popupSlideIn 0.28s cubic-bezier(0.34, 1.4, 0.64, 1) both;
}
@keyframes popupSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(20px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

/* Popup brand title */
.popup-brand {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(2.9rem, 10vw, 4.1rem);
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
  line-height: 1.05;
  white-space: nowrap;
  margin-bottom: clamp(8px, 1.5vh, 14px);
  text-align: center;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.2);
}
.popup-brand-dot {
  color: var(--accent);
}

/* Apply same glow overrides as main brand */
body[data-theme="jungle"] .popup-brand {
  text-shadow:
    0 0 30px rgba(88, 208, 96, 0.5),
    0 2px 16px rgba(0, 0, 0, 0.6);
}
body[data-theme="neon"] .popup-brand {
  text-shadow:
    0 0 20px rgba(255, 45, 120, 0.8),
    0 0 60px rgba(255, 45, 120, 0.4);
}
body[data-theme="midnight"] .popup-brand {
  text-shadow:
    0 0 24px rgba(124, 92, 191, 0.6),
    0 2px 12px rgba(0, 0, 0, 0.5);
}

.popup-sub {
  font-size: clamp(0.62rem, 2vw, 0.78rem);
  letter-spacing: 0.48em;
  color: var(--ink-dim);
  text-transform: uppercase;
  margin-bottom: clamp(18px, 4vh, 30px);
  text-align: center;
}

.popup-rule-line {
  width: clamp(100px, 30vw, 180px);
  height: 1px;
  background: linear-gradient(
    90deg,
    transparent,
    var(--grid-thick),
    transparent
  );
  margin: 0 auto clamp(20px, 4vh, 32px);
}
body[data-theme="neon"] .popup-rule-line {
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  box-shadow: 0 0 6px var(--accent);
}
body[data-theme="jungle"] .popup-rule-line {
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
}

/* Game info strip (time + moves) inside popups */
.popup-info-strip {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-bottom: clamp(16px, 3vh, 26px);
}
.popup-info-cell {
  flex: 1;
  text-align: center;
  padding: 12px 8px 10px;
  background: var(--card-bg);
  border: 1px solid var(--ink-faint);
  border-radius: 12px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
body[data-theme="neon"] .popup-info-cell {
  border-radius: 0;
}
.popup-info-val {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(1.2rem, 4vw, 1.6rem);
  font-weight: 600;
  color: var(--accent);
  line-height: 1;
}
.popup-info-lbl {
  font-size: 0.48rem;
  letter-spacing: 0.25em;
  color: var(--ink-dim);
  text-transform: uppercase;
}

/* Popup action buttons — big primary + secondary */
.popup-btn-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.popup-btn-primary {
  width: 100%;
  padding: 1em 2em;
  background: var(--btn-primary-bg);
  border: none;
  border-radius: var(--radius);
  color: var(--btn-primary-color);
  font-family: "DM Sans", sans-serif;
  font-size: 0.85rem;
  letter-spacing: 0.2em;
  cursor: pointer;
  text-transform: uppercase;
  transition:
    background 0.2s,
    transform 0.15s,
    box-shadow 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.popup-btn-primary:hover {
  background: var(--accent);
  transform: translateY(-1px);
  box-shadow: 0 6px 22px rgba(0, 0, 0, 0.25);
}
.popup-btn-primary svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

.popup-btn-secondary {
  width: 100%;
  padding: 0.8em 2em;
  background: var(--card-bg);
  border: 1.5px solid var(--ink-faint);
  border-radius: var(--radius);
  color: var(--ink-mid);
  font-family: "DM Sans", sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.15em;
  cursor: pointer;
  text-transform: uppercase;
  transition:
    border-color 0.2s,
    color 0.2s,
    transform 0.15s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.popup-btn-secondary:hover {
  border-color: var(--ink);
  color: var(--ink);
  transform: translateY(-1px);
}
.popup-btn-secondary svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex-shrink: 0;
}

.popup-btn-danger {
  width: 100%;
  padding: 0.8em 2em;
  background: transparent;
  border: 1.5px solid var(--ink-faint);
  border-radius: var(--radius);
  color: var(--ink-dim);
  font-family: "DM Sans", sans-serif;
  font-size: 0.78rem;
  letter-spacing: 0.15em;
  cursor: pointer;
  text-transform: uppercase;
  transition:
    border-color 0.2s,
    color 0.2s,
    transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.popup-btn-danger:hover {
  border-color: var(--error-txt);
  color: var(--error-txt);
  transform: translateY(-1px);
}
.popup-btn-danger svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
  flex-shrink: 0;
}

/* Neon popup buttons */
body[data-theme="neon"] .popup-btn-primary,
body[data-theme="neon"] .popup-btn-secondary,
body[data-theme="neon"] .popup-btn-danger {
  border-radius: 0;
}
body[data-theme="neon"] .popup-btn-primary:hover {
  box-shadow: 0 0 20px rgba(255, 45, 120, 0.4);
}

/* Pause icon button (top bar) */
.btn-pause {
  width: clamp(32px, 8vw, 40px);
  height: clamp(32px, 8vw, 40px);
  border-radius: 50%;
  background: var(--card-bg);
  border: 1.5px solid var(--ink-faint);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-mid);
  transition:
    border-color 0.2s,
    color 0.2s,
    transform 0.15s;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  flex-shrink: 0;
}
.btn-pause:hover {
  border-color: var(--accent);
  color: var(--accent);
  transform: scale(1.08);
}
.btn-pause svg {
  width: 44%;
  height: 44%;
  fill: currentColor;
}
body[data-theme="neon"] .btn-pause {
  border-radius: 0;
}

/* ════════════════════════════════════════════════
   EQUATION MATCH — TILE DETAIL POPUP
════════════════════════════════════════════════ */
.match-tile-detail-card {
  max-width: 360px;
  width: 100%;
}
.match-tile-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  margin-bottom: clamp(16px, 3vh, 24px);
}
.match-tile-detail-title {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  font-weight: 600;
  color: var(--ink);
  letter-spacing: -0.01em;
}
.match-tile-detail-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 1.5px solid var(--ink-faint);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-mid);
  transition: all 0.18s;
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}
.match-tile-detail-close:hover {
  border-color: var(--error-txt);
  color: var(--error-txt);
}
.match-tile-detail-close svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}
.match-tile-detail-body {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: clamp(18px, 3vh, 28px);
}
.match-detail-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
}
.match-detail-edge-lbl {
  font-size: 0.58rem;
  letter-spacing: 0.3em;
  color: var(--ink-dim);
  text-transform: uppercase;
  min-width: 52px;
  flex-shrink: 0;
}
.match-detail-edge-val {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(1rem, 3.5vw, 1.3rem);
  font-weight: 600;
  text-align: right;
  flex: 1;
  line-height: 1.3;
  word-break: break-word;
}
.match-detail-eq {
  color: var(--grid-thick);
}
.match-detail-ans {
  color: var(--accent);
  font-style: italic;
}
.match-tile-detail-dismiss {
  width: 100%;
}
body[data-theme="neon"] .match-detail-row {
  border-radius: 0;
}
body[data-theme="neon"] .match-tile-detail-close {
  border-radius: 0;
}

/* ════════════════════════════════════════════════
   CONFIRM DIALOG (legacy, kept for safety)
════════════════════════════════════════════════ */
#confirm-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0, 0, 0, 0.55);
  align-items: center;
  justify-content: center;
}
.confirm-box {
  background: var(--paper);
  border: 1px solid var(--grid-thick);
  border-radius: 10px;
  padding: 28px 24px 22px;
  width: min(300px, 86vw);
  text-align: center;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.3);
  animation: confirmSlide 0.2s ease both;
}
@keyframes confirmSlide {
  from {
    opacity: 0;
    transform: scale(0.93) translateY(10px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
.confirm-icon {
  font-size: 2rem;
  margin-bottom: 8px;
}
.confirm-title {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: 1.15rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
.confirm-msg {
  font-size: 0.72rem;
  color: var(--ink-mid);
  line-height: 1.6;
  margin-bottom: 22px;
}
.confirm-btns {
  display: flex;
  gap: 10px;
  justify-content: center;
}
.confirm-cancel {
  flex: 1;
  max-width: 110px;
  padding: 0.6em 1em;
  background: transparent;
  border: 1.5px solid var(--ink-faint);
  border-radius: 6px;
  color: var(--ink-mid);
  font-family: "DM Sans", sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.18s;
}
.confirm-cancel:hover {
  border-color: var(--ink);
  color: var(--ink);
}
.confirm-ok {
  flex: 1;
  max-width: 110px;
  padding: 0.6em 1em;
  background: var(--btn-primary-bg);
  border: none;
  border-radius: 6px;
  color: var(--btn-primary-color);
  font-family: "DM Sans", sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  cursor: pointer;
  text-transform: uppercase;
  transition: all 0.18s;
}
.confirm-ok:hover {
  background: var(--accent);
}

/* ════════════════════════════════════════════════
   BROWSER NOT SUPPORTED SCREEN
   Reuses loader screen structure
════════════════════════════════════════════════ */
#s-nosupport {
  display: none; /* shown via JS only when needed */
  position: fixed;
  inset: 0;
  z-index: 200;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  text-align: center;
}

#s-nosupport.visible {
  display: flex;
}

.nosupport-icon {
  width: 56px;
  height: 56px;
  margin-bottom: 24px;
  color: var(--accent);
  opacity: 0.85;
}
.nosupport-icon svg {
  width: 100%;
  height: 100%;
  fill: currentColor;
}

.nosupport-title {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: clamp(1.4rem, 5vw, 2rem);
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

.nosupport-msg {
  font-size: clamp(0.7rem, 2.2vw, 0.85rem);
  color: var(--ink-mid);
  line-height: 1.7;
  max-width: 320px;
  margin-bottom: 28px;
}

.nosupport-browsers {
  display: flex;
  gap: 16px;
  align-items: center;
  justify-content: center;
  margin-bottom: 28px;
  flex-wrap: wrap;
}

.nosupport-browser {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  opacity: 0.7;
}

.nosupport-browser-icon {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--card-bg);
  border: 1px solid var(--ink-faint);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
}

.nosupport-browser-name {
  font-size: 0.5rem;
  letter-spacing: 0.2em;
  color: var(--ink-dim);
  text-transform: uppercase;
}

.nosupport-bar-wrap {
  width: clamp(140px, 45vw, 220px);
  height: 2px;
  background: var(--ink-faint);
  border-radius: 2px;
  overflow: hidden;
  opacity: 0.4;
}

/* ================================================================
   LEXIKA MODE-SPECIFIC STYLES
   Connections · Strands · Letter Boxed
================================================================ */

.wl-board-card {
  width: min(560px, 92vw);
  background: var(--card-bg);
  border: 1px solid var(--card-border);
  border-radius: calc(var(--radius) + 6px);
  padding: 22px clamp(16px, 4vw, 30px) 28px;
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
}

.wl-board-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  color: var(--accent);
}

.wl-board-header svg {
  width: 1.15em;
  height: 1.15em;
  fill: currentColor;
  flex-shrink: 0;
}

.wl-board-header span {
  font-family: "DM Sans", sans-serif;
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-mid);
}

.wl-board {
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.wl-theme-banner {
  font-family: "Crimson Pro", Georgia, serif;
  font-style: italic;
  font-size: 0.95rem;
  color: var(--ink-mid);
  text-align: center;
}

/* ---------- WORD CONNECTIONS ---------- */
.wl-conn-solved {
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.wl-conn-solved-row {
  border-radius: var(--radius);
  padding: 12px 16px;
  color: #fff;
  text-align: center;
  animation: wlPop 0.3s ease;
}

.wl-conn-solved-name {
  font-family: "Crimson Pro", Georgia, serif;
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.02em;
}

.wl-conn-solved-words {
  font-family: "DM Sans", sans-serif;
  font-size: 0.78rem;
  opacity: 0.9;
  margin-top: 2px;
}

.wl-conn-grid {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.wl-conn-tile {
  aspect-ratio: 1.4 / 1;
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  background: var(--cell-bg);
  color: var(--ink);
  font-family: "DM Sans", sans-serif;
  font-weight: 700;
  font-size: clamp(0.72rem, 2.5vw, 1rem);
  letter-spacing: 0.02em;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 4px 6px;
  transition:
    transform 0.12s ease,
    background 0.12s ease,
    color 0.12s ease;
  box-shadow: var(--shadow);
}

.wl-conn-tile.wl-word-md {
  font-size: clamp(0.62rem, 2vw, 0.82rem);
}

.wl-conn-tile.wl-word-lg {
  font-size: clamp(0.54rem, 1.7vw, 0.7rem);
  letter-spacing: 0.01em;
}

.wl-conn-tile:hover {
  transform: translateY(-2px);
}

.wl-conn-tile.selected {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.wl-conn-tile.shake {
  animation: wlShake 0.35s ease;
}

/* ---------- STRANDS ---------- */
.wl-strands-found {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.wl-strands-chip {
  font-family: "DM Sans", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.wl-strands-chip.spangram {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.wl-strands-grid-wrap {
  position: relative;
  width: 100%;
}

.wl-strands-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.wl-strands-grid {
  display: grid;
  gap: 6px;
  width: 100%;
}

.wl-strands-cell {
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--cell-bg);
  color: var(--ink);
  font-family: "DM Sans", sans-serif;
  font-weight: 700;
  font-size: clamp(0.68rem, 2.6vw, 1rem);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition:
    background 0.12s ease,
    color 0.12s ease,
    transform 0.12s ease;
}

.wl-strands-cell.in-path {
  background: var(--accent);
  color: #fff;
  transform: scale(1.08);
}

.wl-strands-cell.found {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.wl-strands-cell.found-spangram {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}

.wl-strands-hint-count {
  font-family: "DM Sans", sans-serif;
  font-size: 0.75rem;
  color: var(--ink-dim);
  letter-spacing: 0.04em;
}

/* ---------- LETTER BOXED ---------- */
.wl-lb-current-word {
  font-family: "Crimson Pro", Georgia, serif;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--ink);
  min-height: 2.2rem;
  text-align: center;
}

.wl-lb-current-word.shake {
  animation: wlShake 0.35s ease;
  color: var(--error-txt);
}

.wl-lb-square-wrap {
  position: relative;
  width: min(340px, 82vw);
  aspect-ratio: 1 / 1;
  margin: 8px 0;
}

.wl-lb-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.wl-lb-square {
  position: absolute;
  inset: 18%;
  border: 2px solid var(--ink-faint);
  border-radius: var(--radius);
}

.wl-lb-letter {
  position: absolute;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--cell-bg);
  color: var(--ink);
  font-family: "DM Sans", sans-serif;
  font-weight: 700;
  font-size: 1.15rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow);
  transform: translate(-50%, -50%);
  transition:
    background 0.12s ease,
    color 0.12s ease,
    opacity 0.12s ease;
}

.wl-lb-letter.used {
  background: var(--accent-bg);
  color: var(--accent);
  border-color: var(--accent);
}

.wl-lb-letter.disabled-side {
  opacity: 0.35;
  pointer-events: none;
}

/* position the 12 letters: 3 top, 3 right, 3 bottom, 3 left */
.wl-lb-letter[data-side="top"][data-idx="0"] {
  top: 0%;
  left: 25%;
}
.wl-lb-letter[data-side="top"][data-idx="1"] {
  top: 0%;
  left: 50%;
}
.wl-lb-letter[data-side="top"][data-idx="2"] {
  top: 0%;
  left: 75%;
}
.wl-lb-letter[data-side="right"][data-idx="3"] {
  top: 25%;
  left: 100%;
}
.wl-lb-letter[data-side="right"][data-idx="4"] {
  top: 50%;
  left: 100%;
}
.wl-lb-letter[data-side="right"][data-idx="5"] {
  top: 75%;
  left: 100%;
}
.wl-lb-letter[data-side="bottom"][data-idx="6"] {
  top: 100%;
  left: 75%;
}
.wl-lb-letter[data-side="bottom"][data-idx="7"] {
  top: 100%;
  left: 50%;
}
.wl-lb-letter[data-side="bottom"][data-idx="8"] {
  top: 100%;
  left: 25%;
}
.wl-lb-letter[data-side="left"][data-idx="9"] {
  top: 75%;
  left: 0%;
}
.wl-lb-letter[data-side="left"][data-idx="10"] {
  top: 50%;
  left: 0%;
}
.wl-lb-letter[data-side="left"][data-idx="11"] {
  top: 25%;
  left: 0%;
}

.wl-lb-word-list {
  width: 100%;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  min-height: 28px;
}

.wl-lb-word-chip {
  font-family: "DM Sans", sans-serif;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--accent-bg);
  color: var(--accent);
  border: 1px solid var(--accent);
}

.wl-lb-actions {
  display: flex;
  gap: 10px;
}

.wl-lb-btn {
  font-family: "DM Sans", sans-serif;
  font-weight: 700;
  font-size: 0.85rem;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  background: var(--card-bg);
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition:
    background 0.12s ease,
    color 0.12s ease;
}

.wl-lb-btn svg {
  width: 1.1em;
  height: 1.1em;
  fill: currentColor;
}

.wl-lb-btn.primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-color);
  border-color: var(--btn-primary-bg);
}

.wl-lb-btn:hover {
  opacity: 0.85;
}

@keyframes wlPop {
  from {
    opacity: 0;
    transform: scale(0.94);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

@keyframes wlShake {
  10%,
  90% {
    transform: translateX(-1px);
  }
  20%,
  80% {
    transform: translateX(2px);
  }
  30%,
  50%,
  70% {
    transform: translateX(-4px);
  }
  40%,
  60% {
    transform: translateX(4px);
  }
}

@media (max-width: 480px) {
  .wl-lb-letter {
    width: 42px;
    height: 42px;
    font-size: 1.05rem;
  }
  .wl-conn-tile {
    font-size: 0.68rem;
  }
  .wl-board-card {
    padding: 16px 14px 20px;
  }
}

/* ── Landscape orientation (mobile/tablet) ───────────────────── */
@media (orientation: landscape) and (max-height: 500px) {
  .game-body {
    flex-direction: row;
    align-items: flex-start;
    padding: clamp(4px, 1.5vw, 10px);
    gap: clamp(4px, 1.5vw, 10px);
  }
  .game-page-header {
    padding: 6px clamp(10px, 2vw, 16px);
  }
  .top-title {
    font-size: clamp(1rem, 3vh, 1.4rem);
  }
  .popup-card {
    max-height: 90vh;
    overflow-y: auto;
  }
  .lobby-page {
    padding: clamp(6px, 1.5vh, 12px);
  }
  .lobby-header {
    padding: clamp(6px, 1.5vh, 10px) clamp(10px, 2vw, 16px);
  }
  .grid-wrap {
    width: min(320px, 55vw);
  }
}
