/* Chinese Checkers, a warm maple star on paper; red, blue and green marbles. Fixed palette. */
:root {
  color-scheme: light;
  --bg: #f1eee7;
  --card: #fffdf8;
  --ink: #20232a;
  --muted: #747882;
  --line: #e0dbcf;
  --wood: #ead9b8;
  --wood-2: #e2cda6;
  --wood-edge: #c7ab7c;
  --pit: rgba(98, 72, 36, .34);
  --p0: #d4553f;
  --p0-hi: #f39a83;
  --p0-lo: #9e3322;
  --p1: #3a6db0;
  --p1-hi: #86b0e6;
  --p1-lo: #234a7e;
  --p2: #2f9467;
  --p2-hi: #7fd1a8;
  --p2-lo: #1c6443;
  --gold: #ffc94d;
  /* tutorial kit (tutorial.css) */
  --tut-accent: #ffc94d;
  --tut-accent-ink: #20232a;
  --tut-bubble: #fffdf8;
  --tut-ink: #20232a;
  --tut-muted: #747882;
  --tut-dim: rgba(34, 26, 16, .55);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  touch-action: manipulation;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- bar ---------- */
.app {
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh;
  max-width: 900px; margin: 0 auto;
  padding: env(safe-area-inset-top) max(14px, env(safe-area-inset-right)) env(safe-area-inset-bottom) max(14px, env(safe-area-inset-left));
}
.bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 60px; }
.back { color: var(--muted); text-decoration: none; font-size: 14px; white-space: nowrap; padding: 12px 2px; }
.back:hover, .back:focus-visible { color: var(--ink); }
.bar-actions { display: flex; gap: 8px; }

