/* ==========================================
   CHESS ANATOMY — Premium Stylesheet
   A chess.com-inspired, spacious, modern UI
   ========================================== */

/* ─── Design Tokens / Root Variables ─── */
:root {
  --font-main: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 0.4s ease;

  --sidebar-width: 380px;
  /* Board is capped at a share of viewport height, but on short screens it also
     leaves room for the header + both player bars + control row so nothing gets
     pushed off the viewport. The first declaration is a fallback for browsers
     without dvh; the second wins where dvh is supported (all modern browsers).
     The vertical reservation (16rem) is tuned to the slimmed chrome below. */
  --board-size-sub: 10.5rem;
  --board-max-size: min(88vh, calc(100dvh - var(--board-size-sub)));

  /* Eval bar */
  --eval-bar-width: 20px;

  /* Neon border — only used by cyber, defaults to nothing */
  --neon-border: 0 0 0 transparent;
}

/* ─────────────────────────────────────────
   THEME 1 — Slate (Default Dark)
   ───────────────────────────────────────── */
.theme-slate {
  --bg-app: #0f172a;
  --bg-panel: rgba(30, 41, 59, 0.72);
  --bg-panel-solid: #1e293b;
  --border-color: rgba(255, 255, 255, 0.07);

  --text-primary: #f1f5f9;
  --text-muted: #94a3b8;
  --accent: #38bdf8;
  --accent-glow: rgba(56, 189, 248, 0.22);

  --board-light: #e2e8f0;
  --board-dark: #475569;
  --board-border: #334155;
  --coord-text-light: #475569;
  --coord-text-dark: #e2e8f0;

  --square-select-light: rgba(187, 204, 68, 0.75);
  --square-select-dark: rgba(187, 204, 68, 0.75);
  --square-last-light: #f5f682;
  --square-last-dark: #bbcc44;
  --square-tactic: rgba(217, 70, 239, 0.5);

  --chat-coach-bg: rgba(30, 41, 59, 0.92);
  --chat-player-bg: rgba(56, 189, 248, 0.12);
  --card-bg: rgba(15, 23, 42, 0.55);

  --white-coach-tint: rgba(241, 245, 249, 0.05);
  --black-coach-tint: rgba(0, 0, 0, 0.18);
}

/* ─────────────────────────────────────────
   THEME 2 — Wood (Classic Chess Club)
   ───────────────────────────────────────── */
.theme-wood {
  --bg-app: #1c1917;
  --bg-panel: rgba(41, 37, 36, 0.75);
  --bg-panel-solid: #292524;
  --border-color: rgba(255, 255, 255, 0.06);

  --text-primary: #fafaf9;
  --text-muted: #a8a29e;
  --accent: #f59e0b;
  --accent-glow: rgba(245, 158, 11, 0.22);

  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --board-border: #78350f;
  --coord-text-light: #b58863;
  --coord-text-dark: #f0d9b5;

  --square-select-light: rgba(187, 204, 68, 0.78);
  --square-select-dark: rgba(187, 204, 68, 0.78);
  --square-last-light: #f5f682;
  --square-last-dark: #bbcc44;
  --square-tactic: rgba(139, 92, 246, 0.55);

  --chat-coach-bg: rgba(41, 37, 36, 0.92);
  --chat-player-bg: rgba(245, 158, 11, 0.1);
  --card-bg: rgba(28, 25, 23, 0.55);

  --white-coach-tint: rgba(250, 250, 249, 0.04);
  --black-coach-tint: rgba(0, 0, 0, 0.15);
}

/* ─────────────────────────────────────────
   THEME 3 — Cyber (Neon Grid)
   ───────────────────────────────────────── */
.theme-cyber {
  --bg-app: #090514;
  --bg-panel: rgba(20, 10, 35, 0.72);
  --bg-panel-solid: #140a23;
  --border-color: rgba(244, 63, 94, 0.12);

  --text-primary: #f8f7f9;
  --text-muted: #a78bfa;
  --accent: #ec4899;
  --accent-glow: rgba(236, 72, 153, 0.25);

  --board-light: #2e1065;
  --board-dark: #090514;
  --board-border: #ec4899;
  --coord-text-light: #6b21a8;
  --coord-text-dark: #c084fc;

  --square-select-light: rgba(236, 72, 153, 0.55);
  --square-select-dark: rgba(236, 72, 153, 0.55);
  --square-last-light: rgba(14, 165, 233, 0.4);
  --square-last-dark: rgba(14, 165, 233, 0.35);
  --square-tactic: rgba(232, 121, 249, 0.55);

  --chat-coach-bg: rgba(20, 10, 35, 0.95);
  --chat-player-bg: rgba(236, 72, 153, 0.1);
  --card-bg: rgba(9, 5, 20, 0.65);

  --neon-border: 0 0 12px rgba(236, 72, 153, 0.45);

  --white-coach-tint: rgba(248, 247, 249, 0.04);
  --black-coach-tint: rgba(0, 0, 0, 0.22);
}

/* ─────────────────────────────────────────
   THEME 4 — Green (Emerald/Forest)
   ───────────────────────────────────────── */
.theme-green {
  --bg-app: #022c22;
  --bg-panel: rgba(6, 78, 59, 0.72);
  --bg-panel-solid: #064e3b;
  --border-color: rgba(255, 255, 255, 0.08);

  --text-primary: #fafdfb;
  --text-muted: #a7f3d0;
  --accent: #10b981;
  --accent-glow: rgba(16, 185, 129, 0.22);

  --board-light: #eeeed2;
  --board-dark: #769656;
  --board-border: #4d6435;
  --coord-text-light: #769656;
  --coord-text-dark: #eeeed2;

  --square-select-light: rgba(187, 204, 68, 0.75);
  --square-select-dark: rgba(187, 204, 68, 0.75);
  --square-last-light: #f5f682;
  --square-last-dark: #bbcc44;
  --square-tactic: rgba(217, 70, 239, 0.5);

  --chat-coach-bg: rgba(6, 78, 59, 0.92);
  --chat-player-bg: rgba(16, 185, 129, 0.12);
  --card-bg: rgba(2, 44, 34, 0.55);

  --white-coach-tint: rgba(250, 253, 251, 0.05);
  --black-coach-tint: rgba(0, 0, 0, 0.18);
}

/* ─── Global Reset ─── */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  user-select: none;
}

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  touch-action: pan-x pan-y;
}

body {
  font-family: var(--font-main);
  background-color: var(--bg-app);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
  height: 100dvh; /* dynamic viewport height — avoids mobile URL-bar jump/overflow */
  width: 100vw;
  width: 100dvw;
  display: flex;
  flex-direction: column;
  transition: background-color var(--transition-slow), color var(--transition-slow);
  touch-action: pan-x pan-y;
}

/* ─── Custom Scrollbars ─── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.08);
  border-radius: 10px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.18); }

/* ─── App Container ─── */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100%;
  width: 100%;
}

/* ═══════════════════════════════════════════
   HEADER
   ═══════════════════════════════════════════ */
.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.4rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  background-color: rgba(0, 0, 0, 0.22);
  z-index: 10;
  min-height: 46px;
  transition: background-color var(--transition-slow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.logo-icon {
  font-size: 1.3rem;
  color: var(--accent);
  filter: drop-shadow(0 0 8px var(--accent-glow));
  transition: filter var(--transition-normal), color var(--transition-slow);
}

.logo-text {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.logo h1 {
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.logo-tagline {
  display: none;
}

.accent-text {
  color: var(--accent);
  text-shadow: 0 0 12px var(--accent-glow);
  transition: color var(--transition-slow), text-shadow var(--transition-slow);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

/* ─── Theme Picker ─── */
.theme-picker {
  display: flex;
  background-color: rgba(0, 0, 0, 0.28);
  padding: 3px;
  border-radius: 9999px;
  border: 1px solid var(--border-color);
  transition: border-color var(--transition-slow);
}

.theme-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.45rem;
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.theme-btn:hover {
  color: var(--text-primary);
  transform: scale(1.08);
}

.theme-btn.active {
  background-color: var(--bg-panel-solid);
  color: var(--accent);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.settings-toggle-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0.45rem;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast);
}

.settings-toggle-btn:hover {
  color: var(--text-primary);
  transform: scale(1.08);
  box-shadow: 0 0 10px var(--accent-glow);
}

.settings-toggle-btn .btn-text {
  display: none;
}

/* ═══════════════════════════════════════════
   MAIN LAYOUT
   ═══════════════════════════════════════════ */
.main-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  height: calc(100vh - 46px);
  height: calc(100dvh - 46px);
}

/* ═══════════════════════════════════════════
   LEFT — BOARD SECTION
   Spacious, centered, breathing room
   ═══════════════════════════════════════════ */
.board-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: clamp(0.2rem, 0.8vw, 0.4rem);
  background: radial-gradient(ellipse at 50% 40%, rgba(255, 255, 255, 0.018) 0%, transparent 75%);
  transition: background var(--transition-slow);
  gap: 0.25rem;
}

/* ─── Player Bars ─── */
.player-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: min(100%, calc(var(--board-max-size) + 40px));
  padding: 0.25rem 0.75rem;
  background-color: var(--bg-panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
  /* Only animate cosmetic props — NOT width/padding. Transitioning layout here
     made the bars animate (and, in throttled tabs, freeze) collapsed on every
     responsive reflow / orientation change. */
  transition: border-color var(--transition-normal),
              background-color var(--transition-normal),
              box-shadow var(--transition-normal);
  min-height: 38px;
}

.board-section.eval-visible .player-bar {
  width: min(100%, calc(var(--board-max-size) + var(--eval-bar-width) + 56px));
}

.player-bar:hover {
  border-color: rgba(255, 255, 255, 0.12);
}

.player-self-bar {
  /* bottom bar — no extra margin needed, gap handles it */
}

.player-profile {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.player-avatar {
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 6px;
  background-color: rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  color: var(--accent);
  border: 1px solid var(--border-color);
  transition: all var(--transition-normal);
}

.player-details {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.player-name {
  font-weight: 700;
  font-size: 0.85rem;
  letter-spacing: -0.01em;
}

.player-badge {
  font-size: 0.65rem;
  color: var(--text-muted);
  font-weight: 500;
}

.opening-badge {
  display: inline-block;       /* inline-block so text-overflow ellipsis works */
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  vertical-align: middle;
}

.captured-pieces {
  display: flex;
  align-items: center;
  gap: 1px;
  flex-grow: 1;
  padding-left: 0.8rem;
  opacity: 0.85;
  height: 1.35rem;
  overflow: hidden;
  flex-wrap: wrap;
}

.captured-img {
  width: 18px;
  height: 18px;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.3));
  transition: transform var(--transition-fast);
}

.captured-img:hover {
  transform: scale(1.25);
}

.player-timer {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 26px;
  border-radius: 4px;
  background-color: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  letter-spacing: 0.03em;
  min-width: 4.8rem;
  transition: all var(--transition-normal);
}

/* Thinking Spinner */
.thinking-spinner {
  margin-left: 0.6rem;
  display: flex;
  gap: 3px;
}

.thinking-spinner > div {
  width: 6px;
  height: 6px;
  background-color: var(--accent);
  border-radius: 50%;
  display: inline-block;
  animation: bounceDelay 1.4s infinite ease-in-out both;
}

.thinking-spinner .bounce1 { animation-delay: -0.32s; }
.thinking-spinner .bounce2 { animation-delay: -0.16s; }

@keyframes bounceDelay {
  0%, 80%, 100% { transform: scale(0); }
  40% { transform: scale(1.0); }
}

/* ═══════════════════════════════════════════
   BOARD WRAPPER (Eval bar + Board + Coords)
   ═══════════════════════════════════════════ */
.board-wrapper {
  display: flex;
  align-items: stretch;
  width: min(100%, var(--board-max-size));
  height: auto;
  max-height: var(--board-max-size);
  aspect-ratio: auto;
  position: relative;
  gap: 10px;
}

.board-section.eval-visible .board-wrapper {
  width: min(100%, calc(var(--board-max-size) + var(--eval-bar-width) + 16px));
}

/* ─── Evaluation Bar (wider, smoother) ─── */
.eval-bar-container {
  width: var(--eval-bar-width);
  min-width: var(--eval-bar-width);
  background-color: #e8e8e8;
  border-radius: 6px;
  overflow: hidden;
  position: relative;
  border: 1px solid rgba(0, 0, 0, 0.15);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2), inset 0 0 4px rgba(0, 0, 0, 0.05);
  display: flex;
  flex-direction: column-reverse;
  transition: all var(--transition-slow);
}

