/* ── Modern 2D Chess Design System ─────────────────────────────────── */
:root {
  --bg-primary: #0d1117;
  --bg-secondary: #161b22;
  --bg-card: rgba(22, 27, 34, 0.85);
  --bg-card-hover: rgba(30, 38, 49, 0.9);
  --border-card: rgba(255, 255, 255, 0.08);
  --border-accent: rgba(99, 163, 255, 0.35);

  --accent-blue: #3b82f6;
  --accent-blue-hover: #2563eb;
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-red: #ef4444;

  --text-primary: #f3f4f6;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;

  /* Board Themes (Default: Classic Tournament Green) */
  --board-light: #ebecd0;
  --board-dark: #739552;
  --sq-highlight: rgba(255, 255, 51, 0.42);
  --sq-selected: rgba(20, 85, 30, 0.45);
  --sq-hint: rgba(245, 158, 11, 0.55);
  --sq-check: radial-gradient(circle, rgba(239, 68, 68, 0.85) 0%, rgba(239, 68, 68, 0) 72%);

  --board-size: min(calc(100vh - 60px), calc(100vw - 370px), 760px);
  --sq-size: calc(var(--board-size) / 8);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-lg: 0 14px 40px rgba(0, 0, 0, 0.45);
  --shadow-card: 0 6px 24px rgba(0, 0, 0, 0.3);
}

/* Wood Board Theme */
body[data-theme="wood"] {
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --sq-selected: rgba(100, 60, 20, 0.45);
}

/* Slate Modern Theme */
body[data-theme="slate"] {
  --board-light: #dee3e6;
  --board-dark: #8ca2ad;
  --sq-selected: rgba(30, 60, 90, 0.45);
}

/* Midnight Theme */
body[data-theme="midnight"] {
  --board-light: #4a5568;
  --board-dark: #2d3748;
  --sq-selected: rgba(66, 153, 225, 0.45);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  min-height: 100%;
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, "Helvetica Neue", sans-serif;
  overflow-x: hidden;
  overflow-y: auto;
  background-image: 
    radial-gradient(circle at 15% 15%, rgba(59, 130, 246, 0.08) 0%, transparent 45%),
    radial-gradient(circle at 85% 85%, rgba(16, 185, 129, 0.06) 0%, transparent 45%);
  background-attachment: fixed;
}

/* ── Top Header Navigation ─────────────────────────────────────────── */
/* ── Top Header Navigation ─────────────────────────────────────────── */
.app-header {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: rgba(13, 17, 23, 0.9);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-card);
  position: sticky;
  top: 0;
  z-index: 100;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.brand-icon {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.4);
}

.brand-icon svg {
  width: 16px;
  height: 16px;
  fill: #ffffff;
}

.brand-title {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #ffffff;
}

