/* ============================================================
   Tayyari — Premium Design System
   Direction: minimal & clean, refined teal, light-only.
   ============================================================ */

:root {
  /* Ink / neutrals — premium apps use true neutral grays for text,
     reserving color for accents only (not tinted teal-on-teal). */
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #5b6b81;
  --border: #e7eaee;
  --border-soft: #f0f2f5;

  /* Surfaces */
  --bg: #f7f8fa;
  --surface: #ffffff;

  /* Brand — teal, refined and deepened */
  --primary: #0d9488;
  --primary-600: #0b7d72;
  --primary-700: #0f766e;
  --primary-900: #0c4a44;
  --brand: #0f766e;
  --primary-light: #14b8a6;
  --primary-soft: #eafaf7;
  --primary-soft-2: #d9f5f0;

  /* Accents */
  --gold: #f2b544;
  --gold-dark: #92400e;
  --danger: #e0483e;
  --success: #16a34a;

  /* Radii */
  --r-lg: 22px;
  --r-md: 16px;
  --r-sm: 12px;
  --r-pill: 999px;

  /* Shadows — soft, low-saturation, "expensive" rather than glossy */
  --shadow-xs: 0 1px 2px rgba(15,23,42,.04);
  --shadow-sm: 0 2px 8px rgba(15,23,42,.05), 0 1px 2px rgba(15,23,42,.04);
  --shadow-md: 0 8px 24px rgba(15,23,42,.08);
  --shadow-header: 0 16px 32px -12px rgba(12,74,68,.35);

  --ease: cubic-bezier(.2,.7,.2,1);
}

* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  min-height: 100vh;
  letter-spacing: -.01em;
}

#app {
  max-width: 420px;
  margin: 0 auto;
  padding: 0 16px 90px;
}

h1, h2, h3, h4 { letter-spacing: -.02em; color: var(--ink); line-height: 1.25; }

/* Heading scale (one place to change). Page titles use .page-title; everything else uses one of these:
   .title-lg     full-screen headings (sign-in, plans, review)  1.3rem
   .title-dialog headings inside pop-ups / result cards           1.2rem
   .section-title headings that label a block inside a card       1.02rem */
.title-lg { font-size: 1.3rem; font-weight: 800; margin-top: 4px; }
.title-dialog { font-size: 1.2rem; font-weight: 800; margin-top: 10px; }
.section-title { font-size: 1.02rem; font-weight: 700; margin-bottom: 8px; }
.section-title--brand { color: var(--primary-700); }

header {
  background: linear-gradient(160deg, #0f766e 0%, #0e7f75 100%);
  color: #fff;
  margin: 0 -16px;
  padding: 24px 20px 20px;
  border-radius: 0 0 28px 28px;
  box-shadow: var(--shadow-header);
  position: relative;
}

.header-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand { font-size: 1.5rem; font-weight: 800; letter-spacing: -.02em; }
.brand small { display: block; font-size: .74rem; font-weight: 500; opacity: .8; margin-top: 4px; letter-spacing: 0; }

.board-chip {
  background: rgba(255,255,255,.14);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.3);
  color: #fff;
  font-size: .75rem;
  font-weight: 600;
  padding: 7px 13px;
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: background .15s var(--ease);
}
.board-chip:active { background: rgba(255,255,255,.24); }

.streak-card {
  margin-top: 16px;
  background: rgba(255,255,255,.12);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.16);
  border-radius: var(--r-md);
  padding: 12px 15px;
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: .9rem;
}
.streak-card b { font-size: 1.15rem; font-weight: 800; }

.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  padding: 18px;
  margin-top: 14px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow .18s var(--ease), transform .18s var(--ease);
}

.card h3 { font-size: 1.02rem; margin-bottom: 5px; font-weight: 700; }
.card p.sub { font-size: .83rem; color: var(--ink-2); line-height: 1.45; }

/* Home's three action cards (Daily/Practice/Mock) used to all carry equal
   visual weight, leaving a brand-new student with no signal which one to
   tap first. Used only for a student who has never finished a quiz yet --
   a returning student already knows what they want, so this never nags. */
