/* ============================================================
   UGC NET Knowledge Bank — UI v2
   ============================================================ */

/* ---- DESIGN TOKENS ---------------------------------------- */
:root {
  --bg:             #f0f4f8;
  --surface:        #ffffff;
  --surface-soft:   #f8fafc;
  --surface-hover:  #f1f5f9;
  --border:         #e2e8f0;
  --text:           #0f172a;
  --text-secondary: #334155;
  --muted:          #64748b;
  --muted-light:    #94a3b8;

  --primary:        #4f46e5;
  --primary-hover:  #4338ca;
  --primary-soft:   #eef2ff;
  --primary-muted:  #c7d2fe;

  --ok:             #059669;
  --ok-bg:          #ecfdf5;
  --ok-border:      #6ee7b7;
  --ok-text:        #064e3b;

  --bad:            #dc2626;
  --bad-bg:         #fef2f2;
  --bad-border:     #fca5a5;
  --bad-text:       #7f1d1d;

  --amber:          #d97706;
  --amber-bg:       #fffbeb;
  --amber-border:   #fde68a;
  --amber-text:     #78350f;

  --nav-bg:         #0f172a;
  --nav-border:     #1e293b;
  --nav-text:       #f1f5f9;
  --nav-muted:      #94a3b8;

  --shadow-xs:  0 1px 2px rgba(15,23,42,.04);
  --shadow-sm:  0 2px 6px rgba(15,23,42,.06);
  --shadow-md:  0 4px 18px rgba(15,23,42,.09);
  --shadow-lg:  0 8px 32px rgba(15,23,42,.13);

  --radius-sm:  8px;
  --radius:     14px;
  --radius-lg:  20px;

  --font: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", ui-monospace, SFMono-Regular, Consolas, monospace;
  --transition: 0.16s cubic-bezier(.4,0,.2,1);
}

/* Dark mode via class (manual toggle) */
html[data-theme="dark"] {
  --bg:             #0a0f1a;
  --surface:        #111827;
  --surface-soft:   #1a2235;
  --surface-hover:  #1e2d42;
  --border:         #1e293b;
  --text:           #f1f5f9;
  --text-secondary: #cbd5e1;
  --muted:          #94a3b8;
  --muted-light:    #64748b;

  --primary:        #6366f1;
  --primary-hover:  #818cf8;
  --primary-soft:   #1e1b4b;
  --primary-muted:  #312e81;

  --ok:             #10b981;
  --ok-bg:          #022c22;
  --ok-border:      #065f46;
  --ok-text:        #6ee7b7;

  --bad:            #ef4444;
  --bad-bg:         #2d0a0a;
  --bad-border:     #7f1d1d;
  --bad-text:       #fca5a5;

  --amber:          #f59e0b;
  --amber-bg:       #1c1206;
  --amber-border:   #78350f;
  --amber-text:     #fde68a;

  --nav-bg:         #060d1a;
  --nav-border:     #111827;

  --shadow-xs:  0 1px 2px rgba(0,0,0,.2);
  --shadow-sm:  0 2px 6px rgba(0,0,0,.25);
  --shadow-md:  0 4px 18px rgba(0,0,0,.35);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.45);
}

/* System preference fallback when no manual choice made */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    --bg:             #0a0f1a;
    --surface:        #111827;
    --surface-soft:   #1a2235;
    --surface-hover:  #1e2d42;
    --border:         #1e293b;
    --text:           #f1f5f9;
    --text-secondary: #cbd5e1;
    --muted:          #94a3b8;
    --muted-light:    #64748b;
    --primary:        #6366f1;
    --primary-hover:  #818cf8;
    --primary-soft:   #1e1b4b;
    --primary-muted:  #312e81;
    --ok:             #10b981;
    --ok-bg:          #022c22;
    --ok-border:      #065f46;
    --ok-text:        #6ee7b7;
    --bad:            #ef4444;
    --bad-bg:         #2d0a0a;
    --bad-border:     #7f1d1d;
    --bad-text:       #fca5a5;
    --amber:          #f59e0b;
    --amber-bg:       #1c1206;
    --amber-border:   #78350f;
    --amber-text:     #fde68a;
    --nav-bg:         #060d1a;
    --nav-border:     #111827;
    --shadow-xs:  0 1px 2px rgba(0,0,0,.2);
    --shadow-sm:  0 2px 6px rgba(0,0,0,.25);
    --shadow-md:  0 4px 18px rgba(0,0,0,.35);
    --shadow-lg:  0 8px 32px rgba(0,0,0,.45);
  }
}