.brand-title span {
  color: var(--accent-blue);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.account-guest-actions, .account-user { display: flex; align-items: center; gap: 8px; }
.account-guest-actions[hidden], .account-user[hidden] { display: none !important; }
.account-user { color: var(--text-secondary); font-size: 13px; font-weight: 700; }
.account-user #accountName { color: inherit; text-decoration: none; }
.account-user #accountName.admin-link { color: #93c5fd; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.account-register-btn, .account-submit { background: var(--accent-blue) !important; color: white !important; }
.account-overlay { position: fixed; inset: 0; z-index: 8000; display: none; align-items: center; justify-content: center; padding: 20px; background: rgba(3, 7, 18, .82); backdrop-filter: blur(8px); }
.account-overlay.active { display: flex; }
.account-dialog { position: relative; width: min(100%, 390px); padding: 28px; border: 1px solid var(--border-card); border-radius: var(--radius-lg); background: #111827; box-shadow: var(--shadow-lg); }
.account-dialog h2 { margin: 0 0 6px; color: #fff; font-size: 24px; }
.account-dialog > p { margin: 0 0 22px; color: var(--text-muted); font-size: 13px; }
.account-dialog label { display: block; margin: 13px 0 6px; color: var(--text-secondary); font-size: 13px; font-weight: 600; }
.account-dialog input { width: 100%; box-sizing: border-box; padding: 11px 12px; border: 1px solid var(--border-card); border-radius: 7px; background: #1f2937; color: #fff; font: inherit; }
.account-dialog textarea { width: 100%; box-sizing: border-box; resize: vertical; padding: 11px 12px; border: 1px solid var(--border-card); border-radius: 7px; background: #1f2937; color: #fff; font: inherit; }
.account-dialog input:focus, .account-dialog textarea:focus { outline: 2px solid rgba(59, 130, 246, .45); border-color: var(--accent-blue); }
.account-close { position: absolute; top: 12px; right: 14px; border: 0; background: transparent; color: var(--text-muted); font-size: 26px; cursor: pointer; }
.account-message { min-height: 18px; margin: 10px 0; color: var(--text-muted); font-size: 12px; }
.account-message.error { color: #fca5a5; }
.account-message.success { color: #86efac; }
.account-submit { width: 100%; padding: 11px; border: 0; border-radius: 7px; font-weight: 700; cursor: pointer; }
.account-submit:disabled { cursor: wait; opacity: .65; }
.account-registration-fields[hidden] { display: none !important; }
.account-reason-count { margin-top: 4px; color: var(--text-muted); font-size: 11px; text-align: right; }
.account-slider-row { display: flex; align-items: center; gap: 10px; }
.account-dialog .account-slider { flex: 1; padding: 0; accent-color: var(--accent-blue); }
.account-slider-row span { min-width: 76px; color: var(--text-muted); font-size: 11px; }
.account-slider-row.verified span { color: #86efac; font-weight: 700; }
.is-hidden { display: none !important; }
.sidebar-summary-btn { width: 100%; margin-top: 8px; }
.pref-row-spaced { margin-top: 14px; }
.full-width-control { width: 100%; }
.settings-fields { display: flex; flex-direction: column; gap: 16px; }
.settings-label { display: block; margin-bottom: 6px; color: var(--text-secondary); font-size: 13px; }
.settings-select { width: 100%; padding: 8px; }
.settings-link-row { margin-top: 10px; }
.settings-link { width: 100%; text-align: center; text-decoration: none; }
.online-players-card { flex-shrink: 0; }
.online-players-heading { display: flex; align-items: center; justify-content: space-between; }
.online-players-heading .panel-title { margin-bottom: 0; }
#onlinePlayerCount { min-width: 22px; padding: 2px 7px; border-radius: 999px; background: rgba(34,197,94,.14); color: #86efac; font-size: 11px; text-align: center; }
.online-players-list { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 10px; max-height: 76px; overflow-y: auto; }
.online-player { display: inline-flex; align-items: center; min-width: 0; gap: 6px; color: var(--text-secondary); font-size: 12px; }
.online-player-dot { width: 8px; height: 8px; flex: 0 0 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 7px rgba(34,197,94,.8); }
.online-player-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.online-player-rating { color: #fbbf24; font-size: 10px; font-weight: 700; }
.online-players-empty { color: var(--text-muted); font-size: 12px; }

@media (max-width: 680px) {
  .account-login-btn { display: none; }
  .account-guest-actions, .account-user { gap: 5px; }
  .account-user #accountName { display: none; }
}

.header-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.header-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
  transform: translateY(-1px);
}

.header-btn.btn-3d {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.2), rgba(37, 99, 235, 0.25));
  border-color: rgba(59, 130, 246, 0.4);
  color: #93c5fd;
}

.header-btn.btn-3d:hover {
  background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(37, 99, 235, 0.35));
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.25);
}

/* ── Main Layout ───────────────────────────────────────────────────── */
.game-container {
  display: flex;
  max-width: 1200px;
  margin: 0 auto;
  padding: 4px 16px;
  gap: 16px;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 44px);
  box-sizing: border-box;
}

/* ── Board Column ──────────────────────────────────────────────────── */
.board-column {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  width: 100%;
  max-width: var(--board-size);
  flex-shrink: 0;
}

/* Player Information Bar (Opponent & Player) */
.player-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 10px;
  background: var(--bg-card);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-card);
  min-height: 32px;
}

.sidebar-player-stack { display: flex; flex-direction: column; gap: 4px; flex-shrink: 0; }
.sidebar-player-stack .player-bar { padding: 6px 10px; }
.player-versus { height: 12px; margin: -2px 0; color: var(--text-muted); font-size: 9px; font-weight: 800; line-height: 12px; text-align: center; }

.player-info {
  display: flex;
  align-items: center;
  gap: 8px;
}

.player-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #1f2937;
  border: 1.5px solid rgba(255, 255, 255, 0.15);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  position: relative;
  flex-shrink: 0;
}

