:root {
  color-scheme: light;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --surface-3: #eef2ff;
  --text: #111827;
  --muted: #64748b;
  --muted-2: #94a3b8;
  --line: #e2e8f0;
  --primary: #4f46e5;
  --primary-2: #2563eb;
  --primary-soft: #eef2ff;
  --success: #15803d;
  --success-soft: #ecfdf3;
  --danger: #b91c1c;
  --danger-soft: #fef2f2;
  --warning: #b45309;
  --warning-soft: #fff7ed;
  --shadow: 0 16px 50px rgba(15, 23, 42, .08);
  --radius-lg: 24px;
  --radius-md: 18px;
  --radius-sm: 12px;
  --sidebar: 270px;
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --surface: #111827;
  --surface-2: #172033;
  --surface-3: #1f2a44;
  --text: #f8fafc;
  --muted: #a7b2c5;
  --muted-2: #7d8aa3;
  --line: #25324a;
  --primary: #818cf8;
  --primary-2: #60a5fa;
  --primary-soft: #202853;
  --success: #4ade80;
  --success-soft: #123525;
  --danger: #f87171;
  --danger-soft: #3b1820;
  --warning: #fbbf24;
  --warning-soft: #3c2d14;
  --shadow: 0 16px 50px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Tahoma, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: inherit; text-decoration: none; }
button { color: inherit; }

.app-shell { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 0 0 auto;
  width: var(--sidebar);
  min-height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--line);
  padding: 26px 18px;
  display: flex;
  flex-direction: column;
  z-index: 20;
}
.brand { display: flex; gap: 12px; align-items: center; padding: 0 8px 24px; }
.brand-mark {
  width: 44px; height: 44px; display: grid; place-items: center;
  border-radius: 14px; color: white; font-weight: 900; font-size: 21px;
  background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 10px 26px rgba(79, 70, 229, .24);
}
.brand span:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 18px; }
.brand small { color: var(--muted); font-size: 11px; }
.side-nav { display: grid; gap: 6px; }
.nav-link {
  display: flex; align-items: center; gap: 12px;
  min-height: 48px; padding: 10px 12px; border-radius: 14px;
  color: var(--muted); font-size: 14px; font-weight: 700;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--primary-soft); color: var(--primary); }
.nav-icon { width: 28px; text-align: center; font-size: 17px; }
.sidebar-card {
  margin-top: auto; padding: 16px; border-radius: 18px;
  background: linear-gradient(145deg, var(--surface-3), var(--surface-2));
  border: 1px solid var(--line); display: grid; gap: 8px;
}
.sidebar-card strong { font-size: 15px; }
.eyebrow { color: var(--primary); font-size: 11px; font-weight: 800; }
.mini-progress { height: 8px; border-radius: 20px; background: var(--line); overflow: hidden; }
.mini-progress span { height: 100%; display: block; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--primary), var(--primary-2)); }
.sidebar-card small { color: var(--muted); font-size: 11px; line-height: 1.6; }

.main-area { margin-right: var(--sidebar); min-height: 100vh; }
.topbar {
  min-height: 92px; padding: 22px clamp(20px, 4vw, 52px) 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
}
.page-kicker { margin: 0 0 5px; color: var(--muted); font-size: 12px; font-weight: 700; }
.topbar h1 { margin: 0; font-size: clamp(22px, 3vw, 30px); letter-spacing: -.5px; }
.top-actions { display: flex; gap: 10px; align-items: center; }
.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--surface); cursor: pointer; font-size: 18px;
}
.profile-chip {
  border: 1px solid var(--line); background: var(--surface); border-radius: 16px;
  padding: 7px 9px; display: flex; align-items: center; gap: 10px; cursor: pointer;
}
.avatar { width: 34px; height: 34px; border-radius: 11px; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-weight: 900; }
.profile-text { display: grid; text-align: right; }
.profile-text strong { font-size: 12px; }
.profile-text small { color: var(--muted); font-size: 9px; margin-top: 2px; }
.page-content { padding: 18px clamp(20px, 4vw, 52px) 54px; max-width: 1460px; margin: 0 auto; }

