:root {
  --bg-dark: #12141c;
  --bg-card: #1a1e29;
  --bg-card-hover: #222838;
  --accent: #d4af37;
  --accent-glow: rgba(212, 175, 55, 0.3);
  --text-main: #f0f2f5;
  --text-muted: #94a3b8;
  --border-color: #2a3245;
  
  --board-light: #f0d9b5;
  --board-dark: #b58863;
  --square-select: rgba(20, 85, 30, 0.6);
  --square-highlight: rgba(212, 175, 55, 0.45);
  --square-last: rgba(255, 255, 0, 0.35);
  --square-check: rgba(239, 68, 68, 0.65);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: 'Inter', sans-serif;
  user-select: none;
}

body {
  background-color: var(--bg-dark);
  color: var(--text-main);
  min-height: 100vh;
  overflow-x: hidden;
  display: flex;
  justify-content: center;
  align-items: center;
}

#game-container {
  width: 100%;
  max-width: 1280px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.ui-screen {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
  width: 100%;
}

.ui-screen.hidden {
  display: none !important;
}

/* START SCREEN */
.menu-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 520px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.5);
  text-align: center;
  animation: fadeIn 0.4s ease;
}

.crown-icon {
  font-size: 56px;
  color: var(--accent);
  margin-bottom: 12px;
  text-shadow: 0 0 20px var(--accent-glow);
}

.menu-card h1 {
  font-family: 'Cinzel', serif;
  font-size: 32px;
  font-weight: 900;
  letter-spacing: 2px;
  margin-bottom: 8px;
  color: #fff;
}

.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 32px;
  line-height: 1.5;
}

.menu-section {
  margin-bottom: 24px;
  text-align: left;
}

.menu-section label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 8px;
}

.btn-group {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 8px;
}

.select-btn {
  background: var(--bg-dark);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.select-btn:hover {
  border-color: var(--accent);
  color: var(--text-main);
}

.select-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #12141c;
  box-shadow: 0 0 15px var(--accent-glow);
}

.primary-btn {
  width: 100%;
  background: linear-gradient(135deg, #d4af37, #b89728);
  color: #12141c;
  border: none;
  padding: 14px;
  border-radius: 10px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
  margin-top: 12px;
}

.primary-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(212, 175, 55, 0.5);
}

.secondary-btn {
  background: var(--bg-dark);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 14px 24px;
  border-radius: 10px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

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

/* GAME SCREEN */
#game-screen {
  flex-direction: column;
  justify-content: flex-start;
  padding: 16px 24px;
  max-width: 1400px;
  margin: 0 auto;
}

.game-header {
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border-color);
  margin-bottom: 20px;
}

.game-header .brand {
  font-family: 'Cinzel', serif;
  font-size: 22px;
  font-weight: 700;
  color: var(--accent);
}

.controls-toolbar {
  display: flex;
  gap: 10px;
}

.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  color: var(--text-main);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  border-color: var(--accent);
}

.main-layout {
  display: grid;
  grid-template-columns: 320px minmax(400px, 600px) 300px;
  gap: 24px;
  align-items: center;
  justify-content: center;
  width: 100%;
  flex: 1;
}

@media(max-width: 1100px) {
  .main-layout {
    grid-template-columns: minmax(360px, 520px);
    grid-template-rows: auto auto auto auto;
    justify-items: center;
    overflow-y: auto;
    padding-bottom: 40px;
  }
}

/* PLAYER PANELS */
.player-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 14px 18px;
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  transition: border-color 0.3s;
}

.player-panel.active-turn {
  border-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
}

.player-avatar {
  font-size: 32px;
  width: 48px;
  height: 48px;
  background: var(--bg-dark);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.player-meta {
  flex: 1;
  min-width: 0;
}

.player-name {
  font-weight: 600;
  font-size: 15px;
  display: block;
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.captured-pieces {
  font-size: 14px;
  color: var(--text-muted);
  letter-spacing: 2px;
  min-height: 20px;
}

.player-timer {
  font-family: monospace;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-dark);
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--border-color);
}

.player-panel.active-turn .player-timer {
  color: var(--accent);
  border-color: var(--accent);
}

