/* ============================================================
   DESIGN SYSTEM — The Grand Study
   ============================================================ */
:root {
  --bg-deep: #0a0704;
  --bg-primary: #0f0b08;
  --bg-card: #1a130d;
  --bg-card-hover: #231a12;
  --bg-elevated: #2a1f15;
  --border: #3d3020;
  --border-light: #4a3a28;
  --text-primary: #e8dcc8;
  --text-secondary: #a89878;
  --text-muted: #6a5a42;
  --gold: #c89b3c;
  --gold-light: #ddb04a;
  --gold-pale: #f0d78c;
  --gold-glow: rgba(200,155,60,.12);
  --gold-glow-strong: rgba(200,155,60,.25);
  --burgundy: #7d2e2e;
  --burgundy-light: #a04040;
  --cream: #e8dcc8;
  --green-win: #5cb87a;
  --sq-light: #d4c4a0;
  --sq-dark: #6b4e2e;
  --sq-dark-hover: #7d5c38;
  --checker-light: #f0e4cc;
  --checker-light-stroke: #c8b89a;
  --checker-dark: #2a2235;
  --checker-dark-stroke: #3d3350;
  --highlight-move: rgba(200,155,60,.4);
  --highlight-capture: rgba(168,50,50,.45);
  --highlight-selected: rgba(200,155,60,.6);
  --font-display: 'Cinzel', Georgia, serif;
  --font-body: 'DM Sans', -apple-system, sans-serif;
  --radius: 10px;
  --radius-lg: 16px;
  --shadow: 0 8px 40px rgba(0,0,0,.6);
  --shadow-gold: 0 0 50px rgba(200,155,60,.08);
}

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

body {
  font-family: var(--font-body);
  background: var(--bg-deep);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex; flex-direction: column; align-items: center;
  overflow-x: hidden;
}

body::before {
  content: '';
  position: fixed; inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 512 512' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.035'/%3E%3C/svg%3E");
  pointer-events: none; z-index: 0;
}

body::after {
  content: '';
  position: fixed; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, transparent 0%, var(--gold) 20%, var(--gold-pale) 50%, var(--gold) 80%, transparent 100%);
  z-index: 100;
}

/* ============================================================
   LAYOUT
   ============================================================ */
.page {
  position: relative; z-index: 1;
  display: flex; flex-direction: column; align-items: center;
  width: 100%; max-width: 560px;
  padding: 0 1rem 2rem;
}

/* ============================================================
   BACK LINK
   ============================================================ */
.back-link {
  align-self: center;
  margin-top: 1.5rem;
  display: inline-flex; align-items: center; gap: .4rem;
  color: var(--text-muted);
  text-decoration: none;
  font-size: .8rem; font-weight: 500;
  letter-spacing: .04em;
  transition: color .25s;
}
.back-link:hover { color: var(--gold); }

/* ============================================================
   HEADER
   ============================================================ */
header { text-align: center; padding: 1.5rem 0 .5rem; width: 100%; }

.ornament { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 1rem; }
.ornament-line { width: 50px; height: 1px; background: linear-gradient(90deg, transparent, var(--gold), transparent); }
.ornament-diamond { width: 7px; height: 7px; background: var(--gold); transform: rotate(45deg); flex-shrink: 0; }

h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.6rem, 5vw, 2.2rem);
  letter-spacing: .05em;
  background: linear-gradient(135deg, var(--gold) 0%, var(--gold-pale) 40%, var(--gold) 70%, var(--gold-light) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.subtitle { color: var(--text-muted); font-size: .78rem; letter-spacing: .16em; text-transform: uppercase; margin-top: .3rem; font-weight: 500; }

/* ============================================================
   STATUS BAR
   ============================================================ */
.status-bar {
  width: 100%;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .7rem 1.1rem;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
  box-shadow: var(--shadow);
  transition: border-color .35s, box-shadow .35s;
  margin: 1rem 0;
}
.status-bar.game-over { border-color: var(--gold); box-shadow: var(--shadow), var(--shadow-gold); }
.status-icon { width: 9px; height: 9px; border-radius: 50%; background: var(--green-win); flex-shrink: 0; animation: pulse 2s infinite; }
.status-bar.game-over .status-icon { background: var(--burgundy-light); animation: none; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.35} }

#statusText { flex: 1; font-size: .88rem; font-weight: 500; }

.turn-badge { font-size: .72rem; font-weight: 600; padding: .25rem .65rem; border-radius: 6px; background: var(--bg-elevated); border: 1px solid var(--border); color: var(--text-secondary); letter-spacing: .05em; white-space: nowrap; }

