/* ---- design tokens: calm "study" palette ---- */
:root {
  --bg: #f4f5fb;
  --panel: #ffffff;
  --panel-2: #f9f9fd;
  --text: #1e2238;
  --muted: #6a6f8c;
  --border: #e4e6f0;
  --accent: #4f5bd5;
  --accent-2: #6d78f0;
  --accent-soft: rgba(79, 91, 213, 0.10);
  --hover: rgba(79, 91, 213, 0.07);
  --good: #16a34a; --warn: #d97706; --bad: #dc2626;
  --shadow: 0 1px 2px rgba(30, 34, 56, .05), 0 4px 16px rgba(30, 34, 56, .06);
  --shadow-lg: 0 10px 40px rgba(30, 34, 56, .16);
  --radius: 14px;
  --font-ui: ui-rounded, "SF Pro Rounded", "Nunito", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1220; --panel: #171a2b; --panel-2: #1c2034; --text: #e8eaf6; --muted: #9aa0bd; --border: #272c45;
    --accent: #8d95ff; --accent-2: #a5abff; --accent-soft: rgba(141, 149, 255, 0.15); --hover: rgba(141, 149, 255, 0.10);
    --good: #34c76f; --warn: #f0a33a; --bad: #f2615f;
    --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
  }
}
:root[data-theme="dark"] {
  --bg: #0f1220; --panel: #171a2b; --panel-2: #1c2034; --text: #e8eaf6; --muted: #9aa0bd; --border: #272c45;
  --accent: #8d95ff; --accent-2: #a5abff; --accent-soft: rgba(141, 149, 255, 0.15); --hover: rgba(141, 149, 255, 0.10);
  --good: #34c76f; --warn: #f0a33a; --bad: #f2615f;
  --shadow: 0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3); --shadow-lg: 0 10px 40px rgba(0,0,0,.5);
}
:root { color-scheme: light dark; }
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  display: flex; flex-direction: column; overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
.hidden { display: none !important; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; background: var(--panel); border-bottom: 1px solid var(--border);
  flex: none; z-index: 5;
}
.spacer { flex: 1; }
.icon-btn {
  background: none; border: 1px solid transparent; border-radius: 8px;
  min-width: 32px; height: 32px; font-size: 18px; line-height: 1;
}
.icon-btn:hover { background: var(--hover); }
.book-tabs { display: flex; gap: 4px; background: var(--bg); padding: 3px; border-radius: 10px; }
.book-tabs button {
  border: 0; background: none; padding: 6px 12px; border-radius: 8px; color: var(--muted); font-weight: 500;
}
.book-tabs button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.pagejump { color: var(--muted); display: flex; align-items: center; gap: 6px; }
.pagejump input {
  width: 52px; padding: 4px 6px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text); text-align: center; font: inherit;
}
.zoom { display: flex; align-items: center; gap: 2px; color: var(--muted); }
#zoomLabel { min-width: 44px; text-align: center; font-variant-numeric: tabular-nums; }

