:root {
  --bg: #1d1a16;
  --panel: #2a2621;
  --panel-2: #353029;
  --line: #463f36;
  --text: #f3ece0;
  --muted: #a89c8a;
  --accent: #e0a458;
  --accent-ink: #2a1c08;
  --good: #7cc48a;
  --bad: #e2725b;
  --blue: #6fa8ff;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  -webkit-user-select: none; user-select: none;
}
#app {
  max-width: 560px; margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 24px);
  min-height: 100dvh;
  display: flex; flex-direction: column; gap: 14px;
}

h1, h2, h3 { margin: 0; font-weight: 650; letter-spacing: -0.01em; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; }
p { margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.grow { flex: 1; }
.center { text-align: center; }
.hidden { display: none !important; }

.topbar { display: flex; align-items: center; gap: 10px; min-height: 40px; }
.topbar h2 { flex: 1; }
.back {
  appearance: none; border: 0; background: var(--panel); color: var(--text);
  width: 40px; height: 40px; border-radius: 50%; font-size: 20px; cursor: pointer;
}

.card {
  background: var(--panel); border-radius: var(--radius); padding: 16px;
  display: flex; flex-direction: column; gap: 10px;
}
.card.tap { cursor: pointer; }
.card.tap:active { background: var(--panel-2); }

button.btn, a.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 13px 16px;
  font: inherit; font-weight: 600; color: var(--text); background: var(--panel-2);
  cursor: pointer; text-align: center; text-decoration: none; display: inline-flex;
  align-items: center; justify-content: center; gap: 8px; min-height: 48px;
}
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { color: var(--bad); }
.btn.big { min-height: 58px; font-size: 18px; border-radius: 14px; }
.btn[disabled] { opacity: 0.4; pointer-events: none; }
.btns { display: flex; gap: 8px; }
.btns > * { flex: 1; }

input[type=text], input[type=number], select {
  font: inherit; color: var(--text); background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; width: 100%; -webkit-user-select: text; user-select: text;
}

.seg { display: flex; background: var(--panel-2); border-radius: 12px; padding: 4px; gap: 4px; }
.seg button {
  flex: 1; appearance: none; border: 0; background: transparent; color: var(--muted);
  font: inherit; font-weight: 600; padding: 10px; border-radius: 9px; cursor: pointer;
}
.seg button.on { background: var(--panel); color: var(--text); box-shadow: 0 1px 4px #0006; }

/* ---------- board ---------- */
.board-wrap { position: relative; width: 100%; aspect-ratio: 1; touch-action: manipulation; }
.board-wrap svg { width: 100%; height: 100%; display: block; border-radius: 10px; box-shadow: 0 10px 30px #0008; }
.board-wrap.shake { animation: shake 0.3s; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }

/* ---------- play ---------- */
.players { display: flex; gap: 8px; }
.player {
  flex: 1; display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  border-radius: 14px; background: var(--panel); border: 2px solid transparent; transition: border-color .2s;
}
.player.turn { border-color: var(--accent); }
.player .name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player .caps { color: var(--muted); font-size: 13px; }
.dot { width: 22px; height: 22px; border-radius: 50%; flex: none; }
.dot.b { background: radial-gradient(circle at 35% 30%, #666, #111 70%); }
.dot.w { background: radial-gradient(circle at 35% 30%, #fff, #cfc8bd 75%); }
.status-line { text-align: center; color: var(--muted); min-height: 22px; font-size: 15px; }

/* ---------- review ---------- */
.graph { width: 100%; height: 110px; background: var(--panel); border-radius: 12px; display: block; touch-action: none; }
.nav { display: flex; gap: 6px; }
.nav button { flex: 1; min-height: 44px; padding: 8px; font-size: 18px; }
.nav button.line { flex: 2.2; font-size: 16px; white-space: nowrap; }
input[type=range] { width: 100%; accent-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  appearance: none; border: 0; font: inherit; font-size: 14px; font-weight: 600;
  padding: 6px 10px; border-radius: 999px; background: var(--panel-2); color: var(--text); cursor: pointer;
}
.chip.bad { background: #e2725b2a; color: #ffb3a3; }
.chip.on { outline: 2px solid var(--accent); }
.loss { color: var(--bad); font-weight: 700; }
.gain { color: var(--good); font-weight: 700; }
.progress { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s; }

/* ---------- puzzles ---------- */
.feedback { min-height: 48px; font-size: 17px; text-align: center; display: flex; align-items: center; justify-content: center; }
.feedback.good { color: var(--good); }
.feedback.bad { color: var(--bad); }
.pill { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 99px; background: var(--panel-2); color: var(--muted); }
.pill.good { color: var(--good); }
.pill.retry { color: var(--accent); }

.stat { display: flex; flex-direction: column; align-items: center; flex: 1; padding: 6px 0; }
.stat b { font-size: 26px; }
.stat span { font-size: 12px; color: var(--muted); }

.list-item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.list-item:last-child { border-bottom: 0; }

.sheet-bg { position: fixed; inset: 0; background: #0009; display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet {
  background: var(--panel); width: 100%; max-width: 560px; border-radius: 20px 20px 0 0;
  padding: 20px 16px calc(var(--safe-bottom) + 20px); display: flex; flex-direction: column; gap: 10px;
}

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 24px); transform: translate(-50%, 20px);
  background: #000d; color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 600;
  opacity: 0; transition: all .25s; pointer-events: none; z-index: 20; max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.brand { display: flex; align-items: center; gap: 10px; }
.brand .stones { display: flex; }
.brand .stones .dot { width: 26px; height: 26px; }
.brand .stones .dot + .dot { margin-left: -8px; }