.player-avatar.ai-avatar {
  background: linear-gradient(135deg, #374151, #1f2937);
  color: #60a5fa;
  border-color: rgba(96, 165, 250, 0.4);
}

.player-avatar.user-avatar {
  background: linear-gradient(135deg, #059669, #047857);
  color: #ffffff;
  border-color: rgba(16, 185, 129, 0.4);
}

.player-meta {
  display: flex;
  flex-direction: column;
}

.player-name-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.player-name {
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
}

.player-badge {
  font-size: 11px;
  padding: 1px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--text-secondary);
  font-weight: 500;
}

.player-subtext {
  font-size: 12px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 6px;
}

.turn-pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  padding: 2px 7px;
  border-radius: 12px;
  font-weight: 600;
}

.turn-pill.active {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.turn-pill.waiting {
  background: rgba(156, 163, 175, 0.1);
  color: var(--text-muted);
}

.turn-pill.thinking {
  background: rgba(245, 158, 11, 0.2);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.35);
  animation: pulse-glow 1.5s infinite;
}

@keyframes pulse-glow {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.6; }
}

.captured-box {
  display: flex;
  align-items: center;
  gap: 4px;
}

.captured-pieces {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  max-width: 140px;
  min-height: 22px;
}

.captured-piece-icon {
  width: 18px;
  height: 18px;
  margin-left: -5px;
}

.captured-piece-icon:first-child {
  margin-left: 0;
}

.material-diff {
  font-size: 12px;
  font-weight: 700;
  color: #fbbf24;
  margin-left: 4px;
}

/* ── Chess Board Area ──────────────────────────────────────────────── */
.board-wrapper {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  user-select: none;
  touch-action: none;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow-lg), 0 0 0 1px rgba(255, 255, 255, 0.1);
  background: var(--board-dark);
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

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

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

/* Algebraic Coordinates inside squares */
.coord-rank, .coord-file {
  position: absolute;
  font-size: 11px;
  font-weight: 700;
  pointer-events: none;
  line-height: 1;
  z-index: 5;
}

.coord-rank {
  top: 4px;
  left: 4px;
}

.coord-file {
  bottom: 4px;
  right: 4px;
}

.square.light .coord-rank, .square.light .coord-file {
  color: var(--board-dark);
}

.square.dark .coord-rank, .square.dark .coord-file {
  color: var(--board-light);
}

/* Square Highlight Layers */
.sq-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

/* Square Illumination for Legal Moves */
.sq-legal {
  background: rgba(59, 130, 246, 0.38);
  box-shadow: inset 0 0 0 2.5px rgba(96, 165, 250, 0.85), inset 0 0 16px rgba(59, 130, 246, 0.45);
  z-index: 5;
  animation: legal-pulse 1.8s ease-in-out infinite alternate;
}

.sq-legal.sq-legal-capture {
  background: rgba(239, 68, 68, 0.42);
  box-shadow: inset 0 0 0 3px rgba(248, 113, 113, 0.9), inset 0 0 18px rgba(239, 68, 68, 0.5);
  z-index: 5;
  animation: capture-pulse 1.8s ease-in-out infinite alternate;
}

@keyframes legal-pulse {
  0% { opacity: 0.85; box-shadow: inset 0 0 0 2px rgba(96, 165, 250, 0.75), inset 0 0 10px rgba(59, 130, 246, 0.35); }
  100% { opacity: 1; box-shadow: inset 0 0 0 3px rgba(147, 197, 253, 0.95), inset 0 0 22px rgba(59, 130, 246, 0.6); }
}

@keyframes capture-pulse {
  0% { opacity: 0.85; box-shadow: inset 0 0 0 2.5px rgba(248, 113, 113, 0.8), inset 0 0 12px rgba(239, 68, 68, 0.35); }
  100% { opacity: 1; box-shadow: inset 0 0 0 3.5px rgba(252, 165, 165, 0.95), inset 0 0 24px rgba(239, 68, 68, 0.65); }
}