/* ============================================================
   BOARD FRAME
   ============================================================ */
.board-frame {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px;
  box-shadow: var(--shadow), var(--shadow-gold);
  position: relative;
}
.board-frame::before, .board-frame::after {
  content: ''; position: absolute; width: 20px; height: 20px;
  border-color: var(--gold); border-style: solid; opacity: .3;
}
.board-frame::before { top: 5px; left: 5px; border-width: 2px 0 0 2px; border-radius: 3px 0 0 0; }
.board-frame::after  { bottom: 5px; right: 5px; border-width: 0 2px 2px 0; border-radius: 0 0 3px 0; }

/* ============================================================
   BOARD GRID — 8x8
   ============================================================ */
.board {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  width: min(420px, 85vw);
  height: min(420px, 85vw);
  border-radius: 6px;
  overflow: hidden;
}

.sq {
  aspect-ratio: 1;
  display: flex; align-items: center; justify-content: center;
  position: relative;
  user-select: none;
}

.sq.light { background: var(--sq-light); }
.sq.dark  { background: var(--sq-dark); cursor: pointer; }
.sq.dark:hover { background: var(--sq-dark-hover); }

.sq.selected       { background: var(--highlight-selected) !important; }
.sq.move-target    { background: var(--highlight-move) !important; cursor: pointer; }
.sq.capture-target { background: var(--highlight-capture) !important; cursor: pointer; }
.sq.must-move      { box-shadow: inset 0 0 0 3px var(--gold); }

/* ============================================================
   PIECES
   ============================================================ */
.piece {
  width: 78%; height: 78%;
  border-radius: 50%;
  position: relative;
  transition: transform .15s;
  cursor: grab;
  z-index: 2;
}
.piece:hover { transform: scale(1.08); }
.piece:active { cursor: grabbing; }

.piece.light-piece {
  background: radial-gradient(circle at 35% 35%, #fff, var(--checker-light) 60%, var(--checker-light-stroke));
  border: 2px solid var(--checker-light-stroke);
  box-shadow: 0 3px 8px rgba(0,0,0,.35), inset 0 1px 4px rgba(255,255,255,.3);
}

.piece.dark-piece {
  background: radial-gradient(circle at 35% 35%, #4a3f55, var(--checker-dark) 60%, var(--checker-dark-stroke));
  border: 2px solid var(--checker-dark-stroke);
  box-shadow: 0 3px 8px rgba(0,0,0,.4), inset 0 1px 3px rgba(100,80,120,.3);
}

/* King crown */
.piece.king::after {
  content: '♛';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  font-size: clamp(14px, 3vw, 20px);
  line-height: 1;
  text-shadow: 0 1px 3px rgba(0,0,0,.4);
}
.piece.light-piece.king::after { color: var(--gold); }
.piece.dark-piece.king::after  { color: var(--gold-pale); }

/* Piece animations */
@keyframes piecePlace {
  from { transform: scale(0); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
.piece.placed { animation: piecePlace .25s cubic-bezier(.34,1.56,.64,1) both; }

@keyframes kingPromote {
  0%   { transform: scale(1); }
  50%  { transform: scale(1.3); }
  100% { transform: scale(1); }
}
.piece.just-kinged { animation: kingPromote .5s ease-out; }

/* ============================================================
   DRAG & DROP
   ============================================================ */
.piece.dragging {
  opacity: 0.3;
  pointer-events: none;
}

.drag-ghost {
  position: fixed;
  pointer-events: none;
  z-index: 9999;
  border-radius: 50%;
  transform: translate(-50%, -50%) scale(1.12);
  box-shadow: 0 8px 24px rgba(0,0,0,.5) !important;
  transition: none !important;
}

/* ============================================================
   MOVE INDICATORS
   ============================================================ */
.move-dot {
  position: absolute;
  width: 22%; height: 22%;
  border-radius: 50%;
  background: var(--gold);
  opacity: .45;
  pointer-events: none;
  z-index: 1;
}

.capture-ring {
  position: absolute;
  width: 65%; height: 65%;
  border-radius: 50%;
  border: 3px solid var(--burgundy-light);
  opacity: .6;
  pointer-events: none;
  z-index: 1;
}

/* ============================================================
   CONTROLS
   ============================================================ */
.controls {
  display: flex; flex-wrap: wrap; gap: .5rem;
  width: 100%; justify-content: center;
  margin-top: 1rem;
}

.btn {
  font-family: var(--font-body);
  font-size: .8rem; font-weight: 600;
  padding: .6rem 1.1rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg-card); color: var(--text-primary);
  cursor: pointer; transition: all .2s;
  display: flex; align-items: center; gap: .35rem;
  letter-spacing: .02em;
}
.btn:hover { background: var(--bg-card-hover); border-color: var(--gold); color: var(--gold-light); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }
.btn:disabled { opacity: .35; cursor: default; transform: none; }
.btn-primary { background: linear-gradient(135deg, var(--gold), var(--gold-light)); color: var(--bg-deep); border-color: var(--gold); }
.btn-primary:hover { color: var(--bg-deep); box-shadow: 0 4px 16px var(--gold-glow); }
.btn-danger { border-color: var(--burgundy); color: var(--burgundy-light); }
.btn-danger:hover { background: rgba(125,46,46,.1); color: #c05050; }

/* ============================================================
   SCOREBOARD
   ============================================================ */
.scoreboard {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .75rem 1.2rem;
  margin-top: 1rem;
  box-shadow: var(--shadow);
}
.score-side { display: flex; flex-direction: column; align-items: center; gap: .1rem; }
.score-label { font-size: .58rem; text-transform: uppercase; letter-spacing: .14em; color: var(--text-muted); font-weight: 600; }
.score-main { font-family: var(--font-display); font-size: 1.4rem; font-weight: 700; color: var(--gold); line-height: 1; }
.score-sub { font-size: .65rem; color: var(--text-muted); }
.score-divider { width: 1px; height: 40px; background: var(--border); margin: 0 1rem; }
.score-center { text-align: center; }

/* ============================================================
   THINKING INDICATOR
   ============================================================ */
.thinking { display: none; align-items: center; gap: .4rem; color: var(--text-secondary); font-size: .8rem; margin-top: .5rem; }
.thinking.active { display: flex; }
.thinking-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--gold); display: inline-block;
  animation: dotB .6s infinite alternate;
}
.thinking-dots span:nth-child(2) { animation-delay: .15s; }
.thinking-dots span:nth-child(3) { animation-delay: .3s; }
@keyframes dotB { to { opacity:.2; transform:translateY(-3px); } }

/* ============================================================
   COLOR DIALOG
   ============================================================ */
.overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.78);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; transition: opacity .3s;
}
.overlay.hidden  { display: none; opacity: 0; }
.overlay.visible { opacity: 1; }