/* ---- RESET & BASE ----------------------------------------- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  transition: background 0.2s, color 0.2s;
}

/* ---- TOP NAV --------------------------------------------- */
.topbar {
  background: var(--nav-bg);
  color: var(--nav-text);
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid var(--nav-border);
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 16px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 8px;
  padding: 4px;
}
.brand:focus-visible { outline: 2px solid var(--primary); }

.brand-badge {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #fff;
  font-weight: 800;
  font-size: 0.75rem;
  letter-spacing: .06em;
  padding: 6px 9px;
  border-radius: 9px;
  line-height: 1;
}

.brand-text h1 {
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--nav-text);
}
.brand-text p {
  font-size: 0.69rem;
  color: var(--nav-muted);
  line-height: 1;
  margin-top: 2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stats-pill {
  background: rgba(255,255,255,.07);
  border: 1px solid rgba(255,255,255,.1);
  padding: 5px 11px;
  border-radius: 999px;
  font-size: 0.74rem;
  font-weight: 600;
  white-space: nowrap;
  color: var(--nav-muted);
}
.stats-pill strong { color: var(--nav-text); }

/* Theme toggle button */
.theme-toggle {
  width: 36px; height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.07);
  color: var(--nav-muted);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  font-size: 1rem;
  flex-shrink: 0;
}
.theme-toggle:hover { background: rgba(255,255,255,.14); color: var(--nav-text); }

.icon-circle-btn {
  width: 36px; height: 36px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(255,255,255,.07);
  color: var(--nav-muted);
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: var(--transition);
  flex-shrink: 0;
}
.icon-circle-btn:hover { background: rgba(255,255,255,.14); color: var(--nav-text); }

/* ---- LAYOUT ---------------------------------------------- */
.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 60px;
}

.view { display: none; }
.view.active { display: block; }

/* ---- HOME — HERO DASHBOARD -------------------------------- */
.hero-dashboard {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-sm);
}

.dashboard-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 20px;
}

.subject-switch {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 4px;
  border-radius: 11px;
  gap: 3px;
}

.subject-btn {
  border: none;
  background: transparent;
  padding: 7px 15px;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.84rem;
  color: var(--muted);
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
  font-family: var(--font);
}
.subject-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-sm);
}

/* Stats row */
.stats-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--surface-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  text-align: center;
}
.stat-num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
  line-height: 1;
  display: block;
}
.stat-label {
  font-size: 0.7rem;
  color: var(--muted);
  margin-top: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  display: block;
}

.subject-heading {
  font-size: 1.1rem;
  font-weight: 700;
  margin: 0 0 4px;
}
.subject-subtext {
  color: var(--muted);
  font-size: 0.84rem;
}

/* Quick actions */
.quick-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ---- SECTIONS -------------------------------------------- */
.section-block { margin-bottom: 28px; }

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.section-title {
  font-size: 1rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
}
.section-title .count-tag {
  font-size: 0.72rem;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 2px 9px;
  font-weight: 600;
}

/* ---- UNIT GRID ------------------------------------------- */
.unit-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(270px, 1fr));
  gap: 12px;
}

.unit-card {
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: transform var(--transition), border-color var(--transition), box-shadow var(--transition);
  box-shadow: var(--shadow-xs);
  color: var(--text);
  position: relative;
  overflow: hidden;
  font-family: var(--font);
}
.unit-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  opacity: 0;
  transition: opacity var(--transition);
}
.unit-card:hover { border-color: var(--primary); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.unit-card:hover::before { opacity: 1; }

.unit-card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}
.unit-title {
  font-weight: 700;
  font-size: 0.9rem;
  line-height: 1.4;
}
.unit-q-badge {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 3px 9px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.progress-bar-wrap {
  height: 5px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 8px;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--ok), #34d399);
  border-radius: 999px;
  transition: width 0.4s ease;
}

.unit-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.74rem;
  color: var(--muted);
}
.unit-pct { font-weight: 700; color: var(--ok); }
.unit-pct.zero { color: var(--muted); }

/* ---- PAPER GRID ------------------------------------------ */
.year-filter-wrap { display: flex; gap: 6px; flex-wrap: wrap; }

.chip {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 5px 13px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
}
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.paper-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.paper-card {
  text-align: left;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
  box-shadow: var(--shadow-xs);
  color: var(--text);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-family: var(--font);
}
.paper-card:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); transform: translateY(-1px); }

