/* Teacher app: classic look only, two colour themes. "dark" is the default; "calm" is the light one. */
:root, :root[data-theme="dark"] {
  --bg: #1B1D21;          /* charcoal */
  --surface: #25282E;
  --border: #363A42;
  --text: #F2EFE9;        /* off white */
  --muted: #A3A7AE;
  --accent: #4C8DFF;      /* electric blue */
  --on-accent: #0A0F1F;
  --danger: #FF8A7A;
  --on-danger: #2A0B07;
  color-scheme: dark;
}
:root[data-theme="calm"] {
  --bg: #ECE9E4;          /* warm light gray */
  --surface: #F7F5F1;
  --border: #D3CEC6;
  --text: #2B2D30;        /* charcoal */
  --muted: #666A70;
  --accent: #0F6B6B;      /* deep teal */
  --on-accent: #FFFFFF;
  --danger: #B3261E;
  --on-danger: #FFFFFF;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px; line-height: 1.45;
  -webkit-text-size-adjust: 100%;
}
[hidden] { display: none !important; }
body { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
body > .login, body > #dash-view { flex: 1; }
body.auth-checking > * { visibility: hidden; } /* until the session check says login or dashboard */

h1, h2, p { margin: 0; }

/* ---------- login ---------- */
.login {
  display: flex; align-items: center; justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  position: relative;
}
.login-box {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  padding: 28px 22px 24px; display: flex; flex-direction: column;
}
.login-logo { width: 84px; height: 84px; object-fit: contain; align-self: center; margin-bottom: 10px; }
.login-box h1 { text-align: center; font-size: 22px; font-weight: 800; }
.login-sub { text-align: center; color: var(--muted); margin: 2px 0 22px; }
label { font-weight: 700; font-size: 14px; margin: 0 0 6px; }
input {
  width: 100%; height: 48px; padding: 0 14px; margin-bottom: 16px;
  background: var(--bg); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  font: inherit; font-size: 16px; /* 16px stops iOS zooming on focus */
}
input:focus-visible, .btn:focus-visible, .icon-btn:focus-visible, .pw-toggle:focus-visible, .theme-toggle:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
input:focus { border-color: var(--accent); }
.pw-wrap { position: relative; }
.pw-wrap input { padding-right: 70px; }
.pw-toggle {
  position: absolute; right: 4px; top: 4px; height: 40px; padding: 0 12px;
  background: none; border: 0; color: var(--accent); font: inherit; font-weight: 700; font-size: 14px; cursor: pointer;
}
.login-err { min-height: 20px; margin-bottom: 8px; color: var(--danger); font-size: 14px; font-weight: 600; }
.btn {
  height: 50px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--accent); color: var(--on-accent);
  font: inherit; font-size: 17px; font-weight: 800;
}
.btn:disabled { opacity: .6; cursor: default; }

/* theme switch (login: floating top-right; dashboard: in the header) */
.theme-toggle {
  position: absolute; top: max(14px, env(safe-area-inset-top)); right: 14px;
  height: 40px; padding: 0 14px; border-radius: 20px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  font: inherit; font-size: 14px; font-weight: 700; cursor: pointer;
}
.theme-dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 8px; vertical-align: -1px; background: var(--accent); }

