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

:root {
  --bg:       #070C18;
  --surface:  #0D1525;
  --card:     #111D30;
  --elevated: #172540;
  --hover:    #1E3050;
  --border:       rgba(255,255,255,0.055);
  --border-gold:  rgba(201,164,60,0.22);
  --border-hover: rgba(255,255,255,0.12);

  --gold:     #C9A43C;
  --gold-lt:  #E2C060;
  --gold-dim: rgba(201,164,60,0.13);
  --gold-glow: rgba(201,164,60,0.08);

  --text-0: #EDE5D0;
  --text-1: #8A8070;
  --text-2: #4A4438;

  --board-l: #F0D9B5;
  --board-d: #B58863;

  --hl-move:  rgba(235,195,60,0.38);
  --hl-legal: rgba(46,180,110,0.38);
  --hl-check: rgba(210,50,50,0.52);

  --success: #2E9E6A;
  --danger:  #C44040;
  --info:    #4A90D9;

  --r-sm: 8px;
  --r-md: 12px;
  --r-lg: 18px;
}

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text-0);
  min-height: 100vh;
  overflow-x: hidden;
  line-height: 1.5;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse 60% 50% at 10% 70%, rgba(201,164,60,0.045) 0%, transparent 100%),
    radial-gradient(ellipse 50% 40% at 90% 15%, rgba(74,144,217,0.045) 0%, transparent 100%);
  pointer-events: none;
  z-index: 0;
}

.page {
  position: relative;
  z-index: 1;
  max-width: 980px;
  margin: 0 auto;
  padding: 2.25rem 1.5rem 3rem;
}

/* Header */
header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  padding-bottom: 1.5rem;
  margin-bottom: 1.75rem;
  border-bottom: 0.5px solid var(--border-gold);
}

.header-left h1 {
  font-family: 'Cormorant Garamond', serif;
  font-size: 2.6rem;
  font-weight: 300;
  letter-spacing: 0.015em;
  line-height: 1;
  color: var(--text-0);
}

.header-left h1 em {
  font-style: italic;
  color: var(--gold);
}

.header-left .byline {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-1);
  margin-top: 6px;
}

.conn-badge {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: var(--text-1);
  padding: 5px 12px;
  border: 0.5px solid var(--border);
  border-radius: 99px;
  transition: all 0.3s;
  white-space: nowrap;
}

.conn-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--text-2);
  transition: background 0.4s, box-shadow 0.4s;
}

.conn-badge.online  { color: var(--text-0); border-color: rgba(46,158,106,0.28); }
.conn-badge.online  .conn-dot { background: var(--success); box-shadow: 0 0 7px var(--success); }
.conn-badge.offline { color: var(--text-1); border-color: rgba(196,64,64,0.25); }
.conn-badge.offline .conn-dot { background: var(--danger); }

/* Main grid */
.main-grid {
  display: grid;
  grid-template-columns: 1fr 292px;
  gap: 22px;
  align-items: start;
}

@media (max-width: 700px) {
  .main-grid { grid-template-columns: 1fr; }
  .panel { order: -1; }
  header { flex-direction: column; align-items: flex-start; gap: 12px; }
  .header-left h1 { font-size: 2rem; }
}

/* Board area */
.board-wrap { position: relative; }

.board-frame {
  position: relative;
  background: var(--card);
  border: 0.5px solid var(--border-gold);
  border-radius: var(--r-lg);
  padding: 1.125rem;
  box-shadow:
    0 0 0 1px rgba(201,164,60,0.04),
    0 0 50px var(--gold-glow),
    0 24px 64px rgba(0,0,0,0.55);
  transition: box-shadow 0.5s, border-color 0.5s;
  overflow: hidden;
}

.board-frame.thinking {
  border-color: rgba(201,164,60,0.45);
  box-shadow:
    0 0 0 1px rgba(201,164,60,0.1),
    0 0 70px rgba(201,164,60,0.14),
    0 24px 64px rgba(0,0,0,0.55);
}