.card-featured {
  border: 2px solid var(--brand, #0d9488);
  position: relative;
}
.card-featured-tag {
  position: absolute;
  top: -11px;
  left: 16px;
  background: var(--brand, #0d9488);
  color: #fff;
  font-size: .68rem;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 999px;
  letter-spacing: .2px;
}

/* Home screen "Choose Level" card — the main way in/out of every level, so it
   needs to read as more prominent/tappable than the plain white cards below it. */
.level-switch-card {
  background: var(--primary-700);
  color: #fff;
  border: none;
  box-shadow: 0 10px 24px -8px rgba(13,148,136,.45);
}
.level-switch-card h3 { color: #fff; }
.level-switch-card p.sub { color: rgba(255,255,255,.85); }

.big-btn {
  display: block;
  width: 100%;
  border: none;
  background: linear-gradient(135deg, #0c8277, #0f766e);
  color: #fff;
  font-size: .98rem;
  font-weight: 700;
  padding: 15px;
  border-radius: var(--r-sm);
  margin-top: 12px;
  cursor: pointer;
  letter-spacing: -.01em;
  box-shadow: 0 6px 16px -6px rgba(13,148,136,.5);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease);
}
.big-btn.ghost {
  background: var(--surface);
  color: var(--primary-700);
  border: 1.5px solid var(--primary-light);
  box-shadow: none;
}
.big-btn:active { transform: scale(.98); }

/* Practice-tab per-paper breakdown — fixed-height rows so two subject
   cards with the same paper structure (e.g. Physics vs Chemistry) always
   line up, instead of wrapped chips whose height depends on label length. */
.practice-papers {
  margin-top: 10px;
  border-top: 1px solid var(--border-soft);
}
.practice-paper-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  text-align: left;
  font-family: inherit;
  background: none;
  border: none;
  border-bottom: 1px solid var(--border-soft);
  padding: 9px 2px;
  cursor: pointer;
  color: inherit;
}
.practice-paper-row:last-child { border-bottom: none; }
.practice-paper-row .ppr-label { font-size: .78rem; font-weight: 600; color: var(--ink-2); line-height: 1.3; }
.practice-paper-row .ppr-count {
  flex-shrink: 0;
  font-size: .72rem;
  font-weight: 700;
  color: var(--primary-700);
  background: var(--primary-soft-2);
  padding: 3px 9px;
  border-radius: var(--r-pill);
}

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-top: 12px;
}

.subject-card {
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 20px 14px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-soft);
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), border-color .15s var(--ease);
}
.subject-card:active { transform: scale(.97); }
@media (hover: hover) {
  .subject-card:hover { border-color: var(--primary-light); box-shadow: var(--shadow-md); transform: translateY(-2px); }
}
.subject-card .emoji { font-size: 1.9rem; }
.subject-card h4 { margin-top: 9px; font-size: .92rem; font-weight: 700; }
.subject-card p { font-size: .72rem; color: var(--ink-2); margin-top: 3px; }

