/* Hoshi — phone first. One column, thumb-reachable controls, no hover-only affordance. */

:root {
  --bg: #12100e;
  --surface: #1b1815;
  --surface-2: #241f1a;
  --line: #3a332b;
  --ink: #f2ece3;
  --ink-dim: #a89c8b;
  --ink-faint: #6f6459;
  --wood: #c69a5f;
  --wood-line: #6b4c26;
  --accent: #6ea8ff;
  --good: #62c08a;
  --warn: #e0b64a;
  --bad: #e2705f;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* No top inset here — it belongs on the sticky bar. A sticky element sticks to the SCROLLPORT's
 * edge, not to its container's padding box, so padding on the body pushes the bar down only
 * while the page is unscrolled and then lets it slide under the status bar. Which is what the
 * first iPhone run showed: the title on top of the clock and the identity chip behind the
 * battery icon. */
body {
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

main {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 16px 48px;
  display: grid;
  gap: 16px;
}

/* ---------- bar ---------- */

.bar {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  /* The status-bar inset is reserved HERE, so the bar clears the clock at every scroll
     position. `black-translucent` puts the page under the status bar by design; this is the
     other half of that bargain. */
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
.bar h1 { margin: 0; font-size: 17px; letter-spacing: 0.02em; font-weight: 600; }

.identity {
  display: flex; align-items: center; gap: 7px;
  background: var(--surface); color: var(--ink-dim);
  border: 1px solid var(--line); border-radius: 999px;
  padding: 5px 11px; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  max-width: 62vw; overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
}
.identity__dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-faint); flex: none; }
.identity__dot[data-state="ok"] { background: var(--good); }
.identity__dot[data-state="warn"] { background: var(--warn); }
.identity__dot[data-state="bad"] { background: var(--bad); }

/* ---------- board ---------- */

.stage { display: grid; gap: 12px; padding-top: 16px; }

/* The board is above the viewport once you scroll to the move controls, which makes it the
   browser's scroll anchor. Redrawing stones inside it must never move the page. `board.js`
   rebuilds only the stone layer for the same reason; this opts the region out of anchoring
   entirely. */
.board-host { width: 100%; overflow-anchor: none; }
.status, .scrub { overflow-anchor: none; }

.board { width: 100%; height: auto; display: block; touch-action: manipulation; }
.board--locked .board__hit { pointer-events: none; }

.board__wood { fill: var(--wood); }
.board__line { stroke: var(--wood-line); stroke-width: 0.022; }
.board__star { fill: var(--wood-line); }
.board__coord {
  fill: #7a5b31; font-size: 0.4px; text-anchor: middle;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.board__stone--black { fill: #16130f; }
.board__stone--white { fill: #f6f2ea; }
.board__stone { stroke: rgba(0,0,0,0.35); stroke-width: 0.012; }

.board__last { fill: none; stroke-width: 0.07; }
.board__last--on-black { stroke: #f6f2ea; }
.board__last--on-white { stroke: #16130f; }

.board__mark { fill: none; stroke-width: 0.09; }
.board__mark--bad { stroke: var(--bad); }
.board__mark--warn { stroke: var(--warn); }
.board__mark--good { stroke: var(--good); }
.board__mark-text {
  fill: var(--ink); font-size: 0.36px; text-anchor: middle; font-weight: 700;
  paint-order: stroke; stroke: rgba(0,0,0,0.55); stroke-width: 0.06;
}

.board__hit { fill: transparent; cursor: pointer; }

/* ---------- scoring overlay ---------- */

.board__stone--dead { opacity: 0.32; }
.board__dead-x { stroke-width: 0.075; stroke-linecap: round; fill: none; }
.board__dead-x--on-black { stroke: #f6f2ea; }
.board__dead-x--on-white { stroke: #16130f; }

.board__terr--black { fill: #16130f; opacity: 0.72; }
.board__terr--white { fill: #f6f2ea; opacity: 0.85; }

.score { display: grid; gap: 10px; }
.score__line { display: flex; align-items: baseline; gap: 10px; }
.score__result { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.score__breakdown { color: var(--ink-dim); font-size: 13px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.score__hint { color: var(--ink-dim); font-size: 13px; }
.score__check { font-size: 13px; }
.score__check[data-state="ok"] { color: var(--good); }
.score__check[data-state="warn"] { color: var(--warn); }
.score__check[data-state="bad"] { color: var(--bad); }
.score__check[data-state="none"] { color: var(--ink-faint); }
.score__actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* ---------- status + controls ---------- */

.status { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; min-height: 22px; }
.status__turn { font-weight: 600; }
.status__note { color: var(--ink-dim); font-size: 13px; text-align: right; }

.controls { display: grid; grid-template-columns: 1fr 1fr 1.4fr; gap: 8px; }

button, .file span {
  font: inherit; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 12px 14px;
  min-height: 46px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button:disabled { opacity: 0.42; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: #0d1420; font-weight: 650; }

.scrub {
  display: flex; align-items: center; gap: 6px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 6px;
}
.scrub button { padding: 8px 10px; min-height: 38px; background: transparent; border: 0; }
.scrub__jump { flex: 1; display: flex; align-items: center; justify-content: center; gap: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; color: var(--ink-dim); }
.scrub__jump input {
  width: 3.6em; text-align: right; font: inherit; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 8px; -moz-appearance: textfield;
}
.scrub__jump input::-webkit-outer-spin-button,
.scrub__jump input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.scrub-actions { display: grid; grid-template-columns: 1fr 1.4fr; gap: 8px; overflow-anchor: none; }
.scrub-actions button { font-size: 14px; }

/* ---------- panels ---------- */

.panel {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px;
}
.panel h2 { margin: 0 0 12px; font-size: 14px; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--ink-dim); font-weight: 600; }
.panel__meta { margin: -4px 0 12px; font-size: 12px; color: var(--ink-faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.row:last-child { margin-bottom: 0; }
.row__label { color: var(--ink-dim); font-size: 14px; min-width: 74px; }
.row__value { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.row__note { margin: -4px 0 12px; color: var(--ink-faint); font-size: 12px; line-height: 1.4; }
.row__note strong { color: var(--ink-dim); }

.file { position: relative; overflow: hidden; display: inline-block; }
.file input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; }
.file span { display: inline-block; }

progress { width: 100%; height: 6px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.seg button { border: 0; border-radius: 0; background: transparent; font-size: 13px; padding: 10px 12px; }
.seg button[aria-pressed="true"] { background: var(--surface-2); color: var(--ink); font-weight: 600; }

/* ---------- review ---------- */

.graph { width: 100%; margin-bottom: 12px; }
.graph svg { width: 100%; height: auto; display: block; }
.graph__zero { stroke: var(--line); stroke-width: 1; }
.graph__area { fill: color-mix(in srgb, var(--accent) 18%, transparent); }
.graph__line { fill: none; stroke: var(--accent); stroke-width: 2; stroke-linejoin: round; }
.graph__moment { fill: var(--warn); }
.graph__hit { fill: transparent; cursor: pointer; }

.moments { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.moments li { display: flex; align-items: baseline; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; cursor: pointer; }
.moments__rank { color: var(--warn); font-weight: 700; font-variant-numeric: tabular-nums; }
.moments__move { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.moments__delta { margin-left: auto; color: var(--ink-dim); font-size: 13px;
  font-variant-numeric: tabular-nums; }

/* ---------- history ---------- */

.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.history__row {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px;
}
.history__row[data-current="true"] { border-color: var(--accent); }
/* Depth is shown by indent, because a branch of a branch of a branch has to stay legible. */
.history__row[data-depth="1"] { margin-left: 14px; }
.history__row[data-depth="2"] { margin-left: 28px; }
.history__row[data-depth="3"] { margin-left: 42px; }
.history__row[data-depth="4"] { margin-left: 56px; }

.history__main { flex: 1; min-width: 0; display: grid; gap: 2px; cursor: pointer; }
.history__title { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history__title em { font-style: normal; color: var(--accent); }
.history__meta { color: var(--ink-dim); font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.history__now { color: var(--accent); font-size: 11px; letter-spacing: 0.06em; }
.history__btn {
  flex: none; min-height: 34px; padding: 6px 10px; font-size: 12px;
  background: transparent; border: 1px solid var(--line); border-radius: 8px;
}

/* ---------- lessons ---------- */

.lesson-intro { margin: 0 0 12px; color: var(--ink-dim); font-size: 14px; line-height: 1.5; }

.lesson-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px;
  counter-reset: lesson; }
.lesson-card { display: flex; align-items: center; gap: 12px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 12px 14px; cursor: pointer; }
.lesson-card__tick { width: 22px; height: 22px; flex: none; border-radius: 50%;
  border: 1px solid var(--line); display: grid; place-items: center;
  font-size: 12px; color: var(--bg); }
.lesson-card__tick[data-done="true"] { background: var(--good); border-color: var(--good); }
.lesson-card__text { display: grid; gap: 2px; }
.lesson-card__text small { color: var(--ink-dim); font-size: 12px; }

.lesson-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.lesson-head h2 { margin: 0; font-size: 17px; font-weight: 650; }

.lesson-prompt { margin: 0; font-size: 15px; line-height: 1.5; }
.lesson-feedback { margin: 0; min-height: 44px; font-size: 14px; line-height: 1.5; }
.lesson-feedback[data-tone="yes"] { color: var(--good); }
.lesson-feedback[data-tone="no"] { color: var(--warn); }

a.identity { text-decoration: none; }
.linkbtn { display: inline-block; text-decoration: none; color: var(--ink);
  background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; min-height: 46px; }

.details summary { color: var(--ink-dim); font-size: 13px; cursor: pointer; margin-top: 4px; }
.diag { font-size: 11px; color: var(--ink-faint); white-space: pre-wrap; word-break: break-all;
  margin: 10px 0 0; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

/* ---------- toast ---------- */

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(20px + env(safe-area-inset-bottom));
  background: var(--surface-2); border: 1px solid var(--line); color: var(--ink);
  padding: 11px 16px; border-radius: 999px; font-size: 14px; z-index: 20;
  max-width: min(92vw, 480px); text-align: center;
}
.toast[data-tone="bad"] { border-color: var(--bad); color: #ffd9d2; }