/* BOARD ARENA */
.board-arena {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.board-container {
  position: relative;
  width: 100%;
  max-width: 540px;
  aspect-ratio: 1;
  background: var(--bg-card);
  border-radius: 12px;
  padding: 24px;
  box-shadow: 0 15px 35px rgba(0,0,0,0.4);
  border: 1px solid var(--border-color);
}

#chess-board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  grid-template-rows: repeat(8, 1fr);
  width: 100%;
  height: 100%;
  border: 3px solid #2d3748;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.square {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 44px;
  transition: background-color 0.15s;
}

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

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

.square.selected {
  background-color: var(--square-select) !important;
}

.square.highlight::after {
  content: '';
  position: absolute;
  width: 22px;
  height: 22px;
  background: var(--square-highlight);
  border-radius: 50%;
}

.square.highlight.capture::after {
  width: 100%;
  height: 100%;
  background: transparent;
  border: 4px solid rgba(239, 68, 68, 0.75);
  border-radius: 50%;
}

.square.last-move {
  background-color: var(--square-last) !important;
}

.square.in-check {
  background-color: var(--square-check) !important;
  box-shadow: inset 0 0 15px rgba(255,0,0,0.6);
}

.piece {
  width: 90%;
  height: 90%;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center;
  z-index: 2;
  filter: drop-shadow(0 3px 4px rgba(0,0,0,0.35));
  transition: transform 0.1s ease;
}

.piece:hover {
  transform: scale(1.05);
}

/* Coordinate labels */
.board-rank-labels, .board-file-labels {
  position: absolute;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 700;
  display: flex;
  pointer-events: none;
}
.board-rank-labels {
  flex-direction: column;
  justify-content: space-around;
  left: 8px;
  top: 24px;
  bottom: 24px;
  width: 12px;
  align-items: center;
}
.board-file-labels {
  justify-content: space-around;
  bottom: 8px;
  left: 24px;
  right: 24px;
  height: 12px;
}

/* HISTORY PANEL */
.history-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  height: 520px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

.panel-header h3 {
  font-size: 15px;
  font-weight: 700;
}

.badge {
  background: var(--bg-dark);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
}

.move-list-scroll {
  flex: 1;
  overflow-y: auto;
  font-family: monospace;
  font-size: 14px;
  padding-right: 4px;
}

.empty-history {
  color: var(--text-muted);
  text-align: center;
  font-family: 'Inter', sans-serif;
  font-size: 13px;
  margin-top: 40px;
}

.move-row {
  display: grid;
  grid-template-columns: 36px 1fr 1fr;
  padding: 4px 6px;
  border-radius: 4px;
  margin-bottom: 2px;
}

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

.move-num {
  color: var(--text-muted);
  font-weight: 600;
}

.move-item {
  padding: 2px 6px;
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-main);
  text-align: center;
}

.move-item:hover {
  background: var(--bg-card-hover);
  color: var(--accent);
}

/* EVALUATION BAR */
.eval-bar-container {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

.eval-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.eval-bar {
  width: 100%;
  height: 8px;
  background: #334155;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.eval-fill {
  height: 100%;
  background: #f8fafc;
  width: 50%;
  transition: width 0.4s ease;
}

/* MODALS */
.modal-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(18, 20, 28, 0.85);
  backdrop-filter: blur(4px);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  border-radius: 12px;
}

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

.promotion-box, .gameover-box {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 30px;
  border-radius: 16px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0,0,0,0.6);
  animation: scaleUp 0.3s ease;
  max-width: 400px;
  width: 90%;
}

.promotion-box h3 {
  margin-bottom: 20px;
  font-size: 18px;
}

.promo-options {
  display: flex;
  gap: 12px;
  justify-content: center;
}

.promo-piece-btn {
  background: var(--bg-dark);
  border: 2px solid var(--border-color);
  width: 64px;
  height: 64px;
  border-radius: 12px;
  font-size: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

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

.go-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.gameover-box h2 {
  font-family: 'Cinzel', serif;
  font-size: 26px;
  margin-bottom: 8px;
  color: var(--accent);
}

.gameover-box p {
  color: var(--text-muted);
  margin-bottom: 24px;
  font-size: 15px;
}

.go-buttons {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes scaleUp {
  from { opacity: 0; transform: scale(0.9); }
  to { opacity: 1; transform: scale(1); }
}
