:root {
  --bg: #f6f8fc;
  --bg2: #eef4ff;
  --panel: rgba(255, 255, 255, 0.90);
  --panel-strong: rgba(255, 255, 255, 0.98);
  --text: #101827;
  --muted: #526074;
  --line: rgba(15, 23, 42, 0.12);
  --primary: #1d4ed8;
  --primary-strong: #1e40af;
  --good: #16a34a;
  --good-bg: #dcfce7;
  --bad: #dc2626;
  --bad-bg: #fee2e2;
  --warn: #ca8a04;
  --warn-bg: #fef9c3;
  --shadow: 0 22px 70px rgba(30, 41, 59, .16);
  --small-shadow: 0 12px 30px rgba(30, 41, 59, .10);
  --radius-xl: 28px;
  --radius-lg: 20px;
  --radius-md: 14px;
  --font: Georgia, "Times New Roman", Times, serif;
  --reading-font: Georgia, "Times New Roman", Times, serif;
  --glow-1: rgba(37, 99, 235, .18);
  --glow-2: rgba(249, 115, 22, .14);
  --card-texture: none;
}

[data-theme="cream"] {
  --bg: #f5edcf;
  --bg2: #fff8dc;
  --panel: rgba(255, 248, 220, 0.92);
  --panel-strong: rgba(255, 252, 234, 0.99);
  --text: #2b2418;
  --muted: #6c6048;
  --line: rgba(91, 70, 33, 0.18);
  --primary: #9a6100;
  --primary-strong: #764700;
  --good: #287a3e;
  --good-bg: #e9f5d8;
  --bad: #a33a2f;
  --bad-bg: #f8dfd2;
  --warn: #9a6100;
  --warn-bg: #fff0b8;
  --shadow: 0 22px 70px rgba(79, 57, 24, .18);
  --small-shadow: 0 12px 30px rgba(79, 57, 24, .10);
  --glow-1: rgba(250, 204, 21, .26);
  --glow-2: rgba(180, 83, 9, .12);
  --card-texture: linear-gradient(180deg, rgba(255,255,255,.42), rgba(255,255,255,.05));
}

[data-theme="cream"] .glass-card,
[data-theme="cream"] .sidebar {
  background-image: var(--card-texture);
}

[data-theme="cream"] .question-card {
  border-color: rgba(119, 83, 24, .22);
}

[data-theme="cream"] .topic-pill.active,
[data-theme="cream"] .subtopic-btn.active,
[data-theme="cream"] .subtopic-btn:hover {
  background: rgba(154, 97, 0, .13);
  color: var(--primary-strong);
}


[data-theme="dark"] {
  --bg: #07111f;
  --bg2: #111827;
  --panel: rgba(15, 23, 42, 0.78);
  --panel-strong: rgba(15, 23, 42, 0.96);
  --text: #e5e7eb;
  --muted: #94a3b8;
  --line: rgba(226, 232, 240, 0.13);
  --primary: #60a5fa;
  --primary-strong: #3b82f6;
  --good: #4ade80;
  --good-bg: rgba(22, 163, 74, .18);
  --bad: #f87171;
  --bad-bg: rgba(220, 38, 38, .16);
  --warn: #facc15;
  --warn-bg: rgba(234, 179, 8, .16);
  --shadow: 0 22px 70px rgba(0,0,0,.35);
  --small-shadow: 0 12px 30px rgba(0,0,0,.22);
  --glow-1: rgba(96, 165, 250, .16);
  --glow-2: rgba(14, 165, 233, .10);
}


* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); font-size: 17px; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  color: var(--text);
  background:
    radial-gradient(circle at 10% 0%, var(--glow-1), transparent 32rem),
    radial-gradient(circle at 100% 12%, var(--glow-2), transparent 34rem),
    linear-gradient(135deg, var(--bg), var(--bg2));
  overflow-x: hidden;
  line-height: 1.58;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

