/* ============================================================
   TradePass — "Engineer's Blueprint" redesign
   Schematic-inspired: blueprint navy, faint engineering grid,
   monospaced numerals, a single copper "live conductor" accent.
   All class/id hooks from index.html + app.js are preserved.
   ============================================================ */

:root {
  /* Canvas */
  --bg:        #0b1a2b;   /* blueprint navy */
  --bg-2:      #081320;   /* darker floor / inputs */

  /* Surfaces */
  --panel:     #10243a;   /* card surface */
  --panel-2:   #16314c;   /* raised chips, letters */
  --panel-3:   #1b3a5a;   /* hover lift */

  /* Lines & grid */
  --line:      #244b6e;   /* primary borders */
  --line-soft: #1a3554;   /* hairlines / dividers */
  --grid:      rgba(120,170,220,.05); /* blueprint grid ink */

  /* Text — high contrast (the key fix) */
  --text:      #eaf2fb;   /* primary */
  --muted:     #9db8d4;   /* secondary — ~6.3:1 on --panel */
  --faint:     #6f8fb0;   /* tertiary — sparingly */

  /* Accent — copper / live-conductor amber */
  --accent:    #ff9f1c;
  --accent-ink:#1b1205;
  --accent-2:  #38bdf8;   /* schematic cyan — info only */

  /* Status */
  --green:     #34d399;
  --green-ink: #04241a;
  --red:       #f87171;
  --red-ink:   #2a0606;
  --amber-warn:#fbbf24;

  /* Background radial glow (overridden per theme) */
  --glow:      #10325a;
  --topbar-bg: rgba(8,19,32,.9);   /* translucent bar */
  --overlay:   rgba(4,9,16,.72);   /* modal scrim */

  /* Geometry & type */
  --radius:    10px;
  --radius-sm: 7px;
  --space-section: 28px;
  --space-block: 16px;
  --mono: "JetBrains Mono", ui-monospace, "Cascadia Mono", "SFMono-Regular", Consolas, monospace;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

/* ----- Day (light) theme — "blueprint on paper" ----- */
:root[data-theme="light"] {
  --bg:        #eef2f7;   /* soft paper */
  --bg-2:      #ffffff;   /* inputs / wells */

  --panel:     #ffffff;   /* card surface */
  --panel-2:   #eaf0f7;   /* raised chips, letters */
  --panel-3:   #dfe8f2;   /* hover lift */

  --line:      #cdd9e6;   /* primary borders */
  --line-soft: #e2eaf2;   /* hairlines */
  --grid:      rgba(40,90,140,.05);  /* blueprint grid ink */

  --text:      #14202e;   /* primary */
  --muted:     #4a6075;   /* secondary — ~6.5:1 on white */
  --faint:     #7388a0;   /* tertiary */

  --accent:    #e07b00;   /* slightly deeper copper for contrast on light */
  --accent-ink:#ffffff;
  --accent-2:  #0a7ea4;   /* info cyan, darkened for light bg */

  --green:     #15803d;
  --green-ink: #ffffff;
  --red:       #c0392b;
  --red-ink:   #ffffff;
  --amber-warn:#b45309;

  --glow:      #d6e4f5;   /* gentle paper glow */
  --topbar-bg: rgba(255,255,255,.88);
  --overlay:   rgba(20,32,46,.5);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.65;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px),
    radial-gradient(1200px 600px at 50% -10%, var(--glow), transparent 70%);
  background-size: 32px 32px, 32px 32px, 100% 100%;
  background-attachment: fixed;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background-color .25s ease, color .25s ease;
}

/* Global focus-visible ring (accessibility) */
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px rgba(255,159,28,.35);
  border-radius: var(--radius-sm);
}
.btn.primary:focus-visible { box-shadow: 0 3px 0 #c77400, 0 0 0 3px rgba(56,189,248,.55); }
.btn.ghost:focus-visible { box-shadow: 0 0 0 3px rgba(56,189,248,.45); }

/* Mono / tabular for anything measurable */
#timer, #progress-text, .badge, .letter, .score-ring, .q-source {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

/* ============================================================
   Top bar — powered busbar
   ============================================================ */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 16px;
  padding: 12px 28px;
  background: var(--topbar-bg);
  backdrop-filter: blur(10px);
  position: sticky; top: 0; z-index: 10;
  border-bottom: 1px solid var(--line);
  box-shadow: inset 0 -1px 0 var(--line), 0 1px 0 rgba(255,159,28,.18);
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand .logo { display: inline-flex; line-height: 0; }
.brand h1 {
  margin: 0; font-size: 19px; font-weight: 700; line-height: 1;
  letter-spacing: .3px;
}
.brand p {
  margin: 2px 0 0; font-size: 11.5px; color: var(--muted);
  font-family: var(--mono); letter-spacing: .3px;
}

nav { display: flex; gap: 6px; flex-shrink: 0; }
.nav-btn {
  background: transparent; border: 1px solid transparent; color: var(--muted);
  padding: 8px 14px; border-radius: var(--radius-sm); cursor: pointer;
  font-family: var(--sans); font-size: 14px; font-weight: 500;
  transition: color .15s, background .15s, border-color .15s, box-shadow .15s;
}
.nav-btn:hover { color: var(--text); background: var(--panel-2); }
.nav-btn.active {
  color: var(--accent);
  background: rgba(255,159,28,.10);
  border: 1px solid rgba(255,159,28,.35);
  box-shadow: inset 0 -2px 0 var(--accent);
}

/* ============================================================
   Layout
   ============================================================ */
main { max-width: 1040px; margin: 0 auto; padding: 32px 20px 64px; }
.view { display: none; }
.view.active { display: block; }
.view.active > * + * { margin-top: var(--space-block); }
.view.active > h2 + .view-intro,
.view.active > h2 + .browse-controls,
.view.active > .section-title + .cards,
.view.active > .section-title + .trade-grid { margin-top: 14px; }

@media (prefers-reduced-motion: no-preference) {
  .view.active { animation: schematic-in .28s ease both; }
  @keyframes schematic-in {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: none; }
  }
}

