/* ACCA FA Quiz Tracker — custom palette (colorhunt.co/palette/222831393e4600adb5eeeeee)
   Dark: #222831 / #393E46 / #00ADB5 / #EEEEEE — Light: teal-accented companion, derived. */
:root{
  --base:#393E46; --mantle:#222831; --crust:#1a1e24;
  --surface0:#454b54; --surface1:#525960; --surface2:#656d76;
  --text:#EEEEEE; --subtext1:#cbced1; --subtext0:#a9adb0;
  --overlay1:#82868a; --overlay0:#696d70;
  --blue:#5dade2; --lavender:#3fc6ce; --sapphire:#5dade2; --sky:#5dade2;
  --green:#3ddc84; --teal:#00adb5; --yellow:#ffc94d; --peach:#f2a65a;
  --red:#ff6b6b; --maroon:#e05a5a; --mauve:#00adb5; --pink:#f2a65a;
  --mauve-rgb:0,173,181; --red-rgb:255,107,107; --green-rgb:61,220,132;
  --yellow-rgb:255,201,77; --blue-rgb:93,173,226;
  --radius:12px; --radius-sm:8px;
  --shadow: 0 4px 16px rgba(0,0,0,.35);
  --shadow-rgb: 0,0,0;
  --scheme: dark;
  --sidebar-w: 230px;
  --topbar-h: 56px;
}
[data-theme="light"]{
  --base:#eeeeee; --mantle:#e4e7e8; --crust:#dadddf;
  --surface0:#d2d5d7; --surface1:#bfc3c5; --surface2:#a9aeb1;
  --text:#20242a; --subtext1:#3c4148; --subtext0:#565c63;
  --overlay1:#7a8086; --overlay0:#93989d;
  --blue:#1b6fa8; --lavender:#0090a0; --sapphire:#1b6fa8; --sky:#1b6fa8;
  --green:#2e9e5b; --teal:#008e94; --yellow:#b8790a; --peach:#d9812e;
  --red:#d93030; --maroon:#c0392b; --mauve:#00838a; --pink:#d9812e;
  --mauve-rgb:0,131,138; --red-rgb:217,48,48; --green-rgb:46,158,91;
  --yellow-rgb:184,121,10; --blue-rgb:27,111,168;
  --shadow: 0 4px 16px rgba(34,40,49,.14);
  --shadow-rgb: 34,40,49;
  --scheme: light;
}
html{ color-scheme: var(--scheme); }
*{box-sizing:border-box;}
html,body{margin:0;padding:0;}
body{
  background:var(--base); color:var(--text);
  font-family:'Inter',-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,Arial,sans-serif;
  font-size:15px; line-height:1.55;
  min-height:100vh;
  -webkit-text-size-adjust:100%;
}
body.no-scroll{ overflow:hidden; }
.icon{ display:block; flex-shrink:0; }
[class*="icon-"] svg{ stroke: currentColor; }
b,strong{color:var(--yellow);}
code{background:var(--surface0); padding:1px 6px; border-radius:5px; font-size:.9em; color:var(--teal); word-break:break-word;}
a{color:var(--blue);}
img,svg{ max-width:100%; }
::-webkit-scrollbar{width:10px; height:10px;}
::-webkit-scrollbar-track{background:var(--mantle);}
::-webkit-scrollbar-thumb{background:var(--surface2); border-radius:5px;}

/* ===== Mobile top bar (hidden on desktop) ===== */
.mobile-topbar{
  display:none;
  position:sticky; top:0; left:0; right:0; z-index:60;
  height:var(--topbar-h); padding:0 12px;
  background:var(--mantle); border-bottom:1px solid var(--surface0);
  align-items:center; gap:12px;
  backdrop-filter:saturate(180%) blur(6px);
}
.mobile-brand{ display:flex; align-items:center; gap:9px; min-width:0; }
.mobile-brand .logo{
  width:30px; height:30px; border-radius:8px;
  background:linear-gradient(135deg,var(--mauve),var(--blue));
  display:flex; align-items:center; justify-content:center; flex-shrink:0;
}
.mobile-brand-title{
  font-weight:700; font-size:14.5px; color:var(--text);
  white-space:nowrap; overflow:hidden; text-overflow:ellipsis;
}

