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

:root {
  --wood-dark: #5c3d0a;
  --wood-mid: #8b6914;
  --wood-light: #c49a3c;
  --gold: #d4a537;
  --gold-bright: #fbbf24;
  --bg-dark: #1a1008;
  --bg-panel: #2a1e0e;
  --text: #e8dcc8;
  --text-dim: #a0917a;
  --marble-white: #f0eed8;
  --marble-black: #1c1c1c;
  --green: #22c55e;
  --red: #ef4444;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  overflow: hidden;
}

/* ── Setup Overlay ────────────────────────────────────────────── */
#setup-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10, 6, 2, 0.92);
  z-index: 100;
  backdrop-filter: blur(8px);
}

#setup-card {
  background:
    linear-gradient(135deg, rgba(180,130,60,0.08) 0%, transparent 60%),
    var(--bg-panel);
  border: 1px solid rgba(180,130,60,0.25);
  border-radius: 20px;
  padding: 3rem 2.5rem;
  width: 400px;
  max-width: 92vw;
  text-align: center;
  box-shadow:
    0 20px 60px rgba(0,0,0,0.6),
    0 0 0 1px rgba(255,255,255,0.03) inset;
}

#setup-card h1 {
  font-family: 'Playfair Display', serif;
  font-size: 2.8rem;
  font-weight: 700;
  color: var(--gold);
  letter-spacing: 0.05em;
  margin-bottom: 0.1rem;
}

.subtitle {
  font-size: 0.85rem;
  color: var(--text-dim);
  letter-spacing: 0.15em;
  text-transform: uppercase;
  margin-bottom: 2rem;
}

.setup-group {
  margin-bottom: 1.5rem;
  text-align: left;
}

.setup-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.6rem;
}

/* Color picker */
.color-pick {
  display: flex;
  gap: 0.75rem;
}

.color-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  padding: 0.8rem;
  background: rgba(255,255,255,0.04);
  border: 2px solid rgba(255,255,255,0.08);
  border-radius: 12px;
  color: var(--text);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.color-btn:hover { border-color: rgba(255,255,255,0.15); }
.color-btn.active {
  border-color: var(--gold);
  background: rgba(212,165,55,0.1);
  box-shadow: 0 0 16px rgba(212,165,55,0.15);
}

.marble-preview {
  display: inline-block;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  flex-shrink: 0;
}
.white-marble {
  background: radial-gradient(circle at 35% 30%, #fff 0%, #f0eed8 40%, #d4cfa8 75%, #b8b090 100%);
  box-shadow: 0 2px 6px rgba(0,0,0,0.4), inset 0 -1px 2px rgba(0,0,0,0.1);
}
.black-marble {
  background: radial-gradient(circle at 35% 30%, #555 0%, #2a2a2a 40%, #1a1a1a 75%, #0a0a0a 100%);
  box-shadow: 0 2px 6px rgba(0,0,0,0.5), inset 0 1px 2px rgba(255,255,255,0.05);
}

/* Select */
select {
  width: 100%;
  padding: 0.7rem 1rem;
  background: rgba(255,255,255,0.04);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 10px;
  font-size: 0.95rem;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23a0917a' stroke-width='2' fill='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 1rem center;
  transition: border-color 0.2s;
}
select:focus { border-color: var(--gold); }

/* Start button */
#start-btn {
  width: 100%;
  padding: 0.9rem;
  margin-top: 0.5rem;
  background: linear-gradient(135deg, var(--gold) 0%, #c49220 100%);
  color: #1a1008;
  border: none;
  border-radius: 12px;
  font-size: 1.1rem;
  font-weight: 700;
  font-family: inherit;
  letter-spacing: 0.03em;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 16px rgba(212,165,55,0.3);
}
#start-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px rgba(212,165,55,0.4);
}
#start-btn:active { transform: scale(0.98); }

/* ── Game Container ───────────────────────────────────────────── */
#game-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ── Top Bar ──────────────────────────────────────────────────── */
#top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1.5rem;
  background:
    linear-gradient(180deg, rgba(60,40,10,0.5) 0%, transparent 100%),
    var(--bg-panel);
  border-bottom: 1px solid rgba(180,130,60,0.15);
  flex-shrink: 0;
  min-height: 60px;
  gap: 1rem;
}

.player-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.4rem 0.8rem;
  border-radius: 10px;
  border: 2px solid transparent;
  transition: all 0.3s;
  min-width: 0;
}
.player-bar.active {
  border-color: var(--gold);
  background: rgba(212,165,55,0.08);
  box-shadow: 0 0 14px rgba(212,165,55,0.15);
}

.bar-marble { width: 22px; height: 22px; border-radius: 50%; flex-shrink: 0; }
.bar-name { font-weight: 700; font-size: 0.95rem; white-space: nowrap; }
.bar-pieces { font-size: 0.8rem; color: var(--text-dim); white-space: nowrap; }
.bar-pieces em { font-style: normal; color: var(--text); font-weight: 600; }
.bar-icon { font-size: 0.65rem; }

.bar-stats {
  font-size: 0.72rem;
  color: var(--text-dim);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

#center-info {
  flex: 1;
  text-align: center;
  min-width: 0;
}

#score-display {
  font-family: 'Playfair Display', serif;
  font-size: 0.85rem;
  color: var(--gold);
  font-weight: 700;
  min-height: 1.2em;
}

#status-box {
  font-size: 0.82rem;
  color: var(--text-dim);
  line-height: 1.3;
}

/* ── Board Area ───────────────────────────────────────────────── */
#board-area {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow: hidden;
  position: relative;
}