/* ---------- dashboard ---------- */
.top {
  display: flex; align-items: center; gap: 12px;
  padding: max(12px, env(safe-area-inset-top)) 16px 12px;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.top-logo { width: 40px; height: 40px; object-fit: contain; }
.top-text { flex: 1; min-width: 0; }
.top-text h1 { font-size: 17px; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top-text p { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn {
  min-width: 40px; height: 40px; padding: 0 10px; border-radius: 10px;
  background: none; color: var(--text); border: 1px solid var(--border);
  display: inline-flex; align-items: center; justify-content: center;
  font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
}
.dash { padding: 22px 16px; max-width: 720px; margin: 0 auto; }
.dash h2 { font-size: 22px; font-weight: 800; margin-bottom: 16px; }
.screen-head h2 { margin-bottom: 0; }
.empty {
  border: 1px dashed var(--border); border-radius: 14px; padding: 36px 20px; text-align: center;
  background: var(--surface);
}
.empty p { font-weight: 700; }
.empty small { color: var(--muted); }

/* ---------- dashboard tiles ---------- */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tile {
  aspect-ratio: 1 / 0.9; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 16px;
  font: inherit; cursor: pointer; padding: 12px; -webkit-tap-highlight-color: transparent;
}
.tile:active { transform: scale(.97); border-color: var(--accent); }
.tile:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.tile-icon {
  width: 56px; height: 56px; border-radius: 14px; display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: var(--on-accent);
}
.tile-label { font-weight: 800; font-size: 16px; text-align: center; }
.back-btn {
  height: 40px; padding: 0 14px; margin-bottom: 14px; border-radius: 10px; cursor: pointer;
  background: none; color: var(--accent); border: 1px solid var(--border); font: inherit; font-weight: 700;
}

/* ---------- install bar + dialog ---------- */
.install-bar {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: calc(11px + env(safe-area-inset-top)) 14px 11px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--on-accent); font: inherit; font-weight: 800; font-size: 15px;
}
.install-bar[hidden] { display: none !important; }
.note-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 50; }
.note-box { background: var(--surface); color: var(--text); border: 1px solid var(--border); border-radius: 16px; padding: 22px; max-width: 360px; width: 100%; display: flex; flex-direction: column; gap: 16px; }

/* ---------- Add / Edit Question form ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; margin-bottom: 14px; }
.card label, .sheet-body label { display: block; margin-top: 4px; }
.card > label:first-child, .sheet-body > label:first-child { margin-top: 0; }
select, textarea {
  width: 100%; margin-bottom: 16px; padding: 0 14px;
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: 10px;
  font: inherit; font-size: 16px;
}
select { height: 48px; }
textarea { padding: 12px 14px; resize: vertical; line-height: 1.4; }
select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid var(--accent); outline-offset: 1px; }
select:disabled { opacity: .65; }
.req { color: var(--danger); }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.hint { color: var(--muted); font-size: 13px; margin: -8px 0 14px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.card-head h3 { margin: 0; font-size: 17px; font-weight: 800; }
.loading { color: var(--muted); text-align: center; padding: 30px 0; }
.btn.ghost { background: none; color: var(--accent); border: 1px solid var(--accent); }
.btn.sm { height: 38px; padding: 0 14px; font-size: 15px; }
.empty .btn { margin-top: 14px; padding: 0 20px; }
.link-btn { background: none; border: 0; padding: 6px 4px; color: var(--accent); font: inherit; font-weight: 700; cursor: pointer; }

.thumbs { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 12px; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button {
  position: absolute; top: 3px; right: 3px; width: 26px; height: 26px; border-radius: 50%; border: 0; cursor: pointer;
  background: rgba(0,0,0,.65); color: #fff; font-size: 18px; line-height: 1;
}
[data-f="add-images"] { width: 100%; margin-bottom: 16px; }

.subq-list { list-style: none; margin: 0; padding: 0; }
.subq-list li { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-top: 1px solid var(--border); }
.subq-list li.muted { color: var(--muted); border-top: 0; padding: 4px 0; }
.subq-no { flex: none; width: 24px; height: 24px; border-radius: 50%; background: var(--accent); color: var(--on-accent); font-weight: 800; font-size: 13px; display: flex; align-items: center; justify-content: center; margin-top: 2px; }
.subq-text { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.subq-text small { display: block; color: var(--muted); }
.subq-acts { flex: none; display: flex; flex-direction: column; align-items: flex-end; }

/* sticky save bar */
.savebar {
  position: sticky; bottom: 0; z-index: 5; margin: 0 -16px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px;
}
.savebar .btn { width: 100%; }
.btn-row { display: flex; gap: 10px; }
.btn-row .btn { width: auto; flex: 2; }
.btn-row .btn.secondary { flex: 1; }
.status { margin: 0; min-height: 0; font-size: 14px; font-weight: 600; color: var(--muted); }
.status:empty { display: none; }
.status.bad { color: var(--danger); }

/* sub-question sheet */
.sheet { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; }
.sheet-box { display: flex; flex-direction: column; flex: 1; min-height: 0; max-width: 720px; width: 100%; margin: 0 auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: max(12px, env(safe-area-inset-top)) 16px 12px; border-bottom: 1px solid var(--border); background: var(--surface); }
.sheet-head h2 { margin: 0; font-size: 18px; font-weight: 800; }
.sheet-head .back-btn { margin: 0; }
.sheet-body { flex: 1; overflow-y: auto; padding: 16px; }
.sheet .savebar { margin: 0; }
body.no-scroll { overflow: hidden; }

.toast {
  position: fixed; left: 50%; top: calc(14px + env(safe-area-inset-top)); transform: translate(-50%, -20px); opacity: 0; pointer-events: none;
  background: var(--text); color: var(--bg); font-weight: 800; padding: 12px 20px; border-radius: 12px; z-index: 60;
  max-width: calc(100% - 32px); box-shadow: 0 6px 20px rgba(0,0,0,.35); transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* title row: title (+ summary line) on the left, action button on the right */
.screen-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.screen-head h2 { margin: 0; }
.screen-titles { min-width: 0; }
.screen-sub { margin: 2px 0 0; color: var(--muted); font-size: 14px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.screen-sub[hidden] { display: none; }
.plus-btn {
  flex: none; width: 44px; height: 44px; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--accent); border: 1px solid var(--accent);
}

/* paste button in the label row, above the text box */
.label-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 6px; min-height: 36px; }
.label-row label { margin: 0 !important; }
.paste-btn {
  flex: none; width: 36px; height: 36px; border-radius: 9px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  background: var(--surface); color: var(--accent); border: 1px solid var(--border);
}
.paste-btn:active { border-color: var(--accent); }
.paste-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* secondary + danger buttons, confirm dialog */
.btn.secondary { background: none; color: var(--text); border: 1px solid var(--border); }
.btn.danger { background: var(--danger); color: var(--on-danger); }
.note-box h3 { margin: 0; font-size: 18px; font-weight: 800; }
.note-box p { margin: 0; }
.dlg-btns { display: flex; gap: 10px; }
.dlg-btns .btn { flex: 1; }

/* ---------- Question Bank ---------- */
.filters { padding: 12px; margin-bottom: 10px; }
.filters select { margin-bottom: 0; }
.filters .two { margin-bottom: 10px; }
.q-count { margin: 0 2px 8px; color: var(--muted); font-size: 14px; font-weight: 600; min-height: 20px; }
.q-list { list-style: none; margin: 0 0 14px; padding: 0; display: grid; gap: 10px; }
.q-list .loading { padding: 20px 0; }
.q-item {
  width: 100%; display: flex; align-items: center; gap: 12px; text-align: left; font: inherit; cursor: pointer;
  padding: 12px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  -webkit-tap-highlight-color: transparent;
}
.q-item:active { border-color: var(--accent); }
.q-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.q-no { flex: none; width: 72px; font-weight: 800; display: flex; flex-direction: column; overflow-wrap: anywhere; }
.q-no small { font-weight: 600; color: var(--muted); font-size: 12px; }
.q-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.q-text { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.q-meta { color: var(--muted); font-size: 13px; }
.q-pills { flex: none; display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.pill { font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px; background: var(--bg); color: var(--muted); border: 1px solid var(--border); white-space: nowrap; }
.pill.mine { background: var(--accent); color: var(--on-accent); border-color: var(--accent); }
.q-more { width: 100%; margin-bottom: 14px; }

/* read-only question view */
.qv-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.qv-meta div { display: flex; flex-direction: column; min-width: 0; }
.qv-meta span { color: var(--muted); font-size: 13px; }
.qv-meta b { overflow-wrap: anywhere; }
.qv-text { margin: 0 0 10px; white-space: pre-wrap; overflow-wrap: anywhere; font-weight: 600; }
.qv-opts { list-style: none; margin: 0 0 10px; padding: 0; display: grid; gap: 6px; }
.qv-opts li { padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; background: var(--bg); overflow-wrap: anywhere; }
.qv-opts li.ok { border-color: var(--accent); }
.qv-opts .tick { color: var(--accent); font-weight: 700; font-size: 13px; }
.qv-line { margin: 0 0 8px; overflow-wrap: anywhere; }
.qv-line.muted { color: var(--muted); font-size: 14px; }
.qv-line a { color: var(--accent); }
.qv-subhead { margin: 14px 0 6px; padding-top: 12px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; }
.qv-sub { margin-left: 0; }

/* ---------- homework screens ---------- */
.hw-day { flex: none; width: 88px; font-weight: 800; display: flex; flex-direction: column; }
.hw-day small { font-weight: 600; color: var(--muted); font-size: 12px; }
.notice { margin: 0 0 14px; padding: 12px 14px; border-radius: 12px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); font-weight: 600; }
.pick-list { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 8px; }
.pick-list .loading { padding: 14px 0; }
.card label.pick-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 12px; margin: 0; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); cursor: pointer; font-weight: 400; }
.pick-row input { flex: none; width: 22px; height: 22px; margin: 2px 0 0; padding: 0; accent-color: var(--accent); }
.pick-row:has(input:checked) { border-color: var(--accent); }
.pick-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.pick-top { display: flex; align-items: center; gap: 8px; }
.card .muted, .card-head .muted { color: var(--muted); font-size: 14px; }
.btn.danger-outline { width: 100%; margin-bottom: 14px; background: none; color: var(--danger); border: 1px solid var(--danger); }
[data-f="sel-list"] .subq-text { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.pick-body .q-text { -webkit-line-clamp: 3; }
