:root {
  --bg: #f6f5f1; --card: #ffffff; --ink: #1d2433; --muted: #5d6676; --line: #e2e0d8;
  --brand: #2f5bd3; --brand-ink: #ffffff; --soft: #eef2fd;
  --green: #1f9d55; --amber: #e0a100; --orange: #e8742a; --red: #d64545; --grey: #c9ccd3;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
.wrap { max-width: 760px; margin: 0 auto; padding: 24px 16px 80px; }
.wide { max-width: 1400px; }
h1 { font-size: 1.6rem; margin: 0 0 4px; }
h2 { font-size: 1.2rem; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 20px; margin: 14px 0; }
.center { min-height: 80vh; display: grid; place-items: center; }
.center .card { width: 100%; max-width: 420px; text-align: center; padding: 32px 24px; }
input[type=text], input[type=password], input[type=number], textarea, select {
  width: 100%; font: inherit; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink);
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); }
textarea { min-height: 140px; resize: vertical; }
button, .btn {
  font: inherit; font-weight: 600; border: 0; border-radius: 10px; padding: 12px 18px; cursor: pointer;
  background: var(--brand); color: var(--brand-ink); text-decoration: none; display: inline-block;
}
button.secondary, .btn.secondary { background: var(--soft); color: var(--brand); }
button.ghost { background: transparent; color: var(--muted); padding: 6px 10px; }
button:disabled { opacity: .5; cursor: default; }
.stack > * + * { margin-top: 12px; }
.error { color: var(--red); min-height: 1.5em; }
.logo { font-size: 2.4rem; }

