/* ビーズけいさん — 見た目（設計書 §3）
 * 色の役割は1つずつ：玉の2色＝10のまとまりだけ／数字カード・ボタン＝中立の1色
 * 玉の色は1本目＝オレンジと青・2本目＝黄色と緑（2026-11-26 社長）。各紐の中の2色が「10のまとまり」を表す */
:root {
  --bg: #FFFDF7;
  --ink: #2B2B2B;
  --ink-soft: #6A645A;
  --btn: #FFFFFF;
  --btn-line: #CFC7B8;
  --btn-press: #F1ECE2;
  --board: #EADBC0;
  --board-line: #D2BE98;
  --post: #A08A68;
  --string: #6B5B45;
  /* 1本目 */
  --bead-a: #E8743B;   /* 最初に動かす10玉 */
  --bead-a-dark: #B9531F;
  --bead-a-hi: #FFD2B8;
  --bead-b: #3A7BD5;   /* あとの10玉 */
  --bead-b-dark: #2556A0;
  --bead-b-hi: #CFE0FA;
  /* 2本目 */
  --bead2-a: #F5C518;
  --bead2-a-dark: #B98F00;
  --bead2-a-hi: #FFF3B8;
  --bead2-b: #3FA34D;
  --bead2-b-dark: #24722F;
  --bead2-b-hi: #CDEFD2;
  --gutter: clamp(12px, 2vw, 24px);
  --pick: #2F7DB8;     /* タップで選んだカードのふち（ひっさん たしざんの --slot-on と同じ青） */
  --ok: #2F7D4F;       /* 正解の しるし（ことば・答えの枠のふち）。玉の緑より暗くして玉と見分ける */
  --card: clamp(64px, 11vh, 80px);   /* 数字カードと答えの枠は同じ大きさ・同じ形（2026-11-28 社長） */
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Noto Sans CJK JP", "Noto Sans JP", sans-serif;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

/* ---- 練習画面（上＝式と数字カード／下＝玉） ---- */
.practice {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: 8px var(--gutter) var(--gutter);
  gap: clamp(6px, 1.5vh, 14px);
}
.practice-head {
  /* おと｜問題の種類（画面の真ん中）｜もどる（2026-11-30 社長） */
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}
.practice-head > :first-child { justify-self: start; }
.practice-head > :last-child { justify-self: end; }
.type-name { margin: 0; font-size: 22px; font-weight: bold; color: var(--ink); white-space: nowrap; text-align: center; }
.head-btn {
  min-height: 44px;
  padding: 0 18px;
  border: 2px solid var(--btn-line);
  border-radius: 12px;
  background: var(--btn);
  color: var(--ink);
  font: inherit;
  font-size: 20px;
  font-weight: bold;
}
/* 上の段：左＝式と［こたえる］／そのすぐ右＝数字カード（2026-11-28 社長）。
 * 画面の両端に離すと、枠までカードを運ぶ距離が長くなる（同日 社長「離れてる」）＝式のすぐ横に置く。
 * 式とカードのまとまりは、玉の板と同じく画面の真ん中にそろえる（同日 社長「ズレてる。中央に」） */
.top {
  flex: 0 0 auto;
  /* 縦に余白を持たせる（2026-11-30 社長「ボードの下が空いてる」）：紐が1本になって板が低くなり、下が空いた。
   * 画面が高いほど 上の段を下げ、玉の板は残りの真ん中に置く＝もどるの下・上の段と板の間・板の下 の空きがほぼ同じになる。
   * 高さ 460px 以下（スマホの横向き）は下げない */
  margin-top: clamp(0px, calc(18vh - 20px), 140px);
  margin-top: clamp(0px, calc(18dvh - 20px), 140px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(24px, 4vw, 64px);
}
/* 左のまとまり：1段目＝式（＝まで）｜答えの枠／2段目＝［こたえる］を答えの枠の真下に（2026-11-28 社長） */
.top-left {
  display: grid;
  grid-template-columns: min-content auto;   /* 1列目の幅は式で決まる（下の ことば で広がらない） */
  align-items: center;
  column-gap: clamp(12px, 2.4vh, 24px);
  row-gap: clamp(6px, 1.4vh, 12px);
  min-width: 0;
}
.ans-cell { justify-self: center; line-height: 0; }
.top-left .enter-btn { grid-column: 2; grid-row: 2; justify-self: center; }
/* 正解・やりなおしの ことば：式の下・［こたえる］の左（2026-11-28 社長「正解か間違いかが出てこない」） */
.judge {
  grid-column: 1;
  grid-row: 2;
  justify-self: end;
  margin: 0;
  text-align: right;
  font-size: clamp(22px, 4.4vh, 34px);
  font-weight: bold;
  line-height: 1.25;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.judge.show { opacity: 1; }
.judge.is-ok { color: var(--ok); }
.judge.is-ok.show { animation: judge-pop 0.35s ease-out; }
.judge.is-retry { color: var(--ink-soft); }
@keyframes judge-pop { 0% { transform: scale(0.7); } 70% { transform: scale(1.12); } 100% { transform: scale(1); } }
.formula {
  font-size: clamp(40px, 10vh, 76px);
  font-weight: bold;
  line-height: 1.1;
  letter-spacing: 0.08em;
  white-space: nowrap;
}
/* 式の場所は、いちばん長い式（２０ － １３・１０ ＋ １０）の幅で取っておき、短い式は右に寄せる。
 * 問題が変わっても ＝・答えの枠・数字カードの位置が動かないように（2026-11-28 社長Go）。
 * 見えない「ものさし」を同じマスに重ね、マスの幅をいちばん広いものに合わせる */
.expr { display: inline-grid; }
.expr > * { grid-area: 1 / 1; }
.expr-text { justify-self: end; }
.expr-sizer { visibility: hidden; }
/* 答えの枠は2つ（十・一）。1けたずつカードを入れる（ひっさん たしざんと同じ） */
.ans-slots {
  display: inline-flex;
  gap: clamp(6px, 1.2vh, 10px);   /* 数字カードの間と同じ */
  vertical-align: middle;
  letter-spacing: 0;
}
.slot {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--card);
  height: var(--card);
  border: 3px dashed var(--btn-line);
  border-radius: 14px;
  font-size: calc(var(--card) * 0.62);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  touch-action: none;
}
.slot.is-filled {
  border-style: solid;
  background: var(--btn);
  box-shadow: 0 2px 0 var(--btn-line);
  cursor: grab;
}
.slot.is-holding { opacity: 0.45; }
.enter-btn {
  min-height: clamp(56px, 9vh, 72px);
  width: calc(4.5em + 56px);   /* ［こたえる］と［つぎへ］で幅を変えない＝カードが動かない（2026-11-28） */
  padding: 0 28px;
  white-space: nowrap;
  border: 4px solid var(--ink-soft);
  border-radius: 14px;
  background: var(--btn);
  color: var(--ink);
  font: inherit;
  font-size: clamp(22px, 4.2vh, 30px);
  font-weight: bold;
  touch-action: manipulation;
}
.enter-btn:active { background: var(--btn-press); }

/* 数字カード：横5枚×2段（0〜4／5〜9）。何枚でも取れる */
.tray {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(5, auto);
  gap: clamp(6px, 1.2vh, 10px);
  touch-action: none;
}
.card {
  width: var(--card);
  height: var(--card);
  display: flex;
  align-items: center;
  justify-content: center;
  border: 3px solid var(--btn-line);
  border-radius: 14px;
  background: var(--btn);
  box-shadow: 0 2px 0 var(--btn-line);
  color: var(--ink);
  font-size: calc(var(--card) * 0.62);
  font-weight: bold;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  cursor: grab;
  touch-action: none;
}
.card.is-holding { opacity: 0.45; }
/* タップで選んだカード（ひっさん たしざん v1.16 と同じ）：まっすぐ上に少し浮かせる（高さの1/5）。斜めはトレイで隣に重なって見えるため */
.card, .slot.is-source { transition: transform .12s ease, box-shadow .12s ease; }
.card.is-picked, .slot.is-filled.is-source.is-picked {
  transform: translateY(-20%);
  border-color: var(--pick);
  box-shadow: 0 10px 16px rgba(0, 0, 0, 0.28);
  position: relative; z-index: 5;
}
.card-ghost {
  position: fixed;
  z-index: 50;
  margin: 0;
  pointer-events: none;
  cursor: grabbing;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.22);
}
.card-ghost.is-snap { box-shadow: none; border-color: transparent; background: transparent; }

/* ---- 紐と玉 ---- */
.rack-area {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  margin-top: clamp(8px, 3vh, 32px);   /* 計算エリアとボードの最低限の間。ふだんは下の「真ん中に置く」で広がる（2026-11-30。それまでは 7vh＝2026-11-28 社長「もう少し広く」） */
}
.rack {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;   /* 残りの高さの真ん中に置く（2026-11-30 社長「ボードの下が空いてる」。それまでは上詰め＝2026-11-28） */
  justify-content: center;
  touch-action: none;
}
.rack-board {
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  gap: var(--row-gap);          /* 紐と紐の間・ボードの上下の余白は beads.js が玉の大きさから決める（BOARD_PAD・ROW_GAP） */
  padding: var(--board-pad) 0;
  width: calc(var(--d) * var(--slots) + 56px);
  background: var(--board);
  border: 2px solid var(--board-line);
  border-radius: 18px;
}
.rack-row {
  position: relative;
  height: var(--row-h);
  padding: 0 28px;
}
/* 紐の両端の柱 */
.rack-row::before, .rack-row::after {
  content: "";
  position: absolute;
  top: 10%;
  bottom: 10%;
  width: 10px;
  border-radius: 5px;
  background: var(--post);
}
.rack-row::before { left: 12px; }
.rack-row::after { right: 12px; }
.rack-track {
  position: relative;
  height: 100%;
  width: calc(var(--d) * var(--slots));
}
.rack-string {
  position: absolute;
  left: -16px;
  right: -16px;
  top: 50%;
  height: 4px;
  margin-top: -2px;
  border-radius: 2px;
  background: var(--string);
}
.bead {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--d);
  height: 100%;            /* 当たり判定は紐の高さいっぱい（ねらいやすく） */
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.5s ease-in-out;   /* タップで動くときは、目で追える速さ（2026-11-26 社長） */
  cursor: grab;
  will-change: transform;
}
.rack-track.is-dragging .bead { transition: none; cursor: grabbing; }
.rack.no-anim .bead { transition: none; }
.bead span {
  display: block;
  width: calc(var(--d) - 2px);
  height: calc(var(--d) - 2px);
  border-radius: 50%;
  pointer-events: none;
}
.bead-a span {
  background: radial-gradient(circle at 35% 30%, var(--bead-a-hi) 0 12%, var(--bead-a) 45%, var(--bead-a-dark) 100%);
}
.bead-b span {
  background: radial-gradient(circle at 35% 30%, var(--bead-b-hi) 0 12%, var(--bead-b) 45%, var(--bead-b-dark) 100%);
}
/* 2本だと玉が小さすぎる画面（スマホの横向きなど）は1本だけ（beads.js が is-one を付ける・2026-11-29 社長） */
.rack.is-one .rack-row + .rack-row { display: none; }
/* 2本目は黄色と緑 */
.rack-row + .rack-row {
  --bead-a: var(--bead2-a); --bead-a-dark: var(--bead2-a-dark); --bead-a-hi: var(--bead2-a-hi);
  --bead-b: var(--bead2-b); --bead-b-dark: var(--bead2-b-dark); --bead-b-hi: var(--bead2-b-hi);
}