.paper-name {
  font-weight: 600;
  font-size: 0.86rem;
  line-height: 1.35;
  color: var(--text-secondary);
}
.paper-q-badge {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---- BUTTONS --------------------------------------------- */
.btn {
  border: 1.5px solid transparent;
  border-radius: 9px;
  padding: 8px 15px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: var(--transition);
  font-family: var(--font);
  line-height: 1.4;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

.btn.primary { background: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); box-shadow: var(--shadow-sm); }

.btn.secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn.secondary:hover:not(:disabled) { background: var(--surface-hover); border-color: var(--primary); }

.btn.ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-hover); color: var(--text); }

.btn.danger { background: var(--bad-bg); color: var(--bad-text); border-color: var(--bad-border); }
.btn.amber  { background: var(--amber-bg); color: var(--amber-text); border-color: var(--amber-border); }

.btn.back-btn {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
  padding: 7px 12px;
  font-size: 0.84rem;
}

/* Bookmark button */
.btn-bookmark {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
  display: flex; align-items: center; gap: 5px;
}
.btn-bookmark:hover { border-color: var(--amber); color: var(--amber); }
.btn-bookmark.saved {
  background: var(--amber-bg);
  border-color: var(--amber-border);
  color: var(--amber-text);
}

/* ---- QUIZ VIEW ------------------------------------------- */
#view-quiz {
  max-width: 820px;
  margin: 0 auto;
}