/* Hamburger button */
.hamburger-btn{
  width:42px; height:42px; padding:0; border:1px solid var(--surface1);
  background:var(--surface0); color:var(--text);
  border-radius:var(--radius-sm); cursor:pointer;
  display:inline-flex; align-items:center; justify-content:center; flex-shrink:0;
  transition:background .12s, border-color .12s;
}
.hamburger-btn:hover{ background:var(--surface1); }
.hamburger-btn:active{ transform:scale(.96); }
.hamburger-box{ width:22px; height:16px; position:relative; display:inline-block; }
.hamburger-line{
  position:absolute; left:0; right:0; height:2px; border-radius:2px;
  background:var(--text); transition:transform .3s cubic-bezier(.16,1,.3,1), opacity .2s, top .3s;
}
.hamburger-line:nth-child(1){ top:0; }
.hamburger-line:nth-child(2){ top:7px; }
.hamburger-line:nth-child(3){ top:14px; }
.hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(1){ top:7px; transform:rotate(45deg); }
.hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(2){ opacity:0; }
.hamburger-btn[aria-expanded="true"] .hamburger-line:nth-child(3){ top:7px; transform:rotate(-45deg); }

/* Sidebar close (X) button — visible only on mobile */
.sidebar-close-btn{
  display:none; margin-left:auto; width:34px; height:34px; padding:0;
  background:transparent; border:none; color:var(--subtext0); cursor:pointer;
  border-radius:var(--radius-sm); align-items:center; justify-content:center;
  transition:background .12s, color .12s;
}
.sidebar-close-btn:hover{ background:var(--surface0); color:var(--text); }

/* Backdrop for mobile sidebar */
.sidebar-backdrop{
  display:none; position:fixed; inset:0; z-index:70;
  background:rgba(0,0,0,.55); backdrop-filter:blur(2px);
  opacity:0; transition:opacity .25s;
}
.sidebar-backdrop.show{ display:block; opacity:1; }

/* ===== App shell ===== */
#app{ display:flex; min-height:100vh; }

/* Sidebar (desktop) */
#sidebar{
  width:var(--sidebar-w); flex-shrink:0; background:var(--mantle);
  border-right:1px solid var(--surface0);
  display:flex; flex-direction:column; padding:18px 12px;
  position:sticky; top:0; height:100vh; overflow-y:auto;
  z-index:80;
  transition:transform .3s cubic-bezier(.16,1,.3,1);
}
#sidebar .brand{
  display:flex; align-items:center; gap:10px; padding:8px 10px 20px 10px;
}
#sidebar .brand .logo{
  width:34px; height:34px; border-radius:9px;
  background:linear-gradient(135deg,var(--mauve),var(--blue));
  display:flex; align-items:center; justify-content:center;
  font-size:18px; flex-shrink:0;
}
#sidebar .brand .title{ font-weight:700; font-size:14.5px; color:var(--text); line-height:1.25; }
#sidebar .brand .subtitle{ font-size:11px; color:var(--overlay1); }

.nav-item{
  display:flex; align-items:center; gap:10px;
  padding:10px 12px; border-radius:var(--radius-sm);
  color:var(--subtext1); cursor:pointer; font-size:14px; font-weight:500;
  margin-bottom:3px; user-select:none;
  border:1px solid transparent;
  transition:background .12s, color .12s;
}
.nav-item .ic{ font-size:16px; width:20px; text-align:center; }
.nav-item:hover{ background:var(--surface0); color:var(--text); }
.nav-item.active{ background:var(--surface0); color:var(--lavender); border-color:var(--surface1); }
.nav-item .badge{
  margin-left:auto; background:var(--red); color:var(--crust);
  font-size:10.5px; font-weight:700; padding:1px 7px; border-radius:20px;
}
.nav-sep{ height:1px; background:var(--surface0); margin:12px 4px; }
#sidebar .foot{ margin-top:auto; padding:10px; font-size:11px; color:var(--overlay0); }
#persist-status{
  display:flex; align-items:center; gap:7px; margin:0 10px 10px 10px;
  padding:7px 9px; border-radius:var(--radius-sm); background:var(--surface0);
  font-size:11px; color:var(--subtext0); cursor:default;
}
#persist-status .dot{ width:7px; height:7px; border-radius:50%; flex:none; }
#persist-status .dot-ok{ background:var(--green); box-shadow:0 0 0 3px rgba(var(--green-rgb),.18); }
#persist-status .dot-warn{ background:var(--yellow); box-shadow:0 0 0 3px rgba(var(--yellow-rgb),.18); }
#main.boot-loading{ opacity:.45; pointer-events:none; transition:opacity .15s; }

