/* ==============================================================================
   QMH-KGMU ID & AMR Master Crash-Course Study Portal
   Aesthetic: Dieter Rams Functionalism, Apple Human Interface & Clinical Focus
   ============================================================================== */

:root {
  --sidebar-width: 320px;
  --topbar-height: 60px;
  --reading-max-width: 880px;

  /* Fonts */
  --font-serif: 'Newsreader', Georgia, Cambria, serif;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', Menlo, Monaco, Consolas, monospace;
  --font-reading: var(--font-serif);
}

/* 1. Obsidian Dark Theme (Default) */
[data-theme="dark"] {
  --bg-app: #080a0f;
  --bg-sidebar: #0d111a;
  --bg-surface: #131824;
  --bg-card: #182030;
  --bg-hover: #1f293d;
  --border: #232d42;
  --border-focus: #0284c7;

  --text-main: #f1f5f9;
  --text-muted: #94a3b8;
  --text-faint: #64748b;
  --text-code: #38bdf8;

  --accent: #0284c7;
  --accent-light: #38bdf8;
  --accent-glow: rgba(2, 132, 199, 0.18);
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #f43f5e;
  --accent-purple: #8b5cf6;

  --prose-body: #e2e8f0;
  --prose-heading: #ffffff;
  --prose-code-bg: #111622;

  --trap-bg: rgba(244, 63, 94, 0.08);
  --trap-border: #f43f5e;
  --pearl-bg: rgba(16, 185, 129, 0.08);
  --pearl-border: #10b981;
}

/* 2. Washi Sepia Theme */
[data-theme="sepia"] {
  --bg-app: #fbf9f4;
  --bg-sidebar: #f4ede2;
  --bg-surface: #eae0d0;
  --bg-card: #ffffff;
  --bg-hover: #e2d5c3;
  --border: #dcd0bc;
  --border-focus: #b45309;

  --text-main: #292524;
  --text-muted: #78716c;
  --text-faint: #a8a29e;
  --text-code: #b45309;

  --accent: #b45309;
  --accent-light: #d97706;
  --accent-glow: rgba(180, 83, 9, 0.12);
  --accent-green: #059669;
  --accent-amber: #d97706;
  --accent-rose: #e11d48;
  --accent-purple: #7c3aed;

  --prose-body: #292524;
  --prose-heading: #1c1917;
  --prose-code-bg: #f5efe6;

  --trap-bg: #fff1f2;
  --trap-border: #e11d48;
  --pearl-bg: #f0fdf4;
  --pearl-border: #059669;
}

/* 3. Clinical Light Theme */
[data-theme="light"] {
  --bg-app: #f8fafc;
  --bg-sidebar: #ffffff;
  --bg-surface: #f1f5f9;
  --bg-card: #ffffff;
  --bg-hover: #e2e8f0;
  --border: #cbd5e1;
  --border-focus: #0284c7;

  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --text-code: #0284c7;

  --accent: #0284c7;
  --accent-light: #0369a1;
  --accent-glow: rgba(2, 132, 199, 0.12);
  --accent-green: #10b981;
  --accent-amber: #f59e0b;
  --accent-rose: #ef4444;
  --accent-purple: #8b5cf6;

  --prose-body: #1e293b;
  --prose-heading: #0f172a;
  --prose-code-bg: #f1f5f9;

  --trap-bg: #fef2f2;
  --trap-border: #ef4444;
  --pearl-bg: #f0fdf4;
  --pearl-border: #10b981;
}

/* Global Reset */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

/* Top Reading Progress Bar */
#reading-progress-bar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
  z-index: 1000;
  transition: width 0.1s ease-out;
}

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

/* Top Header Bar */
#topbar {
  position: fixed;
  top: 0;
  left: var(--sidebar-width);
  right: 0;
  height: var(--topbar-height);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 900;
  backdrop-filter: blur(12px);
  transition: left 0.25s ease;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Route Mode Toggle (120m vs 60m) */
.route-selector {
  display: flex;
  background: var(--bg-app);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px;
}

.route-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 16px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 5px;
}

.route-btn.active {
  background: var(--accent);
  color: #ffffff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.2);
}

/* Study Timer Widget */
.timer-widget {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 10px;
  border-radius: 8px;
}

.timer-display {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--accent-light);
  min-width: 50px;
  text-align: center;
}

.timer-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2px;
  border-radius: 4px;
  transition: color 0.15s ease;
}

.timer-btn:hover {
  color: var(--text-main);
}

/* 3-Pass Active Recall Toggle */
.recall-switch-wrapper {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 4px 12px;
  border-radius: 20px;
  cursor: pointer;
  user-select: none;
}

.recall-switch-wrapper:hover {
  border-color: var(--border-focus);
}