.eval-bar-fill {
  width: 100%;
  background: linear-gradient(to top, #1a1a1a 0%, #2d2d2d 100%);
  transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.eval-text {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  bottom: 6px;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.6rem;
  color: #fff;
  mix-blend-mode: difference;
  pointer-events: none;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
  white-space: nowrap;
}

/* ═══════════════════════════════════════════
   CHESS BOARD CONTAINER
   Outer shell with shadow, rounded corners,
   coordinate gutters OUTSIDE the board
   ═══════════════════════════════════════════ */
.chess-board-container {
  position: relative;
  flex: 1;
  aspect-ratio: 1 / 1;
  background-color: var(--board-border);
  padding: 0;
  border-radius: 6px;
  box-shadow:
    0 8px 30px rgba(0, 0, 0, 0.35),
    0 2px 8px rgba(0, 0, 0, 0.2),
    var(--neon-border);
  display: flex;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  transition: box-shadow var(--transition-slow), background-color var(--transition-slow);
}

.chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  position: relative;
  /* Prevent touch scrolling/zoom from hijacking piece drags on mobile */
  touch-action: none;
  /* NO border-radius on the board grid itself */
  transition: filter 4s ease-in-out;
}

/* ═══════════════════════════════════════════
   SQUARES
   ═══════════════════════════════════════════ */
.square {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  /* NO border-radius on individual squares */
}

.square.light {
  background-color: var(--board-light);
  transition: background-color var(--transition-normal);
}

.square.dark {
  background-color: var(--board-dark);
  transition: background-color var(--transition-normal);
}


/* Old on-square coordinates removed — using external coord containers */


/* ═══════════════════════════════════════════
   MOVE & STATE HIGHLIGHTS
   Chess.com-style indicators
   ═══════════════════════════════════════════ */
.square-highlight {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 1;
  transition: background-color var(--transition-fast);
}

.square-highlight.user-highlighted {
  background-color: rgba(245, 158, 11, 0.4) !important;
  z-index: 2;
}

/* Selected square — bright green-yellow like chess.com */
.square-highlight.selected {
  z-index: 1;
}

.light > .square-highlight.selected {
  background-color: var(--square-select-light);
}

.dark > .square-highlight.selected {
  background-color: var(--square-select-dark);
}

/* Last move — subtle yellow-green tint, chess.com style */
.square-highlight.last-move {
  z-index: 1;
}

.light > .square-highlight.last-move {
  background-color: var(--square-last-light);
}

.dark > .square-highlight.last-move {
  background-color: var(--square-last-dark);
}

/* Check — radial gradient red glow from center outward */
.square-highlight.check {
  background: radial-gradient(
    circle at center,
    rgba(255, 0, 0, 0.85) 0%,
    rgba(220, 38, 38, 0.55) 35%,
    rgba(220, 38, 38, 0.2) 65%,
    transparent 100%
  );
  animation: pulseCheck 1.2s ease-in-out infinite alternate;
  z-index: 1;
}

@keyframes pulseCheck {
  0% {
    background: radial-gradient(
      circle at center,
      rgba(255, 0, 0, 0.8) 0%,
      rgba(220, 38, 38, 0.5) 35%,
      rgba(220, 38, 38, 0.15) 65%,
      transparent 100%
    );
  }
  100% {
    background: radial-gradient(
      circle at center,
      rgba(255, 0, 0, 0.95) 0%,
      rgba(220, 38, 38, 0.65) 40%,
      rgba(220, 38, 38, 0.25) 70%,
      transparent 100%
    );
  }
}

/* Tactic highlight — purple inset ring */
.square-highlight.tactic {
  box-shadow: inset 0 0 0 3px var(--square-tactic);
  background-color: rgba(217, 70, 239, 0.08);
  animation: pulseTactic 1.5s infinite alternate;
}

@keyframes pulseTactic {
  0% { box-shadow: inset 0 0 0 2px var(--square-tactic); }
  100% { box-shadow: inset 0 0 0 4px var(--square-tactic); }
}

/* ─── Legal Move Indicators (chess.com style) ─── */

/* Empty square: small, dark, semi-transparent circle */
.legal-dot {
  width: 30%;
  height: 30%;
  border-radius: 50%;
  background-color: rgba(0, 0, 0, 0.12);
  pointer-events: none;
  z-index: 2;
  transition: transform var(--transition-fast);
}

/* Capture indicator: large hollow ring on the square */
.legal-capture {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
  border-radius: 50%;
  background: radial-gradient(
    transparent 55%,
    rgba(0, 0, 0, 0.12) 55%,
    rgba(0, 0, 0, 0.12) 100%
  );
}

.square:hover .legal-dot {
  transform: scale(1.15);
}

/* ═══════════════════════════════════════════
   PIECES
   Use <img> tags loading SVGs (or inline SVGs).
   Positioned absolutely over the board.
   ═══════════════════════════════════════════ */
.piece {
  position: absolute;
  width: 12.5%;
  height: 12.5%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: grab;
  z-index: 3;
  touch-action: none;
  transition: top 0.35s cubic-bezier(0.25, 0.8, 0.25, 1), left 0.35s cubic-bezier(0.25, 0.8, 0.25, 1);
  will-change: auto;
}

.piece:active {
  cursor: grabbing;
}

.piece.dragging {
  z-index: 100;
  transition: none;
  cursor: grabbing;
  filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.45));
  will-change: transform;
}

/* Support for <img> based pieces (Lichess CDN SVGs) */
.piece img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: drop-shadow(1px 2px 3px rgba(0, 0, 0, 0.25));
}

/* Support for inline SVG pieces */
.piece svg {
  width: 88%;
  height: 88%;
  filter: drop-shadow(1px 2px 3px rgba(0, 0, 0, 0.25));
  pointer-events: none;
}

/* Gifted piece spawn animation */
@keyframes spawnBounce {
  0% {
    transform: scale(0) rotate(-180deg);
    filter: drop-shadow(0 0 25px var(--accent)) brightness(2);
  }
  60% {
    transform: scale(1.4) rotate(15deg);
    filter: drop-shadow(0 0 15px var(--accent)) brightness(1.5);
  }
  100% {
    transform: scale(1) rotate(0deg);
    filter: drop-shadow(1px 2px 3px rgba(0, 0, 0, 0.25));
  }
}
.piece.spawn-gif-anim {
  z-index: 10;
}
.piece.spawn-gif-anim img,
.piece.spawn-gif-anim svg {
  animation: spawnBounce 0.9s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* ═══════════════════════════════════════════
   RIGHT — SIDE PANEL
   ═══════════════════════════════════════════ */
.side-panel {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  border-left: 1px solid var(--border-color);
  background-color: var(--bg-panel);
  backdrop-filter: blur(20px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: -4px 0 20px rgba(0, 0, 0, 0.12);
  transition: width var(--transition-normal), min-width var(--transition-normal), background-color var(--transition-slow);
}

/* ─── Collapsible side panel (desktop) — disabled ─── */
.sidebar-collapse-btn {
  display: none !important;
}

/* Mobile drawer affordances — hidden on desktop, activated in the mobile
   media query below. */
.drawer-handle { display: none; }
.drawer-backdrop { display: none; }

/* ─── Panel Tabs ─── */
.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-color);
  background-color: rgba(0, 0, 0, 0.1);
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 1rem 1rem;
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
  position: relative;
}

.tab-btn:hover {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.025);
}

.tab-btn.active {
  color: var(--accent);
}

.tab-btn.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2.5px;
  background-color: var(--accent);
  box-shadow: 0 -2px 10px var(--accent-glow);
  border-radius: 2px 2px 0 0;
}

.tab-contents {
  flex: 1;
  overflow: hidden;
  position: relative;
}

.tab-content {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  overflow-y: auto;
  padding: 1.5rem;
  display: none;
  flex-direction: column;
  gap: 1.5rem;
}

.tab-content.active {
  display: flex;
}

/* ═══════════════════════════════════════════
   TACTIC WARNING BOX
   ═══════════════════════════════════════════ */
.tactic-box {
  background: linear-gradient(135deg, rgba(217, 70, 239, 0.12), rgba(139, 92, 246, 0.08));
  border: 1px solid rgba(217, 70, 239, 0.25);
  border-radius: 12px;
  padding: 1.15rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 4px 18px rgba(217, 70, 239, 0.12);
  animation: slideInDown var(--transition-normal) ease-out;
}

