/* ============================================================
   ChessMaster — Styles
   ============================================================ */

/* ---------- CSS Variables ---------- */
:root {
  --bg: #0f1117;
  --bg2: #161b22;
  --bg3: #21262d;
  --bg4: #30363d;
  --border: #30363d;
  --text: #e6edf3;
  --text2: #8b949e;
  --accent: #58a6ff;
  --accent2: #388bfd;
  --success: #3fb950;
  --danger: #f85149;
  --warning: #d29922;
  --gold: #f0c040;
  --light-sq: #f0d9b5;
  --dark-sq: #b58863;
  --sq-size: 72px;
  --sidebar-w: 220px;
  --radius: 10px;
  --shadow: 0 4px 24px rgba(0,0,0,.5);
  --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --transition: .18s ease;
}

.light-theme {
  --bg: #f4f6fa;
  --bg2: #ffffff;
  --bg3: #eaf0fb;
  --bg4: #d1d9e8;
  --border: #d0d7e3;
  --text: #1a1f2e;
  --text2: #5a6480;
  --accent: #1a73e8;
  --accent2: #1558b0;
  --shadow: 0 4px 24px rgba(0,0,0,.12);
}

/* ---------- Reset & Base ---------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100%;
  overflow: hidden;
}

/* ---------- Splash ---------- */
.splash {
  position: fixed; inset: 0;
  background: linear-gradient(135deg, #0f1117 0%, #1a1f3a 50%, #0f1117 100%);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  transition: opacity .5s, transform .5s;
}
.splash.fade-out { opacity: 0; pointer-events: none; }
.splash-content { text-align: center; }
.splash-icon {
  font-size: 80px;
  display: block;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}
@keyframes float {
  0%,100% { transform: translateY(0); }
  50% { transform: translateY(-12px); }
}
.splash h1 {
  font-size: 48px;
  font-weight: 800;
  background: linear-gradient(135deg, #58a6ff, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 8px;
}
.splash p { color: #8b949e; font-size: 18px; margin-bottom: 32px; }

/* ---------- App Shell ---------- */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}
.hidden { display: none !important; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 0;
  flex-shrink: 0;
  transition: transform var(--transition), width var(--transition);
  z-index: 50;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 20px 16px;
  font-size: 18px; font-weight: 700;
  border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 24px; }
.logo-text { color: var(--text); }

.nav-list { list-style: none; padding: 12px 8px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 12px;
  border-radius: 8px;
  cursor: pointer;
  color: var(--text2);
  font-size: 14px; font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 4px;
}
.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-icon { font-size: 18px; }

.sidebar-footer {
  padding: 16px;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.theme-toggle {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; width: 36px; height: 36px;
  cursor: pointer; font-size: 16px;
  transition: all var(--transition);
}
.theme-toggle:hover { background: var(--bg4); }
.progress-summary { flex: 1; }
.xp-bar-mini {
  height: 4px; border-radius: 2px;
  background: var(--bg4); margin-bottom: 4px; overflow: hidden;
}
.xp-fill-mini {
  height: 100%; background: linear-gradient(90deg, var(--accent), #a78bfa);
  border-radius: 2px; width: 0%;
  transition: width .4s ease;
}
#xp-label { font-size: 11px; color: var(--text2); }

/* ---------- Main Content ---------- */
.main-content {
  flex: 1; display: flex; flex-direction: column;
  overflow: hidden; min-width: 0;
}

.top-bar {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 20px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.menu-toggle {
  background: none; border: none; color: var(--text2);
  font-size: 20px; cursor: pointer; padding: 4px 8px;
  border-radius: 6px; display: none;
}
.menu-toggle:hover { background: var(--bg3); }
.view-title { font-size: 18px; font-weight: 700; flex: 1; }
.top-bar-right { display: flex; align-items: center; gap: 12px; }

.streak-badge {
  display: flex; align-items: center; gap: 4px;
  background: var(--bg3); border: 1px solid var(--border);
  padding: 6px 12px; border-radius: 20px; font-size: 14px;
}
.level-badge {
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  color: #fff; padding: 6px 12px;
  border-radius: 20px; font-size: 13px; font-weight: 700;
}

/* ---------- Views ---------- */
.view-container { flex: 1; overflow: hidden; }
.view { display: none; height: 100%; overflow: auto; }
.view.active { display: flex; flex-direction: column; }

/* ---------- Layouts ---------- */
.openings-layout, .tactics-layout, .endgames-layout {
  display: grid;
  grid-template-columns: 240px 1fr 280px;
  height: 100%;
  overflow: hidden;
}
.sandbox-layout {
  display: grid;
  grid-template-columns: 1fr 300px;
  height: 100%;
  overflow: hidden;
}

/* ---------- Openings Sidebar ---------- */
.openings-sidebar, .tactics-sidebar, .endgames-sidebar {
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
  padding: 12px;
}
.openings-sidebar h3, .tactics-sidebar h3, .endgames-sidebar h3 {
  font-size: 14px; font-weight: 700;
  padding: 4px 4px 12px;
  color: var(--text2);
  text-transform: uppercase; letter-spacing: .05em;
}

.search-box {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 13px;
  margin-bottom: 10px;
  outline: none;
  transition: border-color var(--transition);
}
.search-box:focus { border-color: var(--accent); }
.search-box::placeholder { color: var(--text2); }

.opening-categories, .difficulty-filters {
  display: flex; gap: 4px; flex-wrap: wrap;
  margin-bottom: 10px;
}
.cat-btn, .diff-btn {
  padding: 4px 10px; font-size: 12px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; color: var(--text2);
  cursor: pointer; transition: all var(--transition);
}
.cat-btn:hover, .diff-btn:hover { border-color: var(--accent); color: var(--text); }
.cat-btn.active, .diff-btn.active {
  background: var(--accent); border-color: var(--accent); color: #fff;
}

.opening-list, .puzzle-list, .endgame-list {
  flex: 1; overflow-y: auto;
  display: flex; flex-direction: column; gap: 4px;
}
.opening-list::-webkit-scrollbar,
.puzzle-list::-webkit-scrollbar,
.endgame-list::-webkit-scrollbar { width: 4px; }
.opening-list::-webkit-scrollbar-thumb,
.puzzle-list::-webkit-scrollbar-thumb,
.endgame-list::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }

.opening-item, .puzzle-item, .endgame-item {
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
}
.opening-item:hover, .puzzle-item:hover, .endgame-item:hover {
  background: var(--bg3); border-color: var(--border);
}
.opening-item.active, .puzzle-item.active, .endgame-item.active {
  background: var(--bg3); border-color: var(--accent);
}
.opening-item-name, .puzzle-item-name, .endgame-item-name {
  font-size: 13px; font-weight: 600; margin-bottom: 2px;
}
.opening-item-meta { font-size: 11px; color: var(--text2); }
.puzzle-item-badges { display: flex; gap: 4px; margin-top: 4px; }

/* ---------- Board Area ---------- */
.board-area {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 20px;
  background: var(--bg);
  overflow: hidden;
}
.sandbox-board-area { border-right: 1px solid var(--border); }

.board-wrapper { display: flex; flex-direction: column; align-items: center; }
.board-row-wrapper { display: flex; align-items: center; }

.board-coordinates {
  display: flex;
  color: var(--text2);
  font-size: 11px;
  font-weight: 600;
  user-select: none;
}
.board-coordinates.top,
.board-coordinates.bottom { flex-direction: row; margin: 3px 0; padding-left: 18px; padding-right: 0; }
.board-coordinates.left,
.board-coordinates.right { flex-direction: column; width: 18px; }
.board-coordinates .coord { display: flex; align-items: center; justify-content: center; }
.board-coordinates.top .coord,
.board-coordinates.bottom .coord { width: var(--sq-size); text-align: center; }
.board-coordinates.left .coord,
.board-coordinates.right .coord { height: var(--sq-size); }

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, var(--sq-size));
  grid-template-rows: repeat(8, var(--sq-size));
  border: 3px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: var(--shadow);
  user-select: none;
}

.square {
  width: var(--sq-size); height: var(--sq-size);
  display: flex; align-items: center; justify-content: center;
  position: relative; cursor: pointer;
  transition: filter .1s;
}
.square.light { background: var(--light-sq); }
.square.dark { background: var(--dark-sq); }
.square:hover { filter: brightness(1.12); }
.square.selected { box-shadow: inset 0 0 0 3px #ffff00; }
.square.last-move { box-shadow: inset 0 0 0 3px rgba(255,200,0,.6); }
.square.possible-move::after {
  content: '';
  position: absolute;
  width: 28px; height: 28px;
  background: rgba(0,0,0,.25);
  border-radius: 50%;
}
.square.possible-capture::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 2px;
  border: 4px solid rgba(0,0,0,.3);
}
.square.check { background: #e74c3c !important; }
.square.highlight-green { background: rgba(100,200,100,.5) !important; }
.square.highlight-red { background: rgba(220,60,60,.5) !important; }
.square.hint-sq { box-shadow: inset 0 0 0 3px #a78bfa; }

.piece {
  font-size: calc(var(--sq-size) * .72);
  line-height: 1;
  cursor: grab;
  transition: transform .1s;
  position: relative; z-index: 1;
  pointer-events: none;
}
/* White pieces: bright white fill with strong dark outline */
.piece.white-piece {
  color: #ffffff;
  text-shadow:
    0 0 2px #000,
    1px  1px 0 #222,
   -1px -1px 0 #222,
    1px -1px 0 #222,
   -1px  1px 0 #222,
    0    2px 4px rgba(0,0,0,.6);
  filter: drop-shadow(0 1px 3px rgba(0,0,0,.7));
}
/* Black pieces: near-black fill with subtle light edge */
.piece.black-piece {
  color: #1a1a1a;
  text-shadow:
    0 0 1px rgba(255,255,255,.25),
    1px  1px 0 rgba(255,255,255,.15),
   -1px -1px 0 rgba(255,255,255,.15),
    0    2px 4px rgba(0,0,0,.5);
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.5));
}
.piece.dragging { cursor: grabbing; opacity: .7; transform: scale(1.15); }

/* ---------- Player Bars ---------- */
.player-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 4px;
  border-radius: 6px;
  width: 100%;
  /* matches board width: 8 squares + 2px border each side */
  max-width: calc(var(--sq-size) * 8 + 6px);
  transition: background var(--transition);
}
.player-bar.active {
  background: rgba(88,166,255,.10);
  outline: 1.5px solid var(--accent);
}
.player-swatch {
  width: 18px; height: 18px;
  border-radius: 50%;
  flex-shrink: 0;
  border: 2px solid var(--border);
}
.player-swatch-white {
  background: #f5f5f5;
  box-shadow: 0 0 0 1px #bbb;
}
.player-swatch-black {
  background: #1a1a1a;
  box-shadow: 0 0 0 1px #555;
}
.player-name {
  font-size: 13px;
  font-weight: 600;
  color: var(--text2);
  flex: 1;
}
.player-bar.active .player-name {
  color: var(--text);
}
.player-turn-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: transparent;
  transition: background .2s, box-shadow .2s;
}
.player-turn-dot.active {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  animation: pulse-dot 1.2s ease-in-out infinite;
}
@keyframes pulse-dot {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: .6; transform: scale(1.35); }
}