.switch-indicator {
  width: 28px;
  height: 16px;
  background: var(--border);
  border-radius: 10px;
  position: relative;
  transition: background 0.2s ease;
}

.switch-indicator::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: #ffffff;
  border-radius: 50%;
  transition: transform 0.2s ease;
}

.switch-active .switch-indicator {
  background: var(--accent-rose);
}

.switch-active .switch-indicator::after {
  transform: translateX(12px);
}

/* Header Action Buttons */
.icon-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.2s ease;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-focus);
}

.icon-btn.active {
  background: var(--accent-glow);
  color: var(--accent-light);
  border-color: var(--accent);
}

/* Sidebar */
#sidebar {
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  width: var(--sidebar-width);
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 950;
  transition: transform 0.25s ease;
}

.sidebar-header {
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-badge {
  width: 36px;
  height: 36px;
  background: linear-gradient(135deg, var(--accent) 0%, #0369a1 100%);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-title {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--text-main);
}

.brand-sub {
  font-size: 10.5px;
  color: var(--text-faint);
  font-weight: 500;
}

/* Quick Resume Card */
.resume-card {
  margin: 12px 14px;
  padding: 10px 12px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.resume-card:hover {
  border-color: var(--border-focus);
  background: var(--bg-card);
}

.resume-icon {
  color: var(--accent-light);
}

.resume-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.resume-label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-faint);
}

.resume-chapter {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Sidebar Navigation */
#sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px 24px 12px;
}

.nav-section-title {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  padding: 12px 8px 6px 8px;
}

.chapter-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 500;
  transition: all 0.15s ease;
  margin-bottom: 2px;
}

.chapter-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.chapter-btn.active {
  background: var(--bg-card);
  color: var(--accent-light);
  font-weight: 600;
  border-left: 3px solid var(--accent);
}

.chapter-badge {
  font-size: 9.5px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  background: var(--bg-surface);
  color: var(--text-faint);
  border: 1px solid var(--border);
}

.chapter-btn.active .chapter-badge {
  background: var(--accent-glow);
  color: var(--accent-light);
  border-color: var(--accent);
}

/* Interactive Labs List in Sidebar */
.lab-btn {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 7px 10px;
  border-radius: 6px;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.15s ease;
  margin-bottom: 2px;
}

.lab-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.lab-btn.active {
  background: var(--bg-card);
  color: var(--accent-amber);
  font-weight: 600;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.footer-btn {
  flex: 1;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 8px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.footer-btn:hover {
  background: var(--bg-card);
  color: var(--text-main);
  border-color: var(--border-focus);
}

/* Main Content Area */
#main-content {
  margin-left: var(--sidebar-width);
  margin-top: var(--topbar-height);
  flex: 1;
  min-height: calc(100vh - var(--topbar-height));
  display: flex;
  flex-direction: column;
  transition: margin-left 0.25s ease;
}

.content-wrapper {
  max-width: var(--reading-max-width);
  width: 100%;
  margin: 0 auto;
  padding: 40px 24px 100px 24px;
}

/* Editorial Reading Typography */
.prose {
  font-family: var(--font-reading);
  font-size: 18px;
  line-height: 1.7;
  color: var(--prose-body);
}

[data-font="sans"] .prose {
  font-family: var(--font-sans);
  font-size: 16.5px;
  line-height: 1.65;
}

.prose h1, .prose h2, .prose h3, .prose h4 {
  font-family: var(--font-sans);
  color: var(--prose-heading);
  font-weight: 700;
  margin-top: 36px;
  margin-bottom: 14px;
  line-height: 1.3;
}

.prose h1 {
  font-size: 28px;
  border-bottom: 2px solid var(--accent);
  padding-bottom: 8px;
  margin-top: 0;
  color: var(--accent-light);
}

.prose h2 {
  font-size: 22px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.prose h3 {
  font-size: 18px;
  color: var(--text-main);
}

.prose p {
  margin-bottom: 16px;
}

.prose ul, .prose ol {
  margin-bottom: 18px;
  padding-left: 24px;
}

.prose li {
  margin-bottom: 6px;
}

.prose strong {
  font-family: var(--font-sans);
  font-weight: 600;
  color: var(--text-main);
}

.prose code {
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--prose-code-bg);
  color: var(--text-code);
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.prose pre {
  background: var(--prose-code-bg);
  border: 1px solid var(--border);
  padding: 16px;
  border-radius: 8px;
  overflow-x: auto;
  margin-bottom: 20px;
}

.prose pre code {
  background: transparent;
  padding: 0;
  border: none;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-main);
}

.prose blockquote {
  border-left: 4px solid var(--accent);
  background: var(--bg-card);
  padding: 12px 18px;
  border-radius: 0 8px 8px 0;
  margin: 18px 0;
  color: var(--text-muted);
  font-size: 16px;
}

/* Tables */
.prose table {
  width: 100%;
  border-collapse: collapse;
  margin: 20px 0;
  font-size: 14px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.prose th {
  font-family: var(--font-sans);
  font-weight: 700;
  background: var(--bg-card);
  color: var(--text-main);
  text-align: left;
  padding: 10px 12px;
  border-bottom: 2px solid var(--border);
}

.prose td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.prose tr:nth-child(even) {
  background: var(--bg-app);
}

.prose tr:hover {
  background: var(--bg-hover);
}

/* 3-Pass Active Recall Blur Effect */
.blind-recall-active td:last-child,
.blind-recall-active .recall-blur {
  filter: blur(6px);
  user-select: none;
  cursor: pointer;
  transition: filter 0.2s ease;
}

.blind-recall-active td:last-child:hover,
.blind-recall-active td:last-child:active,
.blind-recall-active .recall-blur:hover,
.blind-recall-active .recall-blur:active,
.revealed {
  filter: none !important;
}

/* High-Yield Alert Callouts */
.callout-trap {
  background: var(--trap-bg);
  border: 1px solid var(--trap-border);
  border-left: 5px solid var(--trap-border);
  border-radius: 8px;
  padding: 16px 18px;
  margin: 20px 0;
}

.callout-trap-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent-rose);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.callout-pearl {
  background: var(--pearl-bg);
  border: 1px solid var(--pearl-border);
  border-left: 5px solid var(--pearl-border);
  border-radius: 8px;
  padding: 16px 18px;
  margin: 20px 0;
}

.callout-pearl-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-sans);
  font-size: 13.5px;
  font-weight: 700;
  color: var(--accent-green);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