h2 {
  margin: 0 0 14px;
  font-size: clamp(24px, 4vw, 32px); font-weight: 700; line-height: 1.15;
}
.section-title {
  margin: 26px 0 18px;
  font-size: 12px; font-weight: 600; line-height: 1;
  text-transform: uppercase; letter-spacing: 1.5px; color: var(--muted);
  display: flex; align-items: center; gap: 12px;
}
.section-title::after {
  content: ''; flex: 1; height: 1px; background: var(--line-soft);
}

/* ============================================================
   Hero
   ============================================================ */
.hero {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: clamp(24px, 5vw, 40px);
  margin-bottom: var(--space-section);
}
/* one faint circuit-corner motif, top-right, decorative */
.hero::after {
  content: "";
  position: absolute; top: -10px; right: -10px;
  width: 180px; height: 120px;
  pointer-events: none; opacity: .08;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='120' fill='none' stroke='%23ff9f1c' stroke-width='2' stroke-linejoin='miter' stroke-linecap='square'%3E%3Cpath d='M0 30 H40 L48 18 L60 42 L72 18 L84 42 L96 18 L104 30 H150 V90'/%3E%3Ccircle cx='150' cy='90' r='4' fill='%23ff9f1c' stroke='none'/%3E%3Ccircle cx='40' cy='30' r='3' fill='%23ff9f1c' stroke='none'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
}
.hero h2 { color: var(--text); position: relative; }
.hero p {
  position: relative;
  color: var(--text); font-weight: 400; line-height: 1.65;
  max-width: 56ch; margin: 0;
}
.hero p strong { color: var(--accent); font-weight: 600; }
.cta-row { display: flex; gap: 12px; margin-top: 26px; flex-wrap: wrap; }

/* Let the hero breathe on wide screens; make the gutter feel intentional */
@media (min-width: 760px) {
  .hero { padding: 44px 48px; }
  .hero h2 { font-size: clamp(28px, 4vw, 38px); }
  .hero p { font-size: 16px; }
  .hero::after { opacity: .12; }
}

/* ============================================================
   Buttons
   ============================================================ */
.btn {
  border: none; border-radius: var(--radius-sm); padding: 12px 20px;
  font-family: var(--sans); font-size: 15px; font-weight: 600; cursor: pointer;
  transition: transform .08s ease, filter .15s, box-shadow .15s, background .15s, border-color .15s;
}
.btn.primary {
  background: var(--accent); color: var(--accent-ink);
  box-shadow: 0 3px 0 #c77400;   /* tactile "throw a switch" depth */
}
.btn.primary:hover {
  filter: brightness(1.06);
  box-shadow: 0 3px 0 #c77400, 0 4px 14px rgba(255,159,28,.30);
}
.btn.primary:active { transform: translateY(2px); box-shadow: 0 1px 0 #c77400; }
.btn.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--text);
}
.btn.ghost:hover { border-color: var(--accent); background: rgba(255,159,28,.06); }
.btn.ghost:active { transform: translateY(1px); }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; transform: none; }
.btn:disabled:hover { filter: none; }

.back {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-family: var(--sans); font-size: 14px; padding: 0 0 16px;
  transition: color .15s, transform .15s;
}
.back:hover { color: var(--text); transform: translateX(-3px); }

/* ============================================================
   Bank cards
   ============================================================ */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
/* Mock-exam cards read better as a balanced 2-up grid (4 banks = clean 2x2)
   instead of auto-fill leaving a lone card in a second row. */
