/* ═══════════════════════════════════════════════
   KINGMAKER — Main Stylesheet
   ═══════════════════════════════════════════════ */

*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
}

:root {
  --bg:          #0d0500;
  --bg2:         #1a0a00;
  --bg3:         #2a1200;
  --gold:        #d4a017;
  --gold-dim:    #8a6010;
  --red:         #cc3300;
  --red-bright:  #ee4400;
  --text:        #f5e6d3;
  --muted:       #b88c50;
  --border:      rgba(255,255,255,0.08);
  --btn-bg:      rgba(255,255,255,0.07);
  --btn-hover:   rgba(255,255,255,0.14);
  --radius:      10px;
  --transition:  0.25s ease;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

/* ─── FOCUS RINGS ──────────────────────────────── */
/* Suppress default ring; restore a gold one only for keyboard nav */
*:focus          { outline: none; }
*:focus-visible  { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 4px; }

/* ─── SCREENS ─────────────────────────────────── */

.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease, transform 0.35s ease;
  transform: translateY(8px);
  /* Iso mode intentionally lets the tilted board spill past .board-scale-outer
     (overflow:visible there, see .board-scale-outer:has(.board-wrap.iso-active))
     so the rotated board isn't clipped mid-perspective. Without a clipping
     boundary somewhere above that, the overflow can register as real page
     content on mobile, letting the browser's viewport creep/scroll toward it
     on repeated resizes. Clip here, at the screen's own edge, so the visual
     spill never escapes past the viewport itself. */
  overflow: hidden;
}
.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}
/* Menu screens always win the stacking order — guarantees their controls
   are clickable even if some other absolutely-positioned element (e.g. a
   leftover overlay layer) ends up still present in the DOM. */
#screen-title.active,
#screen-howto.active,
#screen-players.active,
#screen-lobby.active,
#screen-challenge.active,
#screen-leaderboard.active {
  z-index: 9999;
}

/* ─── TITLE SCREEN ─────────────────────────────── */

/* Scroll wrapper fills #screen-title; canvas stays outside it */
.title-scroll-wrap {
  position: relative;
  z-index: 1;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.title-scroll-wrap::before {
  content: '';
  flex: 1;
  min-height: 70px;
}
.title-scroll-wrap::after {
  content: '';
  flex: 1;
  min-height: 16px;
}
.title-scroll-wrap .title-content {
  flex-shrink: 0;
}

#bg-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.title-content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  padding: 24px 20px;
  width: 100%;
  max-width: 380px;
}

.title-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.logo-board {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  padding: 6px;
  background: rgba(0,0,0,0.4);
  border-radius: 8px;
  border: 1px solid var(--border);
}
.lp {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(0,0,0,0.5);
  animation: bobble 2.4s ease-in-out infinite;
}
.lp.r { background: radial-gradient(circle at 35% 35%, #ff5533, #991100); }
.lp.d { background: radial-gradient(circle at 35% 35%, #555, #111); animation-delay: 1.2s; }

@keyframes bobble {
  0%, 100% { transform: translateY(0) scale(1); }
  50%       { transform: translateY(-5px) scale(1.05); }
}

.game-title {
  font-size: clamp(2.4rem, 10vw, 4.5rem);
  font-weight: 900;
  letter-spacing: 0.25em;
  color: var(--text);
  text-shadow:
    0 0 40px rgba(212,160,23,0.4),
    0 3px 6px rgba(0,0,0,0.8);
}

.title-sub {
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-top: -8px;
}

/* ─── START BUTTON ──────────────────────────────── */

#btn-start {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 48px;
  background: linear-gradient(135deg, #a07010, var(--gold), #a07010);
  border: 1px solid rgba(212,160,23,0.55);
  border-radius: var(--radius);
  color: #0d0500;
  font-size: 1.15rem;
  font-weight: 900;
  letter-spacing: 0.22em;
  cursor: pointer;
  animation: start-pulse 2.2s ease-in-out infinite;
  transition: opacity 0.4s ease, transform 0.4s ease;
  margin-top: 8px;
}
#btn-start:hover { filter: brightness(1.12); }
#btn-start.hidden {
  opacity: 0;
  pointer-events: none;
  transform: scale(0.92);
}

@keyframes start-pulse {
  0%, 100% { box-shadow: 0 0 18px rgba(212,160,23,0.35), 0 0 40px rgba(212,160,23,0.10); }
  50%       { box-shadow: 0 0 32px rgba(212,160,23,0.65), 0 0 70px rgba(212,160,23,0.25); }
}

/* ─── MENU BUTTONS ──────────────────────────────── */

.menu-buttons {
  display: flex;
  flex-direction: column;
  gap: 11px;
  width: 100%;
  margin-top: 10px;
  transition: opacity 0.5s ease;
}
.menu-buttons.hidden {
  opacity: 0;
  pointer-events: none;
  visibility: hidden;
}

.menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  padding: 15px 20px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--btn-bg);
  color: var(--text);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background var(--transition), transform var(--transition), box-shadow var(--transition);
  position: relative;
}
.menu-btn:hover {
  background: var(--btn-hover);
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0,0,0,0.5);
}
.menu-btn:active { transform: translateY(0); box-shadow: none; }
.menu-btn svg { flex-shrink: 0; opacity: 0.8; }
.menu-btn.dimmed { opacity: 0.35; cursor: default; pointer-events: none; }

.menu-btn.primary {
  background: var(--red);
  border-color: rgba(255,100,50,0.35);
}
.menu-btn.primary:hover { background: var(--red-bright); }

.menu-btn.danger {
  background: rgba(120, 20, 10, 0.4);
  border-color: rgba(200,50,30,0.3);
}
.menu-btn.danger:hover { background: rgba(150, 30, 15, 0.6); }

.kofi-btn {
  display: block;
  text-align: center;
  margin-top: 20px;
  padding: 7px 16px;
  border-radius: 8px;
  border: 1px solid rgba(255, 94, 91, 0.35);
  background: rgba(255, 94, 91, 0.1);
  color: #ff7875;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-decoration: none;
  transition: background 0.2s, border-color 0.2s;
}
.kofi-btn:hover {
  background: rgba(255, 94, 91, 0.22);
  border-color: rgba(255, 94, 91, 0.6);
}

.pwa-install-nudge {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px 6px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: transparent;
  color: var(--text);
  border: 1.5px solid rgba(245,230,211,0.45);
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  user-select: none;
}
.pwa-install-nudge:hover {
  background: var(--btn-hover);
  border-color: var(--text);
}
.pwa-nudge-icon { font-size: 0.9rem; flex-shrink: 0; }
.pwa-nudge-text { flex: 1; white-space: nowrap; }
.pwa-nudge-dismiss {
  background: none;
  border: none;
  color: rgba(245,230,211,0.4);
  font-size: 0.7rem;
  padding: 4px 6px;
  cursor: pointer;
  flex-shrink: 0;
  line-height: 1;
  border-radius: 4px;
  min-width: 24px;
  min-height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.pwa-nudge-dismiss:hover { color: var(--text); }
.pwa-install-nudge.hidden { display: none; }

.diff-badge {
  margin-left: auto;
  background: rgba(255,255,255,0.12);
  padding: 5px 10px;
  border-radius: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--gold);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1px;
  flex-shrink: 0;
}
.badge-top {
  font-size: 0.72rem;
  opacity: 0.75;
  line-height: 1.1;
}
.badge-bot {
  font-size: 0.85rem;
  line-height: 1.1;
}
.menu-btn.primary .diff-badge { color: rgba(255,255,255,0.82); }

/* ─── PLAY PANEL ────────────────────────────────── */
.play-panel {
  width: 100%;
  border: 1px solid rgba(212,160,23,0.22);
  border-radius: var(--radius);
  padding: 10px 10px 10px;
  background: rgba(212,160,23,0.04);
}
.play-panel-label {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: var(--gold);
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 8px;
}
.play-panel-btns {
  display: flex;
  gap: 8px;
}
.play-panel-btns .menu-btn {
  flex: 1;
  width: auto;
  padding: 13px 10px;
}

/* ─── PLAYERS SCREEN ───────────────────────────── */