/* Main content */
#main{ flex:1; min-width:0; padding:28px 34px 60px 34px; max-width:1180px; }
.page-title{ display:flex; align-items:center; gap:10px; font-size:22px; font-weight:800; margin:0 0 4px 0; color:var(--text); letter-spacing:-.01em; }
.page-title .icon{ color:var(--mauve); }
.page-sub{ font-size:13.5px; color:var(--subtext0); margin:0 0 24px 0; }

/* ===== Cards / grid ===== */
.card{
  background:var(--mantle); border:1px solid var(--surface0);
  border-radius:var(--radius); padding:18px 20px;
  box-shadow:0 1px 0 rgba(255,255,255,.02) inset, 0 6px 16px rgba(var(--shadow-rgb),.12);
}
.nav-item{ cursor:pointer; }
.grid{ display:grid; gap:16px; }
.grid-4{ grid-template-columns:repeat(4,1fr); }
.grid-2{ grid-template-columns:repeat(2,1fr); }
.grid-sections{ grid-template-columns:repeat(auto-fill,minmax(240px,1fr)); }

.stat-card{ display:flex; flex-direction:column; gap:6px; }
.stat-card .stat-label{ font-size:12px; color:var(--subtext0); font-weight:600; text-transform:uppercase; letter-spacing:.03em; }
.stat-card .stat-value{ font-size:30px; font-weight:800; color:var(--text); font-variant-numeric:tabular-nums; letter-spacing:-.02em; }
.stat-card .stat-delta{ font-size:12.5px; font-weight:600; }
.stat-delta.up{ color:var(--green); }
.stat-delta.down{ color:var(--red); }
.stat-delta.flat{ color:var(--overlay1); }

/* Section mastery bars */
.mastery-row{ display:flex; align-items:center; gap:12px; padding:9px 0; border-bottom:1px solid var(--surface0); }
.mastery-row:last-child{ border-bottom:none; }
.mastery-name{ width:230px; flex-shrink:0; font-size:13.5px; font-weight:600; color:var(--text); }
.mastery-track{ flex:1; height:9px; background:var(--surface0); border-radius:6px; overflow:hidden; min-width:60px; }
.mastery-fill{ height:100%; border-radius:6px; transition:width 1s cubic-bezier(.16,1,.3,1); }
.mastery-pct{ width:52px; text-align:right; font-size:13px; font-weight:700; flex-shrink:0; }
.dot{ width:9px; height:9px; border-radius:50%; flex-shrink:0; }
.fill-strong,.dot-strong{ background:var(--green); }
.fill-medium,.dot-medium{ background:var(--yellow); }
.fill-weak,.dot-weak{ background:var(--red); }
.fill-new,.dot-new{ background:var(--blue); }
.txt-strong{ color:var(--green); } .txt-medium{ color:var(--yellow); } .txt-weak{ color:var(--red); } .txt-new{ color:var(--blue); }

/* Trend chart */
.trend-wrap{ display:flex; align-items:flex-end; gap:6px; height:120px; padding-top:10px; }
.trend-bar-col{ flex:1; display:flex; flex-direction:column; align-items:center; gap:5px; height:100%; justify-content:flex-end; min-width:0; }
.trend-bar{ width:100%; max-width:26px; border-radius:4px 4px 2px 2px; background:var(--surface1); min-height:3px; position:relative; }
.trend-bar.has-data{ background:linear-gradient(180deg,var(--mauve),var(--blue)); }
.trend-label{ font-size:9.5px; color:var(--overlay1); }
.trend-bar-col:hover .trend-bar{ outline:2px solid var(--lavender); }

/* ===== Section picker cards ===== */
.sec-card{
  background:var(--mantle); border:1px solid var(--surface0); border-radius:var(--radius);
  padding:16px 18px; cursor:pointer; transition:border-color .15s, transform .15s, box-shadow .15s;
  min-width:0;
}
.sec-card:hover{ border-color:var(--mauve); transform:translateY(-2px); box-shadow:0 8px 20px rgba(var(--shadow-rgb),.18); }
.sec-card:active{ transform:translateY(0); }
.sec-card.special{ background:linear-gradient(135deg, rgba(var(--red-rgb),.10), rgba(var(--mauve-rgb),.07)); }
.sec-card .sc-top{ display:flex; justify-content:space-between; align-items:center; margin-bottom:10px; gap:10px; }
.sec-card .sc-icon{ width:34px; height:34px; border-radius:9px; display:flex; align-items:center; justify-content:center; background:var(--surface0); flex-shrink:0; }
.sec-card .sc-name{ font-weight:700; font-size:14.5px; color:var(--text); }
.sec-card .sc-count{ font-size:12px; color:var(--subtext0); margin-top:6px; }
.sec-card .sc-pct{ font-size:17px; font-weight:800; font-variant-numeric:tabular-nums; }
.sec-card .sc-uz{ font-size:12px; color:var(--overlay1); margin-top:3px; }
.icon-strong{ color:var(--green); } .icon-medium{ color:var(--yellow); } .icon-weak{ color:var(--red); } .icon-new{ color:var(--blue); }