.quiz-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.quiz-deck-title {
  flex: 1;
  font-weight: 700;
  font-size: 0.95rem;
  color: var(--text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.select-sm {
  padding: 6px 10px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  font-family: var(--font);
}

/* Progress strip */
.quiz-progress { margin-bottom: 16px; }

.progress-track {
  height: 6px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 999px;
  transition: width 0.3s ease;
}
.progress-meta {
  display: flex;
  justify-content: space-between;
  margin-top: 6px;
  font-size: 0.76rem;
  color: var(--muted);
  font-weight: 500;
}
.session-score-pill {
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 2px 10px;
  font-weight: 700;
  font-size: 0.74rem;
}

/* Passage */
.passage-card {
  background: var(--amber-bg);
  border: 1.5px solid var(--amber-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
}
.passage-toggle {
  width: 100%; background: transparent; border: none; padding: 0;
  display: flex; justify-content: space-between; align-items: center;
  font-weight: 700; font-size: 0.9rem; color: var(--amber-text);
  cursor: pointer; font-family: var(--font);
}
.passage-chip {
  font-size: 0.72rem; background: rgba(0,0,0,.08);
  padding: 2px 9px; border-radius: 999px; font-weight: 600;
}
.passage-body {
  margin-top: 10px; font-size: 0.86rem; color: var(--amber-text);
  max-height: 420px; overflow-y: auto; line-height: 1.6;
}
.passage-body p { margin: 0 0 8px; }
.passage-body .q-table-wrap { margin: 8px 0 10px; }
.passage-body .q-table td, .passage-body .q-table th { background: var(--surface); }
.passage-body.collapsed { display: none; }

/* Question card */
.question-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-md);
  margin-bottom: 14px;
}

/* Meta pills */
.q-meta { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }

.pill {
  font-size: 0.72rem; padding: 3px 10px; border-radius: 999px;
  font-weight: 600; line-height: 1.4;
}
.pill.primary { background: var(--primary-soft); color: var(--primary); }
.pill.outline { background: transparent; border: 1px solid var(--border); color: var(--muted); }
.pill.subtle  { background: var(--surface-soft); color: var(--muted); border: 1px solid var(--border); }

/* Question text */
.q-text {
  font-size: 1.05rem; line-height: 1.65; color: var(--text);
  font-family: var(--font); margin-bottom: 20px;
  font-weight: 500; overflow-wrap: break-word;
}
.q-text p { margin: 0 0 10px; }
.q-text p:last-child { margin-bottom: 0; }
.q-text .q-choose { color: var(--text-secondary); font-size: 0.95rem; font-weight: 500; margin-top: 12px; }
.q-text .q-list-head { font-weight: 700; margin-top: 8px; }
.q-items { list-style: none; margin: 8px 0 12px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.q-items li {
  display: flex; gap: 10px; align-items: baseline;
  padding: 7px 12px; border-radius: var(--radius-sm);
  background: var(--surface-soft); border: 1px solid var(--border);
}
.q-item-key { font-weight: 800; color: var(--primary); flex-shrink: 0; min-width: 22px; }
.q-match-wrap { overflow-x: auto; margin: 10px 0 12px; }
.q-match { width: 100%; border-collapse: collapse; font-size: 0.97rem; }
.q-match th {
  text-align: left; font-size: 0.82rem; font-weight: 700; color: var(--primary);
  background: var(--primary-soft); padding: 8px 12px;
}
.q-match td { padding: 8px 12px; border-top: 1px solid var(--border); vertical-align: top; }
.q-match td.mk { font-weight: 800; color: var(--primary); width: 1%; white-space: nowrap; padding-right: 4px; }
.q-match td:nth-child(3) { border-left: 1px solid var(--border); }
.q-rows {
  display: table; border-collapse: collapse; margin: 10px 0 12px;
  font-size: 0.92rem; font-variant-numeric: tabular-nums;
}
.q-row { display: table-row; }
.q-row span { display: table-cell; padding: 6px 10px; border: 1px solid var(--border); text-align: right; }
.q-row span:first-child { text-align: left; font-weight: 600; }
.q-rows .q-row:first-child span { background: var(--primary-soft); font-weight: 700; }

/* Options */
.options-list { display: flex; flex-direction: column; gap: 10px; }

.option-btn {
  width: 100%; text-align: left;
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  cursor: pointer;
  display: flex; align-items: flex-start; gap: 12px;
  font-size: 0.95rem; color: var(--text);
  transition: border-color var(--transition), background var(--transition), transform 0.08s;
  font-family: var(--font); line-height: 1.5;
}
.option-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
  transform: translateX(2px);
}
.option-btn.correct {
  background: var(--ok-bg); border-color: var(--ok-border); color: var(--ok-text);
  animation: flashCorrect 0.4s ease;
}
.option-btn.wrong {
  background: var(--bad-bg); border-color: var(--bad-border); color: var(--bad-text);
  animation: flashWrong 0.3s ease;
}

@keyframes flashCorrect {
  0%  { transform: scale(1); }
  40% { transform: scale(1.015); }
  100%{ transform: scale(1); }
}
@keyframes flashWrong {
  0%  { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
  100%{ transform: translateX(0); }
}

.option-num { font-weight: 800; min-width: 28px; font-size: 0.88rem; flex-shrink: 0; margin-top: 1px; }
.option-text { flex: 1; }
.option-icon { flex-shrink: 0; margin-top: 2px; font-size: 1rem; }

/* ---- FEEDBACK -------------------------------------------- */
.feedback-section {
  display: none; flex-direction: column; gap: 10px;
  margin-top: 14px; animation: fadeUp 0.25s ease;
}
.feedback-section.visible { display: flex; }

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

.result-banner {
  border-radius: var(--radius-sm); padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 0.94rem;
}
.result-banner.ok      { background: var(--ok-bg);    border: 1.5px solid var(--ok-border);    color: var(--ok-text); }
.result-banner.bad     { background: var(--bad-bg);   border: 1.5px solid var(--bad-border);   color: var(--bad-text); }
.result-banner.dropped { background: var(--amber-bg); border: 1.5px solid var(--amber-border); color: var(--amber-text); }
.result-icon { font-size: 1.3rem; flex-shrink: 0; }

/* Per-option explanations */
.option-explanations {
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.opt-exp-item {
  display: flex; flex-direction: column; gap: 6px; padding: 12px 15px;
  font-size: 0.88rem; line-height: 1.55;
  border-bottom: 1px solid var(--border);
}
.opt-exp-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.opt-exp-opt  { font-weight: 700; flex: 1; min-width: 0; }
.opt-exp-tags { display: flex; gap: 6px; }
.opt-exp-tag {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 999px;
  border: 1px solid var(--border); color: var(--text-secondary); opacity: .85;
}
.opt-exp-tag.ok     { border-color: var(--ok-border); color: var(--ok-text); background: var(--ok-bg); opacity: 1; }
.opt-exp-tag.chosen { border-color: var(--primary); color: var(--primary); opacity: 1; }
.opt-exp-item.is-wrong-chosen .opt-exp-tag.chosen { border-color: var(--bad-border); color: var(--bad-text); }
.opt-exp-item .opt-exp-text { padding-left: 36px; }

/* Correct answer box */
.answer-box {
  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--ok-bg); border: 1.5px solid var(--ok-border); color: var(--ok-text);
}
.answer-box:empty { display: none; }
.answer-label { font-size: 0.72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .06em; }
.answer-num   { font-weight: 800; }
.answer-text  { font-weight: 700; font-size: 1rem; }
.opt-exp-item:last-child { border-bottom: none; }
.opt-exp-item.is-correct      { background: var(--ok-bg);  color: var(--ok-text); }
.opt-exp-item.is-wrong-chosen { background: var(--bad-bg); color: var(--bad-text); }
.opt-exp-num  { font-weight: 800; min-width: 26px; flex-shrink: 0; font-size: 0.84rem; }
.opt-exp-text { flex: 1; }

/* Core concept box */
.concept-box {
  background: var(--surface-soft);
  border: 1.5px solid var(--border);
  border-left: 4px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}
.concept-box-title {
  font-size: 0.72rem; font-weight: 700; color: var(--primary);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 6px;
}
.concept-box-text {
  font-size: 0.92rem; line-height: 1.65; color: var(--text-secondary);
}
.concept-box-text p { margin: 0 0 8px; }
.concept-box-text p:last-child { margin-bottom: 0; }
.concept-box-text .exp-list { margin: 4px 0 8px; padding-left: 20px; display: flex; flex-direction: column; gap: 4px; }

/* ---- STICKY NAV ------------------------------------------ */
.sticky-nav {
  position: sticky; bottom: 12px; margin-top: 14px;
  background: rgba(255,255,255,.88);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1.5px solid var(--border);
  border-radius: var(--radius); padding: 10px 12px;
  display: flex; justify-content: space-between; align-items: center;
  gap: 8px; box-shadow: var(--shadow-md); z-index: 10;
}
html[data-theme="dark"] .sticky-nav { background: rgba(17,24,39,.9); }
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) .sticky-nav { background: rgba(17,24,39,.9); }
}