/* Selected square illumination */
.sq-selected {
  background: rgba(245, 158, 11, 0.45);
  box-shadow: inset 0 0 0 3px rgba(251, 191, 36, 0.95), inset 0 0 16px rgba(245, 158, 11, 0.4);
  z-index: 7;
}

.sq-last-move {
  background: var(--sq-highlight);
  z-index: 3;
}

.sq-hint {
  background: var(--sq-hint);
  box-shadow: inset 0 0 0 2.5px rgba(245, 158, 11, 0.9);
  z-index: 9;
  animation: pulse-glow 1s infinite alternate;
}

.sq-in-check {
  background: var(--sq-check);
  z-index: 5;
  animation: check-pulse 0.9s infinite alternate;
}

@keyframes check-pulse {
  0% { transform: scale(0.92); opacity: 0.7; }
  100% { transform: scale(1.08); opacity: 1; }
}

/* Check Attacking Piece Highlight */
.sq-check-attacker {
  background: radial-gradient(circle, rgba(239, 68, 68, 0.75) 0%, rgba(185, 28, 28, 0.5) 100%);
  box-shadow: inset 0 0 0 3px #ef4444, 0 0 16px rgba(239, 68, 68, 0.85);
  z-index: 5;
  animation: attacker-pulse 0.9s ease-in-out infinite alternate;
}

.sq-check-attacker::after {
  content: '⚔️';
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 13px;
  line-height: 1;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.9));
  pointer-events: none;
}

@keyframes attacker-pulse {
  0% { transform: scale(0.96); opacity: 0.85; filter: brightness(1); }
  100% { transform: scale(1.04); opacity: 1; filter: brightness(1.25) drop-shadow(0 0 8px #ef4444); }
}

/* Check Attack Trajectory Path */
.sq-check-path {
  background: rgba(239, 68, 68, 0.28);
  box-shadow: inset 0 0 0 2px rgba(248, 113, 113, 0.7), inset 0 0 14px rgba(239, 68, 68, 0.4);
  z-index: 4;
  animation: path-pulse 1.2s ease-in-out infinite alternate;
}

.sq-check-path::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -50%);
  background: rgba(239, 68, 68, 0.8);
  border: 1.5px solid rgba(254, 202, 202, 0.9);
  border-radius: 50%;
  box-shadow: 0 0 8px #ef4444;
  pointer-events: none;
}

@keyframes path-pulse {
  0% { opacity: 0.7; box-shadow: inset 0 0 0 1.5px rgba(248, 113, 113, 0.55), inset 0 0 8px rgba(239, 68, 68, 0.25); }
  100% { opacity: 1; box-shadow: inset 0 0 0 2.5px rgba(252, 165, 165, 0.9), inset 0 0 16px rgba(239, 68, 68, 0.5); }
}

/* Check Origin Launch Square (where the attacker came from) */
.sq-check-origin {
  background: radial-gradient(circle, rgba(239, 68, 68, 0.38) 0%, rgba(239, 68, 68, 0.12) 70%, transparent 100%);
  box-shadow: inset 0 0 0 2.5px rgba(239, 68, 68, 0.85), inset 0 0 16px rgba(239, 68, 68, 0.4);
  z-index: 4;
}

.sq-check-origin::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  border: 2px dashed rgba(254, 202, 202, 0.95);
  border-radius: 50%;
  background: rgba(239, 68, 68, 0.35);
  box-shadow: 0 0 12px #ef4444;
  pointer-events: none;
  animation: origin-spin 6s linear infinite;
}

@keyframes origin-spin {
  0% { transform: translate(-50%, -50%) rotate(0deg) scale(0.95); }
  50% { transform: translate(-50%, -50%) rotate(180deg) scale(1.08); }
  100% { transform: translate(-50%, -50%) rotate(360deg) scale(0.95); }
}

/* Dynamic Board Arrows Overlay */
.board-arrows {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 12;
}

/* Chess Pieces */
.piece-svg {
  width: 90%;
  height: 90%;
  z-index: 10;
  cursor: grab;
  pointer-events: none;
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, 0.35));
  transition: transform 0.12s ease-out;
}

