/* MCQ Pro – shared styles (no build step needed) */
:root {
  --ink: #142a4f;
  --ink-2: #1e3a68;
  --teal: #1d4b8f;
  --teal-light: #8db3ea;
  --teal-deep: #163a70;
  --teal-soft: #e9f0fa;
  --blue: #2563eb;
  --blue-soft: #e8efff;
  --amber: #f7953b;
  --amber-soft: #fef0e2;
  --red: #dc2626;
  --red-soft: #fdecec;
  --green: #16a34a;
  --green-soft: #e7f7ec;
  --bg: #faf7f2;
  --card: #ffffff;
  --line: #ece6da;
  --text: #1f2a30;
  --muted: #5b6b73;
  --paper: #fffdf8;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(20, 42, 79, .05), 0 8px 24px rgba(20, 42, 79, .06);
  --display: "Outfit", "Segoe UI", system-ui, sans-serif;
  --body: "Inter", "Segoe UI", system-ui, sans-serif;
  --sinhala: "Noto Sans Sinhala", "Noto Sans Tamil", "Iskoola Pota", "Nirmala UI", sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--body), var(--sinhala); font-size: 15px; line-height: 1.55; color: var(--text); background: var(--bg); -webkit-font-smoothing: antialiased; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { font-family: var(--display), var(--sinhala); letter-spacing: -.015em; color: var(--ink); margin: 0; line-height: 1.2; }
p { margin: 0; }
img { max-width: 100%; }
:focus-visible { outline: 3px solid rgba(29, 75, 143, .45); outline-offset: 2px; border-radius: 8px; }