#mock-cards, #mock-cards-2 {
  grid-template-columns: repeat(2, 1fr);
}
@media (max-width: 680px) {
  #mock-cards, #mock-cards-2 { grid-template-columns: 1fr; }
}
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--line-soft);
  border-radius: var(--radius);
  min-height: 168px;
  padding: 22px 22px 20px;
  display: flex; flex-direction: column; gap: 12px;
}
@media (prefers-reduced-motion: no-preference) {
  .card { transition: transform .15s ease, border-color .15s, box-shadow .15s; }
}
.card:hover {
  transform: translateY(-2px);
  border-color: rgba(255,159,28,.45);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.card h4 { margin: 0; font-size: 18px; font-weight: 700; line-height: 1.2; }
.card p {
  margin: 0; flex: 1;
  color: var(--muted); font-size: 13.5px; line-height: 1.55;
}
.card .meta {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: auto; padding-top: 14px; gap: 10px;
  border-top: 1px solid var(--line-soft);
}
.badge {
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--text);
  padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 500;
  white-space: nowrap;
}
.badge::before {
  content: ''; display: inline-block;
  width: 6px; height: 6px; margin-right: 7px;
  border-radius: 50%; background: var(--accent); vertical-align: middle;
}
.card .acts { display: flex; gap: 8px; flex-shrink: 0; }
.card .acts .btn { padding: 8px 14px; font-size: 13px; letter-spacing: .2px; }
/* De-emphasise the in-card Mock CTA to secondary weight so it doesn't
   compete with the hero's solid amber primary. */
.card .acts .btn.primary {
  background: transparent; color: var(--accent);
  border: 1px solid rgba(255,159,28,.45);
  box-shadow: none;
}
.card .acts .btn.primary:hover { background: rgba(255,159,28,.10); }
.card .acts .btn.primary:active { box-shadow: none; }

/* ============================================================
   Setup form
   ============================================================ */
.setup-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 28px;
  display: flex; flex-direction: column; gap: 20px; max-width: 460px;
}
.setup-card label {
  display: flex; flex-direction: column; gap: 9px;
  font-size: 12px; font-weight: 600; color: var(--faint);
  text-transform: uppercase; letter-spacing: 1.5px;
}
.setup-card select, .setup-card input {
  background: var(--bg-2);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 12px 13px;
  font-family: var(--sans); font-size: 16px; /* 16px prevents iOS zoom */
  transition: border-color .15s, box-shadow .15s;
}
.setup-card select:hover, .setup-card input:hover,
#browse-topic:hover, #browse-search:hover { border-color: rgba(255,159,28,.40); }
.setup-card select, #browse-topic { cursor: pointer; }
#setup-count { font-family: var(--mono); font-variant-numeric: tabular-nums; }

/* Short intro line under a view heading */
.view-intro {
  color: var(--muted); max-width: 640px; margin: 0 0 14px; line-height: 1.6;
}

/* Mock-exam cards: state the fixed paper format, then a single start button */
.mock-card { min-height: 200px; }
.exam-facts {
  list-style: none; margin: 4px 0 0; padding: 14px 0 0;
  border-top: 1px solid var(--line-soft);
  display: flex; gap: 14px; flex-wrap: wrap;
}
.exam-facts li {
  display: flex; flex-direction: column; gap: 2px;
  flex: 1; min-width: 70px; align-items: flex-start;
}
.exam-facts li span {
  font-size: 10px; text-transform: uppercase; letter-spacing: .9px; color: var(--faint);
  margin-top: 3px;
}
.exam-facts li b {
  font-family: var(--mono); font-variant-numeric: tabular-nums;
  font-size: 20px; line-height: 1.1; font-weight: 700; color: var(--text);
}
.exam-facts li:last-child b { color: var(--accent); }
.mock-card .start-mock { margin-top: 16px; width: 100%; }

.setup-card select:focus, .setup-card input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255,159,28,.18);
}
.setup-card small {
  color: var(--muted); font-size: 12px;
  border-left: 2px solid var(--accent); padding-left: 10px;
}
.mock-only { display: flex; flex-direction: column; gap: 8px; }

/* ============================================================
   Quiz header — progress + timer
   ============================================================ */
.quiz-header { display: flex; align-items: center; gap: 16px; margin-bottom: 20px; }
.quiz-header .back { padding: 0; align-self: center; }
.progress-wrap { flex: 1; display: flex; align-items: center; gap: 12px; }
.progress-bar {
  flex: 1; height: 8px; background: var(--bg-2);
  border: 1px solid var(--line-soft); border-radius: 6px; overflow: hidden;
}
#progress-fill {
  position: relative; overflow: hidden;
  height: 100%; width: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 23px, rgba(0,0,0,.25) 23px 24px),
    linear-gradient(90deg, var(--accent), #ffb84d);
  transition: width .3s ease;
}
#progress-fill.full { box-shadow: 0 0 8px rgba(255,159,28,.55), 0 0 0 1px rgba(255,159,28,.4) inset; }
@media (prefers-reduced-motion: no-preference) {
  #progress-fill::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,.18), transparent);
    transform: translateX(-100%);
    animation: sheen 2.2s ease-in-out infinite;
  }
  @keyframes sheen { to { transform: translateX(100%); } }
}
#progress-text { font-size: 13px; color: var(--muted); white-space: nowrap; }