/* ===== Buttons / inputs ===== */
.btn{
  display:inline-flex; align-items:center; gap:7px; justify-content:center;
  background:var(--surface0); color:var(--text); border:1px solid var(--surface1);
  padding:9px 16px; border-radius:var(--radius-sm); font-size:13.5px; font-weight:600;
  cursor:pointer; transition:background .12s, border-color .12s, transform .1s, box-shadow .12s;
  min-height:40px;
}
.btn:hover{ background:var(--surface1); }
.btn:active{ transform:scale(.97); }
.btn-primary{ background:var(--mauve); color:var(--crust); border-color:var(--mauve); box-shadow:0 2px 10px rgba(var(--mauve-rgb),.25); }
.btn-primary:hover{ background:var(--lavender); box-shadow:0 4px 14px rgba(var(--mauve-rgb),.35); }
.btn-danger{ background:transparent; color:var(--red); border-color:var(--red); }
.btn-danger:hover{ background:rgba(var(--red-rgb),.12); }
.btn-sm{ padding:6px 12px; font-size:12.5px; min-height:34px; }
.btn:disabled{ opacity:.45; cursor:not-allowed; transform:none; }
.btn:focus-visible, .nav-item:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, .sec-card:focus-visible, .hamburger-btn:focus-visible{
  outline:2px solid var(--mauve); outline-offset:2px;
}
select, input[type=number], input[type=text], textarea{
  background:var(--surface0); border:1px solid var(--surface1); color:var(--text);
  padding:9px 12px; border-radius:var(--radius-sm); font-size:14px; font-family:inherit;
  max-width:100%;
}
textarea{ width:100%; resize:vertical; min-height:220px; line-height:1.5; }
label{ font-size:12.5px; color:var(--subtext0); font-weight:600; }

/* ===== Quiz ===== */
.quiz-header{ display:flex; justify-content:space-between; align-items:center; margin-bottom:18px; flex-wrap:wrap; gap:10px; }
.q-block{
  background:var(--mantle); border:1px solid var(--surface0); border-radius:var(--radius);
  padding:18px 20px; margin-bottom:14px;
}
.q-block.correct{ border-color:var(--green); background:rgba(var(--green-rgb),.06); }
.q-block.wrong{ border-color:var(--red); background:rgba(var(--red-rgb),.06); }
.q-num{ font-size:11.5px; font-weight:700; color:var(--overlay1); text-transform:uppercase; letter-spacing:.04em; margin-bottom:6px; }
.q-text{ font-size:14.5px; font-weight:600; color:var(--text); margin-bottom:12px; overflow-wrap:break-word; }
.q-opt{
  display:flex; align-items:center; gap:11px; padding:11px 12px; border-radius:var(--radius-sm);
  border:1px solid var(--surface1); margin-bottom:7px; cursor:pointer; font-size:14px;
  transition:background .12s, border-color .12s;
  overflow-wrap:break-word;
}
.q-opt > span, .q-opt label{ min-width:0; flex:1; }
.q-opt:hover{ background:var(--surface0); border-color:var(--overlay0); }
.q-opt.was-correct{ border-color:var(--green); background:rgba(var(--green-rgb),.1); }
.q-opt.was-wrong{ border-color:var(--red); background:rgba(var(--red-rgb),.1); }

/* Custom-styled radio/checkbox — replaces the browser-default control (which renders
   in the OS accent blue and clashes with the theme) with a themed indicator. */
