/* ============================================================
   さんすうブロック — スタイル
   小学1年生向け: 大きなボタン・はっきりした色・丸いかたち
   ============================================================ */

:root {
  --orange: #ff9f43;
  --orange-dark: #e8862a;
  --blue: #4aa3ff;
  --blue-dark: #2f7fd6;
  --green: #2ecc71;
  --green-dark: #1faa58;
  --pink: #ff7eb3;
  --purple: #a06cd5;
  --ink: #3d3d4e;
  --mark: #af4809;        /* しきに かきこむ しるし（きょうかしょの えんぴつの いろ）。
                             水色の しきの 上で 4.5:1 に とどく こさに した */
  --paper: #ffffff;
  --bg-top: #cdeeff;
  --bg-bottom: #fff6d8;
  --slot-line: #b9c4d0;

  /* 面用（白ぬき文字を のせられる 濃さ）と 文字用（白い地で 4.5:1）を
     2段階に わける。ひとつの 値で 両方を まかなうと、かならず どちらかが
     とどかない。もとの 色相は 変えず、明度だけ さげている。 */
  --orange-surface: #b15c00;  --orange-surface-d: #8d4c0f;  --orange-text: #b16013;
  --blue-surface:   #0070e4;  --blue-surface-d:   #205ea2;  --blue-text:   #256dbc;
  --amber-surface:  #946c00;  --amber-surface-d:  #7c5607;
  --green-surface:  #1e8349;  --green-surface-d:  #136b37;  --green-text:  #198646;
  --purple-surface: #9751d1;  --purple-surface-d: #793eb6;  --purple-text: #9358cf;
  --pink-surface:   #e30059;  --pink-surface-d:   #af215c;
  --radius: 18px;
  --shadow: 0 4px 0 rgba(0, 0, 0, 0.14);
  /* 端末幅に応じて なめらかに拡大縮小する流体サイズ */
  --slot-size: clamp(32px, 9.5vw, 54px);
  --block-size: calc(var(--slot-size) - 8px);
  --eq-font: clamp(38px, 11vw, 66px);
  /* さくらんぼ: まると まるの あいだは しるし（わ）が とおれる ひろさに する */
  --cherry-r: clamp(40px, 11vw, 54px);
  --cherry-gap: clamp(16px, 4.5vw, 26px);
  --key-h: clamp(54px, 9.5vmin, 78px);
  --key-font: clamp(24px, 4.8vmin, 34px);

  /* ノッチ・ホームバー・丸角の ぶん */
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}

/* 児童むけの がめんなので 配色は 固定する（かってに 暗くしない） */
:root { color-scheme: light; }

/* ---------- タップ領域 44px ----------
   ボタンじたいを 44px に すると、つめて ならべた タブや ＋− が
   おりかえって べつの こわれかたを する。
   見た目は そのままに、疑似要素で あたり判定だけを ひろげる。
   （input は 疑似要素を もてないので、チェックボックスの たぐいは
     かこみの <label> がわで 44px を 確保する） */
.tap-44 { position: relative; }
.tap-44::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  min-width: 44px;
  min-height: 44px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- SVGアイコン（線画・currentColor） ---------- */
.icon {
  width: 1em;
  height: 1em;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.125em;
  flex-shrink: 0;
}

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: "Hiragino Maru Gothic ProN", "BIZ UDPGothic", "Rounded Mplus 1c",
    "Yu Gothic", "Meiryo", sans-serif;
  color: var(--ink);
  background: var(--bg-top);
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* iOS Safari は background-attachment: fixed が使えないため固定レイヤーで描く */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, var(--bg-top), var(--bg-bottom));
}

#app {
  max-width: 620px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
}

/* dvh が つかえない ふるい端末むけ。dvh を さきに 書いて @supports で うける。 */
@supports not (min-height: 100dvh) {
  #app { min-height: 100vh; }
}

/* ひっぱり更新の ぼうはつを ふせぐ。ブロックを ならべている とちゅうに
   画面ごと 下へ ひっぱられると、おいた ブロックが 見えなくなる。 */
#app, .screen, .tab-panel, .map-scroll { overscroll-behavior: contain; }

/* CSP の style-src 'self' は style属性を とめるため、
   もとは index.html に style="display:none" と 書いていたものを ここへ うつした。 */
#icon-defs { display: none; }

/* ---------- 画面の切りかえ ---------- */
.screen {
  display: none;
  flex-direction: column;
  flex: 1;
  padding: 14px 16px 20px;
}

.screen.active {
  display: flex;
}

/* ---------- ホーム（ダッシュボード） ---------- */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 7px;
}

.logo-block {
  width: 24px;
  height: 24px;
  border-radius: 7px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.12);
}

.lb-a { background: var(--orange); }
.lb-b { background: var(--blue); }

.logo-text {
  font-size: 21px;
  font-weight: bold;
  letter-spacing: 1px;
  margin: 0;              /* h1 の 既定の よはくを うちけす */
}

.level-card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.level-chip {
  background: linear-gradient(180deg, #ffd76e, #f4a924);
  color: #7a4d00;
  font-size: 19px;
  font-weight: bold;
  border-radius: 14px;
  padding: 10px 14px;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.12);
  flex-shrink: 0;
}

.level-info { flex: 1; min-width: 0; }

.level-title {
  font-size: 15px;
  font-weight: bold;
  margin-bottom: 4px;
}

.xp-bar {
  height: 12px;
  background: #eef1f5;
  border-radius: 999px;
  overflow: hidden;
}

.xp-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #ffd76e, var(--orange));
  border-radius: 999px;
  transition: width 0.6s ease;
}

.xp-text {
  font-size: 12px;
  opacity: 0.7;
  margin-top: 3px;
}

.mission-card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
}

.mission-ring {
  width: 92px;
  height: 92px;
  flex-shrink: 0;
  transform: rotate(-90deg);
}

.mission-ring circle {
  fill: none;
  stroke-width: 10;
  stroke-linecap: round;
}

.ring-bg { stroke: #eef1f5; }

.ring-fg {
  stroke: var(--orange);
  transition: stroke-dashoffset 0.6s ease;
}

.ring-fg.done { stroke: var(--green); }

.mission-ring text {
  transform: rotate(90deg);
  transform-origin: 50px 50px;
  font-size: 19px;
  font-weight: bold;
  fill: var(--ink);
}

.mission-ring .ring-label {
  font-size: 11px;
  fill: #99a;
}

.mission-info { flex: 1; }

.mission-title {
  font-size: 16px;
  font-weight: bold;
  margin-bottom: 3px;
}

.mission-desc {
  font-size: 13px;
  opacity: 0.8;
  line-height: 1.5;
}

.day-streak {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-top: 6px;
  background: #fff1e2;
  border-radius: 999px;
  padding: 4px 12px;
  font-size: 13px;
  font-weight: bold;
  color: #ae5500;
}

.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.mode-card {
  border: none;
  border-radius: var(--radius);
  padding: 16px 12px;
  font-family: inherit;
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  transition: transform 0.08s;
}

.mode-card:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.14);
}