@keyframes slideInDown {
  from { transform: translateY(-16px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

.tactic-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: #f472b6;
}

.pulse-icon {
  animation: pulseGlow 1.5s infinite alternate;
}

@keyframes pulseGlow {
  0% { transform: scale(1); filter: drop-shadow(0 0 1px #f472b6); }
  100% { transform: scale(1.15); filter: drop-shadow(0 0 6px #f472b6); }
}

.tactic-header h3 {
  font-size: 0.95rem;
  font-weight: 700;
}

.tactic-box p {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-primary);
}

.tactic-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tactic-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 0.25rem 0.55rem;
  border-radius: 5px;
  background-color: rgba(0, 0, 0, 0.25);
  border: 1px solid rgba(255, 255, 255, 0.05);
  display: flex;
  align-items: center;
  gap: 0.25rem;
  color: var(--text-muted);
}

.tactic-badge.active-badge {
  color: #f472b6;
  border-color: rgba(217, 70, 239, 0.2);
}

.tactic-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.tactic-actions .btn {
  flex: 1 1 calc(50% - 0.25rem);
  box-sizing: border-box;
}

/* ═══════════════════════════════════════════
   AI MODE BADGES — Guidance & Coach Pills
   ═══════════════════════════════════════════ */
.ai-mode-toggle {
  display: flex;
  background-color: rgba(0, 0, 0, 0.25);
  border-radius: 9999px;
  padding: 3px;
  border: 1px solid var(--border-color);
  gap: 2px;
}

.ai-mode-btn {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.5rem 1rem;
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 0.78rem;
  cursor: pointer;
  border-radius: 9999px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all var(--transition-fast);
}

.ai-mode-btn:hover {
  color: var(--text-primary);
}

.ai-mode-btn.active-guidance {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(59, 130, 246, 0.08));
  color: #60a5fa;
  box-shadow: 0 0 8px rgba(59, 130, 246, 0.15);
}

.ai-mode-btn.active-coach {
  background: linear-gradient(135deg, rgba(168, 85, 247, 0.2), rgba(168, 85, 247, 0.08));
  color: #c084fc;
  box-shadow: 0 0 8px rgba(168, 85, 247, 0.15);
}

.mode-indicator {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.mode-indicator.guidance { background-color: #3b82f6; }
.mode-indicator.coach { background-color: #a855f7; }

/* ═══════════════════════════════════════════
   COACH CHAT CONSOLE
   ═══════════════════════════════════════════ */
.coach-chat-container {
  display: flex;
  flex-direction: column;
  flex: 1 0 280px;
  min-height: 280px;
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  max-height: 420px;
  transition: all var(--transition-normal);
}

.coach-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.75rem 1.1rem;
  background-color: rgba(0, 0, 0, 0.22);
  border-bottom: 1px solid var(--border-color);
}

.coach-meta {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.coach-avatar {
  width: 2.1rem;
  height: 2.1rem;
  background-color: var(--accent-glow);
  color: var(--accent);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.95rem;
  border: 1px solid rgba(56, 189, 248, 0.3);
  transition: all var(--transition-normal);
}

.coach-meta h4 {
  font-size: 0.88rem;
  font-weight: 600;
}

.coach-status {
  font-size: 0.68rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.status-dot {
  width: 6px;
  height: 6px;
  background-color: #10b981;
  border-radius: 50%;
  display: inline-block;
  box-shadow: 0 0 4px rgba(16, 185, 129, 0.4);
}

.coach-messages {
  flex: 1;
  padding: 1rem 1.15rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

/* ─── Chat Bubble Messages ─── */
.message {
  display: flex;
  max-width: 88%;
  animation: fadeInMsg 0.25s ease-out;
}

@keyframes fadeInMsg {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.message.coach-msg {
  align-self: flex-start;
}

.message.player-msg {
  align-self: flex-end;
}

.msg-bubble {
  padding: 0.7rem 0.95rem;
  border-radius: 14px;
  font-size: 0.84rem;
  line-height: 1.5;
  word-break: break-word;
}

.coach-msg .msg-bubble {
  background-color: var(--chat-coach-bg);
  border-top-left-radius: 3px;
  border: 1px solid var(--border-color);
}

.player-msg .msg-bubble {
  background-color: var(--chat-player-bg);
  border-top-right-radius: 3px;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

/* ─── Coach Areas: White & Black ─── */
.white-coach-area {
  background-color: var(--white-coach-tint);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 200px;
}

.white-coach-area .coach-area-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.white-coach-area .coach-area-label i {
  color: #e2e8f0;
}

.white-coach-area .coach-area-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.black-coach-area {
  background-color: var(--black-coach-tint);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 200px;
}

.black-coach-area .coach-area-label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.black-coach-area .coach-area-label i {
  color: #1a1a1a;
}

.black-coach-area .coach-area-scroll {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

/* Coach bubble inside areas */
.coach-area-bubble {
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
  font-size: 0.82rem;
  line-height: 1.45;
  background-color: var(--chat-coach-bg);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 0.25rem 0;
}

.typing-indicator span {
  width: 6px;
  height: 6px;
  background-color: var(--text-muted);
  border-radius: 50%;
  animation: typingBounce 1s infinite alternate;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0% { transform: translateY(0); }
  100% { transform: translateY(-4px); }
}

/* ═══════════════════════════════════════════
   ENGINE STATISTICS
   ═══════════════════════════════════════════ */
.engine-stats-container {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  transition: all var(--transition-normal);
}

.stats-header {
  font-size: 0.78rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
}

.stat-card {
  background-color: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.6rem 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.2rem;
  transition: all var(--transition-fast);
}

.stat-card:hover {
  background-color: rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 255, 255, 0.1);
}

.stat-label {
  font-size: 0.62rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--accent);
  transition: color var(--transition-slow);
}

.pv-container {
  font-size: 0.75rem;
  padding: 0.55rem 0.7rem;
  background-color: rgba(0, 0, 0, 0.2);
  border-radius: 6px;
  border-left: 3px solid var(--accent);
  transition: border-color var(--transition-slow);
}

.pv-label {
  color: var(--text-muted);
  font-weight: 600;
}

.pv-value {
  font-family: var(--font-mono);
  word-break: break-all;
  color: var(--text-primary);
}

/* ═══════════════════════════════════════════
   PGN / MOVE HISTORY
   Clean 2-column layout, alternating rows
   ═══════════════════════════════════════════ */
.pgn-container {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  height: 200px;
}

.pgn-header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  row-gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.pgn-tools {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 0.25rem;
}

.btn-tool {
  font-size: 0.85rem;
  padding: 0.3rem 0.4rem;
  width: 1.9rem;
  height: 1.9rem;
}

/* ─── Transient Toast ─── */
.app-toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%) translateY(16px);
  background-color: var(--bg-panel-solid);
  color: var(--text-primary);
  border: 1px solid var(--accent);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4), 0 0 0 1px var(--accent-glow);
  padding: 0.7rem 1.2rem;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  z-index: 2000;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal), transform var(--transition-normal);
}

.app-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.pgn-moves {
  flex: 1;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  display: grid;
  grid-template-columns: 32px 1fr 1fr;
  grid-auto-rows: min-content;
  align-items: center;
  padding-right: 0.25rem;
  gap: 0;
}

/* Alternating row backgrounds for the 3-column grid */
.pgn-row {
  display: contents;
}

/* Every odd move-row gets a subtle tint */
.pgn-row:nth-child(odd) .pgn-num,
.pgn-row:nth-child(odd) .pgn-move {
  background-color: rgba(255, 255, 255, 0.025);
}

.pgn-num {
  color: var(--text-muted);
  text-align: right;
  padding: 4px 6px 4px 0;
  font-size: 0.72rem;
  font-weight: 600;
  border-radius: 4px 0 0 4px;
}

.pgn-move {
  padding: 4px 8px;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition-fast);
  font-weight: 500;
}

.pgn-move:hover {
  background-color: rgba(255, 255, 255, 0.06);
  color: var(--text-primary);
}

.pgn-move.active {
  background-color: var(--accent-glow);
  color: var(--accent);
  font-weight: 700;
}

/* ═══════════════════════════════════════════
   GAME SETTINGS (Tab 2)
   ═══════════════════════════════════════════ */
.settings-group {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 1.35rem;
}

.settings-group:last-child {
  border-bottom: none;
}

.settings-group h3 {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Select Dropdowns */
select {
  color-scheme: dark;
}

.select-container {
  position: relative;
  width: 100%;
}

.select-container select {
  color-scheme: dark;
  width: 100%;
  padding: 0.75rem 2.5rem 0.75rem 1rem;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.85), rgba(30, 41, 59, 0.7));
  border: 1px solid rgba(148, 163, 184, 0.18);
  border-radius: 10px;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
  transition: all 0.25s ease;
  backdrop-filter: blur(8px);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.select-container select:hover {
  border-color: var(--accent);
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.95), rgba(30, 41, 59, 0.85));
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3), 0 0 0 1px rgba(56, 189, 248, 0.1);
}

.select-container select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow), 0 4px 20px rgba(0, 0, 0, 0.3);
}

.select-container select option {
  background: #1e293b;
  color: #e2e8f0;
  padding: 10px 14px;
  font-size: 0.88rem;
  font-weight: 500;
}

.select-container select option:checked {
  background-color: #0f172a !important;
  color: var(--accent) !important;
}

.select-container::after {
  content: '';
  position: absolute;
  right: 1rem;
  top: 50%;
  transform: translateY(-50%);
  pointer-events: none;
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--accent);
  opacity: 0.8;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.select-container:hover::after {
  opacity: 1;
}

.color-options {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.color-options-board {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.color-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
}

.btn-group {
  display: flex;
  background-color: rgba(0, 0, 0, 0.22);
  padding: 3px;
  border-radius: 8px;
  border: 1px solid var(--border-color);
}

.btn-group .btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.4rem 0.95rem;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: 6px;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.btn-group .btn:hover {
  color: var(--text-primary);
}

.btn-group .btn.active {
  background-color: var(--bg-panel-solid);
  color: var(--accent);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.board-colors-grid {
  display: flex;
  gap: 0.75rem;
}

.board-color-btn {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 50%;
  border: 2.5px solid transparent;
  cursor: pointer;
  transition: transform var(--transition-fast), border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.board-color-btn:hover {
  transform: scale(1.08);
}

.board-color-btn.active {
  border-color: var(--accent);
  transform: scale(1.12);
  box-shadow: 0 0 8px var(--accent-glow);
}

/* ─── Time Control Picker ─── */
.time-control-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.5rem;
}

.tc-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  padding: 0.55rem 0.4rem;
  background-color: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all var(--transition-fast);
}

.tc-btn span {
  font-family: var(--font-main);
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.tc-btn:hover {
  background-color: rgba(255, 255, 255, 0.06);
  border-color: rgba(255, 255, 255, 0.14);
  transform: translateY(-1px);
}

.tc-btn.active {
  background: linear-gradient(135deg, var(--accent-glow), rgba(255, 255, 255, 0.02));
  border-color: var(--accent);
  color: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

.tc-btn.active span {
  color: var(--accent);
  opacity: 0.85;
}

.tc-custom-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 0.6rem;
}

.tc-custom-field {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.tc-custom-field label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
}

.tc-custom-field input {
  width: 100%;
  padding: 0.5rem 0.7rem;
  background-color: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.9rem;
  transition: all var(--transition-fast);
}

.tc-custom-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

/* Low-time emphasis on the active clock */
.player-timer.low-time {
  background-color: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
  animation: lowTimePulse 1s infinite alternate;
}

@keyframes lowTimePulse {
  0% { box-shadow: 0 0 0 rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 10px rgba(239, 68, 68, 0.5); }
}

/* ─── Sliders ─── */
.slider-container {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.slider-label span:last-child {
  color: var(--accent);
  font-family: var(--font-mono);
  font-weight: 700;
}

input[type="range"] {
  width: 100%;
  height: 5px;
  background-color: rgba(255, 255, 255, 0.08);
  border-radius: 3px;
  appearance: none;
  outline: none;
  cursor: pointer;
  transition: background-color var(--transition-fast);
}

input[type="range"]:hover {
  background-color: rgba(255, 255, 255, 0.12);
}

input[type="range"]::-webkit-slider-thumb {
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  transition: transform var(--transition-fast);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background-color: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  border: none;
}

/* ─── Toggle Switches ─── */
.toggle-control {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.85rem;
  font-weight: 600;
}

.switch {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 20px;
  flex-shrink: 0;
}

.switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(255, 255, 255, 0.1);
  transition: 0.3s;
}

.slider::before {
  position: absolute;
  content: "";
  height: 14px;
  width: 14px;
  left: 3px;
  bottom: 3px;
  background-color: var(--text-muted);
  transition: 0.3s;
}

input:checked + .slider {
  background-color: var(--accent-glow);
}

input:checked + .slider::before {
  transform: translateX(20px);
  background-color: var(--accent);
}

.slider.round { border-radius: 20px; }
.slider.round::before { border-radius: 50%; }

/* ═══════════════════════════════════════════
   BUTTONS — Premium hover states
   ═══════════════════════════════════════════ */
.btn {
  font-family: var(--font-main);
  font-weight: 600;
  border-radius: 8px;
  border: 1px solid transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  transition: all var(--transition-fast);
}

.btn-primary {
  background-color: var(--accent);
  color: #0f172a;
  padding: 0.75rem 1.5rem;
  font-size: 0.92rem;
}

.btn-primary:hover {
  opacity: 0.92;
  box-shadow: 0 4px 16px var(--accent-glow);
  transform: translateY(-1px) scale(1.015);
}

.btn-primary:active {
  transform: translateY(0) scale(0.98);
}

.btn-secondary {
  background-color: rgba(255, 255, 255, 0.05);
  border-color: var(--border-color);
  color: var(--text-primary);
  padding: 0.75rem 1.5rem;
  font-size: 0.92rem;
}

.btn-secondary:hover {
  background-color: rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.12);
  transform: translateY(-1px) scale(1.01);
}

.btn-secondary:active {
  transform: translateY(0) scale(0.98);
}

/* Stuck Helper button styled like a glowing amber beacon */
.board-controls-container {
  width: min(100%, calc(var(--board-max-size) + 40px));
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-top: 0.1rem;
  margin-bottom: 0.1rem;
}

.board-section.eval-visible .board-controls-container {
  width: min(100%, calc(var(--board-max-size) + var(--eval-bar-width) + 56px));
}

@media (max-width: 600px) {
  .board-controls-container {
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
  }
}

.board-controls-container .btn {
  padding: 0.4rem 0.3rem;
  font-size: 0.75rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

#btnNewGameCtrl {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  border: 1px solid rgba(16, 185, 129, 0.4);
  box-shadow: 0 4px 12px rgba(16, 185, 129, 0.15);
}
#btnNewGameCtrl:hover {
  background: linear-gradient(135deg, #34d399, #10b981);
  box-shadow: 0 6px 20px rgba(16, 185, 129, 0.3);
  transform: translateY(-1px) scale(1.02);
}
#btnNewGameCtrl:active {
  transform: translateY(0) scale(0.98);
}

#btnImStuck {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #0f172a;
  border: 1px solid rgba(245, 158, 11, 0.4);
  box-shadow: 0 4px 12px rgba(245, 158, 11, 0.15);
}
#btnImStuck:hover {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  box-shadow: 0 6px 20px rgba(245, 158, 11, 0.3);
  transform: translateY(-1px) scale(1.02);
}
#btnImStuck:active {
  transform: translateY(0) scale(0.98);
}

#btnResignCtrl {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #ffffff;
  border: 1px solid rgba(239, 68, 68, 0.4);
  box-shadow: 0 4px 12px rgba(239, 68, 68, 0.15);
}
#btnResignCtrl:hover:not(:disabled) {
  background: linear-gradient(135deg, #f87171, #ef4444);
  box-shadow: 0 6px 20px rgba(239, 68, 68, 0.3);
  transform: translateY(-1px) scale(1.02);
}
#btnResignCtrl:active:not(:disabled) {
  transform: translateY(0) scale(0.98);
}
#btnResignCtrl:disabled {
  background: rgba(255, 255, 255, 0.05) !important;
  border-color: var(--border-color) !important;
  color: var(--text-muted) !important;
  cursor: not-allowed;
  box-shadow: none !important;
  transform: none !important;
  opacity: 0.5;
}