.q-opt input[type="radio"], .q-opt input[type="checkbox"],
input[type="radio"], input[type="checkbox"]{
  appearance:none; -webkit-appearance:none; margin:0; flex-shrink:0; position:relative;
  width:20px; height:20px; border:2px solid var(--surface2); background:var(--surface0);
  cursor:pointer; transition:border-color .15s, background .15s;
}
input[type="radio"]{ border-radius:50%; }
input[type="checkbox"]{ border-radius:5px; }
input[type="radio"]:hover, input[type="checkbox"]:hover{ border-color:var(--mauve); }
input[type="radio"]:checked, input[type="checkbox"]:checked{ border-color:var(--mauve); background:var(--mauve); }
input[type="radio"]:checked::after{
  content:""; position:absolute; inset:5px; border-radius:50%; background:var(--crust);
}
input[type="checkbox"]:checked::after{
  content:""; position:absolute; left:5px; top:2px; width:6px; height:10px;
  border:solid var(--crust); border-width:0 2px 2px 0; transform:rotate(45deg);
}
input[type="radio"]:disabled, input[type="checkbox"]:disabled{ cursor:default; opacity:.85; }
.q-explain{
  margin-top:10px; padding:11px 13px; background:var(--surface0); border-radius:var(--radius-sm);
  font-size:13px; color:var(--subtext1); border-left:3px solid var(--mauve); display:none;
  overflow-wrap:break-word;
}
.q-explain.show{ display:block; }
.q-result-icon{ display:inline-flex; align-items:center; gap:3px; font-weight:800; font-size:13px; margin-left:8px; vertical-align:middle; }
.q-result-icon.ok{ color:var(--green); } .q-result-icon.no{ color:var(--red); }
.tf-row{ display:flex; gap:10px; flex-wrap:wrap; }
.tf-row .q-opt{ flex:1 1 120px; justify-content:center; text-align:center; }

.score-banner{
  padding:20px 24px; border-radius:var(--radius); margin-bottom:18px; text-align:center;
  background:linear-gradient(135deg, rgba(var(--mauve-rgb),.15), rgba(var(--blue-rgb),.1));
  border:1px solid var(--surface0);
}
.score-banner .big{ font-size:34px; font-weight:800; }
.score-banner .lbl{ font-size:13px; color:var(--subtext0); margin-top:4px; }

/* ===== Mistakes table ===== */
.mistake-row{
  display:flex; align-items:center; gap:12px; padding:12px 14px; border-radius:var(--radius-sm);
  background:var(--mantle); border:1px solid var(--surface0); margin-bottom:8px;
  flex-wrap:wrap;
}
.mistake-row .mr-sec{ font-size:10.5px; font-weight:700; color:var(--crust); background:var(--peach); padding:2px 8px; border-radius:20px; flex-shrink:0; }
.mistake-row .mr-q{ flex:1 1 200px; font-size:13px; color:var(--text); min-width:0; overflow-wrap:break-word; }
.mistake-row .mr-count{ font-size:12px; color:var(--red); font-weight:700; flex-shrink:0; }
.mistake-row .mr-date{ font-size:11px; color:var(--overlay1); flex-shrink:0; width:90px; text-align:right; }

/* ===== Import / parse review ===== */
.import-item{
  background:var(--mantle); border:1px solid var(--surface0); border-radius:var(--radius-sm);
  padding:12px 14px; margin-bottom:8px;
}
.import-item .ii-top{ display:flex; justify-content:space-between; gap:10px; align-items:flex-start; flex-wrap:wrap; }
.import-item .ii-q{ font-size:13px; color:var(--text); flex:1 1 200px; min-width:0; overflow-wrap:break-word; }
.import-item select{ flex-shrink:0; }
.chip{ display:inline-block; font-size:11px; font-weight:700; padding:2px 9px; border-radius:20px; }
.chip-ok{ background:rgba(var(--green-rgb),.18); color:var(--green); }
.chip-bad{ background:rgba(var(--red-rgb),.18); color:var(--red); }
.chip-unsure{ background:rgba(var(--yellow-rgb),.18); color:var(--yellow); }

.helpbox{
  background:var(--surface0); border-radius:var(--radius-sm); padding:14px 16px; font-size:13px;
  color:var(--subtext1); margin-bottom:16px; border-left:3px solid var(--sapphire);
  overflow-wrap:break-word;
}
.helpbox ol,.helpbox ul{ margin:8px 0 0 0; padding-left:20px; }
.helpbox li{ margin-bottom:4px; }

.empty-state{ text-align:center; padding:50px 20px; color:var(--overlay1); }
.empty-state .icon{ margin:0 auto 12px auto; color:var(--green); }

.toast{
  position:fixed; bottom:22px; right:22px; left:auto;
  max-width:calc(100vw - 44px);
  background:var(--surface0); border:1px solid var(--mauve);
  color:var(--text); padding:12px 18px; border-radius:var(--radius-sm); box-shadow:var(--shadow);
  font-size:13.5px; z-index:999; opacity:0; transform:translateY(8px); transition:all .25s;
  pointer-events:none;
}
.toast.show{ opacity:1; transform:translateY(0); }

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