.mode-card.wide { grid-column: 1 / -1; }

.mode-icon { width: 32px; height: 32px; margin-bottom: 3px; }
.mode-name { font-size: 19px; font-weight: bold; }
.mode-desc { font-size: 12px; }

.mc-add { background: linear-gradient(180deg, var(--orange-surface), var(--orange-surface-d)); }
.mc-sub { background: linear-gradient(180deg, var(--blue-surface), var(--blue-surface-d)); }
.mc-timed { background: linear-gradient(180deg, var(--amber-surface), var(--amber-surface-d)); }
.mc-dev { background: linear-gradient(180deg, var(--green-surface), var(--green-surface-d)); }
.mc-rec { background: linear-gradient(180deg, var(--purple-surface), var(--purple-surface-d)); }
.mc-free { background: linear-gradient(180deg, var(--pink-surface), var(--pink-surface-d)); }

/* ホームの いちばん下の クレジット。子どもが つかう ボタンより 目立たせない。
   色は --ink のまま（うすい 灰色に すると、この 画面の 明るい 地に 対して
   4.5:1 に とどかない）。小さくするのは 字の 大きさ と 透明度 だけ。 */
.home-credit {
  margin: 20px auto 8px;
  font-size: 12px;
  color: var(--ink);
  opacity: .75;
  text-align: center;
}
.home-credit a { color: inherit; }

/* ⚠️ クレジットと行き先のリンクを 1 行に収める。ここを折り返させると、
   ホームのいちばん下がそのぶん伸びる。flex-wrap: nowrap と min-width: 0 の
   2 つが要る。nowrap だけだと、文字列が縮まずに列を押し広げて
   横スクロールになる。狭い画面ではクレジットが … で切れる。 */
.home-credit {
  display: flex; flex-wrap: nowrap; align-items: center;
  justify-content: center; gap: .2em;
}
.home-credit__c { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.install-btn {
  margin: 16px auto 0;
  min-height: 44px;
  border: none;
  background: var(--paper);
  color: var(--ink);
  font-family: inherit;
  font-size: 15px;
  font-weight: bold;
  padding: 12px 22px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

.install-btn .icon { width: 18px; height: 18px; color: var(--blue-text); }

/* ---------- メニュー（やりかたえらび） ---------- */
.menu {
  display: flex;
  flex-direction: column;
  gap: 14px;
  width: 100%;
  max-width: 380px;
  margin: 0 auto;
}

.select-note {
  text-align: center;
  font-size: 14px;
  margin: 0 0 14px;
  opacity: 0.85;
}

.menu-btn {
  border: none;
  border-radius: var(--radius);
  padding: 16px 18px;
  font-family: inherit;
  color: #fff;
  cursor: pointer;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: transform 0.08s;
}

.menu-btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.14);
}

/* さくせん名は ながいので、画面はばに あわせて ちぢめ、ことばの とちゅうで おらない */
.menu-main {
  font-size: clamp(17px, 5.2vw, 23px);
  font-weight: bold;
  line-height: 1.35;
  word-break: keep-all;
  overflow-wrap: break-word;
}
.menu-small { font-size: 13px; line-height: 1.45; word-break: keep-all; overflow-wrap: break-word; }
.menu-example {
  font-size: 13px;
  background: rgba(0, 0, 0, 0.22);
  border-radius: 8px;
  padding: 2px 10px;
  margin-top: 4px;
}

.menu-add { background: linear-gradient(180deg, var(--orange-surface), var(--orange-surface-d)); }
.menu-genka { background: linear-gradient(180deg, var(--blue-surface), var(--blue-surface-d)); }
.menu-gengen { background: linear-gradient(180deg, var(--green-surface), var(--green-surface-d)); }
.menu-mix { background: linear-gradient(180deg, var(--pink-surface), var(--pink-surface-d)); }
.menu-rec { background: linear-gradient(180deg, var(--purple-surface), var(--purple-surface-d)); }

/* ---------- ヘッダー ---------- */
.simple-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.simple-header h1 {
  font-size: 20px;
  margin: 0;
}

.simple-header h1 .h-icon {
  width: 22px;
  height: 22px;
  vertical-align: -4px;
}

