:root {
  --bg: #f6f5fb; --card: #ffffff; --ink: #1d1b2f; --ink2: #545169; --ink3: #8a879c;
  --line: #e3e1ee; --line2: #c9c6da; --accent: #4338ca; --accent-ink: #ffffff; --accent-soft: #e8e6fb;
  --ok: #157f3d; --ok-soft: #e3f5e9; --warn: #a15c00; --warn-soft: #fff3dc; --info-soft: #e7f0ff;
  --seg0: #e4e2fc; --seg1: #dcf3e3; --seg2: #fff0cf; --seg3: #ece9f2; --star: #f2a900;
  --radius: 16px; --bar-h: 76px;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  --safe-l: env(safe-area-inset-left, 0px); --safe-r: env(safe-area-inset-right, 0px);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14131c; --card: #1f1d2b; --ink: #f1f0f7; --ink2: #c3c0d4; --ink3: #8f8ca3;
    --line: #34314a; --line2: #4a4664; --accent: #8b83ff; --accent-ink: #120f2a; --accent-soft: #2c2852;
    --ok: #5fd38b; --ok-soft: #173826; --warn: #ffb547; --warn-soft: #3a2b10; --info-soft: #1d2a45;
    --seg0: #2f2b5c; --seg1: #1d3d2a; --seg2: #44361a; --seg3: #302d40; --star: #ffc531;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--ink); overflow-x: hidden; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Noto Sans TC", "Noto Sans CJK TC", "Microsoft JhengHei", system-ui, sans-serif;
  font-size: 17px; line-height: 1.6; -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button, input, textarea, select { font: inherit; color: inherit; }
.wrap { max-width: 560px; margin: 0 auto; padding: 0 calc(16px + var(--safe-r)) calc(var(--bar-h) + 28px + var(--safe-b)) calc(16px + var(--safe-l)); }
.topbar { position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); border-bottom: 1px solid var(--line);
  padding: calc(8px + var(--safe-t)) calc(12px + var(--safe-r)) 8px calc(12px + var(--safe-l)); }