.timer {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: 18px; font-weight: 700;
  background: var(--panel); border: 1px solid var(--line);
  padding: 6px 12px; border-radius: var(--radius-sm); white-space: nowrap;
}
.timer::before {
  content: ""; width: 7px; height: 7px; border-radius: 50%;
  background: var(--green); box-shadow: 0 0 6px var(--green);
}
.timer.warn {
  color: var(--amber-warn); border-color: var(--amber-warn);
}
.timer.warn::before { background: var(--amber-warn); box-shadow: 0 0 6px var(--amber-warn); }
@media (prefers-reduced-motion: no-preference) {
  .timer.warn { animation: live-pulse 1s steps(2, end) infinite; }
  @keyframes live-pulse { 50% { box-shadow: 0 0 0 3px rgba(251,191,36,.25); } }
}

/* ============================================================
   Question card + options
   ============================================================ */
.question-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--line-soft);
  border-radius: var(--radius);
  padding: clamp(20px, 4vw, 28px);
}
.q-source {
  font-size: 12px; color: var(--faint);
  text-transform: uppercase; letter-spacing: .5px; margin-bottom: 10px;
}
.q-text {
  font-size: clamp(17px, 2.4vw, 20px); font-weight: 600; line-height: 1.5;
  color: var(--text); margin-bottom: 22px;
}
.options { display: flex; flex-direction: column; gap: 12px; }

.option {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--bg-2);
  border: 2px solid var(--line); border-radius: var(--radius);
  color: var(--text); font-family: var(--sans);
  font-size: 15.5px; font-weight: 500; line-height: 1.45;
  cursor: pointer; text-align: left; width: 100%;
}
@media (prefers-reduced-motion: no-preference) {
  .option { transition: transform .13s ease, border-color .13s, background .13s, box-shadow .13s; }
}
.option > span:last-child { flex: 1; }
.option .letter {
  width: 30px; height: 30px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--panel-2); border: 1.5px solid var(--line);
  color: var(--muted); font-size: 14px; font-weight: 700;
}

.option:hover:not(.disabled) {
  border-color: rgba(56,189,248,.55);
  background: var(--panel-3);
  transform: translateX(2px);
}

.option.selected {
  border-color: var(--accent);
  background: rgba(255,159,28,.10);
  box-shadow: inset 3px 0 0 var(--accent);
  font-weight: 600;
}
.option.selected .letter {
  background: var(--accent); border-color: var(--accent); color: var(--accent-ink);
}
@media (prefers-reduced-motion: no-preference) {
  .option.selected { animation: patch-in .18s ease; }
  @keyframes patch-in {
    from { box-shadow: inset 3px 0 0 transparent; }
    to   { box-shadow: inset 3px 0 0 var(--accent); }
  }
}

.option.correct {
  border-color: var(--green);
  background: rgba(52,211,153,.14);
  box-shadow: inset 3px 0 0 var(--green);
}
.option.correct .letter {
  background: var(--green); border-color: var(--green); color: var(--green-ink);
}
.option.incorrect {
  border-color: var(--red);
  background: rgba(248,113,113,.14);
  box-shadow: inset 3px 0 0 var(--red);
}
.option.incorrect .letter {
  background: var(--red); border-color: var(--red); color: var(--red-ink);
}
.option.disabled { cursor: default; }
.option.disabled:hover { transform: none; }

@media (prefers-reduced-motion: no-preference) {
  .option.correct { animation: conduct-on .3s ease both; }
  @keyframes conduct-on {
    0%   { box-shadow: inset 3px 0 0 var(--green); }
    40%  { box-shadow: inset 3px 0 0 var(--green), 0 0 0 3px rgba(52,211,153,.30); }
    100% { box-shadow: inset 3px 0 0 var(--green); }
  }
  .option.correct .letter { animation: letter-pop .26s ease both; }
  @keyframes letter-pop {
    0%   { transform: scale(.8); }
    60%  { transform: scale(1.12); }
    100% { transform: scale(1); }
  }
  .option.incorrect { animation: nudge .22s ease both; }
  @keyframes nudge {
    0%, 100% { transform: translateX(0); }
    25%      { transform: translateX(-3px); }
    75%      { transform: translateX(3px); }
  }
}