#board { width: 100%; }

.board-b72b1 { border-radius: var(--r-sm) !important; overflow: hidden; }

.square-55d63 { position: relative; }
.highlight-last  { background: var(--hl-move)  !important; }
.highlight-legal { background: var(--hl-legal) !important; }
.highlight-check { background: var(--hl-check) !important; }
.square-55d63.highlight-selected { box-shadow: inset 0 0 0 3px var(--gold); }

.square-55d63.highlight-legal::after {
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%,-50%);
  width: 30%; aspect-ratio: 1;
  background: rgba(30,190,110,0.75);
  border-radius: 50%;
  pointer-events: none;
  z-index: 2;
}

.board-controls {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 11px;
}

.ghost-btn {
  font-family: 'DM Sans', sans-serif;
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-1);
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: 99px;
  padding: 5px 14px;
  cursor: pointer;
  transition: all 0.2s;
}
.ghost-btn:hover { color: var(--text-0); border-color: var(--border-hover); }

/* Thinking overlay */
.board-overlay {
  display: none;
  position: absolute;
  inset: 0;
  border-radius: var(--r-lg);
  background: rgba(7,12,24,0.68);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 13px;
  z-index: 10;
  backdrop-filter: blur(3px);
}
.board-overlay.active { display: flex; animation: fadeIn 0.25s ease; }

.spin-ring {
  width: 46px; height: 46px;
  border: 2px solid var(--gold-dim);
  border-top-color: var(--gold);
  border-radius: 50%;
  animation: spin 0.85s linear infinite;
}

.thinking-lbl {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--gold);
}

/* Game over overlay */
.go-overlay {
  display: none;
  position: absolute;
  inset: 0;
  border-radius: var(--r-lg);
  background: rgba(7,12,24,0.84);
  align-items: center;
  justify-content: center;
  z-index: 20;
  backdrop-filter: blur(5px);
}
.go-overlay.active { display: flex; animation: fadeIn 0.4s ease; }

.go-card { text-align: center; padding: 2rem; }

.go-result {
  font-family: 'Cormorant Garamond', serif;
  font-size: 3rem;
  font-weight: 300;
  font-style: italic;
  color: var(--gold);
  line-height: 1;
  margin-bottom: 6px;
}

.go-detail {
  font-size: 0.825rem;
  color: var(--text-1);
  letter-spacing: 0.06em;
  margin-bottom: 1.5rem;
}

.go-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
}

/* Panel */
.panel {
  display: flex;
  flex-direction: column;
  gap: 13px;
}

.card {
  background: var(--card);
  border: 0.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 1rem 1.125rem;
}

.card-label {
  font-size: 0.67rem;
  font-weight: 500;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-2);
  margin-bottom: 0.875rem;
}

/* Players */
.player-row {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 7px;
}

.piece-glyph {
  width: 24px; height: 24px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  flex-shrink: 0;
}
.piece-glyph.w { background: var(--board-l); box-shadow: 0 0 0 1.5px rgba(0,0,0,0.25); }
.piece-glyph.b { background: #1a120a;         box-shadow: 0 0 0 1.5px rgba(255,255,255,0.08); }

.player-label { font-size: 0.75rem; color: var(--text-1); min-width: 36px; }

select {
  flex: 1;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  padding: 6px 28px 6px 9px;
  border: 0.5px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--elevated);
  color: var(--text-0);
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='9' height='5'%3E%3Cpath d='M0 0l4.5 5L9 0z' fill='%238A8070'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 9px center;
  transition: border-color 0.2s, background-color 0.2s;
}
select:focus { outline: none; border-color: var(--gold); background-color: var(--hover); }
select option { background: var(--card); color: var(--text-0); }

.vs-strip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 5px 0 6px;
  font-size: 0.65rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-2);
}
.vs-strip::before, .vs-strip::after {
  content: ''; flex: 1;
  height: 0.5px;
  background: var(--border);
}