.ic-dev { color: var(--green-text); }
.ic-timed { color: #e8a10e; }
.ic-free { color: #e05a92; }

/* ---------- じぶんで しきを いれる がめん ---------- */
.free-eq {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: clamp(6px, 2vw, 12px);
  background: var(--paper);
  border-radius: var(--radius);
  padding: clamp(10px, 2.5vw, 16px);
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.free-num {
  min-width: clamp(64px, 18vw, 96px);
  min-height: clamp(56px, 15vw, 84px);
  border: 3px dashed var(--slot-line);
  border-radius: 16px;
  background: #f7f9fc;
  color: var(--ink);
  font-family: inherit;
  font-size: clamp(30px, 8vw, 46px);
  font-weight: bold;
  cursor: pointer;
}

.free-num.selected {
  border-style: solid;
  border-color: var(--pink);
  background: #fff0f6;
  animation: free-sel 1.4s ease-in-out infinite;
}

@keyframes free-sel {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 126, 179, 0); }
  50% { box-shadow: 0 0 0 5px rgba(255, 126, 179, 0.3); }
}

/* あたり判定を 44px に ひろげた ぶん、となりと かさならないよう すきまを ひろげる */
.free-ops { display: flex; flex-direction: column; gap: 12px; }

.free-op {
  border: none;
  border-radius: 12px;
  min-width: 46px;
  min-height: 36px;
  position: relative;
  background: #eef2f7;
  color: #7b8896;
  font-family: inherit;
  font-size: 22px;
  font-weight: bold;
  cursor: pointer;
}

.free-op.on { background: var(--blue-surface); color: #fff; }

.free-eqmark, .free-ans {
  font-size: clamp(28px, 7vw, 40px);
  font-weight: bold;
  color: var(--ink);
}

.free-ans { color: var(--purple-text); }

.free-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(6px, 1.6vmin, 12px);
  max-width: min(400px, 100%);
  margin: 0 auto;
  touch-action: manipulation;
}

.free-keypad button {
  border: none;
  border-radius: 14px;
  min-height: clamp(44px, 8vmin, 60px);
  font-family: inherit;
  font-size: clamp(20px, 4.4vmin, 28px);
  font-weight: bold;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
}

.free-keypad button:active { transform: translateY(3px); box-shadow: none; }
.free-keypad .key-del { background: #ffe3e3; color: #c03148; font-size: clamp(15px, 3.2vmin, 20px); }
.free-keypad .key-clear { background: #eef2f7; color: #656e7b; font-size: clamp(13px, 2.8vmin, 17px); }

.free-msg {
  min-height: 22px;
  margin: 8px 0 0;
  text-align: center;
  font-size: 14px;
  font-weight: bold;
}

.free-msg.warn { color: #d4576b; }

.free-method {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
  text-align: center;
}

.free-method-title { font-size: 13px; font-weight: bold; color: #67707e; }

.free-method-btns { display: flex; gap: 8px; margin-top: 8px; }

.free-method-btn {
  flex: 1;
  position: relative;
  border: 3px solid #e3e9ef;
  border-radius: 12px;
  background: #f7f9fc;
  color: #67707e;
  font-family: inherit;
  font-size: 13px;
  font-weight: bold;
  line-height: 1.4;
  padding: 8px 6px;
  word-break: keep-all;
  cursor: pointer;
}

.free-method-btn.on { border-color: var(--blue-surface); background: #eaf4ff; color: var(--blue-text); }

.free-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border-radius: var(--radius);
  padding: 10px 12px;
  box-shadow: var(--shadow);
  margin: 12px 0;
  cursor: pointer;
}

.free-switch input { position: absolute; opacity: 0; width: 0; height: 0; }

.free-switch-box {
  flex: 0 0 auto;
  width: 52px;
  height: 30px;
  border-radius: 999px;
  background: #d9dee6;
  position: relative;
  transition: background 0.15s;
}

.free-switch-knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}

.free-switch input:checked + .free-switch-box { background: var(--green); }
.free-switch input:checked + .free-switch-box .free-switch-knob { transform: translateX(22px); }
.free-switch input:focus-visible + .free-switch-box { outline: 3px solid var(--blue); outline-offset: 2px; }

.free-switch-text { font-size: 14px; line-height: 1.4; }
.free-switch-text small { display: block; font-size: 12px; opacity: 0.75; }

.free-start { width: 100%; }
.free-start:disabled { background: #d9dee6; color: #8b95a1; cursor: default; }

.free-note {
  margin: 10px 0 0;
  text-align: center;
  font-size: 12px;
  opacity: 0.7;
}

/* ---------- せつめいモード ---------- */
body.explain-mode #keypad { display: none; }
body.free-mode #streak-badge { display: none; }

#explain-bar {
  display: flex;
  justify-content: center;
  margin: 10px auto 4px;
  max-width: min(440px, 100%);
  width: 100%;
}

.explain-btn {
  width: 100%;
  min-height: clamp(52px, 9vmin, 68px);
  border: none;
  border-radius: 16px;
  background: var(--green-surface);
  color: #fff;
  font-family: inherit;
  font-size: clamp(20px, 4.4vmin, 26px);
  font-weight: bold;
  box-shadow: var(--shadow);
  cursor: pointer;
}

.explain-btn:active { transform: translateY(3px); box-shadow: none; }
.explain-btn .icon { width: 26px; height: 26px; vertical-align: -4px; }
body.task-mode #explain-bar { opacity: 0.35; pointer-events: none; }

.play-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.icon-btn {
  border: none;
  background: var(--paper);
  border-radius: 12px;
  width: 44px;
  height: 44px;
  font-size: 20px;
  font-family: inherit;
  color: var(--ink);
  cursor: pointer;
  box-shadow: var(--shadow);
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn .icon { width: 22px; height: 22px; }

.icon-btn:active { transform: translateY(2px); box-shadow: none; }

#play-info {
  flex: 1;
  display: flex;
  justify-content: center;
}

#star-row {
  display: flex;
  gap: 6px;
}

#star-row .icon {
  display: block;
  width: 24px;
  height: 24px;
  color: #ffb400;
}

#star-row .star { opacity: 0.25; transition: opacity 0.3s, transform 0.3s; }
#star-row .star.earned { opacity: 1; animation: star-pop 0.5s; }

@keyframes star-pop {
  0% { transform: scale(0.2) rotate(-30deg); }
  60% { transform: scale(1.5) rotate(10deg); }
  100% { transform: scale(1) rotate(0); }
}

#timed-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

#timed-progress {
  background: var(--paper);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 16px;
  font-weight: bold;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

#timed-clock {
  font-size: 22px;
  font-weight: bold;
  color: #c05e00;
  min-width: 64px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#streak-badge {
  background: var(--paper);
  border-radius: 12px;
  padding: 8px 12px;
  font-size: 16px;
  font-weight: bold;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  gap: 3px;
}

#streak-badge .icon {
  width: 18px;
  height: 18px;
  color: #ff7b2e;
}

/* ---------- 問題エリア ---------- */
#play-main {
  display: flex;
  flex-direction: column;
  flex: 1;
}

#play-left, #play-right {
  display: flex;
  flex-direction: column;
}

/* たて画面では キーパッドを 画面の下に よせて、親指で 押しやすくする */
#play-right { flex: 1; }
#play-right #keypad { margin-top: auto; }

#method-badge {
  /* しるしの わが うえに はみ出しても おびの もじが よめるように */
  position: relative;
  z-index: 5;
  text-align: center;
  font-size: 13px;
  min-height: 22px;
  margin-bottom: 2px;
  word-break: keep-all;
  overflow-wrap: break-word;
}

#method-badge span {
  display: inline-block;
  background: var(--paper);
  border-radius: 999px;
  padding: 3px 14px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
  font-weight: bold;
}

#method-badge .icon { width: 14px; height: 14px; vertical-align: -2px; }
.ic-add { color: #e0508a; }
.ic-sub { color: var(--blue-text); }

#equation {
  position: relative;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
  gap: clamp(6px, 2vw, 12px);
  min-height: clamp(100px, 27vw, 156px);
  margin-bottom: 4px;
}

/* のこりの かずを 下に かきこんだ ときは その ぶんの ばしょを あける */
#equation.has-under { padding-bottom: clamp(20px, 5vw, 30px); }

body.timed-mode #equation {
  min-height: clamp(72px, 20vw, 110px);
  align-items: center;
}

.eq-group {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.eq-num, .eq-op, .eq-ans {
  font-size: var(--eq-font);
  font-weight: bold;
  line-height: 1.25;
}

.eq-num {
  position: relative;
  background: var(--paper);
  border-radius: 0.3em;
  padding: 0 0.28em;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1);
}

.eq-ans {
  color: var(--purple);
  background: var(--paper);
  border-radius: 0.3em;
  padding: 0 0.28em;
  min-width: 1.5em;
  text-align: center;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.1);
}

.eq-ans.answered { animation: pop 0.4s; }