@media (prefers-reduced-motion: reduce) {
  .bead { transition: none; }
  .judge.is-ok.show { animation: none; }
}

/* ======== 画面の切り替え（T3・設計書 §1-1） ========
 * はじめ → たしざん／ひきざん → だん → 練習 → おわり。押すものは少なく・大きく（§1） */
.screen:not(.is-on) { display: none !important; }
.screen-start, .screen-kind, .screen-dan, .screen-edit, .screen-done {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(16px, 5vh, 48px);
  padding: 8px var(--gutter) var(--gutter);
}
.screen-kind, .screen-dan, .screen-edit { justify-content: flex-start; }
.screen-head {
  align-self: stretch;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 44px;
}
.screen-head .spacer { flex: 1; }

/* 声のクレジット（設計書 J4）：はじめの画面の下のはしに小さく */
.screen-start { position: relative; }
/* はじめの画面の おと：練習の画面と同じ左上に置く（真ん中のタイトルとボタンは動かさない） */
.start-head { position: absolute; top: 8px; left: var(--gutter); }
.credit {
  position: absolute;
  bottom: 8px;
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: 12px;
  color: var(--ink-soft);
}

.app-title {
  margin: 0;
  font-size: clamp(40px, 10vh, 72px);
  letter-spacing: 0.08em;
}
.big-btn {
  min-width: min(360px, 60vw);
  min-height: clamp(72px, 13vh, 100px);
  padding: 0 40px;
  border: 4px solid var(--ink-soft);
  border-radius: 20px;
  background: var(--btn);
  color: var(--ink);
  font: inherit;
  font-size: clamp(28px, 6vh, 44px);
  font-weight: bold;
  touch-action: manipulation;
}
.big-btn-sub { border-color: var(--btn-line); }
.big-btn:active, .kind-card:active, .dan-btn:active { background: var(--btn-press); }