.dates { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.date-btn { background: var(--card); color: var(--ink); border: 1.5px solid var(--line); text-align: left; padding: 16px; border-radius: 12px; }
.date-btn:hover { border-color: var(--brand); }
.date-btn .d { font-size: 1.1rem; display: block; }
.date-btn .s { font-weight: 400; color: var(--muted); font-size: .85rem; }
.date-btn.empty { opacity: .6; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.q-head { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.q-num { font-weight: 700; color: var(--brand); }
.saved { font-size: .8rem; color: var(--muted); min-height: 1.2em; }
.score-pill { font-weight: 700; padding: 2px 10px; border-radius: 999px; color: #fff; font-size: .85rem; white-space: nowrap; }

/* traffic light */
.s-none { background: var(--grey); }
.s-0 { background: var(--red); }
.s-low { background: var(--orange); }
.s-mid { background: var(--amber); }
.s-full { background: var(--green); }

/* teacher grid */
.grid-wrap { overflow-x: auto; }
table.grid { border-collapse: separate; border-spacing: 4px; }
table.grid th { font-size: .85rem; color: var(--muted); font-weight: 600; text-align: left; padding: 4px 8px; white-space: nowrap; }
table.grid th.qcol { cursor: pointer; text-align: center; border-radius: 8px; }
table.grid th.qcol:hover, table.grid th.qcol.active { background: var(--soft); color: var(--brand); }
table.grid td.cell { width: 64px; height: 36px; border-radius: 8px; text-align: center; color: #fff; font-weight: 700; font-size: .85rem; cursor: pointer; }
table.grid td.name { white-space: nowrap; padding-right: 12px; font-weight: 600; }
.typing { animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .55; } }

.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.answer { background: var(--card); border: 1px solid var(--line); border-left: 6px solid var(--grey); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.answer .who { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 700; }
.answer .text { white-space: pre-wrap; word-break: break-word; min-height: 3em; }
.answer .text.empty { color: var(--muted); font-style: italic; }
.answer .pts { list-style: none; margin: 0; padding: 0; font-size: .82rem; color: var(--muted); }
.answer .pts li.hit { color: var(--green); font-weight: 600; }
.answer .override { display: flex; gap: 6px; align-items: center; font-size: .85rem; }
.answer .override input { width: 70px; padding: 6px 8px; }
.b-none { border-left-color: var(--grey); } .b-0 { border-left-color: var(--red); } .b-low { border-left-color: var(--orange); }
.b-mid { border-left-color: var(--amber); } .b-full { border-left-color: var(--green); }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: .82rem; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--c); }
.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar label { display: flex; gap: 6px; align-items: center; font-size: .9rem; cursor: pointer; }
.scheme { background: var(--soft); border-radius: 10px; padding: 12px 16px; font-size: .9rem; }
.scheme ol { margin: 6px 0 0; padding-left: 20px; }
.live-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--green); margin-right: 6px; }
.live-dot.off { background: var(--red); }

/* question types */
.intro { background: var(--soft); border-radius: 10px; padding: 10px 14px; margin: 0; }
img.fig { cursor: zoom-in; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 10px; background: #fff; display: block; }
.q-text { font-weight: 500; }
label.opt { display: flex; gap: 12px; align-items: center; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px; cursor: pointer; margin-top: 8px; background: #fff; }
label.opt input { width: 22px; height: 22px; flex: none; margin: 0; }
label.opt:has(input:checked) { border-color: var(--brand); background: var(--soft); }
label.gap { display: grid; gap: 6px; margin-top: 10px; }
label.gap select { font-size: 16px; }
label.opt.right, label.gap.right select { border-color: var(--green); background: #e8f6ee; }
label.opt.wrong, label.gap.wrong select { border-color: var(--red); background: #fdeeee; }
label.opt.right::after { content: "✓"; margin-left: auto; color: var(--green); font-weight: 700; }
label.opt.wrong::after { content: "✗"; margin-left: auto; color: var(--red); font-weight: 700; }
label.gap.right span::after { content: "  ✓"; color: var(--green); font-weight: 700; }
label.gap.wrong span::after { content: "  ✗"; color: var(--red); font-weight: 700; }
.submit-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 12px; }
.fb { background: #f3f7f4; border-radius: 10px; padding: 10px 14px; font-size: .9rem; }
.fb ul { list-style: none; margin: 6px 0 0; padding: 0; color: var(--muted); }
.fb li.hit { color: var(--green); font-weight: 600; }
textarea[readonly] { background: #f3f3f0; }

/* leaderboard */
ol.lb { list-style: none; margin: 0; padding: 0; }
ol.lb li { display: flex; gap: 12px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--line); }
ol.lb li:last-child { border-bottom: 0; }
ol.lb .rank { width: 32px; text-align: center; font-weight: 700; color: var(--muted); }
ol.lb .who { flex: 1; font-weight: 600; }
ol.lb .pts { font-weight: 700; color: var(--brand); }
ol.lb li.me { background: var(--soft); border-radius: 8px; }

/* teacher roster */
.roster { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.roster .r { display: flex; justify-content: space-between; align-items: center; gap: 8px; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; background: #fff; }
.roster .r button { padding: 6px 10px; font-size: .8rem; background: #fdeeee; color: var(--red); }
.chip { display: inline-flex; gap: 6px; align-items: center; background: var(--soft); border-radius: 999px; padding: 4px 10px; font-size: .85rem; margin: 4px 4px 0 0; }
.chip button { padding: 0 4px; background: transparent; color: var(--muted); }
button.small { padding: 6px 10px; font-size: .85rem; }

.site-btn { font-weight: 700; }
.site-btn.open { background: #e8f6ee; color: var(--green); border: 1.5px solid var(--green); }
.site-btn.closed { background: #fdeeee; color: var(--red); border: 1.5px solid var(--red); }

/* calculator (copied from the revision app) */
.calc-bar { margin-top: 10px; }
.calc { margin-top: 10px; max-width: 480px; background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 12px; outline: none; }
.c-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.c-head .c-done { margin-left: auto; font-weight: 600; color: var(--brand); }
.c-screen { position: relative; background: #eef0f3; border-radius: 12px; padding: 10px; }
.c-hist { position: absolute; top: 6px; right: 8px; font-size: .7rem; color: var(--muted); }
.c-expr { min-height: 48px; overflow-x: auto; white-space: nowrap; font-size: 24px; display: flex; align-items: center; }
.c-bottom { display: flex; justify-content: space-between; align-items: flex-end; min-height: 40px; gap: 8px; }
.c-fmt { display: inline-flex; background: rgba(0,0,0,.08); border-radius: 999px; padding: 2px; flex: none; }
.c-fmt button { background: transparent; color: var(--ink); font-size: .75rem; padding: 5px 10px; border-radius: 999px; }
.c-fmt button.on { background: var(--brand); color: #fff; }
.c-ans { font-size: 30px; font-weight: 600; font-variant-numeric: tabular-nums; text-align: right; overflow-x: auto; white-space: nowrap; }
.c-ans.err { color: var(--red); font-size: 20px; }
.c-keys { display: grid; gap: 5px; margin-top: 8px; }
.c-fn { grid-template-columns: repeat(6, 1fr); }
.c-num { grid-template-columns: repeat(5, 1fr); gap: 6px; }
.c-key { padding: 0; min-height: 40px; border-radius: 9px; font-weight: 600; color: var(--ink); touch-action: manipulation; -webkit-user-select: none; user-select: none; }
.c-num .c-key { min-height: 48px; }
.c-key.k-number { background: #e1e3e8; font-size: 1.2rem; font-weight: 500; }
.c-key.k-operation { background: #d5ddf6; font-size: 1.15rem; }
.c-key.k-function { background: #eceef1; }
.c-key.k-arrow { background: #f4f5f7; }
.c-key.k-clear { background: #a34400; color: #fff; }
.c-key.k-equals { background: var(--green); color: #fff; font-size: 1.3rem; }
.c-key.wide { grid-column: span 2; }
.c-key:active { filter: brightness(.88); }
.c-insert { width: 100%; margin-top: 10px; }
.fr-key { display: inline-flex; flex-direction: column; align-items: center; gap: 2px; vertical-align: middle; }
.fr-key i { width: 9px; height: 8px; border: 1.2px solid currentColor; border-radius: 1px; display: block; }
.fr-key b { width: 13px; height: 1.5px; background: currentColor; display: block; }
.m-row { display: inline-flex; align-items: center; gap: 1px; }
.m-frac { display: inline-flex; flex-direction: column; align-items: center; font-size: .85em; margin: 0 2px; vertical-align: middle; }
.m-bar { align-self: stretch; height: 1.5px; background: currentColor; margin: 2px 0; }
.m-sup { font-size: .6em; align-self: flex-start; margin-top: -.2em; }
.m-root { border-top: 1.2px solid currentColor; padding: 3px 1px 0; }
.m-empty { display: inline-flex; align-items: center; justify-content: center; width: .55em; height: .75em; border: 1px dashed #999; border-radius: 2px; }
.m-empty.on { border-color: var(--brand); }
.m-cursor { display: inline-block; width: 2px; height: 1.05em; background: var(--brand); animation: blink 1s steps(1) infinite; }
@keyframes blink { 50% { opacity: .15; } }

/* ---- equations sheet & periodic table (reference.js) */
.ref-bar { position: sticky; top: 0; z-index: 5; display: flex; gap: 8px; flex-wrap: wrap; padding: 8px 0; background: var(--bg); }
.ref-bar button { padding: 10px 14px; }
html.ref-open, html.ref-open body { overflow: hidden; }
.ref-sheet { position: fixed; inset: 0; z-index: 100; background: rgba(20,24,33,.45); display: flex; align-items: stretch; justify-content: center; padding: 16px; }
.ref-sheet.hidden { display: none; }
.ref-panel { position: relative; background: var(--card); border-radius: 16px; width: 100%; max-width: 1240px; display: flex; flex-direction: column; overflow: hidden; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.ref-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.ref-tabs { display: flex; background: var(--soft); border-radius: 10px; padding: 3px; }
.ref-tabs button { background: transparent; color: var(--brand); padding: 8px 14px; border-radius: 8px; }
.ref-tabs button.on { background: var(--brand); color: var(--brand-ink); }
.ref-done { padding: 8px 16px; }
.ref-body { flex: 1; overflow: auto; -webkit-overflow-scrolling: touch; padding: 16px; }
.ref-zoom { position: absolute; right: 14px; bottom: 14px; display: flex; gap: 6px; }
.ref-zoom.hidden { display: none; }
.ref-zoom button { min-width: 48px; min-height: 44px; padding: 8px 12px; box-shadow: 0 2px 8px rgba(0,0,0,.2); }
.pt-wrap { overflow: hidden; }
.pt-inner { transform-origin: top left; width: max-content; }
.pt { position: relative; color: #1d2433; }
.pt > div { position: absolute; box-sizing: border-box; }
.pt-g { top: 0; text-align: center; font-weight: 700; font-size: 13px; color: var(--muted); line-height: 26px; }
.pt-el { border: 1px solid rgba(0,0,0,.18); text-align: center; padding: 3px 2px; display: flex; flex-direction: column; justify-content: space-between; line-height: 1.1; overflow: hidden; }
.pt-el .ms, .pt-el .no { font-size: 10px; }
.pt-el .sy { font-size: 20px; font-weight: 700; }
.pt-el .nm { font-size: 8.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pt-key { font-size: 12px; }
.pt-keybox { margin-top: 4px; border: 1px solid #888; border-radius: 4px; background: #fff; width: 128px; text-align: center; padding: 4px; font-size: 10px; line-height: 1.3; }
.pt-keybox b { font-size: 18px; display: block; }
.pt-note { font-size: 12px; color: var(--muted); margin: 10px 0 6px; }
.pt-legend { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }
.pt-legend i { display: inline-block; width: 14px; height: 14px; border-radius: 3px; margin-right: 6px; vertical-align: -2px; border: 1px solid rgba(0,0,0,.15); }
.eqs { list-style: none; margin: 0; padding: 0; }
.eqs li { padding: 10px 4px; border-bottom: 1px solid var(--line); }
.eq-line { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; }
.eq-line.sym { color: var(--muted); margin-top: 4px; font-family: "Times New Roman", serif; font-style: italic; font-size: 1.05rem; }
.eq-frac { display: inline-flex; flex-direction: column; align-items: center; vertical-align: middle; }
.eq-frac .bar { align-self: stretch; height: 1.2px; background: currentColor; margin: 1px 0; }
.ht, .sep { font-size: .7rem; font-weight: 700; padding: 1px 6px; border-radius: 5px; font-style: normal; font-family: system-ui, sans-serif; }
.ht { background: #fde7c7; color: #8a4b00; }
.sep { background: #e2dcf7; color: #4b2f99; }

/* ---- tap-to-zoom pictures (zoom.js) */
.zoom-sheet { position: fixed; inset: 0; z-index: 110; background: #fff; }
.zoom-sheet.hidden { display: none; }
.zoom-stage { position: absolute; inset: 0; overflow: hidden; touch-action: none; background: #f2f2f2; }
.zoom-stage img { position: absolute; left: 0; top: 0; transform-origin: 0 0; max-width: none; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.zoom-top { position: absolute; left: 0; right: 0; top: 0; display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); }
.zoom-done { padding: 8px 18px; }
.zoom-sheet .ref-zoom { position: absolute; }
.fig-hint { margin: 4px 0 0; }
.masked { -webkit-text-security: disc; text-security: disc; }