/* ---------- さくらんぼ ---------- */
.cherry {
  /* しるし（わ）が となりの まると かさならないよう まると まるを はなす */
  width: calc(var(--cherry-r) * 2 + var(--cherry-gap));
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-top: 2px;
}

.cherry-stems {
  width: 100%;
  height: auto;
  display: block;
}

.cherry-stems line {
  stroke: #c98a5b;
  stroke-width: 3;
  stroke-linecap: round;
}

.cherry-pair {
  display: flex;
  gap: var(--cherry-gap);
}

.cherry-circle {
  position: relative;
  width: var(--cherry-r);
  height: var(--cherry-r);
  border-radius: 50%;
  background: var(--paper);
  border: 3px dashed var(--slot-line);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(20px, 5.5vw, 27px);
  font-weight: bold;
  color: #73738f;
}

.cherry-circle.filled {
  border: 3px solid var(--pink);
  color: var(--ink);
  background: #ffeaf3;
}

.pop { animation: pop 0.4s; }

@keyframes pop {
  0% { transform: scale(0.3); }
  60% { transform: scale(1.25); }
  100% { transform: scale(1); }
}

/* ---------- しきに かきこむ しるし（きょうかしょの えんぴつの あと） ---------- */
.mark-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: visible;
  z-index: 3;
}

.mark-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
}

/* 10を つくる かずを かこむ わ */
.mark-loop {
  fill: none;
  stroke: var(--mark);
  stroke-width: 4;
  stroke-linecap: round;
  opacity: 0.95;
}

/* こたえを つくる さいごの わは くろで（きょうかしょと おなじ） */
.mark-loop.tone-ink { stroke: var(--ink); }

/* あわせる 2つの かずを むすぶ カーブ */
.mark-tie {
  fill: none;
  stroke: var(--mark);
  stroke-width: 4;
  stroke-linecap: round;
}

/* わの よこに かきそえる かず（「10」など） */
.mark-label {
  position: absolute;
  font-size: calc(var(--eq-font) * 0.52);
  font-weight: bold;
  line-height: 1;
  color: var(--mark);
  white-space: nowrap;
  animation: pop 0.4s 0.45s backwards;
}

/* つかいおわった かずに ひく ななめの せん */
.mk-strike {
  position: absolute;
  left: -8%;
  top: 50%;
  width: 116%;
  height: 4px;
  border-radius: 2px;
  background: var(--mark);
  transform-origin: left center;
  transform: translateY(-50%) rotate(-26deg);
  animation: strike-draw 0.35s ease-out;
}

@keyframes strike-draw {
  from { transform: translateY(-50%) rotate(-26deg) scaleX(0); }
}

/* ひいた のこりを 下に 小さく かきこむ */
.mk-under {
  position: absolute;
  left: 34%;
  top: calc(100% + 2px);
  transform: translateX(-50%);
  font-size: clamp(20px, 5.5vw, 28px);
  font-weight: bold;
  line-height: 1.1;
  color: var(--mark);
  animation: pop 0.4s;
}

/* いま つかっている かず */
.mk-used { color: var(--mark); }

/* これから あわせる（ひく）かずを ゆらして 見せる */
.mk-focus { animation: mk-focus 1.1s ease-in-out infinite; }

@keyframes mk-focus {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

/* 動きに よわい子（かんかくかびん）むけ。
   ⚠️ .01ms であって 0 ではない。
      0 にすると animation-fill-mode: forwards / backwards が きかなくなり、
      「うごきを 止める」つもりが「中身を けす」ことに なる。
      このアプリでは ブロックが とんでいく fly-away / absorb（どちらも forwards）と、
      しきに かきそえる かず .mark-label（backwards）が それに あたる。 */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-delay: 0s !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  /* 紙ふぶきは 出さない（うごきの りょうが 多く、いちばん つらい演出） */
  #confetti-layer { display: none !important; }
  /* うごきで しめしていた「いま ここ」を、うごき ぬきで わかるようにする */
  .mk-focus { outline: 3px solid var(--mark); outline-offset: 3px; border-radius: 0.3em; }
}

/* ハイコントラストモード。背景色が むこうに なっても
   「ここが おせる」と わかるように わくを のこす。 */
@media (forced-colors: active) {
  .mode-card, .menu-btn, .icon-btn, .tab-btn, .danger-btn, .install-btn,
  .task-auto, .explain-btn, .howto-next, .free-op, .free-method-btn,
  #keypad button, .free-keypad button {
    border: 2px solid ButtonText;
  }
  .tab-btn[aria-selected="true"], .tab-btn.active { border-width: 3px; }
  .slot, .cherry-circle, #answer-display { border: 2px solid CanvasText; }
}

/* ---------- ブロックステージ ---------- */
#block-stage {
  background: rgba(255, 255, 255, 0.65);
  border-radius: var(--radius);
  padding: clamp(10px, 2vw, 16px) clamp(8px, 2vw, 14px);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  /* かたまりの ラベルが おなじ たかさに ならぶように そこを そろえる */
  align-items: flex-end;
  gap: clamp(10px, 3vw, 20px);
  min-height: clamp(130px, 32vw, 210px);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.06);
}

body.timed-mode #block-stage { display: none; }

/* 10の ぼうは 2かたまり ならぶ ことが ある（じぶんの ぶんと たす ぶん） */
#rod-area {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(8px, 2.5vw, 16px);
}

#rod-area:empty { display: none; }

/* ---------- かたまり（10のぼう／10のわく／ばら）と かずの ラベル ---------- */
.block-group {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}

.group-caption {
  font-size: clamp(11px, 2.7vw, 13px);
  font-weight: bold;
  color: #67707e;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 2px 11px;
  white-space: nowrap;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.07);
}

.group-caption b {
  font-size: 1.35em;
  color: var(--ink);
  margin: 0 2px;
}

.cap-count.bump {
  display: inline-block;
  animation: pop 0.35s;
}

.rod-group {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  max-width: min(280px, 74vw);
}

.ten-rod {
  width: clamp(20px, 4.8vw, 28px);
  height: calc(var(--slot-size) * 2 + 14px);
  background: linear-gradient(180deg, #ffb25e, var(--orange-dark));
  border-radius: 8px;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.18), 0 2px 0 rgba(0, 0, 0, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}

/* タップして うごかせる 10のぼう（じぶんで しきを いれる モード） */
.rod-slot { position: relative; display: flex; }
.rod-slot:empty { display: none; }
.rod-slot.tappable { cursor: pointer; }

.rod-slot.tappable .ten-rod {
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.18), 0 0 0 3px rgba(255, 126, 179, 0.85),
    0 3px 5px rgba(0, 0, 0, 0.16);
  animation: tap-ready 1.7s ease-in-out infinite;
}

.rod-slot.hint .ten-rod { animation: tap-hint 0.7s ease-in-out infinite; }