.dialog {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2rem 1.8rem;
  text-align: center;
  box-shadow: var(--shadow);
  max-width: 340px; width: 90%;
}
.dialog h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.3rem; margin-bottom: .4rem; }
.dialog p  { color: var(--text-secondary); font-size: .85rem; margin-bottom: 1.2rem; }

.color-options { display: flex; gap: .8rem; justify-content: center; margin-bottom: 1.4rem; }
.color-btn {
  width: 72px; height: 72px; border-radius: 12px;
  border: 2px solid var(--border); cursor: pointer;
  transition: all .25s;
  display: flex; align-items: center; justify-content: center;
  flex-direction: column; gap: .25rem;
  font-size: .68rem; font-weight: 600; color: var(--text-secondary);
  background: var(--bg-card-hover);
}
.color-btn:hover { border-color: var(--gold); transform: scale(1.08); box-shadow: 0 0 18px var(--gold-glow); }
.color-btn .swatch { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255,255,255,.12); }

.dialog-label { font-size: .6rem; text-transform: uppercase; letter-spacing: .14em; color: var(--text-muted); font-weight: 600; margin-bottom: .5rem; }

.difficulty-row {
  display: flex; gap: 0;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.diff-btn {
  flex: 1;
  font-family: var(--font-body);
  font-size: .72rem; font-weight: 600;
  padding: .45rem .4rem;
  border: none; background: transparent;
  color: var(--text-muted);
  cursor: pointer; transition: all .2s;
}
.diff-btn + .diff-btn { border-left: 1px solid var(--border); }
.diff-btn.active { background: var(--bg-card); color: var(--gold); }
.diff-btn:hover:not(.active) { color: var(--text-secondary); }

/* ============================================================
   FOOTER
   ============================================================ */
footer { margin-top: 1.5rem; text-align: center; color: var(--text-muted); font-size: .7rem; }

/* ============================================================
   ENTRANCE ANIMATIONS
   ============================================================ */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}
header       { animation: fadeUp .7s ease-out both; }
.status-bar  { animation: fadeUp .7s ease-out .1s both; }
.board-frame { animation: fadeUp .7s ease-out .2s both; }
.controls    { animation: fadeUp .6s ease-out .3s both; }
.scoreboard  { animation: fadeUp .6s ease-out .35s both; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 420px) {
  .board-frame { padding: 10px; }
  .btn { font-size: .75rem; padding: .5rem .85rem; }
}
