:root {
  /* Dark Obsidian & Steel Metallic Palette */
  --bg-main: #09090b;
  --panel-bg: #141416;
  --glass-bg: rgba(20, 20, 22, 0.90);
  --glass-border: rgba(255, 255, 255, 0.08);
  --glass-border-hover: rgba(255, 255, 255, 0.18);
  
  /* Monochrome Steel/Plated Accents (Replaces Orange) */
  --accent: #52525b;
  --accent-hover: #71717a;
  --accent-active: #27272a;
  --accent-glow: rgba(255, 255, 255, 0.12);
  
  /* Text Contrast */
  --text-main: #f4f4f5;
  --text-muted: #a1a1aa;
  
  /* Board Colors */
  --sq-light: #e5dccb;
  --sq-dark: #7a6b5d;
  --sq-selected: #52525b;
  --sq-lastmove: rgba(255, 255, 255, 0.18);
  --sq-check: #dc2626;
  --sq-possible: rgba(0, 0, 0, 0.35);

  /* Moderate Rounding Scale */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
}

body.flat-theme {
  --glass-bg: #141416;
  --glass-border: #27272a;
}
body.flat-theme .game-container,
body.flat-theme .panel,
body.flat-theme .modal-content {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  user-select: none;
}

body {
  background: radial-gradient(circle at 50% 0%, #1c1c21 0%, #09090b 85%);
  color: var(--text-main);
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  padding: 16px;
}

.app-layout {
  display: flex;
  gap: 20px;
  width: 100%;
  max-width: 980px;
  align-items: flex-start;
}

.game-container {
  flex: 1;
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.85), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

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

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

/* Plated Monochrome Logo Icon */
.logo-icon {
  font-size: 1.8rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  filter: drop-shadow(0 2px 6px rgba(255, 255, 255, 0.15));
}

.brand h1 {
  font-size: 1.25rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

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

.status-badge {
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-main);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.05) 0%, rgba(255, 255, 255, 0.02) 100%);
  padding: 6px 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--glass-border);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.eval-container {
  display: flex;
  align-items: center;
  gap: 12px;
}

.eval-bar-bg {
  flex: 1;
  height: 6px;
  background-color: rgba(0, 0, 0, 0.4);
  border-radius: 3px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.05);
}

.eval-bar-fill {
  height: 100%;
  background-color: var(--text-main);
  width: 50%;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.eval-text {
  font-size: 0.8rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-muted);
  min-width: 75px;
  text-align: right;
}

.board-outer {
  display: flex;
  gap: 8px;
  width: 100%;
  position: relative;
}

.rank-labels {
  display: flex;
  flex-direction: column;
  justify-content: space-around;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.board-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  position: relative;
}

.chess-board {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.75), inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  position: relative;
}

