/* ===== Secure Exam — student PWA (mobile first) ===== */
:root {
  --navy: #1e2a4a; --navy-2: #2b3a63; --saffron: #f28c28; --saffron-d: #d9731a;
  --bg: #f3f5f9; --card: #fff; --ink: #1a2133; --muted: #66708a; --line: #e2e6ef;
  --ok: #16a34a; --bad: #dc2626; --warn: #d97706; --review: #7c3aed;
  --radius: 14px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 4px 14px rgba(16,24,40,.06);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[x-cloak] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Noto Sans Devanagari", sans-serif; }
body { overscroll-behavior: none; }
button { font: inherit; cursor: pointer; }
input { font: inherit; }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.25; }
.row { display: flex; align-items: center; gap: 6px; }
.row.gap { gap: 10px; }
.grow { flex: 1; min-width: 0; }
.pad { padding: 16px; }
.center { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.center-text { text-align: center; }
.small, .hint { font-size: 13px; color: var(--muted); }
.err { color: var(--bad); font-size: 14px; margin: 8px 0; }

/* ----- buttons ----- */
.btn { border: 0; border-radius: 10px; padding: 11px 16px; font-weight: 600; background: #e9edf5; color: var(--ink);
  min-height: 44px; transition: transform .05s, background .15s; }
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--navy); color: #fff; }
.btn.primary:hover { background: var(--navy-2); }
.btn.danger { background: var(--bad); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.ghost.on { border-color: var(--review); color: var(--review); background: #f3edff; }
.btn.block { display: block; width: 100%; margin-top: 10px; }
.btn.big { padding: 14px; font-size: 17px; }
.icon-btn { width: 40px; height: 40px; border-radius: 10px; border: 0; background: rgba(255,255,255,.12); color: inherit; font-size: 18px; }
.icon-btn.light { background: rgba(255,255,255,.15); color: #fff; }
.icon-btn.spin { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.card.narrow { max-width: 420px; width: 100%; }

/* ----- net strip ----- */
.netbar { display: flex; align-items: center; gap: 8px; font-size: 12.5px; padding: 6px 14px; color: #fff; }
.netbar.on { background: #0f5132; } .netbar.off { background: #8a3b00; }
.netbar .dot, .sync .dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; display: inline-block; }
.pill { margin-left: auto; padding: 1px 8px; border-radius: 99px; font-weight: 600; }
.pill.warn { background: var(--saffron); color: #1a1a1a; }

/* ----- login ----- */
.login { min-height: calc(100vh - 32px); display: flex; flex-direction: column; justify-content: center; padding: 20px; max-width: 420px; margin: 0 auto; }
.brand { text-align: center; margin-bottom: 18px; }
.logo { width: 64px; height: 64px; margin: 0 auto 10px; border-radius: 18px; background: linear-gradient(135deg, var(--navy), var(--navy-2));
  color: var(--saffron); font-size: 32px; font-weight: 800; display: grid; place-items: center; }
.brand p { color: var(--muted); margin: 0; }
.form label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 14px; color: var(--muted); }
.form input { display: block; width: 100%; margin-top: 6px; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fbfcfe; color: var(--ink); font-size: 17px; }
.form input:focus { outline: none; border-color: var(--saffron); box-shadow: 0 0 0 3px rgba(242,140,40,.18); }

/* ----- home ----- */
.appbar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; background: var(--navy); color: #fff; }
.hello { font-weight: 700; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sub { font-size: 13px; opacity: .8; }
.chips { display: flex; gap: 8px; padding: 12px 16px 4px; overflow-x: auto; }
.chip { border: 1px solid var(--line); background: #fff; border-radius: 99px; padding: 6px 16px; font-weight: 600; font-size: 14px; color: var(--muted); }
.chip.active { background: var(--navy); color: #fff; border-color: var(--navy); }
.list { padding: 10px 16px 40px; display: grid; gap: 12px; max-width: 760px; margin: 0 auto; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }
.exam { cursor: pointer; border-left: 4px solid var(--line); }
.exam.live, .exam.resume { border-left-color: var(--ok); }
.exam.upcoming { border-left-color: var(--warn); cursor: default; }
.exam.ended, .exam.finished { opacity: .75; cursor: default; }
.exam h3 { font-size: 17px; margin: 6px 0; }
.exam-top { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.badge { font-size: 11px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 3px 9px; border-radius: 6px; }
.badge.mock { background: #e0f2fe; color: #075985; } .badge.test { background: #fef3c7; color: #92400e; } .badge.exam { background: #fee2e2; color: #991b1b; }
.state { font-weight: 700; color: var(--ok); } .state.up { color: var(--warn); } .state.end { color: var(--muted); }
.state.res { color: var(--saffron-d); } .state.done { color: var(--navy); }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--muted); }
.paper-code { font-weight: 700; letter-spacing: .4px; color: var(--ink, #1e2a4a); background: rgba(30,42,74,.07); border-radius: 5px; padding: 1px 6px; }
.paper-code.sm { font-size: 11px; color: inherit; background: rgba(255,255,255,.18); margin-right: 6px; }
.ex-title { display: flex; align-items: center; }
.ex-title .paper-code.sm { flex: none; }
.ex-title > span:last-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.score-line { margin-top: 8px; font-size: 14px; display: flex; gap: 12px; }
.cta { margin-top: 10px; font-weight: 700; color: var(--saffron-d); text-align: right; }
.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translateX(-50%); background: #111827; color: #fff;
  padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 80; max-width: 90vw; }

/* ----- brief ----- */
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 14px; }
.facts div, .sum div { background: var(--bg); border-radius: 10px; padding: 10px; text-align: center; }
.facts b, .sum b { display: block; font-size: 22px; color: var(--navy); }
.facts span, .sum span { font-size: 12px; color: var(--muted); }
.rules ul { padding-left: 18px; margin: 0 0 12px; } .rules li { margin-bottom: 6px; font-size: 14.5px; }
.instructions { background: #fff8ef; border: 1px solid #fde3c6; border-radius: 10px; padding: 10px 12px; font-size: 14px; }

/* ----- exam ----- */
.exam-screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }
.exambar { display: flex; align-items: center; gap: 10px; padding: 8px 12px; background: var(--navy); color: #fff; min-height: 56px; }
.ex-title { flex: 1; min-width: 0; font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex-right { display: flex; align-items: center; gap: 8px; }
.timer { font: 700 20px/1 ui-monospace, "SF Mono", Menlo, Consolas, monospace; background: rgba(255,255,255,.12); padding: 7px 10px; border-radius: 8px; letter-spacing: .5px; }
.timer.low { background: var(--saffron); color: #1a1a1a; }
.timer.critical { background: var(--bad); color: #fff; animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.big-timer { font-size: 40px; display: inline-block; margin: 10px 0; padding: 10px 18px; color: var(--navy); background: var(--bg); }
.sync { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; padding: 4px 8px; border-radius: 99px; background: rgba(255,255,255,.12); }
.sync.ok { color: #86efac; } .sync.pend { color: #fde68a; } .sync.off { color: #fdba74; }
.viol { font-size: 12px; font-weight: 700; background: var(--bad); color: #fff; padding: 4px 8px; border-radius: 99px; }

.exam-body { flex: 1; display: flex; min-height: 0; position: relative; }
.paper { flex: 1; overflow-y: auto; padding: 16px 14px 24px; background-color: var(--bg); background-repeat: repeat;
  transition: filter .08s; -webkit-overflow-scrolling: touch; }
.q-wrap { max-width: 860px; margin: 0 auto; }
.q-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; font-size: 13px; color: var(--muted); font-weight: 600; }
.q-marks { background: #fff; border: 1px solid var(--line); padding: 2px 8px; border-radius: 6px; }
.q-body { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); font-size: 16.5px; margin-bottom: 14px; }
.options { display: grid; gap: 10px; }
.opt { display: flex; align-items: flex-start; gap: 12px; width: 100%; text-align: left; background: var(--card); border: 2px solid var(--line);
  border-radius: 12px; padding: 12px 14px; min-height: 54px; color: var(--ink); }
.opt:hover { border-color: #c7cfdf; }
.opt.selected { border-color: var(--navy); background: #eef2fb; }
.opt-l { flex: none; width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 14px;
  background: var(--bg); color: var(--navy); }
.opt.selected .opt-l { background: var(--navy); color: #fff; }
.opt-t { flex: 1; min-width: 0; padding-top: 3px; }

.examfoot { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 8px 10px calc(8px + var(--safe-b)); background: #fff; border-top: 1px solid var(--line); }
.examfoot .btn { padding: 10px 6px; font-size: 14px; }

/* palette: bottom sheet on phones, sidebar on desktop */
.palette { position: fixed; left: 0; right: 0; bottom: 0; max-height: 78vh; overflow-y: auto; background: #fff; z-index: 40;
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(16px + var(--safe-b)); transform: translateY(105%); transition: transform .22s ease;
  box-shadow: 0 -10px 30px rgba(0,0,0,.15); }
.palette.open { transform: none; }
.scrim { position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 35; }
.pal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.pal-head .icon-btn { background: var(--bg); color: var(--ink); }
.pal-name { font-weight: 700; } .pal-sub { font-size: 13px; color: var(--muted); }
.legend { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; font-size: 12.5px; color: var(--muted); margin-bottom: 12px; }
.legend span { display: flex; align-items: center; gap: 6px; }
.legend .cell { width: 18px; height: 18px; min-height: 0; border-radius: 5px; padding: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 8px; margin-bottom: 14px; }
.cell { min-height: 42px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; font-weight: 700; font-size: 14px; color: var(--muted); position: relative; }
.cell.skipped { background: #fde8e8; border-color: #f7c1c1; color: #9b1c1c; }
.cell.answered { background: var(--ok); border-color: var(--ok); color: #fff; }
.cell.review { box-shadow: inset 0 0 0 3px var(--review); }
.cell.review::after { content: ''; position: absolute; top: 3px; right: 3px; width: 7px; height: 7px; border-radius: 50%; background: var(--review); }
.cell.current { outline: 3px solid var(--saffron); outline-offset: 1px; }
i.cell { display: inline-block; }
.only-mobile { display: inline-grid; place-items: center; }

@media (min-width: 900px) {
  .palette { position: static; transform: none; width: 320px; max-height: none; border-radius: 0; border-left: 1px solid var(--line); box-shadow: none; }
  .scrim, .only-mobile { display: none !important; }
  .examfoot { grid-template-columns: repeat(4, 160px); justify-content: center; }
  .paper { padding: 24px 28px; }
}

/* ----- shield / modals ----- */
.shield { position: fixed; inset: 0; z-index: 60; background: rgba(15,23,42,.92); display: grid; place-items: center; padding: 20px; color: #fff; }
.shield-box { text-align: center; max-width: 360px; }
.shield-icon { font-size: 48px; }
.shield .small { color: #cbd5e1; }
.modal { position: fixed; inset: 0; z-index: 70; background: rgba(15,23,42,.55); display: grid; place-items: center; padding: 16px; }
.modal-box { background: #fff; border-radius: 16px; padding: 20px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.sum { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0; }

/* ----- done ----- */
.done-icon { width: 72px; height: 72px; margin: 0 auto 10px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; font-size: 34px; color: var(--ok); }
.score { font-size: 40px; font-weight: 800; color: var(--navy); margin: 10px 0; }
.pending-box { background: #fff8ef; border: 1px solid #fde3c6; border-radius: 12px; padding: 12px; margin: 12px 0; text-align: left; }
.pending-box p { margin: 0 0 6px; }

.spinner { width: 40px; height: 40px; border: 4px solid var(--line); border-top-color: var(--navy); border-radius: 50%; animation: spin .8s linear infinite; }

/* ===== Question formatting (shared with admin preview) ===== */
.qf-text { white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.qf-text + .qf-code, .qf-code + .qf-text { margin-top: 10px; }
.qf-inline { font-family: ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace; font-size: .92em; background: #eef1f7; color: #b4235a;
  padding: 1px 6px; border-radius: 5px; white-space: pre-wrap; }
.qf-code { border-radius: 10px; overflow: hidden; background: #0f172a; color: #e2e8f0; margin: 2px 0; }
.qf-code-head { font: 700 10.5px/1 system-ui, sans-serif; letter-spacing: .1em; color: #94a3b8; padding: 7px 12px; background: #111c33; border-bottom: 1px solid #1e293b; }
.qf-code pre { margin: 0; padding: 10px 0; overflow-x: auto; -webkit-overflow-scrolling: touch; tab-size: 4; }
.qf-code code { display: block; font: 13.5px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, "Courier New", monospace; white-space: pre; counter-reset: ln; min-width: max-content; }
.qf-ln { counter-increment: ln; padding-right: 16px; }
.qf-ln::before { content: counter(ln); display: inline-block; width: 2.6em; padding-right: 12px; margin-right: 4px; text-align: right; color: #475569; border-right: 1px solid #1e293b; }
.qf-kw { color: #c792ea; } .qf-st { color: #c3e88d; } .qf-nu { color: #f78c6c; } .qf-cm { color: #7f8ca3; font-style: italic; }
.qf-pp { color: #ffcb6b; } .qf-fn { color: #82aaff; }
.opt .qf-code { margin-top: 2px; }
@media (min-width: 600px) { .qf-code code { font-size: 14.5px; } }

/* ===== Lockdown ===== */
html.exam-locked, html.exam-locked * { -webkit-user-select: none !important; user-select: none !important; -webkit-touch-callout: none !important; }
html.exam-locked img { pointer-events: none; -webkit-user-drag: none; }
html.shield-on .paper, html.shield-flash .paper, html.shield-on .palette, html.shield-flash .palette { filter: blur(26px) saturate(.4); }
html.shield-flash .paper { opacity: .2; }
@media print { body * { display: none !important; } body::after { content: "Printing is disabled during the exam."; display: block; padding: 40px; } }
