:root {
  --sidebar-width: 260px;
  --surface: #ffffff;
  --surface-muted: #f8f9fc;
  --surface-accent: #eef0ff;
  --page-bg: #f5f7fb;
  --ink: #192033;
  --border-color: #e4e8f2;
  --muted-ink: #77809a;
  --primary: #5b67f1;
}

[data-bs-theme="dark"] {
  color-scheme: dark;
  --surface: #20283a;
  --surface-muted: #252f43;
  --surface-accent: #303a62;
  --page-bg: #151b29;
  --ink: #e8ecf5;
  --border-color: #3b465d;
  --muted-ink: #aab4c8;
  --primary: #7c86ff;
}

body {
  background: var(--page-bg);
  color: var(--ink);
  min-height: 100vh;
}

.sidebar {
  background: #111936;
  color: #fff;
  height: 100vh;
  overflow: hidden;
  position: fixed;
  width: var(--sidebar-width);
  z-index: 20;
}

.sidebar > .nav {
  flex: 1 1 auto;
  flex-wrap: nowrap;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding-bottom: .5rem;
  scrollbar-color: transparent transparent;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
}

.sidebar > .nav:hover,
.sidebar > .nav:focus-within {
  scrollbar-color: rgba(174, 183, 213, .65) transparent;
}

.sidebar > .nav::-webkit-scrollbar {
  width: 6px;
}

.sidebar > .nav::-webkit-scrollbar-track {
  background: transparent;
}

.sidebar > .nav::-webkit-scrollbar-thumb {
  background: transparent;
  border-radius: 999px;
}

.sidebar > .nav:hover::-webkit-scrollbar-thumb,
.sidebar > .nav:focus-within::-webkit-scrollbar-thumb {
  background: rgba(174, 183, 213, .65);
}

.sidebar > .dropdown {
  flex: 0 0 auto;
  margin-top: .75rem !important;
}

.sidebar .brand {
  color: #fff;
  font-size: 1.25rem;
  font-weight: 700;
  padding: .5rem 1rem;
}

.sidebar > .brand { flex: 0 0 auto; }

.brand-lockup { align-items: center; display: inline-flex; gap: .65rem; }
.brand-logo { display: block; flex: 0 0 auto; height: 2.5rem; object-fit: contain; width: 2.5rem; }
.brand-logo-sm { height: 2rem; width: 2rem; }

