/* ==========================================================================
   ChessMind - Modern Mobile-First Design System
   Inspired by Lichess, Chess.com & Linear
   ========================================================================== */

:root {
  /* Color Palette - Modern Dark Slate */
  --bg-app: #0d1117;
  --bg-surface: #161b22;
  --bg-elevated: #21262d;
  --bg-input: #0d1117;
  
  --border-subtle: #21262d;
  --border-default: #30363d;
  --border-muted: #1e252e;
  
  --text-main: #f0f6fc;
  --text-secondary: #8b949e;
  --text-muted: #6e7681;
  
  --accent-emerald: #10b981;
  --accent-emerald-hover: #059669;
  --accent-emerald-bg: rgba(16, 185, 129, 0.12);
  --accent-blue: #38bdf8;
  --accent-red: #f43f5e;
  --accent-amber: #f59e0b;
  
  --eval-white: #e6edf3;
  --eval-black: #161b22;
  
  /* Sizing & Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --header-height: 50px;
  --dock-height: 60px;
  
  /* Dynamic Aspect-Ratio Responsive Board Sizing:
     In portrait (width is the limiting constraint), board spans the viewport width */
  --board-size: min(calc(100vw - 16px), calc(100dvh - var(--header-height) - 140px));
  --board-max-width: var(--board-size);
}

/* Square, Tablets & Landscape Displays (Height is the limiting constraint) */
@media (min-aspect-ratio: 1/1) {
  :root {
    --board-size: min(calc(100vw - 32px), calc(100dvh - var(--header-height) - 110px), 820px);
    --board-max-width: var(--board-size);
  }
}

/* Large Desktop screens (1200px+) */
@media (min-width: 1200px) and (min-aspect-ratio: 1/1) {
  :root {
    --board-size: min(calc(100vw - 48px), calc(100dvh - var(--header-height) - 110px), 850px);
    --board-max-width: var(--board-size);
  }
}

[data-theme="light"] {
  --bg-app: #f6f8fa;
  --bg-surface: #ffffff;
  --bg-elevated: #f0f2f5;
  --bg-input: #ffffff;
  
  --border-subtle: #eaeef2;
  --border-default: #d0d7de;
  --border-muted: #e1e4e8;
  
  --text-main: #1f2328;
  --text-secondary: #59636e;
  --text-muted: #8c959f;
  
  --eval-white: #ffffff;
  --eval-black: #24292f;
}

/* Base Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  width: 100%;
  min-height: 100%;
  background-color: var(--bg-app);
  color: var(--text-main);
  font-family: var(--font-sans);
  line-height: 1.5;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea {
  font-family: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  user-select: none;
  touch-action: manipulation;
}

/* ==========================================================================
   Main Application Layout
   ========================================================================== */

.app-wrapper {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  position: relative;
}

/* App Header */
.app-header {
  min-height: var(--header-height);
  padding: env(safe-area-inset-top, 0px) 16px 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky;
  top: 0;
  z-index: 100;
}

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

.brand-icon {
  font-size: 24px;
  line-height: 1;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text-main);
}

.engine-status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-default);
  padding: 3px 10px;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background-color: var(--accent-amber);
  transition: background-color 0.3s ease;
}

.status-dot.ready {
  background-color: var(--accent-emerald);
  box-shadow: 0 0 8px var(--accent-emerald);
}

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

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  color: var(--text-secondary);
  background-color: transparent;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-elevated);
}

/* Main Content Area */
.app-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 12px 12px 24px 12px;
  gap: 12px;
  max-width: 100%;
}

/* ==========================================================================
   Chessboard & Evaluation Area
   ========================================================================== */

.board-container-card {
  width: var(--board-size);
  max-width: 100%;
  min-height: calc(100dvh - var(--header-height) - 16px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 8px;
  flex-shrink: 0;
}

.board-wrapper {
  position: relative;
  width: 100%;
  display: flex;
  flex-direction: row;
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  background-color: #262421;
  border: 1px solid var(--border-default);
  touch-action: none;
}

/* Integrated Sleek Eval Bar */
.eval-gauge {
  width: 8px;
  flex-shrink: 0;
  position: relative;
  background-color: var(--eval-black);
  z-index: 5;
}

.eval-gauge-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 50%;
  background-color: var(--eval-white);
  transition: height 0.25s ease-out;
}

/* Board Square Container (Pure 1:1 Aspect Ratio) */
.board-square-container {
  flex: 1;
  position: relative;
  aspect-ratio: 1 / 1;
  touch-action: none;
}

/* Chessground Board Mount */
.cg-board-wrap {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  touch-action: none;
}