.piece-svg.draggable {
  pointer-events: auto;
}

.piece-svg:active, .square.active-touch .piece-svg {
  cursor: grabbing;
  transform: scale(1.1);
}

/* Floating Drag Element */
#drag-piece-overlay {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  width: calc(var(--sq-size) * 1.15);
  height: calc(var(--sq-size) * 1.15);
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 12px 24px rgba(0, 0, 0, 0.6));
  display: none;
}

/* Move Animation Layer */
.sliding-piece {
  position: absolute;
  z-index: 25;
  pointer-events: none;
  transition: transform 0.18s cubic-bezier(0.2, 0, 0.2, 1);
  filter: drop-shadow(0 5px 8px rgba(0, 0, 0, 0.4));
}

/* ── Mobile & Quick Controls Bar ──────────────────────────────────── */
.quick-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  width: 100%;
}

.control-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 6px 8px;
  background: var(--bg-card);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s ease;
  user-select: none;
  min-height: 32px;
}

.control-btn:hover:not(:disabled) {
  background: var(--bg-card-hover);
  border-color: var(--border-accent);
  transform: translateY(-1px);
}

.control-btn:active:not(:disabled) {
  transform: translateY(0);
}

.control-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.control-btn.btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  border-color: #3b82f6;
  color: #ffffff;
}

.control-btn.btn-primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  box-shadow: 0 4px 14px rgba(37, 99, 235, 0.4);
}

.control-btn.btn-amber {
  background: rgba(245, 158, 11, 0.15);
  border-color: rgba(245, 158, 11, 0.4);
  color: #fbbf24;
}

.control-btn.btn-amber:hover:not(:disabled) {
  background: rgba(245, 158, 11, 0.28);
}

/* ── Sidebar Column (Desktop & Tablet) ─────────────────────────────── */
.sidebar-column {
  width: 300px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
  max-height: calc(100vh - 54px);
  height: calc(100vh - 54px);
  overflow: hidden;
}

.panel-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  box-shadow: var(--shadow-card);
}

.panel-title {
  font-size: 13px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* Game Status Box */
.status-banner {
  padding: 6px 10px;
  border-radius: var(--radius-sm);
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  transition: all 0.2s ease;
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.status-banner.thinking {
  background: rgba(245, 158, 11, 0.12);
  border-color: rgba(245, 158, 11, 0.35);
  color: #fbbf24;
}

.status-banner.check {
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.4);
  color: #f87171;
  animation: pulse-glow 0.8s infinite;
}

.status-banner.error {
  background: rgba(239, 68, 68, 0.2);
  border-color: var(--accent-red);
  color: #fca5a5;
}

.status-banner.gameover {
  background: rgba(99, 102, 241, 0.18);
  border-color: rgba(129, 140, 248, 0.55);
  color: #c7d2fe;
  font-weight: 700;
}

/* Difficulty Slider Row */
.difficulty-slider-group {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 14px;
}

/* Sidebar Desktop Quick Action Controls */
.sidebar-action-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}

.sidebar-action-bar .control-btn {
  flex: 1;
  padding: 6px 4px;
  font-size: 11px;
  min-height: 30px;
}

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 13px;
}

.slider-header label {
  color: var(--text-secondary);
  font-weight: 500;
}

.difficulty-badge {
  font-size: 12px;
  font-weight: 700;
  color: #93c5fd;
  background: rgba(59, 130, 246, 0.15);
  padding: 2px 8px;
  border-radius: 6px;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

.custom-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 3px;
  background: #374151;
  outline: none;
  cursor: pointer;
  transition: background 0.2s;
}

.custom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  cursor: pointer;
  transition: transform 0.1s, background 0.1s;
}

.custom-slider::-webkit-slider-thumb:hover {
  transform: scale(1.15);
  background: #60a5fa;
}

.custom-slider::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3b82f6;
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  cursor: pointer;
}

/* Move History Sheet */
.move-history-card {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 70px;
  overflow: hidden;
}

.move-table-container {
  flex: 1;
  max-height: 100%;
  overflow-y: auto;
  border-radius: var(--radius-sm);
  background: rgba(13, 17, 23, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.04);
}

