:root {
  --bg: #12151b;
  --bg-2: #181d26;
  --panel: #1b212c;
  --panel-2: #222a37;
  --border: #2b3442;
  --border-soft: #242c38;
  --text: #ece6d9;
  --text-muted: #9aa4b2;
  --text-dim: #6b7482;
  --gold: #d4a24c;
  --gold-bright: #e8bd6a;
  --gold-dim: #8a6a34;
  --board-cream: #f5ecce;
  --board-cream-dark: #e6d49a;
  --board-ink: #2a231a;
  --wood: #2e2018;
  --wood-deep: #1c1410;
  --black-piece: #26262e;
  --white-piece: #f2ead8;
  --red: #e05b5b;
  --green: #6cc070;
  --radius: 14px;
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.45);
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --font-sans: "Avenir Next", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 18% 0%, rgba(212, 162, 76, 0.10), transparent 42%),
    radial-gradient(circle at 85% 100%, rgba(80, 100, 140, 0.16), transparent 45%),
    linear-gradient(180deg, #171b23 0%, #10131a 100%);
  color: var(--text);
  font-family: var(--font-sans);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }

/* ---------- header ---------- */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(18, 21, 27, 0.72);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(145deg, #2a2118, #17120d);
  border: 1px solid #3a2e20;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), 0 6px 14px rgba(0,0,0,0.4);
}
.brand h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-weight: 600;
  letter-spacing: 0.06em;
  font-size: 1.35rem;
  color: var(--text);
  text-transform: none;
}
.brand-tagline { margin: 0; color: var(--text-muted); font-size: 0.78rem; letter-spacing: 0.02em; }

.site-nav { display: flex; gap: 0.5rem; }

/* ---------- buttons ---------- */
.btn {
  border: 1px solid transparent;
  border-radius: 10px;
  padding: 0.55rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
  background: transparent;
  color: var(--text);
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; }
.btn-ghost {
  border-color: var(--border);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.07); border-color: #3a4556; }
.btn-gold {
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
  color: #2b1e0a;
  box-shadow: 0 4px 14px rgba(212, 162, 76, 0.35), inset 0 1px 0 rgba(255,255,255,0.5);
}
.btn-gold:hover { box-shadow: 0 6px 18px rgba(212, 162, 76, 0.5), inset 0 1px 0 rgba(255,255,255,0.5); }
.btn-large { width: 100%; padding: 0.85rem 1.2rem; font-size: 1.02rem; }
.btn-small { padding: 0.35rem 0.7rem; font-size: 0.8rem; }

/* ---------- views ---------- */
main {
  flex: 1;
  width: 100%;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 2.5rem;
}
.view[hidden] { display: none !important; }

/* ---------- menu ---------- */
.menu-card {
  max-width: 560px;
  margin: 0 auto;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem 1.75rem 1.75rem;
}
.menu-card h2 { font-family: var(--font-serif); font-size: 2rem; margin: 0 0 0.25rem; }
.menu-card .muted { margin-top: 0; }
.choice-group { margin-top: 1.4rem; }
.choice-title {
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 0.55rem;
}
.choice-row { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.6rem; }
.choice-row.three { grid-template-columns: repeat(4, 1fr); }
.choice-card {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.8rem 0.9rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.02);
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.08s ease;
  min-height: 54px;
}
.choice-card:hover { border-color: #3f4b5f; background: rgba(255,255,255,0.045); }
.choice-card:has(input:checked) {
  border-color: var(--gold);
  background: rgba(212, 162, 76, 0.08);
  box-shadow: 0 0 0 1px rgba(212, 162, 76, 0.4), 0 8px 20px rgba(0,0,0,0.25);
}
.choice-card input { display: none; }
.choice-dot {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--gold-dim);
  flex-shrink: 0;
  position: relative;
  transition: box-shadow 0.15s ease, border-color 0.15s ease;
}
.choice-card:has(input:checked) .choice-dot {
  border-color: var(--gold);
  box-shadow: inset 0 0 0 3px rgba(212, 162, 76, 0.35);
}
.choice-dot.dot-black { border-color: #b8b0a2; }
.choice-dot.dot-white { border-color: #3c4452; }
.choice-card:has(input:checked) .choice-dot.dot-black { box-shadow: inset 0 0 0 3px rgba(244,238,226,0.85); }
.choice-card:has(input:checked) .choice-dot.dot-white { box-shadow: inset 0 0 0 3px rgba(38,38,46,0.9); border-color: var(--gold); }
.choice-body { display: flex; flex-direction: column; gap: 0.1rem; }
.choice-body strong { font-size: 0.95rem; }
.choice-body small { color: var(--text-muted); font-size: 0.75rem; }
.choice-card.mini { min-height: 48px; padding: 0.6rem 0.8rem; justify-content: center; }
.choice-card.mini .choice-body { align-items: center; }
.menu-foot { color: var(--text-dim); font-size: 0.8rem; margin-top: 1.4rem; text-align: center; }
#btn-start { margin-top: 1.6rem; }

/* ---------- difficulty cards ---------- */
.difficulty-card strong { font-size: 0.92rem; }
.difficulty-card small { display: block; font-size: 0.72rem; color: var(--text-muted); line-height: 1.35; }

/* ---------- game layout ---------- */
.game-layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr) 250px;
  gap: 1.1rem;
  align-items: start;
}
@media (max-width: 1080px) {
  .game-layout { grid-template-columns: 1fr; }
  .panel-left, .panel-right { order: 2; }
  .board-wrap { order: 1; }
}

