:root {
  --bg: #fff8ef;
  --ink: #5a4a42;
  --sub: #9a8a80;
  --pink: #ff8fab;
  --pink-d: #e5728f;
  --blue: #7cc6fe;
  --blue-d: #5aa8e0;
  --green: #8fd694;
  --green-d: #6fb874;
  --yellow: #ffe066;
  --card: #ffffff;
  --line: #f0e2d6;
  --kid: #ff8fab;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', 'Yu Gothic UI', sans-serif;
  font-weight: 500;
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}
button { font-family: inherit; color: inherit; cursor: pointer; }
#app { max-width: 560px; margin: 0 auto; }

.screen {
  display: none;
  flex-direction: column;
  gap: 14px;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
}
.screen.active { display: flex; animation: fadein .25s ease; }
@keyframes fadein { from { opacity: 0; transform: translateY(6px); } }

/* ヘッダー */
.top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 48px; }
.logo { margin: 0; font-size: 28px; font-weight: 800; color: var(--pink-d); letter-spacing: .04em; }
.logo span { color: var(--blue-d); }
.lead { margin: 4px 0 0; font-size: 26px; font-weight: 800; text-align: center; }
.hint { text-align: center; color: var(--sub); font-size: 12px; margin-top: auto; }
.name-tag { font-size: 20px; font-weight: 800; padding: 6px 14px; background: var(--card); border-radius: 999px; border: 3px solid var(--kid); }
.back { background: none; border: none; font-size: 17px; color: var(--sub); padding: 10px 4px; font-weight: 800; }
.back.center { align-self: center; }

/* 歯車（長押し） */
.gear { position: relative; width: 48px; height: 48px; border: none; background: var(--card); border-radius: 50%; font-size: 24px; box-shadow: 0 2px 0 var(--line); }
.gear svg { position: absolute; inset: 0; transform: rotate(-90deg); }
.gear .ring { fill: none; stroke: var(--pink); stroke-width: 4; stroke-dasharray: 107; stroke-dashoffset: 107; }
.gear.pressing .ring { transition: stroke-dashoffset 3s linear; stroke-dashoffset: 0; }
.gear span { position: relative; }

/* 子ども選択 */
.kid-list { display: flex; flex-direction: column; gap: 14px; }
.kid-card {
  display: flex; align-items: center; gap: 16px;
  background: var(--card); border: 4px solid var(--c); border-radius: 28px;
  padding: 12px 18px; box-shadow: 0 6px 0 var(--c); text-align: left;
  transition: transform .08s;
}
.kid-card:active { transform: translateY(4px); box-shadow: 0 2px 0 var(--c); }
.kid-card .av { width: 84px; height: 84px; border-radius: 50%; background: color-mix(in srgb, var(--c) 25%, white); display: grid; place-items: center; overflow: hidden; flex: none; }
.kid-card .av svg, .kid-card .av img { width: 76px; height: 76px; object-fit: contain; }
.kid-card .nm { font-size: 28px; font-weight: 800; }
.kid-card .st { font-size: 15px; color: var(--sub); margin-top: 2px; }

/* 大きいボタン */
.big-btn {
  border: none; border-radius: 26px; font-size: 24px; font-weight: 800; color: #fff;
  padding: 20px 16px; background: var(--pink); box-shadow: 0 7px 0 var(--pink-d);
  transition: transform .08s; letter-spacing: .03em;
}
.big-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 var(--pink-d); }
.big-btn.blue { background: var(--blue); box-shadow: 0 7px 0 var(--blue-d); }
.big-btn.green { background: var(--green); box-shadow: 0 7px 0 var(--green-d); }
.big-btn.small { font-size: 19px; padding: 16px 10px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ホーム */
.hero { display: grid; place-items: center; padding: 6px 0; }
.hero .chr { width: min(56vw, 230px); height: min(56vw, 230px); animation: bob 2.4s ease-in-out infinite; }
.chr svg, .chr img { width: 100%; height: 100%; object-fit: contain; }
.chr img { border-radius: 24px; }
@keyframes bob { 50% { transform: translateY(-8px); } }
.today { display: flex; justify-content: center; gap: 12px; flex-wrap: wrap; }
.pill { background: var(--card); border-radius: 999px; padding: 8px 14px; font-size: 17px; font-weight: 800; border: 2px solid var(--line); }
.pill.on { background: #fff3bf; border-color: #ffd43b; }

/* 泡 */
.bubble-wrap { position: relative; display: grid; place-items: center; }
.bubble-wrap .chr { position: relative; z-index: 1; }
.bubble-wrap::after {
  content: ''; position: absolute; inset: 0; border-radius: 50%; z-index: 2; pointer-events: none;
  background: radial-gradient(circle at 32% 28%, rgba(255,255,255,.95) 0 9%, rgba(255,255,255,0) 10%),
              radial-gradient(circle at 50% 50%, rgba(180,230,255,.15) 55%, rgba(140,200,255,.55) 72%, rgba(255,255,255,.8) 75%, rgba(255,255,255,0) 77%);
  opacity: var(--bub, 1); transition: opacity .4s;
}
.bubble-wrap.big { width: min(72vw, 300px); height: min(72vw, 300px); margin: 0 auto; animation: float 3s ease-in-out infinite; }
.bubble-wrap.big .chr { width: 64%; height: 64%; }
.bubble-wrap.mini { width: 64px; height: 64px; flex: none; }
.bubble-wrap.mini .chr { width: 66%; height: 66%; }
.bubble-wrap.worried { animation: shake .5s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-12px) rotate(2deg); } }
@keyframes shake { 25% { transform: translateX(-4px) rotate(-4deg); } 75% { transform: translateX(4px) rotate(4deg); } }