/* layout */
.layout { flex: 1; display: flex; min-height: 0; }
.sidebar {
  width: 270px; flex: none; overflow-y: auto; background: var(--panel);
  border-right: 1px solid var(--border); padding: 8px 0 40px;
}
.sidebar.collapsed { display: none; }
.sidebar .chapter { padding: 10px 14px 4px; font-weight: 600; font-size: 12.5px; color: var(--muted); }
.sidebar .chapter.link { cursor: pointer; }
.sidebar .chapter.link:hover { color: var(--text); }
.sidebar .ex {
  display: flex; justify-content: space-between; gap: 8px; width: 100%;
  border: 0; background: none; text-align: left; padding: 5px 14px 5px 24px;
}
.sidebar .ex:hover { background: var(--hover); }
.sidebar .ex.current { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.sidebar .ex .count { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.viewer { flex: 1; overflow: auto; position: relative; }
.pages { display: flex; flex-direction: column; align-items: safe center; gap: 16px; padding: 20px 16px 60px; }
.page {
  position: relative; background: #fff; box-shadow: var(--shadow); flex: none;
}
.page canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.page .pnum {
  position: absolute; top: 0; left: -44px; color: var(--muted); font-size: 12px; width: 36px; text-align: right;
}

/* question hotspots */
.qbox {
  position: absolute; border-radius: 6px; cursor: zoom-in;
  border: 1.5px solid transparent; transition: background .12s, border-color .12s;
}
.qbox:hover, .qbox.hl { background: var(--hover); border-color: var(--accent); }
.qbox .qtag {
  position: absolute; right: 4px; top: 4px; font-size: 11px; font-weight: 600;
  background: var(--accent); color: #fff; padding: 1px 6px; border-radius: 10px;
  opacity: 0; transition: opacity .12s; pointer-events: none;
}
.qbox:hover .qtag { opacity: 1; }
.qbox.viewed::after {
  content: "✓"; position: absolute; left: -22px; top: 2px; color: var(--accent); font-weight: 700; font-size: 13px;
}

/* modal */
.modal { position: fixed; inset: 0; z-index: 20; display: flex; align-items: center; justify-content: center; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(10, 14, 20, .55); backdrop-filter: blur(2px); }
.modal-card {
  position: relative; background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  width: min(980px, calc(100vw - 32px)); max-height: calc(100vh - 32px); display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border);
}
.modal-title { flex: 1; display: flex; flex-direction: column; align-items: center; }
.modal-title span { font-weight: 600; font-size: 16px; }
.modal-title small { color: var(--muted); }
.modal-body { overflow-y: auto; padding: 18px; }
.clip-stack { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.clip-stack canvas { max-width: 100%; height: auto; background: #fff; border-radius: 6px; box-shadow: 0 0 0 1px var(--border); }
.clip-stack .note { color: var(--muted); text-align: center; max-width: 560px; }
.answer-bar { display: flex; justify-content: center; margin: 18px 0; }
.primary {
  background: var(--accent); color: #fff; border: 0; border-radius: 10px; padding: 10px 20px; font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }
.primary kbd {
  font: 11px ui-monospace, monospace; background: rgba(255,255,255,.22); padding: 1px 5px; border-radius: 4px; margin-left: 6px;
}
.answer { border-top: 2px dashed var(--border); padding-top: 18px; }
.answer h4 { margin: 0 0 4px; color: var(--accent); font-size: 13px; text-transform: uppercase; letter-spacing: .06em; }
.spinner { color: var(--muted); padding: 30px; }

@media (max-width: 760px) {
  .sidebar { position: absolute; z-index: 4; height: calc(100% - 49px); box-shadow: var(--shadow); }
  .pagejump { display: none; }
  .page .pnum { display: none; }
}

/* lookup */
.lookup { position: relative; flex: 1; max-width: 420px; min-width: 160px; }
.lookup input {
  width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
.lookup input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.lookup-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 30;
  background: var(--panel); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow);
  max-height: 60vh; overflow-y: auto; padding: 4px; min-width: 300px;
}
.lookup-results .group { padding: 6px 10px 2px; font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.lookup-results button {
  display: flex; gap: 10px; justify-content: space-between; align-items: baseline; width: 100%;
  border: 0; background: none; text-align: left; padding: 7px 10px; border-radius: 7px;
}
.lookup-results button.sel, .lookup-results button:hover { background: var(--accent-soft); }
.lookup-results .r-main { flex: 1; min-width: 0; }
.lookup-results .r-snip { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lookup-results .r-snip mark { background: none; color: var(--accent); font-weight: 600; }
.lookup-results .r-page { color: var(--muted); font-size: 12px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.lookup-results .empty { padding: 10px; color: var(--muted); }
@media (max-width: 760px) { .book-tabs button { padding: 6px 8px; font-size: 12px; } }

/* narrow screens: two-row top bar, short book names */
.book-tabs .short { display: none; }
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; row-gap: 8px; }
  .book-tabs .long { display: none; }
  .book-tabs .short { display: inline; }
  .book-tabs button { white-space: nowrap; }
  .lookup { order: 10; flex-basis: 100%; max-width: none; }
  .lookup-results { min-width: 0; }
  .sidebar { height: auto; top: 0; bottom: 0; }
  .layout { position: relative; }
  .pages { padding: 12px 8px 60px; gap: 10px; }
}
@media (max-width: 760px) {
  .modal-card { width: calc(100vw - 12px); max-height: calc(100vh - 12px); }
  .modal-body { padding: 10px 6px; }
}

/* login */
.login {
  position: fixed; inset: 0; z-index: 50; background: var(--bg);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.login-card {
  background: var(--panel); border-radius: 16px; box-shadow: var(--shadow); padding: 32px 28px;
  width: min(380px, 100%); text-align: center; display: flex; flex-direction: column; gap: 12px;
}
.login-card h1 { margin: 0; font-size: 22px; }
.login-card p { margin: 0; color: var(--muted); }
.login .login-msg { min-height: 1.4em; color: var(--text); }
.login.checking #googleSignIn { display: none; }
.linkish { background: none; border: 0; color: var(--accent); text-decoration: underline; }
.admin-link { display: inline-flex; align-items: center; justify-content: center; text-decoration: none; color: inherit; }
.year-tabs button.active { background: var(--accent); color: #fff; }

/* done toggle */
.done-toggle {
  border: 1px solid var(--border); background: none; border-radius: 16px; padding: 4px 11px; font-size: 12.5px; white-space: nowrap; color: var(--muted);
}
.done-toggle:hover { background: var(--hover); }
.done-toggle.is-done { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }

/* progress in the sidebar */
.sidebar .bar { height: 4px; background: var(--border); border-radius: 3px; overflow: hidden; margin-top: 5px; }
.sidebar .bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 3px; transition: width .3s; }
.book-progress { margin: 6px 14px 10px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.bp-top, .ch-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.bp-top span:first-child { font-weight: 600; font-size: 12.5px; }
.bp-count, .ch-count { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; font-weight: 500; white-space: nowrap; }
.sidebar .chapter .bar { height: 3px; }
.sidebar .count.started { color: var(--accent); }
.sidebar .count.complete::after, .ch-count.complete::after { content: " ✓"; color: var(--accent); }
@media (max-width: 760px) { .done-toggle { padding: 4px 8px; } }
.secondary {
  background: none; color: var(--text); border: 1px solid var(--border); border-radius: 10px; padding: 10px 18px; font-weight: 600;
}
.secondary:hover { background: var(--hover); }

/* calculator */
:root { --lcd: #dfe6d3; --lcd-text: #1c241a; --key: #f3f4f6; --key-num: #ffffff; --key-text: #1d2330; --key-shift: #b7791f; --key-del: #d9534f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --lcd: #c7d1bb; --key: #2a2f38; --key-num: #343a45; --key-text: #e6e8ec; --key-shift: #f0b44c; --key-del: #c9483f; } }
:root[data-theme="dark"] { --lcd: #c7d1bb; --key: #2a2f38; --key-num: #343a45; --key-text: #e6e8ec; --key-shift: #f0b44c; --key-del: #c9483f; }
.calc {
  position: fixed; right: 16px; bottom: 16px; width: 340px; z-index: 40;
  background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: 0 10px 40px rgba(0,0,0,.25); display: flex; flex-direction: column;
  max-height: calc(100vh - 32px); overflow: hidden;
}
.calc-head { display: flex; align-items: center; gap: 6px; padding: 8px 8px 6px; cursor: move; touch-action: none; }
.calc-tabs { display: flex; gap: 2px; background: var(--bg); padding: 3px; border-radius: 9px; flex: 1; }
.calc-tabs button { flex: 1; border: 0; background: none; color: var(--muted); padding: 5px 4px; border-radius: 7px; font-size: 12.5px; font-weight: 500; }
.calc-tabs button.active { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.calc-x { border: 0; background: none; color: var(--muted); width: 28px; height: 28px; border-radius: 7px; font-size: 14px; }
.calc-x:hover { background: var(--hover); }
.calc-pane { padding: 4px 10px 12px; overflow-y: auto; }
.calc-screen { background: var(--lcd); color: var(--lcd-text); border-radius: 10px; padding: 6px 10px 8px; margin-bottom: 10px; box-shadow: inset 0 1px 3px rgba(0,0,0,.18); }
.calc-ind { display: flex; gap: 8px; font: 600 10px ui-monospace, monospace; opacity: .75; min-height: 13px; }
.calc-ind .grow { flex: 1; }
#cShiftInd { visibility: hidden; background: var(--lcd-text); color: var(--lcd); padding: 0 3px; border-radius: 2px; }
#cShiftInd.on { visibility: visible; }
.calc-expr {
  width: 100%; border: 0; background: transparent; color: inherit; padding: 4px 0; outline: none;
  font: 18px ui-monospace, "SF Mono", Menlo, monospace; caret-color: var(--lcd-text);
}
.calc-res { text-align: right; font: 600 28px/1.2 ui-monospace, "SF Mono", Menlo, monospace; min-height: 40px; overflow-x: auto; white-space: nowrap; }
.calc-res .err, .calc-out .err { color: #b42318; font-size: 18px; }
.cfrac { display: inline-flex; flex-direction: column; vertical-align: middle; text-align: center; font-size: .78em; line-height: 1.15; margin: 0 2px; }
.cfrac > span:first-child { border-bottom: 1.5px solid currentColor; padding: 0 3px; }
.calc-keys { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.k {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  border: 0; border-radius: 8px; background: var(--key); color: var(--key-text); padding: 3px 0 6px; min-height: 42px;
  box-shadow: 0 1px 0 rgba(0,0,0,.15); touch-action: manipulation; user-select: none; -webkit-user-select: none;
}
.k:active { transform: translateY(1px); box-shadow: none; filter: brightness(.94); }
.k i { font: italic 9.5px/1 system-ui, sans-serif; color: var(--key-shift); min-height: 10px; }
.k b { font-weight: 600; font-size: 14px; }
.k.num { background: var(--key-num); }
.k.num b { font-size: 17px; }
.k.op b { font-size: 18px; }
.k.fn b { font-size: 12px; }
.k.shift { background: var(--key-shift); color: #fff; }
.k.del { background: var(--key-del); color: #fff; }
.k.eq { background: var(--accent); color: #fff; }
.k.eq b { font-size: 20px; }
.calc.shifted .k i:not(:empty) { color: #fff; background: var(--key-shift); border-radius: 3px; padding: 1px 3px; }
.calc.shifted .k.shift { outline: 2px solid var(--key-shift); outline-offset: 2px; }
.calc-pane select, .calc-pane textarea, .calc-f input, .calc-f select {
  width: 100%; padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit;
}
.calc-pane textarea { resize: vertical; font: 14px ui-monospace, Menlo, monospace; }
.calc-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 10px 0; }
.calc-fields[data-cols="3"] { grid-template-columns: repeat(3, 1fr); }
.calc-fields[data-cols="4"] { grid-template-columns: repeat(4, 1fr); }
.calc-f { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); }
.calc-f input { font: 15px ui-monospace, Menlo, monospace; }
.calc-eqhint { grid-column: 1 / -1; font-size: 12px; color: var(--muted); }
.calc-lab { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: var(--muted); margin-top: 10px; }
.calc-go { width: 100%; margin-top: 10px; background: var(--accent); color: #fff; border: 0; border-radius: 9px; padding: 9px; font-weight: 600; }
.calc-out { margin-top: 10px; display: flex; flex-direction: column; gap: 2px; }
.calc-out:empty { display: none; }
.calc-row { display: grid; grid-template-columns: auto 1fr; align-items: center; gap: 2px 10px; padding: 6px 10px; background: var(--lcd); color: var(--lcd-text); border-radius: 8px; }
.calc-row > span { font-size: 13px; opacity: .8; }
.calc-row > b { text-align: right; font: 600 17px ui-monospace, Menlo, monospace; overflow-x: auto; }
.calc-row > small { grid-column: 1 / -1; text-align: right; font-size: 11px; opacity: .7; }
.calc-row small.dec { display: block; font-weight: 400; font-size: 12px; opacity: .7; }
.calc-btn svg { width: 18px; height: 18px; vertical-align: middle; }
@media (max-width: 640px) {
  .calc { left: 0; right: 0; bottom: 0; width: auto; border-radius: 16px 16px 0 0; max-height: 78vh; }
  .calc-head { cursor: default; }
  .k { min-height: 40px; }
}
.calc.wide { width: 440px; }
.calc-hint { font: 11px ui-monospace, Menlo, monospace; opacity: .75; min-height: 14px; }
.k.cx b { font-size: 13.5px; font-style: italic; }
.calc-in { width: 100%; padding: 7px 8px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: 15px ui-monospace, Menlo, monospace; }
.calc-in.bad { border-color: #d9534f; }
.calc-lab .muted { color: var(--muted); font-size: 11px; }
.calc-table { width: 100%; border-collapse: collapse; font: 13px ui-monospace, Menlo, monospace; background: var(--lcd); color: var(--lcd-text); border-radius: 8px; overflow: hidden; }
.calc-table th, .calc-table td { padding: 4px 8px; text-align: right; border-bottom: 1px solid rgba(0,0,0,.08); }
.calc-table th { font: 600 12px system-ui, sans-serif; }
.g-fns { display: flex; flex-direction: column; gap: 5px; margin-bottom: 8px; }
.g-fn { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.g-fn span { width: 34px; font-weight: 600; }
.g-fn.g1 span { color: #2563eb; } .g-fn.g2 span { color: #dc2626; } .g-fn.g3 span { color: #16a34a; }
.g-wrap { position: relative; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
#gCanvas { display: block; width: 100%; height: 260px; touch-action: none; cursor: crosshair; }
.g-tip { position: absolute; background: var(--text); color: var(--panel); font: 12px ui-monospace, Menlo, monospace; padding: 4px 7px; border-radius: 6px; pointer-events: none; white-space: nowrap; }
.g-tools { display: flex; gap: 5px; margin-top: 7px; flex-wrap: wrap; }
.g-tools button { flex: 1; border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 6px 4px; font-size: 12.5px; white-space: nowrap; }
.g-tools button:hover { background: var(--hover); }
.g-help { margin: 8px 0 0; font-size: 11.5px; color: var(--muted); text-align: center; }
.calc-tabs button { padding: 5px 2px; font-size: 12px; }
@media (max-width: 640px) { .calc.wide { width: auto; } }

/* question window tools */
.modal-tools { display: flex; align-items: center; gap: 6px; padding: 7px 12px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.tool-btn {
  display: inline-flex; align-items: center; gap: 5px; border: 1px solid var(--border); background: none; color: var(--muted);
  border-radius: 16px; padding: 4px 11px; font-size: 12.5px; white-space: nowrap; position: relative;
}
.tool-btn:hover { background: var(--hover); }
.tool-btn.on { background: var(--accent-soft); color: var(--accent); border-color: transparent; font-weight: 600; }
#flagToggle.on { background: rgba(234, 140, 0, .14); color: #c26a00; }
.tool-btn svg { width: 15px; height: 15px; }
#scribbleToggle.has::after { content: ""; position: absolute; top: 3px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.fx-btn i, .tool-btn i { font-family: Georgia, "Times New Roman", serif; font-weight: 700; }
.fx-btn { font-size: 15px; }
@media (max-width: 760px) {
  .modal-tools { padding: 6px 8px; gap: 5px; }
  .tool-btn { padding: 4px 8px; }
  .modal-tools .tool-btn[data-formulae-toggle] span, .modal-tools .calc-btn span { display: none; }
}

/* scribble pad */
.modal-content { position: relative; }
.scribble { position: absolute; top: 0; left: 0; pointer-events: none; z-index: 2; }
.scribbling .scribble { pointer-events: auto; touch-action: none; cursor: crosshair; }
.scribbling .scribble.finger-scroll { touch-action: pan-y pinch-zoom; }
.scribbling .modal-body { box-shadow: inset 0 0 0 2px var(--accent-soft); }
.scribble-bar { display: flex; align-items: center; gap: 4px; padding: 6px 12px; border-bottom: 1px solid var(--border); background: var(--bg); flex-wrap: wrap; }
.scribble-bar button { border: 1px solid transparent; background: none; border-radius: 8px; min-width: 32px; height: 30px; padding: 0 8px; font-size: 14px; }
.scribble-bar button:hover { background: var(--hover); }
.scribble-bar button.active { background: var(--panel); border-color: var(--border); box-shadow: var(--shadow); }
.scribble-bar .swatch { min-width: 26px; width: 26px; height: 26px; padding: 0; border-radius: 50%; background: var(--c); border: 2px solid var(--panel); }
.scribble-bar .swatch.active { box-shadow: 0 0 0 2px var(--accent); }
.scribble-bar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.scribble-bar .sb-done { background: var(--accent); color: #fff; font-weight: 600; }
.scribble-bar .sb-done:hover { background: var(--accent); filter: brightness(1.08); }
.scribble-bar #fingerMode { font-size: 12px; }
.spacer { flex: 1; }

/* review later + practice in the sidebar */
.qbox.flagged::before { content: "⚑"; position: absolute; right: -20px; top: 0; color: #e08a00; font-size: 14px; }
.practice-btn { width: 100%; margin-top: 10px; border: 1px solid var(--border); background: var(--bg); border-radius: 8px; padding: 7px; font-weight: 600; font-size: 12.5px; }
.practice-btn:hover { background: var(--hover); }
.review { margin: 0 14px 10px; border: 1px solid var(--border); border-radius: 10px; }
.review summary { display: flex; justify-content: space-between; padding: 9px 12px; cursor: pointer; font-weight: 600; font-size: 12.5px; list-style: none; }
.review summary::-webkit-details-marker { display: none; }
.review summary span:first-child { color: #c26a00; }
.review summary::after { content: "▾"; color: var(--muted); margin-left: 6px; }
.review[open] summary::after { content: "▴"; }
.review summary .rv-count { margin-left: auto; color: var(--muted); font-weight: 500; }
.rv-list { padding: 0 6px 8px; max-height: 260px; overflow-y: auto; }
.rv-item { display: flex; justify-content: space-between; width: 100%; border: 0; background: none; text-align: left; padding: 5px 8px; border-radius: 6px; font-size: 13px; }
.rv-item:hover { background: var(--hover); }
.rv-item small { color: var(--muted); }
.rv-empty { margin: 0 6px; font-size: 12px; color: var(--muted); }

/* practice dialog */
.practice-card { width: min(460px, calc(100vw - 24px)); }
.p-row { display: flex; align-items: center; gap: 10px; margin-bottom: 6px; }
.p-chapters { border: 1px solid var(--border); border-radius: 10px; max-height: 42vh; overflow-y: auto; padding: 4px; }
.p-ch { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px; cursor: pointer; }
.p-ch:hover { background: var(--hover); }
.p-ch span { flex: 1; }
.p-ch small { color: var(--muted); font-variant-numeric: tabular-nums; }
.p-opt { display: flex; gap: 8px; align-items: center; margin-top: 10px; }
.p-foot { display: flex; align-items: center; gap: 12px; margin-top: 16px; }
.p-foot span { flex: 1; color: var(--muted); font-size: 13px; }
.primary:disabled { opacity: .5; cursor: default; }
.modal.practicing .modal-title small { color: var(--accent); font-weight: 500; }

/* formula booklet */
.formulae {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100vw); z-index: 35;
  background: var(--panel); border-left: 1px solid var(--border); box-shadow: -8px 0 30px rgba(0,0,0,.18);
  display: flex; flex-direction: column; padding-top: env(safe-area-inset-top);
}
.f-head { display: flex; align-items: center; gap: 4px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.f-pages { flex: 1; overflow: auto; padding: 10px; display: flex; flex-direction: column; align-items: center; gap: 10px; background: var(--bg); }
.f-page { background: #fff; box-shadow: var(--shadow); border-radius: 4px; flex: none; overflow: hidden; }
.f-page canvas { width: 100%; height: 100%; display: block; }
.f-missing { padding: 20px; color: var(--text); max-width: 380px; }
.f-missing p { margin: 0 0 10px; }

/* resume + toast */
.resume {
  position: fixed; left: 16px; bottom: calc(16px + env(safe-area-inset-bottom)); z-index: 15; display: flex; align-items: stretch;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 8px 30px rgba(0,0,0,.18); overflow: hidden;
  max-width: calc(100vw - 32px);
}
.resume-go { border: 0; background: none; text-align: left; padding: 9px 14px; display: flex; flex-direction: column; min-width: 0; }
.resume-go small { color: var(--accent); font-weight: 600; font-size: 11.5px; }
.resume-go span { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resume-go:hover { background: var(--hover); }
.resume-x { border: 0; border-left: 1px solid var(--border); background: none; color: var(--muted); padding: 0 12px; }
.app-toast {
  position: fixed; left: 50%; top: 70px; transform: translateX(-50%); z-index: 60; background: var(--text); color: var(--panel);
  padding: 8px 14px; border-radius: 20px; font-size: 13px; box-shadow: var(--shadow); pointer-events: none;
}

/* dark pages */
#darkPages.on { background: var(--accent-soft); color: var(--accent); }
.dark-pages .page canvas, .dark-pages .clip-stack canvas, .dark-pages .f-page canvas, .dark-pages .scribble {
  filter: invert(.9) hue-rotate(180deg);
}
.dark-pages .f-page, .dark-pages .page { background: #1a1a1a; }

/* installed app: keep clear of the notch and home bar */
.topbar { padding-top: max(8px, env(safe-area-inset-top)); padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
@media (max-width: 640px) { .calc { padding-bottom: env(safe-area-inset-bottom); } }

/* typed notes */
.notes { width: 100%; max-width: 940px; margin: 14px auto 0; border: 1px solid var(--border); border-radius: 12px; padding: 10px 14px; background: var(--panel); position: relative; z-index: 3; }
.notes-head { display: flex; align-items: center; gap: 10px; }
.notes-status { color: var(--muted); font-size: 12px; }
.notes-view { margin-top: 8px; line-height: 1.6; font-size: 15px; overflow-x: auto; }
.notes-view .muted { color: var(--muted); }
.notes-view.preview { border-top: 1px dashed var(--border); padding-top: 8px; min-height: 24px; }
.notes-editor textarea {
  width: 100%; margin-top: 6px; padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text);
  font: 14px/1.5 ui-monospace, Menlo, monospace; resize: vertical; min-height: 90px;
}
.notes-editor textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.notes-insert { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.notes-insert button { border: 1px solid var(--border); background: var(--bg); border-radius: 6px; min-width: 34px; height: 28px; padding: 0 7px; font-size: 13px; }
.notes-insert button:hover { background: var(--hover); }
.notes-help { font-size: 11.5px; color: var(--muted); margin: 4px 0 6px; }
.notes-help code { background: var(--bg); padding: 0 4px; border-radius: 4px; }
#notesToggle.has::after { content: ""; position: absolute; top: 3px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--accent); }
.modal-tools .tool-btn#notesToggle span { display: inline; }
.notes .katex-display { margin: .4em 0; }

/* sidebar: quick links, due pill, past papers */
.side-links { display: flex; gap: 6px; margin-top: 8px; }
.side-links button { flex: 1; border: 1px solid var(--border); background: none; border-radius: 8px; padding: 5px 4px; font-size: 12px; white-space: nowrap; }
.side-links button:hover { background: var(--hover); }
.due-pill { background: #e08a00; color: #fff; border-radius: 10px; padding: 0 6px; font-size: 11px; font-weight: 600; }
.rv-item em.due { color: #c26a00; font-style: normal; font-weight: 600; }
.due-btn { margin: 0 0 6px; background: rgba(224, 138, 0, .12); border-color: transparent; color: #c26a00; }
.paper-box { margin-top: 10px; }
.pb-meta { font-size: 12px; color: var(--muted); }
.pb-score { font-size: 12.5px; margin-top: 8px; color: var(--muted); }
.pb-score b { color: var(--text); }
.sidebar .pq.scored .count { color: var(--accent); font-weight: 600; }
.paper-select { border: 0; background: var(--panel); color: var(--text); border-radius: 8px; padding: 6px 8px; font: inherit; font-weight: 500; box-shadow: var(--shadow); max-width: 200px; }

/* exam timer */
.exam-timer { display: flex; align-items: center; gap: 6px; background: var(--accent-soft); color: var(--accent); border-radius: 18px; padding: 3px 4px 3px 10px; font-weight: 600; font-variant-numeric: tabular-nums; }
.exam-timer button { border: 0; background: var(--panel); color: var(--text); border-radius: 14px; padding: 3px 9px; font-size: 12px; }
.exam-timer.low { background: rgba(224, 138, 0, .16); color: #c26a00; }
.exam-timer.over { background: rgba(217, 83, 79, .16); color: #c9302c; }
#showAnswer:disabled { opacity: .75; cursor: default; filter: grayscale(.4); }

/* rate bar */
.rate-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; margin: 18px auto 4px; max-width: 940px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--panel); position: relative; z-index: 3; }
.rb-label { font-weight: 600; font-size: 13px; margin-right: 4px; }
.rb { border: 1px solid var(--border); background: none; border-radius: 18px; padding: 6px 14px; font-weight: 600; font-size: 13px; }
.rb:hover { background: var(--hover); }
.rb.good.on { background: #16a34a; color: #fff; border-color: transparent; }
.rb.ok.on { background: #e08a00; color: #fff; border-color: transparent; }
.rb.bad.on { background: #dc2626; color: #fff; border-color: transparent; }
.rb-score { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; margin-left: 6px; }
.rb-score input { width: 58px; padding: 5px 6px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; text-align: center; }
.rb-next { flex-basis: 100%; text-align: center; font-size: 12.5px; color: var(--muted); min-height: 0; }
.rb-next:empty { display: none; }

/* dialogs */
.side-card { width: min(520px, calc(100vw - 24px)); }
.wide-card { width: min(820px, calc(100vw - 24px)); }
.full-card { width: min(1200px, calc(100vw - 24px)); height: calc(100vh - 32px); }
.full-card .modal-body { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.set-body section { padding: 4px 0 14px; border-bottom: 1px solid var(--border); margin-bottom: 12px; }
.set-body section:last-child { border-bottom: 0; }
.set-body h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
.seg { display: inline-flex; background: var(--bg); padding: 3px; border-radius: 10px; gap: 2px; }
.seg button { border: 0; background: none; padding: 6px 16px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.seg button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.set-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.set-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.set-tile { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 12px 6px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); font-size: 20px; text-decoration: none; color: inherit; }
.set-tile span { font-size: 12.5px; font-weight: 500; }
.set-tile:hover { background: var(--hover); }
.keys-table { border-collapse: collapse; font-size: 13px; width: 100%; }
.keys-table td { padding: 5px 4px; border-bottom: 1px solid var(--border); }
.keys-table td:first-child { white-space: nowrap; width: 1%; padding-right: 14px; }
kbd { font: 11.5px ui-monospace, Menlo, monospace; background: var(--bg); border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 5px; padding: 1px 5px; }
.set-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.set-actions .secondary, .nl-top .secondary { padding: 7px 12px; font-size: 13px; }
.reset-box { margin-top: 14px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px; }
.danger-btn { margin-top: 10px; background: #d9534f; color: #fff; border: 0; border-radius: 8px; padding: 7px 14px; font-weight: 600; }
.set-account { display: flex; justify-content: flex-end; }

/* stats */
.st-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.st-card { border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; }
.st-card .v { font-size: 22px; font-weight: 650; font-variant-numeric: tabular-nums; }
.st-card .l { color: var(--muted); font-size: 12.5px; }
.st-h { font-size: 13px; margin: 20px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.st-chart { display: flex; align-items: flex-end; gap: 3px; height: 110px; border-bottom: 1px solid var(--border); }
.st-bar { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.st-bar i { display: block; width: 100%; background: var(--accent); border-radius: 3px 3px 0 0; min-height: 1px; }
.st-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 3px; }
.st-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.st-table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; padding: 6px; border-bottom: 1px solid var(--border); }
.st-table td { padding: 7px 6px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.st-prog { display: inline-block; width: 90px; height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; vertical-align: middle; margin-right: 6px; }
.st-prog i { display: block; height: 100%; background: var(--accent); }
.st-r span { margin-right: 6px; font-weight: 600; }
.st-r .g { color: #16a34a; } .st-r .o { color: #c26a00; } .st-r .b { color: #dc2626; }
.muted { color: var(--muted); }

/* notes list */
.nl-top { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.nl-top input { flex: 1; min-width: 180px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); color: var(--text); font: inherit; }
.nl-item { border: 1px solid var(--border); border-radius: 10px; padding: 10px 14px; margin-bottom: 10px; cursor: pointer; }
.nl-item:hover { border-color: var(--accent); }
.nl-head { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; }
.nl-head small { color: var(--muted); white-space: nowrap; }

@media (max-width: 760px) { .exam-timer .et-icon { display: none; } .paper-select { max-width: 150px; } }
.book-tabs button { white-space: nowrap; }
@media (max-width: 1350px) { .year-tabs .long { display: none; } .year-tabs .short { display: inline; } }
.rb-go { padding: 7px 16px; font-size: 13px; margin-left: 4px; }
.res-bar { height: 10px; background: var(--border); border-radius: 5px; overflow: hidden; margin: 14px 0 6px; }
.res-bar i { display: block; height: 100%; background: var(--accent); }
.res-table td button.linkish { padding: 0; font: inherit; }
.res-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; color: var(--muted); }
.st-card .v .g { color: #16a34a; } .st-card .v .o { color: #c26a00; } .st-card .v .b { color: #dc2626; }


/* =====================================================================
   New UI: simple, friendly study look (overrides the styles above)
   ===================================================================== */
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; letter-spacing: .005em; }
button, .brand, h1, h2, h3, .modal-title span, .chapter, .bp-top, .review summary { font-family: var(--font-ui); }
::selection { background: var(--accent-soft); }

/* top bar */
.topbar { gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); background: var(--panel); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand-mark, .login-mark {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: 10px; color: #fff;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); font: italic 700 17px Georgia, "Times New Roman", serif;
}
.brand-mark sup, .login-mark sup { font-size: .55em; margin-left: 1px; }
.icon-btn { border-radius: 10px; min-width: 36px; height: 36px; color: var(--muted); display: inline-grid; place-items: center; }
.icon-btn:hover { background: var(--hover); color: var(--text); }
.book-tabs { background: var(--bg); padding: 4px; border-radius: 12px; gap: 2px; }
.book-tabs button { border-radius: 9px; padding: 6px 13px; font-weight: 600; font-size: 13.5px; }
.book-tabs button.active { background: var(--panel); color: var(--accent); box-shadow: var(--shadow); }
.year-tabs button.active { background: var(--accent); color: #fff; }
.paper-select { border: 1px solid var(--border); box-shadow: none; border-radius: 10px; padding: 7px 10px; font-family: var(--font-ui); font-weight: 600; }
.lookup { max-width: 460px; }
.lookup-icon { position: absolute; left: 11px; top: 50%; width: 16px; height: 16px; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.lookup input { padding: 9px 12px 9px 34px; border-radius: 12px; background: var(--bg); border-color: transparent; }
.lookup input:focus { background: var(--panel); outline: 3px solid var(--accent-soft); border-color: var(--accent); }
.lookup-results { border-radius: 14px; box-shadow: var(--shadow-lg); padding: 6px; }
.lookup-results button.sel, .lookup-results button:hover { background: var(--accent-soft); }
#signOut { display: none !important; }
.exam-timer { border-radius: 12px; }

/* floating page / zoom control */
.view-ctrl {
  position: sticky; bottom: 16px; margin: -44px auto 16px; width: max-content; z-index: 3;
  display: flex; align-items: center; gap: 4px; padding: 5px 8px; border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 92%, transparent); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); color: var(--muted); font-size: 13px;
}
.view-ctrl .icon-btn { min-width: 30px; height: 30px; font-size: 17px; }
.view-ctrl .pagejump { display: flex; padding-left: 4px; }
.view-ctrl .pagejump input { width: 46px; border-radius: 8px; padding: 4px; }
.view-ctrl #zoomLabel { min-width: 42px; }
.vc-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
#darkPages.on { background: var(--accent-soft); color: var(--accent); }

/* page area */
.pages { gap: 22px; padding: 26px 16px 90px; }
.page { border-radius: 6px; overflow: visible; box-shadow: 0 1px 3px rgba(30,34,56,.08), 0 8px 28px rgba(30,34,56,.08); }
.page canvas { border-radius: 6px; }
.qbox { border-radius: 8px; }
.qbox:hover, .qbox.hl { background: rgba(79, 91, 213, .07); border-color: var(--accent); }
.qbox .qtag { background: var(--accent); border-radius: 8px; padding: 2px 7px; }
.qbox.viewed::after { content: "✓"; left: -26px; width: 18px; height: 18px; border-radius: 50%; background: var(--good); color: #fff; font-size: 11px; display: grid; place-items: center; }

/* sidebar */
.sidebar { width: 290px; padding: 12px 0 40px; background: var(--panel); }
.book-progress { margin: 4px 14px 12px; padding: 14px; border-radius: var(--radius); border: 0; background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--panel-2); box-shadow: inset 0 0 0 1px var(--border); }
.bp-top span:first-child { font-size: 13px; }
.bp-count { font-size: 13px; color: var(--accent); font-weight: 700; }
.sidebar .bar { height: 6px; border-radius: 4px; background: var(--border); }
.sidebar .bar i { border-radius: 4px; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.practice-btn { border-radius: 10px; background: var(--panel); border: 1px solid var(--border); padding: 9px; font-family: var(--font-ui); font-size: 13px; }
.practice-btn:hover { border-color: var(--accent); color: var(--accent); background: var(--panel); }
.side-links button { border-radius: 10px; background: var(--panel); padding: 7px 4px; font-family: var(--font-ui); font-weight: 600; }
.side-links button:hover { border-color: var(--accent); color: var(--accent); background: var(--panel); }
.review { margin: 0 14px 12px; border-radius: var(--radius); background: var(--panel-2); }
.review summary { padding: 11px 14px; }
.sidebar .chapter { padding: 16px 16px 6px; font-size: 13px; color: var(--text); font-weight: 700; }
.sidebar .chapter .ch-count { color: var(--muted); }
.sidebar .chapter .bar { height: 4px; margin-top: 7px; }
.sidebar .ex { margin: 1px 10px; width: calc(100% - 20px); border-radius: 9px; padding: 7px 10px 7px 14px; font-size: 13.5px; color: var(--text); }
.sidebar .ex:hover { background: var(--hover); }
.sidebar .ex.current { background: var(--accent-soft); color: var(--accent); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent); }
.sidebar .count.complete { color: var(--good); }
.sidebar .count.complete::after, .ch-count.complete::after { color: var(--good); }

/* question window */
.modal-backdrop { background: rgba(15, 18, 32, .45); backdrop-filter: blur(3px); }
.modal-card { border-radius: 20px; box-shadow: var(--shadow-lg); overflow: hidden; }
.modal-head { padding: 12px 14px; border-bottom: 0; }
.modal-title span { font-size: 17px; font-weight: 700; }
.modal-head .icon-btn { border-radius: 50%; background: var(--bg); color: var(--text); }
.modal-head .icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.modal-head .icon-btn:disabled { opacity: .35; }
.modal-tools { padding: 4px 14px 12px; border-bottom: 1px solid var(--border); gap: 7px; }
.tool-btn, .done-toggle { border-radius: 10px; padding: 6px 12px; font-family: var(--font-ui); font-weight: 600; font-size: 13px; background: var(--panel); }
.tool-btn:hover, .done-toggle:hover { border-color: var(--accent); color: var(--accent); background: var(--panel); }
.done-toggle.is-done { background: rgba(22, 163, 74, .12); color: var(--good); }
.modal-body { background: var(--bg); padding: 22px; }
.clip-stack canvas { border-radius: 12px; box-shadow: var(--shadow); }
.answer-bar { margin: 22px 0; }
.primary { border-radius: 12px; padding: 11px 22px; font-family: var(--font-ui); font-weight: 700; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 4px 14px rgba(79, 91, 213, .3); }
.primary:hover { filter: brightness(1.06); }
.secondary { border-radius: 12px; font-family: var(--font-ui); }
.answer { border-top: 0; padding-top: 6px; }
.answer h4 { font-family: var(--font-ui); color: var(--accent); letter-spacing: .08em; }
.rate-bar { border-radius: var(--radius); box-shadow: var(--shadow); border: 0; }
.rb { border-radius: 10px; font-family: var(--font-ui); }
.rb.good.on { background: var(--good); } .rb.ok.on { background: var(--warn); } .rb.bad.on { background: var(--bad); }
.notes { border-radius: var(--radius); border: 0; box-shadow: var(--shadow); }

/* dialogs and panels */
.set-tile, .st-card, .nl-item, .reset-box, .p-chapters { border-radius: var(--radius); }
.st-card { background: var(--panel-2); border: 0; box-shadow: inset 0 0 0 1px var(--border); }
.st-bar i { background: linear-gradient(180deg, var(--accent-2), var(--accent)); }
.seg button.on { color: var(--accent); }
.formulae { border-radius: 20px 0 0 20px; }
.resume { border-radius: 14px; box-shadow: var(--shadow-lg); }
.resume-go small { color: var(--accent); }
.app-toast { border-radius: 12px; font-family: var(--font-ui); font-weight: 600; }
.calc { border-radius: 20px; box-shadow: var(--shadow-lg); }

/* sign-in */
.login { background: radial-gradient(1200px 600px at 20% 0%, var(--accent-soft), transparent 60%), var(--bg); }
.login-card { padding: 38px 32px; border-radius: 22px; box-shadow: var(--shadow-lg); align-items: center; }
.login-mark { width: 56px; height: 56px; border-radius: 16px; font-size: 28px; margin-bottom: 4px; }
.login-card h1 { font-size: 24px; }
.login-card .primary { width: 100%; }

@media (max-width: 760px) {
  .topbar { padding: 8px 10px; gap: 8px; }
  .brand-name { display: none; }
  .view-ctrl { bottom: 12px; }
  .view-ctrl .vc-dark { display: none; }
  .modal-body { padding: 12px 8px; }
  .modal-card { border-radius: 16px; }
}
@media (max-width: 1100px) { .brand-name { display: none; } }
.brand-mark, .login-mark { display: inline-flex; align-items: center; justify-content: center; line-height: 1; }
.brand-mark sup, .login-mark sup { vertical-align: super; position: relative; top: -.15em; }
.icon-btn { display: inline-flex; align-items: center; justify-content: center; gap: 0; }
.fx-btn { font-size: 15px; }
@media (max-width: 760px) { .brand { display: none; } }
.login-note { display: flex; gap: 10px; text-align: left; font-size: 13px; line-height: 1.45; color: var(--muted);
  background: var(--accent-soft); border-radius: 12px; padding: 10px 12px; width: 100%; }
.login-note b { display: block; color: var(--text); margin-bottom: 2px; }
.login-lock { font-size: 16px; line-height: 1.3; }
.login-card .login-foot { font-size: 12px; color: var(--muted); }
/* iPhone Safari draws neighbouring layers blurry when a sticky element uses backdrop-filter, so keep it solid */
.view-ctrl { background: var(--panel); backdrop-filter: none; -webkit-backdrop-filter: none; }
@media (max-width: 760px) { .modal-backdrop { backdrop-filter: none; -webkit-backdrop-filter: none; background: rgba(15, 18, 32, .55); } }
#settingsBtn svg { width: 19px; height: 19px; }
/* iPhone zooms the page in (and renders it blurry) when you tap a field with text under 16px */
@media (max-width: 760px), (pointer: coarse) {
  input, select, textarea, .paper-select, .lookup input, .calc-in, .calc-f input, .notes-editor textarea { font-size: 16px !important; }
  .view-ctrl .pagejump input { width: 52px; }
}
/* Keep the top bar clear of the iPhone status bar (the new-UI padding above had dropped the safe-area space) */
.topbar {
  padding-top: calc(env(safe-area-inset-top, 0px) + 10px);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}
@media (max-width: 760px) {
  .topbar { padding-top: calc(env(safe-area-inset-top, 0px) + 8px); padding-left: max(10px, env(safe-area-inset-left, 0px)); padding-right: max(10px, env(safe-area-inset-right, 0px)); }
}
/* home-screen app: iOS fades a blur a little below the clock, so leave a bit more room */
@media (display-mode: standalone) {
  .topbar { padding-top: calc(env(safe-area-inset-top, 0px) + 16px); }
}
/* offline downloads */
.set-hint { margin: -4px 0 10px; font-size: 13px; color: var(--muted); }
.off-progress { margin-bottom: 10px; font-size: 12.5px; color: var(--muted); }
.off-bar { height: 8px; border-radius: 5px; background: var(--border); overflow: hidden; margin-bottom: 5px; }
.off-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .2s; }
.small-btn { padding: 8px 16px; font-size: 13px; }
.small { font-size: 12.5px; }
/* collapsible chapters in the contents */
.sidebar .ch-group { margin: 2px 0; }
.sidebar button.chapter { display: block; width: calc(100% - 20px); margin: 4px 10px 0; text-align: left; border: 0; background: none; border-radius: 10px; padding: 10px 10px 8px; cursor: pointer; color: var(--text); }
.sidebar button.chapter:hover { background: var(--hover); }
.ch-top { align-items: center; }
.ch-chev { width: 16px; height: 16px; flex: none; display: inline-grid; place-items: center; color: var(--muted); transition: transform .18s; }
.ch-chev::before { content: ""; width: 6px; height: 6px; border-right: 2px solid currentColor; border-bottom: 2px solid currentColor; transform: rotate(-45deg); }
.ch-group.open .ch-chev { transform: rotate(90deg); }
.ch-top .ch-name { flex: 1; }
.ch-list { display: none; padding: 2px 0 6px; }
.ch-group.open .ch-list { display: block; }
.sidebar button.chapter .bar { margin-left: 24px; }
/* examiner report in the question window */
.er-box { width: 100%; max-width: 940px; margin: 18px auto 0; padding: 12px 14px; border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); }
.er-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.er-head h4 { margin: 0; flex: 1; }
.er-mean { font-size: 12.5px; font-weight: 600; color: var(--accent); background: var(--accent-soft); padding: 3px 9px; border-radius: 10px; }
.er-show { padding: 7px 12px; font-size: 13px; }
.er-clips:not(:empty) { margin-top: 10px; }
/* AI tutor */
.ai-box { width: 100%; max-width: 940px; margin: 18px auto 0; padding: 14px 16px; border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); position: relative; z-index: 3;
  border-top: 3px solid transparent; border-image: linear-gradient(90deg, var(--accent), var(--accent-2)) 1; }
.ai-head { display: flex; align-items: center; gap: 8px; }
.ai-badge { font-size: 11.5px; color: var(--accent); background: var(--accent-soft); padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.ai-warn { margin: 6px 0 10px; font-size: 12px; color: var(--muted); }
.ai-out .ai-turn + .ai-turn { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.ai-q { font-weight: 600; margin-bottom: 6px; color: var(--accent); }
.ai-q::before { content: "You: "; color: var(--muted); font-weight: 500; }
.ai-ask { display: flex; gap: 8px; margin-top: 12px; }
.ai-ask input { flex: 1; padding: 9px 12px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); color: var(--text); font: inherit; }
.ai-small { padding: 7px 14px; font-size: 13px; }
.err-text { color: var(--bad); }
.seg button { font-size: 13px; }
/* Casio emulators in the calculator panel */
.calc-models { display: flex; gap: 2px; margin: 8px 8px 0; background: var(--bg); padding: 3px; border-radius: 10px; }
.calc-models button { flex: 1; border: 0; background: none; padding: 6px 4px; border-radius: 8px; font: 600 12.5px var(--font-ui); color: var(--muted); }
.calc-models button.on { background: var(--panel); color: var(--accent); box-shadow: var(--shadow); }
.calc.emu { width: 380px; }
.calc.emu-cg50 { width: 360px; }
.calc-emu { position: relative; padding: 8px; }
.calc-frame { display: block; width: 100%; height: min(78vh, 720px); border: 0; border-radius: 12px; background: #111; }
.calc.emu-cg50 .calc-frame { height: min(80vh, 760px); }
.calc-emu-msg { position: absolute; left: 0; right: 0; top: 40%; text-align: center; color: #ddd; font-size: 13px; pointer-events: none; margin: 0; }
.calc-emu-msg:empty { display: none; }
@media (max-width: 640px) { .calc.emu, .calc.emu-cg50 { width: auto; } .calc-frame, .calc.emu-cg50 .calc-frame { height: 70vh; } }

/* the panel now only holds the Casio emulators */
.calc .calc-head, .calc [data-pane] { display: none !important; }
.calc-top { display: flex; align-items: center; gap: 4px; padding: 8px 8px 0; cursor: move; touch-action: none; }
.calc-top .calc-models { flex: 1; margin: 0; }
.calc-top .calc-x { flex: none; }
/* full screen: fill the screen (or window), with the calculator as tall as it fits */
.calc.full { inset: 0 !important; left: 0 !important; top: 0 !important; right: 0 !important; bottom: 0 !important;
  width: auto !important; max-height: none; height: 100dvh; border-radius: 0; border: 0; display: flex; flex-direction: column; z-index: 70;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
.calc.full .calc-top { cursor: default; max-width: 560px; width: 100%; margin: 0 auto; }
.calc.full .calc-emu { flex: 1; display: flex; justify-content: center; min-height: 0; }
.calc.full .calc-frame, .calc.full.emu-cg50 .calc-frame { height: 100%; width: auto; aspect-ratio: 470 / 1001; max-width: 100%; }
.calc.full:not(.emu-cg50) .calc-frame { aspect-ratio: 9 / 17; }
.calc:fullscreen { background: var(--panel); }
/* enlarged calculator: fills the page area under the top bar (not the whole screen) */
.calc.full { top: var(--calc-top, 0px) !important; height: auto !important; z-index: 30; border-radius: 0; padding-top: 0;
  box-shadow: none; border-top: 1px solid var(--border); }
/* welcome + Ask */
.ask-card { width: min(540px, calc(100vw - 24px)); display: flex; flex-direction: column; max-height: calc(100vh - 32px); background: var(--bg); }
.ask-hero { position: relative; text-align: center; padding: 30px 24px 20px; color: #fff;
  background: radial-gradient(120% 140% at 0% 0%, rgba(255,255,255,.22), transparent 55%), linear-gradient(135deg, var(--accent), #8b5cf6 60%, #ec4899); }
.ask-hero h2 { margin: 4px 0 4px; font-family: var(--font-ui); font-size: 26px; letter-spacing: -.01em; }
.ask-hero p { margin: 0; opacity: .9; font-size: 14.5px; }
.ask-x { position: absolute; top: 12px; right: 12px; background: rgba(255,255,255,.18) !important; color: #fff !important; border-radius: 50%; }
.ask-x:hover { background: rgba(255,255,255,.3) !important; }
.ask-emoji { width: 64px; height: 64px; margin: 0 auto 6px; border-radius: 50%; display: grid; place-items: center; font-size: 32px;
  background: rgba(255,255,255,.2); box-shadow: inset 0 0 0 1px rgba(255,255,255,.3); animation: askPop .5s cubic-bezier(.3,1.6,.6,1); }
.ask-dots { display: flex; justify-content: center; gap: 6px; margin-top: 14px; }
.ask-dots i { width: 8px; height: 8px; border-radius: 4px; background: rgba(255,255,255,.4); transition: width .25s, background .25s; }
.ask-dots i.on { width: 22px; background: #fff; }
.ask-body { padding: 20px 22px 22px; overflow-y: auto; }
.ask-body section { animation: askIn .25s ease; }
.ask-h { margin: 0 0 4px; font-size: 18px; font-family: var(--font-ui); }
.ask-books { display: flex; flex-direction: column; gap: 16px; margin: 14px 0 18px; max-height: 44vh; overflow-y: auto; padding: 2px; }
.ask-ghead { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.ask-ghead b { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.ask-all { border: 0; background: none; color: var(--accent); font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; padding: 2px 4px; }
.ask-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.ask-book { position: relative; display: flex; align-items: center; gap: 10px; min-height: 52px; padding: 10px 12px; border-radius: 14px; background: var(--panel);
  box-shadow: inset 0 0 0 1.5px var(--border); cursor: pointer; font-weight: 650; font-size: 14px; line-height: 1.25; transition: box-shadow .15s, background .15s, transform .1s; user-select: none; }
.ask-book:hover { box-shadow: inset 0 0 0 1.5px var(--accent-2); }
.ask-book:active { transform: scale(.98); }
.ask-book input { position: absolute; opacity: 0; pointer-events: none; }
.ask-check { flex: none; width: 22px; height: 22px; border-radius: 50%; box-shadow: inset 0 0 0 2px var(--border); display: grid; place-items: center; transition: background .15s, box-shadow .15s; }
.ask-check::after { content: "✓"; color: #fff; font-size: 13px; font-weight: 800; transform: scale(0); transition: transform .15s cubic-bezier(.3,1.6,.6,1); }
.ask-book:has(input:checked) { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.ask-book input:checked + .ask-check { background: var(--accent); box-shadow: none; }
.ask-book input:checked + .ask-check::after { transform: scale(1); }
.ask-book input:focus-visible + .ask-check { outline: 2px solid var(--accent); outline-offset: 2px; }
.ask-book.have, .ask-book.have:has(input) { cursor: default; background: var(--panel-2); box-shadow: inset 0 0 0 1.5px var(--border); opacity: .75; }
.ask-book.have .ask-check { background: var(--good); box-shadow: none; }
.ask-book.have .ask-check::after { transform: scale(1); }
#askModal { z-index: 80; } /* above the calculator */
.ask-name { min-width: 0; }
.ask-nav { display: flex; gap: 8px; align-items: center; margin-top: 8px; }
#askMsg { width: 100%; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: 14px; background: var(--panel); color: var(--text); font: inherit; resize: vertical; margin: 12px 0 4px; }
#askMsg:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ask-done { text-align: center; padding: 8px 0 4px; }
.ask-done .primary { margin-top: 10px; min-width: 180px; }
.ask-tick { width: 56px; height: 56px; border-radius: 50%; margin: 4px auto 12px; display: grid; place-items: center; font-size: 28px; color: #fff; background: var(--good);
  box-shadow: 0 6px 18px rgba(22,163,74,.35); animation: askPop .45s cubic-bezier(.3,1.6,.6,1); }
@keyframes askPop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes askIn { from { transform: translateY(6px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .ask-emoji, .ask-tick, .ask-body section { animation: none; } }
.my-requests { display: flex; flex-direction: column; gap: 4px; margin-top: 10px; }
.my-req { display: flex; gap: 8px; align-items: center; font-size: 13px; }
.my-req span:nth-child(2) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.req-open, .req-done { font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 10px; white-space: nowrap; }
.req-open { background: rgba(217, 119, 6, .12); color: var(--warn); }
.req-done { background: rgba(22, 163, 74, .12); color: var(--good); }

/* Settings → Offline */
.off-list { display: flex; flex-direction: column; gap: 14px; margin: 12px 0; }
.off-sec-h { display: flex; align-items: center; justify-content: space-between; margin: 0 4px 6px; }
.off-sec-h b { font-size: 11.5px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.off-all { border: 0; background: none; color: var(--accent); font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; padding: 2px 4px; }
.off-card { border-radius: 14px; background: var(--panel); box-shadow: inset 0 0 0 1px var(--border); overflow: hidden; }
.off-card > .off-item + .off-item, .off-card > .off-level + .off-level, .off-card > .off-item + .off-level { border-top: 1px solid var(--border); }
.off-item { display: flex; align-items: center; gap: 12px; min-height: 48px; padding: 8px 12px 8px 14px; cursor: pointer; transition: background .12s; }
.off-item:hover { background: var(--hover); }
.off-item input { flex: none; width: 18px; height: 18px; margin: 0; accent-color: var(--accent); cursor: pointer; }
.off-name { flex: 1; min-width: 0; display: flex; flex-direction: column; font-weight: 600; font-size: 14px; line-height: 1.25; }
.off-name small { color: var(--muted); font-weight: 500; font-size: 12px; margin-top: 1px; }
.off-pill { flex: none; font-style: normal; font-size: 11.5px; font-weight: 700; padding: 3px 9px; border-radius: 20px; white-space: nowrap; }
.off-pill.ok { background: rgba(22, 163, 74, .12); color: var(--good); }
.off-pill.part { background: rgba(217, 119, 6, .12); color: var(--warn); }
.off-del { flex: none; width: 30px; height: 30px; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: var(--muted); cursor: pointer; }
.off-del:hover { background: rgba(220, 38, 38, .1); color: var(--bad); }
.off-expand { flex: none; display: inline-flex; align-items: center; gap: 3px; border: 0; background: var(--accent-soft); color: var(--accent); border-radius: 20px; padding: 5px 10px 5px 12px; font: inherit; font-size: 12.5px; font-weight: 700; cursor: pointer; }
.off-expand svg { transition: transform .18s; }
.off-expand[aria-expanded="true"] svg { transform: rotate(180deg); }
.off-sub { max-height: 300px; overflow-y: auto; background: var(--panel-2); border-top: 1px solid var(--border); }
.off-item.sub { min-height: 40px; padding: 6px 12px 6px 44px; }
.off-item.sub + .off-item.sub { border-top: 1px solid var(--border); }
.off-item.sub .off-name { flex-direction: row; align-items: baseline; gap: 8px; font-weight: 500; font-size: 13px; }
.off-item.sub .off-name small { margin: 0 0 0 auto; }
.off-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.off-sum { flex: 1; min-width: 160px; display: flex; flex-direction: column; font-size: 13.5px; }
.off-sum span:empty { display: none; }
/* welcome → set up this device */
.dev-opts { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 10px; }
.dev-opt-wrap { border-radius: 16px; background: var(--panel); box-shadow: inset 0 0 0 1.5px var(--border); overflow: hidden; }
.dev-opt-wrap .dev-opt { box-shadow: none; border-radius: 0; }
.dev-opt-wrap:has(input:checked) { box-shadow: inset 0 0 0 2px var(--accent); }
.dev-opt-wrap.off { opacity: .6; }
.dev-opt { position: relative; display: flex; align-items: center; gap: 12px; padding: 14px; border-radius: 16px; background: var(--panel);
  box-shadow: inset 0 0 0 1.5px var(--border); cursor: pointer; user-select: none; transition: box-shadow .15s, background .15s; }
.dev-opt:hover { box-shadow: inset 0 0 0 1.5px var(--accent-2); }
.dev-opt > input { position: absolute; opacity: 0; pointer-events: none; }
.dev-opt > input:checked + .ask-check { background: var(--accent); box-shadow: none; }
.dev-opt > input:checked + .ask-check::after { transform: scale(1); }
.dev-opt > input:focus-visible + .ask-check { outline: 2px solid var(--accent); outline-offset: 2px; }
.dev-opt > input:disabled ~ * { cursor: default; }
label.dev-opt:has(input:checked) { box-shadow: inset 0 0 0 2px var(--accent); background: var(--accent-soft); }
.dev-opt-wrap label.dev-opt:has(input:checked) { box-shadow: none; }
.dev-ico { flex: none; width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-size: 20px; background: var(--accent-soft); }
.dev-txt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.dev-txt b { font-size: 15px; }
.dev-txt small { color: var(--muted); font-size: 12.5px; line-height: 1.35; }
.dev-models { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; padding: 0 14px 14px; background: var(--accent-soft); }
.dev-models button { text-align: left; display: flex; flex-direction: column; gap: 3px; padding: 10px 12px; border-radius: 12px; border: 0; background: var(--panel);
  box-shadow: inset 0 0 0 1.5px var(--border); color: var(--text); font: inherit; cursor: pointer; }
.dev-models button b { font-size: 14px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.dev-models button small { color: var(--muted); font-size: 12px; line-height: 1.3; }
.dev-models button.on { box-shadow: inset 0 0 0 2px var(--accent); }
.dev-rec { font-size: 10.5px; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; padding: 2px 7px; border-radius: 10px; background: var(--good); color: #fff; }
.dev-wifi { margin: 0 0 8px; }
@media (max-width: 420px) { .dev-models { grid-template-columns: 1fr; } }