#btnGuessEloCtrl {
  background: var(--accent);
  color: #0f172a;
  border: 1px solid var(--accent-glow);
  box-shadow: 0 4px 12px var(--accent-glow);
}
#btnGuessEloCtrl:hover {
  opacity: 0.92;
  box-shadow: 0 6px 20px var(--accent-glow);
  transform: translateY(-1px) scale(1.02);
}
#btnGuessEloCtrl:active {
  transform: translateY(0) scale(0.98);
}


.btn-sm {
  padding: 0.4rem 0.85rem;
  font-size: 0.78rem;
  border-radius: 6px;
}

.btn-icon {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.15rem;
  cursor: pointer;
  padding: 0.45rem;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  transition: all var(--transition-fast);
}

.btn-icon:hover {
  color: var(--text-primary);
  background-color: rgba(255, 255, 255, 0.06);
  transform: scale(1.08);
}

.btn-text {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 0.73rem;
  font-family: var(--font-main);
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  transition: all var(--transition-fast);
}

.btn-text:hover {
  opacity: 0.8;
  transform: translateX(-1px);
}

.game-control-btns {
  margin-top: 0.65rem;
}

.game-control-btns .btn {
  width: 100%;
}

/* ═══════════════════════════════════════════
   SETTINGS MODAL — Frosted Glass
   ═══════════════════════════════════════════ */
.settings-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  width: 100dvw;
  height: 100vh;
  height: 100dvh;
  background-color: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition-normal);
}

.settings-overlay.active {
  opacity: 1;
  pointer-events: all;
}

.settings-modal {
  background: rgba(30, 41, 59, 0.65);
  backdrop-filter: blur(28px) saturate(1.5);
  -webkit-backdrop-filter: blur(28px) saturate(1.5);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px;
  width: min(92vw, 480px);
  /* Never taller than the (padded) viewport; the body scrolls if content
     is long. Keeps long modals usable on short/landscape screens. */
  max-height: 100%;
  box-shadow:
    0 24px 60px rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  display: flex;
  flex-direction: column;
  transform: translateY(24px) scale(0.97);
  transition: transform var(--transition-normal);
  overflow: hidden;
}

.settings-overlay.active .settings-modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  background-color: rgba(0, 0, 0, 0.12);
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-body {
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1.35rem;
  /* Scroll long settings content instead of overflowing the viewport. */
  overflow-y: auto;
  min-height: 0;
}

.modal-body label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.45rem;
  display: block;
}

.modal-body input[type="text"],
.modal-body input[type="password"] {
  width: 100%;
  padding: 0.7rem 1rem;
  background-color: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  transition: all var(--transition-fast);
}

.modal-body input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-glow);
}

.input-with-icon {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-icon .btn-icon {
  position: absolute;
  right: 0.5rem;
}

.settings-note {
  font-size: 0.72rem;
  color: var(--text-muted);
  line-height: 1.45;
  margin-top: 0.35rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  background-color: rgba(0, 0, 0, 0.08);
}

/* ─── Pawn Promotion Picker ─── */
.promotion-choices {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.6rem;
}

.promotion-choice {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  padding: 0.65rem 0.3rem;
  background-color: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  cursor: pointer;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}

.promotion-choice:hover {
  background-color: var(--accent-glow);
  border-color: var(--accent);
  color: var(--text-primary);
  transform: translateY(-2px) scale(1.04);
}

.promotion-choice img {
  width: 100%;
  max-width: 56px;
  aspect-ratio: 1 / 1;
  pointer-events: none;
  filter: drop-shadow(1px 2px 3px rgba(0, 0, 0, 0.3));
}

.promotion-choice span {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ═══════════════════════════════════════════
   UTILITY ANIMATIONS
   ═══════════════════════════════════════════ */

/* Subtle fade-in for dynamic content */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Slide up for modals / panels */
@keyframes slideUp {
  from { transform: translateY(12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ═══════════════════════════════════════════
   MOBILE RESPONSIVE
   ═══════════════════════════════════════════ */
@media (max-width: 1180px) {
  :root {
    --sidebar-width: 340px;
  }

  .board-section {
    padding: clamp(0.25rem, 1vw, 1rem);
  }
}

/* ═══════════════════════════════════════════
   BOARD OUTER — Coordinate Gutters
   Wraps the chessboard with rank labels left,
   file labels bottom
   ═══════════════════════════════════════════ */
.board-outer {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: 1fr auto;
  flex: 1;
  gap: 0;
  min-height: 0;
}

/* Gutters hidden to reclaim space */
.coord-ranks, .coord-files {
  display: none !important;
}

/* Make board-outer a simple flex column so chess-board-container expands fully */
.board-outer {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  aspect-ratio: 1 / 1;
  min-width: 0;
  min-height: 0;
}

.board-outer .chess-board-container {
  flex: 0 0 auto;
  min-height: 0;
  width: 100%;
  height: auto;
  aspect-ratio: 1 / 1;
}

/* Inside-square coordinate labels using ::before and ::after pseudo-elements */
.square {
  position: relative;
}

/* Left column squares show rank coordinates (top left of square) */
.square:nth-child(8n+1)::before {
  content: attr(data-rank);
  position: absolute;
  top: 4px;
  left: 6px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.7rem;
  line-height: 1;
  pointer-events: none;
}

/* Bottom row squares show file coordinates (bottom right of square) */
.square:nth-child(n+57)::after {
  content: attr(data-file);
  position: absolute;
  bottom: 4px;
  right: 6px;
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.7rem;
  line-height: 1;
  pointer-events: none;
}

/* Apply light/dark themed text colors to coordinate labels based on square color */
.square.light::before, .square.light::after {
  color: var(--coord-text-light);
}

.square.dark::before, .square.dark::after {
  color: var(--coord-text-dark);
}

/* ═══════════════════════════════════════════
   AI MODE SELECTOR — Pill-style Toggle
   ═══════════════════════════════════════════ */
.ai-mode-selector {
  background-color: var(--card-bg);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}

.ai-mode-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.ai-mode-header i {
  color: var(--accent);
  font-size: 0.85rem;
}

.ai-mode-pills {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.ai-mode-toggle-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.85rem;
  border-radius: 8px;
  border: 1px solid var(--border-color);
  background-color: rgba(0, 0, 0, 0.15);
  transition: all var(--transition-fast);
  font-family: var(--font-main);
  color: var(--text-muted);
}

.ai-mode-toggle-item:hover {
  background-color: rgba(0, 0, 0, 0.25);
  border-color: rgba(255, 255, 255, 0.1);
  color: var(--text-primary);
}

.ai-mode-toggle-item.active {
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.12), rgba(56, 189, 248, 0.04));
  border-color: rgba(56, 189, 248, 0.3);
  color: var(--text-primary);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.08);
}

.ai-mode-toggle-item .toggle-control-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.pill-icon {
  width: 2rem;
  height: 2rem;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  background-color: rgba(0, 0, 0, 0.2);
  color: var(--text-muted);
  flex-shrink: 0;
  transition: all var(--transition-fast);
}

.ai-mode-toggle-item.active .pill-icon {
  background-color: rgba(56, 189, 248, 0.15);
  color: var(--accent);
}

.pill-text {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.pill-title {
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.2;
}

.pill-desc {
  font-size: 0.68rem;
  opacity: 0.7;
  line-height: 1.2;
}

/* ═══════════════════════════════════════════
   DUAL COACH CHAT AREAS — White & Black
   ═══════════════════════════════════════════ */
.coach-chat-white .coach-avatar-white {
  background-color: rgba(255, 255, 255, 0.12);
  color: #f8fafc;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.coach-chat-black .coach-avatar-black {
  background-color: rgba(0, 0, 0, 0.35);
  color: #94a3b8;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.coach-chat-white {
  border-color: rgba(255, 255, 255, 0.08);
}

.coach-chat-black {
  border-color: rgba(100, 116, 139, 0.15);
}

/* ═══════════════════════════════════════════
   PIECE IMAGE STYLING
   ═══════════════════════════════════════════ */
.piece-img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  filter: drop-shadow(1px 2px 3px rgba(0, 0, 0, 0.25));
  object-fit: contain;
}

@media (max-width: 1180px) {
  :root {
    --board-size-sub: 22.5rem;
  }

  /* Board fills the screen; the side panel becomes a slide-up bottom sheet so
     the coach/settings are one tap away without ever pushing the board down. */
  .main-layout {
    flex-direction: column;
    height: calc(100dvh - 46px);
    overflow: hidden;
  }

  body {
    overflow: hidden;
    height: 100dvh;
  }

  .app-header {
    padding: 0.35rem 1rem;
    min-height: 44px;
  }

  /* The desktop collapse toggle doesn't apply on mobile (drawer handles it). */
  .sidebar-collapse-btn {
    display: none;
  }

  .board-section {
    flex: 1;
    height: auto;
    justify-content: center;
    /* Bottom padding clears the peeking drawer handle/tabs. */
    padding: 0.5rem 0.5rem 5.25rem;
    overflow: hidden;
  }

  .board-wrapper {
    width: min(94vw, var(--board-max-size));
    max-width: 680px;
    height: auto;
    aspect-ratio: auto;
  }

  .chess-board-container {
    aspect-ratio: 1 / 1;
  }

  .player-bar {
    width: min(94vw, var(--board-max-size));
    max-width: 680px;
    padding: 0.4rem 0.9rem;
    min-height: 44px;
  }

  .board-section.eval-visible .player-bar {
    width: min(94vw, calc(var(--board-max-size) + var(--eval-bar-width) + 16px));
    max-width: calc(680px + var(--eval-bar-width) + 16px);
  }

  .board-controls-container {
    width: min(94vw, var(--board-max-size));
    max-width: 680px;
  }

  .board-section.eval-visible .board-controls-container {
    width: min(94vw, calc(var(--board-max-size) + var(--eval-bar-width) + 16px));
    max-width: calc(680px + var(--eval-bar-width) + 16px);
  }

  .player-timer {
    font-size: 1.05rem;
    height: 28px;
    min-width: 4.5rem;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* ── Bottom-sheet drawer ── */
  .side-panel {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    min-width: 0;
    height: 88dvh;
    max-height: 88dvh;
    border-left: none;
    border-top: 1px solid var(--border-color);
    border-radius: 18px 18px 0 0;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.45);
    /* Peek state: only the grab handle + tab bar (~84px) stay on screen. */
    transform: translateY(calc(100% - 84px));
    transition: transform var(--transition-normal);
    z-index: 60;
    will-change: transform;
  }

  .app-container.drawer-open .side-panel {
    transform: translateY(0);
  }

  .drawer-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 28px;
    background: none;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
  }

  .drawer-grabber {
    width: 42px;
    height: 5px;
    border-radius: 3px;
    background-color: var(--text-muted);
    opacity: 0.5;
  }

  .app-container.drawer-open .drawer-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 55;
    animation: drawerFadeIn var(--transition-normal);
  }

  @keyframes drawerFadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
  }
}

@media (min-width: 760px) and (max-width: 1180px) {
  :root {
    --board-size-sub: 13.75rem;
  }

  .board-section {
    gap: 0.2rem;
    padding: 0.45rem 0.75rem 4.85rem;
  }

  .board-wrapper {
    width: min(94vw, var(--board-max-size));
  }

  .player-bar {
    width: min(94vw, var(--board-max-size));
    max-width: 760px;
    min-height: 38px;
    padding: 0.25rem 0.75rem;
  }

  .board-section.eval-visible .player-bar {
    width: min(94vw, calc(var(--board-max-size) + var(--eval-bar-width) + 16px));
    max-width: calc(760px + var(--eval-bar-width) + 16px);
  }

  .board-controls-container {
    width: min(94vw, var(--board-max-size));
    max-width: 760px;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 0;
  }

  .board-section.eval-visible .board-controls-container {
    width: min(94vw, calc(var(--board-max-size) + var(--eval-bar-width) + 16px));
    max-width: calc(760px + var(--eval-bar-width) + 16px);
  }

  .board-controls-container .color-options {
    grid-column: 1 / -1 !important;
    margin: 0 !important;
    padding: 0 8px !important;
    border-bottom: none !important;
    min-height: 36px;
    gap: 8px;
  }

  .board-controls-container .color-options .color-label {
    display: inline;
    font-size: 0.75rem;
  }

  .board-controls-container .color-options .btn-group {
    width: auto;
  }

  .board-controls-container .color-options .btn-group .btn {
    min-height: 30px;
    padding: 0 8px !important;
  }

  .board-controls-container > .btn {
    min-height: 36px;
    padding: 0.35rem 0.45rem;
    font-size: 0.72rem;
  }
}

