:root {
  /* Purple dark palette, tuned for eye comfort (not pure black) */
  --bg-0: #14101f;        /* app background */
  --bg-1: #1b1530;        /* panels */
  --bg-2: #221a3d;        /* cards */
  --bg-3: #2b2150;        /* raised */
  --line: #352a5e;        /* borders */
  --line-soft: #2a2247;

  --txt-0: #ece8f7;       /* primary text */
  --txt-1: #b9b2d4;       /* secondary */
  --txt-2: #8a83a8;       /* muted */

  --pri: #a779f0;         /* primary purple */
  --pri-2: #8b5cf6;       /* deeper */
  --pri-soft: rgba(167,121,240,.14);
  --accent: #f0abfc;      /* pink accent */

  --ok: #4ade80;
  --ok-soft: rgba(74,222,128,.13);
  --bad: #fb7185;
  --bad-soft: rgba(251,113,133,.13);
  --warn: #fbbf24;

  --radius: 16px;
  --radius-sm: 11px;
  --shadow: 0 12px 34px rgba(0,0,0,.35);
  --sidebar-w: 260px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, sans-serif;
  background:
    radial-gradient(1100px 600px at 12% -8%, rgba(139,92,246,.22), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(240,171,252,.10), transparent 55%),
    var(--bg-0);
  color: var(--txt-0);
  -webkit-font-smoothing: antialiased;
}

h1,h2,h3,h4 { font-family: 'Sora', sans-serif; margin: 0; line-height: 1.2; color: var(--txt-0); }
button { font-family: inherit; cursor: pointer; color: inherit; }
::selection { background: var(--pri-soft); }

#app { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--bg-1), var(--bg-0));
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 4px 6px 22px; }
.brand-mark {
  width: 42px; height: 42px; border-radius: 13px;
  background: linear-gradient(135deg, var(--pri), var(--pri-2));
  display: grid; place-items: center;
  font-family: 'Sora'; font-weight: 800; font-size: 22px; color: #fff;
  box-shadow: 0 6px 18px rgba(139,92,246,.45);
}
.brand-text { display: flex; flex-direction: column; }
.brand-name { font-family: 'Sora'; font-weight: 800; font-size: 19px; letter-spacing: .3px; }
.brand-sub { font-size: 11.5px; color: var(--txt-2); letter-spacing: .4px; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  background: transparent; border: 0; color: var(--txt-1);
  padding: 11px 13px; border-radius: var(--radius-sm);
  font-size: 14.5px; font-weight: 600; text-align: left;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: var(--pri-soft); color: var(--txt-0); }
.nav-item.active { background: var(--pri-soft); color: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.nav-ico { width: 20px; text-align: center; color: var(--pri); font-size: 15px; }

.sidebar-foot { margin-top: auto; padding-top: 18px; }
.progress-mini { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 13px; }
.progress-mini-label { font-size: 11px; color: var(--txt-2); text-transform: uppercase; letter-spacing: .7px; }
.bar { height: 8px; background: var(--bg-0); border-radius: 99px; margin: 9px 0 6px; overflow: hidden; }
.bar-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--pri-2), var(--accent)); border-radius: 99px; transition: width .5s ease; }
.progress-mini-val { font-size: 12.5px; color: var(--txt-1); font-weight: 600; }
.reset-btn { width: 100%; margin-top: 10px; background: transparent; border: 1px solid var(--line); color: var(--txt-2); padding: 8px; border-radius: 10px; font-size: 12px; transition: .15s; }
.reset-btn:hover { color: var(--bad); border-color: var(--bad); }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 14px;
  padding: 16px 30px; border-bottom: 1px solid var(--line-soft);
  position: sticky; top: 0; z-index: 20;
  background: rgba(20,16,31,.72); backdrop-filter: blur(12px);
}
.topbar-title { font-family: 'Sora'; font-weight: 700; font-size: 17px; }
.topbar-right { margin-left: auto; }
.streak { font-size: 12.5px; color: var(--txt-1); background: var(--bg-2); border: 1px solid var(--line); padding: 6px 12px; border-radius: 99px; }
.menu-toggle { display: none; background: var(--bg-2); border: 1px solid var(--line); color: var(--txt-0); width: 38px; height: 38px; border-radius: 10px; font-size: 16px; }