.board-option {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  padding: 16px;
  margin-top: 12px;
  cursor: pointer;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: 1rem;
  color: inherit;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
.board-option.selected { border-color: var(--primary); background: var(--primary-soft); }
.board-option.disabled { opacity: .5; cursor: not-allowed; }
.board-option .emoji { font-size: 1.7rem; }
.board-option .info { flex: 1; }
.board-option .info small { display: block; color: var(--ink-2); font-size: .76rem; margin-top: 2px; }
.badge {
  background: #fdf1da; color: var(--gold-dark);
  font-size: .65rem; font-weight: 700;
  padding: 4px 9px; border-radius: var(--r-pill);
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 16px;
  font-size: .85rem;
  color: var(--ink-2);
  font-weight: 500;
}

.progress-track {
  height: 8px;
  background: var(--primary-soft-2);
  border-radius: var(--r-pill);
  margin-top: 8px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: var(--r-pill);
  transition: width .3s ease;
}

.timer-chip {
  background: #fdeceb; color: var(--danger);
  font-weight: 700; font-size: .8rem;
  padding: 5px 12px; border-radius: var(--r-pill);
}

.q-card { margin-top: 14px; }
.topic-tag {
  display: inline-block;
  background: var(--primary-soft-2); color: var(--primary-700);
  font-size: .68rem; font-weight: 700;
  padding: 4px 10px; border-radius: var(--r-pill);
  text-transform: uppercase;
  letter-spacing: .4px;
}
.q-text { font-size: 1.05rem; font-weight: 600; line-height: 1.5; margin-top: 11px; letter-spacing: -.01em; }

/* Question stems and model answers keep the line breaks they were authored with,
   so mark-scheme bullets and (a)/(b)/(c) parts stay on separate lines. */
.q-body { white-space: pre-wrap; }

/* Urdu (3247/3248) and any other right-to-left content. unicode-bidi: plaintext
   makes each line pick its own direction, so mixed Urdu/English lines order correctly. */
.rtl { direction: rtl; text-align: right; unicode-bidi: plaintext; line-height: 1.9; }

.option-btn {
  display: block;
  width: 100%;
  text-align: left;
  font-family: inherit;
  font-size: .95rem;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 14px;
  margin-top: 10px;
  cursor: pointer;
  color: inherit;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
@media (hover: hover) { .option-btn:not(:disabled):hover { border-color: var(--primary-light); } }
.option-btn .letter {
  display: inline-block;
  width: 26px; height: 26px;
  line-height: 26px;
  text-align: center;
  background: var(--primary-soft);
  border-radius: 8px;
  font-weight: 700;
  font-size: .78rem;
  margin-right: 10px;
  color: var(--primary);
}
.option-btn.correct { border-color: var(--success); background: #f2faf4; }
.option-btn.correct .letter { background: #dcf3e2; color: #158a3d; }
.option-btn.wrong { border-color: var(--danger); background: #fdf3f2; }
.option-btn.wrong .letter { background: #fbe1de; color: var(--danger); }
/* Mock mode: show which option was picked without revealing right/wrong --
   real exam conditions, the student finds out at the end (showAnswerReview). */
.option-btn.picked { border-color: var(--primary, #0d9488); background: #f0fdfa; }
.option-btn.picked .letter { background: #ccfbf1; color: var(--primary, #0d9488); }
.option-btn:disabled { cursor: default; }

.explanation {
  margin-top: 12px;
  background: #fdf7ea;
  border-left: 4px solid var(--gold);
  border-radius: var(--r-sm);
  padding: 13px 15px;
  font-size: .86rem;
  line-height: 1.55;
  animation: fadein .25s ease;
}
.explanation b { color: var(--gold-dark); }

/* On-device auto-grader (grader.js) feedback view -- highlighted model
   answer spans, colour alone never carries the meaning (icons/text already
   say covered/partial/missed in renderAutoGradeFeedback, this is purely a
   visual reinforcement on top). */
.kp-covered { background: #dcfce7; color: #166534; border-radius: 3px; padding: 0 2px; }
.kp-partial { background: #fef3c7; color: #92400e; border-radius: 3px; padding: 0 2px; }
.kp-missing { color: #6b7280; text-decoration: line-through; text-decoration-color: #d1d5db; }

@keyframes fadein { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

/* Loading-subjects placeholder (lazy-loaded question bank) -- a bare static
   "Loading…" read as a stall rather than progress; a moving bar is a much
   cheaper signal of "something is actively happening" than it looks. */
@keyframes subjectsLoadingBar {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(400%); }
}
.subjects-loading-track {
  width: 140px;
  height: 4px;
  background: var(--border-soft);
  border-radius: 999px;
  overflow: hidden;
}
.subjects-loading-bar {
  width: 25%;
  height: 100%;
  background: var(--brand, #0d9488);
  border-radius: 999px;
  animation: subjectsLoadingBar 1.1s ease-in-out infinite;
}
@media (prefers-reduced-motion: reduce) {
  .subjects-loading-bar { animation: none; width: 100%; }
}

.score-hero { text-align: center; padding: 32px 10px 10px; }
.score-hero .big-emoji { font-size: 3.2rem; }
.score-hero h2 { font-size: 2.1rem; margin-top: 10px; font-weight: 800; }
.score-hero p { color: var(--ink-2); margin-top: 6px; font-size: .92rem; }

.stat-row { display: flex; gap: 10px; margin-top: 14px; }
.stat-box {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  padding: 15px 10px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}
.stat-box b { display: block; font-size: 1.28rem; color: var(--primary); font-weight: 800; }
.stat-box span { font-size: .72rem; color: var(--ink-2); }

.premium-banner {
  margin-top: 14px;
  background: var(--primary-900);
  color: #fff;
  border-radius: var(--r-md);
  padding: 17px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  box-shadow: 0 10px 24px -10px rgba(16,27,44,.6);
}
.premium-banner p { font-size: .82rem; opacity: .8; margin-top: 3px; }
.premium-banner button {
  border: none;
  background: var(--gold);
  color: #78350f;
  font-weight: 800;
  font-size: .8rem;
  padding: 10px 15px;
  border-radius: var(--r-sm);
  cursor: pointer;
  white-space: nowrap;
}

.whatsapp-preview {
  background: #e5ddd5;
  border-radius: var(--r-md);
  padding: 16px;
  margin-top: 14px;
}
.bubble {
  background: #dcf8c6;
  border-radius: 12px 12px 12px 2px;
  padding: 12px 14px;
  font-size: .84rem;
  line-height: 1.6;
  max-width: 92%;
  box-shadow: 0 1px 3px rgba(0,0,0,.12);
  white-space: pre-wrap;
}

#nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 420px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(14px);
  display: flex;
  border-top: 1px solid var(--border-soft);
  padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
  z-index: 50;
}

/* Sticky action bar for the active question's Next/Submit button — pinned
   to the bottom of the screen so it's reachable without scrolling, however
   long the question/explanation text runs. Takes over #nav's spot while a
   question is on screen (#nav is hidden meanwhile via JS). */
.quiz-actionbar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 420px;
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--border-soft);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  z-index: 55;
  box-shadow: 0 -2px 10px rgba(0,0,0,.08);
}
.quiz-actionbar .big-btn { margin-top: 0; }
.nav-btn {
  flex: 1;
  border: none;
  background: none;
  font-size: .66rem;
  font-weight: 600;
  color: var(--ink-3);
  cursor: pointer;
  font-family: inherit;
  padding: 5px 2px;
  border-radius: 12px;
  transition: color .15s var(--ease), background .15s var(--ease);
}
.nav-btn span { display: block; font-size: 1.22rem; margin-bottom: 2px; }
.nav-btn.active { color: var(--primary-700); background: var(--primary-soft); }

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 11px 18px;
  border-radius: 18px;
  font-size: .82rem;
  z-index: 99;
  animation: fadein .25s ease;
  white-space: normal;
  text-align: center;
  max-width: min(420px, calc(100vw - 32px));
  overflow-wrap: anywhere;
  width: max-content;
  line-height: 1.4;
  box-shadow: var(--shadow-md);
}

.back-link {
  display: inline-block;
  margin-top: 16px;
  background: none;
  border: none;
  color: var(--primary-700);
  font-weight: 700;
  font-size: .88rem;
  cursor: pointer;
  font-family: inherit;
  padding: 6px 0;
}

.gcard {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
  margin-top: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.gcard summary {
  padding: 15px 16px;
  font-weight: 700;
  font-size: .92rem;
  cursor: pointer;
  list-style: none;
}
.gcard summary::-webkit-details-marker { display: none; }
.gcard summary::after {
  content: "+";
  float: right;
  color: var(--primary);
  font-size: 1.1rem;
}
.gcard[open] summary::after { content: "–"; }
.gcard .body {
  padding: 0 16px 15px;
  font-size: .85rem;
  line-height: 1.6;
  color: #374151;
}

.premium-banner.gold { background: var(--primary-900); }

.lock-wrap { position: relative; margin-top: 14px; border-radius: var(--r-md); overflow: hidden; }
.lock-blur { filter: blur(5px); pointer-events: none; user-select: none; }
.lock-overlay {
  position: absolute; inset: 0;
  background: rgba(15,23,42,.32);
  backdrop-filter: blur(1px);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; text-align: center; color: #fff; font-weight: 700; padding: 16px;
}

.paper-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 11px 2px; border-bottom: 1px solid var(--border-soft); font-size: .86rem;
}
.paper-row:last-child { border-bottom: none; }
.paper-dl {
  border: none; background: var(--primary-soft-2); color: var(--primary-700);
  font-weight: 700; font-size: .75rem; padding: 7px 12px;
  border-radius: var(--r-pill); cursor: pointer; white-space: nowrap; font-family: inherit;
}
a.paper-dl { text-decoration: none; display: inline-block; }
.paper-dl.soon { background: #f0f2f5; color: var(--ink-3); cursor: default; }
.paper-actions { display: flex; gap: 6px; flex-shrink: 0; }
.paper-dl.dl { background: #e6e9fb; color: #3d3ca6; }

/* Vector notation (e.g. F⃗) — drawn with plain CSS instead of the Unicode
   combining-arrow character, which shows as a blank box on fonts (Segoe UI,
   Arial, etc.) that don't include that glyph. */
.vecx { position: relative; display: inline-block; font-weight: 700; padding: 0 1px; }
.vecx::after {
  content: "\2192"; position: absolute; left: 50%; top: -0.62em;
  transform: translateX(-50%) scale(0.85, 0.55); font-weight: 400;
  font-size: 0.85em; line-height: 1; pointer-events: none;
}
.chip-premium {
  display: inline-block; background: #fdf1da; color: var(--gold-dark);
  font-size: .66rem; font-weight: 800; padding: 4px 10px;
  border-radius: var(--r-pill); margin-left: 6px; vertical-align: middle;
}
.chip-premium.locked-chip { background: #fbe1de; color: #a4271f; }

.code-input {
  width: 100%; font-family: inherit; font-size: 1.05rem;
  letter-spacing: 2px; text-transform: uppercase; text-align: center;
  padding: 14px; border: 1.5px solid var(--primary-light); border-radius: var(--r-sm);
  margin-top: 12px; color: var(--ink); outline: none;
  transition: border-color .15s var(--ease);
}
.code-input:focus { border-color: var(--primary); }

#review-sheet { background: var(--surface); }
.rev-head { text-align: center; padding: 18px 8px 6px; }
.rev-item {
  border: 1px solid var(--border); border-radius: var(--r-sm); padding: 12px;
  margin-top: 10px; font-size: .85rem; line-height: 1.5; background: var(--surface);
}
.rev-item.ok { border-left: 4px solid var(--success); }
.rev-item.bad { border-left: 4px solid var(--danger); }
.rev-item .ans-ok { color: #157a37; font-weight: 700; }
.rev-item .ans-bad { color: #a4271f; font-weight: 700; }

@media print {
  body { background: #fff; }
  #nav, .no-print { display: none !important; }
  #app { max-width: none; padding: 0; }
  body * { visibility: hidden; }
  #review-sheet, #review-sheet * { visibility: visible; }
  #review-sheet { position: absolute; top: 0; left: 0; width: 100%; box-shadow: none; }
}

/* Premium Badge Card */
.premium-badge-card {
  position: relative;
  margin-top: 14px;
  border-radius: var(--r-md);
  overflow: hidden;
  cursor: pointer;
  background: var(--primary-900);
  border: 1.5px solid var(--gold);
  box-shadow: 0 10px 24px -10px rgba(16,27,44,.55);
}
.premium-badge-glow {
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: conic-gradient(from 0deg, transparent, rgba(242,181,68,0.15), transparent, rgba(242,181,68,0.15), transparent);
  animation: premiumGlowSpin 4s linear infinite;
}
@keyframes premiumGlowSpin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
.premium-badge-content {
  position: relative;
  z-index: 1;
  padding: 19px 17px;
  color: #fff;
}
.premium-badge-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.premium-crown {
  font-size: 2rem;
  filter: drop-shadow(0 0 8px rgba(242,181,68,0.5));
}
.premium-badge-title {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--gold);
}
.premium-badge-price {
  font-size: .78rem;
  opacity: .8;
  margin-top: 2px;
}
.premium-benefits-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}
.premium-benefit {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: .85rem;
  opacity: .95;
}
.benefit-check {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  background: rgba(34,197,94,0.2);
  color: #4ade80;
  border-radius: 50%;
  font-size: .75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.premium-badge-cta {
  text-align: center;
  padding: 11px;
  background: var(--gold);
  color: #78350f;
  border-radius: var(--r-sm);
  font-weight: 800;
  font-size: .88rem;
}

/* Modal Overlay */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  min-height: 100vh;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  padding: 26px 22px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 24px 60px rgba(15,23,42,0.3);
  animation: modalSlideUp 0.3s ease;
}
@keyframes modalSlideUp {
  from { transform: translateY(20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}
.modal-icon {
  font-size: 2.5rem;
  margin-bottom: 4px;
}
.modal-stat-row {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 16px 0 8px;
}
.modal-stat {
  flex: 1;
  background: var(--bg);
  border-radius: var(--r-sm);
  padding: 12px 8px;
  text-align: center;
}
.modal-stat b {
  display: block;
  font-size: 1.3rem;
  color: var(--primary);
  font-weight: 800;
}
.modal-stat span {
  font-size: .72rem;
  color: var(--ink-2);
}
.premium-btn {
  background: var(--gold) !important;
  color: #78350f !important;
}

/* ---- Ported from CAIE app: report history, daily-challenge subject picker, auth chip ---- */

/* Report history — Report tab */
.report-history-list {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--r-md);
  margin-top: 12px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.report-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 13px 16px; border-bottom: 1px solid var(--border-soft);
  cursor: pointer; transition: background .12s ease;
}
.report-row:last-child { border-bottom: none; }
.report-row:active { background: var(--primary-soft); }
@media (hover: hover) { .report-row:hover { background: #fafbfc; } }
.report-row.no-detail { cursor: default; opacity: .6; }
.report-row.no-detail:active, .report-row.no-detail:hover { background: transparent; }

/* Daily Challenge subject picker */
.subject-check-list { padding: 6px 4px; }
.subject-check-row {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 8px; border-bottom: 1px solid var(--border-soft);
  font-size: .92rem; cursor: pointer;
}
.subject-check-row:last-child { border-bottom: none; }
.subject-check-row input[type="checkbox"] {
  width: 20px; height: 20px; accent-color: var(--primary); cursor: pointer; flex-shrink: 0;
}

/* Always-visible sign-in/out control in the header */
.auth-chip {
  background: rgba(255,255,255,.16);
  backdrop-filter: blur(6px);
  border: 1px solid rgba(255,255,255,.32);
  color: #fff;
  border-radius: var(--r-pill);
  cursor: pointer;
  padding: 0;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .15s var(--ease);
}
.auth-chip:active { background: rgba(255,255,255,.26); }
.auth-chip.auth-chip-text {
  width: auto;
  height: auto;
  padding: 7px 14px;
  font-size: .75rem;
  font-weight: 700;
}

/* Report tab (My Progress) */
.rep-big { font-size: 2.6rem; font-weight: 800; color: var(--primary, #0d9488); line-height: 1.1; margin-top: 6px; }
.rep-sub { font-size: .76rem; color: var(--ink-2, #6b7280); line-height: 1.45; }
.rep-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--border-soft, #eef0f3); font-size: .88rem; }
.rep-row:last-of-type { border-bottom: none; }
.rep-row b { font-weight: 800; }
.rep-btn { flex-shrink: 0; border: 1.5px solid var(--primary, #0d9488); background: #fff; color: var(--primary, #0d9488); font-weight: 700; font-size: .78rem; padding: 9px 14px; border-radius: 10px; cursor: pointer; min-height: 40px; font-family: inherit; }
@media print { .rep-btn { display: none; } }


/* ============================================================
   UX pass v7.0 — hierarchy, consistency, touch targets, nav.
   Layered after the original rules so every change is traceable;
   nothing above this line was edited except the two duplicate
   blocks noted in the changelog.
   ============================================================ */

:root {
  --ink-4: #cbd5e1;
  --success-soft: #eef9f1;
  --danger-soft: #fdf3f2;
}

/* Keyboard focus is visible, mouse/touch focus is not */
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
button:focus:not(:focus-visible) { outline: none; }

/* ---- Header ------------------------------------------------ */
.brand small { max-width: 230px; line-height: 1.35; }
header.header-compact { padding: 12px 20px; border-radius: 0 0 20px 20px; }
header.header-compact .brand { font-size: 1.1rem; }
header.header-compact .board-chip { padding: 6px 11px; font-size: .72rem; }

/* ---- Page rhythm ------------------------------------------- */
.page-title { margin-top: 22px; font-size: 1.3rem; font-weight: 800; line-height: 1.25; }
.page-sub { font-size: .86rem; color: var(--ink-2); margin: 5px 0 14px; line-height: 1.5; }
.page-sub + .page-sub { margin-top: -6px; }

/* ---- Cards ------------------------------------------------- */
.card[onclick] { cursor: pointer; }
.card[onclick]:active { transform: scale(.99); }
.card h3 { font-size: 1.04rem; }
.card p.sub { font-size: .85rem; }

/* Home: compact "studying for" row replaces the gradient level card */
.level-row {
  display: flex; align-items: center; gap: 10px; width: 100%;
  margin-top: 14px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border-soft);
  border-radius: var(--r-md); box-shadow: var(--shadow-xs);
  cursor: pointer; font-family: inherit; color: inherit; text-align: left;
}
.level-row:active { background: var(--primary-soft); }
.level-row-label { flex-shrink: 0; font-size: .68rem; font-weight: 700; color: var(--ink-3); text-transform: uppercase; letter-spacing: .5px; }
.level-row-value { flex: 1; min-width: 0; font-size: .92rem; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.level-row-chevron { color: var(--ink-3); font-size: 1.35rem; line-height: 1; }

/* Premium card: the spinning conic glow read as a casino banner; a still
   warm highlight keeps the card distinct without the motion. */
.premium-badge-glow { animation: none; background: radial-gradient(circle at 88% 12%, rgba(242,181,68,.22), transparent 55%); }
@media (prefers-reduced-motion: reduce) { .premium-badge-glow { background: none; } }

/* ---- Practice tab ------------------------------------------ */
.subject-card { padding: 18px 14px 10px; }
.subject-card h4 { line-height: 1.3; }
.practice-paper-row { min-height: 44px; padding: 8px 4px; border-radius: 8px; }
.practice-paper-row:active { background: var(--primary-soft); }
.practice-paper-row .ppr-label { color: var(--ink); font-weight: 600; }
.practice-paper-row .ppr-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.practice-paper-row .ppr-num { font-size: .8rem; font-weight: 700; color: var(--ink); line-height: 1.3; }
.practice-paper-row .ppr-name { font-size: .74rem; font-weight: 500; color: var(--ink-2); line-height: 1.3; }
.practice-paper-row .ppr-meta { font-size: .68rem; font-weight: 500; color: var(--ink-3); line-height: 1.3; }

/* ---- Quiz screens ------------------------------------------ */
.quiz-header { margin-top: 14px; font-size: .82rem; }
.quiz-header .quiz-label { color: var(--ink); font-weight: 600; }
.quiz-header .quiz-meta { color: var(--ink-3); font-weight: 500; font-variant-numeric: tabular-nums; }
.progress-track { height: 6px; margin-top: 8px; }
.progress-track .progress-fill { background: var(--primary); }

.q-card { padding: 18px 16px 16px; }
.q-meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.q-meta > span:not(.topic-tag):not(.q-chip) { font-size: .68rem; color: var(--ink-2); font-weight: 600; }
.q-chip {
  display: inline-block; font-size: .68rem; font-weight: 600; color: var(--ink-2);
  background: var(--bg); border: 1px solid var(--border-soft);
  padding: 4px 9px; border-radius: var(--r-pill); text-transform: capitalize;
}
.q-source { font-size: .74rem; color: var(--ink-3); margin-top: 10px; line-height: 1.4; }
.q-text { margin-top: 8px; font-size: 1.06rem; }
.q-figure { margin: 14px 0 4px; text-align: center; }
.q-figure img { max-width: 100%; border: 1px solid var(--border); border-radius: 10px; cursor: zoom-in; }

/* One option component for every mode (the old .quiz-option duplicate is gone) */
.option-btn {
  display: flex; align-items: flex-start; gap: 12px;
  min-height: 52px; padding: 13px 14px; margin-top: 10px;
  border-radius: 14px; line-height: 1.45; font-size: .95rem;
}
.option-btn .letter { flex-shrink: 0; margin: 1px 0 0; }
.option-btn .opt-text { flex: 1; min-width: 0; }
.option-btn:not(:disabled):active { transform: scale(.985); border-color: var(--primary-light); }
.option-btn.correct .opt-text { font-weight: 600; }

.answer-box {
  display: block; width: 100%; min-height: 130px; margin-top: 12px; padding: 12px 14px;
  border: 1.5px solid var(--border); border-radius: 12px;
  font: inherit; font-size: .95rem; line-height: 1.5; resize: vertical;
  background: #fff; color: var(--ink);
}
.answer-box:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft-2); }
.answer-box:disabled { background: var(--bg); color: var(--ink-2); }

/* Feedback: colour follows the verdict (gold stays for graded written answers) */
.explanation { border-radius: 12px; }
.explanation.ok { background: var(--success-soft); border-left-color: var(--success); }
.explanation.ok b { color: #166534; }
.explanation.bad { background: var(--danger-soft); border-left-color: var(--danger); }
.explanation.bad b { color: #991b1b; }

.back-link { margin-top: 14px; font-weight: 600; color: var(--ink-2); }

/* ---- Buttons ----------------------------------------------- */
.big-btn { min-height: 48px; }
.big-btn.ghost:active { background: var(--primary-soft); }

/* ---- Mock tab ---------------------------------------------- */
.mock-select {
  width: 100%; margin-top: 10px; padding: 10px 34px 10px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
  font: inherit; font-size: .8rem; font-weight: 600; color: var(--ink);
  background-color: #fff;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%230d9488' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'><path d='m6 9 6 6 6-6'/></svg>");
  background-repeat: no-repeat; background-position: right 10px center;
  -webkit-appearance: none; appearance: none; cursor: pointer; text-align: left;
}
.mock-select:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft-2); }

/* ---- Past papers / accordions ------------------------------ */
.gcard summary { min-height: 52px; display: flex; align-items: center; gap: 8px; }
.gcard summary::after { margin-left: auto; float: none; }
.paper-row { min-height: 44px; }
.paper-dl { min-height: 32px; }

/* ---- Bottom navigation ------------------------------------- */
#nav { padding: 6px 4px calc(6px + env(safe-area-inset-bottom)); gap: 2px; }
.nav-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 7px 2px 6px; font-size: .64rem; letter-spacing: .1px; min-height: 52px;
}
.nav-btn svg {
  display: block; width: 22px; height: 22px;
  stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round;
  transition: transform .15s var(--ease);
}
.nav-btn .nav-label { display: block; font-size: inherit; margin: 0; line-height: 1.1; }
.nav-btn.active svg { stroke-width: 2.3; }
.nav-btn:active svg { transform: scale(.92); }

/* ---- Wide screens: frame the phone-width app ---------------- */
@media (min-width: 720px) {
  body { background: #eceff3; }
  #app {
    background: var(--bg); min-height: 100vh;
    box-shadow: 0 0 0 1px var(--border), 0 24px 60px -24px rgba(15,23,42,.18);
  }
}


/* ============================================================
   Brand pass v8.0 — one teal palette, gradients only on the
   header and primary buttons, line-icon tiles, AA contrast.
   ============================================================ */

/* ---- Brand lockup ------------------------------------------- */
/* The logo is artwork (img), sized by height so its proportions can never be distorted; the tagline sits under it. */
.brand { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; min-width: 0; }
.brand-lockup { display: block; height: 34px; width: auto; max-width: 100%; }
.brand small { margin: 0; opacity: .94; font-weight: 500; font-size: .74rem; line-height: 1.3; }
header.header-compact .brand-lockup { height: 28px; }

/* Loading: the symbol on the page background, its answer dot gently pulsing */
.brand-mark { width: 64px; height: auto; flex: none; display: block; }
.loading-mark .brand-mark-lg { width: 72px; }
.brand-mark .bm-dot { transform-box: fill-box; transform-origin: center; animation: dotPulse 1.4s ease-in-out infinite; }
@keyframes dotPulse { 0%, 100% { transform: scale(.78); opacity: .72; } 50% { transform: scale(1.12); opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .brand-mark .bm-dot { animation: none; } }

/* ---- Header controls: darker glass for readable white text --- */
.board-chip, .auth-chip { background: rgba(4, 52, 47, .30); border-color: rgba(255,255,255,.34); }
.board-chip:active, .auth-chip:active { background: rgba(4, 52, 47, .45); }
.streak-card { background: rgba(4, 52, 47, .24); border-color: rgba(255,255,255,.2); }

/* ---- Icon system -------------------------------------------- */
.ic {
  width: 1.15em; height: 1.15em; flex: none;
  vertical-align: -.2em;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.ic-checkcircle { color: var(--success); }
.ic-xcircle { color: var(--danger); }
.ic-alert { color: #b45309; }

/* Level, grade, board and subject icons sit in a soft tile */
.board-option .emoji, .subject-card .emoji, .big-emoji, .modal-icon, .premium-crown {
  display: flex; align-items: center; justify-content: center; flex: none;
}
.board-option .emoji {
  width: 46px; height: 46px; border-radius: 14px;
  background: var(--primary-soft); color: var(--primary-700); font-size: 1.45rem;
}
.board-option.selected .emoji { background: var(--primary-soft-2); }
.board-option .emoji .ic, .subject-card .emoji .ic { width: 1em; height: 1em; stroke-width: 1.7; vertical-align: 0; }
.emoji-num { font-size: 1.2rem !important; font-weight: 800; letter-spacing: -.02em; }

.subject-card .emoji {
  width: 50px; height: 50px; border-radius: 15px; margin: 0 auto;
  background: var(--primary-soft); color: var(--primary-700); font-size: 1.6rem;
}
.subject-card h4 { margin-top: 12px; }

.score-hero .big-emoji, .big-emoji {
  width: 84px; height: 84px; margin: 0 auto; border-radius: 26px;
  background: var(--primary-soft); color: var(--primary-700); font-size: 2.6rem;
}
.big-emoji .ic { width: 1em; height: 1em; stroke-width: 1.5; vertical-align: 0; }
.modal-icon {
  width: 64px; height: 64px; margin: 0 auto 6px; border-radius: 20px;
  background: var(--primary-soft); color: var(--primary-700); font-size: 1.9rem;
}
.modal-icon .ic { width: 1em; height: 1em; stroke-width: 1.7; vertical-align: 0; }

.level-row-value .ic { color: var(--primary-700); margin-right: 2px; }

/* ---- One palette: Premium is deep teal with a gold accent ---- */
.premium-banner, .premium-badge-card { background: var(--primary-900); }
.premium-banner { border: 1px solid rgba(242,181,68,.45); box-shadow: 0 10px 24px -12px rgba(12,74,68,.6); }
.premium-banner.gold { background: var(--primary-900); border: 1px solid var(--gold); }
.premium-badge-card { border: 1.5px solid rgba(242,181,68,.7); box-shadow: 0 10px 24px -12px rgba(12,74,68,.6); }
.premium-badge-glow { display: none; }
.premium-crown {
  width: 46px; height: 46px; border-radius: 14px; font-size: 1.7rem;
  background: rgba(242,181,68,.14); color: var(--gold); filter: none;
}
.premium-crown .ic { width: 1em; height: 1em; stroke-width: 1.7; vertical-align: 0; }
.premium-btn { background: var(--gold) !important; color: #78350f !important; }
.premium-badge-title { color: var(--gold); }
.benefit-check { background: rgba(94, 234, 212, .16); color: #5eead4; }

/* Gold stays exclusive to Premium: neutral info feedback is teal */
.explanation { background: var(--primary-soft); border-left-color: var(--primary); }
.explanation b { color: var(--primary-900); }
.explanation.ok { background: var(--success-soft); border-left-color: var(--success); }
.explanation.ok b { color: #166534; }
.explanation.bad { background: var(--danger-soft); border-left-color: var(--danger); }
.explanation.bad b { color: #991b1b; }

/* ---- Motivation card: calm, flat, readable -------------------- */
.motivation-card { background: var(--primary-soft); border: 1px solid var(--primary-soft-2); box-shadow: none; margin-bottom: 15px; }
.motivation-card h3 { color: var(--primary-900); display: flex; align-items: center; gap: 8px; }
.motivation-card h3 .ic { color: var(--primary-700); width: 1.25em; height: 1.25em; }
.motivation-card p.sub { color: var(--ink-2); }
.motivation-streak { font-size: .76rem; color: var(--primary-900); font-weight: 600; margin-top: 8px; }

/* ---- Contrast fixes ------------------------------------------ */
.option-btn .letter { color: var(--primary-700); }
.topic-tag { color: var(--primary-900); }
.stat-box b, .modal-stat b { color: var(--primary-700); }
.nav-btn { color: var(--ink-3); }
.nav-btn.active { color: var(--primary-900); }

/* Header layout: brand takes the free space, controls never wrap */
.header-row { gap: 12px; }
.brand { flex: 1; }
.header-row > div:last-child { flex: none; }
.auth-chip.auth-chip-text, .board-chip { white-space: nowrap; }

/* Verdict badges: dark enough on their tinted backgrounds */
.option-btn.correct .letter { color: #14532d; }
.option-btn.wrong .letter { color: #991b1b; }
.paper-dl.soon { color: var(--ink-3); }

.mock-select { font-size: .78rem; padding-right: 30px; text-overflow: ellipsis; }

/* Header: wordmark never gets covered; controls wrap below if they can't fit */
.header-row { flex-wrap: wrap; row-gap: 10px; }
.brand { flex: 1 1 auto; }
.header-row > div:last-child { flex: 0 1 auto; margin-left: auto; min-width: 0; max-width: 100%; }
.board-chip { display: flex; align-items: center; gap: 4px; max-width: 100%; min-width: 0; }
.board-chip .chip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---- My notes badge (notes.js) -------------------------------------------- */
.notes-root[hidden] { display: none; }
.notes-badge {
  position: fixed; right: 10px; top: 104px; z-index: 110;
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; cursor: pointer;
  width: 44px; height: 44px; padding: 0; border: 0; border-radius: 22.4%;      /* same corner radius as the logo tile */
  background: transparent; display: block;
  filter: drop-shadow(0 6px 10px rgba(15,118,110,.38)) drop-shadow(0 1px 2px rgba(15,23,42,.2));
  transition: transform .15s var(--ease, ease), filter .15s;
}
.notes-badge img { width: 100%; height: 100%; display: block; border-radius: 22.4%; pointer-events: none; -webkit-user-drag: none; }
.notes-badge:hover { transform: translateY(-1px) scale(1.04); }
.notes-badge:active { transform: scale(.94); }
.notes-badge.is-dragging { cursor: grabbing; }
.notes-badge:focus-visible, .notes-badge.is-open { outline: 3px solid rgba(15,118,110,.4); outline-offset: 2px; }
.notes-badge.has-notes::after {                       /* a small gold dot on the corner when there is something written */
  content: ""; position: absolute; top: -4px; right: -4px; width: 13px; height: 13px;
  border-radius: 50%; background: var(--gold); border: 2px solid #fff;
}
.notes-panel {
  position: fixed; right: 10px; top: 150px; z-index: 111;
  width: min(calc(100vw - 20px), 340px); max-height: min(72vh, 440px);
  display: flex; flex-direction: column;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md);
  box-shadow: 0 16px 40px rgba(15,23,42,.22);
}
.notes-panel[hidden] { display: none; }
.notes-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 6px 14px; }
.notes-title { display: flex; align-items: center; gap: 7px; font-weight: 700; font-size: .92rem; color: var(--primary-900); }
.notes-x { width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent; color: var(--ink-2); cursor: pointer; display: flex; align-items: center; justify-content: center; }
.notes-x:hover { background: var(--primary-soft); }
.notes-area {
  flex: 1; min-height: 150px; margin: 0 12px; padding: 10px 12px; resize: none;
  font: inherit; font-size: .9rem; line-height: 1.5; color: var(--ink);
  border: 1.5px solid var(--border); border-radius: var(--r-sm); background: #fffefa; outline: none;
}
.notes-area:focus { border-color: var(--primary); }
.notes-foot { padding: 8px 14px 10px; }
.notes-line { display: flex; justify-content: space-between; gap: 8px; font-size: .72rem; color: var(--ink-3); }
.notes-tools { display: flex; gap: 14px; margin-top: 6px; flex-wrap: wrap; }
.notes-link { border: 0; background: none; padding: 4px 0; font: inherit; font-size: .8rem; font-weight: 600; color: var(--primary-700); cursor: pointer; }
.notes-link.notes-off { margin-left: auto; color: var(--ink-3); font-weight: 500; }
.notes-badge[hidden], .notes-restore[hidden] { display: none; }
.notes-restore {                                      /* only shown while the badge is switched off */
  position: fixed; bottom: 84px; z-index: 109;
  border: 0; border-radius: 999px; padding: 8px 14px; font: inherit; font-size: .78rem; font-weight: 600;
  background: var(--surface, #fff); color: var(--primary-700); cursor: pointer;
  box-shadow: 0 4px 14px rgba(15,23,42,.18), 0 0 0 1px var(--border, #e5e7eb);
}
@media print { .notes-root { display: none !important; } }
@media (prefers-reduced-motion: reduce) { .notes-badge { transition: none; } }
.notes-warn { margin: 6px 14px 0; font-size: .72rem; line-height: 1.4; color: var(--gold-dark, #92400e); background: #fffbeb; border-radius: 8px; padding: 6px 9px; }
.notes-badge.is-dragging { cursor: grabbing; transform: scale(1.12); transition: none; filter: drop-shadow(0 10px 14px rgba(15,118,110,.5)) drop-shadow(0 2px 4px rgba(15,23,42,.25)); }
/* the app's general touch-target rules give buttons a larger minimum size and a pointer cursor: the badge is sized exactly, and shows grab cursors */
.notes-root .notes-badge { box-sizing: border-box; flex: none; width: 44px; height: 44px; min-width: 44px; min-height: 44px; cursor: grab; }
.notes-root .notes-badge.is-dragging { cursor: grabbing; }
