@import url('../fonts/kantumruy-pro.css');
@import url('../katex/katex.min.css');

:root {
  --ink: #16212e;
  --muted: #5f6f81;
  --line: #e1e8f0;
  --bg: #f2f6fb;
  --card: #ffffff;
  --brand: #6b63e0;
  --brand-dark: #5249c6;
  --brand-soft: #efedff;
  --good: #16895a;
  --good-soft: #e3f6ec;
  --bad: #d23b3b;
  --bad-soft: #fdeaea;
  --warn: #b7791f;
  --warn-soft: #fff4dc;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(22, 33, 46, .05), 0 6px 18px rgba(22, 33, 46, .06);
  --shadow-lg: 0 10px 40px rgba(22, 33, 46, .18);
}

/* A class that sets display:flex/block on an element also carrying the [hidden]
   attribute would otherwise win over the browser's default [hidden]{display:none} —
   force hidden to always actually hide. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Kantumruy Pro', system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.65;
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--brand); text-decoration: none; }

.wrap { max-width: 780px; margin: 0 auto; padding: 18px 16px 40px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 16px; box-shadow: var(--shadow); }

h1 { font-size: 24px; margin: 0 0 6px; line-height: 1.35; }
h2 { font-size: 19px; margin: 0 0 12px; line-height: 1.4; }
h3 { font-size: 15px; margin: 0 0 8px; color: var(--muted); }
.muted { color: var(--muted); font-size: 14px; }

label { display: block; font-size: 14px; margin: 12px 0 5px; color: var(--muted); font-weight: 500; }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], input[type=date], input[type=time], textarea, select {
  width: 100%; padding: 11px 13px; border: 1.5px solid var(--line); border-radius: 10px;
  font-family: inherit; font-size: 16px; background: #fff; color: var(--ink);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 4px rgba(107, 99, 224, .14); }
textarea { resize: vertical; min-height: 60px; }

button, .btn {
  display: inline-block; border: 1.5px solid transparent; border-radius: 10px; padding: 10px 18px;
  font-family: inherit; font-size: 15px; font-weight: 600; cursor: pointer; line-height: 1.4;
  background: var(--brand); color: #fff; transition: background .15s, transform .05s, box-shadow .15s;
  -webkit-tap-highlight-color: transparent;
}
button:hover, .btn:hover { background: var(--brand-dark); }
button:active, .btn:active { transform: translateY(1px); }
button:focus-visible, .btn:focus-visible { outline: 3px solid rgba(107, 99, 224, .35); outline-offset: 2px; }
button.secondary { background: #fff; color: var(--brand); border-color: #bcd0f3; }
button.secondary:hover { background: var(--brand-soft); }
button.danger { background: #fff; color: var(--bad); border-color: #f0b8b8; }
button.danger:hover { background: var(--bad-soft); }
button.good { background: var(--good); }
button.good:hover { background: #0f6e47; }
button:disabled { opacity: .5; cursor: not-allowed; }
.btn-block { display: block; width: 100%; padding: 13px 18px; font-size: 16px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

.error { background: var(--bad-soft); border: 1px solid #f3c2c2; color: var(--bad); padding: 10px 14px; border-radius: 10px; margin: 12px 0; font-size: 14px; font-weight: 500; }
.notice { background: var(--brand-soft); border: 1px solid #c9dafb; color: var(--brand-dark); padding: 10px 14px; border-radius: 10px; margin: 12px 0; font-size: 14px; }

/* Teacher tabs: a segmented bar that scrolls sideways on a phone */
.tabs { display: flex; gap: 6px; margin-bottom: 16px; padding: 5px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); overflow-x: auto; }
.tabs button { background: transparent; color: var(--muted); border: none; font-weight: 600; white-space: nowrap; padding: 9px 14px; }
.tabs button:hover { background: var(--brand-soft); color: var(--brand); }
.tabs button.active { background: var(--brand); color: #fff; }

.list-item { display: flex; justify-content: space-between; align-items: center; padding: 12px 0; border-bottom: 1px solid var(--line); gap: 10px; }
.list-item:last-child { border-bottom: none; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.open { background: var(--good-soft); color: var(--good); }
.badge.upcoming { background: var(--warn-soft); color: var(--warn); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.closed { background: #eceff3; color: var(--muted); }
.badge.draft { background: #eceff3; color: var(--muted); }
.badge.ready { background: var(--good-soft); color: var(--good); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 600; background: #f7f9fc; position: sticky; top: 0; }
tbody tr:hover { background: #f9fbfe; }
td input[type=number] { width: 70px; padding: 6px 8px; }

/* MCQ widget — a real on-screen list of choices, not a bare <ul> */
.radio-list { display: flex; flex-direction: column; gap: 10px; margin: 12px 0; }
.radio-opt {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1.5px solid var(--line); border-radius: 12px; cursor: pointer; background: #fff;
  transition: border-color .12s, background .12s, box-shadow .12s;
}
.radio-opt:hover { background: #f5f9ff; border-color: #bcd0f3; }
.radio-opt.selected { border-color: var(--brand); background: var(--brand-soft); box-shadow: 0 0 0 3px rgba(107, 99, 224, .12); }
.radio-opt input[type=radio] { position: absolute; opacity: 0; pointer-events: none; }
.opt-letter {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center;
  background: #eef2f8; color: var(--muted); font-weight: 700; font-size: 15px;
}
.radio-opt.selected .opt-letter { background: var(--brand); color: #fff; }
.radio-opt .opt-body { min-width: 0; font-size: 17px; }

/* math-typing toolbar + live preview (see js/mathtype.js) */
.mathbar { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0; padding: 5px; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; }
.mk {
  min-width: 36px; height: 34px; padding: 0 8px; display: inline-flex; align-items: center; justify-content: center;
  white-space: nowrap; font-size: 15px; color: var(--ink); background: #fff; border: 1px solid var(--line);
  border-radius: 6px; cursor: pointer; font-weight: 500; transition: all .15s ease; user-select: none;
}
.mk:hover { border-color: var(--brand); background: #f1f8fd; color: var(--brand); }
.mk:active { transform: scale(0.97); }
.mk i { font-style: italic; font-family: 'Times New Roman', serif; font-size: 1.05em; }
.mk sup { font-size: 0.72em; vertical-align: super; line-height: 0; }
.mk sub { font-size: 0.72em; vertical-align: sub; line-height: 0; }
.time-shortcuts { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0 12px; }
.time-pill { font-size: 13px; padding: 6px 13px; border-radius: 16px; background: #eef3f9; color: var(--ink); border: 1px solid var(--line); cursor: pointer; transition: all .15s; font-family: inherit; font-weight: 500; }
.time-pill:hover { background: var(--brand); color: #fff; border-color: var(--brand); }
.mk-frac { display: inline-flex; flex-direction: column; align-items: center; font-size: 11px; line-height: 1.05; }
.mk-frac i:first-child { border-bottom: 1px solid currentColor; padding: 0 2px; font-style: normal; }
.mk-frac i { font-style: normal; }
.mpv { margin: 2px 0 8px; padding: 6px 10px; font-size: 15px; line-height: 1.8; background: var(--brand-soft); border-left: 3px solid var(--brand); border-radius: 0 6px 6px 0; overflow-x: auto; }
.mpv[hidden] { display: none; }
.mpv-lbl { font-size: 12.5px; color: var(--muted); }

.question-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; margin-bottom: 14px; background: #fff; box-shadow: var(--shadow); }
.question-card img { max-width: 100%; border-radius: 8px; margin: 8px 0; }
.q-count { font-weight: 700; color: var(--brand); }
.q-stem { font-size: 19px; font-weight: 500; margin: 8px 0 14px; line-height: 1.7; }
.question-nav { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 16px; }
.question-nav button { width: 38px; height: 38px; padding: 0; background: #fff; color: var(--ink); border: 1.5px solid var(--line); font-weight: 600; border-radius: 10px; }
.question-nav button:hover { background: var(--brand-soft); }
.question-nav button.answered { background: var(--good-soft); border-color: var(--good); color: var(--good); }
.question-nav button.current { outline: 3px solid rgba(107, 99, 224, .45); outline-offset: 1px; }

.progress { height: 6px; background: #dfe7f2; border-radius: 99px; overflow: hidden; margin-top: 4px; }
.progress-fill { height: 100%; width: 0; background: var(--good); border-radius: 99px; transition: width .3s; }

.timer { position: sticky; top: 0; z-index: 5; background: rgba(255, 255, 255, .96); backdrop-filter: blur(6px); border-bottom: 1px solid var(--line); padding: 10px 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.timer-title { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.timer-clock { font-weight: 700; font-size: 22px; font-variant-numeric: tabular-nums; color: var(--brand); background: var(--brand-soft); padding: 4px 12px; border-radius: 10px; }
.timer.low .timer-clock { color: var(--bad); background: var(--bad-soft); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .55; } }

/* ---------- Student pages ---------- */
.auth-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; background: linear-gradient(160deg, #e8f0ff 0%, #f2f6fb 55%, #eaf7f0 100%); }
.auth-card { width: 100%; max-width: 420px; background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 32px 26px; text-align: center; box-shadow: var(--shadow-lg); }
.auth-card .muted { margin: 4px 0 16px; }
.auth-card label { text-align: left; }
.brand-mark { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; display: flex; align-items: center; justify-content: center; font-size: 34px; font-weight: 700; color: #fff; background: linear-gradient(135deg, var(--brand), #16895a); box-shadow: 0 8px 20px rgba(107, 99, 224, .3); }
.big-input { font-size: 22px !important; text-align: center; letter-spacing: 2px; padding: 14px !important; margin-bottom: 14px; }
.back-link { display: inline-block; margin-top: 16px; font-size: 14px; color: var(--muted); }
.wait-icon { font-size: 52px; margin-bottom: 6px; }
.countdown { font-size: 46px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--brand); margin: 14px 0 6px; letter-spacing: 1px; }

.topbar { background: linear-gradient(135deg, #1747a8, var(--brand)); color: #fff; }
.topbar-in { max-width: 780px; margin: 0 auto; padding: 16px; display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.topbar-name { font-size: 19px; font-weight: 700; }
.topbar-sub { font-size: 13px; opacity: .85; }
.topbar button.secondary { background: rgba(255, 255, 255, .16); color: #fff; border-color: rgba(255, 255, 255, .4); }
.topbar button.secondary:hover { background: rgba(255, 255, 255, .28); }

.section-title { font-size: 17px; color: var(--ink); margin: 18px 0 10px; }
.empty-card { background: #fff; border: 1.5px dashed #c8d4e3; border-radius: var(--radius); padding: 26px 16px; text-align: center; color: var(--muted); }
.empty-icon { font-size: 34px; margin-bottom: 4px; }

.exam-card, .score-card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 12px; box-shadow: var(--shadow); }
.exam-card.is-open { border-color: var(--good); box-shadow: 0 0 0 3px rgba(22, 137, 90, .12), var(--shadow); }
.exam-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.exam-title { font-weight: 700; font-size: 17px; line-height: 1.5; }
.exam-meta { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 6px 0 12px; font-size: 14px; color: var(--muted); }
.pin-row { display: flex; gap: 8px; }
.pin-input { flex: 1; min-width: 0; text-align: center; font-size: 20px !important; font-weight: 700; letter-spacing: 4px; text-transform: uppercase; }
.pin-hint { margin-top: 8px; font-size: 13px; }

.chip { display: inline-block; padding: 3px 11px; border-radius: 99px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.chip-open { background: var(--good-soft); color: var(--good); }
.chip-soon { background: var(--warn-soft); color: var(--warn); }
.chip-closed { background: #eceff3; color: var(--muted); }

.score-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 10px 0 8px; }
.score-big { font-size: 38px; font-weight: 700; color: var(--ink); line-height: 1.1; }
.score-max { font-size: 20px; font-weight: 500; color: var(--muted); }
.grade-pill { text-align: center; padding: 6px 16px; border-radius: 12px; min-width: 84px; }
.grade-letter { font-size: 26px; font-weight: 800; line-height: 1.1; }
.grade-label { font-size: 12.5px; font-weight: 600; }
.bar { height: 8px; background: #e6ecf4; border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 99px; }
.score-detail { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 8px; font-size: 13.5px; color: var(--muted); }
.score-detail span:first-child { font-weight: 700; color: var(--ink); }

.modal-back { position: fixed; inset: 0; background: rgba(15, 23, 42, .6); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; z-index: 9999; padding: 16px; }
.modal-box { max-width: 440px; width: 100%; background: #fff; border-radius: 18px; padding: 26px 22px; text-align: center; box-shadow: var(--shadow-lg); }
.callout { padding: 9px 13px; border-radius: 10px; font-weight: 600; font-size: 14px; margin-bottom: 10px; }
.callout.warn { background: var(--warn-soft); color: #8a5a0d; }
.callout.bad { background: var(--bad-soft); color: #a52a2a; }
.callout.good { background: var(--good-soft); color: #0f6e47; }

/* ---------- Landing + teacher dashboard ---------- */
.landing { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px 16px; background: linear-gradient(160deg, #e8f0ff 0%, #f2f6fb 55%, #eaf7f0 100%); text-align: center; }
.landing h1 { font-size: 30px; margin: 6px 0 4px; }
.landing-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 16px; width: 100%; max-width: 560px; margin-top: 26px; }
.landing-card { display: block; background: #fff; border: 1px solid var(--line); border-radius: 20px; padding: 28px 18px; color: var(--ink); box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s, border-color .15s; }
.landing-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); border-color: var(--brand); }
.landing-icon { font-size: 40px; }
.landing-card strong { display: block; font-size: 20px; margin-top: 6px; }
.landing-card span { font-size: 14px; color: var(--muted); }

.pin-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 8px; background: #17212e; color: #fff; font-family: ui-monospace, Menlo, monospace; font-weight: 700; letter-spacing: 2px; font-size: 14px; }
.pin-chip button { padding: 0 4px; background: transparent; border: none; color: #9fb4d0; font-size: 13px; }

.center-screen { min-height: 70vh; display: flex; align-items: center; justify-content: center; text-align: center; padding: 24px; }
.big-score { font-size: 40px; font-weight: 700; color: var(--brand); }

.pin-sheet { font-family: 'Kantumruy Pro', system-ui; }
.pin-sheet table { font-size: 15px; }
@media print {
  .no-print, .tabs, #change-pwd-btn, #logout-btn { display: none !important; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; }
  table { font-size: 12px; }
  input { border: none !important; width: auto !important; padding: 0 !important; }
}


/* Excel & Roster Management */
.dropzone {
  border: 2px dashed var(--line);
  border-radius: 10px;
  padding: 24px 16px;
  text-align: center;
  background: #fafbfc;
  cursor: pointer;
  transition: all .2s ease;
  margin: 10px 0;
}
.dropzone:hover, .dropzone.dragover {
  border-color: var(--brand);
  background: #eef6ff;
}
.dropzone-icon {
  font-size: 32px;
  margin-bottom: 6px;
  display: block;
}
.preview-box {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-top: 12px;
  max-height: 320px;
  overflow-y: auto;
}
.badge-gender {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
}
.badge-gender.m { background: #e0f2fe; color: #0284c7; }
.badge-gender.f { background: #fce7f3; color: #db2777; }
.btn-sm {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 6px;
}

/* ---------- Yearly gradebook ---------- */
.grade-dot { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: 10px; color: #fff; font-weight: 800; }
.gbar { display: flex; height: 16px; background: #eef2f8; border-radius: 99px; overflow: hidden; }
.gbar-g { background: #ec6aa8; } .gbar-b { background: #4aa3e0; } .gbar-o { background: #a9b6c6; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin: 12px 0 16px; }
.stat-tile { background: var(--brand-soft); border-radius: 12px; padding: 10px 14px; }
.stat-val { font-size: 21px; font-weight: 700; }
.print-only { display: none; }
@media print { .print-only { display: block; } }

/* Student: yearly progress */
.year-card { background: linear-gradient(160deg, #fff 0%, #f3f8ff 100%); border: 1px solid #c9dafb; border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.year-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.year-steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(118px, 1fr)); gap: 10px; }
.year-step { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; text-align: center; }
.year-step.is-empty { background: #f7f9fc; border-style: dashed; color: var(--muted); }
.year-month { font-size: 12.5px; color: var(--muted); }
.year-title { font-size: 12.5px; font-weight: 600; min-height: 20px; }
.year-score { font-size: 26px; font-weight: 700; line-height: 1.3; }
.year-sum { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-top: 12px; }
.year-sum-tile { border-radius: 14px; padding: 12px 14px; color: #fff; background: linear-gradient(135deg, #1747a8, var(--brand)); }
.year-sum-tile.alt { background: linear-gradient(135deg, #0f6e47, #16895a); }
.year-sum-tile .lbl { font-size: 13px; opacity: .9; }
.year-sum-tile .val { font-size: 30px; font-weight: 700; line-height: 1.2; }
.year-sum-tile .gr { font-size: 14px; font-weight: 700; }
.year-sum-tile.is-empty { background: #e7edf5; color: var(--muted); }
.setup-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setup-row:last-of-type { border-bottom: none; }
.setup-field label { margin: 0 0 3px; font-size: 12.5px; }
.setup-kind { align-self: center; }
.setup-check { display: flex; align-items: center; gap: 6px; margin: 0 0 10px; color: var(--ink); font-size: 14px; white-space: nowrap; }
.setup-check input { width: 18px; height: 18px; accent-color: var(--brand); }

/* Writing (part B) questions + teacher preview banner */
.q-stem { white-space: pre-line; }
.question-nav button.writing { width: 46px; background: #fff8e6; border-color: #e9c46a; color: #8a5a0d; }
.question-nav button.writing.current { outline-color: rgba(183, 121, 31, .55); }
.writing-card { border-left: 5px solid #e9c46a; }
.preview-banner { background: #17212e; color: #fff; text-align: center; padding: 8px 14px; font-size: 14px; font-weight: 600; }
.preview-banner a { color: #9fc4ff; margin-left: 8px; }

/* ---------- Notes + read-only ---------- */
.notes { margin-top: 8px; }
.note { background: #fff8e6; border-left: 4px solid #e9c46a; border-radius: 0 10px 10px 0; padding: 8px 12px; margin-top: 6px; font-size: 14px; }
.note.done { background: #f1f6f2; border-left-color: var(--good); opacity: .8; }
.note-del { background: transparent; color: var(--bad); border: none; padding: 4px 8px; font-size: 13px; }
.note-del:hover { background: var(--bad-soft); }
.readonly table button, .readonly table .btn { display: none; }

/* ---------- Tests screen ---------- */
.tests-head { padding-bottom: 12px; }
.tests-head-top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.tests-search { min-width: 220px; max-width: 280px; padding: 9px 12px !important; }
.new-test-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; padding: 12px; background: var(--brand-soft); border-radius: 12px; }
.filter-bar { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.filter-pill { background: #fff; color: var(--muted); border: 1.5px solid var(--line); padding: 6px 14px; font-size: 14px; border-radius: 99px; }
.filter-pill:hover { background: var(--brand-soft); color: var(--brand); }
.filter-pill.on { background: var(--brand); color: #fff; border-color: var(--brand); }
.pill-n { margin-left: 7px; background: rgba(0, 0, 0, .09); padding: 0 7px; border-radius: 99px; font-size: 12px; }
.filter-pill.on .pill-n { background: rgba(255, 255, 255, .25); }

.test-list { display: flex; flex-direction: column; gap: 12px; }
.test-card { position: relative; display: flex; align-items: center; gap: 16px; background: #fff; border: 1px solid var(--line); border-left: 5px solid var(--good); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow); transition: box-shadow .15s, transform .15s; }
.test-card.has-open-menu, .test-card:has(.menu-pop) { z-index: 50 !important; }
.test-card:hover { box-shadow: 0 8px 26px rgba(22, 33, 46, .12); transform: translateY(-1px); }
.test-card.is-draft { border-left-color: #c3ccd8; background: #fcfdfe; }
.test-icon { flex: none; width: 48px; height: 48px; border-radius: 14px; background: var(--brand-soft); display: flex; align-items: center; justify-content: center; font-size: 24px; }
.test-main { flex: 1; min-width: 0; }
.test-title { font-weight: 700; font-size: 17px; line-height: 1.5; }
.test-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip-plain { background: #eef2f8; color: #3d4b5c; font-weight: 500; }
.test-actions { flex: none; display: flex; align-items: center; gap: 8px; }
.btn-primary-sm { padding: 8px 16px; font-size: 14.5px; }
.btn-go { padding: 8px 14px; font-size: 14.5px; background: var(--good-soft); color: var(--good); border-color: #b8e2cb; }
.btn-go:hover { background: var(--good); color: #fff; }
.icon-btn { width: 38px; height: 38px; padding: 0; border-radius: 10px; font-size: 17px; background: #fff; color: var(--ink); border: 1.5px solid var(--line); display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { background: var(--brand-soft); border-color: #bcd0f3; color: var(--brand); }
.menu-wrap { position: relative; }
.menu-wrap.is-open, .menu-wrap:has(.menu-pop) { z-index: 60 !important; }
.menu-pop { position: absolute; right: 0; top: 44px; z-index: 100 !important; min-width: 220px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 16px 38px rgba(15, 27, 61, .22), 0 4px 12px rgba(15, 27, 61, .08); padding: 6px; }
.menu-item { display: block; width: 100%; text-align: left; background: transparent; color: var(--ink); border: none; padding: 9px 12px; border-radius: 8px; font-weight: 500; font-size: 14.5px; }
.menu-item:hover { background: var(--brand-soft); color: var(--brand); }
.menu-item.danger { color: var(--bad); }
.menu-item.danger:hover { background: var(--bad-soft); color: var(--bad); }
.menu-sep { height: 1px; background: var(--line); margin: 4px 6px; }

@media (max-width: 720px) {
  .test-card { flex-wrap: wrap; }
  .test-actions { width: 100%; justify-content: flex-start; }
  .test-icon { display: none; }
}
.tests-head-top .row { flex-wrap: nowrap; }
.tests-search { flex: 1; min-width: 150px; }

/* ---------- Licence / locked UI ---------- */
.license-bar { display: flex; gap: 14px; align-items: center; justify-content: space-between; flex-wrap: wrap; border-radius: 14px; padding: 12px 16px; margin-bottom: 14px; }
.license-bar.trial { background: #fff4dc; border: 1px solid #f1d28a; }
.license-bar.expired { background: #fdeaea; border: 1px solid #f0b8b8; }
.license-text { flex: 1; min-width: 240px; }
.license-contact { font-size: 13.5px; margin-top: 4px; color: var(--muted); }
.code-row { display: flex; gap: 8px; flex: none; }
.code-input { width: 190px; text-align: center; font-family: ui-monospace, Menlo, monospace; font-weight: 700; letter-spacing: 2px; text-transform: uppercase; }
.lock-card { background: #fff; border: 1.5px dashed #c8d4e3; border-radius: 18px; padding: 36px 20px; text-align: center; max-width: 560px; margin: 24px auto; }
.lock-card .code-row { justify-content: center; margin-top: 8px; }
.lock-icon { font-size: 46px; }

/* ---------- Student: save status + flags ---------- */
.save-status { font-size: 12px; font-weight: 600; padding: 1px 9px; border-radius: 99px; background: var(--good-soft); color: var(--good); white-space: nowrap; }
.save-status.busy { background: var(--warn-soft); color: var(--warn); }
.save-status.bad { background: var(--bad-soft); color: var(--bad); animation: pulse 1.2s infinite; }
/* a question the student marked (🏳 ចំណាំ): the number shows an amber ring and a flag on its corner */
.question-nav button.flagged { border-color: #f08c00; box-shadow: 0 0 0 2px rgba(240, 140, 0, .35); }
.question-nav button.flagged::after { content: '🚩'; position: absolute; top: -9px; right: -8px; margin: 0; font-size: 15px; line-height: 1; filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .35)); pointer-events: none; }
.flag-btn { background: transparent; color: var(--muted); border: 1.5px solid var(--line); padding: 4px 12px; font-size: 13px; }
.flag-btn.on { background: #fff4dc; color: #8a5a0d; border-color: #e9c46a; }
.question-nav button { position: relative; }
.dob-toggle { display: flex; gap: 8px; align-items: center; margin: 6px 0 12px; padding: 8px 12px; background: var(--brand-soft); border-radius: 10px; color: var(--ink); font-size: 14px; }

/* ---------- Question bank ---------- */
.bank-bar {
  position: sticky;
  top: 76px;
  z-index: 8;
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
  background: #fff;
  border: 1px solid var(--brand);
  border-radius: 10px;
  padding: 6px 8px;
  margin: 8px 0;
  font-size: 12.5px;
  box-shadow: var(--shadow);
}
.bank-bar-count { font-weight: 600; white-space: nowrap; }
.bank-bar button, .bank-bar select {
  font-size: 12.5px;
  padding: 4px 8px;
  min-height: 30px;
  border-radius: 8px;
  line-height: 1.2;
}
.bank-bar select { width: auto; max-width: 170px; }
.bank-bar .bank-bar-go { background: #16a34a; color: #fff; border: none; font-weight: 600; }
.bank-item { display: flex; gap: 12px; align-items: flex-start; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.bank-item:hover { border-color: #bcd0f3; background: #fafcff; }
.bank-stem { font-size: 15px; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.topic-row { display: flex; align-items: center; gap: 12px; padding: 10px 6px; border-bottom: 1px solid var(--line); cursor: pointer; }
.topic-row:hover { background: #f7faff; }

/* question bank: lesson sidebar */
.bank-layout { display: grid; grid-template-columns: 270px minmax(0, 1fr); gap: 14px; align-items: start; }
.bank-side {
  position: sticky;
  top: 76px;
  z-index: 5;
  align-self: start;
  max-height: calc(100dvh - 92px);
  overflow: auto;
  overscroll-behavior: contain;
}
@media (max-width: 1100px) {
  .bank-layout { grid-template-columns: 1fr; }
  .bank-side { position: static; max-height: none; overflow: visible; }
}
.lesson-title { font-weight: 700; padding: 4px 8px 8px; }
.lesson-btn { display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 8px; width: 100%; text-align: left; background: transparent; color: var(--ink); border: 0; border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.lesson-btn:hover { background: var(--brand-soft); }
.lesson-btn.on { background: var(--brand); color: #fff; }
.lesson-name { flex: 1; min-width: 0; }
.lesson-n { font-weight: 700; }
.lesson-lv { flex-basis: 100%; font-size: 11.5px; opacity: .7; }

/* question bank: chapter grouping */
.chapter-group { margin-top: 8px; margin-bottom: 4px; }
.chapter-btn { display: flex; align-items: baseline; justify-content: space-between; gap: 6px; width: 100%; text-align: left; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 6px 10px; font-size: 13px; font-weight: 700; color: #1e293b; cursor: pointer; transition: all .15s ease; }
.chapter-btn:hover { background: #f1f5f9; border-color: #cbd5e1; }
.chapter-btn.on { background: #047857; color: #fff; border-color: #047857; }
.chapter-btn.on .chapter-n { background: rgba(255,255,255,0.25); color: #fff; }
.chapter-title { flex: 1; min-width: 0; line-height: 1.4; }
.chapter-n { font-size: 11px; padding: 1px 6px; border-radius: 999px; background: #e2e8f0; color: #475569; font-weight: 700; }
.chapter-lessons .lesson-btn { padding: 4px 8px; font-size: 13px; border-radius: 6px; }

/* question bank: lesson subsections in sidebar */
.lesson-node { display: flex; flex-direction: column; }
.lesson-subsections {
  margin-left: 10px;
  padding-left: 8px;
  border-left: 2px solid #cbd5e1;
  margin-top: 3px;
  margin-bottom: 5px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sub-btn {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 6px;
  width: 100%;
  text-align: left;
  background: #f8fafc;
  color: #334155;
  border: 1px solid #e2e8f0;
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 12.5px;
  cursor: pointer;
  transition: all .15s ease;
}
.sub-btn:hover {
  background: var(--brand-soft, #eff6ff);
  border-color: #bfdbfe;
  color: var(--brand-dark, #1d4ed8);
}
.sub-btn.on {
  background: var(--brand, #2563eb);
  border-color: var(--brand, #2563eb);
  color: #fff;
  font-weight: 600;
}
.sub-btn .sub-name {
  flex: 1;
  min-width: 0;
  line-height: 1.35;
}
.sub-btn .sub-n {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 999px;
  background: #e2e8f0;
  color: #475569;
  flex-shrink: 0;
}
.sub-btn.on .sub-n {
  background: rgba(255, 255, 255, 0.28);
  color: #fff;
}

/* free trial + plans */
.plan-row { display: flex; gap: 12px; flex-wrap: wrap; }
.plan-btn { flex: 1 1 150px; border: 2px solid #d6c27a; background: #fff; color: #2a3b38; border-radius: 14px; padding: 12px 14px; cursor: pointer; text-align: center; font: inherit; }
.plan-btn:hover { border-color: #285b55; }
.plan-btn.best { border-color: #285b55; background: #eef7f4; box-shadow: 0 2px 10px rgba(40, 91, 85, .18); }
.plan-name { font-weight: 700; font-size: 1.05em; }
.plan-price { font-size: 1.6em; font-weight: 800; color: #285b55; }
.plan-was { font-size: .6em; color: #a52a2a; font-weight: 600; margin-right: 4px; }
.plan-note { font-size: .85em; color: #6b5a1c; }
.chip-warn { background: #fdeaea; color: #a52a2a; }
.pw-wrap { position: relative; }
.pw-wrap button { position: absolute; right: 6px; top: 50%; transform: translateY(-50%); background: none; border: 0; cursor: pointer; font-size: 1.1em; color: #285b55; }

/* ---- phone: use the whole screen (notch, home bar, collapsing browser bars) ---- */
html, body { min-height: 100%; }
.auth-screen, .landing { min-height: 100vh; min-height: 100dvh; }
body { padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right); }
.timer { padding-top: calc(env(safe-area-inset-top) + 8px); }
#view-test .wrap { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
.ios-hint { position: fixed; left: 8px; right: 8px; bottom: calc(8px + env(safe-area-inset-bottom)); z-index: 300; background: #1e293b; color: #fff; border-radius: 14px; padding: 12px 14px; font-size: 14px; line-height: 1.5; box-shadow: 0 10px 30px rgba(0,0,0,.35); display: flex; gap: 10px; align-items: flex-start; }
.ios-hint button { background: transparent; border: 0; color: #fff; font-size: 20px; padding: 0 4px; cursor: pointer; }
@media (display-mode: fullscreen), (display-mode: standalone) { .ios-hint { display: none; } }