/* Feedback (practice reveal) */
.feedback {
  margin-top: 22px; padding: 18px 20px;
  background: var(--panel-2); border: 1px solid var(--line);
  border-left: 3px solid var(--line); border-left-width: 3px;
  border-radius: var(--radius-sm); display: none;
}
.feedback:has(.verdict.right) { border-left-color: var(--green); }
.feedback:has(.verdict.wrong) { border-left-color: var(--red); }
.feedback.show { display: block; }
@media (prefers-reduced-motion: no-preference) {
  .feedback.show { animation: trace-in .22s ease both; }
  @keyframes trace-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
  }
}
.feedback .verdict {
  font-family: var(--mono); font-weight: 700; margin-bottom: 8px;
  font-size: 14px; letter-spacing: .5px;
}
.feedback .verdict.right { color: var(--green); }
.feedback .verdict.wrong { color: var(--red); }
.feedback .expl { color: var(--muted); font-size: 14px; line-height: 1.6; }

.quiz-nav { display: flex; gap: 12px; margin-top: 24px; justify-content: space-between; }
.quiz-nav .btn { min-width: 120px; }

/* ============================================================
   Results — score ring + review
   ============================================================ */
.score-summary {
  background: var(--panel);
  border: 1px solid var(--line);
  border-top: 2px solid var(--line-soft);
  border-radius: var(--radius);
  padding: 32px 28px; text-align: center; margin-bottom: 24px;
}
.score-ring {
  position: relative; display: inline-flex;
  align-items: center; justify-content: center;
  width: 140px; height: 140px; border-radius: 50%;
  font: 700 40px/1 var(--mono); color: var(--text);
  background: radial-gradient(circle at center, var(--panel) 60%, transparent 61%);
}
.score-ring::before {
  content: ""; position: absolute; inset: -8px; border-radius: 50%; z-index: -1;
  background: conic-gradient(var(--ring-c, var(--accent)) 100%, var(--line-soft) 0);
}
.score-ring.pass { --ring-c: var(--green); color: var(--green); }
.score-ring.fail { --ring-c: var(--red); color: var(--red); }
.score-summary .sub { color: var(--muted); margin-top: 14px; }
.score-summary .sub strong {
  font-family: var(--mono); text-transform: uppercase; letter-spacing: 1px;
}
.score-summary .sub .pass, .score-summary .pass { color: var(--green); }
.score-summary .sub .fail, .score-summary .fail { color: var(--red); }

.results-review {
  display: flex; flex-direction: column; gap: 12px; margin-bottom: 24px;
}
.review-item {
  background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid var(--line); border-radius: var(--radius);
  padding: 16px;
}
.review-item.right { border-left-color: var(--green); }
.review-item.wrong { border-left-color: var(--red); }
.review-item .rq { font-weight: 600; color: var(--text); margin-bottom: 8px; line-height: 1.45; }
.review-item .ra { font-size: 14px; color: var(--muted); }
.review-item .ra b { color: var(--text); }
.review-item .rexpl { font-size: 13px; color: var(--muted); margin-top: 8px; font-style: italic; line-height: 1.55; }

/* ============================================================
   Misc
   ============================================================ */
.hidden { display: none !important; }
.foot {
  text-align: center; padding: 24px;
  color: var(--faint); font-size: 11.5px; font-family: var(--mono);
  border-top: 1px solid var(--line-soft);
}

/* ============================================================
   Responsive — down to 360px
   ============================================================ */
@media (max-width: 560px) {
  .topbar { flex-direction: column; align-items: stretch; gap: 10px; padding: 10px 14px; }
  .brand { justify-content: flex-start; }
  nav {
    gap: 6px; overflow-x: auto; -webkit-overflow-scrolling: touch;
    scrollbar-width: none; padding-bottom: 2px;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 12px, #000 calc(100% - 24px), transparent 100%);
  }
  nav::-webkit-scrollbar { display: none; }
  .nav-btn { white-space: nowrap; padding: 10px 14px; min-height: 40px; display: inline-flex; align-items: center; }

  main { padding: 16px 16px 48px; }
  .hero { padding: 24px 22px; margin-bottom: 22px; }
  .hero h2 { line-height: 1.2; }
  .hero p { margin-top: 12px; }
  .section-title { margin: 22px 0 14px; }
  .cta-row { flex-direction: column; align-items: stretch; }
  .cta-row .btn { width: 100%; text-align: center; }

  .quiz-nav { flex-wrap: wrap; }
  .quiz-nav .btn { min-width: 0; flex: 1; }
  .score-ring { width: 112px; height: 112px; font-size: 32px; }

  .trade-grid { grid-template-columns: 1fr; gap: 12px; }
  .trade-card { min-height: 0; padding: 18px; }
  .trade-icon { font-size: 30px; }

  .browse-controls { flex-direction: column; gap: 10px; }
  #browse-topic { width: 100%; }
  #browse-search, #browse-topic { font-size: 16px; min-height: 44px; }
  .browse-list { gap: 12px; }
  .browse-item { padding: 15px 16px; }
  .bi-q { font-size: 15px; }
  .browse-count { text-align: left; margin-bottom: 14px; }

  .back { padding: 8px 4px 14px; min-height: 36px; display: inline-flex; align-items: center; margin-left: -4px; }
}