/* Organism Atlas Revision Cards */
.organism-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 18px;
  margin-top: 20px;
}

.organism-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  transition: all 0.2s ease;
}

.organism-card:hover {
  border-color: var(--border-focus);
  box-shadow: 0 4px 16px rgba(0,0,0,0.15);
}

.org-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.org-card-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent-light);
}

.org-badge {
  font-size: 10.5px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 12px;
  text-transform: uppercase;
}

.badge-gram-pos {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

.badge-gram-neg {
  background: rgba(244, 63, 94, 0.15);
  color: #fb7185;
  border: 1px solid rgba(244, 63, 94, 0.3);
}

.badge-fungi {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.badge-atypical {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.org-fields-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 12px;
  font-size: 13.5px;
}

.org-field {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
}

.org-field-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-faint);
  margin-bottom: 3px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.org-field-val {
  color: var(--text-main);
}

/* Modals & Interactive Dashboards */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 1200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-container {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 900px;
  width: 100%;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 48px rgba(0,0,0,0.4);
}

.modal-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 10px;
}

.modal-close-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.modal-body {
  padding: 24px;
  overflow-y: auto;
  flex: 1;
}

/* 50-Question Buzzer Quiz Engine */
.quiz-wrapper {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
}

.quiz-top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 14px;
}

.quiz-metric-box {
  display: flex;
  align-items: center;
  gap: 16px;
}

.quiz-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
}

.quiz-question-stem {
  font-size: 18px;
  font-weight: 600;
  line-height: 1.5;
  color: var(--text-main);
  margin-bottom: 24px;
}

.quiz-options-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 24px;
}

.quiz-opt-btn {
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 18px;
  color: var(--text-main);
  font-family: var(--font-sans);
  font-size: 14.5px;
  line-height: 1.4;
  cursor: pointer;
  transition: all 0.15s ease;
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.quiz-opt-btn:hover:not(:disabled) {
  border-color: var(--border-focus);
  background: var(--bg-hover);
}

.quiz-opt-letter {
  font-weight: 700;
  color: var(--accent-light);
  min-width: 20px;
}

.quiz-opt-btn.correct {
  background: rgba(16, 185, 129, 0.15) !important;
  border-color: #10b981 !important;
  color: #34d399 !important;
}

.quiz-opt-btn.wrong {
  background: rgba(244, 63, 94, 0.15) !important;
  border-color: #f43f5e !important;
  color: #fb7185 !important;
}

.quiz-explanation-box {
  background: var(--bg-card);
  border-left: 4px solid var(--accent);
  padding: 16px 18px;
  border-radius: 0 8px 8px 0;
  margin-top: 20px;
  font-size: 14px;
  line-height: 1.55;
}

.quiz-explanation-title {
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Mobile Responsiveness */
@media (max-width: 900px) {
  :root {
    --sidebar-width: 280px;
  }

  #topbar {
    left: 0;
  }

  #sidebar {
    transform: translateX(-100%);
  }

  #sidebar.mobile-open {
    transform: translateX(0);
  }

  #main-content {
    margin-left: 0;
  }

  .sidebar-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 940;
    display: none;
  }

  .sidebar-backdrop.active {
    display: block;
  }
}