.ten-rod.pop { animation: pop 0.4s; }
.ten-rod.fly-away { animation: fly-away 0.55s ease-in forwards; }

.ten-rod.flying {
  position: fixed;
  margin: 0;
  z-index: 50;
  transition: transform 0.55s cubic-bezier(0.5, -0.2, 0.4, 1.2);
}

.ten-rod::before {
  content: "";
  position: absolute;
  inset: 3px;
  border-radius: 6px;
  background: repeating-linear-gradient(
    180deg,
    transparent 0,
    transparent 7px,
    rgba(255, 255, 255, 0.25) 7px,
    rgba(255, 255, 255, 0.25) 9px
  );
}

.rod-label {
  writing-mode: vertical-rl;
  font-size: 12px;
  font-weight: bold;
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  z-index: 1;
}

.ten-frame {
  position: relative;
  display: grid;
  grid-template-columns: repeat(5, var(--slot-size));
  grid-template-rows: repeat(2, var(--slot-size));
  gap: 4px;
  background: #f2f6fa;
  border: 3px solid var(--slot-line);
  border-radius: 10px;
  padding: 5px;
  transition: border-color 0.3s, background 0.3s, box-shadow 0.3s;
}

/* 10こ そろった わくは「10の まとまり」として みどりに ひかる */
.ten-frame.full {
  border-color: var(--green);
  background: #e9faf0;
  box-shadow: 0 0 0 4px rgba(46, 204, 113, 0.25);
}

.frame-tag {
  position: absolute;
  left: 50%;
  top: -15px;
  transform: translateX(-50%);
  background: var(--green-surface);
  color: #fff;
  font-size: 13px;
  font-weight: bold;
  padding: 3px 12px;
  border-radius: 999px;
  white-space: nowrap;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.15);
  animation: pop 0.4s;
  z-index: 3;
}

.slot {
  position: relative;
  width: var(--slot-size);
  height: var(--slot-size);
  border: 2px dashed var(--slot-line);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.slot.hl {
  border-color: var(--pink);
  background: #fff0f6;
  animation: slot-blink 1s ease-in-out infinite;
}

@keyframes slot-blink {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 126, 179, 0); }
  50% { box-shadow: 0 0 0 4px rgba(255, 126, 179, 0.35); }
}

.loose-row {
  display: flex;
  align-items: center;
  gap: 6px;
}

.loose-row.split { gap: clamp(6px, 1.6vw, 10px); }

/* さくらんぼの とおりに ばらを 2つに わけた ときの しきり */
.loose-divider {
  align-self: stretch;
  min-height: var(--slot-size);
  border-left: 3px dashed var(--pink);
  border-radius: 2px;
}

.loose-group {
  display: grid;
  gap: 4px;
}

.loose-slot { border-color: transparent; }

/* ---------- タップして うごかす・とる ---------- */
.slot.tappable,
.slot.countable { cursor: pointer; }

/* さわれる ブロックは うすい ピンクの したじきと ゆれで 「ここを おして」と しらせる */
.slot.tappable {
  background: rgba(255, 126, 179, 0.18);
  border-color: rgba(255, 126, 179, 0.6);
}

.slot.tappable .block {
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18), 0 0 0 2px rgba(255, 255, 255, 0.95),
    0 3px 5px rgba(0, 0, 0, 0.16);
  animation: tap-ready 1.7s ease-in-out infinite;
}

@keyframes tap-ready {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-3px); }
}

/* しばらく タップが ないと、つぎの 1こを おおきく ゆらして おしえる */
.slot.hint .block { animation: tap-hint 0.7s ease-in-out infinite; }

@keyframes tap-hint {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-8px) scale(1.12); }
}

.slot.countable:not(.tappable) .block { outline: 2px solid rgba(255, 255, 255, 0.7); outline-offset: -6px; }

/* 「1・2・3…」と かぞえた 数字 */
.count-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(15px, 3.8vw, 21px);
  font-weight: bold;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  pointer-events: none;
  z-index: 2;
}

.slot > .count-badge {
  color: #e0508a;
  text-shadow: none;
}

.block {
  width: var(--block-size);
  height: var(--block-size);
  border-radius: 8px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18), 0 2px 0 rgba(0, 0, 0, 0.12);
  position: relative;
}

.block::after {
  content: "";
  position: absolute;
  inset: 6px;
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.28);
}

.block.c-orange { background: var(--orange); }
.block.c-blue { background: var(--blue); }
.block.c-green { background: var(--green); }

.block.pop { animation: pop 0.4s; }

.block.pulse { animation: block-pulse 0.9s ease-in-out infinite; }

@keyframes block-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.15); }
}

.block.flying {
  position: fixed;
  margin: 0;
  z-index: 50;
  transition: transform 0.55s cubic-bezier(0.5, -0.2, 0.4, 1.2);
}

.block.fly-away {
  animation: fly-away 0.55s ease-in forwards;
}

@keyframes fly-away {
  to {
    transform: translateY(-60px) scale(0.2) rotate(40deg);
    opacity: 0;
  }
}

.block.absorb, .ten-rod.absorb {
  animation: absorb 0.4s ease-in forwards;
}

@keyframes absorb {
  to { transform: scale(0.1); opacity: 0; }
}

/* ---------- しつもん・こたえ ---------- */
#prompt-box {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin: 10px 0 4px;
  min-height: clamp(62px, 12vw, 80px);
}

#prompt {
  font-size: clamp(18px, 4.6vw, 23px);
  font-weight: bold;
  margin: 0;
  line-height: 1.5;
  max-width: 380px;
  /* ことばの とちゅうで おらず、くぎりの すきまで おりかえす */
  word-break: keep-all;
  overflow-wrap: break-word;
}

#answer-display {
  min-width: clamp(62px, 15vw, 88px);
  height: clamp(56px, 13vw, 78px);
  background: var(--paper);
  border: 3px solid var(--purple);
  border-radius: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(30px, 7.5vw, 44px);
  font-weight: bold;
  color: var(--purple);
  padding: 0 10px;
  flex-shrink: 0;
}

#answer-display.waiting { color: #8466b6; }

#answer-display.shake { animation: shake 0.4s; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* ---------- ブロックそうさ中の おびと たすけぶね ---------- */
#task-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 2px 0 4px;
}

#task-remain {
  font-size: clamp(14px, 3.6vw, 17px);
  font-weight: bold;
  color: var(--blue-text);
  background: var(--paper);
  border-radius: 999px;
  padding: 5px 15px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

#task-remain b { font-size: 1.4em; color: #e0508a; }

.task-auto {
  position: relative;
  border: none;
  border-radius: 999px;
  padding: 8px 16px;
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  background: #eaf1fb;
  color: var(--blue-text);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
  cursor: pointer;
}