/* ============================================================
   Auth area, modal, dashboard (Phase 1)
   ============================================================ */
.auth-area { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.btn-sm { padding: 7px 13px; font-size: 13px; border-radius: var(--radius-sm); }
.user-chip {
  font-family: var(--mono); font-size: 13px; color: var(--accent);
  background: rgba(255,159,28,.10); border: 1px solid rgba(255,159,28,.30);
  padding: 5px 11px; border-radius: 20px; max-width: 160px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.linklike {
  background: none; border: none; color: var(--accent); cursor: pointer;
  font: inherit; padding: 0; text-decoration: underline;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--overlay); backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  position: relative; width: 100%; max-width: 380px;
  background: var(--panel); border: 1px solid var(--line);
  border-top: 3px solid var(--accent); border-radius: var(--radius);
  padding: 26px; box-shadow: 0 20px 60px rgba(0,0,0,.5);
}
.modal h3 { margin: 0 0 18px; font-size: 20px; }
.modal-close {
  position: absolute; top: 8px; right: 8px;
  width: 40px; height: 40px;
  display: inline-flex; align-items: center; justify-content: center;
  background: none; border: none; color: var(--muted);
  font-size: 24px; line-height: 1; cursor: pointer;
  border-radius: var(--radius-sm);
}
.modal-close:hover { color: var(--text); background: var(--panel-2); }
#auth-form, #reset-form { display: flex; flex-direction: column; gap: 14px; }
#auth-form label, #reset-form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
#auth-form input, #reset-form input {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 11px 12px; border-radius: var(--radius-sm); font-size: 16px; font-family: var(--sans);
}
#auth-form input:focus, #reset-form input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,159,28,.18); }
#auth-form .btn, #reset-form .btn { margin-top: 4px; }
.auth-error {
  background: rgba(248,113,113,.12); border: 1px solid var(--red);
  color: var(--red); padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px;
}
.auth-switch { margin: 16px 0 0; font-size: 13px; color: var(--muted); text-align: center; }

/* Dashboard */
.dash-stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px,1fr)); gap: 14px; margin-bottom: 8px; }
.dash-stats .stat {
  background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 16px 18px;
  display: flex; flex-direction: column; gap: 4px;
}
.dash-stats .stat span { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--faint); }
.dash-stats .stat b { font-family: var(--mono); font-size: 26px; font-weight: 700; }
.dash-stats .stat b.pass { color: var(--green); }
.dash-stats .stat b.fail { color: var(--red); }
.dash-history { display: flex; flex-direction: column; gap: 8px; }
.hist-row {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  background: var(--panel); border: 1px solid var(--line);
  border-left: 4px solid var(--line); border-radius: var(--radius); padding: 13px 16px;
}
.hist-row.right { border-left-color: var(--green); }
.hist-row.wrong { border-left-color: var(--red); }
.hist-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.hist-mode { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--faint); }
.hist-exam { font-weight: 600; font-size: 14px; }
.hist-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; flex-shrink: 0; }
.hist-when { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.hist-score { font-family: var(--mono); font-weight: 700; font-size: 15px; }
.hist-score.pass { color: var(--green); }
.hist-score.fail { color: var(--red); }
.muted-line { color: var(--muted); padding: 14px 0; }
.dash-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 8px; padding: 40px 24px;
  background: var(--panel); border: 1px dashed var(--line); border-left: 3px solid var(--accent);
  border-radius: var(--radius); color: var(--muted); font-size: 14.5px;
}
.dash-empty::before { content: '⚡'; font-size: 30px; line-height: 1; color: var(--accent); opacity: .85; }
.dash-empty .linklike { font-weight: 600; }
@media (prefers-reduced-motion: no-preference) {
  .muted-line { animation: soft-pulse 1.4s ease-in-out infinite; }
  @keyframes soft-pulse { 0%, 100% { opacity: .55; } 50% { opacity: 1; } }
}

@media (max-width: 560px) {
  .auth-area { width: 100%; justify-content: center; gap: 10px; }
  .auth-area .btn-sm, #install-btn { min-height: 40px; padding: 9px 16px; flex: 1; max-width: 160px; }
  .user-chip { max-width: none; }
}

/* ============================================================
   Topic analytics (Phase 2)
   ============================================================ */