.panel {
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.phase-card, .turn-card {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
}
.phase-label, .turn-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: 0.3rem;
}
.phase-value, .turn-value {
  font-family: var(--font-serif);
  font-size: 1.15rem;
  letter-spacing: 0.02em;
}
.turn-value.black { color: #d9d2c2; }
.turn-value.white { color: #d9d2c2; }
.phase-detail, .turn-detail { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.35rem; }

.counters { display: flex; flex-direction: column; gap: 0.4rem; }
.counter-row {
  display: flex; align-items: center; justify-content: space-between;
  font-size: 0.82rem;
  color: var(--text-muted);
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 0.45rem 0.65rem;
}
.counter-row strong { color: var(--text); font-variant-numeric: tabular-nums; }

.players-card { display: flex; flex-direction: column; gap: 0.6rem; }
.player-summary {
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 0.6rem 0.7rem;
}
.player-head {
  display: flex; align-items: center; gap: 0.45rem;
  font-weight: 700;
  font-size: 0.86rem;
  margin-bottom: 0.5rem;
}
.player-dot { width: 16px; height: 16px; border-radius: 50%; flex-shrink: 0; box-shadow: 0 2px 5px rgba(0,0,0,0.4), inset 0 -2px 3px rgba(0,0,0,0.35); }
.player-dot.dot-black { background: radial-gradient(circle at 38% 32%, #575770, #26262d 72%); }
.player-dot.dot-white { background: radial-gradient(circle at 38% 32%, #fffaf0, #e4dcc9 72%); }
.player-stats { display: flex; gap: 0.5rem; }
.stat-chip {
  flex: 1;
  display: flex; flex-direction: column; align-items: center; gap: 0.1rem;
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  padding: 0.4rem 0.3rem;
}
.stat-num { font-size: 1.05rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-label { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-dim); }

/* ---------- board ---------- */
.board-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
}
.board-frame {
  width: min(78vw, 560px);
  max-width: 100%;
  border-radius: 22px;
  padding: clamp(0.6rem, 2.4vw, 1.3rem);
  background:
    linear-gradient(160deg, #3b2b1c 0%, #2a1e13 40%, #1e150d 100%);
  border: 1px solid #453321;
  box-shadow:
    inset 0 2px 0 rgba(255, 220, 150, 0.12),
    inset 0 -3px 8px rgba(0,0,0,0.5),
    0 24px 60px rgba(0,0,0,0.6),
    0 4px 18px rgba(0,0,0,0.4);
  position: relative;
}
.board-frame::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 22px;
  pointer-events: none;
  box-shadow: inset 0 0 0 6px rgba(0,0,0,0.22);
}
#board {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 12px;
  background:
    radial-gradient(circle at 35% 28%, rgba(255,255,255,0.55), transparent 55%),
    linear-gradient(155deg, #f9f0d2 0%, #eeddB0 55%, #dcc27f 100%);
  background-color: var(--board-cream);
  box-shadow:
    inset 0 0 0 1px rgba(90, 60, 30, 0.4),
    inset 0 6px 26px rgba(120, 80, 30, 0.22);
  cursor: default;
  touch-action: manipulation;
}
#board .board-edge { stroke: var(--board-ink); stroke-width: 2.2; stroke-linecap: round; opacity: 0.88; }
#board .point-hole { fill: var(--board-ink); opacity: 0.55; }
#board .point-label { fill: rgba(60, 45, 25, 0.55); font-size: 8px; font-family: var(--font-sans); text-anchor: middle; font-weight: 600; pointer-events: none; }
#board .mill-line {
  stroke: var(--gold);
  stroke-width: 6;
  stroke-linecap: round;
  opacity: 0.34;
  filter: blur(1px);
  pointer-events: none;
}
#board .mill-line.white-mill { stroke: #2f2f38; opacity: 0.25; }
#board .piece {
  stroke-width: 1.4;
  transition: transform 0.18s ease, opacity 0.25s ease;
  cursor: pointer;
  filter: drop-shadow(0 3px 3px rgba(0,0,0,0.35));
}
#board .piece.black { fill: url(#pieceBlack); stroke: #0e0e12; }
#board .piece.white { fill: url(#pieceWhite); stroke: #a89e86; }
#board .piece.selected {
  stroke: var(--gold-bright);
  stroke-width: 3;
  filter: drop-shadow(0 0 9px rgba(212, 162, 76, 0.85));
}
#board .piece.removable { stroke: var(--red); stroke-width: 2.5; animation: pulse 1.1s ease-in-out infinite; }
#board .piece.landing-new { animation: landing 0.35s ease; }
#board @keyframes landing { from { transform: translate(-3px, -3px) scale(1.35); opacity: 0; } to { transform: none; opacity: 1; } }
#board .legal-dot {
  fill: #fff;
  opacity: 0.82;
  stroke: var(--board-ink);
  stroke-width: 1.4;
  cursor: pointer;
  animation: breathe 1.4s ease-in-out infinite;
}
#board @keyframes breathe { 0%, 100% { r: 7; opacity: 0.75; } 50% { r: 8.5; opacity: 0.95; } }
#board .remove-ring {
  fill: rgba(224, 91, 91, 0.16);
  stroke: var(--red);
  stroke-width: 2.5;
  cursor: pointer;
  animation: pulse 0.9s ease-in-out infinite;
  transform-origin: center;
}
#board @keyframes pulse { 0%, 100% { opacity: 0.45; } 50% { opacity: 1; } }
#board .flying-piece-ring {
  fill: none;
  stroke: var(--gold-bright);
  stroke-width: 2;
  stroke-dasharray: 5 4;
  animation: spin 14s linear infinite;
  pointer-events: none;
}
#board @keyframes spin { to { transform: rotate(360deg); } }
#board .dead-line { stroke: var(--red); stroke-width: 3; opacity: 0.6; pointer-events: none; }

