/* ============================================================
   Chess.com Theme - Easy on the Eyes, Clean & Authentic
   ============================================================ */

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

:root {
  /* Chess.com Dark Mode Colors */
  --bg-primary: #302e2b;
  --bg-secondary: #262421;
  --bg-card: #21201d;
  --bg-card-hover: #2d2b27;
  --border: #3d3b37;
  --border-subtle: #312f2b;

  --text-primary: #ffffff;
  --text-secondary: #c3c2c1;
  --text-muted: #8b8987;

  /* Chess.com Brand Green */
  --accent: #81b64c;
  --accent-hover: #95c85d;
  --accent-active: #537133;
  --accent-cyan: #38bdf8;
  
  --warning: #f59e0b;
  --danger: #fa412d;

  /* Board Geometry */
  --sidebar-w: 320px;
  --board-size: 512px;
  --radius: 6px;
  --radius-sm: 4px;
}

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  user-select: none;
}

/* Background elements removed for eye comfort */
.bg-gradient, .particles {
  display: none !important;
}

/* Warning Banner if opened from file:// */
.file-protocol-warning {
  background: #3e3215;
  border: 1px solid #785a1c;
  color: #f7d070;
  padding: 10px 18px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  margin: 8px 16px 0;
  text-align: center;
}
.file-protocol-warning code {
  background: rgba(0,0,0,0.4);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  background-color: var(--bg-primary);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: var(--sidebar-w);
  background-color: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 16px 14px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #4d4b47 transparent;
  flex-shrink: 0;
}