@media (min-width: 760px) and (max-width: 1180px) and (orientation: landscape) {
  :root {
    --board-size-sub: 21rem;
  }

  .board-section {
    justify-content: flex-start;
    padding: 0.35rem 0.75rem 4.9rem;
  }

  .board-wrapper {
    width: min(90vw, var(--board-max-size));
  }

  .player-bar {
    width: min(90vw, var(--board-max-size));
    max-width: 620px;
  }

  .board-section.eval-visible .player-bar {
    width: min(90vw, calc(var(--board-max-size) + var(--eval-bar-width) + 16px));
    max-width: calc(620px + var(--eval-bar-width) + 16px);
  }

  .board-controls-container {
    width: min(90vw, var(--board-max-size));
    max-width: 620px;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 5px;
  }

  .board-section.eval-visible .board-controls-container {
    width: min(90vw, calc(var(--board-max-size) + var(--eval-bar-width) + 16px));
    max-width: calc(620px + var(--eval-bar-width) + 16px);
  }

  .board-controls-container .color-options {
    grid-column: 1 / -1 !important;
    min-height: 30px;
    padding: 0 7px !important;
  }

  .board-controls-container .color-options .color-label {
    display: inline;
    font-size: 0.7rem !important;
  }

  .board-controls-container .color-options .btn-group .btn {
    min-height: 26px;
    padding: 0 8px !important;
    font-size: 0.68rem !important;
  }

  .board-controls-container > .btn {
    min-height: 32px;
    padding: 0.25rem 0.4rem;
    font-size: 0.68rem;
  }

  #btnTakeBackCtrl,
  #btnFlipBoardCtrl {
    grid-column: span 2;
  }
}

@media (max-width: 480px) {
  :root {
    --board-size-sub: 24.5rem;
  }

  .app-header {
    padding: 0.6rem 0.85rem;
  }

  .logo h1 {
    font-size: 1.1rem;
  }

  .board-wrapper {
    width: min(94vw, var(--board-max-size));
  }

  .player-bar {
    width: min(94vw, var(--board-max-size));
    padding: 0.4rem 0.7rem;
  }

  .board-section.eval-visible .player-bar {
    width: min(94vw, calc(var(--board-max-size) + var(--eval-bar-width) + 16px));
  }

  .board-controls-container {
    width: min(94vw, var(--board-max-size));
  }

  .board-section.eval-visible .board-controls-container {
    width: min(94vw, calc(var(--board-max-size) + var(--eval-bar-width) + 16px));
  }

  .tab-content {
    padding: 1rem;
  }

  .pgn-container {
    height: 150px;
  }

  .coach-chat-container {
    max-height: 300px;
    min-height: 200px;
    flex: 1 0 200px;
  }

  .modal-footer {
    flex-direction: column-reverse !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 12px 14px !important;
  }

  .modal-footer .btn {
    width: 100% !important;
    justify-content: center !important;
    display: inline-flex !important;
    align-items: center !important;
  }
}

/* Mobile Landscape (Side-by-Side Layout) */
@media (max-width: 1180px) and (orientation: landscape) and (max-height: 550px) {
  :root {
    --board-size-sub: 4.8rem;
  }

  .main-layout {
    flex-direction: row !important;
    height: calc(100dvh - 44px) !important;
    overflow: hidden !important;
  }

  .board-section {
    display: grid !important;
    grid-template-columns: auto minmax(200px, 320px) !important;
    grid-template-rows: auto 1fr auto !important;
    gap: 8px !important;
    padding: 0.25rem 0.5rem 0.25rem 0.5rem !important;
    align-items: center !important;
    justify-content: center !important;
    flex: 1 !important;
    height: 100% !important;
  }

  .board-wrapper {
    grid-column: 1 !important;
    grid-row: 1 / span 3 !important;
    width: min(44vw, var(--board-max-size)) !important;
    max-height: var(--board-max-size) !important;
    margin: 0 auto !important;
  }

  .opponent-bar {
    grid-column: 2 !important;
    grid-row: 1 !important;
    width: 100% !important;
    margin: 0 !important;
  }

  #boardControlsPlaceholder {
    grid-column: 2 !important;
    grid-row: 2 !important;
    width: 100% !important;
    margin: 0 !important;
  }

  .player-self-bar {
    grid-column: 2 !important;
    grid-row: 3 !important;
    width: 100% !important;
    margin: 0 !important;
  }

  .board-controls-container {
    width: 100% !important;
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 4px !important;
    padding: 4px !important;
  }

  .board-controls-container .btn {
    padding: 0.3rem 0.2rem !important;
    font-size: 0.7rem !important;
  }

  .board-controls-container .color-options {
    grid-column: 1 / -1 !important;
    margin-bottom: 2px !important;
    padding-bottom: 4px !important;
  }

  /* Right-side Sliding Panel (Drawer) */
  .side-panel {
    position: fixed !important;
    top: 44px !important;
    bottom: 0 !important;
    left: auto !important;
    right: 0 !important;
    width: 300px !important;
    min-width: 300px !important;
    height: calc(100dvh - 44px) !important;
    max-height: calc(100dvh - 44px) !important;
    border-top: none !important;
    border-left: 1px solid var(--border-color) !important;
    border-radius: 12px 0 0 12px !important;
    box-shadow: -8px 0 30px rgba(0, 0, 0, 0.45) !important;
    transform: translateX(calc(100% - 28px)) !important;
    transition: transform var(--transition-normal) !important;
    z-index: 60 !important;
    will-change: transform !important;
  }

  .app-container.drawer-open .side-panel {
    transform: translateX(0) !important;
  }

  .drawer-handle {
    display: flex !important;
    width: 28px !important;
    height: 100% !important;
    position: absolute !important;
    left: 0 !important;
    top: 0 !important;
    flex-direction: column !important;
    justify-content: center !important;
    align-items: center !important;
    cursor: pointer !important;
    background: rgba(0, 0, 0, 0.1) !important;
    border-right: 1px solid rgba(255, 255, 255, 0.05) !important;
    padding: 0 !important;
  }

  .drawer-grabber {
    width: 5px !important;
    height: 42px !important;
    border-radius: 3px !important;
    background-color: var(--text-muted) !important;
    opacity: 0.5 !important;
  }

  .panel-tabs, .tab-contents {
    padding-left: 28px !important;
  }

  .app-container.drawer-open .drawer-backdrop {
    display: block !important;
    position: fixed !important;
    inset: 0 !important;
    background: rgba(0, 0, 0, 0.5) !important;
    z-index: 55 !important;
  }
}

/* ─── Analyze Position Button ─── */
.btn-analyze {
  margin-left: auto;
  margin-right: 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 600;
  border-radius: 6px;
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
  transition: all var(--transition-fast);
}

.btn-analyze:hover {
  background-color: var(--accent-glow) !important;
  border-color: var(--accent) !important;
  color: var(--text-primary) !important;
  transform: translateY(-1px) scale(1.02);
}

@media (max-width: 650px) {
  .btn-analyze-text {
    display: none;
  }
  .btn-analyze {
    padding: 0.45rem 0.5rem;
    margin-right: 0.75rem;
  }
}

/* ─── Game Over & Game Review Premium Styling ─── */
.game-review-panel button,
.game-over-modal button,
.fen-action-btns button {
  transition: all var(--transition-fast) !important;
}

.game-review-panel button:hover,
.game-over-modal button:hover,
.fen-action-btns button:hover {
  transform: translateY(-1px) scale(1.02);
  filter: brightness(1.1);
}

.review-controls button {
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-secondary);
}

.review-controls button:hover {
  background: var(--accent);
  color: var(--bg-main) !important;
  border-color: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}

.game-over-modal {
  max-width: 420px;
  border: 1px solid var(--accent);
  box-shadow: 0 0 25px rgba(56, 189, 248, 0.15);
}

.game-over-icon i {
  animation: floatIcon 3s ease-in-out infinite;
}

@keyframes floatIcon {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-5px); }
}

/* ═══════════════════════════════════════════
   ERRATIC BOARD ANALYZING ANIMATION
   ═══════════════════════════════════════════ */
.board-analyzing .square {
  animation: erraticGlow 1.4s infinite ease-in-out alternate;
}

.board-analyzing .square:nth-child(2n) {
  animation-delay: 0.1s;
  animation-duration: 0.9s;
}
.board-analyzing .square:nth-child(3n) {
  animation-delay: 0.25s;
  animation-duration: 1.6s;
}
.board-analyzing .square:nth-child(5n) {
  animation-delay: 0.4s;
  animation-duration: 1.2s;
}
.board-analyzing .square:nth-child(7n) {
  animation-delay: 0.5s;
  animation-duration: 1.0s;
}

@keyframes erraticGlow {
  0% {
    box-shadow: inset 0 0 0 0px rgba(59, 130, 246, 0);
  }
  20% {
    box-shadow: inset 0 0 0 2px rgba(59, 130, 246, 0.6), inset 0 0 4px rgba(59, 130, 246, 0.3);
  }
  40% {
    box-shadow: inset 0 0 0 2px rgba(139, 92, 246, 0.6), inset 0 0 4px rgba(139, 92, 246, 0.3);
  }
  60% {
    box-shadow: inset 0 0 0 2px rgba(236, 72, 153, 0.6), inset 0 0 4px rgba(236, 72, 153, 0.3);
  }
  80% {
    box-shadow: inset 0 0 0 2px rgba(16, 185, 129, 0.6), inset 0 0 4px rgba(16, 185, 129, 0.3);
  }
  100% {
    box-shadow: inset 0 0 0 0px rgba(59, 130, 246, 0);
  }
}

/* ═══════════════════════════════════════════
   PLAYER REPORT CARD
   ═══════════════════════════════════════════ */
.report-card-modal {
  width: min(96vw, 640px);
  max-height: 90vh;
}

.report-card-modal .modal-body {
  overflow-y: auto;
}

#reportCardSubject {
  color: var(--accent);
  font-weight: 700;
}

.report-progress-track {
  width: 100%;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 6px;
  overflow: hidden;
  margin-top: 16px;
}

.report-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #a855f7);
  border-radius: 6px;
  transition: width 0.3s ease;
}

.report-stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.55rem;
  margin-bottom: 1.25rem;
}

.report-stat-card {
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 0.7rem 0.4rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  text-align: center;
}

.report-stat-value {
  font-family: var(--font-mono);
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent);
}

.report-stat-label {
  font-size: 0.6rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.report-section {
  margin-top: 1.25rem;
}

.report-section h4 {
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.7rem;
}

.report-section h4 i { color: var(--accent); }

.report-phase-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.5rem;
}

.report-phase-name {
  width: 92px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: capitalize;
  color: var(--text-primary);
}

.report-phase-track {
  flex: 1;
  height: 12px;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 6px;
  overflow: hidden;
}