.sidebar .nav-link { color: #aeb7d5; padding: .72rem 1rem; }
.sidebar .nav-link:hover { color: #fff; background: rgba(255, 255, 255, .08); }
.sidebar .nav-link.active { background: var(--primary); color: #fff; }
.sidebar hr { border-color: #3a4467; }
.main-content { min-width: 0; min-height: 100vh; }

@media (min-width: 992px) {
  .main-content { margin-left: var(--sidebar-width); }
}

.mobile-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 10;
}

.card { border-radius: 1rem; }
.stat-card { transition: transform .18s ease, box-shadow .18s ease; }
.stat-card:hover { transform: translateY(-3px); }
.stat-icon { align-items: center; border-radius: .8rem; display: inline-flex; font-size: 1.25rem; height: 2.6rem; justify-content: center; width: 2.6rem; }
.chart-box { height: 290px; margin-top: 1rem; }
.question-card { border-left: 4px solid var(--primary) !important; }
.question-text { white-space: pre-line; }
.question-image { max-height: 36rem; object-fit: contain; }
.option-display, .study-option, .quiz-option { background: var(--surface-muted); border: 1px solid var(--border-color); border-radius: .75rem; padding: .8rem 1rem; }
.question-card [data-correct-option] { transition: background-color .18s ease, border-color .18s ease, box-shadow .18s ease; }
.question-card.answer-revealed [data-correct-option] { background: #dcfce7; border-color: #22c55e; box-shadow: 0 0 0 1px rgba(34, 197, 94, .16); color: #166534; }
.study-card, .quiz-wrap { max-width: 900px; margin-inline: auto; }
.study-option { display: flex; gap: .8rem; align-items: center; }
.option-letter { align-items: center; background: #e7e9ff; border-radius: 50%; color: #424cc0; display: inline-flex; flex: 0 0 2rem; font-weight: 700; height: 2rem; justify-content: center; }
.answer-panel { background: var(--surface); border: 1px solid var(--border-color); border-radius: .75rem; padding: 1rem; }
.ai-explanation-panel { border-color: var(--border-color); box-shadow: 0 10px 24px rgba(10, 14, 26, .18), 0 2px 6px rgba(10, 14, 26, .12); }
.ai-explanation-panel .ai-explanation-focus-group, .ai-explanation-panel .ai-option-content { margin-inline: auto; width: 97%; }
.ai-explanation-panel .ai-option-section { border-top: 1px solid var(--border-color); margin-top: .75rem; padding-top: .85rem; }
.ai-explanation-panel .ai-option-reasons { margin-top: 0; }
.ai-explanation-panel .ai-option-reason { background: var(--surface); }
.ai-explanation-panel .ai-section-title { align-items: center; color: #424cc0; display: flex; gap: .45rem; margin: 0 0 .75rem; }
.ai-explanation-panel .ai-section-icon { height: 1.15rem; stroke-width: 1.8; width: 1.15rem; }
.ai-explanation-panel .ai-insight-card { border: 1px solid var(--border-color); border-radius: .75rem; height: 100%; padding: 1rem; }
.ai-explanation-panel .ai-insight-card h5 { margin-bottom: .6rem; }
.ai-explanation-panel .ai-insight-knowledge { background: #fff0e8; border-color: #f6c8aa; }
.ai-explanation-panel .ai-insight-knowledge h5 { color: #a94f1d; }
.ai-explanation-panel .ai-insight-memory { background: #eaf4ff; border-color: #b9d9f7; }
.ai-explanation-panel .ai-insight-memory h5 { color: #245f96; }
.quiz-option { cursor: pointer; display: flex; align-items: center; transition: border-color .15s, background .15s; }
.quiz-option:hover, .quiz-option:has(input:checked) { background: #eef0ff; border-color: var(--primary); }
.score-ring { align-items: center; background: linear-gradient(145deg, #5b67f1, #7c3aed); border-radius: 50%; color: white; display: flex; flex-direction: column; height: 150px; justify-content: center; width: 150px; box-shadow: 0 12px 35px rgba(91, 103, 241, .3); }
.score-ring strong { font-size: 2.8rem; line-height: 1; }
.result-correct { border-left: 5px solid #22c55e !important; }
.result-wrong { border-left: 5px solid #ef4444 !important; }
.result-option { align-items: center; background: var(--surface-muted); border: 1px solid var(--border-color); border-radius: .75rem; display: flex; gap: .75rem; padding: .75rem 1rem; }
.result-option.is-correct { background: #ecfdf3; border-color: #22c55e; }
.result-option.is-selected-wrong { background: #fff1f2; border-color: #ef4444; }
.result-option-text { flex: 1 1 auto; min-width: 0; }
.result-option-labels { display: flex; flex: 0 0 auto; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }
.empty-state { background: var(--surface); border: 2px dashed var(--border-color); border-radius: 1rem; color: var(--muted-ink); padding: 4rem 1rem; text-align: center; }
.success-check { align-items: center; background: #dcfce7; border-radius: 50%; color: #16a34a; display: inline-flex; font-size: 3rem; height: 6rem; justify-content: center; width: 6rem; }
.sticky-submit { background: color-mix(in srgb, var(--surface) 94%, transparent); border: 1px solid var(--border-color); border-radius: 1rem; bottom: 1rem; box-shadow: 0 8px 30px rgba(10,14,26,.18); padding: 1rem; position: sticky; z-index: 5; }
.table > :not(caption) > * > * { padding: .9rem 1rem; }
.user-menu { background: rgba(255,255,255,.08); color: #fff; border: 1px solid rgba(255,255,255,.14); }
.user-menu:hover, .user-menu:focus { background: rgba(255,255,255,.14); color: #fff; }
.auth-body { background: radial-gradient(circle at top left, #e8eaff, #f8f9fc 48%, #eef6ff); }
.auth-card { max-width: 520px; border-radius: 1.25rem; }
.app-toast-container { max-width: 390px; width: 100%; z-index: 1090; }
.app-toast-container .toast { width: 100%; }
.auth-logo { display: block; height: 5rem; margin-inline: auto; object-fit: contain; width: 5rem; }
.captcha-box { align-items: center; background: #f3f4ff; border: 1px solid #dde1f4; border-radius: .75rem; display: flex; gap: .75rem; justify-content: center; padding: .45rem; }
.captcha-box img { height: 64px; max-width: 160px; }
.profile-email-card { align-items: center; background: var(--surface-muted); border: 1px solid var(--border-color); border-radius: .9rem; display: flex; gap: .9rem; padding: .9rem 1rem; }
.profile-email-icon { align-items: center; background: #e7e9ff; border-radius: .7rem; color: #424cc0; display: inline-flex; flex: 0 0 2.5rem; font-size: 1.15rem; height: 2.5rem; justify-content: center; }
.profile-email-details { align-items: center; display: flex; flex: 1 1 auto; flex-wrap: wrap; gap: .5rem .75rem; min-width: 0; }
.profile-email-address { font-weight: 600; overflow-wrap: anywhere; }
.profile-email-status { align-items: center; border-radius: 999px; display: inline-flex; flex: 0 0 auto; font-size: .78rem; font-weight: 700; gap: .3rem; padding: .3rem .6rem; }
.profile-email-status.is-verified { background: #dcfce7; color: #166534; }
.profile-email-status.is-unverified { background: #fef3c7; color: #92400e; }
.profile-email-action { flex: 0 0 auto; }
.study-guide-page { max-width: 980px; }
.study-guide-editor { resize: vertical; }
.study-guide-content { font-size: 1.04rem; line-height: 1.85; overflow-wrap: anywhere; }
.study-guide-content > :first-child { margin-top: 0; }
.study-guide-content > :last-child { margin-bottom: 0; }
.study-guide-content h1, .study-guide-content h2, .study-guide-content h3, .study-guide-content h4 { color: #29306f; font-weight: 700; margin-bottom: .8rem; margin-top: 2rem; }
.study-guide-content h1 { font-size: 1.8rem; }
.study-guide-content h2 { border-bottom: 1px solid var(--border-color); font-size: 1.5rem; padding-bottom: .55rem; }
.study-guide-content h3 { font-size: 1.25rem; }
.study-guide-content blockquote { background: #f3f4ff; border-left: 4px solid var(--primary); color: #475071; margin: 1.25rem 0; padding: .85rem 1rem; }
.study-guide-content pre { background: #171c2f; border-radius: .75rem; color: #f3f4ff; overflow-x: auto; padding: 1rem; }
.study-guide-content code { background: #eef0ff; border-radius: .3rem; color: #424cc0; padding: .12rem .3rem; }
.study-guide-content pre code { background: transparent; color: inherit; padding: 0; }
.study-guide-content table { border-collapse: collapse; display: block; margin: 1.25rem 0; max-width: 100%; overflow-x: auto; width: max-content; }
.study-guide-content th, .study-guide-content td { border: 1px solid var(--border-color); padding: .65rem .8rem; text-align: left; }
.study-guide-content th { background: var(--surface-accent); }

[data-bs-theme="dark"] .navbar.bg-white { background-color: var(--surface) !important; }
[data-bs-theme="dark"] .auth-body { background: radial-gradient(circle at top left, #252d54, #151b29 48%, #192638); }
[data-bs-theme="dark"] .option-letter,
[data-bs-theme="dark"] .profile-email-icon { background: #303a62; color: #b9c0ff; }
[data-bs-theme="dark"] .quiz-option:hover,
[data-bs-theme="dark"] .quiz-option:has(input:checked) { background: #303a62; }
[data-bs-theme="dark"] .question-card.answer-revealed [data-correct-option],
[data-bs-theme="dark"] .result-option.is-correct { background: #173b2b; color: #a7f3d0; }
[data-bs-theme="dark"] .result-option.is-selected-wrong { background: #48232d; color: #fecdd3; }
[data-bs-theme="dark"] .ai-explanation-panel .ai-insight-knowledge { background: #49301f; border-color: #87522e; }
[data-bs-theme="dark"] .ai-explanation-panel .ai-insight-knowledge h5 { color: #f6b88d; }
[data-bs-theme="dark"] .ai-explanation-panel .ai-insight-memory { background: #1c344d; border-color: #315f86; }
[data-bs-theme="dark"] .ai-explanation-panel .ai-insight-memory h5 { color: #a9d5ff; }
[data-bs-theme="dark"] .study-guide-content h1,
[data-bs-theme="dark"] .study-guide-content h2,
[data-bs-theme="dark"] .study-guide-content h3,
[data-bs-theme="dark"] .study-guide-content h4 { color: #c5caff; }
[data-bs-theme="dark"] .study-guide-content blockquote,
[data-bs-theme="dark"] .study-guide-content code { background: var(--surface-accent); color: #c5caff; }
[data-bs-theme="dark"] .study-guide-content pre code { background: transparent; color: inherit; }

@media (max-width: 575.98px) {
  .app-toast-container { left: 0; max-width: none; padding: .75rem !important; right: 0; }
  .sticky-submit { align-items: stretch !important; flex-direction: column; }
  .chart-box { height: 230px; }
  .profile-email-card { align-items: flex-start; flex-wrap: wrap; }
  .profile-email-details { align-items: flex-start; flex-direction: column; }
  .profile-email-action { margin-left: 3.4rem; }
  .result-option { align-items: flex-start; flex-wrap: wrap; }
  .result-option-text { flex-basis: calc(100% - 3rem); }
  .result-option-labels { padding-left: 2.75rem; width: 100%; }
}
