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

:root {
  --bg: #1a1a2e;
  --surface: #16213e;
  --surface2: #0f3460;
  --accent: #e94560;
  --text: #eee;
  --text-muted: #999;
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --highlight: rgba(233, 69, 96, 0.5);
  --radius: 8px;
}

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

/* === Header === */
#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  background: var(--surface);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  height: 48px;
}

#app-header h1 {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 1px;
}

#btn-settings {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius);
  transition: background 0.2s;
}
#btn-settings:hover { background: rgba(255,255,255,0.1); }

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

#btn-lang {
  background: none;
  border: 1px solid rgba(255,255,255,0.15);
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  padding: 4px 10px;
  border-radius: var(--radius);
  transition: background 0.2s;
}
#btn-lang:hover { background: rgba(255,255,255,0.1); }

/* === Main Layout === */
#app-main {
  display: flex;
  height: calc(100vh - 48px);
}

/* Side Panels */
#panel-left, #panel-right {
  width: 240px;
  min-width: 200px;
  background: var(--surface);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,0.05);
}
#panel-right {
  border-right: none;
  border-left: 1px solid rgba(255,255,255,0.05);
}

#panel-left h2, #panel-right h2 {
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* Move History */
#move-history {
  flex: 1;
  overflow-y: auto;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.8;
}

.move-row {
  display: flex;
  gap: 8px;
  padding: 2px 6px;
  border-radius: 4px;
}
.move-row:hover { background: rgba(255,255,255,0.05); }
.move-number { color: var(--text-muted); min-width: 28px; }
.move-white, .move-black {
  cursor: pointer;
  padding: 0 4px;
  border-radius: 3px;
}
.move-white:hover, .move-black:hover { background: var(--accent); }

/* Game Controls */
#game-controls {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

button {
  padding: 8px 14px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  background: var(--surface2);
  color: var(--text);
  cursor: pointer;
  font-size: 13px;
  transition: all 0.2s;
}
button:hover { background: var(--accent); border-color: var(--accent); }
button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  background: var(--surface2);
  border-color: rgba(255,255,255,0.08);
}

/* Captured Pieces */
.captured-row {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  font-size: 18px;
  min-height: 24px;
}

/* === Board Container === */
#board-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#board-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

#piece-hint {
  position: absolute;
  z-index: 10;
  background: rgba(0,0,0,0.82);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  padding: 10px 14px;
  max-width: 220px;
  pointer-events: none;
  font-size: 12px;
  line-height: 1.5;
}

#game-status {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(8px);
  padding: 8px 20px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
#game-status.visible { opacity: 1; }

/* === Selects === */
select {
  flex: 1;
  padding: 6px 8px;
  border-radius: var(--radius);
  border: 1px solid rgba(255,255,255,0.15);
  background: var(--surface2);
  color: var(--text);
  font-size: 13px;
}

/* === Computer Section === */
#computer-section {
  border-bottom: 1px solid rgba(255,255,255,0.06);
  padding-bottom: 14px;
}
#computer-mode-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
#computer-mode-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
#computer-mode-group input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}
#computer-color {
  flex: 1;
}
#engine-depth-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.hint-toggle {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
  margin-left: auto;
}
.hint-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}
#engine-depth-group label {
  font-size: 13px;
  color: var(--text-muted);
}

/* === AI Teaching Section === */
#ai-provider-select {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
#ai-provider-select label { font-size: 13px; color: var(--text-muted); }

/* === Piece Style Section === */
#style-section {
  border-top: 1px solid rgba(255,255,255,0.06);
  padding-top: 12px;
}
#piece-style { width: 100%; }

#piece-scale-group {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
#piece-scale-group label {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}
#piece-scale {
  flex: 1;
  accent-color: var(--accent);
}

#color-picker-group {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
}
.color-pick {
  display: flex;
  align-items: center;
  gap: 4px;
}
.color-pick label {
  font-size: 12px;
  color: var(--text-muted);
}
.color-pick input[type="color"] {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 4px;
  background: none;
  cursor: pointer;
}
.color-pick input[type="color"]::-webkit-color-swatch-wrapper { padding: 2px; }
.color-pick input[type="color"]::-webkit-color-swatch { border-radius: 2px; border: none; }
#btn-reset-colors {
  padding: 4px 8px;
  font-size: 11px;
  margin-left: auto;
}

#btn-get-suggestion {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  font-weight: 600;
}

#auto-suggest-group {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
}
#auto-suggest-group label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
#auto-suggest-group input[type="checkbox"] {
  accent-color: var(--accent);
  width: 15px;
  height: 15px;
  cursor: pointer;
}

/* Dragging cursor */
#board-canvas.dragging {
  cursor: grabbing;
}
#btn-get-suggestion:hover { filter: brightness(1.15); }

#ai-thinking {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 0;
  font-size: 13px;
  color: var(--text-muted);
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid rgba(255,255,255,0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* AI Suggestion Cards */
.suggestion-card {
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  padding: 10px;
  margin-top: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.suggestion-card:hover {
  border-color: var(--accent);
  background: rgba(233, 69, 96, 0.08);
}
.suggestion-move {
  font-weight: 700;
  font-size: 15px;
  margin-bottom: 4px;
}
.suggestion-eval {
  font-size: 12px;
  color: var(--accent);
  margin-bottom: 4px;
}
.suggestion-explanation {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.ai-thinking-text {
  margin-top: 8px;
  padding: 8px;
  background: rgba(255,255,255,0.03);
  border-radius: var(--radius);
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
  font-style: italic;
}

/* === Modals === */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
}

.modal-content {
  background: var(--surface);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  padding: 24px;
  min-width: 320px;
  max-width: 420px;
}

.modal-content h2 {
  margin-bottom: 16px;
  font-size: 16px;
}

.setting-group {
  margin-bottom: 12px;
}
.setting-group label {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
}
.setting-group input {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
}

.modal-actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}
.modal-actions button { flex: 1; }

/* Promotion Modal */
.promotion-choices { text-align: center; }
#promotion-buttons {
  display: flex;
  gap: 8px;
  justify-content: center;
}
#promotion-buttons button {
  font-size: 24px;
  padding: 12px 18px;
  min-width: 72px;
}

/* === Utilities === */
.hidden { display: none !important; }

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.25); }

/* === Responsive === */
@media (max-width: 900px) {
  #app-main { flex-direction: column; }
  #panel-left, #panel-right {
    width: 100%;
    min-width: unset;
    max-height: 30vh;
    flex-direction: row;
    flex-wrap: wrap;
    border: none;
    border-bottom: 1px solid rgba(255,255,255,0.05);
  }
  #board-container { min-height: 50vh; }
}