/* たしざん／ひきざん＝トップ（2026-11-30）：タイトルと大きな2枚のカードを まとめて真ん中に。下のはしに声のクレジット */
.screen-kind { position: relative; }
.kind-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 4vh, 40px);
  padding-bottom: 44px;   /* 上の空き（screen-head）とつり合わせて真ん中に見せる */
}
.screen-kind .app-title { font-size: clamp(28px, 7vh, 56px); }
.kind-cards {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: clamp(24px, 5vw, 64px);
}
.kind-card {
  width: clamp(240px, 32vw, 380px);
  height: clamp(180px, 44vh, 320px);   /* 上にタイトルが入るので少し低く（52vh→44vh・2026-11-30） */
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(8px, 2vh, 20px);
  border: 4px solid var(--btn-line);
  border-radius: 24px;
  background: var(--btn);
  box-shadow: 0 4px 0 var(--btn-line);
  color: var(--ink);
  font: inherit;
  font-weight: bold;
  touch-action: manipulation;
}
.kind-mark { font-size: clamp(72px, 18vh, 140px); line-height: 1; }
.kind-name { font-size: clamp(30px, 6.5vh, 48px); letter-spacing: 0.06em; }

/* だん：たての一覧 */
.dan-list {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: clamp(8px, 1.8vh, 16px);
  width: min(640px, 86vw);
  padding-bottom: 44px;
}
.dan-btn {
  min-height: clamp(56px, 10.5vh, 84px);
  padding: 0 28px;
  border: 3px solid var(--btn-line);
  border-radius: 16px;
  background: var(--btn);
  box-shadow: 0 3px 0 var(--btn-line);
  color: var(--ink);
  font: inherit;
  font-size: clamp(24px, 4.8vh, 36px);
  font-weight: bold;
  text-align: left;
  touch-action: manipulation;
}

