:root {
  --bg: #fff4de;
  --ink: #4a3426;
  --sub: #8a6a55;
  --wood: #d49a5c;
  --wood-dark: #a8703a;
  --board: #fffdf7;
  --red: #e8473f;
  --blue: #2f7de1;
  --rod: #9aa0a6;
  --green: #3aa76d;
  --yellow: #ffd24a;
  --card: #ffffff;
  --shadow: 0 6px 0 rgba(74, 52, 38, .18);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Maru Gothic Pro", "BIZ UDGothic", "Yu Gothic UI", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; touch-action: manipulation;
  overscroll-behavior: none;
}
#app { position: fixed; inset: 0; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; }
button { font-family: inherit; color: inherit; border: none; cursor: pointer; touch-action: manipulation; }

/* ---- タイトル ---- */
.title-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2vh; }
.title-mascot { width: min(30vh, 34vw); animation: bounce 1.6s ease-in-out infinite; }
.title-text { font-size: min(10vh, 11vw); font-weight: 800; letter-spacing: .08em; margin: 0; }
.title-text .r { color: var(--red); } .title-text .b { color: var(--blue); }
.menu { display: flex; gap: 3vw; flex-wrap: wrap; justify-content: center; }
.big-btn {
  font-size: min(4.6vh, 5vw); font-weight: 800; padding: 2.2vh 4vw; border-radius: 999px;
  background: var(--card); box-shadow: var(--shadow); min-width: 22vw;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(74, 52, 38, .18); }