.move-table-container::-webkit-scrollbar {
  width: 5px;
}
.move-table-container::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 3px;
}

.move-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.move-table th {
  position: sticky;
  top: 0;
  background: #1f2937;
  color: var(--text-muted);
  font-weight: 600;
  text-align: left;
  padding: 6px 10px;
  font-size: 11px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

.move-table td {
  padding: 6px 10px;
  color: var(--text-secondary);
  border-bottom: 1px solid rgba(255, 255, 255, 0.03);
}

.move-table tr:hover td {
  background: rgba(255, 255, 255, 0.03);
}

.move-table td.move-num {
  color: var(--text-muted);
  width: 40px;
  font-weight: 500;
}

.move-table td.active-move {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
  font-weight: 700;
  border-radius: 4px;
}

/* Theme & Preferences Row */
.pref-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  font-size: 13px;
  color: var(--text-secondary);
}

.pref-select {
  background: #1f2937;
  color: #ffffff;
  border: 1px solid var(--border-card);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 12px;
  outline: none;
  cursor: pointer;
}

/* ── Promotion Dialog (Overlay & Inline) ───────────────────────────── */
#promotion-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
}

#promotion-overlay.active {
  display: flex;
}

.promotion-modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-lg);
  text-align: center;
  max-width: 320px;
  width: 90%;
  animation: modal-pop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes modal-pop {
  0% { transform: scale(0.85); opacity: 0; }
  100% { transform: scale(1); opacity: 1; }
}

.promotion-title {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
  margin-bottom: 6px;
}

.promotion-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 20px;
}

.promotion-pieces {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.promotion-option {
  width: 100%;
  aspect-ratio: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border-card);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
  padding: 6px;
}

.promotion-option:hover {
  background: rgba(59, 130, 246, 0.25);
  border-color: var(--accent-blue);
  transform: translateY(-2px);
}

.promotion-option svg {
  width: 100%;
  height: 100%;
}

/* ── Game Over Modal ───────────────────────────────────────────────── */
#gameover-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  backdrop-filter: blur(8px);
  z-index: 6000;
  display: none;
  align-items: center;
  justify-content: center;
}

#gameover-overlay.active {
  display: flex;
}

.gameover-modal {
  background: linear-gradient(160deg, #1f2937, #111827);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  text-align: center;
  max-width: 380px;
  width: 90%;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.7);
  animation: modal-pop 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.gameover-icon {
  font-size: 52px;
  line-height: 1;
  margin-bottom: 16px;
}

.gameover-title {
  font-size: 28px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.gameover-subtitle {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.gameover-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ── Mobile Settings Sheet ─────────────────────────────────────────── */
#settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(6px);
  z-index: 4000;
  display: none;
  align-items: flex-end;
  justify-content: center;
}

#settings-overlay.active {
  display: flex;
}

.settings-sheet {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-card);
  border-radius: 20px 20px 0 0;
  padding: 24px;
  width: 100%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  animation: slide-up 0.25s ease-out;
}

@keyframes slide-up {
  0% { transform: translateY(100%); }
  100% { transform: translateY(0); }
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}

.sheet-title {
  font-size: 18px;
  font-weight: 700;
  color: #ffffff;
}

.sheet-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 24px;
  cursor: pointer;
  line-height: 1;
}

/* ── Desktop View (>= 993px): Clean non-redundant layout ─────────── */
@media (min-width: 993px) {
  /* Hide under-board toolbar on PC desktop (all controls are in the sidebar) */
  .board-column .quick-controls {
    display: none !important;
  }
  
  /* Hide under-board review bar on PC desktop (review summary is in Game Status card) */
  .board-column .review-bar {
    display: none !important;
  }

  /* Hide header settings button on PC desktop (Options card is already in the sidebar) */
  .header-actions #open-settings-btn {
    display: none !important;
  }
}

/* ── Responsive Adaptations (<= 992px) ─────────────────────────────── */
@media (max-width: 992px) {
  html, body {
    overflow-y: auto;
    height: auto;
  }

  .game-container {
    flex-direction: column;
    align-items: center;
    padding: 8px 12px 20px;
    gap: 12px;
    height: auto;
    min-height: calc(100vh - 44px);
    overflow: visible;
  }

  .sidebar-column {
    width: 100%;
    max-width: var(--board-size);
    height: auto;
    max-height: none;
    overflow: visible;
  }

  .sidebar-action-bar {
    display: none !important;
  }

  #sidebar-summary-btn {
    display: none !important;
  }

  :root {
    --board-size: min(calc(100vh - 190px), 94vw, 460px);
  }
}