/* じぶんで つくる（任意の式・2026-11-28 社長）：数字カードで2つの数を入れ、＋か－を選ぶ */
.dan-btn-edit { border-style: dashed; margin-top: clamp(4px, 1vh, 10px); }
.edit-main {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(12px, 3vh, 28px);
  padding-bottom: 44px;
}
.edit-row {
  display: flex;
  align-items: center;
  gap: clamp(16px, 3vw, 40px);
}
.op-toggle { display: inline-flex; gap: clamp(6px, 1.2vh, 10px); }
.op-btn {
  width: var(--card);
  height: var(--card);
  border: 3px solid var(--btn-line);
  border-radius: 14px;
  background: var(--btn);
  color: var(--ink-soft);
  font: inherit;
  font-size: calc(var(--card) * 0.62);
  font-weight: bold;
  line-height: 1;
  touch-action: manipulation;
}
.op-btn.is-on { border: 4px solid var(--ink-soft); color: var(--ink); background: var(--btn-press); }
/* ［URLを コピー］は先生用＝小さめ。［はじめる］の左に並べる（2026-12-01） */
.edit-btns { display: flex; align-items: center; gap: clamp(16px, 3vw, 32px); }
.copy-btn[hidden], .edit-url[hidden] { display: none; }
.edit-url { width: min(640px, 90vw); font: inherit; font-size: 16px; padding: 8px 10px; border: 2px solid var(--btn-line); border-radius: 8px; background: var(--btn); color: var(--ink); -webkit-user-select: text; user-select: text; }
.edit-msg {
  margin: 0;
  min-height: 1.4em;
  font-size: clamp(22px, 4vh, 30px);
  font-weight: bold;
  color: var(--ink-soft);
}