/* Prevent browser scroll gestures from interrupting drag */
.cg-board-wrap, cg-board, cg-container, .cg-wrap piece {
  touch-action: none !important;
  -webkit-touch-callout: none !important;
  -webkit-user-select: none !important;
  user-select: none !important;
}

/* Ensure pieces scale perfectly */
.cg-board-wrap piece {
  background-size: cover;
}

/* Fluid, responsive piece lift effect on touch / drag */
cg-board piece.dragging {
  cursor: grabbing !important;
  cursor: -webkit-grabbing !important;
  z-index: 99 !important;
  filter: drop-shadow(0 14px 22px rgba(0, 0, 0, 0.65)) brightness(1.12);
  pointer-events: none !important;
}

/* Semi-transparent ghost piece on origin square */
.cg-wrap piece.ghost {
  opacity: 0.38 !important;
  filter: grayscale(0.4);
}

/* ==========================================================================
   Engine HUD Strip (Directly Below Board)
   ========================================================================== */

.engine-hud {
  width: 100%;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.hud-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.hud-eval-badge {
  font-size: 0.82rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-default);
  white-space: nowrap;
}

.hud-eval-badge.white-lead {
  color: #10b981;
  background-color: rgba(16, 185, 129, 0.12);
  border-color: rgba(16, 185, 129, 0.3);
}

.hud-eval-badge.black-lead {
  color: #f43f5e;
  background-color: rgba(244, 63, 94, 0.12);
  border-color: rgba(244, 63, 94, 0.3);
}

.hud-best-move {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--accent-emerald);
  white-space: nowrap;
}

.hud-best-move .icon {
  font-size: 13px;
}

.hud-right {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.hud-pill-btn {
  height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-default);
  font-size: 0.78rem;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.hud-pill-btn:hover, .hud-pill-btn.active {
  color: var(--text-main);
  background-color: var(--bg-surface);
  border-color: var(--accent-emerald);
}

/* ==========================================================================
   Candidate Moves Panel
   ========================================================================== */
.candidate-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.candidate-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  transition: background-color 0.15s ease;
}

.candidate-item:hover {
  background-color: var(--border-default);
}

.candidate-item .move-name {
  font-weight: 700;
  color: var(--accent-blue);
  font-size: 0.95rem;
}

.candidate-item .pv-preview {
  font-size: 0.78rem;
  color: var(--text-muted);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   Voice & Type Bar
   ========================================================================== */

.type-input-group {
  display: flex;
  gap: 6px;
}

.text-command-input {
  flex: 1;
  height: 42px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  font-size: 0.88rem;
  color: var(--text-main);
  outline: none;
  transition: border-color 0.2s ease;
}

.text-command-input:focus {
  border-color: var(--accent-emerald);
  box-shadow: 0 0 0 2px var(--accent-emerald-bg);
}

.btn-submit-move {
  height: 42px;
  padding: 0 16px;
  background-color: var(--accent-emerald);
  color: #ffffff;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  transition: background-color 0.2s ease;
}

.btn-submit-move:hover {
  background-color: var(--accent-emerald-hover);
}

/* Dedicated Large Push-To-Talk Button */
.ptt-large-btn {
  height: 52px;
  border-radius: var(--radius-md);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: all 0.2s ease;
}

.ptt-large-btn:hover {
  border-color: var(--accent-emerald);
  background-color: rgba(16, 185, 129, 0.08);
}

.ptt-large-btn.recording {
  background-color: rgba(244, 63, 94, 0.2) !important;
  color: #ffffff !important;
  border-color: var(--accent-red) !important;
  box-shadow: 0 0 16px rgba(244, 63, 94, 0.6) !important;
  animation: ptt-pulse 1s infinite alternate;
}

.ptt-large-btn.processing {
  background-color: rgba(56, 189, 248, 0.2) !important;
  color: #ffffff !important;
  border-color: var(--accent-blue) !important;
}

@keyframes ptt-pulse {
  0% { transform: scale(1); box-shadow: 0 0 6px rgba(244, 63, 94, 0.4); }
  100% { transform: scale(1.02); box-shadow: 0 0 18px rgba(244, 63, 94, 0.7); }
}

/* Piece Palette Deck */
.piece-palette-deck {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 8px;
}

.palette-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
}

.palette-item {
  flex: 1;
  height: 38px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  color: var(--text-main);
  transition: all 0.15s ease;
}

.palette-item:hover {
  background-color: var(--bg-elevated);
}