.sidebar::-webkit-scrollbar { width: 5px; }
.sidebar::-webkit-scrollbar-thumb { background: #4d4b47; border-radius: 3px; }

/* Header */
.sidebar-header {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

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

.logo-img {
  width: 32px;
  height: 32px;
  object-fit: contain;
}

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

.logo-title {
  font-size: 17px;
  font-weight: 800;
  color: #ffffff;
  letter-spacing: -0.2px;
}

.logo-sub {
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}

/* Panel Cards */
.panel-card {
  background-color: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 8px;
}

/* Engine status */
.engine-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-primary);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.ready { background: var(--accent); }
.status-dot.loading { background: var(--warning); }
.status-dot.thinking { background: var(--accent-cyan); }
.status-dot.error { background: var(--danger); }

.engine-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Depth Control */
.depth-control {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.depth-btn {
  width: 28px;
  height: 28px;
  border-radius: 4px;
  background: #363431;
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}

.depth-btn:hover {
  background: #45433f;
}

.depth-value {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: baseline;
  gap: 4px;
}

.depth-label {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
}

.depth-slider {
  width: 100%;
  accent-color: var(--accent);
  cursor: pointer;
}

/* Side Selector Buttons */
.side-buttons {
  display: flex;
  gap: 6px;
}

.side-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 6px;
  background: #312f2c;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.side-btn:hover {
  background: #3d3b37;
  color: #fff;
}

.side-btn.active {
  background: #3e4835;
  border-color: var(--accent);
  color: #fff;
}

/* Suggestion Card */
.suggestion-card {
  border-color: #4a543b;
}

.suggestion-waiting {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
  padding: 6px 0;
}

.suggestion-move {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.move-from-to {
  display: flex;
  align-items: center;
  gap: 6px;
}

.sq-badge {
  font-size: 14px;
  font-weight: 800;
  padding: 4px 8px;
  background: #363431;
  border-radius: 4px;
  color: #ffffff;
  font-family: 'JetBrains Mono', monospace;
}

.move-arrow {
  color: var(--accent);
  font-size: 14px;
  font-weight: 800;
}

.move-san {
  font-size: 24px;
  font-weight: 800;
  color: var(--accent);
  letter-spacing: -0.5px;
}

.move-score {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 500;
}

.score-val {
  color: var(--text-secondary);
  font-weight: 700;
}

.play-suggested-card-btn {
  width: 100%;
  margin-top: 6px;
  padding: 9px 12px;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-bottom: 3px solid var(--accent-active);
  border-radius: 5px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.play-suggested-card-btn:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.play-suggested-card-btn:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
}

/* Eval Bar */
.eval-container {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.eval-bar-wrap {
  flex: 1;
  height: 12px;
  background: #111;
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.eval-bar {
  display: flex;
  height: 100%;
  width: 100%;
}

.eval-fill.white {
  background: #ffffff;
  transition: width 0.3s ease;
}

.eval-fill.black {
  background: #222222;
  transition: width 0.3s ease;
}

.eval-score {
  font-size: 14px;
  font-weight: 800;
  color: #ffffff;
  font-family: 'JetBrains Mono', monospace;
  min-width: 45px;
  text-align: right;
}

.eval-who {
  font-size: 11px;
  color: var(--text-muted);
}

/* Move history */
.move-history-card {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 140px;
  max-height: 200px;
}

.move-list {
  overflow-y: auto;
  flex: 1;
  font-size: 12px;
  font-family: 'JetBrains Mono', monospace;
  scrollbar-width: thin;
}

.move-empty {
  font-size: 11px;
  color: var(--text-muted);
  text-align: center;
  padding: 20px 0;
  font-style: italic;
}

.move-row {
  display: flex;
  padding: 3px 6px;
  border-radius: 3px;
}

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

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

.move-san-cell {
  flex: 1;
  color: var(--text-secondary);
  padding: 1px 4px;
  border-radius: 3px;
  cursor: pointer;
}

.move-san-cell:hover {
  background: #363431;
  color: #fff;
}

.move-san-cell.current {
  background: #45433f;
  color: var(--accent);
  font-weight: 700;
}

/* ============================================================
   MAIN CONTENT & BOARD
   ============================================================ */
.main-content {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  background-color: var(--bg-primary);
}

.board-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: var(--board-size);
}

/* Player Bar */
.player-bar {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
  transition: border-color 0.2s;
}

.player-bar.active-turn {
  border-color: var(--accent);
  background-color: #2b2f27;
}

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

.player-avatar {
  width: 34px;
  height: 34px;
  border-radius: 4px;
  background: #1c1a18;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
}

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

.player-sub {
  display: flex;
  align-items: center;
  gap: 1px;
  font-size: 11px;
  color: var(--text-muted);
  min-height: 18px;
}

.mini-piece {
  width: 18px;
  height: 18px;
  vertical-align: middle;
}

.no-cap {
  color: var(--text-muted);
  font-size: 11px;
}

.turn-indicator {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 4px;
  background: #312f2c;
  color: var(--text-muted);
}

.player-bar.active-turn .turn-indicator {
  background: var(--accent);
  color: #ffffff;
}

/* Board Wrapper & Container */
.board-wrapper {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
}

.board-container {
  position: relative;
  width: var(--board-size);
  height: var(--board-size);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

#chessCanvas {
  display: block;
  cursor: pointer;
  touch-action: none;
}

/* Quick Move / FEN input bar */
.move-input-bar {
  display: flex;
  gap: 8px;
  width: 100%;
}

.manual-input {
  flex: 1;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
  color: #ffffff;
  outline: none;
  font-family: 'JetBrains Mono', monospace;
  transition: border-color 0.15s;
}

.manual-input:focus {
  border-color: var(--accent);
}

.manual-input::placeholder {
  color: var(--text-muted);
  font-family: 'Inter', sans-serif;
  font-size: 11px;
}

.apply-btn {
  background: #3d3b38;
  border: none;
  border-bottom: 2px solid #282725;
  color: #fff;
  font-weight: 600;
  font-size: 12px;
  padding: 0 14px;
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.1s;
}

.apply-btn:hover {
  background: #4a4744;
}

.apply-btn:active {
  transform: translateY(1px);
}

/* Action Buttons (Chess.com Style) */
.action-bar {
  display: flex;
  gap: 8px;
  width: 100%;
  flex-wrap: wrap;
}

.action-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 4px;
  border: none;
  border-bottom: 3px solid #282725;
  background: #3d3b38;
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.1s;
}

.action-btn:hover {
  background: #4a4744;
  color: #ffffff;
  transform: translateY(-1px);
}

.action-btn:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
}

/* The Primary Green Button */
.play-suggest-btn {
  background: var(--accent);
  color: #ffffff;
  border-bottom: 3px solid var(--accent-active);
  font-size: 13px;
  font-weight: 800;
  flex: 1 1 100%;
}

.play-suggest-btn:hover {
  background: var(--accent-hover);
  color: #ffffff;
}

.play-suggest-btn:active {
  transform: translateY(2px);
  border-bottom-width: 1px;
}

/* Promotion Dialog */
.promotion-dialog {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: #262421;
  border: 2px solid var(--accent);
  border-radius: 6px;
  padding: 12px;
  z-index: 100;
  box-shadow: 0 10px 30px rgba(0,0,0,0.8);
}

.promo-title {
  font-size: 11px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
}

.promo-pieces {
  display: flex;
  gap: 6px;
}

.promo-piece-btn {
  width: 54px;
  height: 54px;
  border-radius: 4px;
  background: #312f2c;
  border: 1px solid var(--border);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.promo-piece-btn:hover {
  background: #4a4744;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-card {
  background: #262421;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  max-width: 320px;
  width: 90%;
  text-align: center;
}

.modal-icon {
  font-size: 40px;
  margin-bottom: 8px;
}

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

.modal-body {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.modal-actions {
  display: flex;
  gap: 8px;
}

.modal-btn {
  flex: 1;
  padding: 10px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  border: none;
}

.modal-btn.primary {
  background: var(--accent);
  color: #fff;
  border-bottom: 2px solid var(--accent-active);
}

.modal-btn.secondary {
  background: #3d3b38;
  color: #fff;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: #21201d;
  color: #ffffff;
  border: 1px solid #4a4744;
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: all 0.2s ease;
  z-index: 300;
  box-shadow: 0 4px 12px rgba(0,0,0,0.5);
}

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

/* ============================================================
   BOARD TOP CONTROLS (ALWAYS VISIBLE & MOBILE FRIENDLY)
   ============================================================ */
.board-top-bar {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 6px 12px;
}

.side-selector-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-secondary);
}

.top-side-buttons {
  display: flex;
  gap: 6px;
}

.top-side-buttons .side-btn {
  padding: 6px 12px;
  font-size: 12px;
}

/* ============================================================
   MOBILE RESPONSIVE DESIGN (FOR SMARTPHONES & TABLETS)
   ============================================================ */
@media (max-width: 960px) {
  html, body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    height: auto !important;
    min-height: 100% !important;
  }

  .app-layout {
    flex-direction: column !important;
    height: auto !important;
    min-height: 100% !important;
    overflow-y: visible !important;
  }

  .main-content {
    order: 1 !important;
    padding: 10px 8px !important;
    width: 100% !important;
    align-items: center !important;
    flex: none !important;
  }

  .board-area {
    max-width: 100% !important;
    width: 100% !important;
    gap: 6px !important;
  }

  .board-wrapper {
    width: 100% !important;
  }

  .board-container {
    width: min(94vw, 512px) !important;
    height: min(94vw, 512px) !important;
    max-width: 100% !important;
    margin: 0 auto;
  }

  #chessCanvas {
    width: 100% !important;
    height: 100% !important;
  }

  .sidebar {
    order: 2 !important;
    width: 100% !important;
    border-right: none !important;
    border-top: 1px solid var(--border);
    padding: 14px 12px !important;
    overflow-y: visible !important;
    flex: none !important;
  }

  .board-top-bar {
    padding: 6px 10px;
  }

  .top-side-buttons .side-btn {
    padding: 6px 8px;
    font-size: 11px;
  }

  .action-bar {
    gap: 6px;
  }

  .action-btn {
    padding: 8px 10px;
    font-size: 11px;
  }

  .play-suggest-btn {
    padding: 10px 14px;
    font-size: 13px;
  }
}