.report-phase-fill {
  height: 100%;
  background: linear-gradient(90deg, #f59e0b, #ef4444);
  border-radius: 6px;
  transition: width 0.4s ease;
}

.report-phase-meta {
  width: 110px;
  text-align: right;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.report-motifs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.report-motif {
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.35rem 0.7rem;
  border-radius: 9999px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
}

.report-narrative {
  font-size: 0.88rem;
  line-height: 1.6;
  color: var(--text-primary);
  background: var(--card-bg);
  border: 1px solid var(--border-color);
  border-left: 3px solid var(--accent);
  border-radius: 8px;
  padding: 0.9rem 1rem;
}

.report-narrative .report-head {
  display: inline-block;
  margin-top: 0.6rem;
  color: var(--accent);
  font-size: 0.82rem;
  letter-spacing: 0.04em;
}

.report-examples {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.report-example {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  font-size: 0.82rem;
  line-height: 1.45;
  background: rgba(0, 0, 0, 0.18);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
}

.report-example-tag {
  flex-shrink: 0;
  font-size: 0.62rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #0f172a;
  padding: 0.15rem 0.45rem;
  border-radius: 5px;
  margin-top: 0.1rem;
}

.report-example-body { color: var(--text-primary); }

@media (max-width: 560px) {
  .report-stat-grid { grid-template-columns: repeat(3, 1fr); }
  .report-phase-name { width: 70px; }
  .report-phase-meta { width: 90px; }
}

/* Custom Report Card Verdict & Styled Habit/Strength Cards */
.report-verdict {
  font-size: 0.92rem;
  line-height: 1.5;
  color: var(--text-primary);
  background: linear-gradient(135deg, rgba(234, 179, 8, 0.08), rgba(234, 179, 8, 0.02));
  border: 1px solid rgba(234, 179, 8, 0.15);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 0.85rem 1rem;
  margin-bottom: 1.2rem;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.report-h-good {
  color: #10b981 !important; /* Green for strengths */
}

.report-h-good i {
  color: #10b981 !important;
}

.report-h-bad {
  color: #ef4444 !important; /* Red/orange for warnings */
}

.report-h-bad i {
  color: #ef4444 !important;
}

.report-cards {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  margin-bottom: 1.2rem;
}

.report-card {
  background: rgba(255, 255, 255, 0.02);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 0.8rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  transition: transform 0.2s ease, background-color 0.2s ease;
}

.report-card:hover {
  background: rgba(255, 255, 255, 0.04);
}

.report-card-good {
  border-left: 3px solid #10b981;
}

.report-card-bad {
  border-left: 3px solid #ef4444;
}

.report-card-title {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.report-card-good .report-card-title i {
  color: #10b981;
}

.report-card-bad .report-card-title i {
  color: #ef4444;
}

.report-card-detail {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
}

.report-card-evidence {
  font-size: 0.78rem;
  color: var(--text-primary);
  line-height: 1.4;
}

.report-card-fix {
  font-size: 0.76rem;
  background: rgba(56, 189, 248, 0.06);
  border: 1px solid rgba(56, 189, 248, 0.12);
  border-radius: 6px;
  padding: 0.45rem 0.6rem;
  color: #38bdf8;
  line-height: 1.4;
  margin-top: 0.15rem;
}

.report-loading, .report-error-card {
  text-align: center;
  padding: 1.25rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: rgba(0, 0, 0, 0.1);
  border: 1px dashed var(--border-color);
  border-radius: 8px;
}

.report-error-card {
  color: #ef4444;
  border-color: rgba(239, 68, 68, 0.25);
  background: rgba(239, 68, 68, 0.04);
}

/* Threat Overlay */
.btn-tool.active {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--text-primary);
}

.square-highlight.threat-attacked {
  box-shadow: inset 0 0 0 999px rgba(239, 68, 68, 0.16);
}

.square-highlight.threat-hanging {
  box-shadow: inset 0 0 0 3px #ef4444, inset 0 0 18px rgba(239, 68, 68, 0.38);
}

.square-highlight.threat-target {
  box-shadow: inset 0 0 0 3px #22c55e, inset 0 0 18px rgba(34, 197, 94, 0.32);
}

.square-highlight.threat-mate {
  box-shadow: inset 0 0 0 4px #ef4444, inset 0 0 22px rgba(239, 68, 68, 0.55);
  animation: pulseCheck 1s ease-in-out infinite alternate;
}

.square-highlight.threat-motif {
  box-shadow: inset 0 0 0 3px #a855f7, inset 0 0 18px rgba(168, 85, 247, 0.42);
}

/* ═══════════════════════════════════════════
   Anatomy Overlay — positional structure layers + legend
   (extends the Threat Overlay above with the position's "skeleton")
   ═══════════════════════════════════════════ */
/* Structural markers use a corner dot so they never clash with the
   ring/fill-based threat markers — a square can be both a threat and a feature. */
.square-highlight.anatomy-outpost { background-image: radial-gradient(circle at 84% 16%, #14b8a6 0 17%, transparent 18%); z-index: 2; }
.square-highlight.anatomy-weak    { background-image: radial-gradient(circle at 84% 16%, #f59e0b 0 17%, transparent 18%); z-index: 2; }
.square-highlight.anatomy-passer  { background-image: radial-gradient(circle at 84% 16%, #8b5cf6 0 17%, transparent 18%); z-index: 2; }
.square-highlight.anatomy-rook7   { background-image: radial-gradient(circle at 84% 16%, #eab308 0 17%, transparent 18%); z-index: 2; }

.anatomy-legend {
  margin-top: 10px;
  padding: 8px 11px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: 8px;
  font-size: 0.72rem;
  line-height: 1.3;
  color: var(--text-main, #e5e7eb);
}
.anatomy-legend .legend-title {
  font-weight: 700;
  margin-bottom: 6px;
  color: var(--accent, #38bdf8);
  display: flex;
  align-items: center;
  gap: 6px;
}
.anatomy-legend .legend-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 4px 14px;
}
.anatomy-legend .legend-item { display: flex; align-items: center; gap: 7px; }
.anatomy-legend .legend-swatch {
  width: 12px; height: 12px; border-radius: 3px; flex: none;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3);
}
.anatomy-legend .legend-breakdown {
  margin-top: 7px; padding-top: 7px;
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  display: flex; flex-wrap: wrap; gap: 4px 14px;
  color: var(--text-muted, #9aa4b2);
}
.anatomy-legend .legend-breakdown b { color: var(--text-main, #e5e7eb); font-weight: 700; }
.anatomy-legend .legend-hint { font-style: italic; opacity: 0.8; }

/* ═══════════════════════════════════════════
   Rating X-ray — "what each level plays here"
   ═══════════════════════════════════════════ */
.rating-xray-panel {
  margin-top: 10px;
  padding: 9px 11px;
  background: rgba(0, 0, 0, 0.28);
  border: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  border-radius: 8px;
  font-size: 0.78rem;
  color: var(--text-main, #e5e7eb);
}
.rating-xray-panel .xray-title {
  font-weight: 700; color: var(--accent, #38bdf8);
  display: flex; align-items: center; gap: 7px;
}
.rating-xray-panel .xray-close { margin-left: auto; cursor: pointer; font-size: 1.15rem; color: var(--text-muted, #9aa4b2); line-height: 1; }
.rating-xray-panel .xray-close:hover { color: var(--text-main, #e5e7eb); }
.rating-xray-panel .xray-sub { font-size: 0.68rem; color: var(--text-muted, #9aa4b2); margin: 2px 0 8px; }
.rating-xray-panel .xray-loading { color: var(--text-muted, #9aa4b2); padding: 4px 0; }
.rating-xray-panel .xray-rows { display: flex; flex-direction: column; gap: 3px; }
.rating-xray-panel .xray-row {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 6px;
  border-radius: 4px;
  transition: background-color 0.18s ease, transform 0.15s ease;
}
.rating-xray-panel .xray-row:hover {
  background: rgba(255, 255, 255, 0.08);
  transform: translateX(3px);
}
.rating-xray-panel .xray-swatch { width: 10px; height: 10px; border-radius: 50%; flex: none; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3); }
.rating-xray-panel .xray-band { flex: 1; display: flex; flex-direction: column; line-height: 1.1; }
.rating-xray-panel .xray-bandsub { font-size: 0.62rem; color: var(--text-muted, #9aa4b2); }
.rating-xray-panel .xray-move { font-family: 'JetBrains Mono', monospace; font-weight: 700; min-width: 54px; text-align: right; }
.rating-xray-panel .xray-eval { font-family: 'JetBrains Mono', monospace; min-width: 46px; text-align: right; color: var(--text-muted, #9aa4b2); }
.rating-xray-panel .xray-insight {
  margin-top: 8px; padding-top: 7px;
  border-top: 1px solid var(--border, rgba(255, 255, 255, 0.08));
  font-size: 0.72rem; color: var(--text-muted, #9aa4b2);
}
.rating-xray-panel .xray-insight b { color: var(--text-main, #e5e7eb); }

/* Move Quality Badges + Review Graph */
.move-quality-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  margin-left: 0.35rem;
  padding: 0.12rem 0.4rem;
  border-radius: 5px;
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 1.2;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: #0f172a;
  background: #94a3b8;
}

.move-quality-badge.quality-best,
.quality-best .move-quality-badge { background: #22c55e; }
.move-quality-badge.quality-excellent,
.quality-excellent .move-quality-badge { background: #14b8a6; }
.move-quality-badge.quality-good,
.quality-good .move-quality-badge { background: #38bdf8; }
.move-quality-badge.quality-ok,
.quality-ok .move-quality-badge { background: #94a3b8; }
.move-quality-badge.quality-inaccuracy,
.quality-inaccuracy .move-quality-badge { background: #eab308; }
.move-quality-badge.quality-mistake,
.quality-mistake .move-quality-badge { background: #f97316; }
.move-quality-badge.quality-blunder,
.quality-blunder .move-quality-badge { background: #ef4444; color: #fff; }
.move-quality-badge.quality-start,
.move-quality-badge.quality-unknown { background: #64748b; color: #fff; }

.pgn-move {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

.review-eval-graph {
  height: 78px;
  margin: 0 0 12px;
  padding: 8px;
  border: 1px solid var(--border-color);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.16);
}

.review-eval-graph svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.eval-baseline {
  stroke: rgba(255, 255, 255, 0.16);
  stroke-width: 2;
}

.eval-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  stroke-linecap: round;
  stroke-linejoin: round;
  opacity: 0.9;
}

.eval-node {
  fill: #94a3b8;
  stroke: rgba(15, 23, 42, 0.9);
  stroke-width: 3;
  cursor: pointer;
}

.eval-node.quality-best { fill: #22c55e; }
.eval-node.quality-excellent { fill: #14b8a6; }
.eval-node.quality-good { fill: #38bdf8; }
.eval-node.quality-inaccuracy { fill: #eab308; }
.eval-node.quality-mistake { fill: #f97316; }
.eval-node.quality-blunder { fill: #ef4444; }
.eval-node.active {
  stroke: #fff;
  stroke-width: 5;
}

/* Epic Mode Visual FX */
@keyframes boardShakeHeavy {
  0% { transform: translate(0, 0) rotate(0deg); }
  10% { transform: translate(-3px, 2px) rotate(-1deg); }
  20% { transform: translate(2px, -3px) rotate(1deg); }
  30% { transform: translate(-1px, -2px) rotate(0deg); }
  40% { transform: translate(3px, 1px) rotate(1deg); }
  50% { transform: translate(-2px, 3px) rotate(-1deg); }
  60% { transform: translate(1px, -1px) rotate(0deg); }
  70% { transform: translate(-3px, 1px) rotate(1deg); }
  80% { transform: translate(2px, 2px) rotate(-1deg); }
  90% { transform: translate(-1px, -2px) rotate(0deg); }
  100% { transform: translate(0, 0) rotate(0deg); }
}

@keyframes boardShakeLight {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-1px, 1px); }
  40% { transform: translate(1px, -1px); }
  60% { transform: translate(-1px, -1px); }
  80% { transform: translate(1px, 1px); }
  100% { transform: translate(0, 0); }
}

.epic-shake-heavy {
  animation: boardShakeHeavy 0.4s ease-in-out;
}

.epic-shake-light {
  animation: boardShakeLight 0.2s ease-in-out;
}

.epic-particle {
  position: absolute;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  pointer-events: none;
  z-index: 10;
  transition: transform 0.6s cubic-bezier(0.1, 0.8, 0.3, 1), opacity 0.6s ease-out;
  will-change: transform, opacity;
}

.epic-shockwave {
  position: absolute;
  border: 4px solid var(--accent);
  border-radius: 50%;
  pointer-events: none;
  z-index: 9;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%);
  animation: epicShockwaveAnim 0.5s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
}

@keyframes epicShockwaveAnim {
  0% {
    width: 10px;
    height: 10px;
    opacity: 1;
    border-width: 8px;
  }
  100% {
    width: 120px;
    height: 120px;
    opacity: 0;
    border-width: 1px;
  }
}

.epic-flash {
  position: absolute;
  top: 0; left: 0; width: 100%; height: 100%;
  pointer-events: none;
  z-index: 8;
  opacity: 0;
  animation: epicFlashAnim 0.3s ease-out forwards;
}

@keyframes epicFlashAnim {
  0% { opacity: 0.6; }
  100% { opacity: 0; }
}

/* --- Epic Mode Upgrade Styles --- */

/* Moving Piece Fly & Glow */
.piece.epic-moving-piece {
  z-index: 99 !important;
  transform: scale(1.18);
  filter: drop-shadow(0 8px 20px rgba(59, 130, 246, 0.85)) brightness(1.2) contrast(1.1);
  transition: top 0.35s cubic-bezier(0.25, 0.8, 0.25, 1), left 0.35s cubic-bezier(0.25, 0.8, 0.25, 1), transform 0.25s ease-out;
}

/* Fading Ghost Trails */
.epic-piece-trail {
  position: absolute;
  pointer-events: none;
  z-index: 12;
  opacity: 0.5;
  transform-origin: center;
  animation: epicTrailAnim 0.22s cubic-bezier(0.25, 1, 0.5, 1) forwards;
}

@keyframes epicTrailAnim {
  0% {
    opacity: 0.5;
    transform: scale(1.05);
  }
  100% {
    opacity: 0;
    transform: scale(0.9);
    filter: blur(1.5px) brightness(1.5);
  }
}

/* Grid Ripples - Outline/Border Glow Ripple only */
.square.epic-ripple-square::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  border: 2px solid var(--accent);
  box-shadow: 0 0 8px var(--accent);
  border-radius: inherit;
  pointer-events: none;
  z-index: 5;
  opacity: var(--ripple-opacity, 1);
  animation: squareRippleAnim 0.45s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
}

@keyframes squareRippleAnim {
  0% {
    transform: scale(0.9);
    opacity: 0;
  }
  30% {
    transform: scale(1);
    opacity: var(--ripple-opacity, 1);
  }
  100% {
    transform: scale(1.05);
    opacity: 0;
  }
}

/* Double Sword Slash Overlays */
.epic-slash-container {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  pointer-events: none;
  z-index: 20;
  overflow: visible;
  display: flex;
  align-items: center;
  justify-content: center;
}

.epic-slash-line {
  position: absolute;
  width: 220%; height: 6px;
  background: linear-gradient(90deg, transparent, #ffffff 25%, var(--accent) 50%, #ffffff 75%, transparent);
  box-shadow: 0 0 10px var(--accent), 0 0 20px var(--accent);
  transform-origin: center;
  opacity: 0;
}

.epic-slash-line.slash-1 {
  --rot: -45deg;
  transform: rotate(-45deg) scaleX(0);
  animation: swordSlashAnim 0.22s cubic-bezier(0.15, 0.85, 0.35, 1) forwards;
}

.epic-slash-line.slash-2 {
  --rot: 45deg;
  transform: rotate(45deg) scaleX(0);
  animation: swordSlashAnim 0.22s cubic-bezier(0.15, 0.85, 0.35, 1) 0.06s forwards;
}

@keyframes swordSlashAnim {
  0% {
    transform: rotate(var(--rot)) scaleX(0);
    opacity: 1;
  }
  50% {
    transform: rotate(var(--rot)) scaleX(1);
    opacity: 1;
  }
  100% {
    transform: rotate(var(--rot)) scaleX(1.15);
    opacity: 0;
  }
}

/* Slash Spark Particles */
.epic-slash-spark {
  position: absolute;
  width: 6px; height: 6px;
  background-color: #fff;
  border-radius: 50%;
  box-shadow: 0 0 6px var(--accent), 0 0 12px var(--accent);
  pointer-events: none;
  z-index: 21;
  animation: sparkAnim 0.4s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
  will-change: transform, opacity;
}

@keyframes sparkAnim {
  0% {
    transform: translate(-50%, -50%) translate(0, 0) scale(1);
    opacity: 1;
  }
  100% {
    transform: translate(-50%, -50%) translate(var(--tx), var(--ty)) scale(0.2);
    opacity: 0;
  }
}

.blunder-deck-card .btnDeckTrain {
  align-self: flex-start;
  margin-top: 0.25rem;
}

/* ==========================================================================
   FLOATING COMPACT BLUNDER WARNING CARD OVERRIDES
   ========================================================================== */
#blunderWarningOverlay {
  position: fixed;
  top: auto;
  left: 24px;
  bottom: 24px;
  right: auto;
  width: 360px;
  height: auto;
  background: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
  z-index: 1050;
  display: flex;
  align-items: flex-end;
  justify-content: flex-start;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s cubic-bezier(0.4, 0, 0.2, 1), transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  transform: translateY(20px);
}

#blunderWarningOverlay.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

#blunderWarningOverlay .settings-modal {
  width: 100%;
  max-width: 100%;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid rgba(239, 68, 68, 0.35); /* red glowing warning border */
  border-radius: 12px;
  box-shadow: 
    0 12px 32px rgba(0, 0, 0, 0.5), 
    0 0 15px rgba(239, 68, 68, 0.15);
  transform: none; /* remove default settings scale transform */
  transition: none;
}

#blunderWarningOverlay.active .settings-modal {
  transform: none;
}

#blunderWarningOverlay .modal-header {
  padding: 10px 14px;
  background-color: rgba(239, 68, 68, 0.12); /* warning-tinted header */
  border-bottom: 1px solid rgba(239, 68, 68, 0.2);
}

#blunderWarningOverlay .modal-body {
  padding: 12px 14px;
}

#blunderWarningOverlay .modal-footer {
  padding: 8px 14px 12px 14px;
  border-top: none;
  background-color: transparent;
}

/* ==========================================================================
   PERSISTENT EPIC MODE SHADOWS AND AMBIENT BACKGROUND GLOW
   ========================================================================== */
body.epic-mode-active .chess-board-container {
  position: relative;
  border: 2px solid var(--accent);
  box-shadow: 
    0 0 25px var(--accent-glow), 
    0 0 50px rgba(0, 0, 0, 0.6);
  transition: box-shadow 0.3s ease, border-color 0.3s ease;
  overflow: visible; /* Prevent clipping of epic flying pieces! */
}

body.epic-mode-active .board-section {
  background: radial-gradient(ellipse at 50% 40%, rgba(168, 85, 247, 0.12) 0%, rgba(56, 189, 248, 0.05) 50%, transparent 80%);
}

/* ==========================================================================
   EPIC CAPTURED PIECE FLYAWAY & IMPACT FRAME
   ========================================================================== */
.captured-piece-flying {
  position: absolute;
  pointer-events: none;
  z-index: 100;
  will-change: transform, opacity;
  animation: pieceKnockout 0.65s cubic-bezier(0.1, 0.8, 0.3, 1) forwards;
}

@keyframes pieceKnockout {
  0% {
    transform: translate(0, 0) scale(1) rotate(0deg);
    opacity: 1;
    filter: brightness(2) drop-shadow(0 0 15px var(--accent));
  }
  15% {
    transform: translate(var(--kx-mid), var(--ky-mid)) scale(1.4) rotate(60deg);
    opacity: 1;
    filter: brightness(1.8) drop-shadow(0 0 12px var(--accent));
  }
  100% {
    transform: translate(var(--kx-end), var(--ky-end)) scale(0.1) rotate(720deg);
    opacity: 0;
    filter: brightness(0.4) blur(1.5px);
  }
}

/* Stark high-contrast inverted impact frame flash */
body.epic-impact-active .chess-board-container {
  animation: impactFrameFlash 0.08s ease-out forwards;
}

@keyframes impactFrameFlash {
  0% {
    filter: invert(1) contrast(4) brightness(1.8);
  }
  50% {
    filter: invert(1) contrast(4) brightness(1.8);
  }
  100% {
    filter: none;
  }
}

/* ═══════════════════════════════════════════
   BOARD WAITING OVERLAY & COACH TOUR POPUPS
   ═══════════════════════════════════════════ */
.board-waiting-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(15, 23, 42, 0.4);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
  border-radius: 6px;
}

.board-waiting-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.board-waiting-content {
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid rgba(56, 189, 248, 0.2);
  padding: 16px 24px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 0 15px rgba(56, 189, 248, 0.25);
  color: #38bdf8;
  font-family: var(--font-outfit, 'Outfit', sans-serif);
  font-weight: 600;
  font-size: 1.1rem;
}

.board-waiting-spinner {
  font-size: 1.4rem;
  animation: waitingSpinnerPulse 2s infinite ease-in-out;
}

@keyframes waitingSpinnerPulse {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 0.8; }
  50% { transform: scale(1.15) rotate(180deg); opacity: 1; }
}

/* Glowing cyan coach highlights */
.square-highlight.coach-highlight {
  border: 3px solid #06b6d4;
  box-shadow: inset 0 0 10px rgba(6, 182, 212, 0.6), 0 0 8px rgba(6, 182, 212, 0.6);
  background-color: rgba(6, 182, 212, 0.15);
  z-index: 2;
  animation: coachHighlightPulse 1.5s infinite ease-in-out;
}

@keyframes coachHighlightPulse {
  0%, 100% { border-color: rgba(6, 182, 212, 0.8); box-shadow: inset 0 0 10px rgba(6, 182, 212, 0.4), 0 0 6px rgba(6, 182, 212, 0.4); }
  50% { border-color: rgba(6, 182, 212, 1); box-shadow: inset 0 0 15px rgba(6, 182, 212, 0.8), 0 0 12px rgba(6, 182, 212, 0.8); }
}

/* Coach tour popups */
.coach-tour-popup {
  position: absolute;
  background: rgba(15, 23, 42, 0.95);
  border: 2px solid var(--accent, #38bdf8);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 0 15px rgba(56, 189, 248, 0.3);
  color: #f8fafc;
  z-index: 100;
  width: 280px;
  font-family: var(--font-outfit, 'Outfit', sans-serif);
  font-size: 0.85rem;
  line-height: 1.4;
  pointer-events: auto;
  animation: popupScaleIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  transform-origin: bottom center;
}

@keyframes popupScaleIn {
  from { scale: 0.9; opacity: 0; }
  to { scale: 1; opacity: 1; }
}

.coach-tour-popup.position-below {
  transform-origin: top center;
  animation: popupScaleInBelow 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes popupScaleInBelow {
  from { scale: 0.9; opacity: 0; }
  to { scale: 1; opacity: 1; }
}

/* Arrow/tooltip pointer */
.coach-tour-popup::after {
  content: '';
  position: absolute;
  left: var(--arrow-left, 50%);
  transform: translateX(-50%);
  border-width: 8px;
  border-style: solid;
}

/* Arrow pointing down (when popup is above the square) */
.coach-tour-popup.position-above::after {
  top: 100%;
  border-color: var(--accent, #38bdf8) transparent transparent transparent;
}

/* Arrow pointing up (when popup is below the square) */
.coach-tour-popup.position-below::after {
  bottom: 100%;
  border-color: transparent transparent var(--accent, #38bdf8) transparent;
}

/* ═══════════════════════════════════════════
   ACCESSIBILITY & SRS DECK STYLING
   ═══════════════════════════════════════════ */

/* SRS Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 9999px;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1;
}

.badge-box {
  background-color: rgba(148, 163, 184, 0.15);
  color: #94a3b8;
  border: 1px solid rgba(148, 163, 184, 0.3);
}

.badge-mastered {
  background-color: rgba(34, 197, 94, 0.15);
  color: #22c55e;
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge-due {
  background-color: rgba(239, 68, 68, 0.15);
  color: #ef4444;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-learning {
  background-color: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

/* Mobile Bottom-sheet styling for screens <= 600px */
@media (max-width: 600px) {
  .side-panel {
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    margin-top: 15px;
    box-shadow: 0 -8px 30px rgba(0, 0, 0, 0.25);
  }
}

/* Prefers Reduced Motion overrides */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-delay: 0s !important;
    animation-duration: 0s !important;
    animation-iteration-count: 1 !important;
    transition-delay: 0s !important;
    transition-duration: 0s !important;
    scroll-behavior: auto !important;
  }
  
  .epic-shake,
  .epic-glow,
  .epic-flash,
  .epic-particle,
  .epic-tnt-fuse,
  .epic-meteor-tail,
  .epic-laser-beam,
  .square-highlight.coach-highlight {
    animation: none !important;
    transition: none !important;
  }

  .epic-particle {
    display: none !important;
  }
}

/* ═══════════════════════════════════════════
   NEW REORGANIZED LAYOUT STYLES
   ═══════════════════════════════════════════ */

/* Desktop layout adaptations */
@media (min-width: 1181px) {
  .app-header {
    display: none !important;
  }
  
  .main-layout {
    height: 100vh;
    height: 100dvh;
  }
  
  /* Left Control Sidebar */
  .left-control-sidebar {
    width: 220px;
    min-width: 220px;
    background-color: var(--bg-panel);
    border-right: 1px solid var(--border-color);
    backdrop-filter: blur(20px);
    display: flex;
    flex-direction: column;
    padding: 1.25rem 1rem;
    gap: 1.5rem;
    overflow-y: auto;
    box-shadow: 4px 0 20px rgba(0, 0, 0, 0.12);
    z-index: 5;
  }
  
  .left-control-sidebar .sidebar-logo-wrap {
    margin-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 1rem;
  }
  
  .left-control-sidebar .logo {
    display: flex;
    align-items: center;
    gap: 0.6rem;
  }
  
  .left-control-sidebar .logo .logo-icon {
    font-size: 1.35rem;
    color: var(--accent);
    filter: drop-shadow(0 0 6px var(--accent-glow));
  }
  
  .left-control-sidebar .logo h1 {
    font-size: 1.15rem;
    font-weight: 800;
    margin: 0;
    letter-spacing: -0.02em;
    line-height: 1.2;
  }
  
  /* Board controls stacked vertically inside sidebar */
  .left-control-sidebar .sidebar-controls-wrap .board-controls-container {
    display: flex;
    flex-direction: column;
    width: 100% !important;
    gap: 0.5rem;
    margin: 0;
  }
  
  .left-control-sidebar .sidebar-controls-wrap .board-controls-container .btn {
    width: 100%;
    padding: 0.55rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    border-radius: 6px;
  }
  
  /* Quick Actions (Train due, weakness report) */
  .left-control-sidebar .sidebar-actions-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
  }
  
  .left-control-sidebar .sidebar-actions-wrap .settings-toggle-btn {
    background: none;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    padding: 0.55rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.5rem;
    cursor: pointer;
    transition: all var(--transition-fast);
    text-align: left;
    width: 100%;
    height: auto;
  }

  .left-control-sidebar .sidebar-actions-wrap .settings-toggle-btn .btn-text {
    display: inline;
  }
  
  .left-control-sidebar .sidebar-actions-wrap .settings-toggle-btn:hover {
    background-color: rgba(255, 255, 255, 0.05);
    border-color: var(--accent);
    box-shadow: 0 0 10px var(--accent-glow);
    transform: translateY(-1px);
  }
  
  .left-control-sidebar .sidebar-actions-wrap .settings-toggle-btn span#dueDeckBadge {
    position: static !important;
    margin-left: auto;
  }
  
  /* Theme Picker */
  .left-control-sidebar .sidebar-actions-wrap .theme-picker {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    background: none;
    border: none;
    border-radius: 0;
    padding-left: 0;
    padding-right: 0;
  }
  
  .left-control-sidebar .sidebar-actions-wrap .theme-picker::before {
    content: "Theme";
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.2rem;
  }
  
  .left-control-sidebar .sidebar-actions-wrap .theme-picker .theme-btn {
    width: 100%;
    height: 34px;
    border-radius: 6px;
    background-color: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    transition: all var(--transition-fast);
  }
  
  .left-control-sidebar .sidebar-actions-wrap .theme-picker .theme-btn.active,
  .left-control-sidebar .sidebar-actions-wrap .theme-picker .theme-btn:hover {
    background-color: var(--accent);
    color: #fff;
    border-color: var(--accent);
  }
  
  /* Play As selector in Left Sidebar */
  .left-control-sidebar .sidebar-actions-wrap .color-options {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1rem;
    margin-top: 1.5rem;
  }
  
  .left-control-sidebar .sidebar-actions-wrap .color-options .color-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  .left-control-sidebar .sidebar-actions-wrap .color-options .btn-group {
    width: 100%;
  }

  .left-control-sidebar .sidebar-actions-wrap .color-options .btn-group .btn {
    flex: 1;
    height: 34px;
    border-radius: 6px;
    padding: 0;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
  }
  
  /* Analysis Section Column */
  .analysis-section {
    width: 320px;
    min-width: 320px;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1.25rem 0.75rem;
    border-left: 1px solid var(--border-color);
    background-color: rgba(0, 0, 0, 0.12);
    overflow-y: auto;
    height: 100%;
    z-index: 4;
  }
  
  .analysis-section .coach-chat-container {
    width: 100%;
    margin: 0;
  }
}

@media (min-width: 1181px) and (max-width: 1599px) {
  :root {
    --sidebar-width: 340px;
  }

  .left-control-sidebar {
    width: 210px;
    min-width: 210px;
    padding: 1rem 0.85rem;
    gap: 1.1rem;
  }

  .side-panel {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
  }

  .analysis-section {
    display: none !important;
  }

  .board-section {
    padding: 0.75rem;
  }

  .panel-tabs .tab-btn {
    padding: 0.85rem 0.6rem;
    font-size: 0.82rem;
  }

  .tab-content {
    padding: 1.1rem;
  }
}

/* Mobile responsive adaptations */
@media (max-width: 1180px) {
  .left-control-sidebar {
    display: none !important;
  }
  
  .analysis-section {
    display: none !important;
  }
}

/* ═══════════════════════════════════════════
   CYBERPUNK NEON THEME (CYBER) POLISH
   ═══════════════════════════════════════════ */

/* Add outlines and pink drop-shadow glows to SVGs/images inside the theme-cyber board */
.theme-cyber .piece img,
.theme-cyber .piece svg {
  filter: drop-shadow(1px 0 0 #ffffff) 
          drop-shadow(-1px 0 0 #ffffff) 
          drop-shadow(0 1px 0 #ffffff) 
          drop-shadow(0 -1px 0 #ffffff) 
          drop-shadow(0 0 5px var(--accent)) !important;
  transition: filter var(--transition-fast) !important;
}

.theme-cyber .piece:hover img,
.theme-cyber .piece:hover svg {
  filter: drop-shadow(1px 0 0 #ffffff) 
          drop-shadow(-1px 0 0 #ffffff) 
          drop-shadow(0 1px 0 #ffffff) 
          drop-shadow(0 -1px 0 #ffffff) 
          drop-shadow(0 0 10px var(--accent)) !important;
}

/* Mobile/performance budget: keep the board responsive on coarse pointers by
   removing the heaviest paint effects while preserving layout and controls. */
@media (max-width: 1180px), (pointer: coarse) {
  .piece {
    transition: none;
    will-change: auto;
  }

  .piece.dragging {
    filter: none;
    will-change: transform;
  }

  .piece img,
  .piece-img,
  .piece svg,
  .theme-cyber .piece img,
  .theme-cyber .piece svg,
  .theme-cyber .piece:hover img,
  .theme-cyber .piece:hover svg {
    filter: none !important;
  }

  .player-bar,
  .side-panel,
  .left-control-sidebar,
  .settings-modal,
  #blunderWarningOverlay .settings-modal,
  .board-waiting-overlay,
  .board-waiting-content {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
  }

  .chess-board-container {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.28), var(--neon-border);
  }

  body.epic-mode-active .chess-board-container {
    box-shadow: 0 0 16px var(--accent-glow), 0 4px 18px rgba(0, 0, 0, 0.38);
  }
}

/* Style code elements in coach message bubbles and review boxes for premium styling */
.msg-bubble code, 
.review-body code, 
#weaknessPlan code {
  background-color: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.1);
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
  font-size: 0.88em;
  color: var(--accent);
}

/* Premium hover effects for the clickable quota tracker container */
.quota-link-container:hover {
  background-color: rgba(255, 255, 255, 0.08) !important;
  border-color: var(--accent) !important;
  box-shadow: 0 0 12px var(--accent-glow);
  transform: translateY(-1px);
}

/* Scary Red Glowing Border for Secret Engine Board Squares */
.scary-red-hue .square {
  box-shadow: inset 0 0 12px rgba(255, 0, 0, 0.8), 0 0 4px rgba(255, 0, 0, 0.6) !important;
  border: 1px solid #ff0000 !important;
}

/* Spooky Doom Warning Popup styling */
.doom-popup {
  position: absolute;
  width: 260px;
  background: rgba(20, 0, 0, 0.95) !important;
  border: 2px solid #ff0000 !important;
  box-shadow: 0 0 15px rgba(255, 0, 0, 0.6), inset 0 0 10px rgba(255, 0, 0, 0.4) !important;
  border-radius: 8px;
  padding: 12px;
  z-index: 9999;
  font-family: 'Courier New', Courier, monospace;
  color: #ffcccc !important;
  transform-origin: bottom center;
  animation: doom-bounce 0.5s ease-out, doom-glow 2s infinite alternate;
  pointer-events: auto;
}

.doom-popup.position-below {
  transform-origin: top center;
}

.doom-popup.fade-out {
  opacity: 0;
  scale: 0.9;
  transition: opacity 0.5s ease, scale 0.5s ease;
}

.doom-popup-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 0.75rem;
  font-weight: bold;
  color: #ff3333;
  text-shadow: 0 0 5px rgba(255, 0, 0, 0.8);
  letter-spacing: 1px;
}

.doom-popup-close-btn {
  background: none;
  border: none;
  color: #ff8888;
  cursor: pointer;
  font-size: 1.1rem;
  font-weight: bold;
  line-height: 1;
}

.doom-popup-close-btn:hover {
  color: #ff0000;
}

.doom-popup-body {
  font-size: 0.8rem;
  line-height: 1.4;
  font-weight: 500;
  text-shadow: 0 0 2px rgba(255, 0, 0, 0.3);
}

/* Position above/below arrows */
.doom-popup::after {
  content: '';
  position: absolute;
  border-width: 8px;
  border-style: solid;
  left: var(--arrow-left, 50%);
  transform: translateX(-50%);
}

.doom-popup.position-above::after {
  top: 100%;
  border-color: #ff0000 transparent transparent transparent;
}

.doom-popup.position-below::after {
  bottom: 100%;
  border-color: transparent transparent #ff0000 transparent;
}

@keyframes doom-bounce {
  0% { scale: 0.8; opacity: 0; }
  70% { scale: 1.05; }
  100% { scale: 1; opacity: 1; }
}

@keyframes doom-glow {
  0% { box-shadow: 0 0 10px rgba(255, 0, 0, 0.4), inset 0 0 5px rgba(255, 0, 0, 0.2); }
  100% { box-shadow: 0 0 20px rgba(255, 0, 0, 0.8), inset 0 0 15px rgba(255, 0, 0, 0.5); }
}

/* Cap max width on ultra-wides for a premium, unified desktop experience */
@media (min-width: 1600px) {
  .app-container {
    max-width: 1600px;
    margin: 0 auto;
    border-left: 1px solid var(--border-color);
    border-right: 1px solid var(--border-color);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.5);
  }
}

/* --- Interactive Onboarding Tutorial Tour --- */
.tour-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.75);
  backdrop-filter: blur(2px);
  z-index: 10000;
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.3s ease;
}
.tour-backdrop.active {
  opacity: 1;
}

.tour-highlighted {
  z-index: 10001 !important;
  position: relative !important;
  outline: 3px solid var(--accent) !important;
  outline-offset: 4px !important;
  box-shadow: 0 0 25px var(--accent) !important;
  transition: outline 0.2s ease, box-shadow 0.2s ease !important;
}

.tour-popup {
  position: fixed;
  z-index: 10002;
  max-width: 340px;
  width: calc(100vw - 40px);
  background: rgba(30, 41, 59, 0.9);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5), 0 0 15px var(--accent);
  backdrop-filter: blur(20px) saturate(1.5);
  -webkit-backdrop-filter: blur(20px) saturate(1.5);
  padding: 18px;
  color: var(--text-main);
  opacity: 0;
  transform: scale(0.95);
  transition: opacity 0.3s ease, transform 0.3s ease, top 0.3s ease, left 0.3s ease;
}
.tour-popup.active {
  opacity: 1;
  transform: scale(1);
}

.tour-popup-header {
  font-weight: 800;
  color: var(--accent);
  font-size: 0.9rem;
  margin-bottom: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.tour-popup-body {
  font-size: 0.85rem;
  line-height: 1.5;
  color: var(--text-primary);
  margin-bottom: 16px;
}
.tour-popup-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.tour-popup-footer .btn {
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 700;
}
