/* ═══════════════════════════════════════════════
   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:       #7a5a3a;
  --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;
}

/* ─── 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);
}
.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

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

#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.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); }

.diff-badge {
  margin-left: auto;
  background: rgba(255,255,255,0.12);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--gold);
}
.menu-btn.primary .diff-badge { color: rgba(255,255,255,0.82); }

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

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

.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; }

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

.theme-swatches { display: flex; gap: 7px; align-items: center; }

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

.theme-swatch[data-theme="classic"] { background: linear-gradient(135deg, #f0d9b5 50%, #b58863 50%); }
.theme-swatch[data-theme="green"]   { background: linear-gradient(135deg, #e8f0d0 50%, #4a8540 50%); }
.theme-swatch[data-theme="slate"]   { background: linear-gradient(135deg, #b8c5d8 50%, #4a5870 50%); }
.theme-swatch[data-theme="night"]   { background: linear-gradient(135deg, #3a3a44 50%, #1a1a22 50%); }
.theme-swatch[data-theme="maple"]   { 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);
}

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

/* ─── 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; }
#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-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: rgba(0,0,0,0.6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  height: 54px;
  width: 100%;
  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 {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  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 {
  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-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 6px;
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

#game-canvas {
  display: block;
  cursor: pointer;
  touch-action: none;
  border-radius: 6px;
  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);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  width: 100%;
  position: relative;
}

.footer-diff {
  font-size: 0.75rem;
  color: var(--gold-dim);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  font-weight: 700;
  padding-left: 4px;
  border-left: 1px solid var(--border);
  margin-left: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.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; }

.footer-hint {
  font-size: 0.75rem;
  color: var(--muted);
  transition: opacity 0.3s;
}

/* ─── 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);
  z-index: 200;
  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; }

@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;
}

/* ─── 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   { height: 46px; padding: 4px 12px; }
  .game-footer   { height: 30px; }
}

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

/* ─── 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-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;
}

.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; }