#board-frame {
  position: relative;
  max-width: min(80vh, 80vw, 700px);
  max-height: min(80vh, 80vw, 700px);
  width: 100%;
  aspect-ratio: 1;
}

#board {
  width: 100%;
  height: 100%;
  border-radius: 16px;
  box-shadow:
    0 0 0 4px rgba(90,60,15,0.6),
    0 0 0 8px rgba(50,30,5,0.4),
    0 12px 40px rgba(0,0,0,0.6),
    0 2px 8px rgba(0,0,0,0.4),
    inset 0 2px 0 rgba(255,255,255,0.05);
  cursor: default;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

/* ── SVG Board Elements ───────────────────────────────────────── */
.board-square {
  fill: none;
  stroke: #3a2208;
  stroke-width: 4;
  stroke-linejoin: round;
  opacity: 0.7;
}
.board-line {
  stroke: #3a2208;
  stroke-width: 4;
  stroke-linecap: round;
  opacity: 0.7;
}

/* Position dots (empty) */
.pos-dot {
  fill: rgba(40,25,8,0.5);
  stroke: rgba(60,40,12,0.4);
  stroke-width: 1.5;
  cursor: pointer;
  transition: fill 0.15s;
}
.pos-dot:hover { fill: rgba(60,40,12,0.7); }

/* Pieces */
.piece {
  cursor: grab;
  transition: filter 0.15s;
}
.piece:active { cursor: grabbing; }
.piece.dragging {
  cursor: grabbing;
  filter: drop-shadow(0 8px 16px rgba(0,0,0,0.7)) !important;
}

.piece-white {
  fill: url(#grad-white);
  filter: url(#piece-shadow);
}
.piece-black {
  fill: url(#grad-black);
  filter: url(#piece-shadow);
}

/* Marble veins overlay */
.piece-vein-white {
  fill: none;
  stroke: rgba(180,170,140,0.25);
  stroke-width: 0.5;
  pointer-events: none;
}
.piece-vein-black {
  fill: none;
  stroke: rgba(80,80,90,0.2);
  stroke-width: 0.5;
  pointer-events: none;
}

/* Highlights */
.pos-dot.valid-dest {
  fill: rgba(34,197,94,0.35) !important;
  stroke: #22c55e !important;
  stroke-width: 2.5 !important;
  filter: url(#glow-green);
}
.pos-dot.valid-src {
  stroke: #22c55e !important;
  stroke-width: 2.5 !important;
}

.piece.selected {
  filter: url(#glow-gold) !important;
}
.piece.removable {
  filter: url(#glow-red) !important;
  animation: pulse-red 0.6s ease-in-out infinite alternate;
  cursor: pointer;
}

@keyframes pulse-red {
  from { opacity: 1; }
  to   { opacity: 0.65; }
}

/* Position numbers */
.pos-num {
  fill: rgba(90,65,20,0.5);
  font-size: 11px;
  font-family: monospace;
  font-weight: 700;
  text-anchor: middle;
  dominant-baseline: central;
  pointer-events: none;
  user-select: none;
}

/* ── Piece Trays ──────────────────────────────────────────────── */
.piece-tray {
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
  align-items: center;
  flex-shrink: 0;
}
.tray-left { margin-right: 0.5rem; order: -1; }
.tray-right { margin-left: 0.5rem; order: 1; }

.tray-piece {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  transition: opacity 0.3s;
}
.tray-piece.white-marble { opacity: 0.7; }
.tray-piece.black-marble { opacity: 0.7; }
.tray-piece.used { opacity: 0.15; }

/* ── Bottom Bar ───────────────────────────────────────────────── */
#bottom-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 0.5rem 1.5rem;
  background: var(--bg-panel);
  border-top: 1px solid rgba(180,130,60,0.1);
  flex-shrink: 0;
}

.btn-secondary {
  padding: 0.5rem 1.2rem;
  background: rgba(255,255,255,0.06);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-secondary:hover {
  background: rgba(255,255,255,0.1);
  border-color: rgba(255,255,255,0.2);
}

.btn-icon {
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon:hover {
  background: rgba(255,255,255,0.1);
}
.btn-icon.muted { opacity: 0.4; }

/* ── Animations ───────────────────────────────────────────────── */
@keyframes piece-place {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}

.piece-enter {
  animation: piece-place 0.2s ease-out;
}

@keyframes piece-remove {
  from { transform: scale(1); opacity: 1; }
  to   { transform: scale(0); opacity: 0; }
}

/* ── Responsive ───────────────────────────────────────────────── */
@media (max-width: 600px) {
  #top-bar {
    flex-direction: column;
    padding: 0.4rem 0.8rem;
    gap: 0.3rem;
  }
  .player-bar { font-size: 0.8rem; }
  .bar-name { font-size: 0.82rem; }
  #board-frame {
    max-width: min(95vw, 75vh);
    max-height: min(95vw, 75vh);
  }
  #board-area {
    flex-direction: column;
    flex-wrap: nowrap;
    padding: 0.25rem;
    gap: 0.2rem;
  }
  .piece-tray {
    flex-direction: row;
    justify-content: center;
    gap: 6px;
    margin: 0;
  }
  .tray-left { order: -1; }
  .tray-right { order: 1; }
}

@media (max-height: 600px) {
  #top-bar { padding: 0.3rem 1rem; min-height: 44px; }
  #board-area { padding: 0.5rem; }
  #bottom-bar { padding: 0.3rem 1rem; }
  .piece-tray {
    flex-direction: row;
    justify-content: center;
    gap: 6px;
    margin: 0;
  }
}

@media (min-width: 1200px) and (min-height: 900px) {
  #board-frame { max-width: min(75vh, 700px); max-height: min(75vh, 700px); }
}