.kbd-hint {
  font-size: 0.7rem; color: var(--muted);
  font-family: var(--font-mono);
  display: flex; gap: 6px; align-items: center;
}
.kbd {
  background: var(--surface-soft); border: 1px solid var(--border);
  border-radius: 4px; padding: 1px 5px; font-size: 0.68rem;
}

/* ---- SLIDE-IN SETTINGS PANEL ----------------------------- */
.settings-panel-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 50; opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}
.settings-panel-backdrop.open { opacity: 1; pointer-events: auto; }

.settings-panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 340px; max-width: 100vw;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); z-index: 51;
  display: flex; flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(.4,0,.2,1);
}
.settings-panel.open { transform: translateX(0); }

.settings-header {
  padding: 18px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center;
}
.settings-header h2 { font-size: 1rem; font-weight: 700; }

.btn-close-panel {
  width: 30px; height: 30px; border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface-soft); color: var(--muted);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  font-size: 1rem; transition: var(--transition); font-family: var(--font);
}
.btn-close-panel:hover { background: var(--border); color: var(--text); }

.settings-body { flex: 1; overflow-y: auto; padding: 20px; }

.settings-section { margin-bottom: 24px; }
.settings-section-title {
  font-size: 0.72rem; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .06em; margin-bottom: 10px;
}

/* Theme selector in settings */
.theme-selector {
  display: flex; gap: 8px; margin-bottom: 4px;
}
.theme-opt {
  flex: 1; padding: 10px 8px; border-radius: 9px;
  border: 1.5px solid var(--border); background: var(--surface-soft);
  cursor: pointer; font-size: 0.82rem; font-weight: 600;
  color: var(--muted); text-align: center; transition: var(--transition);
  font-family: var(--font);
}
.theme-opt:hover { border-color: var(--primary); color: var(--primary); }
.theme-opt.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

.settings-stat-row {
  display: flex; justify-content: space-between;
  font-size: 0.88rem; padding: 8px 0;
  border-bottom: 1px solid var(--border);
}
.settings-stat-row:last-child { border: none; }
.settings-stat-row span:first-child { color: var(--muted); }
.settings-stat-row span:last-child { font-weight: 600; }

.settings-actions { display: flex; flex-direction: column; gap: 8px; }

.flash-msg {
  font-size: 0.82rem; color: var(--ok); font-weight: 600;
  min-height: 1.4em; margin-top: 10px; text-align: center;
}
.flash-msg.error { color: var(--bad); }

/* ---- TIMER ----------------------------------------------- */
.timer-score-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.timer-wrap {
  position: relative;
  width: 38px;
  height: 38px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.timer-ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 3;
}

.timer-ring-fill {
  fill: none;
  stroke: var(--ok);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-dasharray: 100 100;
  stroke-dashoffset: 0;
  transition: stroke-dashoffset 0.9s linear, stroke 0.4s;
}

.timer-ring-fill.zone-ok     { stroke: var(--ok); }
.timer-ring-fill.zone-warn   { stroke: var(--amber); }
.timer-ring-fill.zone-danger { stroke: var(--bad); animation: timerPulse 0.7s ease-in-out infinite; }

@keyframes timerPulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

