:root {
  --blue: #38B6FF;
  --blue-strong: #1593E6;
  --blue-soft: #E3F3FF;
  --navy: #0B1B33;
  --bg: #F4F8FD;
  --surface: #FFFFFF;
  --surface-2: #EEF4FB;
  --text: #0B1B33;
  --muted: #5B6B82;
  --line: #DCE6F2;
  --danger: #E5484D;
  --ok: #1F9E89;
  --shadow: 0 10px 30px rgba(11, 27, 51, .10);
  --shadow-soft: 0 2px 8px rgba(11, 27, 51, .06);
  --radius: 18px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #07111F; --surface: #0E1D33; --surface-2: #13253F; --text: #E8F1FB; --muted: #93A4BC;
    --line: #1E3352; --blue-soft: #0F2E4D; --shadow: 0 10px 30px rgba(0,0,0,.45); --shadow-soft: 0 2px 8px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #07111F; --surface: #0E1D33; --surface-2: #13253F; --text: #E8F1FB; --muted: #93A4BC;
  --line: #1E3352; --blue-soft: #0F2E4D; --shadow: 0 10px 30px rgba(0,0,0,.45); --shadow-soft: 0 2px 8px rgba(0,0,0,.35);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font); font-size: 16px; }
body { overscroll-behavior: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
#app { min-height: 100%; }

.boot { height: 100vh; display: grid; place-items: center; }
.logo-big { font-size: 40px; font-weight: 800; letter-spacing: -.5px; }
.logo-big b, .logo b { color: var(--blue); font-weight: 800; }
.logo { font-size: 22px; font-weight: 800; letter-spacing: -.3px; }

/* ---------- buttons & fields ---------- */
.btn { border: 0; border-radius: 999px; padding: 13px 22px; font-weight: 700; background: var(--blue); color: #06223C; transition: transform .12s, background .2s, box-shadow .2s; box-shadow: 0 6px 16px rgba(56,182,255,.35); }
.btn:hover { background: #4CBEFF; }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .55; pointer-events: none; }
.btn.ghost { background: transparent; color: var(--blue-strong); box-shadow: none; padding: 10px 14px; }
:root[data-theme="dark"] .btn.ghost { color: var(--blue); }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.ghost { color: var(--blue); } }
.btn.soft { background: var(--surface-2); color: var(--text); box-shadow: none; }
.btn.danger { background: var(--danger); color: #fff; box-shadow: none; }
.btn.block { width: 100%; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; border: 0; background: transparent; display: inline-grid; place-items: center; color: var(--text); }
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin: 0 0 6px 4px; }
.input { width: 100%; border: 1.5px solid var(--line); background: var(--surface); border-radius: 14px; padding: 13px 14px; outline: none; transition: border-color .2s, box-shadow .2s; }
.input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(56,182,255,.18); }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 4px 10px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.spacer { flex: 1; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background:
  radial-gradient(1200px 500px at 10% -10%, rgba(56,182,255,.25), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, rgba(56,182,255,.18), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 28px; padding: 32px 26px; box-shadow: var(--shadow); animation: rise .35s ease; }
.auth-card .logo-big { font-size: 34px; text-align: center; }
.auth-card .tag { text-align: center; color: var(--muted); margin: 6px 0 26px; }
.auth-card h2 { margin: 0 0 8px; font-size: 22px; }
.auth-switch { text-align: center; margin-top: 16px; font-size: 14px; color: var(--muted); }
.lang-pick { position: fixed; top: max(12px, env(safe-area-inset-top)); inset-inline-end: 12px; z-index: 5; }
.lang-select { width: auto; min-width: 150px; padding: 8px 12px; font-weight: 600; }
.lang-pick .lang-select { background-color: var(--surface); box-shadow: var(--shadow-soft); border-radius: 999px; }
.powered { text-align: center; margin-top: 22px; font-size: 12px; color: var(--muted); }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

/* ---------- onboarding ---------- */
.ob { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.ob-card { width: 100%; max-width: 640px; animation: rise .35s ease; }
.ob-card h1 { font-size: 30px; margin: 0 0 8px; letter-spacing: -.4px; }
.ob-big { font-size: 19px; padding: 18px; border-radius: 18px; }
.chips { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 26px; }
.chip { border: 1.5px solid var(--line); background: var(--surface); border-radius: 999px; padding: 10px 16px; font-weight: 600; transition: all .15s; }
.chip.on { background: var(--blue); border-color: var(--blue); color: #06223C; }
.preview { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-soft); margin-bottom: 20px; }
.preview li { margin: 8px 0; }
.preview b { color: var(--blue-strong); }

/* ---------- library ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 10px; padding: max(10px, env(safe-area-inset-top)) 16px 10px; background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); }
.searchbar { flex: 1; max-width: 560px; margin: 0 auto; position: relative; }
.searchbar input { width: 100%; border: 0; background: var(--surface); border-radius: 999px; padding: 12px 18px 12px 44px; box-shadow: var(--shadow-soft); outline: none; }
.searchbar input:focus { box-shadow: 0 0 0 3px rgba(56,182,255,.35); }
.searchbar svg { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--muted); }
.lib { padding: 8px 16px 120px; max-width: 1180px; margin: 0 auto; }
.lib h1 { font-size: 26px; margin: 14px 4px 18px; letter-spacing: -.3px; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px; }
.nb { position: relative; background: none; border: 0; padding: 0; text-align: left; }
.nb-cover { aspect-ratio: 3/4; border-radius: 8px 16px 16px 8px; position: relative; overflow: hidden; box-shadow: var(--shadow); transition: transform .18s; }
.nb:hover .nb-cover { transform: translateY(-3px); }
.nb-cover::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 12px; background: rgba(0,0,0,.14); }
.nb-cover::after { content: ""; position: absolute; inset: 0; background: linear-gradient(135deg, rgba(255,255,255,.25), transparent 50%); }
.nb-cover .nb-label { position: absolute; left: 22px; right: 12px; top: 18px; background: rgba(255,255,255,.92); color: #0B1B33; border-radius: 8px; padding: 8px 10px; font-weight: 700; font-size: 14px; line-height: 1.25; word-break: break-word; }
.nb-meta { margin: 8px 4px 0; font-size: 13px; color: var(--muted); }
.nb-new .nb-cover { background: var(--surface); border: 2px dashed var(--line); box-shadow: none; display: grid; place-items: center; color: var(--blue-strong); font-weight: 700; }
.nb-new .nb-cover::before, .nb-new .nb-cover::after { display: none; }
.nb-new .nb-cover svg { width: 44px; height: 44px; }
.nb-more { position: absolute; right: 6px; bottom: 30px; width: 36px; height: 36px; border-radius: 12px; border: 0; background: rgba(255,255,255,.9); color: #0B1B33; display: grid; place-items: center; z-index: 2; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.results { display: grid; gap: 8px; margin-bottom: 24px; }
.result { text-align: left; border: 0; background: var(--surface); border-radius: 14px; padding: 12px 14px; box-shadow: var(--shadow-soft); }
.result b { display: block; }

/* ---------- modal / sheet ---------- */
.backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(7,17,31,.42); display: grid; place-items: center; padding: 16px; animation: fade .2s; }
.sheet { width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 24px; padding: 22px; box-shadow: var(--shadow); animation: rise .25s ease; }
.sheet h3 { margin: 0 0 16px; font-size: 20px; }
.sheet .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 18px; }
.menu-list { display: grid; gap: 6px; }
.menu-list button { text-align: left; border: 0; background: var(--surface-2); border-radius: 14px; padding: 14px 16px; font-weight: 600; }
.menu-list button:hover { background: var(--blue-soft); }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch { width: 36px; height: 36px; border-radius: 50%; border: 3px solid transparent; box-shadow: inset 0 0 0 1px rgba(0,0,0,.12); }
.swatch.on { border-color: var(--text); }
.tpls { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.tpl { border: 2px solid var(--line); border-radius: 12px; background: #fff; padding: 0; overflow: hidden; }
.tpl.on { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(56,182,255,.25); }
.tpl canvas { display: block; width: 100%; }
.tpl span { display: block; font-size: 11px; padding: 4px 0; color: #33445C; text-align: center; }
@keyframes fade { from { opacity: 0; } }

/* ---------- toast & tips ---------- */
#toast { position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translateX(-50%) translateY(30px); opacity: 0; pointer-events: none; z-index: 200; background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 14px; font-size: 14px; transition: all .25s; max-width: calc(100vw - 32px); }
#toast.show { opacity: 1; transform: translateX(-50%); }
.tip { position: fixed; z-index: 60; left: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); max-width: 320px; background: var(--surface); border-left: 4px solid var(--blue); border-radius: 14px; padding: 14px 16px; box-shadow: var(--shadow); font-size: 14px; animation: rise .3s; }
.tip .row { margin-top: 8px; justify-content: flex-end; }
.tip .btn { padding: 8px 14px; font-size: 13px; box-shadow: none; }
.offline-bar { background: #FFF4D6; color: #6A4B00; font-size: 13px; text-align: center; padding: 6px 12px; }

/* ---------- editor ---------- */
.editor { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--surface-2); }
.ed-top { display: flex; align-items: center; gap: 6px; padding: max(6px, env(safe-area-inset-top)) 8px 6px; background: var(--surface); box-shadow: var(--shadow-soft); z-index: 30; }
.ed-title { flex: 1; min-width: 0; border: 0; background: transparent; font-weight: 700; font-size: 17px; padding: 8px; border-radius: 10px; outline: none; text-overflow: ellipsis; }
.ed-title:focus { background: var(--surface-2); }
.ed-page-no { font-size: 13px; color: var(--muted); white-space: nowrap; padding: 0 4px; }
.ed-scroll { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; position: relative; }
.ed-scroll.pen-only { touch-action: pan-x pan-y; }
.page-wrap { margin: 20px auto 140px; position: relative; box-shadow: var(--shadow); border-radius: 4px; background: #fff; }
.page-wrap canvas, .page-wrap .layer { position: absolute; left: 0; top: 0; }
.layer { width: 100%; height: 100%; }
.c-ink, .c-live { touch-action: none; }
.pen-only .c-ink, .pen-only .c-live { touch-action: pan-x pan-y; }
.layer-images, .layer-texts, .c-bg, .c-ink { pointer-events: none; }
.img-box, .txt-box { pointer-events: none; }
.selecting .img-box, .selecting .txt-box, .texting .txt-box { pointer-events: auto; }
.selecting .c-live { pointer-events: none; }
.img-box { position: absolute; user-select: none; }
.img-box img { width: 100%; height: 100%; display: block; pointer-events: none; border-radius: 2px; }
.selecting .img-box { outline: 2px dashed rgba(56,182,255,.7); cursor: move; }
.img-box .handle { display: none; position: absolute; right: -10px; bottom: -10px; width: 22px; height: 22px; border-radius: 50%; background: var(--blue); border: 3px solid #fff; cursor: nwse-resize; }
.img-box .del, .txt-box .del { display: none; position: absolute; right: -10px; top: -12px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; font-size: 14px; line-height: 24px; padding: 0; }
.selecting .img-box .handle, .selecting .img-box .del, .selecting .txt-box .del { display: block; }
.txt-box { position: absolute; min-width: 60px; color: #0B1B33; font-family: var(--font); line-height: 1.35; white-space: pre-wrap; word-break: break-word; outline: none; padding: 2px 4px; border-radius: 4px; }
.texting .txt-box { outline: 1px dashed rgba(56,182,255,.6); cursor: text; }
.selecting .txt-box { outline: 1px dashed rgba(56,182,255,.6); cursor: move; }
.txt-box:focus { outline: 2px solid var(--blue); background: rgba(227,243,255,.5); }
.txt-box:empty::before { content: attr(data-ph); color: #9AA8BC; }

.page-nav { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(16px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 4px; background: var(--surface); border-radius: 999px; padding: 4px; box-shadow: var(--shadow); z-index: 25; }
.page-nav .icon-btn { width: 40px; height: 40px; border-radius: 999px; }
.page-nav .label { font-size: 13px; font-weight: 600; padding: 0 6px; min-width: 56px; text-align: center; }

/* tool ring */
.ring { position: fixed; z-index: 40; width: 64px; height: 64px; bottom: calc(18px + env(safe-area-inset-bottom)); right: 18px; }
.ring.left { right: auto; left: 18px; }
.ring-main { position: absolute; inset: 0; border-radius: 50%; border: 0; background: var(--blue); color: #06223C; box-shadow: 0 10px 26px rgba(56,182,255,.55); display: grid; place-items: center; transition: transform .2s; touch-action: none; }
.ring-main svg { width: 28px; height: 28px; }
.ring-main .dot { position: absolute; right: 8px; bottom: 8px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid #fff; }
.ring.open .ring-main { transform: rotate(-20deg) scale(.92); }
.ring-item { position: absolute; left: 8px; top: 8px; width: 48px; height: 48px; border-radius: 50%; border: 0; background: var(--surface); color: var(--text); box-shadow: var(--shadow); display: grid; place-items: center; opacity: 0; transform: scale(.4); pointer-events: none; transition: transform .25s cubic-bezier(.2,.9,.3,1.3), opacity .2s; }
.ring-item svg { width: 22px; height: 22px; }
.ring-item.active { background: var(--blue); color: #06223C; }
.ring.open .ring-item { opacity: 1; pointer-events: auto; }
.ring-item .lbl { position: absolute; top: -22px; font-size: 11px; font-weight: 700; white-space: nowrap; background: var(--navy); color: #fff; padding: 2px 6px; border-radius: 6px; opacity: 0; transition: opacity .2s; pointer-events: none; }
.ring-item:hover .lbl { opacity: 1; }

.pal { position: fixed; z-index: 45; right: 96px; bottom: calc(18px + env(safe-area-inset-bottom)); background: var(--surface); border-radius: 20px; padding: 14px; box-shadow: var(--shadow); width: 260px; animation: rise .2s; }
.ring.left ~ .pal { right: auto; left: 96px; }
.pal h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); }
.sizes { display: flex; gap: 8px; margin-top: 12px; align-items: center; }
.size { width: 40px; height: 40px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface); display: grid; place-items: center; }
.size.on { border-color: var(--blue); }
.size i { display: block; border-radius: 50%; background: var(--text); }

.overview { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 12px; }
.ov-page { border: 2px solid var(--line); border-radius: 8px; padding: 0; background: #fff; overflow: hidden; position: relative; }
.ov-page.on { border-color: var(--blue); }
.ov-page img { display: block; width: 100%; }
.ov-page span { position: absolute; bottom: 4px; right: 6px; font-size: 11px; color: #5B6B82; background: rgba(255,255,255,.9); padding: 1px 5px; border-radius: 6px; }

/* settings & admin */
.panel { max-width: 720px; margin: 0 auto; padding: 8px 16px 80px; }
.card { background: var(--surface); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-soft); margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 16px; }
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 6px 0; }
.switch input { width: 46px; height: 28px; appearance: none; background: var(--line); border-radius: 999px; position: relative; transition: background .2s; flex: none; }
.switch input::after { content: ""; position: absolute; left: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0,0,0,.2); }
.switch input:checked { background: var(--blue); }
.switch input:checked::after { transform: translateX(18px); }
.seg { display: inline-flex; background: var(--surface-2); border-radius: 12px; padding: 3px; }
.seg button { border: 0; background: transparent; padding: 8px 14px; border-radius: 10px; font-weight: 600; }
.seg button.on { background: var(--surface); box-shadow: var(--shadow-soft); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 12px; }
.stat { background: var(--surface-2); border-radius: 14px; padding: 14px; }
.stat b { display: block; font-size: 26px; color: var(--blue-strong); }
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl-wrap { overflow-x: auto; }

@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 14px; }
  .tpls { grid-template-columns: repeat(3, 1fr); }
  .ob-card h1 { font-size: 25px; }
}
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- stage 2: board-snap, recording, player, PDF import ---------- */
.sheet.wide { max-width: 920px; }
.snap-stage { background: #0B1B33; border-radius: 14px; padding: 10px; display: grid; place-items: center; overflow: hidden; }
.snap-cv { max-width: 100%; height: auto; border-radius: 6px; touch-action: none; }
.rec-btn.recording { width: auto; padding: 0 12px; gap: 6px; background: #FDE7E8; color: #B4232A; border-radius: 999px; display: inline-flex; align-items: center; font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: #E5484D; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .3; } }
.player { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; padding: 6px 10px; background: var(--blue-soft); border-bottom: 1px solid var(--line); z-index: 29; }
.player .pl-time { font-size: 13px; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 92px; }
.player .pl-range { flex: 1; min-width: 120px; accent-color: var(--blue-strong); }
.player .pl-rate { padding: 8px 12px; min-width: 52px; }
.player .pl-sel { width: auto; padding: 8px 10px; }
.player .pl-hint { flex-basis: 100%; padding: 0 4px 2px; }
.player .pl-play { background: var(--blue); color: #06223C; border-radius: 999px; }
.nb-import .nb-cover { background: var(--surface); border: 2px dashed var(--line); box-shadow: none; display: grid; place-items: center; color: var(--blue-strong); font-weight: 700; }
.nb-import .nb-cover::before, .nb-import .nb-cover::after { display: none; }
.nb-import .nb-cover svg { width: 40px; height: 40px; }
@media (max-width: 640px) { .ed-top .icon-btn[data-a="zoomOut"], .ed-top .icon-btn[data-a="zoomIn"] { display: none; } }

/* ---------- stage 3: study tape, markers, study screen ---------- */
.layer-tapes, .layer-marks { pointer-events: none; }
.tape { position: absolute; pointer-events: auto; border-radius: 3px; cursor: pointer;
  background: repeating-linear-gradient(135deg, #38B6FF 0 14px, #4FC0FF 14px 22px); box-shadow: 0 2px 6px rgba(11,27,51,.25); transition: background .2s, opacity .2s; }
.tape.peek { background: rgba(56,182,255,.12); box-shadow: inset 0 0 0 2px rgba(21,147,230,.6); }
.tape .del { display: none; position: absolute; right: -10px; top: -12px; width: 24px; height: 24px; border-radius: 50%; border: 0; background: var(--danger); color: #fff; font-size: 14px; line-height: 24px; padding: 0; }
.selecting .tape { cursor: move; } .selecting .tape .del { display: block; }
.taping .tape { pointer-events: none; }
.mark { position: absolute; pointer-events: auto; width: 34px; height: 34px; border-radius: 10px; border: 0; display: grid; place-items: center; box-shadow: 0 3px 8px rgba(11,27,51,.2); }
.mark svg { width: 20px; height: 20px; }
.mark-lost { background: #FFE9A8; color: #7A5300; }
.mark-exam { background: #FFD3D5; color: #A3161D; }
.mark .del { display: none; position: absolute; right: -8px; top: -8px; width: 18px; height: 18px; border-radius: 50%; background: var(--danger); color: #fff; font-size: 12px; line-height: 18px; }
.selecting .mark .del { display: block; }
.mark-btn { color: var(--muted); }
.study-btn { position: relative; }
.study-btn .badge { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; }
.exam-chip { display: inline-block; margin-top: 4px; font-size: 12px; font-weight: 700; color: #A3161D; background: #FFE3E4; padding: 2px 8px; border-radius: 999px; }
.focus-time { font-size: 34px; font-weight: 800; font-variant-numeric: tabular-nums; letter-spacing: -.5px; }
.course { padding: 12px 0; border-top: 1px solid var(--line); }
.course:first-of-type { border-top: 0; }
.course-head { display: flex; align-items: center; gap: 10px; }
.course-dot { width: 12px; height: 12px; border-radius: 50%; flex: none; }
.plan { margin-top: 8px; background: var(--blue-soft); border-radius: 10px; padding: 8px 12px; font-size: 14px; font-weight: 600; }
.spots { display: grid; gap: 10px; }
.spot { display: flex; gap: 12px; align-items: center; text-align: left; border: 0; background: var(--surface-2); border-radius: 14px; padding: 8px; }
.spot-img { width: 168px; flex: none; border-radius: 8px; overflow: hidden; background: #fff; }
.spot-img canvas { display: block; width: 100%; }
.spot-kind { display: inline-flex; align-items: center; gap: 4px; }
.spot-kind svg { width: 16px; height: 16px; }
.spot-kind.lost { color: #7A5300; } .spot-kind.exam { color: #A3161D; }
.review { max-width: 760px; margin: 0 auto; padding: 12px 16px 40px; }
.rv-card { background: var(--surface); border-radius: 22px; padding: 18px; box-shadow: var(--shadow); min-height: 260px; }
.rv-src { font-size: 13px; color: var(--muted); margin-bottom: 10px; font-weight: 600; }
.rv-img { display: block; max-width: 100%; height: auto; margin: 0 auto; border-radius: 8px; background: #fff; }
.rv-text { font-size: 21px; line-height: 1.45; padding: 10px 4px; white-space: normal; }
.rv-back { color: var(--blue-strong); }
.rv-done { text-align: center; padding: 40px 10px; }
.rv-actions { margin-top: 16px; }
.grades { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.grade { display: grid; gap: 2px; padding: 12px 6px; box-shadow: none; }
.grade span { font-size: 12px; font-weight: 600; opacity: .75; }
.g-again { background: #FFD3D5; color: #8F1218; } .g-hard { background: #FFE9A8; color: #6A4B00; }
.g-good { background: #CDF3E8; color: #0D5C4F; } .g-easy { background: var(--blue-soft); color: var(--blue-strong); }

/* ---------- stage 4: live shared pages ---------- */
.c-remote { pointer-events: none; }
.layer-cursors { pointer-events: none; }
.rcursor { position: absolute; transform: translate(-2px, -2px); pointer-events: none; transition: left .12s linear, top .12s linear; z-index: 5; }
.rcursor svg { width: 18px; height: 18px; display: block; filter: drop-shadow(0 1px 2px rgba(0,0,0,.3)); }
.rcursor span { position: absolute; left: 16px; top: 14px; background: var(--c); color: #fff; font-size: 12px; font-weight: 700; padding: 2px 7px; border-radius: 8px; white-space: nowrap; }
.presence { display: flex; align-items: center; gap: 2px; padding: 0 4px; }
.presence .avatar { width: 30px; height: 30px; border-radius: 50%; border: 2px solid var(--surface); margin-left: -6px; color: #fff; font-weight: 800; font-size: 13px; display: grid; place-items: center; padding: 0; box-shadow: var(--shadow-soft); }
.live-dot { width: 10px; height: 10px; border-radius: 50%; background: #F2A93B; margin-right: 8px; }
.live-dot.on { background: #1F9E89; box-shadow: 0 0 0 4px rgba(31,158,137,.2); animation: pulse 2s infinite; }
.live-chip { position: absolute; right: 10px; bottom: 10px; background: #E5484D; color: #fff; font-size: 11px; font-weight: 800; letter-spacing: .5px; padding: 3px 8px; border-radius: 999px; z-index: 1; }
.live-rooms h2 { font-size: 18px; margin: 14px 4px 10px; }
.live-list { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 8px; }
.live-room { display: flex; align-items: center; gap: 10px; border: 0; background: var(--surface); border-radius: 16px; padding: 12px 16px; box-shadow: var(--shadow-soft); text-align: left; }
.live-room svg { width: 26px; height: 26px; color: var(--blue-strong); }
.live-room > span { display: grid; }
.invite-banner { display: flex; gap: 10px; align-items: center; background: var(--blue-soft); border-radius: 14px; padding: 12px 14px; margin: -8px 0 18px; font-size: 14px; font-weight: 600; }
.invite-banner svg { width: 26px; height: 26px; flex: none; color: var(--blue-strong); }
@media (max-width: 640px) { .presence .avatar:nth-child(n+4) { display: none; } }

/* mock exam & teach-back */
.course-tools { margin-top: 6px; gap: 4px; }
.course-tools .btn { padding: 8px 10px; font-size: 14px; }
.exam-clock { font-weight: 800; font-variant-numeric: tabular-nums; padding: 6px 12px; border-radius: 999px; background: var(--surface); box-shadow: var(--shadow-soft); }
.exam-clock.low { background: #FFD3D5; color: #8F1218; }
.mc { display: grid; gap: 10px; }
.mc-opt { text-align: left; border: 2px solid var(--line); background: var(--surface); border-radius: 16px; padding: 14px 16px; font-size: 16px; line-height: 1.4; }
.mc-opt:hover:not(:disabled) { border-color: var(--blue); }
.mc-opt.right { border-color: #1F9E89; background: #CDF3E8; color: #0D5C4F; }
.mc-opt.wrong { border-color: #E5484D; background: #FFD3D5; color: #8F1218; }
.grades.two { grid-template-columns: 1fr 1fr; }
.score { font-size: 64px; font-weight: 800; letter-spacing: -1px; }
.score.good, .teach-score.good { color: #1F9E89; } .score.mid, .teach-score.mid { color: #B7791F; } .score.low, .teach-score.low { color: #E5484D; }
.wrong-list { text-align: left; max-width: 520px; margin: 12px auto 0; }
.wrong-list li { margin-bottom: 10px; }
.teach-topic { font-size: 20px; margin: 4px 0 6px; } .teach-topic span { color: var(--blue-strong); }
.teach-box { width: 100%; margin-top: 8px; resize: vertical; font-size: 16px; }
.teach-score { font-size: 18px; font-weight: 800; margin: 14px 0 8px; }
.terms { display: flex; flex-wrap: wrap; gap: 8px; }
.term { padding: 6px 12px; border-radius: 999px; font-weight: 600; font-size: 14px; }
.term.hit { background: #CDF3E8; color: #0D5C4F; } .term.miss { background: #FFD3D5; color: #8F1218; }
[data-speak].recording { background: #FDE7E8; color: #B4232A; }
[data-speak] svg { width: 18px; height: 18px; vertical-align: -4px; }

/* ---------- stage 5: present mode ---------- */
.present { position: fixed; inset: 0; z-index: 300; background: #05101F; display: grid; place-items: center; cursor: default; }
.pr-canvas { display: block; box-shadow: 0 20px 60px rgba(0,0,0,.6); background: #fff; }
.pr-bar { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); display: flex; align-items: center; gap: 6px; background: rgba(14,29,51,.85); color: #fff; border-radius: 999px; padding: 4px 8px; opacity: .25; transition: opacity .25s; }
.pr-bar:hover { opacity: 1; }
.pr-bar .icon-btn { color: #fff; }
.pr-bar .icon-btn:hover { background: rgba(255,255,255,.12); }
.pr-count { font-weight: 700; font-size: 14px; font-variant-numeric: tabular-nums; padding: 0 6px; }
.pr-laser-btn { padding: 8px 14px; background: rgba(255,255,255,.12); color: #fff; }
.pr-laser-btn.on { background: #E5484D; }
.pr-laser { position: fixed; left: -9px; top: -9px; width: 18px; height: 18px; border-radius: 50%; background: radial-gradient(circle, #fff 0 18%, #FF3B3B 30%, rgba(255,59,59,.0) 72%); box-shadow: 0 0 18px 6px rgba(255,40,40,.65); pointer-events: none; opacity: 0; transition: opacity .2s; z-index: 2; }
.pr-laser.on { opacity: 1; }
.present-btn { background: var(--blue-soft) !important; }

/* phones: compact editor top bar, alignment fixes */
.more-btn { display: none; }
@media (max-width: 760px) {
  .ed-top .opt { display: none !important; }
  .ed-top .more-btn { display: inline-grid; }
  .ed-top .ed-page-no { display: none; }
  .ed-top .icon-btn { width: 40px; height: 40px; }
  .ed-title { min-width: 60px; }
}
.icon-list button { display: flex; align-items: center; gap: 12px; }
.icon-list button svg { width: 22px; height: 22px; flex: none; }
button.nb { display: flex; flex-direction: column; justify-content: flex-start; align-self: start; }
button.nb .nb-cover { width: 100%; }
/* No accidental text selection while writing (long-press on tablets) */
.editor, .ring, .page-nav, .ed-top, .player { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.editor .txt-box, .editor input, .editor textarea { -webkit-user-select: text; user-select: text; }
.powered a { color: inherit; }

/* ---------- stage 6: AI helper, backup and sync, calendar ---------- */
.menu-list button .muted { font-weight: 400; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--blue-soft); border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -4px; margin-right: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }
.ai-wait { padding: 26px 4px; color: var(--muted); }
.ai-out { max-height: 46vh; overflow: auto; background: var(--surface-2); border-radius: 14px; padding: 14px 16px; line-height: 1.55; white-space: normal; user-select: text; -webkit-user-select: text; }
.ai-cards { display: grid; gap: 8px; max-height: 48vh; overflow: auto; margin: 8px 0; }
.ai-card { display: flex; gap: 10px; align-items: flex-start; background: var(--surface-2); border-radius: 14px; padding: 10px 12px; cursor: pointer; }
.ai-card input { margin-top: 4px; width: 18px; height: 18px; accent-color: var(--blue); flex: none; }
.ai-provs { display: grid; gap: 6px; margin: 10px 0 6px; }
.ai-prov { display: grid; grid-template-columns: 1fr auto; text-align: left; gap: 2px 8px; border: 2px solid transparent; background: var(--surface-2); border-radius: 14px; padding: 10px 14px; }
.ai-prov .muted { grid-column: 1 / -1; }
.ai-prov.on { border-color: var(--blue); background: var(--blue-soft); }
.ai-prov[disabled] { opacity: .55; cursor: default; }
.free-chip { font-size: 11px; font-weight: 700; color: #0B6B5C; background: #D7F5EF; padding: 2px 8px; border-radius: 999px; align-self: center; }
.ai-test { min-height: 1.2em; }
.ai-btn svg { color: var(--blue-strong); }
.sync-btn { position: relative; color: var(--blue-strong); }
.icon-btn[hidden], .btn[hidden] { display: none !important; }
.sync-btn .badge { position: absolute; top: 4px; right: 2px; min-width: 16px; height: 16px; border-radius: 8px; background: #F2A93B; color: #fff; font-size: 11px; font-weight: 800; line-height: 16px; }
.sync-box { background: var(--surface-2); border-radius: 14px; padding: 12px 14px; }
.btn svg { width: 18px; height: 18px; vertical-align: -3px; margin-right: 4px; }
.cal-list { display: grid; gap: 6px; margin: 8px 0; }
.cal-item { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border-radius: 14px; padding: 8px 6px 8px 12px; }
details summary { cursor: pointer; color: var(--blue-strong); font-weight: 600; }
.today { margin: 6px 0 4px; }
.today-head h2 { font-size: 18px; margin: 14px 4px 10px; }
.today-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 10px; }
.lecture { position: relative; display: flex; flex-direction: column; gap: 4px; text-align: left; border: 0; background: var(--surface); border-radius: 16px; padding: 12px 16px 12px 20px; box-shadow: var(--shadow-soft); overflow: hidden; min-width: 0; }
.lecture::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 5px; background: var(--c, var(--blue)); }
.lecture.now { box-shadow: 0 0 0 2px var(--blue), var(--shadow-soft); }
.lec-top, .lec-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; }
.lec-time { font-weight: 700; font-size: 13px; color: var(--muted); }
.lec-title { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lec-foot .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lec-open { display: inline-flex; align-items: center; gap: 2px; font-size: 13px; font-weight: 700; color: var(--blue-strong); flex: none; }
.lec-open svg { width: 16px; height: 16px; }
.now-chip, .soon-chip { flex: none; font-size: 11px; font-weight: 800; padding: 2px 8px; border-radius: 999px; color: #fff; background: var(--blue); }
.soon-chip { background: #F2A93B; }
.exam-rows { display: grid; gap: 10px; max-height: 50vh; overflow: auto; margin: 8px 0; }
.exam-row { display: grid; gap: 6px; background: var(--surface-2); border-radius: 14px; padding: 10px 12px; }
.ai-prov.pat { border-color: var(--line); }
.ai-prov.pat.on { border-color: var(--blue); }
.ai-or { margin: 6px 4px 0; }
.plan-form { background: var(--surface-2); border-radius: 14px; padding: 12px 14px; margin: 12px 0; }
.age-check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; color: var(--muted); margin: 4px 0 10px; cursor: pointer; }
.age-check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--blue); flex: none; }
.age-check a { color: var(--blue-strong); }
.birth-row { gap: 8px; }
.birth-row select { flex: 1; min-width: 0; }
.parent-box { background: var(--blue-soft); border-radius: 14px; padding: 10px 12px 2px; margin: 4px 0 8px; }
.parent-box p { margin: 0 0 6px; }
.age-msg:empty { display: none; }
.consent-switches { display: grid; gap: 8px; margin: 10px 0; }
.consent-switches .switch { background: var(--surface-2); border-radius: 14px; padding: 10px 12px; }
.auth-card.consent h2 { margin-top: 10px; }
[hidden] { display: none !important; }

/* ---------- stage 7: 20 languages ---------- */
:lang(zh) body, :lang(zh-CN) body { font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", var(--font); }
:lang(ja) body { font-family: -apple-system, "Hiragino Sans", "Yu Gothic UI", "Meiryo", "Noto Sans CJK JP", "Noto Sans JP", var(--font); }
:lang(ko) body { font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans CJK KR", "Noto Sans KR", var(--font); }
:lang(ar) body, :lang(fa) body { font-family: "Segoe UI", Tahoma, "Geeza Pro", "Noto Naskh Arabic", "Noto Sans Arabic", var(--font); }
:lang(hi) body { font-family: "Nirmala UI", "Kohinoor Devanagari", "Noto Sans Devanagari", var(--font); }
/* Right-to-left (Arabic, Persian): the app mirrors, the paper and drawing stay as they are. */
[dir="rtl"] .menu-list button, [dir="rtl"] .lecture, [dir="rtl"] .live-room, [dir="rtl"] .ai-prov, [dir="rtl"] .result { text-align: right; }
[dir="rtl"] .lecture::before { left: auto; right: 0; }
[dir="rtl"] .icon-btn[data-back] svg, [dir="rtl"] [data-a="back"] svg, [dir="rtl"] .lec-open svg { transform: scaleX(-1); }
[dir="rtl"] .ed-canvas-wrap, [dir="rtl"] .page-wrap, [dir="rtl"] canvas { direction: ltr; }
.page-wrap [contenteditable], .page-wrap textarea, .ai-out, .rv-text { unicode-bidi: plaintext; }
[dir="rtl"] [data-a="prev"] svg, [dir="rtl"] [data-a="next"] svg { transform: scaleX(-1); }