.task-auto:active { transform: translateY(2px); box-shadow: none; }

/* そうさちゅうは キーパッドを おやすみさせて、ブロックに 気もちを むける */
body.task-mode #prompt { color: var(--blue-text); }
body.task-mode #answer-display { opacity: 0.3; }
body.task-mode #keypad { opacity: 0.35; pointer-events: none; }

#feedback {
  text-align: center;
  min-height: 28px;
  font-size: clamp(16px, 4.2vw, 20px);
  font-weight: bold;
}

#feedback.good { color: var(--green-text); }
#feedback.bad { color: #e0508a; }

/* ---------- キーパッド ---------- */
#keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 1.8vmin, 14px);
  max-width: min(440px, 100%);
  width: 100%;
  margin: 10px auto 4px;
  touch-action: manipulation;
}

#keypad button {
  border: none;
  border-radius: 16px;
  height: var(--key-h);
  min-height: 48px;
  font-size: var(--key-font);
  font-weight: bold;
  font-family: inherit;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--shadow);
  cursor: pointer;
  touch-action: manipulation;
}

#keypad button:active { transform: translateY(3px); box-shadow: none; }

#keypad .key-del { background: #ffe3e3; color: #c03148; font-size: calc(var(--key-font) - 4px); }
#keypad .key-ok { background: var(--green-surface); color: #fff; }
#keypad .key-ok .icon { width: 28px; height: 28px; stroke-width: 2.6; vertical-align: middle; }

/* ---------- よこむき・タブレットの 2カラム ---------- */
@media (min-width: 700px) {
  :root {
    /* 2カラムでは 式が左カラム（約半分）に入るため、カラム幅基準で調整 */
    --eq-font: clamp(40px, 5.5vw, 60px);
    --slot-size: clamp(36px, 4.5vw, 52px);
    --cherry-r: clamp(40px, 5.5vw, 54px);
    --cherry-gap: clamp(16px, 2.4vw, 26px);
  }

  #app { max-width: 1040px; }

  .cherry-circle { font-size: clamp(20px, 2.8vw, 27px); }
  .mk-under { font-size: clamp(20px, 2.8vw, 28px); }

  /* れんしゅう画面いがいは よみやすい はばに おさめる */
  .screen:not(#screen-play) {
    width: 100%;
    max-width: 660px;
    margin: 0 auto;
  }

  #screen-play { padding: 14px 24px 20px; }

  #play-main {
    flex-direction: row;
    gap: 24px;
    align-items: stretch;
  }

  #play-left {
    flex: 1.2;
    justify-content: center;
    gap: 6px;
  }

  #play-right {
    flex: 1;
    max-width: 420px;
    justify-content: center;
  }

  #play-right #keypad { margin-top: 12px; }

  #block-stage { min-height: clamp(160px, 24vw, 240px); }

  #prompt-box { flex-direction: column; gap: 10px; }

  #prompt { text-align: center; }
}

/* ---------- オーバーレイ ---------- */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(60, 50, 90, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.overlay.show { display: flex; }

.overlay-card {
  background: var(--paper);
  border-radius: 24px;
  padding: 28px 32px;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  animation: pop 0.4s;
  max-width: 340px;
  width: 100%;
}

.big-praise {
  font-size: 32px;
  font-weight: bold;
  color: var(--orange-text);
  margin-bottom: 8px;
}

.big-praise .icon { vertical-align: -3px; }

/* ---------- けいさんの しかた（きょうかしょの ふりかえり） ---------- */
.howto-card {
  margin-top: 10px;
  border: 3px solid var(--green);
  border-radius: 18px;
  padding: 10px 12px 12px;
  text-align: left;
}

.howto-title {
  background: var(--green-surface);
  color: #fff;
  font-weight: bold;
  font-size: 15px;
  text-align: center;
  border-radius: 999px;
  padding: 3px 10px;
  margin: -20px auto 8px;
  width: fit-content;
}

.howto-list {
  list-style: none;
  margin: 0;
  padding: 0;
  counter-reset: howto;
}

.howto-list li {
  counter-increment: howto;
  position: relative;
  padding-left: 26px;
  font-size: 15px;
  line-height: 1.6;
  animation: howto-in 0.35s backwards;
}

.howto-list li::before {
  content: counter(howto);
  position: absolute;
  left: 0;
  top: 0.3em;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--green);
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  line-height: 19px;
  text-align: center;
}

.howto-list li:nth-child(1) { animation-delay: 0.15s; }
.howto-list li:nth-child(2) { animation-delay: 0.35s; }
.howto-list li:nth-child(3) { animation-delay: 0.55s; }
.howto-list li:nth-child(4) { animation-delay: 0.75s; }

@keyframes howto-in {
  from { opacity: 0; transform: translateX(-8px); }
}

/* よむ じかんの めやす（5びょうで いっぱいに なる） */
.howto-wait {
  margin-top: 10px;
  height: 8px;
  border-radius: 999px;
  background: #e7eef4;
  overflow: hidden;
}

.howto-wait-bar {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 999px;
  background: var(--green);
  transform-origin: left center;
  transform: scaleX(0);
}

@keyframes howto-wait-grow {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

/* 5びょう たつまでは おせない「つぎへ」ボタン */
.howto-next {
  margin-top: 10px;
  width: 100%;
  min-height: 48px;
  border: none;
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 18px;
  font-weight: bold;
  color: #5f6d7c;
  background: #e3e9ef;
  box-shadow: var(--shadow);
  cursor: default;
}

.howto-next .icon { vertical-align: -3px; }

.howto-next.ready {
  background: var(--green-surface);
  color: #fff;
  cursor: pointer;
  animation: howto-next-in 0.3s;
}

.howto-next.ready:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.14);
}

@keyframes howto-next-in {
  from { transform: scale(0.94); opacity: 0.5; }
}

/* ---------- 紙吹雪（せいかい・クリアの おいわい） ---------- */
#confetti-layer {
  position: fixed;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 150;
}

.confetti-piece {
  position: absolute;
  top: -14px;
  border-radius: 2px;
  opacity: 0;
  animation: confetti-fall linear forwards;
}

.confetti-piece.round { border-radius: 50%; }

@keyframes confetti-fall {
  0% {
    transform: translate(0, 0) rotate(0) rotateX(0);
    opacity: 1;
  }
  100% {
    transform: translate(var(--drift), 105vh) rotate(var(--spin)) rotateX(680deg);
    opacity: 1;
  }
}

.confetti span:nth-child(2) { animation-delay: 0.1s; }
.confetti span:nth-child(3) { animation-delay: 0.2s; }
.confetti span:nth-child(4) { animation-delay: 0.3s; }
.confetti span:nth-child(5) { animation-delay: 0.4s; }

.set-stars {
  display: flex;
  justify-content: center;
  gap: 7px;
  margin: 10px 0;
}