.file-labels {
  display: flex;
  justify-content: space-around;
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.square {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: clamp(2rem, 5.5vw, 3.4rem);
  line-height: 1;
  cursor: pointer;
  position: relative;
  transition: background-color 0.1s ease;
}

.square.light { background-color: var(--sq-light); color: #2c2520; }
.square.dark { background-color: var(--sq-dark); color: #181412; }
.square.selected { background-color: var(--sq-selected) !important; color: #fff; }
.square.last-move { background-color: var(--sq-lastmove); }
.square.in-check { background-color: var(--sq-check) !important; color: #fff; }

.square.possible::after {
  content: '';
  width: 24%;
  height: 24%;
  background-color: var(--sq-possible);
  border-radius: 50%;
  position: absolute;
}

.sliding-piece {
  position: absolute;
  z-index: 50;
  pointer-events: none;
  font-size: clamp(2rem, 5.5vw, 3.4rem);
  display: flex;
  justify-content: center;
  align-items: center;
  line-height: 1;
  transition: transform 0.22s cubic-bezier(0.25, 1, 0.5, 1);
}

.square.best-move-from {
  background-color: rgba(255, 255, 255, 0.25) !important;
  box-shadow: inset 0 0 0 2px var(--text-main);
}

.square.best-move-to {
  background-color: rgba(255, 255, 255, 0.4) !important;
  box-shadow: inset 0 0 0 3px #ffffff;
}

.square.best-move-to::before {
  content: '★';
  position: absolute;
  top: 4px;
  right: 6px;
  font-size: 0.85rem;
  color: #ffffff;
  text-shadow: 0 0 4px rgba(0, 0, 0, 0.9);
  pointer-events: none;
}

.controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.player-selectors {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

/* ==========================================
   CUSTOM PLATED LIST PICKER (DROPDOWN)
   ========================================== */

.select-group {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.select-group::after {
  content: '';
  position: absolute;
  right: 12px;
  pointer-events: none;
  width: 0;
  height: 0;
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--text-muted);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.select-group:hover::after {
  border-top-color: var(--text-main);
}

select {
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  background: linear-gradient(180deg, rgba(38, 38, 42, 0.9) 0%, rgba(20, 20, 22, 0.9) 100%);
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.14);
  padding: 9px 32px 9px 14px;
  border-radius: var(--radius-sm);
  outline: none;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.15), 
    inset 0 -1px 0 rgba(0, 0, 0, 0.7), 
    0 3px 6px rgba(0, 0, 0, 0.4);
  transition: all 0.15s ease;
}

select:hover {
  border-color: rgba(255, 255, 255, 0.25);
  background: linear-gradient(180deg, rgba(52, 52, 58, 0.9) 0%, rgba(28, 28, 32, 0.9) 100%);
  transform: translateY(-1px);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.22), 
    inset 0 -1px 0 rgba(0, 0, 0, 0.7), 
    0 5px 10px rgba(0, 0, 0, 0.5);
}

select:focus {
  border-color: rgba(255, 255, 255, 0.35);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.25), 
    0 0 0 2px rgba(255, 255, 255, 0.12);
}

select option {
  background-color: #141416;
  color: var(--text-main);
  padding: 10px;
}

.action-buttons {
  display: flex;
  gap: 8px;
}

/* ==========================================
   PLATED BUTTON ARCHITECTURE (GRAY / BLACK)
   ========================================== */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: all 0.15s ease;
  border: 1px solid rgba(255, 255, 255, 0.14);
  outline: none;
}

/* Dark Steel Secondary Button Plate */
.btn-secondary {
  color: var(--text-main);
  background: linear-gradient(180deg, rgba(38, 38, 42, 0.9) 0%, rgba(20, 20, 22, 0.9) 100%);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.15), 
    inset 0 -1px 0 rgba(0, 0, 0, 0.7), 
    0 3px 6px rgba(0, 0, 0, 0.4);
}

.btn-secondary:hover { 
  background: linear-gradient(180deg, rgba(52, 52, 58, 0.9) 0%, rgba(28, 28, 32, 0.9) 100%);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.22), 
    inset 0 -1px 0 rgba(0, 0, 0, 0.7), 
    0 5px 12px rgba(0, 0, 0, 0.5);
}

.btn-secondary:active {
  transform: translateY(1px);
  background: linear-gradient(180deg, rgba(16, 16, 18, 0.9) 0%, rgba(32, 32, 36, 0.9) 100%);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.8);
}

/* High-Contrast Charcoal/Black Primary Button Plate (Replaced Orange) */
.btn-primary {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.25);
  background: linear-gradient(180deg, #3f3f46 0%, #18181b 100%);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.3), 
    inset 0 -1px 0 rgba(0, 0, 0, 0.8), 
    0 4px 12px rgba(0, 0, 0, 0.6);
}

.btn-primary:hover { 
  background: linear-gradient(180deg, #52525b 0%, #27272a 100%);
  border-color: rgba(255, 255, 255, 0.35);
  transform: translateY(-1px);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.4), 
    inset 0 -1px 0 rgba(0, 0, 0, 0.8), 
    0 6px 16px rgba(0, 0, 0, 0.7);
}

.btn-primary:active {
  transform: translateY(1px);
  background: linear-gradient(180deg, #18181b 0%, #27272a 100%);
  box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.85);
}

/* Plated Toggle Button */
.btn-toggle {
  padding: 8px 14px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(180deg, rgba(32, 32, 36, 0.8) 0%, rgba(18, 18, 20, 0.8) 100%);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.1), 
    inset 0 -1px 0 rgba(0, 0, 0, 0.6), 
    0 2px 4px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-toggle:hover {
  color: var(--text-main);
  background: linear-gradient(180deg, rgba(46, 46, 52, 0.8) 0%, rgba(26, 26, 30, 0.8) 100%);
  transform: translateY(-1px);
}

