:root {
  --blue: #06B2FC;
  --pink: #F653A2;
  --ink: #222222;
  --muted: #626262;
  --line: #F2F2F2;
  --blue-soft: #E6F7FF;
  --pink-soft: #FEEEF6;
  --yellow: #FFE066;
  --red: #C8102E;
  --green: #1a9a4b;
  --teal: #20b2aa;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: "Nunito", system-ui, sans-serif; color: var(--ink); }
[hidden] { display: none !important; }

/* ---------------- home ---------------- */
#home { min-height: 100%; display: flex; flex-direction: column; background: linear-gradient(180deg, var(--blue-soft), #fff 40%); }
#home main { width: 100%; max-width: 980px; margin: 0 auto; padding: 0 16px 32px; flex: 1; }
header { display: flex; align-items: center; justify-content: space-between; max-width: 980px; width: 100%; margin: 0 auto; padding: 16px; }
.logo { font-weight: 800; font-size: 1.4rem; color: var(--ink); text-decoration: none; }
.logo span { color: var(--pink); }
.grade { font-weight: 600; color: var(--muted); }
.grade select { font: inherit; padding: 6px 10px; border-radius: 10px; border: 2px solid var(--line); margin-left: 6px; background: #fff; }
.hero { text-align: center; padding: 24px 0 8px; }
.hero h1 { font-size: clamp(2rem, 5vw, 3.2rem); margin: 0 0 12px; }
.hero em { font-style: normal; color: var(--blue); }
.hero p { color: var(--muted); font-size: 1.15rem; max-width: 660px; margin: 0 auto; }
.card { background: #fff; border-radius: 20px; box-shadow: 0 6px 24px rgb(0 0 0 / .07); padding: 20px; }
.upload { margin: 24px auto; display: flex; flex-direction: column; gap: 14px; }
.drop { border: 3px dashed #ABABAB; border-radius: 16px; padding: 28px; text-align: center; display: flex; flex-direction: column; gap: 8px; align-items: center; color: var(--muted); transition: .15s; }
.drop.over { border-color: var(--blue); background: var(--blue-soft); }
.drop strong { color: var(--ink); font-size: 1.15rem; }
.drop-icon { font-size: 2.4rem; }
.drop-buttons { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.filelist { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.filelist li { background: var(--pink-soft); border-radius: 999px; padding: 6px 12px; font-weight: 600; display: flex; gap: 8px; align-items: center; }
.filelist button { border: 0; background: none; cursor: pointer; font-size: 1rem; }
textarea, input { font: inherit; width: 100%; padding: 12px 14px; border-radius: 14px; border: 2px solid var(--line); resize: vertical; background: #fff; }
textarea:focus, input:focus { outline: none; border-color: var(--blue); }
.how { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; }
.how b { display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--pink); color: #fff; }
.how h3 { margin: 10px 0 4px; }
.how p { margin: 0; color: var(--muted); }
.saved { margin: 0 0 24px; }
.saved h2 { font-size: 1.2rem; margin: 0 0 10px; }
.saved ul { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.saved li { background: #fff; border-radius: 14px; box-shadow: 0 3px 12px rgb(0 0 0 / .06); display: flex; align-items: center; }
.saved li button.open { flex: 1; text-align: left; border: 0; background: none; font: inherit; padding: 12px 14px; cursor: pointer; }
.saved li small { display: block; color: var(--muted); }
.saved li button.del { border: 0; background: none; padding: 12px; cursor: pointer; color: #ababab; }
.error { color: #c0124f; background: var(--pink-soft); padding: 10px 14px; border-radius: 12px; margin: 0; font-weight: 600; }
footer { text-align: center; color: #ABABAB; padding: 18px; font-size: .9rem; }
footer a { color: inherit; }

.btn { font: inherit; font-weight: 800; border: 0; border-radius: 999px; padding: 10px 18px; cursor: pointer; transition: transform .1s, opacity .1s; white-space: nowrap; }
.btn:active { transform: scale(.96); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.blue { background: var(--blue); color: #fff; }
.btn.pink { background: var(--pink); color: #fff; }
.btn.gradient { background: linear-gradient(90deg, var(--pink), var(--blue)); color: #fff; box-shadow: 0 4px 14px rgb(246 83 162 / .3); }
.btn.big { font-size: 1.2rem; padding: 14px 24px; }

/* ---------------- lesson: one big board ---------------- */
.lesson { position: fixed; inset: 0; background: #f7f9fb; overflow: hidden; }
.viewport { position: absolute; inset: 0; overflow: hidden; touch-action: none; cursor: grab; background-color: #fbfcfd;
  background-image: radial-gradient(#e3e8ec 1px, transparent 1px); background-size: 28px 28px; }
.viewport.dragging { cursor: grabbing; }
.viewport.drawing { cursor: crosshair; }
.world { position: absolute; left: 0; top: 0; transform-origin: 0 0; padding: 120px 80px 260px; }
.sections { display: grid; grid-template-columns: repeat(var(--cols, 3), 460px); gap: 70px 80px; align-items: start; }
.ink { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.ink path { fill: none; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }

.section { font-family: "Patrick Hand", "Caveat", cursive; font-size: 1.45rem; line-height: 1.3; color: var(--ink); }
.section h2 { font-family: "Patrick Hand", cursive; font-size: 1.75rem; margin: 0 0 12px; font-weight: 400; }
.section.current h2::after { content: " ✏️"; font-size: .9em; }
.section .it { margin: 0 0 8px; min-height: 1em; }
.section .it.subheading { font-size: 1.55rem; margin-top: 16px; text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 4px; }
.section .it.bullet { padding-left: 1.1em; text-indent: -1.1em; }
.section .it.bullet::before { content: "- "; }
.section .it.math { overflow-x: auto; font-size: 1.05em; }
.section .it.math .katex-display { margin: .3em 0; text-align: left; }
.section .it.math .katex-display > .katex { text-align: left; }
.section .red { color: var(--red); }
.section .blue { color: #0a7fc2; }
.section .check::after { content: " ✓"; color: var(--green); font-weight: 700; }
.section .highlight .ink-text { background: linear-gradient(transparent 12%, rgb(255 224 102 / .85) 12%, rgb(255 224 102 / .85) 88%, transparent 88%);
  background-repeat: no-repeat; background-size: 0% 100%; animation: hilite .6s .1s forwards; padding: 0 3px; border-radius: 3px; -webkit-box-decoration-break: clone; box-decoration-break: clone; }
@keyframes hilite { to { background-size: 100% 100%; } }
.section .circle { display: inline-block; position: relative; padding: 4px 14px; }
.section .circle svg { position: absolute; inset: -6px -10px; width: calc(100% + 20px); height: calc(100% + 12px); overflow: visible; pointer-events: none; }
.section .circle ellipse { fill: none; stroke: var(--teal); stroke-width: 2.5; stroke-dasharray: 1000; stroke-dashoffset: 1000; animation: draw 1s forwards; }
@keyframes draw { to { stroke-dashoffset: 0; } }
.section table { border-collapse: collapse; font-size: 1.15rem; margin: 6px 0 4px; }
.section td, .section th { border: 1.5px solid #8a9299; padding: 4px 10px; text-align: left; font-weight: 400; vertical-align: top; }
.section th { color: #0a7fc2; }
.section th:nth-child(2) { color: var(--red); }
.section .pic { text-align: center; margin: 10px 0; }
.section .pic img { max-width: 100%; max-height: 330px; mix-blend-mode: multiply; filter: saturate(.9); opacity: 0; transition: opacity .8s; }
.section .pic img.in { opacity: 1; }
.section .pic .sketching { font-size: 1.1rem; color: var(--muted); border: 2px dashed #c5ccd2; border-radius: 12px; padding: 30px 16px; }
.section .pic figcaption { font-size: 1rem; color: var(--muted); }
.section .diagram img { max-width: 100%; height: auto; }
.section .fadein { animation: fadein .5s forwards; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }
.cursor::after { content: "▍"; color: var(--blue); animation: blink .8s infinite; }
@keyframes blink { 50% { opacity: 0; } }

.section.plan { background: #fff6cc; padding: 18px 22px; border-radius: 6px; box-shadow: 2px 3px 0 rgb(0 0 0 / .05); transform: rotate(-.6deg); }
.section.plan ol { margin: 0; padding-left: 1.3em; }
.section.plan li.done { text-decoration: line-through; text-decoration-color: rgb(0 0 0 / .35); }
.section.plan li.done::after { content: " ✓"; color: var(--green); text-decoration: none; display: inline-block; }
.section.plan li.now { color: #0a7fc2; }
.section.aside { background: var(--blue-soft); border-radius: 18px; padding: 16px 20px; border: 2px dashed #9fdcf7; }
.section.aside h2 { color: #0a7fc2; }
.section.quiz { background: var(--pink-soft); border-radius: 18px; padding: 16px 20px; }
.quiz .q { margin: 10px 0 4px; }
.quiz form { display: flex; gap: 6px; margin-bottom: 4px; }
.quiz input { font-family: "Nunito", sans-serif; font-size: 1rem; padding: 8px 10px; }
.quiz .btn { font-size: .95rem; padding: 8px 14px; }
.quiz .fb { font-size: 1.2rem; min-height: 1em; }
.quiz .fb.good { color: var(--green); }
.quiz .fb.bad { color: var(--red); }
.quiz .hint { border: 0; background: none; color: var(--muted); font: inherit; font-size: 1rem; cursor: pointer; padding: 0; }
.writing-placeholder { color: #9aa3ab; font-size: 1.2rem; }

/* overlay chrome */
.topbar { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: calc(10px + env(safe-area-inset-top)) 14px 10px; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.lesson-title { flex: 1; text-align: center; font-size: 1.05rem; margin: 0; color: var(--muted); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.zoom { display: flex; gap: 6px; align-items: center; }
.round { width: 44px; height: 44px; border-radius: 50%; border: 0; background: #fff; box-shadow: 0 2px 10px rgb(0 0 0 / .1); font-size: 1.15rem; cursor: pointer; display: grid; place-items: center; }
.round.on { background: var(--blue-soft); outline: 2px solid var(--blue); }
.pill { height: 40px; border-radius: 999px; border: 0; background: #fff; box-shadow: 0 2px 10px rgb(0 0 0 / .1); font: inherit; font-weight: 700; padding: 0 14px; cursor: pointer; }
.pens { position: absolute; right: 14px; top: 50%; transform: translateY(-50%); display: flex; flex-direction: column; gap: 8px; background: #fff; padding: 8px; border-radius: 999px; box-shadow: 0 2px 10px rgb(0 0 0 / .1); }
.pen { width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); background: var(--c, #fff); cursor: pointer; font-size: 1rem; padding: 0; }
.pen.active { outline: 3px solid var(--blue); outline-offset: 1px; }

.bottombar { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; gap: 14px; padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); pointer-events: none; }
.bottombar > * { pointer-events: auto; }
.tutor { display: flex; align-items: flex-end; gap: 10px; flex: 1; min-width: 0; }
.avatar { flex: none; width: 64px; height: 64px; border-radius: 50%; background: #fff; box-shadow: 0 2px 12px rgb(0 0 0 / .12); font-size: 2.3rem; display: grid; place-items: center; }
.avatar.talking { animation: talk .5s ease-in-out infinite alternate; box-shadow: 0 0 0 4px var(--blue-soft), 0 0 0 7px rgb(6 178 252 / .35); }
.avatar.thinking { animation: think 1.2s ease-in-out infinite; }
.avatar.listening { box-shadow: 0 0 0 4px var(--pink-soft), 0 0 0 7px rgb(246 83 162 / .45); }
@keyframes talk { from { transform: scale(1); } to { transform: scale(1.06) rotate(-2deg); } }
@keyframes think { 50% { transform: rotate(8deg); } }
.caption { background: rgb(255 255 255 / .95); border-radius: 16px 16px 16px 4px; padding: 8px 14px; box-shadow: 0 2px 10px rgb(0 0 0 / .08); max-width: 520px; font-size: 1rem; color: #333; }
.caption:empty { display: none; }
.actions { display: flex; flex-direction: column; align-items: flex-end; gap: 8px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.chip { border: 0; background: #fff; box-shadow: 0 2px 10px rgb(0 0 0 / .1); border-radius: 999px; padding: 8px 12px; font: inherit; font-weight: 700; font-size: .92rem; cursor: pointer; }
.chip:disabled { opacity: .5; }
.ask { display: flex; gap: 6px; width: min(460px, 80vw); }
.ask input { box-shadow: 0 2px 10px rgb(0 0 0 / .1); border: 2px solid #fff; }
.buttons { display: flex; gap: 8px; align-items: center; }
.mic { width: 76px; height: 76px; border-radius: 50%; border: 0; background: #e8434b; color: #fff; font-size: 2rem; box-shadow: 0 6px 18px rgb(232 67 75 / .45); cursor: pointer; }
.mic.listening { animation: pulse 1s infinite; background: var(--pink); }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgb(246 83 162 / .6); } 100% { box-shadow: 0 0 0 22px rgb(246 83 162 / 0); } }
.toast { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); background: #c0124f; color: #fff; padding: 10px 16px; border-radius: 12px; font-weight: 700; max-width: 90vw; }

@media (max-width: 700px) {
  .caption { display: none; }
  .chips { display: none; }
  .round { width: 40px; height: 40px; }
  .mic { width: 64px; height: 64px; }
  .lesson-title { display: none; }
  .pens { top: auto; bottom: 110px; transform: none; }
}

/* ---------------- sign-in, settings ---------------- */
.authpage { min-height: 100%; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, var(--blue-soft), var(--pink-soft)); }
.authcard { width: min(420px, 100%); text-align: center; display: flex; flex-direction: column; gap: 12px; }
.logo.big { font-size: 2rem; }
.logo.big span, #brand-name { color: var(--pink); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.wide { width: 100%; }
.or { color: var(--muted); margin: 4px 0; font-size: .9rem; }
.swap { font-size: .92rem; color: var(--muted); margin: 0; }
.link { border: 0; background: none; color: #0a7fc2; font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: .85rem; margin: 0; }
.btn.ghost { background: #fff; color: var(--ink); border: 2px solid var(--line); }
.btn.soft { background: var(--blue-soft); color: var(--ink); }
.modal-back { position: fixed; inset: 0; background: rgb(0 0 0 / .35); display: grid; place-items: center; z-index: 50; padding: 16px; overflow-y: auto; }
.modal { width: min(480px, 100%); text-align: left; }
.modal h2 { margin: 0; }
.modal h3 { margin: 6px 0 0; font-size: 1.05rem; }
.modal label { display: flex; flex-direction: column; gap: 4px; font-weight: 700; font-size: .95rem; }
.modal select { font: inherit; padding: 10px 12px; border-radius: 12px; border: 2px solid var(--line); background: #fff; flex: 1; }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { margin-top: 6px; }
.grow { flex: 1; }
.admin { border-top: 2px solid var(--line); padding-top: 8px; display: flex; flex-direction: column; gap: 6px; }
.admin p { margin: 0; font-size: .9rem; }
.mic.on { background: var(--pink); animation: pulse 1.4s infinite; }
.mic.capturing { background: #e8434b; animation: pulse .6s infinite; }
.section .it.diagram svg, .section .live-svg { max-width: 100%; height: auto; display: block; overflow: visible; font-family: "Patrick Hand", cursive; }
.section .pic-wrap { position: relative; }
.section .live-pic { display: block; mix-blend-mode: multiply; }
.section .pencil { position: absolute; font-size: 1.6rem; transform: translate(-10%, -90%); pointer-events: none; transition: left .05s linear, top .05s linear; }
.section .sketching.wiggle { animation: think 1.2s ease-in-out infinite; }