/* ---------- Board Controls ---------- */
.board-controls {
  display: flex; gap: 8px;
  margin-top: 12px;
}
.ctrl-btn {
  padding: 8px 14px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text2);
  cursor: pointer; font-size: 14px;
  transition: all var(--transition);
}
.ctrl-btn:hover { background: var(--bg3); color: var(--text); border-color: var(--accent); }
.flip-btn { letter-spacing: 2px; }

/* ---------- Info Panel ---------- */
.info-panel {
  background: var(--bg2);
  border-left: 1px solid var(--border);
  padding: 16px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 16px;
}
.info-panel::-webkit-scrollbar { width: 4px; }
.info-panel::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }

.opening-header h3 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.opening-meta { display: flex; gap: 6px; flex-wrap: wrap; }

.move-list-container h4 { font-size: 12px; font-weight: 700; color: var(--text2); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px; }
.move-list {
  display: flex; flex-wrap: wrap; gap: 4px;
  max-height: 120px; overflow-y: auto;
}
.move-chip {
  padding: 4px 8px; border-radius: 6px;
  font-size: 13px; font-weight: 600;
  background: var(--bg3); border: 1px solid var(--border);
  cursor: pointer; transition: all var(--transition);
  font-family: 'Courier New', monospace;
}
.move-chip:hover { border-color: var(--accent); }
.move-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.move-chip.white-move { color: var(--text); }
.move-chip.black-move { color: var(--text2); }