.timer-digits {
  position: relative;
  font-size: 0.65rem;
  font-weight: 800;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  line-height: 1;
  z-index: 1;
}
.timer-digits.zone-warn   { color: var(--amber); }
.timer-digits.zone-danger { color: var(--bad); }

.timer-wrap.timer-hidden { display: none; }

/* Time-exceeded warning strip */
.timer-warning {
  background: var(--bad-bg);
  border: 1.5px solid var(--bad-border);
  color: var(--bad-text);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-size: 0.84rem;
  font-weight: 600;
  margin-bottom: 10px;
  animation: fadeUp 0.25s ease;
}

/* ---- SETTINGS TIMER CONTROLS ----------------------------- */
.settings-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  padding: 6px 0 10px;
  cursor: pointer;
  color: var(--text-secondary);
}
.settings-toggle-row input[type="checkbox"] {
  width: 18px; height: 18px; cursor: pointer; accent-color: var(--primary);
}

.timer-pace-row { padding: 4px 0 0; }
.settings-pace-label {
  font-size: 0.78rem;
  color: var(--muted);
  margin-bottom: 8px;
  display: block;
}

.pace-selector { display: flex; gap: 6px; flex-wrap: wrap; }

.pace-opt {
  padding: 7px 11px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  font-family: var(--font);
  display: flex;
  align-items: center;
  gap: 5px;
}
.pace-opt:hover  { border-color: var(--primary); color: var(--primary); }
.pace-opt.active { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }

.pace-tag {
  font-size: 0.65rem;
  font-weight: 700;
  background: var(--primary);
  color: #fff;
  border-radius: 999px;
  padding: 1px 6px;
}

/* ---- UTILS ----------------------------------------------- */
.muted { color: var(--muted); font-size: 0.86rem; }
.hidden { display: none !important; }