.hr{ height:1px; background:var(--surface0); margin:20px 0; }
.flex-between{ display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:8px; }
.small-muted{ font-size:12px; color:var(--overlay1); }

/* ===== Animations ===== */
@keyframes fadeInUp{ from{ opacity:0; transform:translateY(10px); } to{ opacity:1; transform:translateY(0); } }
.fade-in-up{ animation:fadeInUp .5s cubic-bezier(.16,1,.3,1) both; }
.stagger > *{ animation:fadeInUp .45s cubic-bezier(.16,1,.3,1) both; }
.stagger > *:nth-child(1){ animation-delay:.02s; } .stagger > *:nth-child(2){ animation-delay:.06s; }
.stagger > *:nth-child(3){ animation-delay:.10s; } .stagger > *:nth-child(4){ animation-delay:.14s; }
.stagger > *:nth-child(5){ animation-delay:.18s; } .stagger > *:nth-child(6){ animation-delay:.22s; }
.stagger > *:nth-child(7){ animation-delay:.26s; } .stagger > *:nth-child(8){ animation-delay:.30s; }
.stagger > *:nth-child(9){ animation-delay:.34s; } .stagger > *:nth-child(10){ animation-delay:.38s; }
.stagger > *:nth-child(n+11){ animation-delay:.40s; }

@media (prefers-reduced-motion: reduce){
  *, *::before, *::after{
    animation-duration:.01ms !important; animation-iteration-count:1 !important;
    transition-duration:.01ms !important; scroll-behavior:auto !important;
  }
}

/* ===== Chart containers ===== */
.chart-box{ position:relative; width:100%; }
.chart-box canvas{ width:100% !important; max-width:100%; }
.gauge-wrap{ position:relative; width:104px; height:104px; margin:6px auto 4px auto; }
.gauge-wrap canvas{ width:100% !important; height:100% !important; }
.gauge-center{
  position:absolute; inset:0; display:flex; align-items:center; justify-content:center;
  font-size:21px; font-weight:800; color:var(--text); font-variant-numeric:tabular-nums;
}
.stat-card:has(.gauge-wrap){ align-items:center; text-align:center; }

/* ===== AI insights card ===== */
.insight-card{
  background:linear-gradient(135deg, rgba(var(--mauve-rgb),.09), rgba(var(--blue-rgb),.05));
  border-color:var(--surface1);
}
.insight-head{ display:flex; align-items:center; gap:8px; flex-wrap:wrap; }
.insight-head .icon{ color:var(--mauve); }
.insight-recs{ margin:6px 0 0 0; padding-left:18px; font-size:13px; color:var(--subtext1); }
.insight-recs li{ margin-bottom:4px; }
.insight-empty{ border-style:dashed; }

/* ===== Collapsible secondary tool ===== */
.collapse-toggle{
  display:flex; align-items:center; gap:8px; background:none; border:none; color:var(--subtext0);
  font-size:13px; font-weight:600; cursor:pointer; padding:8px 4px; width:100%; text-align:left;
}
.collapse-toggle:hover{ color:var(--text); }
.collapse-toggle svg{ transition:transform .2s; }
.collapse-toggle.open svg{ transform:rotate(90deg); }
.collapse-body{ padding-top:4px; }

/* ===== File inputs — hidden native input + styled label button ===== */
.file-input-hidden{
  position:absolute; width:1px; height:1px; padding:0; margin:-1px; overflow:hidden;
  clip:rect(0,0,0,0); white-space:nowrap; border:0;
}
.file-field{ display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-top:4px; }
.file-btn-label{
  display:inline-flex; align-items:center; gap:7px; justify-content:center;
  background:var(--surface0); color:var(--text); border:1px solid var(--surface1);
  padding:10px 16px; border-radius:var(--radius-sm); font-size:13px; font-weight:600;
  cursor:pointer; transition:background .12s, border-color .12s, transform .1s;
  min-height:40px;
}
.file-btn-label:hover{ background:var(--surface1); }
.file-btn-label:active{ transform:scale(.97); }
.file-input-hidden:focus-visible + .file-btn-label{ outline:2px solid var(--mauve); outline-offset:2px; }
.file-name-display{ font-size:12px; color:var(--subtext0); overflow-wrap:break-word; word-break:break-all; }
.file-name-display.has-file{ color:var(--green); font-weight:600; }