.btn-toggle.active {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.3);
  background: linear-gradient(180deg, #52525b 0%, #27272a 100%);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.35), 
    inset 0 -1px 0 rgba(0, 0, 0, 0.6), 
    0 0 12px rgba(255, 255, 255, 0.12);
}

.sidebar {
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.panel {
  background: var(--glass-bg);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.45);
}

.panel-title {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.captured-container {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.captured-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  min-height: 24px;
}

.captured-label {
  color: var(--text-muted);
  width: 45px;
}

.captured-list {
  font-size: 1.1rem;
  letter-spacing: -2px;
}

.engine-info { gap: 8px; }

.stat-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.stat-row strong {
  color: var(--text-main);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.history-panel { flex: 1; }

.move-log {
  height: 150px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.85rem;
}

.move-log::-webkit-scrollbar { width: 4px; }
.move-log::-webkit-scrollbar-thumb { 
  background: rgba(255, 255, 255, 0.14); 
  border-radius: 2px; 
}

.log-entry {
  display: flex;
  justify-content: space-between;
  padding: 4px 8px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-sm);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.82);
  backdrop-filter: blur(10px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
}

.modal-overlay.hidden { display: none; }

.modal-content {
  background: rgba(14, 14, 16, 0.96);
  backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  padding: 24px;
  border-radius: var(--radius-lg);
  box-shadow: 0 25px 50px rgba(0, 0, 0, 0.75);
  width: 100%;
  max-width: 420px;
}

.settings-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

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

/* Plated Close Button */
.close-btn {
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(180deg, rgba(38, 38, 42, 0.8) 0%, rgba(20, 20, 22, 0.8) 100%);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 1.1rem;
  cursor: pointer;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1), inset 0 -1px 0 rgba(0, 0, 0, 0.5);
  transition: all 0.15s ease;
}

.close-btn:hover { 
  color: var(--text-main); 
  border-color: rgba(255, 255, 255, 0.25);
  background: linear-gradient(180deg, rgba(52, 52, 58, 0.8) 0%, rgba(28, 28, 32, 0.8) 100%);
  transform: translateY(-1px);
}

.settings-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.setting-item.vertical {
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  color: var(--text-muted);
}

.slider-label strong {
  color: var(--text-main);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

input[type="range"] {
  accent-color: var(--text-muted);
  cursor: pointer;
}

input[type="checkbox"] {
  width: 18px;
  height: 18px;
  accent-color: var(--text-muted);
  cursor: pointer;
}

.divider {
  border: none;
  border-top: 1px solid var(--glass-border);
  margin: 4px 0;
}

/* Plated Promotion Option Buttons */
.promotion-options {
  display: flex;
  gap: 12px;
  margin-top: 16px;
}

.promotion-options button {
  flex: 1;
  padding: 12px;
  font-size: 1.2rem;
  color: var(--text-main);
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius-sm);
  cursor: pointer;
  background: linear-gradient(180deg, rgba(38, 38, 42, 0.9) 0%, rgba(20, 20, 22, 0.9) 100%);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.15), 
    inset 0 -1px 0 rgba(0, 0, 0, 0.7), 
    0 3px 6px rgba(0, 0, 0, 0.4);
  transition: all 0.15s ease;
}

.promotion-options button:hover { 
  background: linear-gradient(180deg, #52525b 0%, #27272a 100%);
  border-color: rgba(255, 255, 255, 0.3);
  box-shadow: 
    inset 0 1px 0 rgba(255, 255, 255, 0.35), 
    inset 0 -1px 0 rgba(0, 0, 0, 0.7), 
    0 4px 12px rgba(0, 0, 0, 0.5);
  transform: translateY(-1px);
}

.loading-container { width: 100%; margin: 4px 0; }
.loading-bar {
  width: 100%;
  height: 4px;
  background-color: rgba(255, 255, 255, 0.06);
  border-radius: 2px;
  overflow: hidden;
}

.loading-bar-fill {
  width: 0%;
  height: 100%;
  background-color: var(--text-main);
  transition: width 0.1s linear;
}

.hidden { display: none !important; }

@media (max-width: 800px) {
  .app-layout { flex-direction: column; align-items: center; }
  .sidebar { width: 100%; max-width: 480px; }
}