:root {
  --bg: #FFF8EE;
  --card: #FFFFFF;
  --ink: #2B2420;
  --sub: #7A6E66;
  --line: #EADFD3;
  --accent: #FF8A3D;
  --accent-dark: #E06A1B;
  --ok: #2E9E6B;
  --ng: #D9485F;
  --weak: #F7A1AE;
  --slow: #FFD98A;
  --good: #A8DFC2;
  --none: #F2ECE6;
  --radius: 18px;
  --font: "Hiragino Maru Gothic ProN", "Hiragino Sans", "BIZ UDPGothic", "Yu Gothic UI", system-ui, sans-serif;
  --num: "SF Pro Rounded", "Hiragino Maru Gothic ProN", ui-rounded, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font-family: var(--font);
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
#app {
  max-width: 560px; margin: 0 auto; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 24px);
}
button { font-family: inherit; color: inherit; touch-action: manipulation; cursor: pointer; }
.loading { text-align: center; color: var(--sub); margin-top: 40vh; }

/* 共通 */
.card { background: var(--card); border-radius: var(--radius); padding: 20px; box-shadow: 0 2px 0 var(--line); margin-bottom: 16px; }
.btn {
  display: block; width: 100%; border: 0; border-radius: 999px; padding: 16px; font-size: 18px; font-weight: 700;
  background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark);
}
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--accent-dark); }
.btn.secondary { background: #fff; color: var(--ink); box-shadow: 0 4px 0 var(--line); border: 2px solid var(--line); }
.btn.small { display: inline-block; width: auto; padding: 8px 16px; font-size: 14px; }
.btn[disabled] { opacity: .5; }
.link { background: none; border: 0; color: var(--sub); text-decoration: underline; font-size: 14px; padding: 8px; }
.muted { color: var(--sub); font-size: 14px; }
.row { display: flex; gap: 12px; align-items: center; }
.row > * { flex: 1; }
.spacer { height: 12px; }
.notice { background: #FFF1D6; border-radius: 12px; padding: 10px 14px; font-size: 14px; margin-bottom: 12px; }
.error { background: #FDE3E7; color: #8A1C2E; border-radius: 12px; padding: 10px 14px; font-size: 14px; margin: 12px 0; }
.demo-bar { background: #2B2420; color: #fff; border-radius: 12px; padding: 8px 12px; font-size: 13px; display: flex; gap: 8px; align-items: center; margin-bottom: 12px; }
.demo-bar button { background: #fff2; color: #fff; border: 1px solid #fff5; border-radius: 999px; padding: 4px 10px; font-size: 13px; }
.demo-bar span { flex: 1; }

/* ログイン */
.login h1 { text-align: center; font-size: 28px; margin: 24px 0 8px; }
.login label { display: block; font-size: 14px; color: var(--sub); margin: 14px 0 6px; }
.login input { width: 100%; font-size: 17px; padding: 14px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-family: inherit; }
.login input:focus { outline: none; border-color: var(--accent); }
.version-line { text-align: center; margin-top: 16px; }

/* 子ども: ホーム */
.hello { font-size: 22px; font-weight: 700; margin: 8px 4px 16px; }
.today { text-align: center; padding: 28px 20px; }
.today .label { color: var(--sub); font-size: 15px; }
.today .dans { font-size: 34px; font-weight: 800; margin: 8px 0 4px; letter-spacing: .02em; }
.today .mode { display: inline-block; background: #FFE8D6; color: var(--accent-dark); border-radius: 999px; padding: 4px 14px; font-weight: 700; margin-bottom: 20px; }

.streak { text-align: center; font-size: 15px; color: var(--sub); }

/* 子ども: 出題 */
.play { display: flex; flex-direction: column; flex: 1; }
.play-top { display: flex; justify-content: space-between; align-items: center; font-size: 16px; color: var(--sub); }
.progress { height: 10px; background: var(--line); border-radius: 999px; overflow: hidden; margin: 8px 0 0; }
.progress > div { height: 100%; background: var(--accent); transition: width .25s; }
.question { flex: 1; display: flex; flex-direction: column; justify-content: center; align-items: center; min-height: 110px; }
.q-text { font-family: var(--num); font-size: clamp(44px, min(16vw, 9dvh), 76px); font-weight: 800; white-space: nowrap; }
.q-input {
  font-family: var(--num); font-size: clamp(40px, min(15vw, 8dvh), 72px); font-weight: 800; min-width: 2.6em; text-align: center;
  border-bottom: 5px solid var(--accent); margin-top: 6px; min-height: 1.25em; line-height: 1.2;
}
.q-feedback { min-height: 28px; margin-top: 10px; text-align: center; font-size: 20px; font-weight: 700; }
.q-feedback.ng { color: var(--ng); }
.q-feedback.ok { color: var(--ok); }
.q-feedback.hint { color: var(--accent-dark); }
.shake { animation: shake .35s; }
@keyframes shake { 20%,60% { transform: translateX(-10px); } 40%,80% { transform: translateX(10px); } }
.pop { animation: pop .3s; }
@keyframes pop { 50% { transform: scale(1.12); } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; user-select: none; -webkit-user-select: none; }
.key {
  font-family: var(--num); font-size: 32px; font-weight: 800; height: clamp(48px, 8dvh, 68px); border-radius: 16px; border: 0;
  background: #fff; box-shadow: 0 4px 0 var(--line);
}
.key:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--line); background: #FFF3EA; }
.key.del { font-size: 18px; font-family: var(--font); color: var(--sub); }
.key.enter { grid-column: 1 / -1; background: var(--accent); color: #fff; font-family: var(--font); font-size: 24px; box-shadow: 0 4px 0 var(--accent-dark); }
.key.enter:active { box-shadow: 0 1px 0 var(--accent-dark); background: var(--accent); }
.quit { align-self: flex-start; }

/* 子ども: 結果 */
.result { text-align: center; }
.result .big { font-size: 64px; margin: 8px 0; }
.result h2 { font-size: 26px; margin: 4px 0 16px; }
.stats { display: flex; gap: 12px; margin: 0 0 16px; }
.stat { flex: 1; background: var(--bg); border-radius: 14px; padding: 14px 8px; }
.stat .v { font-family: var(--num); font-size: 30px; font-weight: 800; }
.stat .k { font-size: 13px; color: var(--sub); }
.wrong-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0 4px; }
.wrong-list span { background: #FDE3E7; border-radius: 10px; padding: 6px 10px; font-family: var(--num); font-weight: 700; font-size: 18px; }
.sync { font-size: 14px; color: var(--sub); margin: 12px 0; }

/* 保護者 */
.p-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.p-head h1 { font-size: 20px; margin: 0; }
.tabs { display: flex; background: #fff; border-radius: 999px; padding: 4px; margin-bottom: 16px; box-shadow: 0 2px 0 var(--line); }
.tabs button { flex: 1; border: 0; background: none; padding: 10px 4px; border-radius: 999px; font-size: 15px; font-weight: 700; color: var(--sub); }
.tabs button.on { background: var(--accent); color: #fff; }
.select { width: 100%; font-size: 16px; padding: 10px; border-radius: 12px; border: 2px solid var(--line); background: #fff; font-family: inherit; margin-bottom: 12px; }
.sess { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; padding: 14px 4px; border-bottom: 1px solid var(--line); width: 100%; text-align: left; background: none; border-left: 0; border-right: 0; border-top: 0; font-size: 15px; }
.sess:last-child { border-bottom: 0; }
.sess .when { font-weight: 700; }
.sess .meta { color: var(--sub); font-size: 13px; }
.sess .score { grid-row: 1 / span 2; grid-column: 2; align-self: center; text-align: right; font-family: var(--num); }
.sess .score b { font-size: 18px; }
.badge { display: inline-block; border-radius: 999px; padding: 2px 8px; font-size: 12px; font-weight: 700; }
.badge.ng { background: #FDE3E7; color: var(--ng); }
.badge.ok { background: #DDF3E8; color: var(--ok); }
table.detail { width: 100%; border-collapse: collapse; font-size: 15px; }
table.detail th, table.detail td { padding: 8px 4px; border-bottom: 1px solid var(--line); text-align: left; }
table.detail th { color: var(--sub); font-size: 12px; font-weight: 400; }
table.detail td.q { font-family: var(--num); font-weight: 700; white-space: nowrap; }
.tries span { display: inline-block; margin-right: 6px; font-family: var(--num); }
.tries .x { color: var(--ng); text-decoration: line-through; }
.tries .o { color: var(--ok); font-weight: 700; }
.slowmark { color: #B7791F; font-weight: 700; }

.grid9 { display: grid; grid-template-columns: 28px repeat(9, 1fr); gap: 3px; font-family: var(--num); }
.grid9 .h { font-size: 12px; color: var(--sub); display: flex; align-items: center; justify-content: center; }
.grid9 button { aspect-ratio: 1; border: 0; border-radius: 8px; font-size: 12px; font-weight: 700; padding: 0; color: #4a3f38; }
.grid9 button.sel { outline: 3px solid var(--ink); }
.lv-weak { background: var(--weak); } .lv-slow { background: var(--slow); } .lv-good { background: var(--good); } .lv-none { background: var(--none); color: #b9aea5 !important; }
.legend { display: flex; flex-wrap: wrap; gap: 12px; font-size: 12px; color: var(--sub); margin-top: 12px; }
.legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; vertical-align: -1px; margin-right: 4px; }
.cell-info { margin-top: 12px; font-size: 14px; min-height: 40px; }
.weak-list { display: flex; flex-wrap: wrap; gap: 8px; }
.weak-list span.lv-slow { background: var(--slow); }
.weak-list span { background: #FDE3E7; border-radius: 10px; padding: 6px 10px; font-family: var(--num); font-weight: 700; }

.chips { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.chip { border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 10px 0; font-size: 16px; font-weight: 700; }
.chip.on { border-color: var(--accent); background: #FFE8D6; color: var(--accent-dark); }
.seg { display: flex; gap: 8px; }
.seg button { flex: 1; border: 2px solid var(--line); background: #fff; border-radius: 14px; padding: 12px 0; font-size: 16px; font-weight: 700; }
.seg button.on { border-color: var(--accent); background: #FFE8D6; color: var(--accent-dark); }
.field-label { font-size: 14px; color: var(--sub); margin: 16px 0 8px; font-weight: 700; }
.field-label:first-child { margin-top: 0; }
.saved { color: var(--ok); font-size: 14px; text-align: center; margin-top: 10px; min-height: 20px; }

@media (min-width: 760px) {
  #app { max-width: 720px; }
}

/* 子ども: 出し方ボタン */
.mode-btns { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 18px; }
.mode-col { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.mode-btn {
  width: 100%; border: 0; border-radius: 20px; padding: 18px 4px 14px; color: #fff; display: flex; flex-direction: column; align-items: center; gap: 4px;
  box-shadow: 0 5px 0 rgba(0,0,0,.18);
}
.mode-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.mb-name { font-size: clamp(20px, 6vw, 26px); font-weight: 800; }
.mb-n { font-size: 13px; opacity: .9; }
.m-agari { background: #3BA7E8; } .m-sagari { background: #8A6CE0; } .m-bara { background: var(--accent); }
.mode-count { margin-top: 6px; font-size: 15px; font-weight: 700; color: var(--sub); }
.mode-count.done { color: var(--ok); }
.mode-time { font-family: var(--num); font-size: 14px; color: var(--sub); }
.mode-best { font-family: var(--num); font-size: 14px; font-weight: 700; color: #B7791F; }
.streak { margin: 4px 0 14px; }

/* 子ども: きろく */
.rec-head { display: flex; align-items: center; gap: 4px; margin-bottom: 8px; }
.rec-head h2 { font-size: 20px; margin: 0; }
.best-cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.best-card { background: #FFF6DB; border-radius: 14px; padding: 12px 4px; text-align: center; }
.bc-mode { font-weight: 800; }
.bc-trophy { font-size: 28px; }
.bc-time { font-family: var(--num); font-size: 24px; font-weight: 800; }
.bc-date { font-size: 12px; color: var(--sub); }
.rec-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 12px 6px; border-bottom: 1px solid var(--line); }
.rec-row:last-child { border-bottom: 0; }
.rec-row.is-best { background: #FFF6DB; border-radius: 10px; }
.rr-when { font-weight: 700; font-size: 15px; }
.rr-mode { font-size: 13px; color: var(--sub); }
.rr-time { grid-row: 1; grid-column: 2; text-align: right; font-family: var(--num); font-weight: 800; font-size: 18px; }
.rr-wrong { grid-column: 2; text-align: right; font-size: 13px; color: var(--sub); }

/* 子ども: お祝い */
#confetti { position: fixed; inset: 0; width: 100vw; height: 100vh; pointer-events: none; z-index: 10; }
.celebrate { position: relative; overflow: visible; background: linear-gradient(180deg, #FFF3C4 0%, #fff 55%); animation: cardIn .5s cubic-bezier(.2,1.4,.4,1) both; }
@keyframes cardIn { from { transform: scale(.6) translateY(40px); opacity: 0; } }
.medal { font-size: 88px !important; display: inline-block; animation: medalIn .9s cubic-bezier(.2,1.6,.4,1) .15s both, wiggle 2.2s ease-in-out 1.2s infinite; }
@keyframes medalIn { from { transform: scale(0) rotate(-200deg); } }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-10deg) scale(1.05); } 75% { transform: rotate(10deg) scale(1.05); } }
.title-pop { animation: titleIn .6s cubic-bezier(.2,1.5,.4,1) .45s both; color: var(--accent-dark); }
@keyframes titleIn { from { transform: scale(.3); opacity: 0; } }
.mode-done { font-weight: 700; color: var(--sub); margin-bottom: 8px; animation: fadeUp .4s ease .6s both; }
.new-best { display: inline-block; background: linear-gradient(90deg, #FFD23F, #FF8A3D); color: #fff; font-weight: 800; font-size: 20px;
  padding: 8px 18px; border-radius: 999px; margin: 4px 0 14px; box-shadow: 0 4px 0 #E06A1B; animation: titleIn .6s cubic-bezier(.2,1.6,.4,1) .8s both, glow 1.4s ease-in-out 1.5s infinite; }
@keyframes glow { 50% { transform: scale(1.06); box-shadow: 0 4px 18px #FFD23F; } }
.best-line { font-family: var(--num); font-weight: 700; color: #B7791F; margin: 0 0 12px; animation: fadeUp .4s ease .8s both; }
.pop-in { animation: fadeUp .45s cubic-bezier(.2,1.4,.4,1) var(--d, .5s) both; }
@keyframes fadeUp { from { transform: translateY(16px) scale(.9); opacity: 0; } }
.burst { position: absolute; left: 50%; top: 70px; width: 0; height: 0; pointer-events: none; }
.burst span { position: absolute; font-size: 26px; transform: translate(-50%, -50%); animation: burst 1.1s ease-out calc(.25s + var(--i) * .03s) both; }
@keyframes burst {
  0% { transform: translate(-50%, -50%) rotate(calc(var(--i) * 45deg)) translateY(0) scale(.2); opacity: 0; }
  30% { opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(calc(var(--i) * 45deg)) translateY(-120px) scale(1.1); opacity: 0; }
}
@media (prefers-reduced-motion: reduce) {
  .medal, .new-best { animation: none !important; }
}
