/* 色は :root の変数。珠と盤の色は data/support-levels.json から JS が --bead-light 等を入れる（コントラスト検査と同じ値） */
:root {
  --bg: #fbf7ef; --fg: #2b211b; --muted: #6b5d52; --card: #ffffff; --line: #e3d8c6;
  --primary: #2f5d8a; --primary-fg: #ffffff; --ok: #2e7d4f; --warn: #8a6d00; --ng: #a14a1d;
  --bead: var(--bead-light, #4a2c1d); --board: var(--board-light, #f4ecdc); --rod: #9b8a77; --beam: #6b5440;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120f; --fg: #f1e9df; --muted: #b9ab9d; --card: #201b17; --line: #3a322b;
    --primary: #7fb0e0; --primary-fg: #10161c; --ok: #7fd3a1; --warn: #e2c25a; --ng: #f0a27a;
    --bead: var(--bead-dark, #e9c49a); --board: var(--board-dark, #1d1a17); --rod: #6c5f53; --beam: #a88c6e;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* display:flex の部品でも hidden で必ず隠す（REV-R2-002） */
html { -webkit-text-size-adjust: 100%; }
/* 下へ引っぱって再読み込み・端の跳ね返りを止める（途中経過が消えないように・社長 2026-10-16） */
html, body { overscroll-behavior: none; }
/* 練習中・フラッシュ中はページ自体を動かさない */
html.lock-scroll, html.lock-scroll body { overflow: hidden; height: 100%; }
html.lock-scroll main { touch-action: none; }
/* 1画面に収まらない時も、2本指の拡大縮小（ピンチ）は止める。止めないと2本指で珠をはさんだ時にブラウザが操作を取り消す（社長 2026-10-16） */
main[data-screen="practice"], main[data-screen="flash"] { touch-action: pan-y; padding-bottom: 16px; }
/* Safari のタブでは下のツールバーが画面に重なるので、ボタンが隠れないよう余白を取る（ホーム画面のアプリでは不要） */
html.in-browser main[data-screen="practice"], html.in-browser main[data-screen="flash"] { padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
/* スライドを止めるのはそろばんと数字の枠の上だけ。収まらない時は式の欄などに触れて上下にスクロールできる */
.soroban, .flash-box { touch-action: none; }
main[data-screen="practice"] .bar { padding: 6px 0; }
main[data-screen="practice"] .bar h1 { font-size: 16px; line-height: 1.3; }
main[data-screen="practice"] .bar .back { min-height: 40px; padding: 4px 12px; white-space: nowrap; }
main[data-screen="practice"] .practice .hint { display: none; } /* 案内は最初の一言（msg）に出す */
.practice .top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.practice .top .msg { margin: 0; text-align: right; }
main[data-screen="practice"] .actions { margin-top: 8px; }
html.lock-scroll main button, html.lock-scroll main input, html.lock-scroll main select { touch-action: manipulation; }
body {
  margin: 0; background: var(--bg); color: var(--fg);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic UI", system-ui, sans-serif;
  font-size: 18px; line-height: 1.6; touch-action: manipulation;
}
main { max-width: 760px; margin: 0 auto; padding: 0 16px 96px; }
.bar { display: flex; align-items: center; gap: 12px; padding: 12px 0; }
.bar h1 { font-size: 20px; margin: 0; }
h2 { font-size: 18px; margin: 20px 0 8px; }
button, select, input {
  font: inherit; color: inherit; min-height: 48px; border-radius: 12px; border: 2px solid var(--line);
  background: var(--card); padding: 8px 16px;
}
button { cursor: pointer; }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
button.primary { background: var(--primary); color: var(--primary-fg); border-color: var(--primary); font-weight: 700; }
button.danger { border-color: var(--ng); color: var(--ng); }
button:disabled { opacity: .5; cursor: default; }
.back { min-width: 72px; }
.students { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }
.student { font-size: 20px; }
.students .empty { grid-column: 1 / -1; }
.new-student { margin-top: 12px; display: grid; gap: 8px; }
.note { color: var(--muted); font-size: 15px; }
.error { color: var(--ng); }
.empty { color: var(--muted); }
.guide, .reminder { background: var(--card); border: 2px dashed var(--line); border-radius: 12px; padding: 8px 14px; font-size: 15px; }
.guide h2 { margin-top: 4px; }
.links, .actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.actions button { flex: 1 1 140px; }
.stages { list-style: none; padding: 0; display: grid; gap: 8px; }
.stage { width: 100%; display: flex; justify-content: space-between; align-items: center; text-align: left; }
.stage .badge { font-size: 14px; color: var(--muted); }
.stage.is-cleared .badge { color: var(--ok); font-weight: 700; }
.flash-link { width: 100%; margin-top: 16px; }
.grades { margin-top: 16px; }
.grades .grade { margin: 4px 6px 4px 0; }
.practice .progress { color: var(--muted); margin: 0; }
.practice .hint { margin: 2px 0 8px; font-size: 15px; color: var(--muted); }
/* 式は縦（見取算の形・社長 2026-10-16）。右そろえで位をそろえる */
/* 式（左）とそろばん（右）を横に並べる。珠を大きくしても1画面に収まるように */
.practice-main { display: flex; gap: 10px; align-items: flex-start; justify-content: center; }
.practice-board { flex: 0 1 auto; min-width: 0; }
.practice-board .board { justify-content: flex-start; }
.soroban { flex: none; } /* 親の flex で縮められると当たり判定が 44px を割る */
@media (max-width: 339px) { .practice-main { flex-direction: column; align-items: center; } .numbers { flex-direction: row; gap: 0 12px; } }
.numbers { list-style: none; padding: 4px 10px; margin: 4px 0 0; flex: 0 0 auto; width: max-content; min-width: 3.4em; display: flex; flex-direction: column; align-items: stretch; gap: 0;
  font-size: 30px; line-height: 1.25; font-variant-numeric: tabular-nums; font-weight: 700; border: 2px solid var(--line); border-radius: 12px; background: var(--card); }
.numbers li { text-align: right; color: var(--muted); padding: 0 4px; white-space: pre; }
.numbers li.current { color: var(--fg); background: var(--bg); box-shadow: inset 5px 0 0 var(--primary); border-radius: 6px; }
.numbers li.done { opacity: .45; }
[data-mode="answer"] .numbers li { color: var(--fg); }
.msg { min-height: 1.6em; margin: 4px 0; font-weight: 700; }
.msg[data-kind="ok"] { color: var(--ok); }
.msg[data-kind="warn"] { color: var(--warn); }
.msg[data-kind="ng"] { color: var(--ng); }
.think { background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 16px; text-align: center; font-size: 20px; }
.board { display: flex; justify-content: center; overflow-x: auto; padding: 4px 0; }
.soroban { display: block; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.soroban .frame { fill: var(--board); stroke: var(--beam); stroke-width: 3; }
.soroban .rod { stroke: var(--rod); stroke-width: 3; }
.soroban .beam { fill: var(--beam); }
.soroban .unit-dot { fill: var(--board); }
.soroban .bead-shape {
  fill: var(--bead); fill-opacity: var(--bead-fill-opacity, 1);
  stroke: var(--bead); stroke-opacity: var(--bead-outline-opacity, 1); stroke-width: 2.5;
  /* 不透明度に transition を付けない: 切り替えの途中で下限を割る瞬間を作らない（REV-R2-004・ADR-007） */
}
.soroban .bead { transition: transform .08s ease-out; }
.soroban .hit, .soroban .zone { fill: transparent; pointer-events: all; }
.soroban .frame, .soroban .rod, .soroban .beam, .soroban .unit-dot { pointer-events: none; } /* 下の列の当たり判定に指を通す */
.soroban.is-locked .zone { pointer-events: none; }
.soroban.is-hidden { visibility: hidden; pointer-events: none; height: 0 !important; }
.soroban.is-locked .hit { pointer-events: none; }
/* 触った珠を光らせる（不透明度を上げる向きだけ＝特許の下限を割らない） */
.soroban .bead.touched .bead-shape { fill: #2f7fb3; fill-opacity: 1; stroke: #2f7fb3; stroke-opacity: 1; }
.soroban .bead.glow .bead-shape { fill: #f2b01e; fill-opacity: 1; stroke: #f2b01e; stroke-opacity: 1; stroke-width: 3; filter: drop-shadow(0 0 6px #f6c445); }
.soroban.is-demo .bead.demo-col .bead-shape { stroke: var(--primary); stroke-opacity: 1; stroke-width: 4; }
.result { text-align: center; }
.score { font-size: 26px; font-weight: 700; }
.stamp { display: inline-flex; flex-direction: column; align-items: center; border: 4px solid var(--warn); color: var(--warn); border-radius: 50%; width: 140px; height: 140px; justify-content: center; }
.stamp span { font-size: 48px; line-height: 1; }
.stamp p { margin: 4px 0 0; font-size: 14px; font-weight: 700; }
.form { display: grid; gap: 10px; }
.form label { display: grid; gap: 4px; }
.flash { text-align: center; }
.flash-box {
  width: min(300px, 90vw); height: 180px; margin: 12px auto; display: flex; align-items: center; justify-content: center;
  font-size: 96px; font-weight: 700; font-variant-numeric: tabular-nums; border: 2px solid var(--line); border-radius: 16px; background: var(--card);
}
.flash-overlay { display: flex; justify-content: center; transform: scale(.7); transform-origin: top center; margin-bottom: -90px; }
.records table { width: 100%; border-collapse: collapse; font-size: 15px; }
.records td, .records th { border-bottom: 1px solid var(--line); padding: 4px 6px; text-align: left; }
.student-card { background: var(--card); border: 2px solid var(--line); border-radius: 12px; padding: 4px 14px 12px; margin-bottom: 12px; }
.teacher { margin-top: 20px; display: grid; gap: 8px; }
.teacher label { display: grid; gap: 6px; }
.ok { color: var(--ok); font-weight: 700; }
#toast { position: fixed; left: 16px; right: 16px; bottom: 16px; margin: 0 auto; max-width: 700px; background: var(--fg); color: var(--bg); padding: 12px 16px; border-radius: 12px; }
#toast[data-kind="error"] { background: var(--ng); color: #fff; }
.touch-debug { position: fixed; left: 4px; right: 4px; bottom: 4px; margin: 0; padding: 4px 6px; font: 11px/1.3 ui-monospace, monospace; background: rgba(0,0,0,.75); color: #fff; border-radius: 6px; pointer-events: none; z-index: 10; }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }
@media (prefers-reduced-motion: reduce) { .soroban .bead { transition: none; } }