.intro-box { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 20px; flex: 1; }
.speech { background: var(--card); border-radius: 22px; padding: 12px 20px; font-size: 24px; font-weight: 800; position: relative; border: 3px solid var(--line); margin: 0; }
.speech::after { content: ''; position: absolute; left: 50%; bottom: -14px; border: 8px solid transparent; border-top-color: var(--card); transform: translateX(-50%); }
.intro-text { font-size: 18px; text-align: center; margin: 0; line-height: 1.6; }

/* 歯みがき画面 */
.brush { gap: 10px; }
.cam-wrap { position: relative; width: 100%; aspect-ratio: 3 / 4; max-height: 48dvh; margin: 0 auto; border-radius: 26px; overflow: hidden; background: #ffe9f0; border: 5px solid var(--kid); }
.cam-wrap video, .cam-wrap canvas { position: absolute; inset: 0; width: 100%; height: 100%; transform: scaleX(-1); }
.cam-wrap video { object-fit: fill; }
.nocam { position: absolute; inset: 0; display: none; place-items: center; }
.nocam .chr { width: 55%; height: 55%; animation: bob 1.6s ease-in-out infinite; }
.cam-wrap.no-camera .nocam { display: grid; }
.cam-wrap.no-camera video { display: none; }
.countdown { position: absolute; inset: 0; display: grid; place-items: center; font-size: 120px; font-weight: 800; color: #fff; text-shadow: 0 4px 0 var(--pink-d), 0 0 20px rgba(0,0,0,.2); pointer-events: none; z-index: 3; }
.status { position: absolute; left: 50%; top: 10px; transform: translateX(-50%); background: rgba(255,255,255,.92); border-radius: 999px; padding: 6px 16px; font-size: 18px; font-weight: 800; white-space: nowrap; z-index: 3; }
.status.go { color: #2b8a3e; }
.status.stop { color: #e8590c; }
.meter { position: absolute; left: 10px; right: 10px; bottom: 10px; height: 12px; background: rgba(255,255,255,.7); border-radius: 6px; display: none; z-index: 3; }
.meter.show { display: block; }
.meter i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--green); border-radius: 6px; }
.meter b { position: absolute; top: -3px; bottom: -3px; width: 3px; background: #e03131; }

.zone-panel { display: flex; align-items: center; gap: 10px; background: var(--card); border-radius: 22px; padding: 8px 12px; border: 3px solid var(--line); }
.zone-svg { width: 46%; flex: none; }
.zone-svg svg { width: 100%; display: block; }
.zone-text { flex: 1; }
.zone-step { font-size: 14px; color: var(--sub); font-weight: 800; }
.zone-label { font-size: 22px; font-weight: 800; line-height: 1.3; }
.zone-side { display: inline-block; margin-top: 4px; font-size: 15px; font-weight: 800; background: #fff3bf; border-radius: 999px; padding: 2px 10px; }
.tooth { fill: #fff; stroke: #c9b8ab; stroke-width: 2; transition: fill .3s; }
.tooth.on { fill: #ffe066; stroke: #f59f00; stroke-width: 3; animation: glow 1s ease-in-out infinite; }
.tooth.done { fill: #e7f8ff; }
@keyframes glow { 50% { fill: #fff9db; } }

.progress-row { display: flex; align-items: center; gap: 10px; }
.pbar { flex: 1; height: 22px; background: #fff; border-radius: 11px; border: 3px solid var(--line); overflow: hidden; }
.pbar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--blue), var(--green)); border-radius: 8px; transition: width .3s; }
.time-left { font-size: 18px; font-weight: 800; min-width: 3.2em; text-align: right; }

/* 結果 */
.result-box { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1; justify-content: center; position: relative; z-index: 1; }
.result-title { font-size: 44px; font-weight: 800; color: var(--pink-d); margin: 0; animation: pop .6s cubic-bezier(.2, 1.6, .4, 1); }
.result-char { width: min(64vw, 260px); height: min(64vw, 260px); }
.result-char .chr { width: 100%; height: 100%; animation: jump 0.9s ease-in-out infinite; }
.result-text { font-size: 22px; font-weight: 800; text-align: center; margin: 0; line-height: 1.5; }
.result-stamp { font-size: 18px; }
@keyframes pop { from { transform: scale(.2); opacity: 0; } }
@keyframes jump { 0%, 100% { transform: translateY(0) scale(1, 1); } 15% { transform: translateY(0) scale(1.1, .9); } 45% { transform: translateY(-28px) scale(.95, 1.05); } 70% { transform: translateY(0) scale(1.05, .95); } }
.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.confetti i { position: absolute; top: -20px; width: 10px; height: 16px; border-radius: 3px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

/* ずかん */
.zukan-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.zk { background: var(--card); border-radius: 20px; padding: 8px 4px 6px; text-align: center; border: 3px solid var(--line); }
.zk .chr { width: 100%; aspect-ratio: 1; }
.zk.locked .chr { filter: brightness(0) opacity(.15); }
.zk .nm { font-size: 14px; font-weight: 800; margin-top: 2px; }
.zk .hearts { font-size: 12px; color: var(--pink-d); min-height: 1.2em; }
.zk-big { position: fixed; inset: 0; background: rgba(255, 248, 239, .96); display: grid; place-items: center; z-index: 10; }
.zk-big .inner { text-align: center; }
.zk-big .chr { width: min(70vw, 300px); height: min(70vw, 300px); margin: 0 auto; animation: jump .9s ease-in-out infinite; }
.zk-big p { font-size: 30px; font-weight: 800; margin: 10px 0 0; }

/* カレンダー */
.cal-head { display: flex; align-items: center; justify-content: space-between; }
.cal-nav { border: none; background: var(--card); border-radius: 50%; width: 48px; height: 48px; font-size: 18px; box-shadow: 0 3px 0 var(--line); }
.cal-title { font-size: 24px; font-weight: 800; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 5px; }
.cal-grid .dow { text-align: center; font-size: 13px; color: var(--sub); font-weight: 800; }
.cal-grid .d { background: var(--card); border-radius: 12px; min-height: 58px; padding: 3px; text-align: center; border: 2px solid var(--line); }
.cal-grid .d.today { border-color: var(--kid); }
.cal-grid .d .n { font-size: 13px; color: var(--sub); }
.cal-grid .d .s { font-size: 16px; line-height: 1.1; }
.cal-grid .d .s .off { opacity: .15; filter: grayscale(1); }
.cal-grid .d.full { background: #fff3bf; }
.cal-sum { text-align: center; font-size: 18px; font-weight: 800; }

/* 設定 */
.settings h2 { font-size: 18px; margin: 14px 0 0; padding-bottom: 4px; border-bottom: 3px solid var(--line); }
.note { font-size: 13px; color: var(--sub); margin: 0; line-height: 1.6; }
.note.small { margin-top: 10px; }
.set-kid { background: var(--card); border-radius: 18px; padding: 12px; border: 3px solid var(--c); display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 15px; flex-wrap: wrap; }
.field.check { justify-content: flex-start; }
.field input[type=text] { font: inherit; font-size: 18px; padding: 6px 10px; border-radius: 10px; border: 2px solid var(--line); width: 10em; user-select: text; -webkit-user-select: text; }
.field input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--pink); }
.seg { display: inline-flex; background: #f3ebe4; border-radius: 12px; padding: 3px; }
.seg button { border: none; background: none; font-size: 14px; font-weight: 800; padding: 7px 11px; border-radius: 9px; }
.seg button.on { background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.12); color: var(--pink-d); }
.swatches { display: flex; gap: 6px; }
.swatches button { width: 30px; height: 30px; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px var(--line); }
.swatches button.on { box-shadow: 0 0 0 3px var(--ink); }
.danger { border: none; background: #fff0f0; color: #c92a2a; font-weight: 800; border-radius: 10px; padding: 8px 12px; font-size: 14px; align-self: flex-start; }
.file-btn { display: block; text-align: center; background: var(--blue); color: #fff; font-weight: 800; font-size: 18px; border-radius: 16px; padding: 14px; box-shadow: 0 5px 0 var(--blue-d); cursor: pointer; }
.set-images { display: flex; flex-direction: column; gap: 10px; }
.img-row { display: flex; gap: 10px; background: var(--card); border-radius: 16px; padding: 10px; border: 2px solid var(--line); }
.img-row img { width: 72px; height: 72px; object-fit: contain; border-radius: 12px; background: #f8f3ee; flex: none; }
.img-row .body { flex: 1; display: flex; flex-direction: column; gap: 6px; }
.img-row input[type=text] { font: inherit; font-size: 16px; padding: 4px 8px; border-radius: 8px; border: 2px solid var(--line); width: 100%; user-select: text; -webkit-user-select: text; }
.img-row .kids { display: flex; gap: 10px; flex-wrap: wrap; font-size: 14px; }
.img-row .kids label { display: flex; align-items: center; gap: 3px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-size: 15px; transition: transform .3s; z-index: 20; max-width: 90vw; }
.toast.show { transform: translateX(-50%) translateY(0); }
.back { white-space: nowrap; }
.settings .name-tag { font-size: 16px; white-space: nowrap; }