/* ── Review Mode Bar ─────────────────────────────────────────────── */
.review-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.96), rgba(15, 23, 42, 0.98));
  border: 1.5px solid rgba(99, 102, 241, 0.5);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.4), 0 0 14px rgba(99, 102, 241, 0.25);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  margin: 2px 0;
  width: 100%;
  box-sizing: border-box;
  animation: slide-in-bar 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 50;
}

@keyframes slide-in-bar {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.review-status-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.review-pill {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  background: rgba(99, 102, 241, 0.25);
  border: 1px solid rgba(129, 140, 248, 0.4);
  color: #c7d2fe;
  padding: 2px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.review-result-title {
  font-size: 13px;
  font-weight: 700;
  color: #f8fafc;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.review-buttons-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.review-buttons-wrap .control-btn {
  padding: 6px 12px;
  font-size: 12px;
  min-height: 32px;
}

.review-new-game-btn.attention-pulse {
  animation: btn-attention-pulse 0.6s ease-in-out 2;
}

@keyframes btn-attention-pulse {
  0%, 100% {
    transform: scale(1);
    box-shadow: 0 0 0 rgba(99, 102, 241, 0);
  }
  50% {
    transform: scale(1.08);
    box-shadow: 0 0 16px rgba(99, 102, 241, 0.85);
  }
}

/* ── In-board Floating Toast ─────────────────────────────────────── */
.toast-message {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.9);
  background: rgba(15, 23, 42, 0.94);
  color: #f1f5f9;
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 10px 18px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  text-align: center;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.65);
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 500;
  max-width: 85%;
  line-height: 1.4;
}

.toast-message.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

@media (max-width: 600px) {
  :root {
    --board-size: min(94vw, 420px);
  }

  .app-header {
    padding: 0 12px;
    height: 44px;
  }

  .brand-title {
    font-size: 15px;
  }

  .player-bar {
    padding: 4px 8px;
    min-height: 32px;
  }

  .player-avatar {
    width: 24px;
    height: 24px;
    font-size: 13px;
  }

  .player-name {
    font-size: 12px;
  }

  .quick-controls .control-btn {
    padding: 6px 8px;
    font-size: 11px;
    min-height: 32px;
  }

  .review-bar {
    padding: 6px 10px;
    gap: 8px;
  }

  .review-pill {
    font-size: 9px;
    padding: 2px 6px;
  }

  .review-result-title {
    font-size: 12px;
  }

  .review-buttons-wrap .control-btn {
    padding: 5px 8px;
    font-size: 11px;
    min-height: 30px;
  }

  /* In mobile, hide the desktop sidebar move table by default into collapsible card */
  .desktop-only-panel {
    display: none;
  }
}

/* ── Reduced motion ──────────────────────────────────────────────────────────
   Every highlight carries its meaning in colour, not in movement, so honouring
   the OS "reduce motion" setting costs the player no information: the colours
   stay exactly as they are and simply stop moving. The in-check square pulses by
   scaling, so it is also pinned at full size. The 3D board and the threat arrows
   are handled in chess-core.js / chess-2d.js via prefersReducedMotion(). */
@media (prefers-reduced-motion: reduce) {
  .turn-pill.thinking,
  .sq-legal,
  .sq-legal.sq-legal-capture,
  .sq-hint,
  .sq-in-check,
  .sq-check-attacker,
  .sq-check-path,
  .sq-check-origin::after,
  .status-banner.check,
  .promotion-modal,
  .gameover-modal,
  .settings-sheet,
  .review-bar,
  .review-new-game-btn.attention-pulse {
    animation: none !important;
  }

  .sq-in-check {
    transform: none !important;
  }

  /* The moving piece must still land on its square: only the glide is removed,
     so it arrives instantly instead of travelling. */
  .piece-svg,
  .sliding-piece {
    transition: none !important;
  }
}