/* Sliders */
.slider-group { margin-top: 10px; }

.slider-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 5px;
}
.slider-header label { font-size: 0.75rem; color: var(--text-1); }
.slider-val { font-size: 0.75rem; color: var(--gold); font-weight: 500; }

input[type=range] {
  width: 100%;
  accent-color: var(--gold);
  cursor: pointer;
}

input[type=checkbox] {
  accent-color: var(--gold);
  cursor: pointer;
}

.slider-hints {
  display: flex;
  justify-content: space-between;
  font-size: 0.65rem;
  color: var(--text-2);
  margin-top: 2px;
}

/* Buttons */
.btn-gold {
  width: 100%;
  padding: 9px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.825rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  border: none;
  border-radius: var(--r-sm);
  background: var(--gold);
  color: #06090F;
  cursor: pointer;
  margin-top: 13px;
  transition: background 0.2s, transform 0.1s;
}
.btn-gold:hover  { background: var(--gold-lt); }
.btn-gold:active { transform: scale(0.98); }

.action-inline {
  width: auto;
  display: inline-block;
  padding: 9px 32px;
  margin: 0 auto;
}

.btn-ghost {
  width: 100%;
  padding: 8px;
  font-family: 'DM Sans', sans-serif;
  font-size: 0.8rem;
  color: var(--text-1);
  background: transparent;
  border: 0.5px solid var(--border);
  border-radius: var(--r-sm);
  cursor: pointer;
  margin-top: 6px;
  transition: all 0.2s;
}
.btn-ghost:hover { color: var(--text-0); border-color: var(--border-hover); }

/* Status */
.status-inner {
  background: var(--surface);
  border-radius: var(--r-sm);
  padding: 0.75rem 0.875rem;
  display: flex;
  align-items: center;
  gap: 11px;
  min-height: 54px;
}

.turn-glyph {
  font-size: 22px;
  line-height: 1;
  flex-shrink: 0;
  transition: all 0.3s;
}
.turn-glyph.pulse { animation: pulse 1.1s ease-in-out infinite; }

.status-txt  { font-size: 0.825rem; color: var(--text-0); line-height: 1.3; }
.status-sub  { font-size: 0.72rem;  color: var(--text-1); margin-top: 2px; }

/* Move history */
.history-scroll {
  max-height: 220px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--elevated) transparent;
}
.history-scroll::-webkit-scrollbar { width: 3px; }
.history-scroll::-webkit-scrollbar-thumb { background: var(--elevated); border-radius: 3px; }

.move-pair {
  display: grid;
  grid-template-columns: 22px 1fr 1fr;
  gap: 4px;
  padding: 3.5px 0;
  border-bottom: 0.5px solid var(--border);
  font-size: 0.8125rem;
  animation: fadeUp 0.18s ease;
}
.move-pair:last-child { border-bottom: none; }
.mn { color: var(--text-2); font-size: 0.7rem; padding-top: 1px; }
.mw { color: var(--text-0); }
.mb { color: var(--text-1); }

.mw[data-ply], .mb[data-ply] {
  cursor: pointer;
  border-radius: 4px;
  padding: 0 4px;
  transition: background 0.15s, color 0.15s;
}
.mw[data-ply]:hover, .mb[data-ply]:hover { background: var(--hover); color: var(--text-0); }
.mw.active, .mb.active { background: var(--gold-dim); color: var(--gold-lt); }

.history-empty {
  font-size: 0.8rem;
  color: var(--text-2);
  text-align: center;
  padding: 1.25rem 0;
  font-style: italic;
}

/* Animations */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes fadeIn  { from { opacity: 0; } to { opacity: 1; } }
@keyframes fadeUp  { from { opacity:0; transform:translateY(5px); } to { opacity:1; transform:none; } }
@keyframes pulse   { 0%,100%{opacity:1} 50%{opacity:0.35} }
@keyframes slideIn { from{opacity:0;transform:translateX(16px)} to{opacity:1;transform:none} }