.topic-breakdown {
  margin-top: 22px; padding-top: 20px; border-top: 1px solid var(--line);
  text-align: left;
}
.topic-breakdown h4 { margin: 0 0 14px; font-size: 12px; text-transform: uppercase; letter-spacing: 1.5px; color: var(--faint); }
.topic-row { display: grid; grid-template-columns: 1fr 2fr auto; align-items: center; gap: 12px; margin-bottom: 9px; }
.topic-name { font-size: 13px; color: var(--text); text-align: left; }
.topic-bar { height: 8px; background: var(--bg-2); border-radius: 6px; overflow: hidden; }
.topic-fill { height: 100%; border-radius: 6px; transition: width .4s; }
.topic-fill.strong { background: var(--green); }
.topic-fill.ok { background: var(--amber-warn); }
.topic-fill.weak { background: var(--red); }
.topic-pct { font-family: var(--mono); font-size: 13px; font-weight: 700; min-width: 64px; text-align: right; }
.topic-pct small { font-weight: 400; color: var(--muted); }
.topic-pct.strong { color: var(--green); }
.topic-pct.ok { color: var(--amber-warn); }
.topic-pct.weak { color: var(--red); }
.topic-tip { margin: 14px 0 0; font-size: 14px; color: var(--muted); }
.topic-tip strong { color: var(--red); }
.topic-tip.good strong, .topic-tip.good { color: var(--green); }

.review-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.topic-tag, .reg-tag {
  font-size: 12px; padding: 4px 10px; border-radius: 20px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted);
}
.reg-tag { color: var(--accent-2); font-family: var(--mono); }

/* Dashboard weak-topic section */
.dash-topics { margin: 8px 0 8px; }

.trust-note {
  color: var(--green); font-size: 13px; font-weight: 500; margin: 0 0 24px;
  display: inline-flex; align-items: center; gap: 8px;
  background: rgba(52,211,153,.08); border: 1px solid rgba(52,211,153,.25);
  padding: 7px 12px; border-radius: 20px;
}

/* ============================================================
   Trade picker (entry screen)
   ============================================================ */
.hero-trades { text-align: center; }
.hero-trades p { margin-left: auto; margin-right: auto; }
.trade-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px;
}
.trade-card {
  text-align: left; cursor: pointer; font: inherit; color: var(--text);
  background: var(--panel); border: 1px solid var(--line);
  border-top: 2px solid var(--line-soft); border-radius: var(--radius);
  padding: 22px 22px 20px; display: flex; flex-direction: column; gap: 6px; min-height: 168px;
  transition: transform .15s, border-color .15s, box-shadow .15s;
}
.trade-card.live:hover {
  transform: translateY(-2px);
  border-color: rgba(255,159,28,.45);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.trade-card.soon { opacity: .55; cursor: not-allowed; transition: opacity .15s, border-color .15s; }
.trade-card.soon:hover { opacity: .78; border-color: var(--line); }
.trade-card.soon:hover .trade-badge.soon { border-color: var(--accent-2); color: var(--accent-2); }
.trade-icon { font-size: 34px; line-height: 1; margin-bottom: 6px; }
.trade-name { font-size: 18px; font-weight: 700; line-height: 1.2; }
.trade-tagline { font-size: 13px; color: var(--muted); flex: 1; line-height: 1.5; margin-bottom: 4px; }
.trade-badge { margin-top: auto; font-size: 12px; padding: 4px 10px; border-radius: 20px; align-self: flex-start; font-family: var(--mono); }
.trade-badge.live { background: rgba(255,159,28,.12); border: 1px solid rgba(255,159,28,.35); color: var(--accent); }
.trade-badge.live::before {
  content: ''; display: inline-block; width: 6px; height: 6px;
  margin-right: 7px; border-radius: 50%; background: var(--accent); vertical-align: middle;
}
.trade-badge.soon { background: var(--panel-2); border: 1px solid var(--line); color: var(--faint); }

/* ============================================================
   Browse / search question bank
   ============================================================ */
/* Keep search + topic filter in view while scrolling the long question list. */
.browse-controls {
  display: flex; gap: 12px; margin-bottom: 10px; flex-wrap: wrap;
  position: sticky; top: 64px; z-index: 5;
  background: var(--bg); padding: 10px 0;
  box-shadow: 0 8px 12px -8px rgba(4,9,16,.8);
}
.browse-count { position: sticky; top: 122px; z-index: 5; background: var(--bg); }
#browse-search {
  flex: 1; min-width: 220px;
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 14px; border-radius: var(--radius-sm); font-size: 15px; font-family: var(--sans);
}
#browse-search:focus, #browse-topic:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(255,159,28,.18); }
#browse-topic {
  background: var(--bg-2); border: 1px solid var(--line); color: var(--text);
  padding: 12px 14px; border-radius: var(--radius-sm); font-size: 14px;
}
.browse-count { color: var(--muted); font-size: 13px; margin: 0 0 18px; padding-top: 2px; font-family: var(--mono); }
@media (min-width: 560px) { .browse-count { text-align: right; } }
.browse-list { display: flex; flex-direction: column; gap: 14px; }
.browse-item {
  background: var(--panel); border: 1px solid var(--line);
  border-left: 3px solid var(--line); border-radius: var(--radius); padding: 18px 20px;
}
@media (prefers-reduced-motion: no-preference) {
  .browse-item { transition: border-color .15s, box-shadow .15s, transform .15s; }
}
.browse-item:hover {
  border-left-color: var(--accent);
  box-shadow: 0 6px 18px rgba(0,0,0,.30);
  transform: translateY(-1px);
}
.bi-q { font-weight: 600; font-size: 15.5px; margin-bottom: 12px; line-height: 1.5; }
.bi-a { font-size: 14px; color: var(--text); margin-bottom: 8px; padding-top: 10px; border-top: 1px solid var(--line-soft); }
.bi-a .bi-label, .bi-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--green);
  font-weight: 700; margin-right: 6px;
}
.bi-expl { font-size: 13px; color: var(--muted); line-height: 1.55; font-style: italic; margin-bottom: 12px; }
.bi-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.browse-more-wrap { text-align: center; margin-top: 18px; }