/* ---- RESPONSIVE ------------------------------------------ */
@media (max-width: 600px) {
  .topbar-inner { height: 52px; padding: 0 10px; gap: 8px; }
  .brand-text p { display: none; }
  .brand-text h1 { white-space: nowrap; }
  .stats-pill { display: none; }        /* solved count is on Home and the Dashboard */
  .topbar-right { gap: 6px; flex-shrink: 0; }
  .container { padding: 16px 12px 56px; }
  .hero-dashboard { padding: 15px; border-radius: var(--radius); }
  .question-card { padding: 16px; border-radius: var(--radius); }
  .q-text { font-size: 0.98rem; }
  .opt-exp-item .opt-exp-text { padding-left: 0; }
  .unit-grid { grid-template-columns: 1fr; }
  .paper-grid { grid-template-columns: 1fr; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
  .settings-panel { width: 100vw; }
  .sticky-nav { bottom: 8px; border-radius: 12px; }
  .kbd-hint { display: none; }
  .quiz-topbar { flex-wrap: wrap; }
}

/* ============================================================
   DASHBOARD
   ============================================================ */
.dash-head { display: flex; align-items: center; gap: 16px; margin: 8px 0 18px; }
.dash-title { font-size: 1.35rem; font-weight: 800; color: var(--text); }
.dash-sub { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }

.dash-filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.seg {
  display: inline-flex; background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 999px; padding: 3px; gap: 2px;
}
.seg-btn {
  border: 0; background: transparent; color: var(--muted); font: inherit; font-size: 0.84rem; font-weight: 600;
  padding: 6px 14px; border-radius: 999px; cursor: pointer; transition: background var(--transition), color var(--transition);
}
.seg-btn:hover { color: var(--text); }
.seg-btn.active { background: var(--primary); color: #fff; }
.date-pick {
  display: inline-flex; align-items: center; gap: 8px; font-size: 0.84rem; font-weight: 600; color: var(--muted);
  background: var(--surface); border: 1.5px solid var(--border); border-radius: 999px; padding: 4px 6px 4px 14px;
}
.date-pick input {
  border: 0; background: transparent; color: var(--text); font: inherit; font-size: 0.84rem; padding: 3px 6px;
  color-scheme: light dark;
}
.dash-empty {
  background: var(--amber-bg); border: 1.5px solid var(--amber-border); color: var(--amber-text);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 0.9rem; margin-bottom: 14px;
}

.dash-kpis { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 14px; }
.kpi {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 2px; box-shadow: var(--shadow-xs);
}
.kpi-val { font-size: 1.6rem; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; line-height: 1.15; }
.kpi-lab { font-size: 0.78rem; font-weight: 700; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .04em; }
.kpi-sub { font-size: 0.78rem; color: var(--muted); }

.dash-card {
  background: var(--surface); border: 1.5px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; margin-bottom: 14px; box-shadow: var(--shadow-xs);
}
.dash-card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; margin-bottom: 12px; }
.dash-card-head h3 { font-size: 0.98rem; font-weight: 700; color: var(--text); }
.dash-hint { font-size: 0.78rem; color: var(--muted); }
.dash-grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.dash-grid2 .dash-card { margin-bottom: 14px; }
.dash-note { font-size: 0.82rem; color: var(--muted); margin-top: 10px; line-height: 1.5; }

/* Daily stacked bars */
.chart-legend { display: flex; gap: 16px; align-items: center; font-size: 0.8rem; color: var(--text-secondary); margin-bottom: 8px; }
.chart-legend .lg { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: -1px; }
.lg-correct { background: var(--ok); }
.lg-wrong   { background: var(--bad); }
.chart-max { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.bar-chart {
  display: flex; align-items: flex-end; gap: 4px; height: 180px;
  border-bottom: 1px solid var(--border); padding-bottom: 0; position: relative;
}
.bar-col {
  flex: 1; min-width: 0; height: 100%; display: flex; flex-direction: column; justify-content: flex-end;
  align-items: stretch; cursor: pointer; position: relative; padding-bottom: 0;
}
.bar-col:hover { background: var(--surface-hover); border-radius: 4px 4px 0 0; }
.bar-col.dim .bar-stack { opacity: .35; }
.bar-stack {
  display: flex; flex-direction: column; gap: 2px; min-height: 0;
  margin: 0 auto; width: 100%; max-width: 28px;
}
.bar-stack > div { min-height: 2px; }
.bar-stack > div:first-child { border-radius: 4px 4px 0 0; }
.seg-correct { background: var(--ok); }
.seg-wrong   { background: var(--bad); }
.bar-lab {
  position: absolute; top: 100%; left: 50%; transform: translateX(-50%); margin-top: 4px;
  font-size: 0.68rem; color: var(--muted); white-space: nowrap;
}
#dash-daily { padding-bottom: 20px; }

/* Speed buckets */
.hbar-row {
  display: grid; grid-template-columns: 120px 1fr 40px 70px; gap: 10px; align-items: center;
  padding: 7px 4px; border-radius: 6px;
}
.hbar-row:hover { background: var(--surface-hover); }
.hbar-lab { display: flex; flex-direction: column; font-size: 0.84rem; color: var(--text); line-height: 1.25; }
.hbar-lab span { font-size: 0.72rem; color: var(--muted); }
.hbar-track { height: 10px; background: var(--surface-soft); border-radius: 0 4px 4px 0; }
.hbar-fill  { height: 100%; background: var(--primary); border-radius: 0 4px 4px 0; min-width: 2px; }
.hbar-val { font-weight: 700; font-size: 0.88rem; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }
.hbar-acc { font-size: 0.84rem; color: var(--text-secondary); text-align: right; font-variant-numeric: tabular-nums; }
.hbar-acc span { font-size: 0.72rem; color: var(--muted); }

/* Focus list */
.focus-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; }
.focus-list li {
  display: flex; align-items: center; gap: 10px; font-size: 0.86rem; color: var(--text-secondary);
  padding: 9px 10px; background: var(--surface-soft); border-radius: var(--radius-sm); line-height: 1.4;
}
.focus-list li > span:nth-child(2) { flex: 1; }
.btn-xs { padding: 4px 10px; font-size: 0.78rem; border-radius: 999px; border: 1.5px solid var(--border) !important; white-space: nowrap; }

.pill-status {
  font-size: 0.68rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em;
  padding: 2px 8px; border-radius: 999px; white-space: nowrap; flex-shrink: 0;
}
.pill-status.weak      { background: var(--bad-bg);   color: var(--bad-text);   border: 1px solid var(--bad-border); }
.pill-status.strong    { background: var(--ok-bg);    color: var(--ok-text);    border: 1px solid var(--ok-border); }
.pill-status.slow      { background: var(--amber-bg); color: var(--amber-text); border: 1px solid var(--amber-border); }
.pill-status.untouched { background: var(--surface-soft); color: var(--muted); border: 1px solid var(--border); }

/* Units table */
.table-wrap { overflow-x: auto; }
.dash-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.dash-table th {
  text-align: left; font-size: 0.72rem; font-weight: 700; color: var(--muted); text-transform: uppercase;
  letter-spacing: .04em; padding: 8px 10px; border-bottom: 1.5px solid var(--border); white-space: nowrap;
}
.dash-table td { padding: 9px 10px; border-bottom: 1px solid var(--border); color: var(--text); vertical-align: middle; }
.dash-table tr:last-child td { border-bottom: none; }
.dash-table tr.untouched td { color: var(--muted); }
.dash-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.unit-cell { display: flex; align-items: center; gap: 8px; }
.link-btn {
  border: 0; background: none; padding: 0; font: inherit; color: inherit; text-align: left; cursor: pointer;
}
.link-btn:hover { color: var(--primary); text-decoration: underline; }
.cover-cell { display: flex; align-items: center; gap: 8px; min-width: 120px; }
.cover-track { flex: 1; height: 6px; background: var(--surface-soft); border-radius: 0 3px 3px 0; }
.cover-fill  { height: 100%; background: var(--primary); border-radius: 0 3px 3px 0; }
.cover-cell span { font-size: 0.78rem; color: var(--muted); font-variant-numeric: tabular-nums; min-width: 32px; text-align: right; }

/* Tooltip */
.chart-tip {
  position: fixed; top: 0; left: 0; z-index: 50; pointer-events: none;
  background: var(--nav-bg); color: var(--nav-text); font-size: 0.8rem; line-height: 1.4;
  padding: 7px 10px; border-radius: 8px; box-shadow: var(--shadow-md); max-width: 280px;
  opacity: 0; transition: opacity .1s;
}
.chart-tip.show { opacity: 1; }

@media (max-width: 860px) {
  .dash-kpis { grid-template-columns: repeat(2, 1fr); }
  .dash-grid2 { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .hbar-row { grid-template-columns: 90px 1fr 32px 56px; }
  .seg-btn { padding: 6px 10px; }
}

/* Data tables rebuilt from question / passage text */
.q-table-wrap { overflow-x: auto; margin: 10px 0 14px; }
.q-table {
  border-collapse: collapse; font-size: 0.92rem; font-variant-numeric: tabular-nums;
  min-width: 60%; font-weight: 500;
}
.q-table th {
  background: var(--primary-soft); color: var(--text); font-weight: 700; font-size: 0.8rem;
  text-align: center; vertical-align: bottom; padding: 8px 10px; border: 1px solid var(--border);
  line-height: 1.3; min-width: 64px;
}
.q-table td { padding: 7px 12px; border: 1px solid var(--border); color: var(--text); }
.q-table td.num { text-align: right; white-space: nowrap; }
.q-table td.lbl { text-align: left; font-weight: 600; }
.q-table tbody tr:nth-child(even) td { background: var(--surface-soft); }
.q-table caption {
  caption-side: top; text-align: left; font-size: 0.82rem; font-weight: 700;
  color: var(--text-secondary); padding: 0 0 6px;
}
.q-table th.span { text-align: left; font-weight: 600; }

/* Tables never break inside words; they scroll sideways instead */
.q-table th, .q-table td, .q-match th, .q-match td { overflow-wrap: normal; word-break: normal; hyphens: manual; }
.q-table th { max-width: 220px; }

@media (max-width: 600px) {
  .q-table { font-size: 0.84rem; }
  .q-table th { font-size: 0.72rem; padding: 6px 8px; min-width: 56px; }
  .q-table td { padding: 6px 9px; }
  .q-match { font-size: 0.88rem; }
  .q-match td { padding: 7px 8px; }
  .q-match td.mk { padding-right: 2px; }

  /* Dashboard: keep the essentials, drop secondary columns */
  .dash-head { margin: 4px 0 12px; }
  .dash-filters { gap: 8px; }
  .dash-card { padding: 14px; }
  .dash-table th:nth-child(4), .dash-table td:nth-child(4),
  .dash-table th:nth-child(5), .dash-table td:nth-child(5),
  .dash-table th:nth-child(6), .dash-table td:nth-child(6) { display: none; }
  .dash-table td, .dash-table th { padding: 8px 6px; }
  .dash-table tr.untouched .pill-status.untouched { display: none; }
  .dash-card-head { flex-wrap: wrap; }
  .focus-list li { flex-wrap: wrap; }
  .focus-list li > span:nth-child(2) { flex-basis: 100%; order: 3; }
  .focus-list li .btn-xs { margin-left: auto; }
  .kpi-val { font-size: 1.35rem; }
}
@media (max-width: 600px) {
  .dash-table { font-size: 0.82rem; }
  .dash-table th { font-size: 0.62rem; letter-spacing: 0; }
  .dash-table td.num, .dash-table th.num { padding-left: 4px; padding-right: 4px; }
  .dash-table .btn-xs { padding: 3px 8px; }
}