.topbar-in { max-width: 560px; margin: 0 auto; display: flex; align-items: center; gap: 8px; min-height: 44px; }
.brand { flex: 1; min-width: 0; font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { font-weight: 500; color: var(--ink3); font-size: 13px; margin-left: 4px; }
.wallet { font-size: 15px; font-weight: 600; color: var(--ink2); white-space: nowrap; background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; }
.wallet b { color: var(--star); }
.iconbtn { min-width: 44px; min-height: 44px; border: 0; background: transparent; font-size: 22px; border-radius: 12px; cursor: pointer; color: var(--ink); padding: 0 6px; }
.iconbtn:active { background: var(--line); }
h1 { font-size: 24px; line-height: 1.3; margin: 18px 0 6px; }
h2 { font-size: 20px; line-height: 1.35; margin: 26px 0 10px; }
h3 { font-size: 18px; margin: 20px 0 8px; }
p { margin: 10px 0; }
.muted { color: var(--ink2); }
.small { font-size: 15px; }
.kid h2 { font-size: 22px; }
.kid body, .kid .lead { font-size: 19px; }

.callout { border-radius: var(--radius); padding: 12px 14px; margin: 14px 0; font-size: 15.5px; line-height: 1.55; border: 1px solid transparent; }
.callout b.lead { display: block; font-size: 15px; margin-bottom: 2px; }
.callout.info { background: var(--info-soft); }
.callout.ok { background: var(--ok-soft); }
.callout.warn { background: var(--warn-soft); }

.seg { display: flex; background: var(--line); border-radius: 14px; padding: 4px; gap: 4px; margin: 12px 0; }
.seg button { flex: 1; min-height: 44px; border: 0; border-radius: 11px; background: transparent; font-size: 16px; font-weight: 600; color: var(--ink2); cursor: pointer; padding: 6px 4px; line-height: 1.2; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }

.steps { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; margin: 10px 0 4px; }
.steps button { min-height: 56px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); padding: 6px 2px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.15; color: var(--ink); }
.steps button .n { font-size: 12px; color: var(--ink3); }
.steps button .z { font-size: 14px; font-weight: 700; white-space: nowrap; }
.steps button .e { font-size: 10.5px; color: var(--ink3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.steps button.cur { border: 2px solid var(--accent); background: var(--accent-soft); }
.steps button.done .n { color: var(--ok); }
.steps button:disabled { opacity: .45; cursor: default; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 12px 0; }
.choice { display: block; width: 100%; text-align: left; min-height: 64px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin: 10px 0; cursor: pointer; color: var(--ink); }
.choice:active { transform: scale(.99); }
.choice[aria-pressed="true"] { border: 2px solid var(--accent); background: var(--accent-soft); padding: 13px 15px; }
.choice .t { font-size: 17px; font-weight: 700; line-height: 1.4; display: block; }
.choice .s { font-size: 15px; color: var(--ink2); margin-top: 4px; line-height: 1.45; display: block; }
.choice .m { font-size: 14px; color: var(--ink3); margin-top: 6px; display: block; }
.choice .m .stars { color: var(--star); letter-spacing: 1px; }
.kid .choice { min-height: 80px; }
.kid .choice .t { font-size: 20px; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.two .choice { margin: 0; }

.formula { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.formula div { border-radius: 14px; padding: 12px; }
.formula .k { font-size: 13px; color: var(--ink2); font-weight: 600; }
.formula .t { font-size: 17px; font-weight: 700; margin-top: 2px; line-height: 1.3; }
.formula .s { font-size: 15px; color: var(--ink2); margin-top: 4px; }
.kid .formula .t { font-size: 19px; }
.c0 { background: var(--seg0); } .c1 { background: var(--seg1); } .c2 { background: var(--seg2); } .c3 { background: var(--seg3); }

ul.list, ol.list { padding-left: 1.3em; margin: 10px 0; }
ul.list li, ol.list li { margin: 8px 0; }
ul.pro { list-style: none; padding-left: 0; }
ul.pro li::before { content: "✓ "; color: var(--ok); font-weight: 700; }

.hl { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; line-height: 2.15; font-size: 17px; margin: 12px 0; overflow-wrap: anywhere; }
.hl span.sg { border-radius: 6px; padding: 3px 6px; margin-right: 4px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
.hl span.sg.sugg { outline: 1.5px dashed var(--line2); outline-offset: -1px; }
.hl span.tag { font-size: 12.5px; font-weight: 700; color: var(--ink2); margin-right: 6px; }

blockquote { margin: 12px 0; padding: 10px 14px; border-left: 4px solid var(--accent); background: var(--card); border-radius: 0 12px 12px 0; overflow-wrap: anywhere; }
blockquote cite { display: block; font-style: normal; font-size: 13.5px; color: var(--ink3); margin-top: 6px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.chip { min-height: 44px; border-radius: 999px; border: 1px solid var(--line2); background: var(--card); padding: 8px 14px; font-size: 16px; cursor: pointer; color: var(--ink); }
.chip:active { background: var(--accent-soft); }
.badge { display: inline-flex; align-items: center; min-height: 36px; border-radius: 999px; padding: 6px 12px; font-size: 14.5px; background: var(--line); color: var(--ink2); }
.badge.on { background: var(--accent-soft); color: var(--accent); font-weight: 700; }

textarea.answer { width: 100%; min-height: 190px; padding: 14px; border-radius: var(--radius); border: 1px solid var(--line2); background: var(--card); font-size: 17px; line-height: 1.6; resize: vertical; -webkit-appearance: none; appearance: none; }
.kid textarea.answer { font-size: 19px; min-height: 170px; }
textarea.answer:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

.btn { min-height: 48px; border-radius: 14px; border: 1px solid var(--line2); background: var(--card); padding: 10px 16px; font-size: 16px; font-weight: 600; cursor: pointer; color: var(--ink); }
.btn:active { filter: brightness(.95); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.rec { background: #d92d20; color: #fff; border-color: #d92d20; }
.btnrow { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.btnrow .btn { flex: 1 1 auto; }

.timer { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 12px 0; }
.switch { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; cursor: pointer; font-size: 16px; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 52px; height: 32px; border-radius: 999px; background: var(--line2); position: relative; transition: background .2s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.25); }
.switch input:checked + .track { background: var(--ok); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--accent); outline-offset: 2px; }
.clock { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; }
.clock.over { color: var(--warn); }
.pill { display: inline-block; border-radius: 999px; padding: 3px 10px; font-size: 13.5px; font-weight: 700; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }

.rows { margin: 8px 0; }
.row { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; margin: 8px 0; }
.row .hd { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; font-weight: 700; }
.row .bd { font-size: 15.5px; color: var(--ink2); margin-top: 4px; overflow-wrap: anywhere; }

.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin: 12px 0; }
.metric { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
.metric .v { font-size: 24px; font-weight: 800; }
.metric .l { font-size: 14px; color: var(--ink2); }
.metric .d { font-size: 14px; color: var(--star); letter-spacing: 1px; }
.metric .d.txt { color: var(--ink2); letter-spacing: 0; }
.bigstars { text-align: center; padding: 10px 0 2px; }
.bigstars .s { font-size: 46px; letter-spacing: 4px; color: var(--star); line-height: 1.2; }
.starline { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: center; gap: 4px 8px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.starline .l { font-size: 18px; font-weight: 600; }
.starline .s { font-size: 28px; letter-spacing: 3px; color: var(--star); }

details { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); margin: 14px 0; }
details summary { min-height: 48px; padding: 12px 16px; font-weight: 700; cursor: pointer; list-style: none; display: flex; align-items: center; justify-content: space-between; }
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "＋"; color: var(--ink3); }
details[open] summary::after { content: "－"; }
details .in { padding: 0 16px 12px; }
.kv { border-top: 1px solid var(--line); padding: 10px 0; font-size: 15.5px; }
.kv b { display: block; }

ol.howto { counter-reset: s; list-style: none; padding: 0; margin: 10px 0; }
ol.howto li { position: relative; padding: 6px 0 6px 44px; min-height: 40px; }
ol.howto li::before { counter-increment: s; content: counter(s); position: absolute; left: 0; top: 6px; width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; display: flex; align-items: center; justify-content: center; }
ol.howto b { display: block; }
ol.howto span { color: var(--ink2); font-size: 15.5px; }

.actionbar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); border-top: 1px solid var(--line);
  padding: 10px calc(16px + var(--safe-r)) calc(10px + var(--safe-b)) calc(16px + var(--safe-l)); }
.actionbar .in { max-width: 560px; margin: 0 auto; display: flex; gap: 10px; }
.actionbar .btn { min-height: 52px; font-size: 17px; }
.actionbar .btn.primary { flex: 1 1 auto; }
.actionbar .btn.sec { flex: 0 0 auto; max-width: 42%; }
body.typing .actionbar { display: none; }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--bar-h) + 20px + var(--safe-b)); z-index: 40; background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 999px; font-size: 15px; max-width: 90vw; text-align: center; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.note { font-size: 14.5px; color: var(--ink2); background: var(--info-soft); border-radius: 12px; padding: 8px 12px; margin: 12px 0 0; line-height: 1.5; }
.toast { top: calc(68px + var(--safe-t)); bottom: auto; animation: tin .25s ease-out; }
@keyframes tin { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* kid lesson video */
.lesson-video { margin: 10px 0 18px; }
.lesson-video h3 { margin-top: 4px; }
.lv-slot { position: relative; width: 100%; aspect-ratio: 16 / 9; border-radius: 16px; overflow: hidden; background: #cfeedd; box-shadow: 0 2px 10px rgba(0,0,0,.12); }
.lv-slot video.lv { display: block; width: 100%; height: 100%; object-fit: contain; background: #000; }
