:root {
  --wood-dark: #3a2417;
  --wood: #5a3a24;
  --wood-light: #7a5230;
  --panel: #241610;
  --panel-2: #2e1d14;
  --cream: #f5e6c8;
  --cream-dim: #cbb590;
  --gold: #d4a94e;
  --gold-bright: #f0c869;
  --black-piece: #1c1c1e;
  --white-piece: #f2ead8;
  --ok: #7bc47f;
  --danger: #e07a5f;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Georgia, 'Times New Roman', serif;
  background:
    radial-gradient(1200px 700px at 50% -10%, #4a2e1d 0%, transparent 60%),
    radial-gradient(900px 600px at 50% 120%, #2c1a10 0%, transparent 55%),
    var(--wood-dark);
  color: var(--cream);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
button { font-family: inherit; cursor: pointer; }

.app-header {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: 0.8rem 1.6rem;
  background: linear-gradient(180deg, #1d110a 0%, #241610 100%);
  border-bottom: 2px solid var(--gold);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 0.8rem; }
.brand-mark { width: 46px; height: 46px; color: var(--gold); flex: none; }
.app-header h1 { font-size: 1.45rem; margin: 0; letter-spacing: 0.04em; color: var(--gold-bright); }
.tagline { margin: 0; font-size: 0.78rem; color: #bfa87c; font-style: italic; }
.main-nav { display: flex; gap: 0.6rem; }
.nav-btn {
  background: transparent; color: var(--cream);
  border: 1px solid var(--gold); border-radius: 8px;
  padding: 0.45rem 1rem; font-size: 0.9rem; transition: all .15s;
}
.nav-btn:hover { background: var(--gold); color: #241610; }

main { flex: 1; display: flex; }
.screen { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 1.5rem; }
.hidden { display: none !important; }

/* ---------- menu ---------- */
.menu-card {
  max-width: 640px; width: 100%;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid #4a3222; border-radius: 18px;
  padding: 1.8rem 2rem; box-shadow: 0 24px 60px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.06);
}
.menu-card h2 { margin: 0 0 1rem; color: var(--gold-bright); letter-spacing: .03em; }
.menu-card h3 { margin: 1.1rem 0 .45rem; font-size: .85rem; text-transform: uppercase; letter-spacing: .12em; color: #bfa87c; }
.mode-row { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.mode-card {
  background: #312015; border: 2px solid #4a3222; border-radius: 14px;
  color: var(--cream); padding: 1rem .8rem; display: flex; flex-direction: column; align-items: center; gap: .3rem;
  transition: all .15s;
}
.mode-card:hover { border-color: var(--gold); transform: translateY(-2px); }
.mode-card.selected { border-color: var(--gold-bright); background: #3d2817; box-shadow: 0 0 0 3px rgba(212,169,78,.25); }
.mode-icon { font-size: 2rem; }
.mode-name { font-weight: bold; font-size: 1.05rem; }
.mode-desc { font-size: .75rem; color: #bfa87c; text-align: center; }
.option-block { margin-top: .5rem; }
.pill-row { display: flex; gap: .5rem; flex-wrap: wrap; }
.pill {
  flex: 1 1 120px; background: #312015; border: 2px solid #4a3222; border-radius: 12px;
  color: var(--cream); padding: .55rem .7rem; display: flex; flex-direction: column; align-items: center; gap: .1rem;
  transition: all .15s;
}
.pill:hover { border-color: var(--gold); }
.pill.selected { border-color: var(--gold-bright); background: #3d2817; box-shadow: 0 0 0 3px rgba(212,169,78,.25); }
.pill-sub { font-size: .68rem; color: #bfa87c; font-style: italic; text-align:center; }
.cta {
  display: block; width: 100%; margin-top: 1.4rem;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #241610; font-weight: bold; font-size: 1.1rem; letter-spacing: .05em;
  border: none; border-radius: 12px; padding: .8rem 1rem;
  box-shadow: 0 6px 18px rgba(212,169,78,.35); transition: all .15s;
}
.cta:hover { filter: brightness(1.08); transform: translateY(-1px); }
.menu-foot { margin: .9rem 0 0; font-size: .75rem; color: #a08b62; text-align: center; }

/* ---------- game ---------- */
.screen-game { padding: 1rem; }
.game-layout { display: flex; gap: 1.25rem; width: 100%; max-width: 1180px; margin: 0 auto; align-items: flex-start; }
.board-panel {
  flex: 1 1 auto; min-width: 0;
  background:
    radial-gradient(ellipse at center, #6e4a2c 0%, #54331f 75%, #462a1a 100%);
  border: 3px solid var(--gold); border-radius: 16px;
  padding: 1rem; box-shadow: 0 20px 50px rgba(0,0,0,.55), inset 0 0 60px rgba(0,0,0,.45);
}
#board { width: 100%; height: auto; display: block; }
.side-panel { flex: 0 0 320px; display: flex; flex-direction: column; gap: .8rem; }
.status-card, .score-card, .log-card {
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid #4a3222; border-radius: 12px; padding: .8rem 1rem;
}
.turn-line { display: flex; align-items: center; gap: .7rem; }
.turn-dot { width: 26px; height: 26px; border-radius: 50%; flex: none; border: 2px solid rgba(0,0,0,.5); box-shadow: 0 2px 5px rgba(0,0,0,.5); }
.turn-dot.black { background: radial-gradient(circle at 35% 35%, #55555c, #0d0d10); }
.turn-dot.white { background: radial-gradient(circle at 35% 35%, #ffffff, #cfc4a8); }
.turn-label { font-size: 1.05rem; font-weight: bold; color: var(--gold-bright); }
.phase-label { font-size: .75rem; text-transform: uppercase; letter-spacing: .14em; color: #bfa87c; }
.status-msg { margin-top: .55rem; min-height: 1.4em; font-size: .88rem; color: var(--cream); }
.status-msg.alert { color: var(--gold-bright); font-weight: bold; }
.player-row { display: flex; align-items: center; gap: .55rem; padding: .35rem .2rem; border-radius: 8px; }
.player-row.active { background: rgba(212,169,78,.12); outline: 1px solid rgba(212,169,78,.4); }
.player-chip { width: 18px; height: 18px; border-radius: 50%; border: 1px solid rgba(0,0,0,.6); }
.player-chip.black { background: radial-gradient(circle at 35% 35%, #55555c, #0d0d10); }
.player-chip.white { background: radial-gradient(circle at 35% 35%, #ffffff, #cfc4a8); }
.player-name { font-weight: bold; flex: 1; }
.player-men { font-size: .78rem; color: #bfa87c; min-width: 64px; text-align: right; }
.player-men.captured { color: #a08b62; min-width: 56px; }
.log-title { font-size: .75rem; text-transform: uppercase; letter-spacing: .14em; color: #bfa87c; margin-bottom: .3rem; }
.move-log {
  margin: 0; padding-left: 1.6rem; max-height: 190px; overflow-y: auto;
  font-size: .8rem; line-height: 1.5; color: #e8dcc0;
}
.action-row { display: flex; gap: .6rem; }
.ghost-btn {
  flex: 1; background: transparent; border: 1px solid #6b4d33; color: #d8c8a2;
  border-radius: 10px; padding: .5rem .8rem; font-size: .85rem; transition: all .15s;
}
.ghost-btn:hover { border-color: var(--gold); color: var(--gold-bright); }

/* board svg elements */
.board-line { stroke: #d9c49a; stroke-width: 7; stroke-linecap: round; opacity: .92; }
.board-inner-line { stroke: #d9c49a; }
.point { fill: transparent; stroke: transparent; cursor: pointer; }
.point-ring { fill: #4a2e1c; stroke: #d9c49a; stroke-width: 2.5; pointer-events: none; }
.point-hot { fill: rgba(240,200,105,.0); }
.dest-dot { fill: rgba(240,200,105,.75); stroke: #5a3a24; stroke-width: 2; pointer-events: none; }
.dest-dot.capture-hint { fill: rgba(224,122,95,.9); }
.piece { pointer-events: none; }
.piece circle.face { stroke-width: 3; }
.piece.black circle.face { fill: url(#gradBlack); stroke: #000; }
.piece.white circle.face { fill: url(#gradWhite); stroke: #8a7a58; }
.piece-selected circle.halo { stroke: var(--gold-bright); stroke-width: 4; fill: rgba(240,200,105,.22); }
.last-move-ring { stroke: rgba(240,200,105,.55); stroke-width: 3; fill: none; stroke-dasharray: 6 6; pointer-events: none; }
svg text.point-label { fill: rgba(245,230,200,.4); font-size: 13px; font-family: Georgia, serif; text-anchor: middle; pointer-events: none; }

/* game over overlay */
.game-over {
  position: fixed; inset: 0; background: rgba(10,5,2,.72);
  display: flex; align-items: center; justify-content: center; z-index: 20; backdrop-filter: blur(3px);
}
.game-over-card {
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 2px solid var(--gold); border-radius: 18px; padding: 2rem 2.4rem; text-align: center;
  box-shadow: 0 30px 80px rgba(0,0,0,.6); max-width: 420px;
}
.game-over-title { font-size: 1.9rem; color: var(--gold-bright); font-weight: bold; }
.game-over-reason { margin-top: .4rem; color: #e8dcc0; }
.game-over-saved { margin-top: .6rem; font-size: .75rem; color: #9db98a; font-style: italic; }
.game-over-saved.error { color: var(--danger); }
.game-over-actions { display: flex; gap: .7rem; margin-top: 1.3rem; }
.game-over-actions .cta { margin-top: 0; }

/* ---------- stats ---------- */
.stats-wrap { max-width: 1000px; width: 100%; }
.stats-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 1rem; }
.stats-head h2 { color: var(--gold-bright); margin: .2rem 0; }
.stats-head p { color: #bfa87c; font-size: .85rem; flex: 1 1 320px; margin: 0; }
#btn-refresh-stats { flex: 0 0 auto; }
.stats-summary { display: flex; gap: .8rem; margin: 1rem 0; flex-wrap: wrap; }
.stat-tile {
  background: linear-gradient(160deg, var(--panel-2), var(--panel)); border: 1px solid #4a3222;
  border-radius: 12px; padding: .7rem 1.2rem; min-width: 130px;
}
.stat-tile .num { font-size: 1.7rem; color: var(--gold-bright); font-weight: bold; }
.stat-tile .lbl { font-size: .7rem; text-transform: uppercase; letter-spacing: .12em; color: #bfa87c; }
.stats-tables { display: grid; grid-template-columns: 1.4fr 1fr; gap: .8rem; margin-bottom: .8rem; }
.stats-card {
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid #4a3222; border-radius: 12px; padding: .9rem 1rem; overflow-x: auto;
}
.stats-card h3 { margin: 0 0 .5rem; font-size: .85rem; text-transform: uppercase; letter-spacing: .12em; color: #bfa87c; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th, td { padding: .4rem .5rem; text-align: left; border-bottom: 1px solid #3a281c; white-space: nowrap; }
th { color: #bfa87c; font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; }
tr:last-child td { border-bottom: none; }
td.win { color: var(--ok); font-weight: bold; }
td.loss { color: var(--danger); font-weight: bold; }
td.draw { color: var(--gold); }

.app-footer { text-align: center; font-size: .72rem; color: #7a6844; padding: .6rem; border-top: 1px solid #2e2015; }

@media (max-width: 900px) {
  .game-layout { flex-direction: column; align-items: stretch; }
  .side-panel { flex: 1 1 auto; }
  .stats-tables { grid-template-columns: 1fr; }
  .app-header { padding: .6rem .8rem; }
  .tagline { display: none; }
}