/* おわり */
.done-msg { margin: 0; font-size: clamp(48px, 12vh, 96px); font-weight: bold; letter-spacing: 0.08em; }
.done-btns { display: flex; gap: clamp(16px, 3vw, 40px); flex-wrap: wrap; justify-content: center; }

/* 正解のとき：答えの枠を少し強く見せる。［こたえる］は［つぎへ］に変わる（ほめる声は T5） */
.practice.is-correct .slot.is-filled { border-color: var(--ok); border-width: 4px; }

/* 縦向き・小さすぎる画面のお知らせ（§3・仮5） */
.overlay {
  position: fixed; inset: 0; z-index: 60; display: none;
  align-items: center; justify-content: center; text-align: center;
  padding: 24px;
  background: rgba(255, 253, 247, 0.97);
  font-size: clamp(32px, 7vw, 48px); font-weight: bold;
}
.overlay.show { display: flex; }

/* おと OFF（§6-1）：ボタンを薄くして斜めの線を引く */
.voice-btn.is-off { color: var(--btn-line); position: relative; }
.voice-btn.is-off::after { content: ''; position: absolute; left: 10px; right: 10px; top: 50%; border-top: 3px solid currentColor; transform: rotate(-20deg); }

/* 試作ページだけ：いま読んでいる ことば（仮の音は電子音なので、何を言っているかを文字で見せる） */
.voice-cap { display: none; }
.show-cap .voice-cap { display: block; position: fixed; left: 50%; bottom: 8px; transform: translateX(-50%); z-index: 10; padding: 4px 14px; border-radius: 10px; background: rgba(51, 46, 40, 0.78); color: #fff; font-size: 18px; pointer-events: none; }
.show-cap .voice-cap:empty { display: none; }

/* 高さの低い画面（スマホの横向きなど）：式・カード・［こたえる］を小さくして、横に並びきるように（2026-11-29 社長「式と数字カードが被ってる」）。
 * Chromebook（高さ 480px 以上）は変わらない。上の指定を上書きするので、このファイルのいちばん最後に置く */
@media (max-height: 460px) {
  :root { --card: clamp(44px, min(13vh, 5.8vw), 64px); }
  .formula { font-size: calc(var(--card) * 0.72); }
  .enter-btn { min-height: 44px; font-size: 20px; padding: 0 16px; width: calc(4.5em + 32px); }
  .judge { font-size: 20px; }
  .head-btn { min-height: 40px; font-size: 18px; }
  .type-name { font-size: 18px; }
  .top { gap: clamp(16px, 3vw, 32px); }
  .rack-area { margin-top: 12px; }
  .slot, .card { border-radius: 10px; }
  /* だん：6つを 2列×3段に（たて1列だと下にはみ出す・2026-11-29 社長） */
  .dan-list { display: grid; grid-template-columns: 1fr 1fr; align-content: center; gap: 10px 12px; width: min(820px, 92vw); padding-bottom: 8px; }
  .dan-btn { min-height: 52px; padding: 0 16px; font-size: 20px; border-radius: 12px; }
  .dan-btn-edit { margin-top: 0; }
  .edit-main { padding-bottom: 8px; gap: 10px; }
  .big-btn { min-height: 56px; font-size: 26px; border-radius: 14px; }
  .edit-msg { font-size: 20px; }
  .kind-mark { font-size: clamp(56px, 18vh, 140px); }
  .kind-name { font-size: clamp(24px, 6.5vh, 48px); }
  /* それでも入りきらないときは、その画面の中だけ縦に動かせるように */
  .screen-kind, .screen-dan, .screen-edit, .screen-done { overflow-y: auto; }
}