.hero {
  position: relative; overflow: hidden; border-radius: var(--radius-lg);
  padding: clamp(24px, 4vw, 42px); background: linear-gradient(135deg, #111827 0%, #312e81 58%, #2563eb 100%);
  color: #fff; box-shadow: var(--shadow); min-height: 230px; display: flex; align-items: center;
}
.hero::after { content: ""; position: absolute; width: 310px; height: 310px; border-radius: 50%; left: -80px; top: -120px; background: rgba(255,255,255,.09); }
.hero::before { content: ""; position: absolute; width: 200px; height: 200px; border-radius: 48px; left: 160px; bottom: -130px; transform: rotate(24deg); background: rgba(255,255,255,.06); }
.hero-content { position: relative; z-index: 2; max-width: 720px; }
.hero .badge { background: rgba(255,255,255,.12); color: #dbeafe; border: 1px solid rgba(255,255,255,.18); }
.hero h2 { font-size: clamp(25px, 4vw, 42px); line-height: 1.2; margin: 14px 0 10px; }
.hero p { color: #dbeafe; margin: 0; line-height: 1.9; max-width: 650px; font-size: 14px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 22px; }

.btn { border: 0; border-radius: 13px; padding: 12px 17px; font-weight: 800; cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; }
.btn-primary { background: linear-gradient(135deg, var(--primary), var(--primary-2)); color: #fff; box-shadow: 0 10px 24px rgba(79,70,229,.22); }
.btn-light { background: #fff; color: #111827; }
.btn-soft { background: var(--primary-soft); color: var(--primary); }
.btn-ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn:disabled { opacity: .45; cursor: not-allowed; box-shadow: none; }

.badge { display: inline-flex; align-items: center; gap: 6px; min-height: 28px; padding: 5px 10px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-size: 11px; font-weight: 800; }
.badge.success { background: var(--success-soft); color: var(--success); }
.badge.warning { background: var(--warning-soft); color: var(--warning); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }

.section { margin-top: 26px; }
.section-head { display: flex; align-items: end; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-head h2 { margin: 0; font-size: 19px; }
.section-head p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.section-head a { color: var(--primary); font-size: 12px; font-weight: 800; }

.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-top: 18px; }
.stat-card, .card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius-md); box-shadow: 0 8px 28px rgba(15,23,42,.03);
}
.stat-card { padding: 18px; min-height: 126px; display: grid; align-content: space-between; }
.stat-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.stat-icon { width: 36px; height: 36px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-3); }
.stat-card small { color: var(--muted); font-size: 11px; }
.stat-card strong { font-size: 25px; letter-spacing: -.5px; }
.stat-card .delta { color: var(--success); font-size: 10px; font-weight: 800; }
.card { padding: 20px; }

.two-col { display: grid; grid-template-columns: 1.35fr .85fr; gap: 18px; }
.three-col { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.topic-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.topic-card { padding: 18px; cursor: pointer; transition: transform .18s ease, border-color .18s ease; }
.topic-card:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--primary) 32%, var(--line)); }
.topic-card h3 { margin: 13px 0 6px; font-size: 15px; }
.topic-card p { margin: 0; font-size: 11px; color: var(--muted); line-height: 1.7; }
.topic-footer { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; font-size: 10px; color: var(--muted); }
.progress-bar { height: 8px; background: var(--line); border-radius: 999px; overflow: hidden; }
.progress-bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--primary), var(--primary-2)); border-radius: inherit; }

.activity-list { display: grid; gap: 10px; }
.activity-item { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.activity-item:last-child { border-bottom: 0; }
.activity-dot { width: 38px; height: 38px; border-radius: 12px; background: var(--primary-soft); display: grid; place-items: center; color: var(--primary); }
.activity-main strong { font-size: 12px; display: block; }
.activity-main small, .activity-time { color: var(--muted); font-size: 10px; }
.score-chip { min-width: 58px; text-align: center; font-weight: 900; }

.empty-state { text-align: center; padding: 44px 18px; display: grid; justify-items: center; gap: 10px; }
.empty-icon { width: 64px; height: 64px; border-radius: 22px; display: grid; place-items: center; background: var(--surface-3); font-size: 28px; }
.empty-state h3 { margin: 4px 0 0; }
.empty-state p { color: var(--muted); margin: 0; max-width: 460px; line-height: 1.8; font-size: 12px; }

.setup-grid { display: grid; grid-template-columns: 1.1fr .9fr; gap: 18px; }
.option-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.option-card { position: relative; }
.option-card input { position: absolute; opacity: 0; pointer-events: none; }
.option-card label { display: block; border: 1px solid var(--line); border-radius: 16px; padding: 16px; background: var(--surface); cursor: pointer; min-height: 116px; }
.option-card input:checked + label { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 14%, transparent); }
.option-card strong { display: block; margin-top: 10px; font-size: 13px; }
.option-card small { color: var(--muted); font-size: 10px; line-height: 1.6; }
.field { display: grid; gap: 7px; margin-top: 15px; }
.field label { font-size: 11px; font-weight: 800; color: var(--muted); }
.field select, .field input[type="number"], .field input[type="text"] { width: 100%; border: 1px solid var(--line); background: var(--surface); color: var(--text); border-radius: 12px; padding: 12px 13px; outline: none; }
.field select:focus, .field input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 12%, transparent); }
.checkbox-row { display: flex; align-items: center; gap: 10px; padding: 12px 0; }
.checkbox-row input { width: 18px; height: 18px; accent-color: var(--primary); }