.palette-item.selected {
  border-color: var(--accent-emerald);
  background-color: var(--accent-emerald-bg);
  box-shadow: 0 0 8px rgba(16, 185, 129, 0.4);
  transform: translateY(-2px);
}

.palette-trash.selected {
  border-color: var(--accent-red) !important;
  background-color: rgba(244, 63, 94, 0.15) !important;
}

.action-btn {
  height: 36px;
  border-radius: var(--radius-sm);
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-default);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: all 0.2s ease;
}

.action-btn:hover {
  color: var(--text-main);
  border-color: var(--text-secondary);
}

/* ==========================================================================
   Modals & Overlays
   ========================================================================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
  opacity: 1;
  transition: opacity 0.2s ease;
}

.modal-backdrop.hidden {
  opacity: 0;
  pointer-events: none;
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 560px;
  max-height: 85vh;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.5);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.close-btn {
  font-size: 24px;
  line-height: 1;
  color: var(--text-muted);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: color 0.2s ease;
}

.close-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-elevated);
}

.modal-body {
  padding: 18px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Help Guide Styles */
.guide-section h3 {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--accent-emerald);
  margin-bottom: 6px;
}

.guide-section p, .guide-section ul {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.guide-section ul {
  padding-left: 18px;
}

.guide-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 6px;
  font-size: 0.8rem;
}

.guide-table th, .guide-table td {
  border: 1px solid var(--border-default);
  padding: 6px 10px;
  text-align: left;
}

.guide-table th {
  background-color: var(--bg-elevated);
  color: var(--text-main);
}

.guide-table code {
  color: var(--accent-emerald);
  background-color: var(--bg-elevated);
  padding: 2px 5px;
  border-radius: 4px;
}

/* Settings Form */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.88rem;
}

.setting-row select, .setting-row input[type="number"] {
  height: 34px;
  padding: 0 10px;
  background-color: var(--bg-input);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  color: var(--text-main);
}

/* Toasts - Positioned neatly at bottom, non-blocking */
.toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  width: calc(100% - 32px);
  max-width: 420px;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  z-index: 2000;
  pointer-events: none !important;
}

.toast {
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 600;
  color: #ffffff;
  background-color: var(--bg-elevated);
  border: 1px solid var(--border-default);
  pointer-events: none !important;
  text-align: center;
  transition: all 0.3s ease;
}

.toast.toast-success {
  background-color: #065f46;
  border-color: #10b981;
}

.toast.toast-error {
  background-color: #881337;
  border-color: #f43f5e;
}

.toast.toast-warning {
  background-color: #78350f;
  border-color: #f59e0b;
}

/* ==========================================================================
   Unified Single-Screen Layout
   ========================================================================== */

.single-screen-layout {
  padding: 8px 8px 36px 8px;
  gap: 16px;
  align-items: center;
  width: 100%;
}

.unified-controls-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: var(--board-size);
  max-width: 100%;
  margin: 0 auto;
}

/* Subtle scroll cue under board container */
.scroll-cue {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-size: 0.74rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 4px 0 2px 0;
  cursor: pointer;
  opacity: 0.75;
  transition: all 0.2s ease;
  user-select: none;
}

.scroll-cue:hover {
  opacity: 1;
  color: var(--accent-emerald);
}

.scroll-cue .cue-arrow {
  display: inline-block;
  font-size: 0.85rem;
  animation: bounceDown 1.8s infinite ease-in-out;
}

@keyframes bounceDown {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(3px); }
}

.quick-actions-bar {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 8px;
}

@media (max-width: 480px) {
  .quick-actions-bar {
    gap: 6px;
  }
  .quick-actions-bar .action-btn {
    font-size: 0.72rem;
    padding: 0 4px;
    height: 38px;
  }
}

.action-btn.btn-danger:hover {
  border-color: var(--accent-red);
  color: var(--accent-red);
}

.action-btn.toggle-free.active {
  background-color: var(--accent-emerald);
  color: #fff;
  border-color: var(--accent-emerald);
}