#screen-players {
  background: radial-gradient(ellipse at 50% 40%, var(--bg3) 0%, var(--bg) 70%);
}
.players-scroll-wrap {
  position: relative;
  width: 100%;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.players-scroll-wrap::-webkit-scrollbar,
.players-scroll-wrap::-webkit-scrollbar-thumb,
.players-scroll-wrap::-webkit-scrollbar-track,
.players-scroll-wrap::-webkit-scrollbar-corner { width: 0; height: 0; background: transparent; display: none; }
.players-scroll-wrap::before,
.players-scroll-wrap::after {
  content: '';
  flex: 1;
  min-height: 20px;
}
.players-scroll-wrap .players-panel {
  flex-shrink: 0;
}

.players-panel {
  gap: 14px;
  max-width: 460px;
}

.mode-tabs {
  display: flex;
  gap: 10px;
  width: 100%;
}

.mode-tab {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--btn-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
}
.mode-tab:hover { background: var(--btn-hover); border-color: rgba(255,255,255,0.2); }
.mode-tab.active {
  border-color: var(--gold);
  background: rgba(212,160,23,0.12);
}
.mode-tab-num {
  font-size: 1.8rem;
  font-weight: 900;
  color: var(--gold);
  line-height: 1;
  flex-shrink: 0;
}
.mode-tab-label {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.4;
  color: var(--text);
}
.mode-tab-label small { font-weight: 400; color: var(--muted); }

.player-cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}

.player-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  transition: opacity 0.2s;
}
.player-card.p3p4 { display: none; }
.player-card.p3p4.visible { display: flex; }