.test-layout { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 18px; align-items: start; }
.test-card { padding: clamp(20px, 4vw, 32px); min-height: 500px; }
.test-meta { display: flex; justify-content: space-between; gap: 12px; align-items: center; color: var(--muted); font-size: 11px; }
.question-text { font-size: clamp(19px, 3vw, 25px); line-height: 1.8; margin: 28px 0 24px; font-weight: 800; }
.answers { display: grid; gap: 11px; }
.answer-btn {
  width: 100%; display: grid; grid-template-columns: 38px 1fr; gap: 12px; align-items: center;
  text-align: right; border: 1px solid var(--line); background: var(--surface-2); color: var(--text);
  padding: 12px 13px; border-radius: 15px; cursor: pointer; min-height: 58px;
}
.answer-btn:hover { border-color: color-mix(in srgb, var(--primary) 30%, var(--line)); }
.answer-btn.selected { border-color: var(--primary); background: var(--primary-soft); }
.answer-letter { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; border: 1px solid var(--line); font-weight: 900; }
.answer-btn.selected .answer-letter { background: var(--primary); border-color: var(--primary); color: #fff; }
.test-actions { margin-top: 28px; display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.test-tools { display: flex; gap: 8px; flex-wrap: wrap; }
.test-side { position: sticky; top: 18px; }
.timer { font-size: 26px; font-variant-numeric: tabular-nums; font-weight: 900; letter-spacing: 1px; }
.question-map { display: grid; grid-template-columns: repeat(5, 1fr); gap: 7px; margin-top: 14px; }
.q-dot { aspect-ratio: 1; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-2); cursor: pointer; font-size: 10px; font-weight: 800; }
.q-dot.answered { background: var(--primary-soft); color: var(--primary); border-color: color-mix(in srgb, var(--primary) 35%, var(--line)); }
.q-dot.flagged::after { content: "•"; color: var(--warning); margin-right: 2px; }
.q-dot.current { background: var(--primary); color: #fff; border-color: var(--primary); }

.result-hero { text-align: center; padding: 32px; }
.score-ring {
  --score: 0; width: 150px; height: 150px; border-radius: 50%; margin: 0 auto 18px; display: grid; place-items: center;
  background: conic-gradient(var(--primary) calc(var(--score) * 1%), var(--line) 0);
  position: relative;
}
.score-ring::after { content: ""; position: absolute; width: 116px; height: 116px; border-radius: 50%; background: var(--surface); }
.score-ring span { position: relative; z-index: 2; font-size: 31px; font-weight: 900; }
.result-hero h2 { margin: 0 0 7px; }
.result-hero p { margin: 0; color: var(--muted); font-size: 12px; }
.breakdown { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 18px; }
.breakdown .mini { padding: 14px; background: var(--surface-2); border: 1px solid var(--line); border-radius: 14px; text-align: center; }
.breakdown strong { display: block; font-size: 20px; }
.breakdown small { color: var(--muted); font-size: 10px; }

.review-list { display: grid; gap: 12px; }
.review-card { border: 1px solid var(--line); border-radius: 16px; padding: 16px; background: var(--surface); }
.review-card.correct { border-right: 4px solid var(--success); }
.review-card.wrong { border-right: 4px solid var(--danger); }
.review-card.unanswered { border-right: 4px solid var(--warning); }
.review-card h4 { margin: 0 0 10px; font-size: 14px; line-height: 1.8; }
.review-answer { font-size: 11px; color: var(--muted); line-height: 1.8; }
.explanation { margin-top: 10px; padding: 11px 12px; border-radius: 12px; background: var(--surface-2); font-size: 11px; line-height: 1.8; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 680px; }
th, td { padding: 13px 10px; border-bottom: 1px solid var(--line); text-align: right; font-size: 11px; }
th { color: var(--muted); font-size: 10px; }
td strong { font-size: 12px; }
.row-actions { display: flex; gap: 6px; }
.small-btn { border: 1px solid var(--line); background: var(--surface-2); border-radius: 9px; padding: 7px 9px; cursor: pointer; font-size: 10px; }

.saved-list { display: grid; gap: 12px; }
.saved-card { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: start; }
.saved-card h3 { margin: 0 0 6px; font-size: 14px; line-height: 1.7; }
.saved-card p { margin: 0; color: var(--muted); font-size: 10px; }

.chart-card { min-height: 310px; }
.chart-wrap { margin-top: 18px; height: 220px; display: flex; align-items: end; gap: 10px; padding: 10px 4px 0; border-bottom: 1px solid var(--line); }
.chart-bar-col { flex: 1; display: grid; grid-template-rows: 1fr auto; height: 100%; min-width: 28px; gap: 7px; }
.chart-bar-track { align-self: end; height: 100%; display: flex; align-items: end; }
.chart-bar { width: 100%; min-height: 3px; border-radius: 9px 9px 3px 3px; background: linear-gradient(180deg, var(--primary-2), var(--primary)); position: relative; }
.chart-bar span { position: absolute; top: -22px; width: 100%; text-align: center; font-size: 9px; color: var(--muted); }
.chart-label { text-align: center; color: var(--muted); font-size: 8px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topic-analysis { display: grid; gap: 12px; }
.topic-row { display: grid; gap: 7px; }
.topic-row-head { display: flex; justify-content: space-between; gap: 12px; font-size: 11px; }
.topic-row-head span:last-child { color: var(--muted); }

.resource-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
.resource-card { padding: 20px; display: grid; gap: 10px; }
.resource-card h3 { margin: 0; font-size: 15px; }
.resource-card p { margin: 0; color: var(--muted); font-size: 11px; line-height: 1.8; }
.resource-card .btn { margin-top: 4px; width: fit-content; }
.notice { padding: 14px 16px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface-2); color: var(--muted); font-size: 11px; line-height: 1.8; }

.settings-list { display: grid; gap: 12px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 14px 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-copy strong { display: block; font-size: 12px; }
.setting-copy small { display: block; color: var(--muted); font-size: 10px; margin-top: 3px; line-height: 1.6; }
.switch { position: relative; width: 48px; height: 28px; flex: 0 0 auto; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: var(--line); cursor: pointer; transition: .2s; }
.switch span::after { content: ""; position: absolute; width: 22px; height: 22px; border-radius: 50%; top: 3px; right: 3px; background: var(--surface); box-shadow: 0 2px 8px rgba(0,0,0,.16); transition: .2s; }
.switch input:checked + span { background: var(--primary); }
.switch input:checked + span::after { transform: translateX(-20px); }

.modal-backdrop { position: fixed; inset: 0; background: rgba(2,6,23,.58); display: grid; place-items: center; padding: 18px; z-index: 100; }
.modal { width: min(480px, 100%); background: var(--surface); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--shadow); padding: 22px; }
.modal h3 { margin: 0 0 8px; }
.modal p { color: var(--muted); font-size: 11px; line-height: 1.8; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 18px; }

.toast-region { position: fixed; left: 18px; bottom: 18px; z-index: 110; display: grid; gap: 8px; }
.toast { background: var(--text); color: var(--surface); padding: 11px 14px; border-radius: 12px; box-shadow: var(--shadow); font-size: 11px; animation: toastIn .2s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(6px); } }

.bottom-nav { display: none; }

@media (max-width: 1120px) {
  :root { --sidebar: 228px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .topic-grid { grid-template-columns: repeat(2, 1fr); }
  .test-layout { grid-template-columns: 1fr; }
  .test-side { position: static; }
}

@media (max-width: 760px) {
  body { padding-bottom: calc(74px + env(safe-area-inset-bottom)); }
  .sidebar { display: none; }
  .main-area { margin-right: 0; }
  .topbar { min-height: 76px; padding: 16px 16px 8px; }
  .page-content { padding: 12px 14px 26px; }
  .profile-text { display: none; }
  .profile-chip { padding: 5px; border-radius: 13px; }
  .hero { min-height: 265px; padding: 25px 20px; }
  .hero h2 { font-size: 28px; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { min-height: 110px; padding: 14px; }
  .stat-card strong { font-size: 22px; }
  .two-col, .three-col, .setup-grid, .resource-grid { grid-template-columns: 1fr; }
  .topic-grid { grid-template-columns: 1fr; }
  .option-cards { grid-template-columns: 1fr; }
  .option-card label { min-height: auto; }
  .breakdown { grid-template-columns: repeat(2, 1fr); }
  .question-text { margin-top: 22px; }
  .test-card { min-height: auto; }
  .test-actions > .btn { flex: 1; }
  .saved-card { grid-template-columns: 1fr; }
  .bottom-nav {
    position: fixed; display: grid; grid-template-columns: repeat(5, 1fr); inset: auto 0 0 0;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(18px); border-top: 1px solid var(--line); z-index: 50;
  }
  .bottom-nav .nav-link { min-height: 50px; display: grid; justify-items: center; gap: 1px; padding: 4px 2px; border-radius: 11px; font-size: 9px; }
  .bottom-nav .nav-icon { font-size: 17px; height: 22px; }
  .toast-region { bottom: calc(84px + env(safe-area-inset-bottom)); left: 12px; right: 12px; }
  .toast { text-align: center; }
}

@media (max-width: 390px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-card { padding: 12px; }
  .topbar h1 { font-size: 20px; }
  .question-map { grid-template-columns: repeat(6, 1fr); }
}

/* Newton section views */
.section-toolbar{display:grid;grid-template-columns:1fr 220px;gap:10px;margin-bottom:16px}.section-search,.section-toolbar select{width:100%;border:1px solid var(--line);background:var(--surface);color:var(--text);border-radius:12px;padding:12px 13px;outline:none}.section-number-grid{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:12px}.section-number-card{border:1px solid var(--line);background:var(--surface-2);border-radius:16px;padding:15px;text-align:right;cursor:pointer;min-height:145px;transition:.18s ease}.section-number-card:hover{transform:translateY(-2px);border-color:var(--primary)}.section-number-head{display:flex;align-items:flex-start;justify-content:space-between;gap:8px}.section-number-head>strong{font-size:24px;color:var(--primary)}.section-number-head>div{display:flex;flex-wrap:wrap;gap:4px;justify-content:flex-end}.section-number-card h3{font-size:14px;margin:12px 0 5px}.section-number-card p{font-size:10px;color:var(--muted);margin:0;line-height:1.7}.section-card-meta{display:flex;justify-content:space-between;color:var(--muted);font-size:9px;margin-top:13px}.question-image{max-width:100%;border-radius:14px;border:1px solid var(--line);margin:0 0 18px}.passage{background:var(--surface-2);border:1px solid var(--line);padding:16px;border-radius:14px;line-height:2;color:var(--muted);font-size:13px;margin-top:20px}.history-list{display:grid;gap:8px}.history-row{display:grid;grid-template-columns:1fr auto auto auto;gap:10px;align-items:center;padding:12px 0;border-bottom:1px solid var(--line)}.history-row:last-child{border-bottom:0}.history-row strong{display:block;font-size:12px}.history-row small{display:block;color:var(--muted);font-size:10px;margin-top:4px}
@media(max-width:1100px){.section-number-grid{grid-template-columns:repeat(3,minmax(0,1fr))}}
@media(max-width:760px){.section-toolbar{grid-template-columns:1fr}.section-number-grid{grid-template-columns:repeat(2,minmax(0,1fr))}.history-row{grid-template-columns:1fr auto}.history-row .btn{display:none}}

/* v3: search, streak, saved answers and richer mistake review */
.streak-week { display:grid; grid-template-columns:repeat(7,1fr); gap:8px; }
.streak-day { min-height:86px; border:1px solid var(--line); border-radius:15px; background:var(--surface-2); display:grid; place-items:center; align-content:center; gap:7px; padding:8px; text-align:center; }
.streak-day span { width:30px; height:30px; border-radius:50%; background:var(--surface-3); display:grid; place-items:center; font-weight:900; color:var(--muted); }
.streak-day small { color:var(--muted); font-size:9px; line-height:1.5; }
.streak-day.done { border-color:color-mix(in srgb,var(--success) 32%,var(--line)); background:var(--success-soft); }
.streak-day.done span { background:var(--success); color:white; }
.search-hero { max-width:850px; margin:0 auto; padding:8px 0 18px; }
.search-hero h2 { margin:12px 0 18px; font-size:clamp(22px,4vw,34px); }
.global-search { display:grid; grid-template-columns:auto 1fr; gap:10px; align-items:center; border:1px solid var(--line); border-radius:17px; padding:0 16px; background:var(--surface-2); min-height:58px; }
.global-search span { font-size:24px; color:var(--muted); }
.global-search input { border:0; background:transparent; outline:0; color:var(--text); font:inherit; width:100%; min-width:0; }
.search-tabs { display:flex; gap:8px; flex-wrap:wrap; margin-top:14px; }
.search-tabs button { border:1px solid var(--line); background:var(--surface); color:var(--muted); border-radius:999px; min-height:36px; padding:7px 13px; font-weight:800; cursor:pointer; }
.search-tabs button.active { background:var(--primary-soft); color:var(--primary); border-color:color-mix(in srgb,var(--primary) 35%,var(--line)); }
.search-block { margin-top:22px; }
.section-number-grid.compact { grid-template-columns:repeat(5,1fr); }
.saved-main { min-width:0; flex:1; }
.saved-actions { display:flex; gap:8px; flex-wrap:wrap; justify-content:flex-end; }
.result-badges { display:flex; gap:7px; flex-wrap:wrap; align-items:center; }
.answer-details { margin-top:12px; border:1px solid var(--line); border-radius:13px; background:var(--surface-2); overflow:hidden; }
.answer-details summary { cursor:pointer; padding:11px 13px; font-size:11px; font-weight:900; color:var(--primary); }
.answer-details > div { border-top:1px solid var(--line); padding:12px 13px; font-size:12px; line-height:1.8; }
.answer-details p { margin:7px 0 0; color:var(--muted); }
.meta-line { color:var(--muted); font-size:10px; margin:7px 0 0; }
.quick-search { display:grid; align-content:center; justify-items:start; }
.quick-search h2 { margin:12px 0 5px; }
.quick-search p { color:var(--muted); line-height:1.8; font-size:12px; margin:0 0 14px; }

@media (max-width: 900px) {
  .streak-week { grid-template-columns:repeat(7,minmax(56px,1fr)); overflow-x:auto; padding-bottom:4px; }
  .section-number-grid.compact { grid-template-columns:repeat(3,1fr); }
}
@media (max-width: 620px) {
  .section-number-grid.compact { grid-template-columns:repeat(2,1fr); }
  .saved-actions { width:100%; justify-content:stretch; }
  .saved-actions .btn { flex:1; }
}

/* v4: cloud account + device hardening */
.profile-chip { color:var(--text); font:inherit; cursor:pointer; }
.profile-chip[data-cloud="synced"] .avatar { background:var(--success-soft); color:var(--success); }
.profile-chip[data-cloud="syncing"] .avatar { animation:cloudPulse 1s ease-in-out infinite alternate; }
.profile-chip[data-cloud="offline"] .avatar { background:var(--warning-soft); color:var(--warning); }
@keyframes cloudPulse { to { transform:scale(.9); opacity:.68; } }
.auth-modal code { direction:ltr; display:inline-block; background:var(--surface-2); border:1px solid var(--line); padding:2px 6px; border-radius:7px; }
.auth-form { display:grid; gap:12px; margin-top:18px; }
.auth-form label { display:grid; gap:7px; color:var(--muted); font-size:11px; font-weight:800; }
.auth-form input { width:100%; min-height:46px; border:1px solid var(--line); background:var(--surface-2); color:var(--text); border-radius:13px; padding:11px 13px; outline:0; direction:ltr; text-align:left; }
.auth-form label:first-child input:not([type="email"]):not([type="password"]) { direction:rtl; text-align:right; }
.auth-form input:focus { border-color:var(--primary); box-shadow:0 0 0 3px color-mix(in srgb,var(--primary) 12%,transparent); }
.auth-switch { width:100%; margin-top:12px; border:0; background:transparent; color:var(--primary); font-weight:800; cursor:pointer; padding:8px; }
.auth-error, .auth-success { margin-top:12px; min-height:20px; font-size:11px; line-height:1.7; }
.auth-error { color:var(--danger); }
.auth-success { color:var(--success); }
.account-hero { display:flex; align-items:center; gap:14px; }
.account-hero h3 { margin:7px 0 2px; }
.account-hero p { margin:0; direction:ltr; text-align:right; }
.avatar.big { width:58px; height:58px; border-radius:18px; font-size:22px; flex:0 0 auto; }
.sync-explain { margin-top:18px; background:var(--surface-2); border:1px solid var(--line); border-radius:14px; padding:14px; color:var(--muted); font-size:11px; line-height:1.9; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible { outline:3px solid color-mix(in srgb,var(--primary) 35%,transparent); outline-offset:2px; }
.modal { max-height:min(720px,calc(100vh - 32px)); overflow:auto; }

@media (max-width: 520px) {
  .top-actions { gap:7px; }
  .icon-btn { width:40px; height:40px; border-radius:12px; }
  .profile-chip { min-width:40px; min-height:40px; }
  .avatar { width:30px; height:30px; border-radius:10px; }
  .page-content { padding-inline:12px; }
  .card { padding:16px; }
  .stats-grid { gap:8px; }
  .stat-card { min-width:0; }
  .hero-actions .btn { flex:1 1 150px; }
  .section-head { align-items:flex-start; }
}

@media (max-width: 340px) {
  .stats-grid, .section-number-grid, .section-number-grid.compact { grid-template-columns:1fr; }
  .bottom-nav .nav-link { font-size:8px; }
  .bottom-nav .nav-icon { font-size:15px; }
  .topbar { gap:8px; }
}

@media (orientation: landscape) and (max-height: 520px) and (max-width: 900px) {
  .hero { min-height:190px; }
  .bottom-nav { padding-top:5px; padding-bottom:calc(5px + env(safe-area-inset-bottom)); }
  body { padding-bottom:calc(66px + env(safe-area-inset-bottom)); }
}


/* v6: study activity calendar */
.activity-calendar {
  display:grid; grid-template-columns:repeat(14,minmax(18px,1fr)); gap:7px; margin-top:8px;
}
.activity-day {
  aspect-ratio:1; min-width:0; border:1px solid var(--line); border-radius:8px; background:var(--surface-2);
  display:grid; place-items:center; font-size:9px; color:var(--muted); font-style:normal;
}
.activity-day.done { background:var(--primary); border-color:var(--primary); color:#fff; }
.activity-day.mini { width:14px; height:14px; display:inline-block; aspect-ratio:auto; border-radius:4px; vertical-align:middle; }
.activity-legend { margin-top:10px; display:flex; gap:14px; flex-wrap:wrap; font-size:10px; color:var(--muted); }
.activity-legend span { display:flex; align-items:center; gap:6px; }
@media (max-width:760px){ .activity-calendar{grid-template-columns:repeat(7,minmax(20px,1fr));gap:6px;} }
@media (max-width:390px){ .activity-calendar{gap:4px}.activity-day{border-radius:6px;font-size:8px} }

/* v7: section detail, flags, notes, goals */
.section-detail-hero{overflow:hidden;position:relative}
.section-detail-main{max-width:880px}
.section-detail-main h2{font-size:clamp(24px,4vw,38px);margin:14px 0 8px}
.section-detail-main>p{color:var(--muted);line-height:1.9;margin:0 0 14px}
.section-big-number{width:54px;height:54px;border-radius:17px;background:var(--primary);color:#fff;display:grid;place-items:center;font-size:22px;font-weight:900;box-shadow:0 10px 24px color-mix(in srgb,var(--primary) 22%,transparent)}
.section-action-grid{display:grid;grid-template-columns:1fr 1fr;gap:12px}
.action-tile{border:1px solid var(--line);background:var(--surface-2);color:var(--text);border-radius:16px;padding:17px;text-align:right;cursor:pointer;display:grid;gap:5px;min-height:88px}
.action-tile:hover:not(:disabled){border-color:var(--primary);transform:translateY(-1px)}
.action-tile:disabled{opacity:.48;cursor:not-allowed}
.action-tile strong{font-size:13px}.action-tile span{font-size:10px;color:var(--muted)}
.qnav.flagged{box-shadow:inset 0 0 0 2px var(--warning);position:relative}
.qnav.flagged::after{content:'•';position:absolute;top:-6px;left:-3px;color:var(--warning);font-size:19px}
.question-note{display:grid;gap:7px;margin-top:14px;color:var(--muted);font-size:10px;font-weight:800}
.question-note textarea{width:100%;min-height:86px;resize:vertical;border:1px solid var(--line);background:var(--surface);color:var(--text);border-radius:12px;padding:11px 12px;font:inherit;line-height:1.8;outline:0}
.question-note textarea:focus{border-color:var(--primary);box-shadow:0 0 0 3px color-mix(in srgb,var(--primary) 12%,transparent)}
.setting-select{min-width:130px;border:1px solid var(--line);background:var(--surface-2);color:var(--text);border-radius:11px;padding:9px 11px;font:inherit}
@media(max-width:700px){.section-action-grid{grid-template-columns:1fr}.section-big-number{width:46px;height:46px;border-radius:14px;font-size:19px}.test-actions{display:grid;grid-template-columns:1fr 1fr}.test-actions .btn:last-child{grid-column:1/-1}.section-detail-main .hero-actions{display:grid;grid-template-columns:1fr}.section-detail-main .hero-actions .btn{width:100%}}
@media(max-width:420px){.test-actions{grid-template-columns:1fr}.test-actions .btn:last-child{grid-column:auto}.question-note textarea{min-height:74px}}

/* v8: daily study plan + richer activity intensity */
.goal-meter { display:grid; gap:9px; margin-top:10px; }
.goal-meter-head { display:flex; align-items:center; justify-content:space-between; gap:12px; font-size:11px; }
.goal-meter-head span { color:var(--muted); font-weight:900; }
.compact-actions { margin-top:16px; }
.streak-day b { font-size:9px; color:var(--muted); font-weight:900; }
.today-hero { display:flex; align-items:center; justify-content:space-between; gap:24px; overflow:hidden; }
.today-hero h2 { margin:10px 0 7px; font-size:clamp(24px,4vw,38px); }
.today-hero p { margin:0; color:var(--muted); }
.today-rings { display:flex; gap:12px; flex:0 0 auto; }
.mini-ring { --score:0; width:92px; height:92px; border-radius:50%; display:grid; place-items:center; align-content:center; background:conic-gradient(var(--primary) calc(var(--score)*1%),var(--line) 0); position:relative; isolation:isolate; }
.mini-ring::before { content:""; position:absolute; inset:9px; border-radius:50%; background:var(--surface); z-index:-1; }
.mini-ring strong { font-size:18px; }
.mini-ring small { color:var(--muted); font-size:9px; margin-top:2px; }
.progress-bar.big { height:12px; }
.plan-grid { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:12px; }
.plan-card { display:grid; align-content:start; gap:10px; min-height:190px; }
.plan-card.priority { border-color:color-mix(in srgb,var(--warning) 45%,var(--line)); background:linear-gradient(180deg,color-mix(in srgb,var(--warning-soft) 55%,var(--surface)),var(--surface)); }
.plan-card h3 { margin:0; font-size:16px; }
.plan-card p { margin:0 0 4px; color:var(--muted); font-size:11px; line-height:1.9; }
.plan-card .btn { margin-top:auto; justify-self:start; }
.activity-day.level-0 { background:var(--surface-2); border-color:var(--line); color:var(--muted); box-shadow:none; }
.activity-day.level-1 { background:color-mix(in srgb,var(--primary) 35%,var(--surface)); border-color:color-mix(in srgb,var(--primary) 42%,var(--line)); color:var(--text); }
.activity-day.level-2 { background:color-mix(in srgb,var(--primary) 70%,var(--surface)); border-color:var(--primary); color:#fff; }
.activity-day.level-3 { background:var(--primary); border-color:var(--primary); color:#fff; box-shadow:0 4px 10px color-mix(in srgb,var(--primary) 22%,transparent); }
@media(max-width:980px){.plan-grid{grid-template-columns:repeat(2,minmax(0,1fr))}}
@media(max-width:760px){.bottom-nav{grid-template-columns:repeat(6,1fr)}.today-hero{align-items:flex-start}.today-rings{gap:8px}.mini-ring{width:74px;height:74px}.mini-ring::before{inset:7px}.mini-ring strong{font-size:15px}.plan-grid{grid-template-columns:1fr}}
@media(max-width:520px){.today-hero{display:grid}.today-rings{width:100%;justify-content:flex-start}.plan-card{min-height:0}.streak-day b{display:none}}