.voice-type-bar {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.candidate-moves-panel {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.candidate-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.pv-snippet {
  font-family: monospace;
  color: var(--text-main);
  font-size: 0.75rem;
}

/* ==========================================================================
   Game Mode Selector
   ========================================================================== */

.mode-selector-bar {
  display: flex;
  gap: 4px;
  padding: 4px;
  background: var(--bg-app);
  border-radius: var(--radius-md);
  margin-bottom: 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.mode-selector-bar::-webkit-scrollbar {
  display: none;
}

.mode-btn {
  flex: 1;
  padding: 8px 4px;
  background: transparent;
  color: var(--text-muted);
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  font-family: var(--font-sans);
  white-space: nowrap;
}

.mode-btn:hover {
  color: var(--text-secondary);
  background: var(--bg-elevated);
}

.mode-btn.active {
  background: var(--accent-emerald-bg);
  color: var(--accent-emerald);
}

.mode-panel {
  padding: 8px 0;
  border-top: 1px solid var(--border-subtle);
}

.mode-panel.hidden {
  display: none;
}

.setting-row.compact {
  padding: 6px 0;
}

.setting-row.compact label {
  font-size: 0.82rem;
}

.setting-row.compact select {
  font-size: 0.82rem;
  padding: 4px 8px;
}

.action-btn.btn-primary {
  background: var(--accent-emerald);
  color: #fff;
  border: none;
  font-weight: 600;
}

.action-btn.btn-primary:hover {
  background: var(--accent-emerald-hover);
}

.action-btn.btn-sm {
  padding: 4px 12px;
  font-size: 0.78rem;
  height: 30px;
}

.game-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  color: var(--text-main);
  margin-top: 6px;
}

.game-status-bar.hidden {
  display: none;
}

/* ==========================================================================
   Tactile Button Press Feedback
   ========================================================================== */

.action-btn:active,
.mode-btn:active,
.icon-btn:active,
.hud-pill-btn:active,
.palette-item:active,
.nav-step-btn:active,
.action-btn-xs:active {
  transform: scale(0.96);
  transition: transform 0.05s ease;
}

/* ==========================================================================
   Player Info Strips & Captured Pieces Graveyard
   ========================================================================== */

.player-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px;
  min-height: 32px;
  background: transparent;
  user-select: none;
}

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

.player-avatar {
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
}

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

.player-name {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  line-height: 1.2;
}

.player-badge {
  font-size: 0.68rem;
  padding: 1px 6px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-weight: 500;
}

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

.captured-tray {
  display: flex;
  align-items: center;
  font-size: 0.95rem;
  line-height: 1;
  min-height: 20px;
  letter-spacing: -2px;
}

.captured-piece {
  display: inline-block;
  opacity: 0.85;
  transition: transform 0.15s ease;
}

.captured-piece.piece-white {
  color: #f0f6fc;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.captured-piece.piece-black {
  color: #94a3b8;
  text-shadow: 0 1px 2px rgba(0,0,0,0.8);
}

.material-diff-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent-emerald);
  background: var(--accent-emerald-bg);
  padding: 1px 5px;
  border-radius: var(--radius-full);
  line-height: 1.2;
}

.material-diff-badge.hidden {
  display: none;
}

.player-right-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

.player-clock {
  font-family: ui-monospace, SFMono-Regular, "Roboto Mono", Menlo, Consolas, monospace;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  min-width: 62px;
  text-align: center;
  transition: all 0.15s ease;
  line-height: 1.2;
}

.player-clock.active {
  background: #1e293b;
  border-color: var(--accent-emerald);
  color: #ffffff;
  box-shadow: 0 0 10px rgba(16, 185, 129, 0.4);
}

.player-clock.low-time {
  border-color: var(--accent-red);
  color: var(--accent-red);
  animation: clock-pulse 1s infinite alternate;
}

@keyframes clock-pulse {
  from {
    background: rgba(244, 63, 94, 0.1);
    box-shadow: 0 0 4px rgba(244, 63, 94, 0.3);
  }
  to {
    background: rgba(244, 63, 94, 0.25);
    box-shadow: 0 0 12px rgba(244, 63, 94, 0.6);
  }
}

.player-clock.hidden {
  display: none;
}

/* ==========================================================================
   Move History Panel & Interactive Navigation
   ========================================================================== */

.move-history-panel {
  display: flex;
  flex-direction: column;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  gap: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.history-title-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
}

.history-title-icon {
  font-size: 0.95rem;
}

.history-title-text {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text-main);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.history-count-badge {
  font-size: 0.7rem;
  background: var(--bg-elevated);
  color: var(--text-muted);
  padding: 1px 6px;
  border-radius: var(--radius-full);
  font-weight: 500;
}

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

.action-btn-xs {
  font-size: 0.72rem;
  padding: 2px 8px;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  font-weight: 500;
}

.action-btn-xs:hover {
  background: var(--border-subtle);
  color: var(--text-main);
}

.action-btn-xs:active {
  transform: scale(0.95);
}

.history-moves-list {
  display: flex;
  flex-direction: column;
  max-height: 120px;
  min-height: 48px;
  overflow-y: auto;
  gap: 2px;
  padding-right: 4px;
  scrollbar-width: thin;
  scrollbar-color: var(--border-default) transparent;
}