/* Browse empty state */
.browse-empty {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 6px; padding: 48px 24px;
  background: var(--panel); border: 1px dashed var(--line); border-radius: var(--radius);
  color: var(--muted);
}
.browse-empty-ico {
  font-family: var(--mono); font-size: 34px; line-height: 1;
  color: var(--accent-2); opacity: .7; margin-bottom: 4px;
}
.browse-empty-title { margin: 0; font-weight: 600; color: var(--text); font-size: 16px; }
.browse-empty-sub { margin: 0; font-size: 13.5px; color: var(--muted); }
@media (prefers-reduced-motion: no-preference) {
  .browse-empty { animation: trace-in .22s ease both; }
}

/* ============================================================
   Day / night theme toggle
   ============================================================ */
.theme-toggle {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  width: 38px; height: 38px; border-radius: 50%; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  font-size: 16px; line-height: 1; padding: 0;
  transition: background .15s, border-color .15s, transform .1s;
}
.theme-toggle:hover { border-color: var(--accent); transform: translateY(-1px); }
.theme-toggle:active { transform: translateY(0); }
/* Show moon in dark mode (offer to go light), sun in light mode. */
.theme-ico { display: none; }
:root[data-theme="dark"]  .theme-ico-moon { display: inline; }
:root[data-theme="light"] .theme-ico-sun  { display: inline; }

/* ============================================================
   Paywall / upgrade
   ============================================================ */
.plan-badge.premium {
  font-family: var(--mono); font-size: 12px; font-weight: 700;
  color: var(--accent); background: rgba(255,159,28,.12);
  border: 1px solid rgba(255,159,28,.35); padding: 5px 10px; border-radius: 20px;
}
.upgrade-card {
  max-width: 460px; margin: 10px auto 0; text-align: center;
  background: linear-gradient(135deg, var(--panel), var(--panel-2));
  border: 1px solid var(--line); border-top: 3px solid var(--accent);
  border-radius: var(--radius); padding: 32px 28px;
}
.upgrade-badge {
  display: inline-block; font-family: var(--mono); font-size: 12px; letter-spacing: 1px;
  text-transform: uppercase; color: var(--accent);
  background: rgba(255,159,28,.10); border: 1px solid rgba(255,159,28,.35);
  padding: 5px 12px; border-radius: 20px; margin-bottom: 14px;
}
.upgrade-card h2 { margin: 0 0 10px; }
.upgrade-price { margin: 6px 0 2px; }
.up-amount { font-family: var(--mono); font-size: 40px; font-weight: 700; color: var(--text); }
.up-per { color: var(--muted); font-size: 16px; }
.upgrade-sub { color: var(--muted); font-size: 14px; margin: 0 0 20px; }
.upgrade-list { list-style: none; padding: 0; margin: 0 0 24px; text-align: left; display: flex; flex-direction: column; gap: 10px; }
.upgrade-list li { position: relative; padding-left: 28px; font-size: 14px; line-height: 1.45; }
.upgrade-list li::before {
  content: '✓'; position: absolute; left: 0; top: 0;
  color: var(--green); font-weight: 700;
}
.upgrade-cta { width: 100%; font-size: 16px; padding: 14px; }
.upgrade-note { margin: 14px 0 0; font-size: 13px; color: var(--muted); min-height: 18px; }

.results-upsell {
  margin-top: 22px; padding: 18px; border-radius: var(--radius);
  background: rgba(255,159,28,.08); border: 1px solid rgba(255,159,28,.3); text-align: center;
}
.results-upsell p { margin: 0 0 12px; color: var(--text); font-size: 14px; }

/* Auth success message + forgot-password link */
.auth-ok {
  background: rgba(52,211,153,.12); border: 1px solid var(--green);
  color: var(--green); padding: 9px 12px; border-radius: var(--radius-sm); font-size: 13px;
}
.auth-forgot { margin: 12px 0 0; text-align: center; }
.auth-forgot .linklike { font-size: 13px; color: var(--muted); }
.auth-forgot .linklike:hover { color: var(--accent); }

/* Brand wordmark — amber "Pass" */
.brand h1 .brand-pass { color: var(--accent); }