::selection { background: color-mix(in srgb, var(--primary) 22%, transparent); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
code { font-size: .9em; padding: .1rem .35rem; border-radius: 7px; background: rgba(148,163,184,.15); }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 20px;
  padding: 18px;
}
.glass-card {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--small-shadow);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
}
.sidebar {
  position: sticky;
  top: 18px;
  height: calc(100vh - 36px);
  border-radius: var(--radius-xl);
  padding: 18px;
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  overflow: auto;
  z-index: 20;
}
.brand-block { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.brand-mark {
  width: 48px; height: 48px; border-radius: 16px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, var(--primary), #f97316);
  color: white; font-weight: 900; font-size: 1.6rem;
  box-shadow: 0 10px 22px rgba(37,99,235,.24);
}
.brand-title { font-weight: 900; letter-spacing: -.02em; font-size: 1.08rem; }
.brand-subtitle { color: var(--muted); font-size: .95rem; margin-top: 2px; }
.bank-box { padding: 14px; border-radius: 18px; margin-bottom: 14px; }
.field-label { display:block; color: var(--muted); font-weight: 800; font-size: .9rem; margin-bottom: 8px; }
.select, .search-input {
  width: 100%; color: var(--text); background: var(--panel-strong);
  border: 1px solid var(--line); border-radius: 14px; outline: none;
  padding: 13px 15px;
  font-size: 1rem;
  line-height: 1.35;
}
.select:focus, .search-input:focus, .note-box:focus { border-color: var(--primary); box-shadow: 0 0 0 4px rgba(37,99,235,.12); }
.bank-actions { display:flex; gap: 8px; margin-top: 10px; }
.tiny-btn, .soft-btn, .icon-btn, .topic-pill, .full-btn, .nav-btn, .danger-btn {
  border: 1px solid var(--line);
  color: var(--text);
  background: var(--panel-strong);
  border-radius: 13px;
  padding: 10px 12px;
  transition: transform .12s ease, background .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.tiny-btn { flex: 1; font-size: .92rem; padding: 10px 10px; color: var(--muted); font-weight: 800; }
.soft-btn { font-weight: 800; white-space: nowrap; }
.icon-btn { width: 42px; height: 42px; display: grid; place-items: center; font-size: 1.2rem; }
button:hover { transform: translateY(-1px); box-shadow: 0 8px 16px rgba(30,41,59,.08); }
button:active { transform: translateY(0); box-shadow: none; }
.primary, .nav-btn.primary, .full-btn.primary { background: var(--primary); border-color: var(--primary); color: white; }
.danger-btn { color: var(--bad); font-weight: 800; }
.danger-btn.muted { color: var(--muted); }
.topic-tools { display: grid; gap: 8px; margin: 12px 0 14px; }
.topic-pill { text-align: left; font-weight: 800; padding: 11px 12px; color: var(--muted); }
.topic-pill.active { background: rgba(37,99,235,.12); border-color: rgba(37,99,235,.32); color: var(--primary); }
.topic-tree { display: grid; gap: 10px; padding-bottom: 30px; }
.topic-group { border: 1px solid var(--line); border-radius: 18px; overflow: hidden; background: rgba(255,255,255,.22); }
[data-theme="dark"] .topic-group { background: rgba(15,23,42,.3); }
.topic-head {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  width: 100%; padding: 12px; border: 0; background: transparent; color: var(--text); font-weight: 900; text-align: left;
}
.topic-count { color: var(--muted); font-weight: 850; font-size: .88rem; }
.subtopic-list { display: grid; gap: 4px; padding: 0 8px 8px; }
.subtopic-btn {
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
  width: 100%; border: 0; border-radius: 12px; background: transparent; color: var(--muted);
  padding: 10px 11px; text-align: left; font-size: .98rem; line-height: 1.35;
}
.subtopic-btn.active, .subtopic-btn:hover { background: rgba(37,99,235,.10); color: var(--primary); box-shadow: none; }
.main-panel { min-width: 0; display: grid; gap: 16px; align-content: start; }
.topbar {
  position: sticky; top: 18px; z-index: 10;
  border-radius: var(--radius-xl);
  padding: 12px;
  display: flex; gap: 12px; align-items: center;
}
.search-wrap { position: relative; flex: 1; }
.search-icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 900; }
.search-input { padding-left: 40px; font-size: 1rem; }
.topbar-actions { display: flex; gap: 9px; align-items: center; }
.font-control {
  min-width: 46px;
  font-weight: 950;
  font-size: 1.08rem;
  padding-inline: 12px;
}
.font-control.small { font-size: .96rem; }
.font-control.large { font-size: 1.22rem; }
.mobile-only { display: none; }
.hero-grid { display: grid; grid-template-columns: 1fr 360px; gap: 16px; }
.hero-card, .progress-card { border-radius: var(--radius-xl); padding: 22px; }
.hero-card { display: flex; align-items: stretch; justify-content: space-between; gap: 18px; }
.eyebrow { color: var(--primary); font-weight: 900; text-transform: uppercase; letter-spacing: .08em; font-size: .74rem; }
h1 { font-size: clamp(1.6rem, 3.4vw, 2.7rem); line-height: 1; margin: 8px 0 8px; letter-spacing: -.055em; }
p { color: var(--muted); line-height: 1.65; }
.hero-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; min-width: 320px; }
.hero-stats > div {
  border: 1px solid var(--line); background: rgba(255,255,255,.34); border-radius: 18px; padding: 14px;
  display: flex; flex-direction: column; justify-content: center;
}
[data-theme="dark"] .hero-stats > div { background: rgba(15,23,42,.34); }
.hero-stats strong { font-size: 1.6rem; letter-spacing: -.04em; }
.hero-stats span { color: var(--muted); font-size: .78rem; font-weight: 800; margin-top: 4px; }
.progress-card { display: grid; align-content: center; gap: 12px; }
.progress-header { display:flex; justify-content:space-between; color: var(--muted); font-weight: 900; }
.meter { height: 13px; border-radius: 999px; background: rgba(148,163,184,.22); overflow:hidden; }
.meter-fill { height:100%; width:0%; background: linear-gradient(90deg, var(--primary), var(--good)); border-radius: inherit; transition: width .25s ease; }
.progress-text { color: var(--muted); font-size: .88rem; }
.study-layout { display: grid; grid-template-columns: minmax(0, 1fr) 310px; gap: 16px; align-items: start; }
.question-card { border-radius: var(--radius-xl); padding: 26px; min-height: 500px; box-shadow: var(--shadow); }
.q-meta { display:flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.badge { display:inline-flex; align-items:center; gap: 6px; border-radius: 999px; padding: 8px 12px; font-size: .86rem; font-weight: 900; color: var(--muted); background: rgba(148,163,184,.14); border: 1px solid var(--line); line-height: 1.25; }
.badge.primary { color: var(--primary); background: rgba(37,99,235,.11); border-color: rgba(37,99,235,.22); }
.badge.good { color: var(--good); background: var(--good-bg); }
.badge.bad { color: var(--bad); background: var(--bad-bg); }
.q-title { font-family: var(--reading-font); font-size: clamp(1.28rem, 2.1vw, 1.7rem); line-height: 1.44; letter-spacing: -.018em; margin: 0 0 24px; font-weight: 900; max-width: 980px; }
.options { display: grid; gap: 11px; }
.option-btn {
  width: 100%; display: grid; grid-template-columns: 48px 1fr auto; gap: 14px; align-items: center;
  border: 1px solid var(--line); background: var(--panel-strong); color: var(--text); border-radius: 20px; padding: 16px 17px;
  text-align: left; min-height: 70px;
  transition: transform .08s ease, border-color .12s ease, background .12s ease;
}
.option-btn:active { transform: scale(.995); }
.option-btn:focus-visible { outline: 3px solid color-mix(in srgb, var(--primary) 35%, transparent); outline-offset: 2px; }
.option-label { width: 40px; height: 40px; border-radius: 13px; display:grid; place-items:center; font-weight: 950; background: rgba(148,163,184,.16); color: var(--muted); font-size: .98rem; }
.option-text { font-family: var(--reading-font); line-height: 1.58; font-size: 1.02rem; letter-spacing: .003em; }
.option-status { font-weight: 950; font-size: .95rem; line-height: 1.25; }
.option-btn.correct { border-color: rgba(22, 163, 74, .45); background: var(--good-bg); }
.option-btn.correct .option-label { background: var(--good); color: white; }
.option-btn.incorrect { border-color: rgba(220,38,38,.45); background: var(--bad-bg); }
.option-btn.incorrect .option-label { background: var(--bad); color: white; }
.feedback { margin-top: 18px; border-radius: 20px; padding: 18px; border: 1px solid var(--line); display: none; font-size: 1rem; }
.feedback.show { display: block; animation: pop .16s ease-out; }
.feedback.correct { background: var(--good-bg); border-color: rgba(22,163,74,.36); }
.feedback.incorrect { background: var(--bad-bg); border-color: rgba(220,38,38,.36); }
.feedback.neutral { background: var(--warn-bg); border-color: rgba(202,138,4,.32); }
.feedback h3 { margin: 0 0 10px; font-size: 1.08rem; }
.feedback p { margin: 8px 0 0; color: var(--text); }
.explanation { font-family: var(--reading-font); margin-top: 14px; border-top: 1px solid var(--line); padding-top: 14px; line-height: 1.62; max-width: 1000px; }
.card-actions { display:flex; flex-wrap:wrap; gap: 10px; margin-top: 18px; }
.chip-btn { border: 1px solid var(--line); background: var(--panel-strong); color: var(--text); border-radius: 999px; padding: 10px 13px; font-weight: 850; font-size: .94rem; }
.chip-btn.active { color: #fff; background: #f59e0b; border-color: #f59e0b; }
.right-rail { display: grid; gap: 16px; position: sticky; top: 106px; }
.mini-card { border-radius: var(--radius-lg); padding: 16px; }
.rail-title { font-weight: 950; margin-bottom: 12px; }
.nav-row { display:grid; grid-template-columns: 1fr 1fr; gap: 9px; }
.nav-btn { font-weight: 850; font-size: 1rem; }
.position-label { margin-top: 12px; color: var(--muted); font-weight: 800; font-size: .9rem; }
.stacked-actions { display: grid; gap: 9px; }
.full-btn { width: 100%; font-weight: 850; text-align: center; font-size: 1rem; }
.note-box { width:100%; min-height: 150px; resize: vertical; border-radius: 16px; border: 1px solid var(--line); padding: 14px; color: var(--text); background: var(--panel-strong); outline: none; font-size: 1rem; line-height: 1.55; }
.note-status { margin-top: 8px; color: var(--muted); font-size: .8rem; font-weight: 800; }
.empty-state { min-height: 430px; display:grid; place-items:center; align-content:center; text-align:center; gap: 10px; }
.loader { width: 36px; height:36px; border-radius:50%; border: 4px solid rgba(148,163,184,.25); border-top-color: var(--primary); animation: spin 1s linear infinite; }
.dialog { border:0; background: transparent; padding: 20px; max-width: 880px; width: min(94vw, 880px); }
.dialog::backdrop { background: rgba(2,6,23,.42); backdrop-filter: blur(8px); }
.dialog-card { border-radius: var(--radius-xl); padding: 22px; }
.dialog-header { display:flex; justify-content:space-between; align-items:center; gap: 12px; }
.dialog-header h2 { margin: 0; font-size: 1.6rem; }
.dialog-grid { display:grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-top: 16px; }
.dialog-actions { display:grid; gap: 9px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(100px); opacity: 0; z-index: 99; background: var(--panel-strong); color: var(--text); border: 1px solid var(--line); border-radius: 999px; padding: 12px 16px; box-shadow: var(--shadow); font-weight: 850; transition: all .22s ease; }
.toast.show { transform: translateX(-50%) translateY(0); opacity: 1; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pop { from { transform: scale(.985); opacity: .3; } to { transform: scale(1); opacity: 1; } }

@media (max-width: 1050px) {
  .app-shell { grid-template-columns: 1fr; padding: 12px; }
  .sidebar { position: fixed; inset: 12px auto 12px 12px; width: min(88vw, 330px); height: auto; transform: translateX(calc(-100% - 20px)); transition: transform .18s ease; }
  .sidebar.open { transform: translateX(0); }
  .mobile-only { display: grid; }
  .topbar { top: 12px; }
  .hero-grid { grid-template-columns: 1fr; }
  .study-layout { grid-template-columns: 1fr; }
  .right-rail { position: static; grid-template-columns: 1fr 1fr; }
  .notes-card { grid-column: 1 / -1; }
}
@media (max-width: 700px) {
  html { font-size: 16px; }

  .topbar { flex-wrap: wrap; }
  .search-wrap { order: 2; flex-basis: 100%; }
  .topbar-actions { flex: 1; justify-content: flex-end; }
  .hero-card { flex-direction: column; }
  .hero-stats { min-width: 0; }
  .right-rail { grid-template-columns: 1fr; }
  .dialog-grid { grid-template-columns: 1fr; }
  .question-card { padding: 22px; }
  .option-btn { grid-template-columns: 44px 1fr; padding: 16px; }
  .option-status { grid-column: 2; }
}
@media (min-width: 1200px) {
  .question-card { max-width: 1040px; }
}

@media print {
  body { background: white; }
  .sidebar, .topbar, .right-rail, .hero-grid, .toast { display:none !important; }
  .app-shell, .study-layout { display:block; padding:0; }
  .question-card { box-shadow:none; border:0; }
}