/* ---------- brand ---------- */
.brand { display: inline-flex; align-items: center; gap: 9px; text-decoration: none !important; color: inherit;
  --logo-navy: #1b3461; --logo-orange: #f7953b; --logo-gap: var(--bg); }
.logo-mark { width: 44px; height: 39px; flex: none; overflow: visible; }
.logo-mark .lm-paper { stroke: var(--logo-orange); }
.logo-mark .lm-dot { stroke: var(--logo-orange); }
.logo-mark .lm-dots circle { stroke: var(--logo-orange); }
.logo-mark .lm-dots circle.f { fill: var(--logo-orange); }
.logo-mark .lm-gap { stroke: var(--logo-gap); }
.logo-mark .lm-tick { stroke: var(--logo-navy); }
.brand-name { font-family: var(--display); font-weight: 700; font-size: 23px; line-height: 1; letter-spacing: -.02em; color: var(--logo-navy); white-space: nowrap; }
.brand-name .pro { color: var(--logo-orange); }
/* dark backgrounds (sidebar, login side panel): white tick and text */
.sidebar .brand, .auth-side .brand, .on-dark .brand { --logo-navy: #ffffff; --logo-gap: var(--ink); }
/* old tagline (not used now) */
.brand-name small { display: block; font-size: 10.5px; font-weight: 600; letter-spacing: .18em; text-transform: uppercase; opacity: .6; margin-top: 3px; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 10px 18px; border-radius: 10px; border: 1px solid transparent; font: 600 14px var(--body); cursor: pointer; text-decoration: none !important; transition: background .15s, border-color .15s, transform .05s, box-shadow .15s; white-space: nowrap; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn svg { width: 17px; height: 17px; flex: none; }
.btn-primary { background: var(--ink); color: #fff; }
.btn-primary:hover { background: var(--ink-2); }
.btn-teal { background: var(--teal); color: #fff; }
.btn-teal:hover { background: var(--teal-deep); box-shadow: 0 6px 18px rgba(29, 75, 143, .3); }
.btn-ghost { background: #fff; color: var(--text); border-color: var(--line); }
.btn-ghost:hover { border-color: #c4d2d8; background: #fafcfc; }
.btn-danger { background: #fff; color: var(--red); border-color: #f5c2c2; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn-lg { padding: 14px 24px; font-size: 15.5px; border-radius: 12px; }
.btn-block { width: 100%; }

/* ---------- forms ---------- */
.field { display: grid; gap: 6px; margin-bottom: 16px; }
.field label, .label { font-size: 13px; font-weight: 600; color: #334855; }
.input, select.input, textarea.input { width: 100%; padding: 11px 13px; font: inherit; color: var(--text); background: #fff; border: 1px solid var(--line); border-radius: 10px; transition: border-color .15s, box-shadow .15s; }
.input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 4px rgba(29, 75, 143, .15); }
textarea.input { min-height: 96px; resize: vertical; }
.hint { font-size: 12.5px; color: var(--muted); }
.error { font-size: 12.5px; color: var(--red); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 720px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* segmented choice (e.g. 4 / 5 options) */
.seg { display: inline-flex; background: #eef3f5; border-radius: 10px; padding: 4px; gap: 4px; }
.seg input { display: none; }
.seg label { padding: 7px 16px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg input:checked + label { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .08); }

/* dropzone */
.drop { position: relative; display: grid; place-items: center; text-align: center; gap: 8px; padding: 34px 20px; border: 2px dashed #c9d7dc; border-radius: var(--radius); background: #fafcfc; cursor: pointer; transition: border-color .15s, background .15s; }
.drop:hover, .drop.over { border-color: var(--teal); background: var(--teal-soft); }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop .ic { width: 52px; height: 52px; border-radius: 14px; background: #fff; display: grid; place-items: center; color: var(--teal-deep); box-shadow: var(--shadow); }
.drop .ic svg { width: 26px; height: 26px; }
.drop b { font-size: 15px; }
.drop .file-name { font-weight: 600; color: var(--teal-deep); }

/* ---------- cards / layout ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-body { padding: 22px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--line); }
.card-head h2, .card-head h3 { font-size: 16px; }
.stack { display: grid; gap: 18px; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.tabular { font-variant-numeric: tabular-nums; }

/* app shell */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--ink); color: #c9d6dd; padding: 20px 14px; display: flex; flex-direction: column; gap: 22px; position: sticky; top: 0; height: 100vh; height: 100dvh;
  overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.18) transparent; }
.sidebar > * { flex-shrink: 0; }
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-radius: 6px; }
.sidebar .brand { color: #fff; padding: 4px 8px; }
.nav { display: grid; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border-radius: 10px; color: #b5c5cd; font-weight: 500; text-decoration: none; }
.nav a svg { width: 18px; height: 18px; opacity: .85; }
.nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.nav a.on { background: rgba(111, 211, 196, .14); color: var(--teal-light); }
.nav-label { font-size: 11px; text-transform: uppercase; letter-spacing: .12em; color: #6f8794; padding: 0 12px; margin-top: 4px; }
.credit-box { margin-top: auto; background: linear-gradient(135deg, rgba(29, 75, 143, .16), rgba(37, 99, 235, .16)); border: 1px solid rgba(255, 255, 255, .08); border-radius: 14px; padding: 16px; }
.credit-box small { font-size: 12px; color: #9fb4bf; }
.credit-box b { display: block; font-family: var(--display); font-size: 28px; color: #fff; margin: 2px 0 10px; font-variant-numeric: tabular-nums; }
.main { min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 16px 28px; background: rgba(244, 247, 248, .85); backdrop-filter: blur(8px); position: sticky; top: 0; z-index: 5; border-bottom: 1px solid var(--line); }
.topbar h1 { font-size: 20px; }
.content { padding: 26px 28px 60px; max-width: 1180px; }
.menu-toggle { display: none; background: none; border: 0; padding: 6px; cursor: pointer; color: var(--ink); }
@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 30; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, .35); }
  .menu-toggle { display: block; }
  .content { padding: 20px 16px 60px; }
  .topbar { padding: 12px 16px; }
}

/* avatar menu */
.who { display: flex; align-items: center; gap: 10px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--teal-soft); color: var(--teal-deep); display: grid; place-items: center; font-weight: 700; font-size: 14px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.stat { padding: 18px 20px; }
.stat small { color: var(--muted); font-size: 13px; }
.stat b { display: block; font-family: var(--display); font-size: 28px; color: var(--ink); margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat .ic { width: 38px; height: 38px; border-radius: 11px; display: grid; place-items: center; float: right; }
.stat .ic svg { width: 19px; height: 19px; }
@media (max-width: 1000px) { .stats { grid-template-columns: 1fr 1fr; } }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 11px 16px; border-bottom: 1px solid var(--line); background: #fafcfc; white-space: nowrap; }
.table td { padding: 13px 16px; border-bottom: 1px solid #edf2f4; vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: #fbfdfd; }

/* ---------- badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.ready { background: var(--green-soft); color: var(--green); }
.badge.generating { background: var(--blue-soft); color: var(--blue); }
.badge.pending { background: #eef2f4; color: #546b78; }
.badge.failed { background: var(--red-soft); color: var(--red); }
.badge.admin { background: var(--amber-soft); color: #b45309; }

/* ---------- alerts ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: 12px; font-size: 14px; margin-bottom: 18px; }
.alert.ok { background: var(--green-soft); color: #166534; }
.alert.err { background: var(--red-soft); color: #991b1b; }
.alert.info { background: var(--blue-soft); color: #1e40af; }

/* ---------- empty state ---------- */
.empty { text-align: center; padding: 48px 20px; }
.empty .ic { width: 64px; height: 64px; margin: 0 auto 14px; border-radius: 18px; background: var(--teal-soft); color: var(--teal-deep); display: grid; place-items: center; }
.empty .ic svg { width: 30px; height: 30px; }
.empty h3 { font-size: 18px; margin-bottom: 6px; }

/* ---------- questions ---------- */
.q { padding: 20px 22px; border-bottom: 1px solid #edf2f4; }
.q:last-child { border-bottom: 0; }
.q-head { display: flex; gap: 12px; align-items: flex-start; }
.q-num { flex: none; width: 30px; height: 30px; border-radius: 9px; background: var(--ink); color: #fff; display: grid; place-items: center; font: 700 13px var(--display); }
.q-text { font-weight: 600; flex: 1; font-size: 15px; white-space: pre-wrap; }
.opts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 14px 0 0 42px; }
.opt { display: flex; gap: 10px; align-items: flex-start; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 14px; }
.opt .l { flex: none; width: 22px; height: 22px; border-radius: 6px; background: #eef3f5; display: grid; place-items: center; font-size: 12px; font-weight: 700; color: var(--muted); }
.opt.correct { border-color: #9be3c0; background: var(--green-soft); }
.opt.correct .l { background: var(--green); color: #fff; }
.explain { margin: 10px 0 0 42px; font-size: 13.5px; color: var(--muted); }
@media (max-width: 720px) { .opts { grid-template-columns: 1fr; margin-left: 0; } .explain { margin-left: 0; } }

/* progress */
.progress { height: 10px; background: #e5edf0; border-radius: 999px; overflow: hidden; }
.progress > div { height: 100%; width: 0; background: linear-gradient(90deg, var(--teal), var(--teal-light)); border-radius: 999px; transition: width .4s; }

/* ---------- auth pages ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1fr 1fr; }
.auth-side { background: radial-gradient(700px 400px at 20% 10%, rgba(29, 75, 143, .3), transparent 60%), radial-gradient(600px 400px at 90% 90%, rgba(37, 99, 235, .3), transparent 60%), var(--ink); color: #d4e0e6; padding: 48px; display: flex; flex-direction: column; justify-content: space-between; }
.auth-side .brand { color: #fff; }
.auth-side h2 { color: #fff; font-size: 34px; margin-bottom: 14px; }
.auth-side ul { list-style: none; padding: 0; margin: 24px 0 0; display: grid; gap: 12px; }
.auth-side li { display: flex; gap: 10px; align-items: center; }
.auth-side li svg { width: 20px; height: 20px; color: var(--teal-light); flex: none; }
.auth-form { display: grid; place-items: center; padding: 40px 20px; }
.auth-form .box { width: 100%; max-width: 400px; }
.auth-form h1 { font-size: 28px; margin-bottom: 6px; }
@media (max-width: 860px) { .auth { grid-template-columns: 1fr; } .auth-side { display: none; } }

/* ---------- print (question paper / answer key) ---------- */
.sheet { background: var(--paper); max-width: 820px; margin: 0 auto; padding: 48px 56px; box-shadow: var(--shadow); border-radius: 6px; font-family: "Noto Serif", Georgia, var(--sinhala), serif; }
.sheet h1 { font-family: inherit; text-align: center; font-size: 22px; }
.sheet .meta { display: flex; justify-content: space-between; border-top: 2px solid #222; border-bottom: 1px solid #222; padding: 8px 0; margin: 14px 0 22px; font-size: 14px; }
.sheet .pq { break-inside: avoid; margin-bottom: 16px; }
.sheet .pq-text { font-weight: 600; }
.sheet .pq-opts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 24px; margin: 6px 0 0 26px; }
.key-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.key-grid div { border: 1px solid #ccc; padding: 6px 10px; border-radius: 4px; font-variant-numeric: tabular-nums; }
.print-bar { max-width: 820px; margin: 0 auto 16px; display: flex; gap: 10px; flex-wrap: wrap; }
@media print {
  body { background: #fff; }
  .print-bar, .no-print { display: none !important; }
  .sheet { box-shadow: none; padding: 0; max-width: none; background: #fff; }
  .page-break { break-before: page; }
}

/* Language button (English / සිංහල / தமிழ்) */
.lang-switch { display: inline-flex; background: #eef3f5; border-radius: 10px; padding: 3px; gap: 2px; }
.lang-switch a { padding: 5px 10px; border-radius: 8px; font-size: 12.5px; font-weight: 600; color: var(--muted); text-decoration: none; white-space: nowrap; }
.lang-switch a:hover { color: var(--ink); }
.lang-switch a.on { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(11, 31, 46, .12); }
.lang-switch.dark { background: rgba(255, 255, 255, .08); }
.lang-switch.dark a { color: #b9c9d1; }
.lang-switch.dark a.on { background: rgba(255, 255, 255, .16); color: #fff; box-shadow: none; }
@media (max-width: 640px) { .lang-switch a { padding: 4px 7px; font-size: 12px; } }

/* Ceylon theme extras */
.btn-amber { background: var(--amber); color: var(--ink); font-weight: 700; }
.btn-amber:hover { background: #e48f06; }
.badge.popular { background: var(--amber); color: var(--ink); }
.badge.popular::before { display: none; }
.badge.save { background: var(--teal-soft); color: var(--teal-deep); }
.badge.save::before { display: none; }
/* Credit packs */
.packs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 18px; align-items: stretch; padding-top: 12px; }
.pack { position: relative; display: flex; flex-direction: column; gap: 4px; background: var(--bg); border: 1px solid var(--line); border-radius: 20px; padding: 26px 24px 24px; }
.pack.pop { background: #fff; border: 2px solid var(--teal); box-shadow: 0 24px 48px -28px rgba(29, 75, 143, .55); }
.pack-flag { position: absolute; top: -13px; left: 22px; }
.pack-name { font-weight: 600; color: var(--muted); }
.pack-price { font: 700 32px var(--display); color: var(--ink); line-height: 1.2; }
.pack-credits { color: var(--teal-deep); font-weight: 600; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.pack-uses { margin: 12px 0 16px; padding-left: 18px; color: #4a5a62; font-size: 14.5px; flex: 1 1 auto; }
.pack-uses li { margin-bottom: 3px; }
.pack-cta { margin-top: auto; }

/* ---------- Support assistant (corner chat) ---------- */
.asst { position: fixed; right: 20px; bottom: 20px; z-index: 900; font-family: var(--body); }
.asst-fab { position: relative; width: 60px; height: 60px; border-radius: 50%; border: 0; cursor: pointer; color: #fff;
  background: linear-gradient(135deg, var(--teal) 0%, var(--ink) 100%); box-shadow: 0 10px 28px rgba(20,42,79,.32);
  display: grid; place-items: center; transition: transform .2s ease; animation: asst-float 3.2s ease-in-out infinite; }
.asst-fab:hover { transform: scale(1.06); }
.asst-fab svg { width: 27px; height: 27px; transition: transform .25s ease, opacity .2s; }
.asst-fab .i-close { position: absolute; opacity: 0; transform: rotate(-90deg); }
.asst.open .asst-fab { animation: none; }
.asst.open .asst-fab .i-open { opacity: 0; transform: rotate(90deg); }
.asst.open .asst-fab .i-close { opacity: 1; transform: none; }
.asst-ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid var(--teal-light); animation: asst-ping 2.4s ease-out infinite; pointer-events: none; }
.asst.open .asst-ring { display: none; }
/* The assistant's "face": a white chat bubble with two eyes that look around, like someone talking to you */
.asst-face { position: relative; width: 31px; height: 21px; border-radius: 8px; background: #fff; display: flex; align-items: center; justify-content: center; gap: 6px;
  box-shadow: 0 2px 6px rgba(20,42,79,.18); transition: transform .25s ease, opacity .2s; }
.asst-face i { width: 5px; height: 5px; border-radius: 50%; background: var(--ink); animation: asst-look 4s ease-in-out infinite, asst-wink 4s steps(1) infinite; }
@keyframes asst-look { 0%, 12% { transform: translateX(0); } 22%, 40% { transform: translateX(-3px); } 50%, 68% { transform: translateX(3px); } 78%, 100% { transform: translateX(0); } }
@keyframes asst-wink { 0%, 86%, 92%, 100% { height: 5px; } 88% { height: 1.5px; } }
.asst-badge { position: absolute; top: 1px; right: 1px; width: 14px; height: 14px; border-radius: 50%; background: var(--amber); border: 2.5px solid #fff; animation: asst-badge 1.8s ease-in-out infinite; }
.asst.open .asst-badge { display: none; }
@keyframes asst-badge { 50% { transform: scale(1.18); } }
@keyframes asst-ping { 0% { transform: scale(1); opacity: .85; } 80%, 100% { transform: scale(1.55); opacity: 0; } }
@keyframes asst-float { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }

.asst-bubble { position: absolute; right: 4px; bottom: 74px; width: max-content; max-width: 230px; padding: 11px 32px 11px 14px;
  background: var(--card); color: var(--text); border: 1px solid var(--line); border-radius: 14px 14px 4px 14px; box-shadow: var(--shadow);
  font-size: 14px; line-height: 1.4; cursor: pointer; opacity: 0; transform: translateY(8px) scale(.96); pointer-events: none;
  transition: opacity .35s ease, transform .35s cubic-bezier(.2,1.4,.4,1); }
.asst-bubble.show { opacity: 1; transform: none; pointer-events: auto; }
.asst-bubble strong { color: var(--teal); }
.asst-bubble-x { position: absolute; top: 4px; right: 6px; border: 0; background: none; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 4px; }

.asst-panel { position: absolute; right: 0; bottom: 74px; width: min(380px, calc(100vw - 32px)); height: min(560px, calc(100vh - 120px));
  display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 24px 60px rgba(20,42,79,.25); overflow: hidden; animation: asst-in .25s ease; }
.asst-panel[hidden] { display: none; }
@keyframes asst-in { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: none; } }
.asst-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 14px 16px; color: #fff;
  background: linear-gradient(120deg, var(--ink) 0%, var(--teal) 100%); }
.asst-head strong { display: block; font-family: var(--display); font-size: 16px; }
.asst-head small { display: flex; align-items: center; gap: 6px; font-size: 12px; opacity: .85; }
.asst-dot { width: 7px; height: 7px; border-radius: 50%; background: #4ade80; box-shadow: 0 0 0 3px rgba(74,222,128,.25); }
.asst-avatar { width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center; background: var(--amber); color: var(--ink); font-size: 18px; flex: none; }
.asst-new { margin-left: auto; border: 0; background: rgba(255,255,255,.14); color: #fff; width: 34px; height: 34px; border-radius: 10px; cursor: pointer; display: grid; place-items: center; }
.asst-close-m { display: none !important; margin-left: 0; }
.asst-new:hover { background: rgba(255,255,255,.24); }
.asst-new svg { width: 17px; height: 17px; }

.asst-msgs { flex: 1; overflow-y: auto; padding: 16px 14px; display: flex; flex-direction: column; gap: 10px; background: var(--bg); }
.asst-msg { max-width: 86%; padding: 10px 13px; border-radius: 14px; font-size: 14px; line-height: 1.55; word-wrap: break-word; font-family: var(--body), var(--sinhala); }
.asst-msg.bot { align-self: flex-start; background: var(--card); border: 1px solid var(--line); border-bottom-left-radius: 4px; color: var(--text); }
.asst-msg.me { align-self: flex-end; background: var(--teal); color: #fff; border-bottom-right-radius: 4px; }
.asst-msg.err { border-color: #f5c2c2; background: var(--red-soft); }
.asst-msg.typing { color: var(--muted); font-style: italic; animation: asst-blink 1.2s ease-in-out infinite; }
.asst-msg a { color: var(--teal); text-decoration: underline; word-break: break-all; }
@keyframes asst-blink { 50% { opacity: .45; } }
.asst-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.asst-chip { border: 1px solid #c9d9f2; background: var(--teal-soft); color: var(--teal-deep); border-radius: 999px; padding: 6px 11px; font-size: 13px; cursor: pointer; font-family: inherit; }
.asst-chip:hover { background: #dbe6f7; }

.asst-form { display: flex; align-items: flex-end; gap: 8px; padding: 10px 10px 6px; border-top: 1px solid var(--line); background: var(--card); }
.asst-form textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; font: inherit; font-size: 14px; max-height: 120px; background: var(--paper); color: var(--text); }
.asst-form textarea:focus { outline: 2px solid var(--teal-light); border-color: var(--teal); }
.asst-send { flex: none; width: 42px; height: 42px; border: 0; border-radius: 12px; background: var(--amber); color: var(--ink); cursor: pointer; display: grid; place-items: center; }
.asst-send svg { width: 19px; height: 19px; }
.asst-form.busy .asst-send { opacity: .5; cursor: wait; }
.asst-foot { margin: 0; padding: 0 12px 10px; font-size: 11px; color: var(--muted); background: var(--card); text-align: center; }

@media (max-width: 520px) {
  .asst { right: 14px; bottom: 14px; }
  .asst-fab { width: 54px; height: 54px; }
  .asst-panel { position: fixed; right: 8px; left: 8px; bottom: 80px; width: auto; height: calc(100vh - 100px); }
}
@media (prefers-reduced-motion: reduce) { .asst-fab, .asst-ring, .asst-msg.typing, .asst-face i, .asst-badge { animation: none; } }
@media print { .asst { display: none !important; } }

/* ---------- "Writing a paper" loading screen ---------- */
.pl { display: none; }
.pl.on { display: grid; place-items: center; position: fixed; inset: 0; z-index: 2000; cursor: pointer;
  background: radial-gradient(ellipse at 30% 20%, #24487f 0%, var(--ink) 60%); transition: opacity .45s ease, visibility .45s; }
.pl.out { opacity: 0; visibility: hidden; }
.pl-card { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.pl-paper { position: relative; width: 230px; padding: 18px 18px 14px; background: var(--paper); border-radius: 10px;
  box-shadow: 0 30px 60px rgba(0,0,0,.35); transform: rotate(-2deg); animation: pl-rise .6s cubic-bezier(.2,1.2,.4,1); }
.pl-top { display: flex; justify-content: space-between; margin-bottom: 14px; padding-bottom: 10px; border-bottom: 2px solid var(--teal-soft); }
.pl-top span { height: 7px; border-radius: 4px; background: var(--teal); width: 46%; }
.pl-top span + span { width: 22%; background: var(--line); }
.pl-q { display: grid; grid-template-columns: 16px 1fr; gap: 4px 6px; align-items: center; margin-bottom: 11px; }
.pl-q b { font: 700 11px var(--display); color: var(--ink); opacity: 0; animation: pl-show .2s var(--d) forwards; }
.pl-line { height: 6px; border-radius: 3px; background: #c9d6d3; width: 0; animation: pl-write .55s var(--d) ease-out forwards; }
.pl-opts { grid-column: 2; display: flex; gap: 8px; }
.pl-opts em { width: 11px; height: 11px; border-radius: 50%; border: 1.6px solid #b9c8c5; opacity: 0; animation: pl-show .2s calc(var(--d) + .5s) forwards; }
.pl-opts em.ok { animation: pl-show .2s calc(var(--d) + .5s) forwards, pl-fill .25s calc(var(--d) + .65s) forwards; }
.pl-pen { position: absolute; width: 42px; height: 42px; left: 32px; top: 19px; filter: drop-shadow(0 6px 6px rgba(0,0,0,.25)); animation: pl-pen 2.8s ease-in-out forwards; }
.pl-brand { font: 700 22px var(--display); color: #fff; letter-spacing: -.01em; }
.pl-brand span { color: var(--amber); }
.pl-text { color: #cfe7e3; font-size: 14px; font-family: var(--body), var(--sinhala); animation: asst-blink 1.4s ease-in-out infinite; }
.pl-bar { width: 180px; height: 4px; border-radius: 4px; background: rgba(255,255,255,.15); overflow: hidden; }
.pl-bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--teal-light), var(--amber)); animation: pl-bar 3.3s ease-in-out forwards; }
@keyframes pl-rise { from { opacity: 0; transform: translateY(20px) rotate(-6deg); } to { opacity: 1; transform: rotate(-2deg); } }
@keyframes pl-write { to { width: 100%; } }
@keyframes pl-show { to { opacity: 1; } }
@keyframes pl-fill { to { background: var(--teal); border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-soft); } }
@keyframes pl-bar { to { width: 100%; } }
@keyframes pl-pen {
  0%   { transform: translate(0, 0); }
  18%  { transform: translate(150px, 0); }
  25%  { transform: translate(0, 34px); }
  43%  { transform: translate(150px, 34px); }
  50%  { transform: translate(0, 68px); }
  68%  { transform: translate(150px, 68px); }
  75%  { transform: translate(0, 102px); }
  93%  { transform: translate(150px, 102px); }
  100% { transform: translate(170px, 120px) rotate(20deg); opacity: 0; }
}
@media print { .pl { display: none !important; } }

/* ================= Phone & tablet layout ================= */
.btn-glass { background: rgba(255, 255, 255, .12); color: #fff; border: 1px solid rgba(255, 255, 255, .35); }
.btn-glass:hover { background: rgba(255, 255, 255, .2); }
.top-credits, .tabbar, .side-backdrop, .side-mobile, .auth-brand { display: none; }
.top-actions { display: contents; }
.qstat-row { display: grid; grid-template-columns: 34px minmax(0, 1fr) 160px; gap: 12px; align-items: center; }
.auth-top { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-bottom: 18px; }
html { -webkit-text-size-adjust: 100%; }
a, button, label, summary { -webkit-tap-highlight-color: rgba(29, 75, 143, .12); }

@media (max-width: 900px) {
  /* menu drawer */
  .sidebar { width: min(300px, 86vw); padding-top: max(20px, env(safe-area-inset-top)); padding-bottom: max(20px, env(safe-area-inset-bottom)); transition: transform .25s cubic-bezier(.3,.8,.3,1); }
  .sidebar.open { box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .side-backdrop { display: block; position: fixed; inset: 0; z-index: 29; background: rgba(20, 42, 79, .45); opacity: 0; pointer-events: none; transition: opacity .25s; }
  body.menu-open { overflow: hidden; }
  body.menu-open .side-backdrop { opacity: 1; pointer-events: auto; }
  .side-mobile { display: grid; gap: 12px; }
  .side-mobile .lang-switch { display: flex; }
  .side-mobile .lang-switch a { flex: 1; text-align: center; }
  .nav a { padding: 12px; }
  .credit-box { margin-top: 6px; }

  /* top bar: menu · title · credits */
  .topbar { gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); flex-wrap: wrap; background: rgba(250, 247, 242, .92); }
  .topbar h1 { font-size: 18px; flex: 1 1 0; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar > .spacer, .topbar > .lang-switch, .topbar > .who { display: none; }
  .menu-toggle { width: 40px; height: 40px; margin-left: -6px; border-radius: 10px; display: grid; place-items: center; }
  .top-credits { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: var(--teal-soft); color: var(--teal-deep);
    font: 700 14px var(--display); font-variant-numeric: tabular-nums; text-decoration: none !important; }
  .top-credits svg { width: 16px; height: 16px; }
  .top-actions { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }
  .top-actions:empty { display: none; }
  .top-actions > * { flex: 1 1 auto; }
  .top-actions form { display: flex; }
  .top-actions form .btn { flex: 1; }

  /* bottom tab bar */
  .tabbar { display: grid; grid-template-columns: repeat(5, 1fr); position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
    background: rgba(255, 255, 255, .97); backdrop-filter: blur(10px); border-top: 1px solid var(--line);
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 -6px 20px rgba(20, 42, 79, .06); }
  .tabbar a { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 4px 2px; color: #6a7c84; font-size: 11px; font-weight: 600;
    text-decoration: none !important; border-radius: 10px; min-height: 48px; justify-content: center; }
  .tabbar a svg { width: 22px; height: 22px; }
  .tabbar a span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .tabbar a.on { color: var(--teal); }
  .tabbar a.on svg { stroke-width: 2.4; }
  .tab-new .tab-plus { width: 46px; height: 46px; margin-top: -24px; border-radius: 16px; display: grid; place-items: center; color: #fff;
    background: linear-gradient(135deg, var(--teal), var(--ink)); box-shadow: 0 8px 18px rgba(29, 75, 143, .4); border: 3px solid #fff; }
  .tab-new .tab-plus svg { width: 22px; height: 22px; }
  .has-tabbar .content { padding-bottom: calc(96px + env(safe-area-inset-bottom, 0px)); }
  .has-tabbar .asst { bottom: calc(82px + env(safe-area-inset-bottom, 0px)); }

  .qstat-row { grid-template-columns: 30px minmax(0, 1fr) 110px; gap: 8px; }
}

@media (max-width: 640px) {
  body { font-size: 15px; }
  .content { padding: 16px 12px; }
  .stack { gap: 14px; }
  .card { border-radius: 14px; }
  .card-body { padding: 16px; }
  .card-head { padding: 14px 16px; flex-wrap: wrap; }
  /* 16px inputs stop iPhones zooming in; bigger tap targets */
  .input, select.input, textarea.input, .asst-form textarea { font-size: 16px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 36px; }
  .row > .btn { flex: 1 1 auto; }
  .seg { display: flex; }
  .seg label { flex: 1; text-align: center; padding: 9px 10px; }
  .drop { padding: 26px 14px; }
  .stats { gap: 10px; }
  .stat { padding: 14px; }
  .stat b { font-size: 22px; }
  .stat .ic { width: 32px; height: 32px; border-radius: 9px; }
  .stat .ic svg { width: 16px; height: 16px; }
  .alert { font-size: 14px; }
  .q { padding: 16px; }
  .q-head { gap: 10px; }
  .empty { padding: 36px 16px; }
  .packs { grid-template-columns: 1fr; gap: 22px; }
  .pack { padding: 24px 20px 20px; }
  .key-grid { grid-template-columns: repeat(3, 1fr); }
  .sheet { padding: 24px 18px; }
  .sheet .pq-opts { grid-template-columns: 1fr; margin-left: 12px; }

  /* lists become cards: each table row is a small card (tables with inputs stay scrollable) */
  .table-wrap:has(> table.table:not(:has(input, select, textarea))) { overflow: visible; }
  table.table:not(:has(input, select, textarea)) { display: block; }
  table.table:not(:has(input, select, textarea)) tbody { display: block; }
  table.table:not(:has(input, select, textarea)) tr:has(> th) { display: none; }
  table.table:not(:has(input, select, textarea)) tr { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 12px; padding: 12px 16px; border-bottom: 1px solid #edf2f4; }
  table.table:not(:has(input, select, textarea)) tr:last-child { border-bottom: 0; }
  table.table:not(:has(input, select, textarea)) td { display: block; padding: 0; border: 0; font-size: 14px; }
  table.table:not(:has(input, select, textarea)) td:first-child { flex: 1 1 100%; font-size: 15px; }
  table.table:not(:has(input, select, textarea)) td:empty { display: none; }
  table.table:not(:has(input, select, textarea)) tr:hover td { background: none; }
  .table th, .table td { padding: 10px 12px; }

  .qstat-row { grid-template-columns: 28px minmax(0, 1fr) 92px; }
  .auth-form { place-items: start center; padding: max(18px, env(safe-area-inset-top)) 18px 40px; }
  .auth-form h1 { font-size: 24px; }
  .auth-top { justify-content: space-between; margin-bottom: 26px; }
  .auth-brand { display: block; }
  .print-bar .btn { flex: 1 1 auto; }

  /* assistant: full screen sheet on phones */
  .asst-panel { position: fixed; inset: auto 0 0 0; width: 100%; border-width: 1px 0 0; height: min(88vh, 100dvh); border-radius: 20px 20px 0 0; animation: asst-up .28s cubic-bezier(.3,.8,.3,1); }
  .asst.open .asst-fab { display: none; }
  .asst-head { padding-top: 16px; }
  .asst-form { padding-bottom: calc(6px + env(safe-area-inset-bottom, 0px)); }
  .asst-msg { max-width: 90%; }
  @keyframes asst-up { from { transform: translateY(40px); opacity: .4; } to { transform: none; opacity: 1; } }
  .asst-close-m { display: grid !important; }
}
@media (max-width: 380px) { .stats { grid-template-columns: 1fr 1fr; } .stat b { font-size: 20px; } .tabbar a { font-size: 10px; } }

/* Share-link box (student upload link) */
.share-box { display: flex; gap: 8px; flex-wrap: wrap; }
.share-box .input { flex: 1 1 260px; min-width: 0; font-family: ui-monospace, Consolas, monospace; font-size: 14px; background: var(--paper); }
.badge.online { background: #e0f2fe; color: #075985; }
/* Student's marks page */
.res-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: 8px; }
.res-cell { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 8px 10px; border: 1.5px solid var(--line); border-radius: 10px; font-size: 14px; }
.res-cell b { font: 700 13px var(--display); color: var(--muted); }
.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--teal-soft); border-top-color: var(--teal); animation: spin .8s linear infinite; flex: none; }
@keyframes spin { to { transform: rotate(360deg); } }