/* ===== Theme toggle (dark/light) ===== */
.theme-toggle{
  display:flex; align-items:center; gap:9px; padding:10px 12px; margin-bottom:8px;
  border-radius:var(--radius-sm); cursor:pointer; user-select:none; color:var(--subtext0);
  font-size:12.5px; font-weight:600; transition:background .12s;
}
.theme-toggle:hover{ background:var(--surface0); }
.theme-toggle .tt-icon{ display:flex; color:var(--overlay1); flex-shrink:0; }
.theme-toggle .tt-track{
  width:36px; height:20px; background:var(--surface1); border-radius:20px; position:relative;
  flex-shrink:0; transition:background .2s; border:1px solid var(--surface2);
}
.theme-toggle .tt-knob{
  position:absolute; top:2px; left:2px; width:14px; height:14px; border-radius:50%;
  background:var(--mauve); transition:left .2s cubic-bezier(.16,1,.3,1);
}
[data-theme="light"] .theme-toggle .tt-track{ background:var(--peach); border-color:var(--peach); }
[data-theme="light"] .theme-toggle .tt-knob{ left:18px; background:#fff; }
.theme-toggle .tt-label{ flex:1; }

/* =================================================================================
   RESPONSIVE BREAKPOINTS
   Desktop  : > 1024px  (default styles above)
   Tablet   : 769–1024px
   Mobile   : ≤ 768px   (sidebar becomes off-canvas drawer, hamburger visible)
   Small    : ≤ 480px
   ================================================================================= */

/* --- Large / Wide Tablet: 4-col → 2-col --- */
@media (max-width:1200px){
  .grid-4{ grid-template-columns:repeat(2,1fr); }
}

/* --- Tablet: compress main padding + tighter grids --- */
@media (max-width:1024px){
  :root{ --sidebar-w: 210px; }
  #main{ padding:24px 22px 50px 22px; }
  .page-title{ font-size:20px; }
  .grid-sections{ grid-template-columns:repeat(auto-fill,minmax(210px,1fr)); }
  .mastery-name{ width:170px; font-size:13px; }
}

/* --- Mobile: sidebar becomes off-canvas drawer --- */
@media (max-width:768px){
  :root{ --sidebar-w: 280px; }

  /* Show mobile top bar */
  .mobile-topbar{ display:flex; }

  /* Sidebar becomes off-canvas drawer */
  #sidebar{
    position:fixed; top:0; left:0; bottom:0; height:100vh; height:100dvh;
    width:var(--sidebar-w); max-width:86vw;
    transform:translateX(-100%);
    box-shadow:0 12px 40px rgba(0,0,0,.4);
    z-index:80;
  }
  #sidebar.open{ transform:translateX(0); }

  /* Show close-X inside drawer */
  .sidebar-close-btn{ display:inline-flex; }

  /* Reset app layout — main below topbar, sidebar overlays */
  #app{ display:block; min-height:calc(100vh - var(--topbar-h)); }

  /* Main content padding scaled down */
  #main{ padding:18px 14px 40px 14px; max-width:100%; }

  .page-title{ font-size:19px; }
  .page-sub{ font-size:13px; margin-bottom:18px; }

  /* Cards a bit tighter */
  .card{ padding:15px 15px; }

  /* Grid: everything collapses to single column on mobile */
  .grid-4, .grid-2{ grid-template-columns:1fr; }
  .grid-sections{ grid-template-columns:repeat(auto-fill,minmax(150px,1fr)); gap:12px; }

  /* Stat card compressed */
  .stat-card .stat-value{ font-size:26px; }

  /* Mastery rows — stack name over track on very tight width */
  .mastery-row{ gap:10px; }
  .mastery-name{ width:120px; font-size:12.5px; }
  .mastery-pct{ width:44px; font-size:12.5px; }

  /* Trend chart shrink */
  .trend-wrap{ height:100px; gap:4px; }
  .trend-bar{ max-width:20px; }
  .trend-label{ font-size:9px; }

  /* Section cards */
  .sec-card{ padding:14px 15px; }
  .sec-card .sc-name{ font-size:14px; }
  .sec-card .sc-pct{ font-size:16px; }
  .sec-card .sc-icon{ width:30px; height:30px; }

  /* Quiz */
  .q-block{ padding:15px 15px; }
  .q-text{ font-size:14px; }
  .q-opt{ padding:12px 12px; font-size:13.5px; }
  .quiz-header{ margin-bottom:14px; }

  /* Score banner */
  .score-banner{ padding:16px 16px; }
  .score-banner .big{ font-size:28px; }

  /* Mistakes — allow multi-line */
  .mistake-row{ padding:11px 12px; gap:8px; }
  .mistake-row .mr-date{ width:auto; text-align:left; }

  /* Buttons a bit bigger touch target on mobile */
  .btn{ padding:11px 16px; font-size:14px; min-height:44px; }
  .btn-sm{ padding:8px 12px; font-size:13px; min-height:36px; }
  .file-btn-label{ padding:11px 16px; min-height:44px; }

  /* Toast full-width bottom on mobile */
  .toast{
    left:12px; right:12px; bottom:12px; max-width:none;
    text-align:center;
  }

  /* Larger checkboxes/radios for touch */
  .q-opt input[type="radio"], .q-opt input[type="checkbox"],
  input[type="radio"], input[type="checkbox"]{
    width:22px; height:22px;
  }
  input[type="radio"]:checked::after{ inset:5px; }
  input[type="checkbox"]:checked::after{ left:6px; top:3px; width:6px; height:10px; }

  /* Textareas smaller minimum on mobile */
  textarea{ min-height:180px; }

  /* Gauge slightly smaller */
  .gauge-wrap{ width:96px; height:96px; }
  .gauge-center{ font-size:19px; }
}