.board-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  text-align: center;
  min-height: 1.4em;
  font-style: italic;
}
.board-hint.urgent { color: var(--gold-bright); font-style: normal; font-weight: 600; }

/* ---------- history ---------- */
.history-header { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.history-header h3 { margin: 0; font-family: var(--font-serif); font-size: 1.05rem; letter-spacing: 0.04em; }
.history {
  list-style: none;
  margin: 0;
  padding: 0;
  flex: 1;
  overflow-y: auto;
  max-height: 480px;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  padding-right: 0.25rem;
  scrollbar-width: thin;
}
.history::-webkit-scrollbar { width: 8px; }
.history::-webkit-scrollbar-thumb { background: #2e3746; border-radius: 8px; }
.history li {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  padding: 0.4rem 0.55rem;
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-soft);
  font-size: 0.82rem;
  animation: history-in 0.25s ease;
}
@keyframes history-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.history .history-turn {
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  min-width: 2ch;
  font-size: 0.72rem;
}
.history .history-player { font-weight: 700; min-width: 38px; font-size: 0.74rem; letter-spacing: 0.04em; }
.history .history-player.black { color: #d9d2c2; }
.history .history-player.white { color: #e8e2d2; }
.history .history-text { color: var(--text-muted); }
.history .history-text strong { color: var(--text); }

/* ---------- cards (howto/stats) ---------- */
.card {
  max-width: 900px;
  margin: 0 auto;
  background: linear-gradient(180deg, var(--panel), var(--bg-2));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}
.card h2 { font-family: var(--font-serif); font-size: 1.7rem; margin: 0 0 0.5rem; }
.card h3 { font-size: 0.95rem; letter-spacing: 0.06em; text-transform: uppercase; color: var(--gold); margin: 1.4rem 0 0.6rem; }
.howto-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 1rem; }
.howto-grid > div { background: rgba(255,255,255,0.02); border: 1px solid var(--border-soft); border-radius: 12px; padding: 0.85rem 1rem; }
.howto-grid h3 { margin-top: 0; color: var(--text-muted); }
.howto-grid p { color: var(--text-muted); font-size: 0.9rem; margin: 0.3rem 0; }
.howto-grid strong { color: var(--text); }

.stats-header { display: flex; align-items: center; justify-content: space-between; }
.stats-summary { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.6rem; margin: 1rem 0; }
.summary-tile {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--border-soft);
  border-radius: 12px;
  padding: 0.7rem 0.8rem;
  text-align: center;
}
.summary-tile .stat-num { font-size: 1.6rem; font-weight: 800; color: var(--gold-bright); }
.summary-tile .stat-label { margin-top: 0.15rem; }
.difficulty-row {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border-soft);
  border-radius: 10px;
  margin-bottom: 0.45rem;
  background: rgba(255,255,255,0.02);
}
.difficulty-row .diff-name { font-weight: 700; letter-spacing: 0.06em; text-transform: capitalize; min-width: 88px; }
.difficulty-row .diff-record { color: var(--text-muted); font-size: 0.85rem; min-width: 130px; }
.difficulty-row .diff-bar { flex: 1; height: 10px; border-radius: 5px; background: #242c38; overflow: hidden; display: flex; }
.difficulty-row .diff-bar > span { display: block; height: 100%; }
.diff-bar .win { background: var(--green); }
.diff-bar .loss { background: var(--red); opacity: 0.85; }
.diff-bar .draw { background: var(--gold-dim); }
.recent-list { display: flex; flex-direction: column; gap: 0.4rem; max-height: 420px; overflow-y: auto; }
.recent-game {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.35rem 0.8rem;
  padding: 0.55rem 0.7rem;
  border-radius: 10px;
  background: rgba(255,255,255,0.02);
  border: 1px solid var(--border-soft);
  font-size: 0.82rem;
}
.recent-game .rg-line { display: flex; justify-content: space-between; gap: 0.6rem; }
.recent-game .rg-mode { color: var(--text-muted); }
.recent-game .rg-result { font-weight: 700; }
.rg-tag { font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--gold); }