.history-moves-list::-webkit-scrollbar {
  width: 4px;
}

.history-moves-list::-webkit-scrollbar-thumb {
  background: var(--border-default);
  border-radius: var(--radius-full);
}

.history-empty-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 44px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-style: italic;
}

.history-row {
  display: flex;
  align-items: center;
  border-radius: var(--radius-sm);
  padding: 1px 4px;
  font-family: var(--font-sans);
}

.history-row:nth-child(odd) {
  background: rgba(255, 255, 255, 0.02);
}

.history-num {
  width: 32px;
  font-size: 0.78rem;
  color: var(--text-muted);
  font-weight: 500;
  flex-shrink: 0;
}

.history-move-cell {
  flex: 1;
  text-align: left;
  padding: 3px 8px;
  font-size: 0.82rem;
  color: var(--text-main);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}

.history-move-cell:hover {
  background: var(--bg-elevated);
}

.history-move-cell.active-step {
  background: var(--accent-emerald-bg);
  color: var(--accent-emerald);
  font-weight: 700;
  box-shadow: 0 0 0 1px var(--accent-emerald);
}

.history-nav-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding-top: 4px;
  border-top: 1px solid var(--border-subtle);
}

.nav-step-btn {
  flex: 1;
  max-width: 52px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s ease;
}

.nav-step-btn:hover:not(:disabled) {
  background: var(--border-default);
  color: var(--text-main);
}

.nav-step-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.nav-step-btn:active:not(:disabled) {
  transform: scale(0.94);
}

.nav-live-btn {
  padding: 4px 10px;
  height: 30px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--accent-emerald);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.nav-live-btn:hover {
  background: var(--accent-emerald-hover);
}

.nav-live-btn.hidden {
  display: none;
}

/* ==========================================================================
   Phase 3: Opening Banner, Board Themes & Import Modal
   ========================================================================== */

/* Opening Name Banner */
.opening-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text-primary);
  font-weight: 500;
  transition: all 0.2s ease;
}

.opening-banner .opening-icon {
  font-size: 1rem;
}

.opening-banner .opening-text {
  color: var(--accent-emerald);
  font-weight: 600;
}

.opening-banner.hidden {
  display: none;
}

/* Board Themes */
.board-theme-brown cg-board {
  background-color: #f0d9b5 !important;
}

.board-theme-green cg-board {
  background-color: #eeeed2 !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 2'%3E%3Crect width='1' height='1' fill='%23eeeed2'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%23eeeed2'/%3E%3Crect width='1' height='1' x='1' fill='%23769656'/%3E%3Crect width='1' height='1' y='1' fill='%23769656'/%3E%3C/svg%3E") !important;
  background-size: 25% 25% !important;
  background-repeat: repeat !important;
}

.board-theme-blue cg-board {
  background-color: #dee3e6 !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 2'%3E%3Crect width='1' height='1' fill='%23dee3e6'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%23dee3e6'/%3E%3Crect width='1' height='1' x='1' fill='%238ca2ad'/%3E%3Crect width='1' height='1' y='1' fill='%238ca2ad'/%3E%3C/svg%3E") !important;
  background-size: 25% 25% !important;
  background-repeat: repeat !important;
}

.board-theme-wood cg-board {
  background-color: #e4c896 !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 2'%3E%3Crect width='1' height='1' fill='%23e4c896'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%23e4c896'/%3E%3Crect width='1' height='1' x='1' fill='%23a06c3a'/%3E%3Crect width='1' height='1' y='1' fill='%23a06c3a'/%3E%3C/svg%3E") !important;
  background-size: 25% 25% !important;
  background-repeat: repeat !important;
}

.board-theme-charcoal cg-board {
  background-color: #94a3b8 !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 2 2'%3E%3Crect width='1' height='1' fill='%2394a3b8'/%3E%3Crect width='1' height='1' x='1' y='1' fill='%2394a3b8'/%3E%3Crect width='1' height='1' x='1' fill='%23475569'/%3E%3Crect width='1' height='1' y='1' fill='%23475569'/%3E%3C/svg%3E") !important;
  background-size: 25% 25% !important;
  background-repeat: repeat !important;
}

/* Import Modal */
.import-textarea {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-surface);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, "Roboto Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
  resize: vertical;
  min-height: 120px;
  line-height: 1.4;
}

.import-textarea:focus {
  outline: none;
  border-color: var(--accent-emerald);
  box-shadow: 0 0 0 2px rgba(16, 185, 129, 0.2);
}