.content { padding: 30px; max-width: 1080px; width: 100%; margin: 0 auto; }

/* ---------- Generic cards / typography ---------- */
.card { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; }
.section-head { margin-bottom: 18px; }
.section-head h1 { font-size: 27px; }
.section-head p { color: var(--txt-1); margin: 8px 0 0; font-size: 14.5px; line-height: 1.6; max-width: 720px; }
.eyebrow { color: var(--pri); font-size: 12px; font-weight: 700; letter-spacing: 1.3px; text-transform: uppercase; }

.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-auto { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }

/* ---------- Home ---------- */
.hero {
  background:
    radial-gradient(600px 220px at 88% -30%, rgba(240,171,252,.18), transparent 60%),
    linear-gradient(135deg, var(--bg-3), var(--bg-1));
  border: 1px solid var(--line);
  border-radius: 22px; padding: 34px 32px; position: relative; overflow: hidden;
}
.hero h1 { font-size: 33px; letter-spacing: .2px; }
.hero h1 span { background: linear-gradient(90deg, var(--pri), var(--accent)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--txt-1); font-size: 15px; line-height: 1.7; max-width: 640px; margin: 14px 0 22px; }
.hero-actions { display: flex; gap: 12px; flex-wrap: wrap; }

.stat-row { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-top: 20px; }
.stat { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; }
.stat-num { font-family: 'Sora'; font-weight: 800; font-size: 26px; color: #fff; }
.stat-lbl { color: var(--txt-2); font-size: 12.5px; margin-top: 3px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 9px; justify-content: center;
  border: 1px solid transparent; border-radius: 12px;
  padding: 12px 20px; font-size: 14.5px; font-weight: 700;
  transition: transform .08s, filter .15s, background .15s, border-color .15s;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(135deg, var(--pri), var(--pri-2)); color: #fff; box-shadow: 0 8px 22px rgba(139,92,246,.4); }
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost { background: var(--bg-2); border-color: var(--line); color: var(--txt-0); }
.btn-ghost:hover { border-color: var(--pri); color: #fff; }
.btn-sm { padding: 8px 14px; font-size: 13px; border-radius: 10px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Topic cards ---------- */
.topic-card {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; cursor: pointer; transition: transform .12s, border-color .15s, background .15s;
  display: flex; flex-direction: column; gap: 10px; text-align: left; width: 100%;
}
.topic-card:hover { transform: translateY(-3px); border-color: var(--pri); background: var(--bg-3); }
.topic-ico { width: 44px; height: 44px; border-radius: 12px; background: var(--pri-soft); display: grid; place-items: center; font-size: 22px; }
.topic-card h3 { font-size: 16.5px; }
.topic-card p { color: var(--txt-2); font-size: 13px; margin: 0; line-height: 1.55; }
.topic-meta { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 6px; }
.tag { font-size: 11px; font-weight: 700; color: var(--pri); background: var(--pri-soft); padding: 4px 9px; border-radius: 99px; }
.topic-bar { height: 6px; flex: 1; background: var(--bg-0); border-radius: 99px; overflow: hidden; }
.topic-bar > div { height: 100%; background: linear-gradient(90deg, var(--pri-2), var(--accent)); border-radius: 99px; }

/* ---------- Study notes ---------- */
.notes-wrap { display: grid; grid-template-columns: 230px 1fr; gap: 22px; align-items: start; }
.toc { position: sticky; top: 86px; background: var(--bg-1); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; }
.toc-title { font-size: 11px; text-transform: uppercase; letter-spacing: .8px; color: var(--txt-2); padding: 6px 8px; }
.toc a { display: block; color: var(--txt-1); text-decoration: none; font-size: 13.5px; padding: 8px 10px; border-radius: 9px; transition: .15s; }
.toc a:hover { background: var(--pri-soft); color: #fff; }

.note-block { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; margin-bottom: 18px; scroll-margin-top: 86px; }
.diagram-frame { scroll-margin-top: 86px; }
.note-block h2 { font-size: 21px; margin-bottom: 6px; }
.note-block .sub { color: var(--txt-2); font-size: 13px; margin-bottom: 18px; }
.note-point { display: flex; gap: 13px; padding: 13px 0; border-top: 1px solid var(--line-soft); }
.note-point:first-of-type { border-top: 0; }
.note-point .dot { flex-shrink: 0; width: 9px; height: 9px; border-radius: 50%; background: var(--pri); margin-top: 7px; box-shadow: 0 0 0 4px var(--pri-soft); }
.note-point .pt-body { flex: 1; }
.note-point .pt-term { font-weight: 700; color: #fff; font-size: 14.5px; }
.note-point .pt-def { color: var(--txt-1); font-size: 14px; line-height: 1.65; margin-top: 3px; }
.note-point code, .pt-def code, .q-text code, .ans-model code { background: var(--bg-0); border: 1px solid var(--line); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; color: var(--accent); }

.callout { background: var(--pri-soft); border: 1px solid var(--line); border-left: 3px solid var(--pri); border-radius: 10px; padding: 14px 16px; margin: 16px 0 4px; font-size: 13.5px; color: var(--txt-1); line-height: 1.6; }
.callout b { color: #fff; }

.note-table { width: 100%; border-collapse: collapse; margin: 14px 0 4px; font-size: 13.5px; }
.note-table th, .note-table td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line-soft); }
.note-table th { color: var(--pri); font-family: 'Sora'; font-size: 12.5px; }
.note-table tr:hover td { background: var(--bg-3); }

.diagram-frame { background: var(--bg-0); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin: 16px 0 4px; text-align: center; }
.diagram-frame .cap { color: var(--txt-2); font-size: 12px; margin-top: 10px; }

/* ---------- Setup / choices ---------- */
.choice-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px,1fr)); gap: 14px; }
.choice {
  background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; text-align: left; transition: .15s; position: relative;
}
.choice:hover { border-color: var(--pri); transform: translateY(-2px); }
.choice h4 { font-size: 15px; margin-bottom: 5px; }
.choice p { color: var(--txt-2); font-size: 12.5px; margin: 0; line-height: 1.5; }
.choice .tag { position: static; display: inline-block; margin-top: 12px; }

/* ---------- Quiz ---------- */
.quiz-head { display: flex; align-items: center; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.quiz-head h2 { font-size: 20px; }
.qprogress { flex: 1; min-width: 160px; }
.qprogress .bar { margin: 0; }
.qcount { font-size: 13px; color: var(--txt-1); font-weight: 600; white-space: nowrap; }

.qcard { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; }
.qtype-badge { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase; color: var(--accent); background: rgba(240,171,252,.1); padding: 5px 11px; border-radius: 99px; margin-bottom: 14px; }
.q-text { font-size: 18px; line-height: 1.55; font-weight: 600; color: #fff; margin-bottom: 6px; }
.q-text .blank { color: var(--accent); font-weight: 800; letter-spacing: 1px; }

.options { display: flex; flex-direction: column; gap: 10px; margin-top: 18px; }
.option {
  display: flex; align-items: center; gap: 13px; width: 100%; text-align: left;
  background: var(--bg-1); border: 1.5px solid var(--line); color: var(--txt-0);
  padding: 14px 16px; border-radius: 12px; font-size: 14.5px; transition: .13s;
}
.option:hover:not(:disabled) { border-color: var(--pri); background: var(--bg-3); }
.option .key { width: 26px; height: 26px; flex-shrink: 0; border-radius: 7px; background: var(--bg-3); display: grid; place-items: center; font-weight: 700; font-size: 13px; color: var(--txt-1); }
.option.correct { border-color: var(--ok); background: var(--ok-soft); }
.option.correct .key { background: var(--ok); color: #06210f; }
.option.wrong { border-color: var(--bad); background: var(--bad-soft); }
.option.wrong .key { background: var(--bad); color: #2a0710; }
.option:disabled { cursor: default; }

.tf-row { display: flex; gap: 12px; margin-top: 18px; }
.tf-row .option { justify-content: center; font-weight: 700; }

.fill-row { margin-top: 18px; display: flex; gap: 10px; flex-wrap: wrap; }
.fill-input { flex: 1; min-width: 220px; background: var(--bg-1); border: 1.5px solid var(--line); color: #fff; padding: 13px 15px; border-radius: 12px; font-size: 15px; font-family: inherit; }
.fill-input:focus { outline: none; border-color: var(--pri); }
.fill-input.correct { border-color: var(--ok); background: var(--ok-soft); }
.fill-input.wrong { border-color: var(--bad); background: var(--bad-soft); }

.reveal-area { margin-top: 18px; }
.self-grade { display: flex; gap: 10px; margin-top: 14px; }

.ans-box { margin-top: 18px; border-radius: 12px; padding: 16px 18px; font-size: 14px; line-height: 1.65; }
.ans-box.ok { background: var(--ok-soft); border: 1px solid rgba(74,222,128,.35); }
.ans-box.bad { background: var(--bad-soft); border: 1px solid rgba(251,113,133,.35); }
.ans-box.neutral { background: var(--bg-1); border: 1px solid var(--line); }
.ans-title { font-weight: 800; font-family: 'Sora'; font-size: 14px; margin-bottom: 7px; display: flex; align-items: center; gap: 8px; }
.ans-title.ok { color: var(--ok); }
.ans-title.bad { color: var(--bad); }
.ans-model { color: var(--txt-1); }
.ans-model b { color: #fff; }

.q-foot { display: flex; align-items: center; gap: 12px; margin-top: 22px; }
.q-foot .spacer { flex: 1; }
.bookmark-btn { background: transparent; border: 1px solid var(--line); color: var(--txt-2); border-radius: 10px; padding: 9px 13px; font-size: 13px; transition: .15s; }
.bookmark-btn:hover, .bookmark-btn.on { color: var(--warn); border-color: var(--warn); }

.q-diagram { margin: 6px 0 4px; }

/* ---------- Results ---------- */
.result-hero { text-align: center; padding: 30px 20px; }
.score-ring { width: 168px; height: 168px; margin: 0 auto 18px; position: relative; }
.score-ring svg { transform: rotate(-90deg); }
.score-ring .pct { position: absolute; inset: 0; display: grid; place-items: center; flex-direction: column; }
.score-ring .pct b { font-family: 'Sora'; font-size: 40px; color: #fff; line-height: 1; }
.score-ring .pct span { font-size: 12px; color: var(--txt-2); }
.result-msg { font-size: 16px; color: var(--txt-1); margin: 4px 0 22px; }
.result-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

.review-item { background: var(--bg-2); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 12px; }
.review-item .ri-q { font-weight: 600; color: #fff; font-size: 14.5px; margin-bottom: 8px; line-height: 1.5; }
.review-item .ri-meta { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; }
.ri-badge { font-size: 11px; padding: 3px 9px; border-radius: 99px; font-weight: 700; }
.ri-badge.ok { color: var(--ok); background: var(--ok-soft); }
.ri-badge.bad { color: var(--bad); background: var(--bad-soft); }
.ri-ans { font-size: 13.5px; color: var(--txt-1); line-height: 1.6; }
.ri-ans b { color: #fff; }

.empty { text-align: center; padding: 60px 20px; color: var(--txt-2); }
.empty .big { font-size: 40px; margin-bottom: 12px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; bottom: 26px; left: 50%; transform: translateX(-50%) translateY(24px);
  background: var(--bg-3); border: 1px solid var(--line); color: #fff;
  padding: 13px 20px; border-radius: 12px; font-size: 14px; font-weight: 600;
  box-shadow: var(--shadow); z-index: 100;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform .3s cubic-bezier(.2,.8,.2,1), opacity .3s ease, visibility .3s;
}
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; visibility: visible; }

.fade-in { animation: fade .35s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 920px) {
  .notes-wrap { grid-template-columns: 1fr; }
  .toc { position: static; }
  .grid-3, .stat-row { grid-template-columns: repeat(2,1fr); }
}
@media (max-width: 760px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 50; transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow); }
  .menu-toggle { display: grid; place-items: center; }
  .content { padding: 20px 16px; }
  .grid-2, .grid-3, .stat-row { grid-template-columns: 1fr; }
  .hero h1 { font-size: 26px; }
}