.btn {
  min-height: 44px; min-width: 44px; padding: 0 18px; border-radius: 22px;
  border: 0; background: var(--card); color: var(--ink);
  font-weight: 650; cursor: pointer; box-shadow: 0 1px 2px rgba(32, 35, 42, .1), 0 0 0 1px var(--line);
  transition: transform .12s, background .15s, opacity .15s;
}
.btn:active { transform: scale(.97); }
.btn.icon { padding: 0; width: 44px; font-size: 22px; line-height: 1; letter-spacing: .04em; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.primary { background: var(--ink); color: var(--card); box-shadow: none; }
.btn.wide { width: 100%; min-height: 50px; font-size: 17px; }
.btn:disabled, .row:disabled { opacity: .35; cursor: default; transform: none; }
.btn:focus-visible, .hole:focus-visible, .seg button:focus-visible, .row:focus-visible, .link:focus-visible {
  outline: 3px solid var(--gold); outline-offset: 2px;
}

/* ---------- game ---------- */
.game {
  flex: 1; min-height: 0;
  display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px; padding-bottom: 14px;
}
.turn {
  justify-self: center; display: inline-flex; align-items: center; gap: 10px;
  padding: 6px 16px; border-radius: 999px; background: var(--card);
  box-shadow: 0 0 0 1px var(--line); font-weight: 650; font-size: 16px; min-height: 40px;
}
.turn.thinking #turn-text::after { content: ''; display: inline-block; width: 1.1em; text-align: left; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
.toast {
  justify-self: center; min-height: 24px; font-size: 15px; color: var(--muted); text-align: center;
  opacity: 0; transform: translateY(4px); transition: opacity .25s, transform .25s;
}
.toast.show { opacity: 1; transform: none; }

.dot { display: inline-block; flex: none; width: 18px; height: 18px; border-radius: 50%; }
.dot.p0 { background: radial-gradient(circle at 35% 30%, var(--p0-hi), var(--p0) 55%, var(--p0-lo)); }
.dot.p1 { background: radial-gradient(circle at 35% 30%, var(--p1-hi), var(--p1) 55%, var(--p1-lo)); }
.dot.p2 { background: radial-gradient(circle at 35% 30%, var(--p2-hi), var(--p2) 55%, var(--p2-lo)); }
.dot.none { background: var(--line); }

/* ---------- board ---------- */
.board-wrap { min-height: 0; min-width: 0; display: flex; align-items: center; justify-content: center; }
.board { position: relative; width: min(100%, calc((100vh - 170px) * 15 / 17), 620px); aspect-ratio: 15 / 17; }
@supports (container-type: size) {
  .board-wrap { container-type: size; }
  .board { width: min(100cqw, 100cqh * 15 / 17, 620px); }
}
.art, .holes, .marbles { position: absolute; inset: 0; width: 100%; height: 100%; }
.art { overflow: visible; }
.marbles { pointer-events: none; }
.star { fill: var(--wood); stroke: var(--wood); stroke-width: .9; stroke-linejoin: round; }
.star-edge { fill: none; stroke: var(--wood-edge); stroke-width: .06; stroke-linejoin: round; }
.star-shade { fill: url(#woodgrad); }
.arm { stroke-width: .9; stroke-linejoin: round; }
.arm.p0 { fill: #e9c6a6; stroke: #e9c6a6; }       /* the wood tinted with each player's colour */
.arm.p1 { fill: #d3cdbb; stroke: #d3cdbb; }
.arm.p2 { fill: #d2d3b0; stroke: #d2d3b0; }
.pit { fill: var(--pit); }
.trail { fill: none; stroke: rgba(32, 35, 42, .45); stroke-width: .08; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: .16 .16; }
.trail-from { fill: none; stroke: rgba(32, 35, 42, .4); stroke-width: .07; }

.hole {
  position: absolute; border: 0; padding: 0; margin: 0; background: transparent; cursor: default;
  display: grid; place-items: center;
}
.hole.can, .hole.target { cursor: pointer; }
.hole.target::before {
  content: ''; width: 84%; aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle, #fffaf0 0 26%, #ffd060 32% 50%, rgba(255, 201, 77, .4) 58%, rgba(255, 201, 77, 0) 72%);
  animation: glow 1.1s ease-in-out infinite alternate;
}
.hole.target.far::before { background: radial-gradient(circle, #fffaf0 0 26%, #ffc23d 32% 52%, rgba(255, 190, 60, .45) 60%, rgba(255, 190, 60, 0) 74%); }
@keyframes glow { from { transform: scale(.9); opacity: .85; } to { transform: scale(1.08); opacity: 1; } }

.mb {
  position: absolute; border-radius: 50%;
  transition: left .17s cubic-bezier(.3, .1, .3, 1), top .17s cubic-bezier(.3, .1, .3, 1), transform .15s, box-shadow .15s;
  box-shadow: 0 .12em .14em rgba(40, 25, 5, .35);
}
.mb.p0 { background: radial-gradient(circle at 35% 30%, var(--p0-hi), var(--p0) 52%, var(--p0-lo)); }
.mb.p1 { background: radial-gradient(circle at 35% 30%, var(--p1-hi), var(--p1) 52%, var(--p1-lo)); }
.mb.p2 { background: radial-gradient(circle at 35% 30%, var(--p2-hi), var(--p2) 52%, var(--p2-lo)); }
.mb.can { box-shadow: 0 0 0 2px rgba(255, 253, 248, .85), 0 .12em .14em rgba(40, 25, 5, .35); }
.mb.sel { box-shadow: 0 0 0 3px var(--gold), 0 .3em .4em rgba(40, 25, 5, .35); transform: scale(1.14); z-index: 2; }
.mb.hop { z-index: 3; transform: scale(1.12); }
.mb.hot { box-shadow: 0 0 0 2.5px rgba(32, 35, 42, .55), 0 .12em .14em rgba(40, 25, 5, .35); }

/* ---------- overlays ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(32, 35, 42, .36);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 12px;
  animation: fade .2s ease-out;
}
.overlay.soft { background: rgba(241, 238, 231, .5); align-items: center; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.sheet, .card {
  background: var(--card); color: var(--ink);
  width: 100%; max-width: 440px; max-height: calc(100vh - 24px); max-height: calc(100dvh - 24px);
  overflow: auto; overscroll-behavior: contain;
  border-radius: 24px; padding: 8px 20px 20px;
  box-shadow: 0 20px 50px rgba(32, 35, 42, .22);
  animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(16px); opacity: .6; } to { transform: none; opacity: 1; } }
@media (min-width: 600px) { .overlay { align-items: center; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; min-height: 52px; }
.sheet-head h2 { margin: 0; font-size: 20px; }
.row {
  display: block; width: 100%; text-align: left; min-height: 50px; padding: 0 4px;
  border: 0; border-bottom: 1px solid var(--line); background: transparent; font-weight: 600; cursor: pointer;
}
.group { padding: 12px 0 4px; }
.label { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.seg { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: var(--bg); }
.seg button {
  flex: 1 1 0; min-height: 44px; border: 0; border-radius: 12px; background: transparent;
  font-weight: 600; cursor: pointer; color: var(--muted); transition: background .15s, color .15s;
}
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(32, 35, 42, .16); }
.note { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.menu-sheet .row:first-of-type { border-top: 1px solid var(--line); }
.menu-sheet #menu-help { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet .btn.wide { margin-top: 16px; }

.over-card { max-width: 340px; text-align: center; padding: 24px 22px 14px; }
.over-mark { display: flex; justify-content: center; gap: 8px; margin-bottom: 10px; }
.over-mark .dot { width: 46px; height: 46px; }
.over-title { font-size: 28px; font-weight: 800; }
.over-sub { color: var(--muted); margin: 4px 0 20px; }
.link { display: block; margin: 8px auto 0; min-height: 44px; padding: 0 16px; border: 0; background: transparent; color: var(--muted); cursor: pointer; }

.help-sheet { max-width: 560px; }
.help-body { padding-bottom: 6px; }
.help-body h3 { font-size: 16px; margin: 18px 0 4px; }
.help-body p, .help-body li { font-size: 15px; margin: 4px 0; }
.help-body ul { padding-left: 20px; }
.fine { font-size: 13px; color: var(--muted); margin-top: 14px; }

/* ---------- small and landscape screens ---------- */
@media (max-width: 380px) {
  .app { padding-left: max(8px, env(safe-area-inset-left)); padding-right: max(8px, env(safe-area-inset-right)); }
  .btn { padding: 0 14px; }
  .back { font-size: 13px; }
}
@media (min-aspect-ratio: 1/1) and (max-height: 480px) {
  .bar { min-height: 50px; }
  .game { gap: 4px; padding-bottom: 6px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-delay: 0ms !important; transition-duration: .01ms !important; }
}

/* Online play (online.js): no New game while a friend is playing; a presence line under the turn. */
body.is-online #btn-new { display: none; }
.top { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.net { color: var(--muted, #767a86); }
/* The online rows sit above How to play: they carry its divider (one line), and it joins them. */
.menu-sheet #menu-online, .menu-sheet #menu-leave { margin-top: 10px; border-top: 1px solid var(--line); }
.menu-sheet #menu-online + #menu-leave + #menu-help, .menu-sheet #menu-leave + #menu-help { margin-top: 0; border-top: 0; }
#over-leave { margin-top: 8px; }