/* ---------- modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(8, 10, 14, 0.78);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  z-index: 100;
  padding: 1rem;
  animation: fade-in 0.25s ease;
}
.modal-backdrop[hidden] { display: none !important; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  max-width: 480px;
  width: 100%;
  background: linear-gradient(180deg, #232b38, #171d27);
  border: 1px solid #3a4556;
  border-radius: 18px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.6), inset 0 1px 0 rgba(255,255,255,0.07);
  padding: 2rem;
  text-align: center;
  animation: pop-in 0.32s cubic-bezier(0.2, 0.9, 0.3, 1.2);
}
@keyframes pop-in { from { transform: scale(0.86) translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-crown { font-size: 3rem; line-height: 1; margin-bottom: 0.5rem; }
.modal h2 { font-family: var(--font-serif); font-size: 1.9rem; margin: 0 0 0.35rem; }
.modal .muted { color: var(--text-muted); margin: 0 0 1rem; }
.gameover-stats { display: flex; justify-content: center; gap: 1.2rem; margin: 1.1rem 0 1.4rem; flex-wrap: wrap; }
.gameover-stats .stat-chip { min-width: 90px; }
.modal-actions { display: flex; gap: 0.55rem; justify-content: center; flex-wrap: wrap; }

/* ---------- footer ---------- */
.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-soft);
  color: var(--text-dim);
  font-size: 0.76rem;
}

.muted { color: var(--text-muted); }

@media (max-width: 700px) {
  .site-header { flex-direction: column; align-items: stretch; gap: 0.75rem; padding: 0.8rem 0.9rem; }
  .brand h1 { font-size: 1.15rem; }
  .site-nav { justify-content: center; }
  .site-nav .btn { flex: 1; }
  main { padding: 1rem 0.75rem 1.75rem; }
  .stats-summary { grid-template-columns: repeat(2, 1fr); }
  .howto-grid { grid-template-columns: 1fr; }
  .choice-row { grid-template-columns: 1fr; }
  .choice-row.three { grid-template-columns: repeat(2, 1fr); }
  .board-frame { width: min(94vw, 560px); }
  .site-footer { flex-direction: column; text-align: center; gap: 0.15rem; }
}