.pc-dot {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid rgba(0,0,0,0.4);
}
.pc-dot.pc-red  { background: radial-gradient(circle at 35% 35%, #ff5533, #881100); border-color: #cc3300; }
.pc-dot.pc-dark { background: radial-gradient(circle at 35% 35%, #555, #111);    border-color: #444; }
.pc-dot.pc-blue { background: radial-gradient(circle at 35% 35%, #4499ff, #0a3377); border-color: #2266cc; }
.pc-dot.pc-gold { background: radial-gradient(circle at 35% 35%, #ffcc44, #775500); border-color: #cc9900; }

.pc-name {
  flex: 1;
  font-weight: 700;
  font-size: 0.95rem;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  outline: none;
  color: var(--text);
  padding: 2px 0;
  min-width: 0;
  font-family: inherit;
  cursor: text;
  transition: border-color 0.2s;
}
.pc-name:focus {
  border-bottom-color: var(--gold-dim);
}

.pc-type-btn {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 20px;
  color: var(--text);
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
  transition: all var(--transition);
  min-width: 110px;
  text-align: center;
}
.pc-type-btn:hover { background: rgba(255,255,255,0.18); }
.pc-type-btn.is-human {
  background: rgba(100,200,100,0.18);
  border-color: rgba(100,200,100,0.5);
  color: #aaffaa;
}
.pc-type-btn.is-ai-casual   { background: rgba(100,160,255,0.15); border-color: rgba(100,160,255,0.4); }
.pc-type-btn.is-ai-normal   { background: rgba(255,200,0,0.15);   border-color: rgba(255,200,0,0.4); }
.pc-type-btn.is-ai-hard     { background: rgba(255,80,60,0.15);   border-color: rgba(255,80,60,0.4); }
.pc-type-btn.is-ai-learner  { background: rgba(180,80,255,0.18);  border-color: rgba(180,80,255,0.5); }

.players-info {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  letter-spacing: 0.04em;
}

/* ─── RULE TABS ─────────────────────────────────── */

.rule-tabs {
  display: grid;
  /* auto-fit: hidden tabs (display:none) collapse out; remaining items fill row */
  grid-template-columns: repeat(auto-fit, minmax(60px, 1fr));
  gap: 6px;
  width: 100%;
}
.rule-tabs.hidden { display: none; }

.rule-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 9px 4px;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  transition: all var(--transition);
}
.rule-tab:hover { background: var(--btn-hover); color: var(--text); }
.rule-tab.active {
  background: rgba(212,160,23,0.12);
  border-color: rgba(212,160,23,0.4);
  color: var(--text);
}
.rule-tab[data-rule="surge"].active,
.rule-tab[data-4prule="surge"].active {
  background: rgba(180,80,255,0.13);
  border-color: rgba(180,80,255,0.45);
}
.rule-tab[data-4psize="large"].active {
  background: rgba(255,60,40,0.13);
  border-color: rgba(255,60,40,0.45);
}
.rule-tab-name { font-size: 0.78rem; font-weight: 700; }
.rule-tab-desc { font-size: 0.62rem; opacity: 0.7; }

/* ─── SETTINGS CATEGORIES ───────────────────────── */

.settings-category {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 6px 0 2px;
}
.settings-category::before,
.settings-category::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── THEME SWATCHES ────────────────────────────── */

.theme-swatches { display: flex; gap: 7px; align-items: flex-start; flex-wrap: nowrap; overflow-x: auto; width: 275px; max-width: calc(100vw - 160px); flex-shrink: 1; margin-left: 40px; margin-right: 14px; scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; cursor: grab; }
.theme-swatches::-webkit-scrollbar { display: none; }

.theme-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  padding: 2px;
  width: 52px;
}

.ts-disc {
  display: block;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.12);
  transition: border-color 0.2s, transform 0.15s;
}
.theme-swatch:hover:not(.active) .ts-disc { border-color: rgba(255,255,255,0.4); }
.theme-swatch.active .ts-disc { border-color: var(--gold); transform: scale(1.18); }

.theme-swatch[data-theme="classic"] .ts-disc { background: linear-gradient(135deg, #f0d9b5 50%, #b58863 50%); }
.theme-swatch[data-theme="green"]   .ts-disc { background: linear-gradient(135deg, #e8f0d0 50%, #4a8540 50%); }
.theme-swatch[data-theme="slate"]   .ts-disc { background: linear-gradient(135deg, #b8c5d8 50%, #4a5870 50%); }
.theme-swatch[data-theme="night"]   .ts-disc { background: linear-gradient(135deg, #3a3a44 50%, #1a1a22 50%); }
.theme-swatch[data-theme="maple"]   .ts-disc { background: linear-gradient(135deg, #f0d898 50%, #8b4010 50%); }

/* ─── DIFFICULTY SCREEN ─────────────────────────── */

#screen-difficulty {
  background: radial-gradient(ellipse at 50% 40%, var(--bg3) 0%, var(--bg) 70%);
}

.panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  padding: 28px 20px;
  width: 100%;
  max-width: 440px;
}

.panel-title {
  font-size: 1.9rem;
  font-weight: 800;
  color: var(--gold);
  letter-spacing: 0.08em;
}

.panel-sub {
  font-size: 0.88rem;
  color: var(--muted);
}

.diff-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
}

.diff-card {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  background: var(--btn-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  text-align: left;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}
.diff-card:hover {
  background: var(--btn-hover);
  transform: translateX(4px);
}
.diff-card[aria-checked="true"] {
  border-color: var(--gold);
  background: rgba(212,160,23,0.1);
}
.diff-card[aria-checked="true"] .diff-check { opacity: 1; }

.diff-emoji { font-size: 2rem; flex-shrink: 0; }

.diff-info {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 3px;
}
.diff-name { font-weight: 700; font-size: 1.05rem; }
.diff-desc { font-size: 0.8rem; color: var(--muted); }

.diff-check {
  font-size: 1.2rem;
  color: var(--gold);
  opacity: 0;
  transition: opacity var(--transition);
  flex-shrink: 0;
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 14px 18px;
  background: var(--btn-bg);
  border: 2px solid var(--border);
  border-radius: var(--radius);
}
.settings-row.hidden { display: none; }

.settings-label {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.sound-toggle {
  padding: 6px 20px;
  border-radius: 20px;
  border: 2px solid var(--gold);
  background: rgba(212,160,23,0.15);
  color: var(--gold);
  font-weight: 700;
  font-size: 0.9rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.sound-toggle:hover { background: rgba(212,160,23,0.25); }
.sound-toggle.off {
  border-color: var(--muted);
  background: transparent;
  color: var(--muted);
}

/* ─── Volume Sliders ───────────────────────── */
.vol-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 150px;
  height: 15px;
  border-radius: 8px;
  outline: none;
  cursor: pointer;
  flex-shrink: 0;
  border: 1.5px solid var(--gold);
  background: linear-gradient(
    to right,
    #ffe566 0%,
    var(--gold) var(--fill, 100%),
    #000 var(--fill, 100%),
    #000 100%
  );
  box-shadow: 0 0 8px rgba(201,162,39,0.55), 0 0 2px rgba(255,229,102,0.4);
}
.vol-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 0;
  height: 0;
  opacity: 0;
}
.vol-slider::-moz-range-thumb {
  width: 0;
  height: 0;
  border: none;
  opacity: 0;
  background: transparent;
}
.vol-slider::-moz-range-track {
  height: 15px;
  border-radius: 8px;
  background: #000;
  border: 1.5px solid var(--gold);
}
.vol-slider::-moz-range-progress {
  background: linear-gradient(to right, #ffe566, var(--gold));
  height: 15px;
  border-radius: 8px 0 0 8px;
}

.back-btn {
  width: auto;
  min-width: 180px;
  font-size: 0.9rem;
}

.lb-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 8px;
  width: 100%;
}

/* ─── HOW TO PLAY SCREEN ───────────────────────── */

.howto-screen {
  justify-content: flex-start;
  overflow-y: auto;
  padding: 16px 0 24px;
}

.howto-panel {
  align-items: flex-start;
  gap: 0;
  padding-top: 20px;
}

.howto-section {
  width: 100%;
  padding: 14px 0;
  border-bottom: 1px solid var(--border);
}
.howto-section:last-of-type { border-bottom: none; padding-bottom: 0; }

.howto-back-btn { margin-top: 14px; }
#btn-tutorial { margin-top: 20px; }

.howto-heading {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 7px;
}

.howto-text {
  font-size: 0.87rem;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 4px;
}
.howto-text:last-child { margin-bottom: 0; }
.howto-text strong { color: var(--text); }

.howto-rule {
  color: #ff8844;
  margin-top: 8px;
}

.howto-list {
  font-size: 0.87rem;
  color: var(--muted);
  line-height: 1.65;
  padding-left: 18px;
  margin: 0;
}
.howto-list li { margin-bottom: 3px; }
.howto-list strong { color: var(--text); }

/* ─── GAME SCREEN ─────────────────────────────── */

#screen-game {
  padding: 0;
  justify-content: flex-start;
  align-items: stretch;
  background: #0a0300;
  height: 100%;
}

.game-main {
  flex: 1;
  min-height: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
}
.game-sidebar { display: none; }

.game-header {
  display: flex;
  flex-direction: column;
  padding: 6px 12px 5px;
  background: rgba(0,0,0,0.6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  width: 100%;
  position: relative;
  z-index: 10;
}

.hdr-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: relative;
}

.hdr-btn {
  background: var(--btn-bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  transition: background var(--transition);
  flex-shrink: 0;
}
.hdr-btn:hover { background: var(--btn-hover); }

.hdr-center {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 2px 0 1px;
  pointer-events: none;
}

.turn-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  transition: color 0.3s;
  white-space: nowrap;
}
.turn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--red);
  flex-shrink: 0;
  box-shadow: 0 0 6px var(--red);
  animation: pulse 1.5s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.5; }
}
.turn-dot.hidden  { opacity: 0; animation: none; }

.hdr-left-col {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 1px;
}

.hdr-left {
  display: flex;
  align-items: center;
  gap: 6px;
}

.hdr-counts {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.hdr-count {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 1rem;
  font-weight: 700;
}
.hdr-count-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
}
.ai-dot, .hdr-count-dot.ai-dot   { background: radial-gradient(circle at 35% 35%, #555, #111); border: 2px solid #444; }
.player-dot2                       { background: radial-gradient(circle at 35% 35%, #ff5533, #991100); border: 2px solid #cc3300; }
.hdr-vs { font-size: 0.75rem; color: var(--muted); }

.board-scale-outer {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 54px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
  position: relative;
  touch-action: none;
}
@media (max-width: 700px) {
  .board-scale-outer {
    padding: 10px 18px;
  }
}
@media (max-height: 500px) {
  .board-scale-outer {
    padding: 8px 18px;
  }
}
.board-wrap {
  width: 900px;
  height: 900px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  transform-origin: center center;
}
.iso-inner {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  height: 100%;
  position: relative;
}
.board-wrap.iso-active {
  perspective: 2000px;
  overflow: visible;
}
.board-scale-outer:has(.board-wrap.iso-active) {
  overflow: visible;
}
.board-wrap.iso-active .iso-inner {
  transform: scale(1.25);
  transform-style: preserve-3d;
}
.board-hit {
  border-radius: 6px;
  background: rgba(0, 255, 100, 0.1);
  outline: 1px solid rgba(0, 255, 100, 0.3);
  transition: background 0.08s ease;
}
.board-hit:hover,
.board-hit.hit-hover {
  background: rgba(255, 220, 80, 0.5);
}
.board-wrap.iso-active #game-canvas {
  transform: rotateX(48deg);
  transform-origin: bottom center;
  pointer-events: none;
}

#game-canvas {
  display: block;
  cursor: pointer;
  touch-action: none;
  border-radius: 6px;
  will-change: transform;
  box-shadow: 0 10px 50px rgba(0,0,0,0.9), 0 0 0 2px rgba(255,255,255,0.05);
  /* Size is set by JS to fill available space; max constraints are fallbacks only */
  max-width: 100%;
  max-height: 100%;
  flex-shrink: 0;
}

.game-footer {
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 16px;
  background: rgba(0,0,0,0.4);
  position: relative;
  z-index: 10;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  width: 100%;
  position: relative;
}

.footer-diff {
  pointer-events: none;
  font-size: 0.65rem;
  color: var(--gold-dim);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 2px;
}

.drought-counter {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--muted);
  transition: color 0.4s;
  white-space: nowrap;
  margin-right: 4px;
}
.drought-counter:empty { margin-right: 0; }
.drought-counter.warning { color: #ff8844; }
.drought-counter.danger  { color: #ff3322; animation: pulse 0.7s ease-in-out infinite; }

.turn-timer {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
  margin-left: 6px;
  transition: color 0.3s;
}
.turn-timer.hidden { display: none; }
.turn-timer.timer-urgent { color: #ff3322; animation: pulse 0.7s ease-in-out infinite; }

.footer-hint {
  font-size: 0.75rem;
  color: var(--muted);
  transition: opacity 0.3s;
}
.footer-hint.hint-thinking::after {
  content: '';
  display: inline-block;
  animation: thinking-dots 1.2s steps(4, end) infinite;
}
@keyframes thinking-dots {
  0%   { content: ''; }
  25%  { content: '.'; }
  50%  { content: '..'; }
  75%  { content: '...'; }
  100% { content: ''; }
}

/* ─── VOICE BUTTONS ─────────────────────────────── */
.voice-btns {
  display: flex;
  gap: 6px;
}
.voice-btn {
  padding: 5px 14px;
  font-size: 0.8rem;
  font-weight: 600;
  background: var(--btn-bg);
  color: #f0d060;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.voice-btn.active {
  background: var(--gold-dim);
  color: var(--gold);
  border-color: var(--gold-dim);
}
#voice-select-row { gap: 10px; }
.voice-select {
  flex: 1;
  min-width: 0;
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 0.78rem;
  cursor: pointer;
}
.voice-select option { background: #1a1a2a; }
.voice-test-btn {
  flex-shrink: 0;
  padding: 5px 10px;
  font-size: 0.76rem;
  font-weight: 600;
  background: var(--btn-bg);
  color: var(--gold);
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
}
.voice-test-btn:hover { background: var(--gold-dim); }

/* ─── PIECE STYLE SWATCHES ───────────────────────── */

.piece-swatches { display: flex; gap: 8px; align-items: flex-start; flex-wrap: nowrap; overflow-x: auto; width: 275px; max-width: calc(100vw - 160px); flex-shrink: 1; margin-left: 40px; margin-right: 14px; scrollbar-width: none; -ms-overflow-style: none; -webkit-overflow-scrolling: touch; cursor: grab; }
.piece-swatches::-webkit-scrollbar { display: none; }

.piece-swatch {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  background: none;
  border: none;
  padding: 2px;
  cursor: pointer;
  flex-shrink: 0;
  width: 52px;
}

.ps-name {
  font-size: 9px;
  color: rgba(255,255,255,0.55);
  text-align: center;
  white-space: normal;
  max-width: 40px;
  line-height: 1.2;
  pointer-events: none;
}

.ps-disc {
  display: block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.12);
  transition: border-color 0.2s, transform 0.15s;
}
.piece-swatch:hover:not(.active) .ps-disc { border-color: rgba(255,255,255,0.4); }
.piece-swatch.active .ps-disc { border-color: var(--gold); transform: scale(1.18); }

/* Disc visual styles — each style uses a different team colour */
.piece-swatch[data-style="glossy"] .ps-disc {
  background: radial-gradient(circle at 35% 30%, #ff9977, #cc3300 52%, #7a1500); /* red */
}
.piece-swatch[data-style="flat"] .ps-disc {
  background: #303030; /* dark */
  box-shadow: inset 0 0 0 5px rgba(255,255,255,0.14);
}
.piece-swatch[data-style="marble"] .ps-disc {
  background-color: #0a3377; /* blue */
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 28"><path d="M4 27 Q10 18 15 22 Q21 26 25 14 Q27 7 28 3" stroke="%23aaddff" stroke-width="1.8" fill="none" stroke-opacity="0.78"/><path d="M0 15 Q5 10 9 13 Q14 16 16 9 Q17 5 20 1" stroke="%23aaddff" stroke-width="1" fill="none" stroke-opacity="0.52"/></svg>');
  background-size: cover;
}
.piece-swatch[data-style="metallic"] .ps-disc {
  background: linear-gradient(180deg,
    #443300 0%, #886600 9%, #ffcc44 20%, #ffffff 29%,
    #ffcc44 37%, #cc9900 50%, #775500 58%,
    #ffcc44 68%, #ffffff 76%, #cc9900 86%, #443300 100%); /* gold */
}
.piece-swatch[data-style="wood"] .ps-disc {
  background-color: #664400; /* gold-wood */
  background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 28 28"><path d="M-2 4 Q5 2 11 5 Q17 8 24 4 Q28 2 30 4" stroke="%23ffcc44" stroke-width="1.5" fill="none" stroke-opacity="0.5"/><path d="M-2 13 Q4 10 10 14 Q17 18 23 13 Q28 10 31 13" stroke="%23ffcc44" stroke-width="1.5" fill="none" stroke-opacity="0.5"/><path d="M-2 22 Q5 19 11 23 Q18 27 25 22 Q28 19 31 22" stroke="%23ffcc44" stroke-width="1.5" fill="none" stroke-opacity="0.5"/></svg>');
  background-size: cover;
}
.piece-swatch[data-style="crystal"] .ps-disc {
  background:
    linear-gradient(135deg, rgba(255,255,255,0.82) 0%, rgba(255,255,255,0.0) 38%,
      rgba(255,255,255,0.0) 62%, rgba(255,255,255,0.35) 100%),
    radial-gradient(circle at 50% 50%, rgba(80,140,255,0.6), rgba(10,20,100,0.8)); /* blue crystal */
  border-color: rgba(150,180,255,0.45);
}
.ps-custom-disc {
  background: rgba(255,255,255,0.05);
  border: 1.5px dashed rgba(255,255,255,0.28) !important;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  color: rgba(255,255,255,0.45);
}
.piece-swatch.active .ps-custom-disc {
  border-color: var(--gold) !important;
  color: var(--gold);
}

.elo-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 4px;
  background: rgba(255,255,255,0.06);
  flex-shrink: 0;
  white-space: nowrap;
}
.elo-num { font-weight: 400; opacity: 0.8; }
.ranked-badge {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  color: var(--gold);
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid rgba(212,168,67,0.35);
  background: rgba(212,168,67,0.08);
  flex-shrink: 0;
}

.commentary-note {
  font-size: 0.72rem;
  color: var(--muted);
  text-align: center;
  margin: 2px 0 0;
  opacity: 0.8;
}

/* ─── OVERLAYS ─────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.75);
  /* backdrop-filter: blur(6px); — removed: expensive GPU pass on mobile/TV, rgba bg provides sufficient legibility */
  z-index: 10000;
  padding: 20px;
}
.overlay.hidden { display: none; }

.overlay-box {
  background: linear-gradient(145deg, var(--bg3), var(--bg));
  border: 1px solid rgba(212,160,23,0.25);
  border-radius: 18px;
  padding: 36px 28px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 320px;
  width: 100%;
  box-shadow: 0 24px 80px rgba(0,0,0,0.9);
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}
.overlay-box.small { max-width: 280px; }
.overlay-box.attention {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(212,160,23,0.25), 0 24px 80px rgba(0,0,0,0.9);
  animation: popIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), attention-pulse 1.8s ease-in-out 0.4s infinite;
}
@keyframes attention-pulse {
  0%, 100% { box-shadow: 0 0 0 3px rgba(212,160,23,0.20), 0 24px 80px rgba(0,0,0,0.9); }
  50%       { box-shadow: 0 0 0 6px rgba(212,160,23,0.45), 0 24px 80px rgba(0,0,0,0.9); }
}
.btn-pulse {
  animation: btn-pulse 1.4s ease-in-out infinite;
}
@keyframes btn-pulse {
  0%, 100% { transform: scale(1); }
  50%       { transform: scale(1.05); }
}

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

.go-icon {
  font-size: 4rem;
  line-height: 1;
  animation: popIn 0.5s 0.1s cubic-bezier(0.175, 0.885, 0.32, 1.275) both;
}

.go-title {
  font-size: 2rem;
  font-weight: 800;
  color: var(--gold);
  text-align: center;
}

.go-sub {
  font-size: 0.9rem;
  color: var(--muted);
  text-align: center;
}

.go-record-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.go-record {
  font-size: 0.78rem;
  color: #c8952a;
  letter-spacing: 0.06em;
}

.export-btn {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.7rem;
  padding: 2px 7px;
  cursor: pointer;
  opacity: 0.6;
  white-space: nowrap;
  transition: opacity 0.2s, border-color 0.2s;
}
.export-btn:hover { opacity: 1; border-color: rgba(255,255,255,0.35); }
.export-btn.hidden { display: none; }

.overlay-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
  width: 100%;
  margin-top: 8px;
}
.overlay-btns.hidden { display: none; }
.menu-btn.hidden     { display: none; }

.go-like-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 4px 0;
}
.go-like-row.hidden { display: none; }
.like-opp-btn {
  background: rgba(80,160,80,0.15);
  border: 1px solid rgba(80,200,80,0.3);
  border-radius: 20px;
  color: var(--fg);
  font-size: 0.95rem;
  padding: 5px 16px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}
.like-opp-btn:hover:not(:disabled) { background: rgba(80,200,80,0.25); }
.like-opp-btn:disabled { opacity: 0.5; cursor: default; }
.like-all-btn { background: rgba(80,160,80,0.28); font-weight: 600; }
.like-opp-label {
  font-size: 0.75rem;
  color: var(--muted);
}

#btn-rematch:disabled {
  opacity: 0.45;
  cursor: default;
}

#btn-decline-rematch {
  background: rgba(180,50,50,0.18);
  color: #d07070;
  border: 1px solid rgba(180,50,50,0.3);
}
#btn-decline-rematch:hover {
  background: rgba(180,50,50,0.3);
}

/* ─── SCROLLBAR ────────────────────────────────── */

::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--bg3); border-radius: 3px; }

/* ─── RESPONSIVE ADJUSTMENTS ───────────────────── */

@media (max-width: 400px) {
  .game-title  { letter-spacing: 0.15em; }
  .menu-btn    { padding: 13px 16px; font-size: 0.95rem; }
  .diff-card   { padding: 13px 14px; }
  .diff-emoji  { font-size: 1.6rem; }
}

@media (max-height: 600px) and (orientation: landscape) {
  .title-content { gap: 10px; padding: 10px; }
  .logo-board    { display: none; }
  .game-title    { font-size: 2rem; }
  .title-sub     { display: none; }
  .menu-buttons  { margin-top: 4px; gap: 7px; }
  .menu-btn      { padding: 11px 16px; }
  .game-header   { padding: 3px 12px 3px; }
  .hdr-center    { padding: 1px 0; gap: 0; }
  .game-footer   { height: 30px; }
}

@media (min-width: 600px) {
  .title-content  { max-width: 440px; }
  .diff-options   { gap: 12px; }
}





/* ─── SCROLL ARROWS (all screen sizes) ─────────────── */
.swatch-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
}
.swatch-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  z-index: 6;
  background: rgba(20,12,4,0.88);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 50%;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  line-height: 26px;
  text-align: center;
  cursor: pointer;
  padding: 0 0 1px 0;
  transition: opacity 0.2s, background 0.15s;
  flex-shrink: 0;
  user-select: none;
}
.swatch-arrow:hover { background: rgba(60,40,10,0.95); }
.swatch-arrow-l { left: 2px; }
.swatch-arrow-r { right: 2px; }
.swatch-arrow.sa-hidden { opacity: 0; pointer-events: none; }

/* ─── LARGE SCREEN / 4K SCALING ─────────────────── */
/* Scales menus, overlays and the game header for 1440p+ / 4K displays.
   The game canvas is excluded — it fills available space automatically via JS. */

@media (min-width: 2048px) {
  .title-content, .panel, .overlay-box, .modal-box, .challenge-panel,
  .game-header, .game-footer, .lobby-inner {
    zoom: 1.25;
  }
}

@media (min-width: 2560px) {
  .title-content, .panel, .overlay-box, .modal-box, .challenge-panel,
  .game-header, .game-footer, .lobby-inner {
    zoom: 1.5;
  }
}

@media (min-width: 3200px) {
  .title-content, .panel, .overlay-box, .modal-box, .challenge-panel,
  .game-header, .game-footer, .lobby-inner {
    zoom: 2.0;
  }
}

/* ─── SAVES OVERLAY ───────────────────────────── */

.saves-overlay-box { max-width: 360px; }

.saves-list {
  width: 100%;
  max-height: 260px;
  overflow-y: auto;
  margin: 4px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.saves-empty {
  text-align: center;
  color: var(--muted);
  padding: 24px 0;
  font-size: 0.9rem;
}

.save-item {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.save-load-btn {
  flex: 1;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-align: left;
  padding: 9px 12px;
  cursor: pointer;
  transition: background var(--transition);
  min-width: 0;
}

.save-load-btn:hover, .save-load-btn:focus { background: var(--btn-hover); }

.save-item-date    { font-size: 0.75rem; color: var(--muted); margin-bottom: 3px; }
.save-item-summary { font-size: 0.82rem; font-weight: 600; line-height: 1.3; }

.save-del-btn {
  background: rgba(200,50,20,0.12);
  border: 1px solid rgba(200,50,20,0.3);
  color: #cc4422;
  border-radius: 8px;
  width: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  font-size: 0.8rem;
  transition: background var(--transition);
}

.save-del-btn:hover { background: rgba(200,50,20,0.28); }

/* ─── LEADERBOARD BUTTON (title screen) ─── */

.lb-btn-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.lb-btn-stats {
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--gold);
  letter-spacing: 0.04em;
  opacity: 0.85;
  text-transform: none;
}

/* ─── LEADERBOARD SCREEN ───────────────────────── */

.lb-screen {
  justify-content: flex-start;
  overflow-y: auto;
  padding: 16px 0 24px;
  background: radial-gradient(ellipse at 50% 40%, var(--bg3) 0%, var(--bg) 70%);
}

.lb-panel {
  align-items: flex-start;
  gap: 0;
  padding-top: 20px;
}

.lb-section {
  width: 100%;
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.lb-section:last-of-type { border-bottom: none; padding-bottom: 0; }

.lb-heading {
  font-size: 0.8rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.lb-sub-heading {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.45);
  margin: 14px 0 8px;
}


.lb-coming-soon {
  font-size: 0.68rem;
  font-weight: 600;
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2px 8px;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.lb-stats-grid {
  display: flex;
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
  margin-bottom: 10px;
}

.lb-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 12px 0;
  border-right: 1px solid var(--border);
  background: var(--btn-bg);
}
.lb-stat:last-child { border-right: none; }

.lb-stat-val {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.02em;
}

.lb-stat-key {
  font-size: 0.63rem;
  color: var(--muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-top: 3px;
}

.lb-games-played {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

.lb-placeholder {
  font-size: 0.87rem;
  color: var(--muted);
  line-height: 1.6;
}

/* ─── LOGIN BUTTON ─────────────────────────────── */
#btn-login {
  margin: 20px 0 20px;
  z-index: 2;
  padding: 8px 14px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  background: transparent;
  color: var(--text);
  border: 1.5px solid rgba(245,230,211,0.45);
  border-radius: 8px;
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
  max-width: 200px;
  display: flex;
  align-items: center;
  overflow: hidden;
}
#btn-login span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
#btn-login:hover { background: var(--btn-hover); border-color: var(--text); }
#btn-login.logged-in { color: var(--gold); border-color: var(--gold); }
#btn-login .login-avatar {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  object-fit: cover;
  vertical-align: middle;
  margin-right: 6px;
}

/* ─── LOGIN REQUIRED TAG ───────────────────────── */
.login-required-tag {
  display: inline-block;
  margin-top: 8px;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--muted);
  border: 1px solid color-mix(in srgb, var(--muted) 35%, transparent);
  border-radius: 20px;
}
.login-required-tag.hidden { display: none; }

/* ─── GLOBAL LEADERBOARD ───────────────────────── */
#lb-online-loggedout.hidden,
#lb-online-loading.hidden,
#lb-online-content.hidden { display: none; }

.lb-loading {
  font-size: 0.84rem;
  color: var(--muted);
  text-align: center;
  padding: 10px 0;
}
.lb-skeleton-list { display: flex; flex-direction: column; gap: 6px; padding: 4px 0; }
.lb-skeleton-row {
  height: 38px;
  border-radius: 8px;
  background: linear-gradient(90deg,
    rgba(255,255,255,0.05) 25%,
    rgba(255,255,255,0.10) 50%,
    rgba(255,255,255,0.05) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.4s ease-in-out infinite;
}
@keyframes skeleton-shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}
.lb-global-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 8px;
}
.lb-global-entry {
  display: grid;
  grid-template-columns: 22px 28px 1fr 40px 44px;
  align-items: center;
  gap: 8px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  font-size: 0.82rem;
}
.lb-global-entry.is-me {
  border-color: var(--gold);
  background: color-mix(in srgb, var(--gold) 8%, var(--btn-bg));
}
.lb-global-rank {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
}
.lb-global-entry.is-me .lb-global-rank { color: var(--gold); }
.lb-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}
.lb-avatar-init {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--gold);
  color: #1a1a1a;
  font-size: 0.7rem;
  font-weight: 700;
}
.lb-global-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text);
}
.lb-global-entry.is-me .lb-global-name { color: var(--gold); font-weight: 600; }
.lb-global-wins {
  text-align: right;
  font-weight: 700;
  color: #7ecf7e;
  font-size: 0.78rem;
}
.lb-global-rate {
  text-align: right;
  color: var(--muted);
  font-size: 0.75rem;
}
.lb-global-likes {
  text-align: right;
  color: var(--muted);
  font-size: 0.75rem;
}
.lb-global-myrank {
  font-size: 0.76rem;
  color: var(--muted);
  text-align: center;
  margin-top: 4px;
}