.opening-description { font-size: 14px; line-height: 1.6; color: var(--text2); }
.opening-description p { margin-bottom: 8px; }

.quiz-section { border-top: 1px solid var(--border); padding-top: 16px; }
.quiz-prompt {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px;
  font-size: 14px; margin-bottom: 8px;
}
.quiz-feedback {
  font-size: 14px; font-weight: 600;
  min-height: 24px; margin-bottom: 8px;
}

/* ---------- Badges ---------- */
.badge {
  padding: 3px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
}
.badge-easy { background: rgba(63,185,80,.2); color: #3fb950; border: 1px solid rgba(63,185,80,.3); }
.badge-medium { background: rgba(210,153,34,.2); color: #d29922; border: 1px solid rgba(210,153,34,.3); }
.badge-hard { background: rgba(248,81,73,.2); color: #f85149; border: 1px solid rgba(248,81,73,.3); }
.badge-fork { background: rgba(88,166,255,.2); color: #58a6ff; border: 1px solid rgba(88,166,255,.3); }
.badge-pin { background: rgba(167,139,250,.2); color: #a78bfa; border: 1px solid rgba(167,139,250,.3); }
.badge-mate { background: rgba(240,192,64,.2); color: #f0c040; border: 1px solid rgba(240,192,64,.3); }
.badge-skewer { background: rgba(63,185,80,.2); color: #3fb950; border: 1px solid rgba(63,185,80,.3); }

/* ---------- Tactics ---------- */
.tactic-status {
  display: flex; align-items: center; gap: 10px;
  margin: 12px 0;
  padding: 10px 16px;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 8px; min-width: 300px;
}
.status-icon { font-size: 22px; }
.status-text { font-size: 14px; font-weight: 600; }

.score-panel {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: 8px; margin-bottom: 4px;
}
.score-item {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 8px; text-align: center;
}
.score-val { font-size: 22px; font-weight: 800; color: var(--accent); }
.score-lbl { font-size: 11px; color: var(--text2); margin-top: 2px; }

.solution-reveal { border-top: 1px solid var(--border); padding-top: 12px; }
.solution-reveal h4 { font-size: 12px; font-weight: 700; color: var(--text2); text-transform: uppercase; margin-bottom: 8px; }
.solution-moves { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Endgames ---------- */
.endgames-layout { grid-template-columns: 220px 1fr 260px; }
.step-indicator {
  display: flex; gap: 6px; flex-wrap: wrap; margin: 4px 0;
}
.step-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--bg4); border: 1px solid var(--border);
  cursor: pointer; transition: all var(--transition);
}
.step-dot.active { background: var(--accent); border-color: var(--accent); }
.step-dot.done { background: var(--success); border-color: var(--success); }

.endgame-explanation {
  font-size: 14px; line-height: 1.65; color: var(--text);
  flex: 1;
}
.endgame-explanation h4 { font-size: 15px; font-weight: 700; margin-bottom: 8px; color: var(--text); }
.endgame-explanation p { margin-bottom: 10px; }

.key-principles h4 {
  font-size: 12px; font-weight: 700; color: var(--text2);
  text-transform: uppercase; letter-spacing: .05em; margin-bottom: 8px;
}
.principle-item {
  display: flex; gap: 8px; padding: 8px 0;
  border-bottom: 1px solid var(--border); font-size: 13px;
}
.principle-item:last-child { border-bottom: none; }
.principle-icon { font-size: 16px; flex-shrink: 0; }

/* ---------- Sandbox ---------- */
.sandbox-panel {
  display: flex; flex-direction: column;
  background: var(--bg2); padding: 20px;
  gap: 16px; overflow-y: auto;
}
.sandbox-header { display: flex; align-items: center; justify-content: space-between; }
.sandbox-header h3 { font-size: 18px; font-weight: 700; }
.sandbox-modes { display: flex; gap: 6px; }
.mode-btn {
  padding: 6px 14px; border-radius: 20px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); font-size: 13px; cursor: pointer;
  transition: all var(--transition);
}
.mode-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.mode-btn:hover:not(.active) { border-color: var(--accent); color: var(--text); }

.sandbox-move-log h4 { font-size: 12px; font-weight: 700; color: var(--text2); text-transform: uppercase; margin-bottom: 8px; }
.move-log {
  display: grid; grid-template-columns: auto 1fr 1fr;
  gap: 2px; max-height: 300px; overflow-y: auto;
  font-family: 'Courier New', monospace; font-size: 13px;
}
.move-log::-webkit-scrollbar { width: 4px; }
.move-log::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }
.log-num { color: var(--text2); padding: 3px 6px; }
.log-white { padding: 3px 6px; cursor: pointer; border-radius: 4px; }
.log-black { padding: 3px 6px; cursor: pointer; border-radius: 4px; }
.log-white:hover, .log-black:hover { background: var(--bg3); }
.log-white.current, .log-black.current { background: var(--accent); color: #fff; border-radius: 4px; }

.sandbox-status {
  padding: 12px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; font-weight: 600; text-align: center;
}

.captured-pieces { display: flex; flex-direction: column; gap: 6px; }
.captured-row { display: flex; flex-wrap: wrap; gap: 2px; min-height: 28px; font-size: 22px; }

/* ---------- Buttons ---------- */
.btn {
  padding: 10px 20px; border-radius: 8px;
  font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all var(--transition);
  border: none; outline: none;
}
.btn-primary {
  background: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent2); transform: translateY(-1px); }
.btn-success {
  background: var(--success); color: #fff; width: 100%;
}
.btn-success:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* ---------- Puzzle Info ---------- */
.puzzle-info h3 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.puzzle-badge-row { display: flex; gap: 6px; margin-bottom: 8px; }
.puzzle-info p { font-size: 14px; color: var(--text2); line-height: 1.5; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; backdrop-filter: blur(4px);
}
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 24px;
  min-width: 320px; max-width: 480px;
  box-shadow: var(--shadow);
  animation: pop-in .2s ease;
}
@keyframes pop-in {
  from { transform: scale(.9); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-header h3 { font-size: 20px; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text2); cursor: pointer; font-size: 18px; }
.modal-body { font-size: 14px; line-height: 1.6; color: var(--text2); margin-bottom: 16px; }
.modal-footer { display: flex; justify-content: flex-end; }

.promo-modal {
  min-width: 280px; text-align: center;
}
.promo-modal h3 { margin-bottom: 16px; }
.promo-choices { display: flex; gap: 12px; justify-content: center; }
.promo-piece-btn {
  width: 64px; height: 64px; font-size: 44px;
  background: var(--bg3); border: 2px solid var(--border);
  border-radius: 8px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
}
.promo-piece-btn:hover { border-color: var(--accent); background: var(--bg4); transform: scale(1.1); }

/* ---------- Toast ---------- */
.toast-container {
  position: fixed; bottom: 20px; right: 20px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 300;
}
.toast {
  padding: 12px 18px; border-radius: 8px;
  font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow);
  animation: slide-in .25s ease;
  max-width: 280px;
}
@keyframes slide-in {
  from { transform: translateX(100px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--accent); color: #fff; }
.toast.warning { background: var(--warning); color: #fff; }

/* ---------- AI Panel ---------- */
.ai-panel {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.ai-row {
  display: flex; align-items: center; gap: 10px;
}
.ai-label {
  font-size: 12px; font-weight: 700;
  color: var(--text2); text-transform: uppercase;
  letter-spacing: .05em; min-width: 70px;
}
.ai-btns { display: flex; gap: 4px; }
.ai-btn, .ai-side-btn {
  padding: 5px 12px; font-size: 12px; font-weight: 600;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text2);
  cursor: pointer; transition: all var(--transition);
}
.ai-btn:hover:not(.active), .ai-side-btn:hover:not(.active) {
  border-color: var(--accent); color: var(--text);
}
.ai-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.ai-side-btn.active { background: var(--bg4); border-color: var(--accent); color: var(--text); }

.ai-thinking {
  display: flex; align-items: center; gap: 8px;
  font-size: 13px; color: var(--accent); font-weight: 600;
  padding: 4px 0;
}
.thinking-dots { display: flex; gap: 4px; }
.thinking-dots span {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  animation: bounce-dot .9s ease-in-out infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: .15s; }
.thinking-dots span:nth-child(3) { animation-delay: .30s; }
@keyframes bounce-dot {
  0%, 80%, 100% { transform: translateY(0); opacity: .4; }
  40%           { transform: translateY(-6px); opacity: 1; }
}

/* Board thinking overlay */
.board-area.ai-thinking-overlay .chess-board {
  opacity: .65;
  pointer-events: none;
}

/* ---------- Scrollbar global ---------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 3px; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  :root { --sq-size: 60px; }
  .openings-layout, .tactics-layout, .endgames-layout {
    grid-template-columns: 200px 1fr 240px;
  }
}

@media (max-width: 900px) {
  :root { --sq-size: 52px; }
  .openings-layout, .tactics-layout, .endgames-layout {
    grid-template-columns: 1fr;
    grid-template-rows: auto 1fr auto;
  }
  .openings-sidebar, .tactics-sidebar, .endgames-sidebar {
    border-right: none; border-bottom: 1px solid var(--border);
    max-height: 160px;
  }
  .info-panel { border-left: none; border-top: 1px solid var(--border); }
  .sidebar { position: fixed; height: 100vh; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .menu-toggle { display: block; }
  .sandbox-layout { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
}

@media (max-width: 600px) {
  :root { --sq-size: 42px; }
  .piece { font-size: calc(var(--sq-size) * .75); }
  .board-area { padding: 10px; }
}