.big-btn.primary { background: var(--red); color: #fff; }
.big-btn.blue { background: var(--blue); color: #fff; }
.big-btn.green { background: var(--green); color: #fff; }
.parent-btn {
  position: absolute; right: 2vw; bottom: 2vh; font-size: 14px; padding: 10px 14px; border-radius: 12px;
  background: rgba(255, 255, 255, .7); color: var(--sub);
}
.parent-btn .fill { position: absolute; left: 0; bottom: 0; height: 4px; width: 0; background: var(--sub); border-radius: 2px; }
.loading { position: absolute; bottom: 12vh; font-size: 18px; color: var(--sub); }

/* ---- 上の帯 ---- */
.topbar { width: 100%; display: flex; align-items: center; justify-content: space-between; padding: 1.5vh 2vw 0; }
.home-btn { font-size: 18px; padding: 10px 16px; border-radius: 14px; background: rgba(255, 255, 255, .8); box-shadow: 0 3px 0 rgba(74, 52, 38, .12); }
.dots { display: flex; gap: 8px; }
.dot { width: 18px; height: 18px; border-radius: 50%; background: #ead9bf; }
.dot.done { background: var(--yellow); box-shadow: 0 0 0 2px #e0ac1a inset; }
.dot.miss { background: #f3c6a8; }
.dot.now { outline: 3px solid var(--blue); outline-offset: 2px; }

/* ---- 問題の画面 ---- */
.lesson { justify-content: flex-start; }
.prompt-row { width: 100%; display: flex; align-items: center; gap: 2vw; padding: 1vh 4vw 0; min-height: 15vh; }
.mascot { width: min(14vh, 13vw); flex: none; transition: transform .2s; }
.mascot.jump { animation: jump .6s ease; }
.mascot.tilt { animation: tilt .8s ease; }
.bubble {
  position: relative; background: #fff; border-radius: 28px; padding: 1.6vh 2.4vw; font-size: min(4.4vh, 4.2vw);
  font-weight: 800; line-height: 1.35; box-shadow: var(--shadow); flex: 1;
}
.bubble::before { content: ""; position: absolute; left: -16px; top: 50%; margin-top: -12px; border: 12px solid transparent; border-right: 16px solid #fff; border-left: 0; }
.replay { flex: none; width: 64px; height: 64px; border-radius: 50%; background: #fff; box-shadow: var(--shadow); font-size: 28px; }

.scene { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; gap: 3vw; min-height: 0; padding: 1vh 4vw; }
.target-num { font-size: min(22vh, 20vw); font-weight: 800; color: var(--ink); line-height: 1; }
.train { height: min(24vh, 30vw); }
.frame10 { display: grid; grid-template-columns: repeat(5, 1fr); gap: min(1.2vh, 1vw); padding: min(1.4vh, 1.2vw); background: #fff; border-radius: 18px; box-shadow: var(--shadow); }
.frame10 .cell { width: min(10vh, 8vw); height: min(10vh, 8vw); border-radius: 12px; background: #f6efe3; display: flex; align-items: center; justify-content: center; }
.frame10 .cell img { width: 90%; height: 90%; object-fit: contain; }
.frame10 .cell img.pop { animation: pop .5s ease; }
.frame10 .cell.newc { background: #ffe9a3; box-shadow: 0 0 0 3px #f5c242 inset; }
.frame10 .cell img.gone { opacity: .12; transform: scale(.6); transition: all .6s ease; }

.choices { display: flex; gap: 3vw; padding-bottom: 1vh; min-height: 13vh; align-items: center; }
.choice {
  width: min(12vh, 13vw); height: min(12vh, 13vw); border-radius: 50%; font-size: min(7vh, 7vw); font-weight: 800;
  background: #fff; box-shadow: var(--shadow);
}
.choice:active { transform: translateY(4px); }
.choice.right { background: var(--green); color: #fff; }
.choice.wrong { background: #e9e2d8; color: #b9aa98; }

/* ---- そろばん（1段） ---- */
.abacus { width: min(92vw, 150vh); padding: 1.6vh 2vw 2.4vh; margin-bottom: 2vh; background: var(--wood); border-radius: 22px; box-shadow: inset 0 -6px 0 var(--wood-dark), var(--shadow); }
.abacus .board { position: relative; background: var(--board); border-radius: 12px; }
.row { position: relative; width: 100%; }
.row .rod { position: absolute; left: 0; right: 0; top: 50%; height: 6px; margin-top: -3px; background: var(--rod); border-radius: 3px; }
.bead {
  position: absolute; top: 50%; border-radius: 50%; transform: translate(0, -50%);
  transition: left .28s cubic-bezier(.3, 1.3, .5, 1);
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .55) 0 18%, transparent 19%), var(--c);
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .18);
}
.bead.red { --c: var(--red); } .bead.blue { --c: var(--blue); }
.bead.hint { animation: wiggle .8s ease infinite; }
.count-badge { position: absolute; right: 12px; top: -46px; font-size: 30px; font-weight: 800; background: #fff; border-radius: 14px; padding: 2px 14px; box-shadow: var(--shadow); }
.bead .lbl { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 800; opacity: 0; transition: opacity .2s; text-shadow: 0 1px 2px rgba(0, 0, 0, .35); pointer-events: none; }
.bead.on .lbl { opacity: 1; }

/* ---- じゆうモード（12段） ---- */
.free .abacus { flex: 1; min-height: 0; display: flex; margin-bottom: 1.5vh; }
.free .board { flex: 1; display: flex; flex-direction: column; justify-content: space-around; padding: 0.6vh 0; }
.free .row { flex: 1; }
.free-tools { display: flex; align-items: center; gap: 2vw; }
.total { font-size: 34px; font-weight: 800; background: #fff; border-radius: 16px; padding: 4px 18px; box-shadow: var(--shadow); min-width: 120px; text-align: center; }

/* ---- シール ---- */
.reward { justify-content: center; gap: 3vh; }
.reward .sticker-big { width: min(40vh, 40vw); animation: spinIn 1s ease; }
.reward h2 { font-size: min(6vh, 6vw); margin: 0; }
.book { display: grid; grid-template-columns: repeat(5, 1fr); gap: 2vw; padding: 3vh 4vw; }
.slot { width: min(22vh, 15vw); height: min(22vh, 15vw); border-radius: 24px; background: #fff; box-shadow: var(--shadow); display: flex; align-items: center; justify-content: center; position: relative; }
.slot img { width: 85%; height: 85%; object-fit: contain; }
.slot.locked img { filter: brightness(0); opacity: .1; }
.slot .n { position: absolute; right: 8px; bottom: 6px; font-size: 18px; font-weight: 800; color: var(--sub); }

/* ---- おうちのかたへ ---- */
.parent { overflow-y: auto; align-items: stretch; padding: 3vh 5vw; font-family: system-ui, -apple-system, "Hiragino Sans", "Yu Gothic UI", sans-serif; }
.parent h2 { margin: 0 0 8px; font-size: 24px; }
.parent p { margin: 4px 0 16px; color: var(--sub); line-height: 1.6; font-size: 15px; }
.parent table { width: 100%; border-collapse: collapse; background: #fff; border-radius: 12px; overflow: hidden; font-size: 15px; }
.parent th, .parent td { padding: 10px 12px; border-bottom: 1px solid #f0e6d8; text-align: left; vertical-align: middle; }
.parent td.num { text-align: right; font-variant-numeric: tabular-nums; }
.parent th { background: #f7efe2; font-weight: 600; }
.hist { display: inline-flex; gap: 3px; }
.hist i { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: #ddd; }
.hist i.o { background: var(--green); } .hist i.x { background: #e8a07a; }
.parent .actions { margin-top: 20px; display: flex; gap: 12px; }
.parent .actions button { padding: 12px 18px; border-radius: 12px; background: #fff; box-shadow: 0 3px 0 rgba(74, 52, 38, .12); font-size: 15px; }

/* ---- 演出 ---- */
.burst { position: fixed; pointer-events: none; font-size: 54px; animation: burst 1s ease forwards; z-index: 10; }
@keyframes bounce { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-14px); } }
@keyframes jump { 0% { transform: translateY(0); } 40% { transform: translateY(-30px) rotate(-8deg); } 100% { transform: translateY(0); } }
@keyframes tilt { 0%, 100% { transform: rotate(0); } 30% { transform: rotate(-12deg); } 60% { transform: rotate(10deg); } }
@keyframes pop { 0% { transform: scale(.2); } 70% { transform: scale(1.15); } 100% { transform: scale(1); } }
@keyframes wiggle { 0%, 100% { margin-left: 0; } 25% { margin-left: -4px; } 75% { margin-left: 4px; } }
@keyframes spinIn { 0% { transform: scale(0) rotate(-180deg); } 100% { transform: scale(1) rotate(0); } }
@keyframes burst { 0% { transform: translate(-50%, -50%) scale(.3); opacity: 1; } 100% { transform: translate(-50%, -160%) scale(1.4); opacity: 0; } }