.lb-streaks {
  display: flex;
  gap: 20px;
  justify-content: center;
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 8px;
}
.lb-streaks:empty { display: none; }
.lb-streaks strong { color: var(--text); }

.lb-diff-table {
  width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  overflow: hidden;
}
.lb-diff-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--btn-bg);
}
.lb-diff-row:last-child { border-bottom: none; }
.lb-diff-label {
  flex: 1;
  padding: 9px 12px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
}
.lb-diff-vals {
  display: flex;
  gap: 10px;
  padding: 9px 12px;
  font-size: 0.82rem;
  font-weight: 600;
}
.lb-diff-w { color: #66cc66; }
.lb-diff-l { color: #ff6644; }
.lb-diff-d { color: var(--muted); }

/* ─── UNDO BUTTON ──────────────────────────────── */

#btn-undo { color: var(--gold); border-color: rgba(212,160,23,0.35); }
#btn-undo:hover { background: rgba(212,160,23,0.12); }
#btn-undo.hidden { display: none; }

/* ─── HISTORY OVERLAY ──────────────────────────── */

.history-box {
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.history-list {
  overflow-y: auto;
  flex: 1;
  margin: 8px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  max-height: 50vh;
}
.history-entry {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 9px 4px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.history-entry:last-child { border-bottom: none; }
.history-num {
  font-size: 0.67rem;
  color: var(--muted);
  min-width: 24px;
  padding-top: 3px;
  flex-shrink: 0;
  text-align: right;
}
.history-move { display: flex; flex-direction: column; gap: 1px; }
.history-player {
  font-size: 0.68rem;
  color: var(--muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.history-notation {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
  letter-spacing: 0.03em;
}
.history-capture { color: #ff8844; }
.history-empty {
  padding: 28px;
  text-align: center;
  color: var(--muted);
  font-size: 0.87rem;
}

/* ─── TUTORIAL PANEL ───────────────────────────── */

.tut-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: linear-gradient(to top, rgba(0,0,0,0.92), rgba(5,5,10,0.82));
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.tut-panel.hidden { display: none; }

.tut-body {
  flex: 1;
  min-width: 0;
}

.tut-step-num {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 2px;
}

.tut-msg {
  font-size: 0.82rem;
  color: var(--text);
  line-height: 1.4;
  margin: 0;
}

.tut-actions {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex-shrink: 0;
}

.tut-btn {
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 6px 12px;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--transition);
  text-align: center;
}
.tut-btn:hover { background: var(--btn-hover); }
.tut-btn.primary { background: var(--red); border-color: var(--red-bright); }
.tut-btn.primary:hover { background: var(--red-bright); }
.tut-btn.hidden { display: none; }

/* ─── CHALLENGE SCREEN ─────────────────────────── */

.challenge-panel {
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.challenge-date {
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
  margin: -4px 0 4px;
}

.challenge-cards {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.challenge-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cc-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.cc-icon {
  font-size: 1.6rem;
  line-height: 1;
  flex-shrink: 0;
}

.cc-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.cc-title {
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: var(--text);
}

.cc-desc {
  font-size: 0.75rem;
  color: var(--muted);
}

.cc-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}

.cc-result {
  font-size: 0.78rem;
  font-weight: 600;
}
.cc-result.pending { color: var(--muted); }
.cc-result.won  { color: #66cc66; }
.cc-result.lost { color: #ff6644; }

/* ─── ONLINE BUTTON — darkened when no internet ─── */

#btn-play-online.offline {
  opacity: 0.32;
  pointer-events: none;
  cursor: default;
  filter: grayscale(0.5);
}

/* ─── LOBBY SCREEN ─────────────────────────────── */

#screen-lobby {
  flex-direction: column;
  justify-content: flex-start;
  align-items: center;
  overflow: hidden;
}
.lobby-inner {
  width: 100%;
  max-width: 880px;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.lobby-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px 9px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.lobby-back-btn {
  flex-shrink: 0;
}

.lobby-title {
  flex: 1;
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  text-align: center;
}

.lobby-status-text {
  font-size: 0.68rem;
  color: #b8a898;
  flex-shrink: 0;
  min-width: 50px;
  text-align: right;
}

.lobby-join-bar.hidden { display: none; }
.lobby-join-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  width: 100%;
  box-sizing: border-box;
}

.lobby-code-input {
  width: 7em;
  flex: none;
  background: rgba(255,255,255,0.07);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--gold);
  font-family: 'Courier New', monospace;
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.25em;
  text-align: center;
  text-transform: uppercase;
  padding: 7px 10px;
  outline: none;
  transition: border-color var(--transition);
}
.lobby-code-input::placeholder {
  color: #b8a898;
  font-weight: 400;
  letter-spacing: 0.05em;
  font-family: inherit;
}
.lobby-code-input:focus { border-color: var(--gold); }

.lobby-join-btn {
  flex-shrink: 0;
  padding: 7px 0.75em;
  font-size: 0.82rem;
  width: auto;
}

.reconnect-banner.hidden { display: none; }
.reconnect-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  background: rgba(80, 160, 80, 0.15);
  border-bottom: 1px solid rgba(100, 200, 100, 0.22);
  flex-shrink: 0;
}

.reconnect-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.reconnect-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #8dcc8d;
}

.reconnect-timer {
  font-size: 0.68rem;
  color: #b8a898;
}

.reconnect-btns {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.reconnect-btns .menu-btn {
  padding: 5px 12px;
  font-size: 0.78rem;
}

.lobby-grid {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-content: flex-start;
}

.lobby-loading {
  width: 100%;
  text-align: center;
  color: #b8a898;
  font-size: 0.85rem;
  padding: 40px 0;
}

.lobby-login-prompt {
  width: 100%;
  text-align: center;
  padding: 60px 20px 40px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  color: var(--muted);
  font-size: 0.9rem;
}

/* ── Lobby cards ─────────────────────────────────── */

.lobby-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 11px 12px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  width: calc(50% - 5px);
  min-width: 150px;
  max-width: 240px;
  transition: border-color var(--transition), background var(--transition);
}

@media (max-width: 380px) {
  .lobby-card { width: 100%; max-width: 100%; }
}

.lobby-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.lobby-code {
  font-family: 'Courier New', monospace;
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--gold);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  transition: opacity 0.15s;
}
.lobby-code:active { opacity: 0.6; }

.lobby-type-badge {
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #b8a898;
  background: rgba(255,255,255,0.06);
  padding: 2px 5px;
  border-radius: 4px;
  white-space: nowrap;
  flex: 1;
}
.lobby-delete-btn {
  background: none;
  border: none;
  color: rgba(255,255,255,0.3);
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  cursor: pointer;
  transition: color 0.15s;
  flex-shrink: 0;
}
.lobby-delete-btn:hover { color: rgba(220, 70, 50, 0.9); }

/* Mini board thumbnail */
.lobby-thumb-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 6px;
  overflow: visible;
  border: 1px solid rgba(255,255,255,0.07);
}

.lobby-thumb {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  border-radius: 6px;
  overflow: hidden;
}

/* ── Slot rows — overlaid on board thumbnail ─── */

.lobby-slots {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px 7px 7px;
  background: rgba(12, 7, 2, 0.9);
  box-shadow: 0 4px 18px rgba(0,0,0,0.7);
}

.lobby-slots-4p {
  gap: 2px;
  padding: 4px 6px;
}
.lobby-slots-4p .lobby-slot {
  padding: 2px 5px;
  font-size: 0.66rem;
}
.lobby-slots-4p .lobby-slot-avatar {
  width: 22px;
  height: 22px;
  min-width: 22px;
  font-size: 0.6rem;
}

.lobby-slot {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 4px 6px;
  border-radius: 5px;
  font-size: 0.75rem;
  background: rgba(255,255,255,0.06);
  color: #e8ddd0;
}

.lobby-slot.filled { border: 1px solid rgba(255,255,255,0.1); }
.lobby-slot.empty  { border: 1px dashed rgba(255,255,255,0.12); color: rgba(232,221,208,0.5); }
.lobby-slot.is-me  { border-color: rgba(212,160,23,0.5); background: rgba(212,160,23,0.1); }

.lobby-slot-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  flex-shrink: 0;
  object-fit: cover;
  background: var(--bg2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text);
  border: 3px solid var(--border);
  overflow: hidden;
}
.slot-col-0 { border-color: #cc3300; }
.slot-col-1 { border-color: #708090; }
.slot-col-2 { border-color: #3b82d8; }
.slot-col-3 { border-color: #d4a017; }

.lobby-slot-info {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.lobby-slot-name {
  white-space: nowrap;
  font-size: 0.76rem;
  color: #f0e8df;
}

.lobby-slot-name.scrolling {
  animation: lobby-name-scroll 5s ease-in-out infinite;
}

@keyframes lobby-name-scroll {
  0%, 25%  { transform: translateX(0); }
  75%, 100% { transform: translateX(var(--scroll-dist)); }
}

.slot-ready-tick {
  font-size: 0.7rem;
  font-weight: 700;
  color: #55cc55;
  flex-shrink: 0;
}
.slot-ready-tick.pending { color: rgba(240,232,223,0.4); }


.lobby-slot-waiting {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.18);
}

.lobby-slot-join,
.lobby-slot-leave {
  font-size: 0.67rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 5px;
  border: none;
  cursor: pointer;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  flex-shrink: 0;
  transition: background var(--transition);
}
.lobby-slot-join  { background: var(--red); color: #fff; }
.lobby-slot-join:hover  { background: var(--red-bright); }
.lobby-slot-leave { background: rgba(255,255,255,0.07); color: #b8a898; }
.lobby-slot-leave:hover { background: rgba(255,255,255,0.13); }

/* Ready button */
.lobby-ready-btn {
  width: 100%;
  padding: 6px;
  background: #1e5c1e;
  border: 1px solid #3a8a3a;
  border-radius: 7px;
  color: #99ee99;
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  cursor: pointer;
  transition: background var(--transition);
  text-align: center;
}
.lobby-ready-btn:hover { background: #266626; }

.lobby-start-btn {
  width: 100%;
  padding: 6px;
  background: #1a4a8a;
  border: 1px solid #3a7acc;
  border-radius: 7px;
  color: #aaddff;
  font-size: 0.77rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  cursor: pointer;
  transition: background var(--transition), opacity var(--transition);
  text-align: center;
}
.lobby-start-btn:hover:not([disabled]) { background: #1f5caa; }
.lobby-start-btn.dimmed { opacity: 0.38; cursor: default; }

/* All-ready banner */
.lobby-all-ready {
  width: 100%;
  text-align: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  color: #99ee99;
  padding: 8px;
  background: rgba(40,100,40,0.18);
  border: 1px solid rgba(80,180,80,0.25);
  border-radius: 7px;
  animation: pulse-green 1.2s ease-in-out infinite;
}
@keyframes pulse-green {
  0%,100% { opacity: 0.8; }
  50%      { opacity: 1;   }
}

/* ── Create card ─────────────────────────────────── */

.lobby-section-label {
  width: 100%;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #b8a898;
  padding: 4px 2px 2px;
}

.live-badge {
  font-size: 0.62rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  color: #ff4444;
  background: rgba(255,60,60,0.15);
  border: 1px solid rgba(255,60,60,0.35);
  border-radius: 4px;
  padding: 1px 5px;
}

/* ── Spectator card edge name labels ─── */
.spec-name {
  position: absolute;
  font-size: 0.58rem;
  font-weight: 700;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  pointer-events: none;
  line-height: 1.3;
  padding: 2px 4px;
  letter-spacing: 0.02em;
}
.spec-name-top {
  top: 0; left: 0; right: 0;
  text-align: center;
  background: rgba(40,40,40,0.88);
  color: #c0c0c0;
}
.spec-name-bottom {
  bottom: 0; left: 0; right: 0;
  text-align: center;
  background: rgba(160,30,0,0.88);
  color: #fff;
}
.spec-name-left {
  left: 0; top: 0; bottom: 0;
  width: 14px;
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  text-align: center;
  background: rgba(15,70,160,0.88);
  color: #fff;
  padding: 4px 2px;
}
.spec-name-right {
  right: 0; top: 0; bottom: 0;
  width: 14px;
  writing-mode: vertical-rl;
  text-align: center;
  background: rgba(150,110,0,0.88);
  color: #fff;
  padding: 4px 2px;
}

.spectator-count {
  font-size: 0.68rem;
  color: #b8a898;
  margin-left: auto;
}

.lobby-watch-btn {
  background: rgba(80,120,200,0.18);
  color: #88aaee;
  border: 1px solid rgba(80,120,200,0.3);
}
.lobby-watch-btn:hover { background: rgba(80,120,200,0.3); }

/* ─── SPECTATOR BAR ─────────────────────────── */

.spectator-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 14px;
  background: rgba(60,100,180,0.18);
  border-bottom: 1px solid rgba(80,120,220,0.25);
  gap: 10px;
}
.spectator-bar.hidden { display: none; }
.spectator-label {
  font-size: 0.78rem;
  color: var(--muted);
  letter-spacing: 0.03em;
}
.spectator-back-btn {
  background: none;
  border: 1px solid rgba(80,120,220,0.35);
  border-radius: 6px;
  color: var(--fg);
  font-size: 0.78rem;
  padding: 3px 10px;
  cursor: pointer;
  white-space: nowrap;
}
.spectator-back-btn:hover { background: rgba(80,120,220,0.15); }

.lobby-card.create-card {
  border-style: dashed;
  border-color: rgba(212,160,23,0.22);
  background: transparent;
  justify-content: center;
  align-items: center;
  min-height: 110px;
  gap: 7px;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.lobby-card.create-card:hover {
  border-color: rgba(212,160,23,0.5);
  background: rgba(30,14,0,0.4);
}

.create-card-plus {
  font-size: 2rem;
  color: var(--gold-dim);
  line-height: 1;
  transition: color var(--transition);
  pointer-events: none;
}
.lobby-card.create-card:hover .create-card-plus { color: var(--gold); }

.create-card-label {
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--muted);
  pointer-events: none;
}

/* ── Waiting for opponent in-game ────────────────── */

.online-waiting-banner {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(10,5,0,0.88);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px 24px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.04em;
  pointer-events: none;
  z-index: 10;
  display: none;
}
.online-waiting-banner.visible { display: block; }

/* ─── CREATE GAME MODAL ─────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg2);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: 14px;
  padding: 20px 18px;
  width: min(360px, calc(100vw - 20px));
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 24px 56px rgba(0,0,0,0.65);
}

.modal-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  text-align: center;
  margin-bottom: 2px;
}

.modal-section-gap { padding-top: 6px; }

.modal-section-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.modal-tabs {
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}
.modal-tabs.hidden { display: none; }

.modal-tab {
  flex: 1;
  min-width: 54px;
  padding: 7px 6px;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  cursor: pointer;
  transition: all var(--transition);
  text-align: center;
}
.modal-tab:hover  { background: var(--btn-hover); color: var(--text); }
.modal-tab.active { background: var(--red); color: #fff; border-color: var(--red-bright); }

.modal-btns {
  display: flex;
  gap: 9px;
  margin-top: 16px;
}
.modal-btns .menu-btn { flex: 1; margin: 0; }

/* ─── STORE ─────────────────────────────────────── */

.title-top-bar {
  position: absolute;
  top: 16px;
  left: 16px;
  right: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 3;
}
.title-top-bar.hidden { display: none; }
.title-top-bar #btn-login { margin: 0; height: 34px; box-sizing: border-box; }
.title-top-bar .store-icon-btn { height: 34px; box-sizing: border-box; }

.store-icon-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  background: transparent;
  color: var(--gold);
  border: 1.5px solid rgba(212,160,23,0.38);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
  flex-shrink: 0;
  white-space: nowrap;
}
.store-icon-btn:hover {
  background: rgba(212,160,23,0.12);
  border-color: rgba(212,160,23,0.68);
}

#screen-store {
  background: radial-gradient(ellipse at 50% 30%, var(--bg3) 0%, var(--bg) 70%);
  overflow-y: auto;
  justify-content: flex-start;
  align-items: center;
}

.store-wrap {
  width: 100%;
  max-width: 460px;
  padding: 0 16px 60px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.store-topbar {
  display: grid;
  grid-template-columns: 44px 1fr 44px;
  align-items: center;
  gap: 8px;
  padding: 18px 0 6px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: linear-gradient(to bottom, var(--bg) 78%, transparent 100%);
}

.store-back-btn {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--btn-bg);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--text);
  transition: background var(--transition);
  flex-shrink: 0;
}
.store-back-btn:hover { background: var(--btn-hover); }

.store-heading {
  font-size: 1.5rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  color: var(--text);
  text-align: center;
}

.store-heading-icon {
  color: var(--gold);
  opacity: 0.6;
  flex-shrink: 0;
}

.store-pills {
  display: flex;
  gap: 8px;
}

.store-pill {
  flex: 1;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1.5px solid var(--border);
  background: var(--btn-bg);
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  cursor: pointer;
  transition: all var(--transition);
}
.store-pill:hover:not(.active) { background: var(--btn-hover); color: var(--text); }
.store-pill.active {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(212,160,23,0.12);
}

.store-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: clamp(7px, 2vw, 12px);
}

.store-card {
  background: linear-gradient(155deg, rgba(255,255,255,0.07) 0%, rgba(0,0,0,0.12) 100%);
  border: 1.5px solid var(--border);
  border-radius: clamp(8px, 2.5vw, 14px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.18s, border-color 0.18s, box-shadow 0.18s;
}
.store-card:hover {
  transform: translateY(-3px);
  border-color: rgba(255,255,255,0.24);
  box-shadow: 0 8px 24px rgba(0,0,0,0.6);
}
.store-card.is-premium {
  border-color: rgba(212,160,23,0.3);
  background: linear-gradient(155deg, rgba(212,160,23,0.08) 0%, rgba(0,0,0,0.12) 100%);
}
.store-card.is-premium:hover {
  border-color: rgba(212,160,23,0.55);
  box-shadow: 0 8px 24px rgba(212,160,23,0.14);
}

.store-card-canvas {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  background: rgba(0,0,0,0.3);
}

.store-card-body {
  padding: clamp(6px, 1.5vw, 10px) clamp(7px, 1.8vw, 12px) clamp(8px, 2vw, 12px);
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.store-card-name {
  font-size: clamp(0.72rem, 2.2vw, 0.88rem);
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.store-card-type {
  font-size: clamp(0.6rem, 1.7vw, 0.7rem);
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: -2px;
}

.store-card-btn {
  width: 100%;
  padding: clamp(5px, 1.4vw, 8px) 0;
  border-radius: 6px;
  font-size: clamp(0.7rem, 2vw, 0.8rem);
  font-weight: 700;
  letter-spacing: 0.03em;
  cursor: pointer;
  border: 1.5px solid;
  transition: all 0.15s;
}
.store-card-btn.btn-free {
  background: rgba(100,210,100,0.13);
  border-color: rgba(100,210,100,0.4);
  color: #88ee88;
}
.store-card-btn.btn-free:hover { background: rgba(100,210,100,0.24); }
.store-card-btn.btn-buy {
  background: rgba(212,160,23,0.13);
  border-color: rgba(212,160,23,0.4);
  color: var(--gold);
}
.store-card-btn.btn-buy:hover { background: rgba(212,160,23,0.24); }
.store-card-btn.btn-owned {
  background: transparent;
  border-color: rgba(100,210,100,0.22);
  color: rgba(136,221,136,0.5);
  cursor: default;
  pointer-events: none;
}

/* ── TV / WebOS ────────────────────────────────────────────────────── */
@media (min-width: 1920px) {
  html, body { width: 100%; height: 100%; overflow: hidden; }
  .screen { width: 100vw !important; height: 100vh !important; }
  :root { font-size: 20px; }
}
/* WebOS focus ring for D-pad navigation */
.webos-focus button:focus,
.webos-focus a:focus,
.webos-focus [tabindex]:focus {
  outline: 3px solid var(--gold);
  outline-offset: 3px;
  box-shadow: 0 0 12px rgba(201,162,39,0.7);
}

/* ── WebOS native TV app only (window.PalmSystem/webOSSystem) ──────────
   The webOS 5.0 native app container runs Chrome 68, which predates
   flexbox `gap` (added in Chrome 84) and has a button-sizing bug where
   display:flex buttons don't grow to fit their own content. Both
   fallbacks below are scoped to .is-webos-native, which JS only adds
   when window.PalmSystem/webOSSystem exist — i.e. never in any browser,
   not even this TV's own browser. Cannot affect the PWA or other devices. */
.is-webos-native .menu-btn {
  min-height: 52px;
}
.is-webos-native .menu-buttons > *:not(:last-child),
.is-webos-native .overlay-btns > *:not(:last-child),
.is-webos-native .panel:not(.howto-panel) > *:not(:last-child) {
  margin-bottom: 16px;
}
.is-webos-native .play-panel-btns > *:not(:last-child) {
  margin-right: 8px;
}
/* Icon-to-text gap inside buttons (same missing-gap issue, one level
   deeper: .menu-btn/#btn-start use gap for their own svg+label spacing). */
.is-webos-native .menu-btn svg,
.is-webos-native #btn-start svg {
  margin-right: 10px;
}
/* Same flex-gap fallback, extended to every other flex container reachable
   on the TV build (settings/players, game header, tutorial, challenge,
   how-to-play buttons already handled above). Grid gap (.rule-tabs) is
   unaffected by this engine and needs no fallback. */
.is-webos-native .mode-tabs > *:not(:last-child),
.is-webos-native .mode-tab > *:not(:last-child),
.is-webos-native .settings-category > *:not(:last-child),
.is-webos-native .history-entry > *:not(:last-child),
.is-webos-native .tut-panel > *:not(:last-child) {
  margin-right: 10px;
}
.is-webos-native .hdr-left > *:not(:last-child),
.is-webos-native .voice-btns > *:not(:last-child) {
  margin-right: 6px;
}
/* .settings-label/.store-icon-btn are icon + bare text (no wrapping tag
   around the label), so :not(:last-child) can't see the text node as a
   sibling — margin the icon directly instead. */
.is-webos-native .settings-label svg,
.is-webos-native .store-icon-btn svg {
  margin-right: 10px;
}
.is-webos-native .hdr-count > *:not(:last-child),
.is-webos-native .modal-tabs > *:not(:last-child) {
  margin-right: 5px;
}
.is-webos-native .hdr-counts > *:not(:last-child),
.is-webos-native .go-record-row > *:not(:last-child),
.is-webos-native .piece-swatches > *:not(:last-child) {
  margin-right: 8px;
}
.is-webos-native .theme-swatches > *:not(:last-child) {
  margin-right: 7px;
}
.is-webos-native .modal-btns > *:not(:last-child) {
  margin-right: 9px;
}
.is-webos-native .player-card > *:not(:last-child),
.is-webos-native .cc-header > *:not(:last-child) {
  margin-right: 12px;
}
.is-webos-native .diff-card > *:not(:last-child) {
  margin-right: 14px;
}
.is-webos-native .title-logo > *:not(:last-child),
.is-webos-native .overlay-box > *:not(:last-child) {
  margin-bottom: 16px;
}
.is-webos-native .title-content > *:not(:last-child) {
  margin-bottom: 18px;
}
.is-webos-native .player-cards > *:not(:last-child) {
  margin-bottom: 8px;
}
.is-webos-native .rule-tab > *:not(:last-child),
.is-webos-native .theme-swatch > *:not(:last-child),
.is-webos-native .piece-swatch > *:not(:last-child) {
  margin-bottom: 3px;
}
.is-webos-native .diff-options > *:not(:last-child),
.is-webos-native .challenge-cards > *:not(:last-child),
.is-webos-native .challenge-card > *:not(:last-child) {
  margin-bottom: 10px;
}
.is-webos-native .diff-info > *:not(:last-child) {
  margin-bottom: 3px;
}
.is-webos-native .tut-actions > *:not(:last-child) {
  margin-bottom: 5px;
}
.is-webos-native .challenge-panel > *:not(:last-child),
.is-webos-native .modal-box > *:not(:last-child) {
  margin-bottom: 12px;
}
/* Google popup sign-in has no popup surface in the native app container
   and is blocked by Google for embedded webviews regardless — hide it,
   and hide the online-only features that require being signed in. */
.is-webos-native #btn-login,
.is-webos-native #btn-play-online,
.is-webos-native #btn-leaderboard {
  display: none !important;
}
/* Medium/Large 4P boards (20x20 / 28x28, up to 85 pieces) are too
   demanding for this hardware — TV only offers the Small board. */
.is-webos-native [data-4psize="medium"],
.is-webos-native [data-4psize="large"] {
  display: none !important;
}


/* ═══════════════════════════════════════════════════════
   DESKTOP LAYOUT  ≥860px
   Targets menus, settings, and the store.
   Title screen and game screen are unchanged.
   ═══════════════════════════════════════════════════════ */
@media (min-width: 860px) {

  /* ── Panels ─────────────────────────────────────────── */
  .panel         { max-width: 600px; padding: 32px 28px; gap: 18px; overflow-x: hidden; }
  .players-panel { max-width: 600px; }
  .overlay-box   { max-width: 480px; padding: 40px 36px 32px; }
  .overlay-box.small { max-width: 360px; }

  /* Mode tabs and rule tabs spread evenly */
  .mode-tabs { gap: 14px; }
  .mode-tab  { padding: 14px 20px; }
  .rule-tabs { gap: 12px; }
  .rule-tab  { padding: 12px 10px; font-size: 0.9rem; }

  /* Play button less stretched on desktop */
  #btn-go {
    max-width: 260px;
    align-self: center;
    padding: 16px 40px;
    font-size: 1.05rem;
  }

  /* Settings rows a little roomier */
  .settings-row { padding: 14px 20px; gap: 20px; }

  /* Swatch containers fill the full available row width on desktop */
  .piece-swatches,
  .theme-swatches {
    width: calc(100% - 64px);
    max-width: calc(100% - 64px);
    margin-left: 32px;
    margin-right: 32px;
  }

  /* Play panel buttons side-by-side */
  .play-panel-btns { flex-direction: row; }
  .play-panel-btns .menu-btn { flex: 1; }

  /* ── Online lobby ────────────────────────────────────── */
  .lobby-inner { max-width: 1100px; }
  .lobby-join-bar {
    max-width: 480px;
    align-self: center;
    border-bottom: none;
    padding: 14px 0;
  }
  .lobby-join-bar .menu-btn { min-width: 120px; }
  .lobby-loading { text-align: right; padding-right: 4px; }

  /* ── Store ───────────────────────────────────────────── */
  .store-wrap {
    max-width: 100%;
    padding: 0 5vw 100px;
    gap: 22px;
  }
  .store-topbar  { padding: 28px 0 10px; }
  .store-heading { font-size: 1.7rem; }

  /* Filter pills — more padding, centred */
  .store-pills {
    max-width: 500px;
    align-self: center;
    gap: 14px;
  }
  .store-pill {
    padding: 14px 22px;
    font-size: 1rem;
    border-radius: 24px;
  }

  /* 6 cards per row on desktop, half the previous size */
  .store-grid {
    grid-template-columns: repeat(6, 1fr);
    gap: 24px;
  }
  .store-card        { border-radius: 16px; }
  .store-card-preview { min-height: 220px; }
  .store-card-info   { padding: 16px 18px 18px; gap: 10px; }
  .store-card-name   { font-size: 1.1rem; }
  .store-card-btn    { padding: 10px 18px; font-size: 0.95rem; border-radius: 10px; }


  /* ── Game screen: full-width header above the board ───── */
  .game-main { position: relative; }
  .turn-bar { font-size: 1rem; }

} /* end @media ≥860px */

@media (min-width: 1280px) {
  /* At wider screens go to 4 columns but keep cards large */
  .store-grid { grid-template-columns: repeat(8, 1fr); gap: 28px; }
  .store-card-preview { min-height: 260px; }
  .panel, .players-panel { max-width: 680px; }
}

@media (min-width: 1920px) {
  .store-grid { grid-template-columns: repeat(10, 1fr); gap: 32px; }
  .store-card-preview { min-height: 300px; }
}

/* ── Music prerender loading indicator ─────────────────── */
.music-loading {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 5px;
  opacity: 0.45;
  font-size: 11px;
  color: #fff;
  white-space: nowrap;
  transition: opacity 0.8s ease;
  pointer-events: none;
}
.music-loading.hidden { opacity: 0; }
.music-loading-note { font-size: 13px; margin-right: 2px; }
.music-loading-bar {
  display: inline-block;
  width: 3px;
  border-radius: 2px;
  background: #fff;
  animation: ml-bounce 0.9s ease-in-out infinite alternate;
}
.music-loading-bar:nth-child(2) { height: 8px; animation-delay: 0s; }
.music-loading-bar:nth-child(3) { height: 13px; animation-delay: 0.2s; }
.music-loading-bar:nth-child(4) { height: 6px; animation-delay: 0.4s; }
@keyframes ml-bounce {
  from { transform: scaleY(0.4); opacity: 0.5; }
  to   { transform: scaleY(1);   opacity: 1; }
}