.set-stars .icon { width: 34px; height: 34px; }

.st-on { color: #ffb400; }
.st-off { color: #d9dee6; }

#set-message { font-size: 16px; margin: 6px 0 16px; }

.overlay-btns {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-rows { margin: 10px 0 18px; }

.result-row {
  display: flex;
  justify-content: space-between;
  padding: 7px 6px;
  border-bottom: 2px dashed #eef1f5;
  font-size: 15px;
}

.result-row b { font-size: 17px; color: var(--orange-text); }

/* ---------- トースト ---------- */
#toast-area {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(92vw, 400px);
  pointer-events: none;
}

.toast {
  background: var(--paper);
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: bold;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.18);
  opacity: 0;
  transform: translateY(-16px);
  transition: opacity 0.35s, transform 0.35s;
  border-left: 6px solid var(--orange);
}

.toast.show { opacity: 1; transform: translateY(0); }

.toast .icon {
  width: 19px;
  height: 19px;
  margin-right: 6px;
  vertical-align: -4px;
}

.t-amber { color: #ffb400; }
.t-gold { color: #f4a924; }
.t-purple { color: var(--purple-text); }
.t-blue { color: var(--blue-text); }

.toast-mission { border-left-color: var(--green); }
.toast-level { border-left-color: #f4a924; }
.toast-badge { border-left-color: var(--purple); }

/* ---------- きろく：タブ ---------- */
.tab-bar {
  display: flex;
  gap: 6px;
  margin-bottom: 14px;
  background: rgba(255, 255, 255, 0.6);
  border-radius: 14px;
  padding: 5px;
}

.tab-btn {
  flex: 1;
  position: relative;
  border: none;
  border-radius: 10px;
  padding: 9px 4px;
  font-family: inherit;
  font-size: 14px;
  font-weight: bold;
  background: transparent;
  color: var(--ink);
  cursor: pointer;
}

.tab-btn.active {
  background: var(--paper);
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
}

.tab-panel { display: none; flex-direction: column; }
.tab-panel.active { display: flex; }

/* ---------- きろく：せいせき ---------- */
#records-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.record-card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 14px 18px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.record-name { font-size: 16px; font-weight: bold; }
.record-name small { display: block; font-size: 12px; font-weight: normal; opacity: 0.7; }

.record-nums {
  text-align: right;
  font-size: 13px;
  line-height: 1.6;
}

.record-nums b { font-size: 19px; color: var(--orange-text); }

.danger-btn {
  margin-top: 22px;
  min-height: 44px;
  border: none;
  background: #ffd9d9;
  color: #b53629;
  font-family: inherit;
  font-size: 15px;
  padding: 12px;
  border-radius: 12px;
  cursor: pointer;
  align-self: center;
}

/* ---------- きろく：あしあと（学習ログ） ---------- */
.log-note {
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
  margin: 0 0 10px;
  opacity: 0.75;
}

.log-range {
  align-self: center;
  background: rgba(255, 255, 255, 0.75);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 13px;
  font-weight: bold;
  margin-bottom: 10px;
}

.log-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.log-tile {
  background: var(--paper);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.log-tile-label { font-size: 12px; opacity: 0.7; }

.log-tile-value {
  font-size: 24px;
  font-weight: bold;
  color: var(--orange-text);
  line-height: 1.2;
}

.log-tile-value small { font-size: 13px; margin-left: 2px; }

.log-empty {
  grid-column: 1 / -1;
  background: var(--paper);
  border-radius: 14px;
  padding: 20px 14px;
  box-shadow: var(--shadow);
  text-align: center;
  font-size: 14px;
  line-height: 1.9;
  margin: 0;
}

.log-modes {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 14px;
}

.log-mode {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 34% auto;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border-radius: 12px;
  padding: 9px 12px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
}

.log-mode-name { font-size: 13px; font-weight: bold; line-height: 1.4; }
.log-mode-name small { display: block; font-size: 11px; font-weight: normal; opacity: 0.65; }

.log-mode-bar {
  height: 10px;
  border-radius: 999px;
  background: #e8eef5;
  overflow: hidden;
}

.log-mode-bar span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffd35c, #4cd07d);
}

.log-mode-pct { font-size: 14px; font-weight: bold; color: var(--green-text); min-width: 3.2em; text-align: right; }

.log-title { font-size: 15px; margin: 18px 0 8px; }

.log-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.log-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  background: var(--paper);
  border-radius: 12px;
  padding: 9px 12px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.1);
  border-left: 5px solid var(--green);
}

.log-item.aborted { border-left-color: var(--slot-line); }

.log-item-when { font-size: 12px; font-weight: bold; line-height: 1.3; }
.log-item-when small { display: block; font-size: 11px; font-weight: normal; opacity: 0.65; }

.log-item-body b { font-size: 13px; }
.log-item-body small { display: block; font-size: 11px; opacity: 0.7; line-height: 1.5; }

.log-item-stars { white-space: nowrap; }
.log-item-stars .icon { width: 14px; height: 14px; }

@media (min-width: 520px) {
  .log-summary { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

/* ---------- きろく：マップ ---------- */
.map-note {
  font-size: 13px;
  text-align: center;
  line-height: 2;
  margin: 0 0 8px;
}

.cell-sample {
  display: inline-block;
  width: 14px;
  height: 14px;
  border-radius: 4px;
  vertical-align: -2px;
  margin: 0 3px 0 10px;
}

.cs-green { background: #4cd07d; }
.cs-yellow { background: #ffd35c; }
.cs-red { background: #ff8f8f; }
.cs-gray { background: #dfe5ec; }

.map-title {
  font-size: 16px;
  margin: 12px 0 6px;
}

.map-title .icon { width: 18px; height: 18px; vertical-align: -3px; }
.mt-add { color: #e0508a; }
.mt-sub { color: var(--blue-text); }

.map-scroll { overflow-x: auto; }

.fact-map table {
  border-collapse: separate;
  border-spacing: 3px;
  margin: 0 auto;
}

.fact-map th {
  font-size: clamp(12px, 2.8vw, 15px);
  font-weight: bold;
  color: #778;
  min-width: clamp(26px, 6vw, 36px);
  height: clamp(26px, 6vw, 36px);
}

.fact-map td {
  width: clamp(26px, 6vw, 36px);
  height: clamp(26px, 6vw, 36px);
  border-radius: 6px;
}

.cell-green { background: #4cd07d; }
.cell-yellow { background: #ffd35c; }
.cell-red { background: #ff8f8f; }
.cell-gray { background: #dfe5ec; }
.cell-na { background: transparent; }

/* ---------- きろく：カレンダー ---------- */
.cal-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

#cal-title { font-size: 17px; font-weight: bold; }

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.cal-head {
  text-align: center;
  font-size: 12px;
  font-weight: bold;
  color: #889;
  padding: 4px 0;
}

.cal-cell {
  background: var(--paper);
  border-radius: 10px;
  min-height: 52px;
  padding: 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.06);
}

.cal-today { outline: 3px solid var(--orange); }

.cal-day { font-size: 12px; font-weight: bold; }

.cal-stamp {
  min-height: 20px;
  display: flex;
  align-items: center;
}

.cal-stamp .icon { width: 17px; height: 17px; }
.stamp-star { color: #ffb400; }
.stamp-check { color: var(--green); }

.cal-legend {
  text-align: center;
  font-size: 12px;
  opacity: 0.75;
  margin-top: 10px;
}

.cal-legend .icon { width: 15px; height: 15px; vertical-align: -3px; }

/* ---------- きろく：バッジ ---------- */
.badge-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.badge-card {
  background: var(--paper);
  border-radius: 14px;
  padding: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08);
  opacity: 0.55;
}

.badge-card.earned { opacity: 1; box-shadow: var(--shadow); }

.badge-icon {
  width: 46px;
  height: 46px;
  border-radius: 14px;
  background: #f3eefb;
  color: #8a53c4;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.badge-icon .icon { width: 26px; height: 26px; }

.badge-icon.locked { background: #eef1f5; color: #9aa3ad; }

.badge-text b { font-size: 13px; display: block; }
.badge-text small { font-size: 11px; opacity: 0.75; display: block; line-height: 1.4; }
.badge-date { color: var(--green-text); }

@media (max-width: 400px) {
  .badge-list { grid-template-columns: 1fr; }
}

/* ---------- せのひくい画面（よこむきスマホなど）むけ ---------- */
@media (max-height: 560px) {
  :root {
    --eq-font: clamp(28px, 8vh, 44px);
    --key-h: clamp(42px, 9vh, 54px);
    --key-font: 22px;
    --slot-size: clamp(26px, 6.5vh, 40px);
    --cherry-r: 40px;
    --cherry-gap: 16px;
  }
  #equation { min-height: 80px; }
  #block-stage { min-height: 100px; }
  #prompt-box { margin: 4px 0 2px; min-height: 40px; }
  #prompt { font-size: 16px; }
  #answer-display { height: 46px; min-width: 58px; font-size: 26px; }
  #feedback { min-height: 20px; font-size: 15px; }
  #task-bar { margin: 0; gap: 8px; }
  #task-remain { padding: 3px 12px; font-size: 14px; }
  .task-auto { padding: 5px 12px; font-size: 13px; }
  .group-caption { font-size: 11px; padding: 1px 8px; }
  #keypad { gap: 6px; margin-top: 4px; }
  .play-header { margin-bottom: 2px; }
  .cherry-circle { font-size: 20px; }
  .mk-under { font-size: 19px; }
  #equation.has-under { padding-bottom: 18px; }
}

/* ---------- あたり判定だけを 44px に ひろげる（§2-9） ----------
   実測で 44px に とどいていなかった もの。
   .tab-btn 118.8×36 ／ .free-op 46×34 ／ .task-auto 147.9×34 ／
   .free-method-btn 298×40.2（かくれた 状態を 出して はじめて 見つかった）
   ヨコに ならぶ .free-method-btn は すきま 8px。上下に 2px ずつ しか
   はみ出さないので、となりと かさならない。 */
.tab-btn::after,
.free-op::after,
.free-method-btn::after,
.task-auto::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  height: 100%;
  min-width: 44px;
  min-height: 44px;
}

/* ---------- 提示モード（電子黒板・一斉授業）§2-11 ----------
   先生が「大きく表示」を おすと body に .presentation が つく。
   教室の うしろの せきから 読めることが 要件なので、
   文字も ボタンも まとめて 大きくする。
   このアプリは 児童の 名前・出席番号を 一切 もたないため、
   提示モードで ふせる 個人情報は ない。 */
body.presentation { font-size: 150%; }

body.presentation .mode-name   { font-size: 26px; }
body.presentation .mode-desc   { font-size: 16px; }
body.presentation .menu-main   { font-size: clamp(22px, 6vw, 30px); }
body.presentation .menu-small,
body.presentation .menu-example { font-size: 17px; }
body.presentation .logo-text   { font-size: 27px; }
body.presentation .mission-title,
body.presentation .level-title { font-size: 20px; }
body.presentation .mission-desc,
body.presentation .day-streak  { font-size: 17px; }

body.presentation .mode-card,
body.presentation .menu-btn,
body.presentation .explain-btn,
body.presentation .howto-next,
body.presentation .task-auto,
body.presentation .danger-btn  { min-height: 64px; }
body.presentation .icon-btn    { width: 56px; height: 56px; }
body.presentation .icon-btn .icon { width: 28px; height: 28px; }
body.presentation .tab-btn     { font-size: 18px; padding: 14px 6px; }

body.presentation #prompt      { font-size: clamp(22px, 3.4vw, 34px); }
body.presentation .howto-list  { font-size: clamp(18px, 2.6vw, 26px); }
body.presentation #app         { max-width: none; }

/* 大画面では よはくを いかして 主役（しき）を 大きく */
body.presentation { --eq-font: clamp(52px, 9vw, 130px); }
@media (min-width: 1600px) {
  body.presentation {
    --eq-font: clamp(64px, 8vw, 160px);
    --slot-size: clamp(48px, 4.6vw, 76px);
    --cherry-r: clamp(56px, 5.4vw, 88px);
  }
}

/* おしている あいだ わかるように */
.btn-present[aria-pressed="true"] {
  background: var(--blue-surface);
  color: #fff;
}

/* ---------- あたらしい ばんの おしらせ ----------
   したに 出す ので、ホームバーの ぶんを かならず たす。 */
.update-bar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  z-index: 250;
  width: min(94vw, 520px);
  margin-bottom: calc(12px + var(--safe-b));
  background: var(--paper);
  border-radius: 16px;
  border-left: 6px solid var(--orange-surface);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.22);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.update-text {
  font-size: clamp(15px, 3.6vw, 17px);
  font-weight: bold;
  color: var(--ink);
}

.update-btn {
  min-height: 44px;
  border: none;
  border-radius: 999px;
  padding: 10px 20px;
  font-family: inherit;
  font-size: clamp(15px, 3.6vw, 17px);
  font-weight: bold;
  background: var(--orange-surface);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.15);
}

.update-btn:active { transform: translateY(2px); box-shadow: none; }
.update-btn:focus-visible { outline: 3px solid var(--blue-surface); outline-offset: 3px; }

@media (forced-colors: active) {
  .update-bar { border: 2px solid CanvasText; }
  .update-btn { border: 2px solid ButtonText; }
}