/* --- Small phones (≤ 480px) --- */
@media (max-width:480px){
  body{ font-size:14.5px; }
  #main{ padding:14px 12px 32px 12px; }
  .page-title{ font-size:17.5px; }

  .card{ padding:13px 13px; border-radius:10px; }

  /* Section grid to single row of pairs */
  .grid-sections{ grid-template-columns:repeat(2,minmax(0,1fr)); gap:10px; }
  .sec-card{ padding:12px 12px; }
  .sec-card .sc-top{ margin-bottom:8px; }
  .sec-card .sc-icon{ width:28px; height:28px; }
  .sec-card .sc-name{ font-size:13px; }
  .sec-card .sc-uz{ font-size:11px; }

  /* Mastery — name on top, bar+% below */
  .mastery-row{ flex-wrap:wrap; padding:10px 0; }
  .mastery-row .dot{ order:1; }
  .mastery-name{ order:2; flex:1 1 auto; width:auto; }
  .mastery-pct{ order:3; width:auto; }
  .mastery-track{ order:4; flex-basis:100%; height:8px; }

  /* Score */
  .score-banner{ padding:14px 12px; }
  .score-banner .big{ font-size:24px; }

  /* Quiz options: True/False stacked */
  .tf-row{ flex-direction:column; }
  .tf-row .q-opt{ flex:1 1 auto; }

  /* Trend labels get busy — hide alternating */
  .trend-wrap{ height:90px; }
  .trend-bar{ max-width:16px; }
  .trend-bar-col:nth-child(even) .trend-label{ display:none; }

  /* Mistake row: date/count wrap under */
  .mistake-row{ flex-direction:column; align-items:flex-start; gap:6px; }
  .mistake-row .mr-count, .mistake-row .mr-date{ font-size:11px; }

  /* Import item */
  .import-item .ii-top{ flex-direction:column; }
  .import-item select{ width:100%; }

  /* Buttons full width when needed */
  .btn.btn-block-sm{ width:100%; }

  /* Mobile brand title truncates already */
  .mobile-brand-title{ font-size:13.5px; }
  .mobile-topbar{ padding:0 10px; gap:8px; }
  .hamburger-btn{ width:40px; height:40px; }

  /* Sidebar drawer takes more room on very tight screens */
  :root{ --sidebar-w: 260px; }
}

/* --- Very small (≤ 360px) --- */
@media (max-width:360px){
  .grid-sections{ grid-template-columns:1fr; }
  .stat-card .stat-value{ font-size:22px; }
  #main{ padding:12px 10px 28px 10px; }
}

/* --- Landscape phones: reduce vertical paddings --- */
@media (max-width:900px) and (orientation:landscape) and (max-height:500px){
  #main{ padding-top:12px; padding-bottom:24px; }
  .mobile-topbar{ height:48px; }
  :root{ --topbar-h: 48px; }
}

/* --- Print (bonus: clean print of quiz results) --- */
@media print{
  .mobile-topbar, #sidebar, .sidebar-backdrop, .theme-toggle, .btn, .hamburger-btn{ display:none !important; }
  #app{ display:block; }
  #main{ padding:0; max-width:100%; }
  body{ background:white; color:black; }
  .card, .q-block{ break-inside:avoid; border-color:#999; }
}
