/* ============================================================
   Visual MBE Prep — Design System v2
   Philosophy: Calm, intelligent, psychologically supportive.
   "Structured understanding under pressure."
   
   Designed for stressed, fatigued bar takers in long sessions.
   Prioritize: readability, cognitive ease, confidence restoration.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Instrument+Serif:ital@0;1&family=Inter:wght@300;400;500;600&family=JetBrains+Mono:wght@400;500&display=swap');

:root {
  /* ── Backgrounds — warm, not clinical ── */
  --bg:           #f7f6f3;   /* warm off-white, easy on fatigued eyes */
  --bg2:          #ffffff;
  --bg3:          #f2f1ee;
  --bg4:          #eae9e5;
  --bg5:          #e0dfd9;

  /* ── Navy — sidebar, header. Authoritative, calm ── */
  --navy:         #4a5f8a;
  --navy2:        #5a7099;
  --navy3:        #6a80a8;
  --navy-dim:     rgba(74,95,138,0.08);
  --navy-border:  rgba(74,95,138,0.18);

  /* ── Slate-teal accent — calm, intelligent, not alarming ── */
  --accent:       #3d6b8e;   /* muted slate blue — reduces anxiety vs gold */
  --accent-light: #4d7fa5;
  --accent-dim:   rgba(61,107,142,0.09);
  --accent-border:rgba(61,107,142,0.22);

  /* ── Sage green — mastery. Calm achievement, not loud success ── */
  --green:        #3a7055;
  --green-light:  #4a8a6a;
  --green-dim:    rgba(58,112,85,0.09);
  --green-border: rgba(58,112,85,0.22);
  --green-text:   #2d5941;

  /* ── Soft amber — needs more study. Not "wrong", not alarming ── */
  --amber:        #8a6520;
  --amber-dim:    rgba(138,101,32,0.08);
  --amber-border: rgba(138,101,32,0.20);

  /* ── Muted terracotta — caution notes. Softer than red ── */
  --caution:      #9b4e3a;
  --caution-dim:  rgba(155,78,58,0.07);
  --caution-border:rgba(155,78,58,0.18);

  /* ── Text — warm dark, not harsh black ── */
  --text:         #1c1c2e;
  --text2:        #3a3a52;
  --text3:        #7a7a96;
  --text4:        #b0b0c4;

  /* ── Borders — subtle, not grid-like ── */
  --border:       rgba(74,95,138,0.09);
  --border2:      rgba(74,95,138,0.15);
  --border3:      rgba(74,95,138,0.22);

  /* ── Shadows — soft depth, not dramatic ── */
  --shadow-sm:    0 1px 4px rgba(30,45,74,0.07), 0 1px 2px rgba(30,45,74,0.04);
  --shadow-md:    0 4px 14px rgba(30,45,74,0.09), 0 2px 4px rgba(30,45,74,0.05);
  --shadow-lg:    0 8px 32px rgba(30,45,74,0.11), 0 4px 8px rgba(30,45,74,0.05);

  /* ── Typography ── */
  --serif:        'Instrument Serif', Georgia, serif;
  --sans:         'Inter', system-ui, sans-serif;
  --mono:         'JetBrains Mono', monospace;

  /* ── Spacing ── */
  --radius:       8px;
  --radius-lg:    12px;
  --transition:   0.15s ease;

  /* ── Readability — generous for long sessions ── */
  --line-height:  1.80;
  --font-size:    16px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: var(--font-size);
  line-height: var(--line-height);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

/* ── SCROLLBAR — unobtrusive ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg5); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text4); }

/* ── LAYOUT ── */
#app { display: grid; grid-template-rows: auto 1fr; min-height: 100dvh; }

/* ── TOP NAV ── */
.top-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  height: 54px;
  background: var(--navy);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 12px rgba(30,45,74,0.18);
}

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

.nav-logo {
  font-family: var(--serif);
  font-size: 18px;
  color: #ffffff;
  letter-spacing: -0.01em;
  font-weight: 400;
}

.nav-logo em {
  font-style: italic;
  color: #a8c8e8;   /* soft blue — calm, not gold/urgent */
}

.nav-badge {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #a8c8e8;
  background: rgba(168,200,232,0.12);
  border: 1px solid rgba(168,200,232,0.25);
  padding: 2px 8px;
  border-radius: 3px;
}

.nav-right { display: flex; align-items: center; gap: 14px; }

.nav-progress-text {
  font-family: var(--mono);
  font-size: 10px;
  color: rgba(255,255,255,0.45);
  letter-spacing: 0.08em;
}

.nav-progress-bar {
  width: 80px; height: 3px;
  background: rgba(255,255,255,0.12);
  border-radius: 2px; overflow: hidden;
}

.nav-progress-fill {
  height: 100%;
  background: #a8c8e8;
  border-radius: 2px;
  transition: width 0.6s ease;
  width: 0%;
}

/* ── MAIN LAYOUT ── */
.main-layout {
  display: grid;
  grid-template-columns: 230px 1fr;
  height: calc(100dvh - 54px);
}

/* ── SIDEBAR ── */
.sidebar {
  background: var(--navy);
  border-right: 1px solid rgba(255,255,255,0.06);
  overflow-y: auto;
  padding: 20px 0;
}

.sidebar-section { margin-bottom: 4px; }

.sidebar-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.25);
  padding: 0 18px;
  margin-bottom: 10px;
}

.subject-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 9px 18px;
  font-size: 14.5px;
  font-weight: 500;
  color: rgba(255,255,255,0.60);
  background: transparent;
  border: none;
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
  position: relative;
  line-height: 1.4;
}

.subject-btn:hover {
  color: rgba(255,255,255,0.90);
  background: rgba(255,255,255,0.06);
}

.subject-btn.active {
  color: #a8c8e8;
  background: rgba(168,200,232,0.10);
}

.subject-btn.active::before {
  content: '';
  position: absolute;
  left: 0; top: 0;
  height: 100%; width: 3px;
  background: #a8c8e8;
  border-radius: 0 2px 2px 0;
}

.cluster-list { padding: 2px 0 8px 28px; }

.cluster-btn {
  display: block;
  width: 100%;
  text-align: left;
  padding: 5px 12px;
  font-size: 12px;
  color: rgba(255,255,255,0.38);
  background: transparent;
  border: none;
  cursor: pointer;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
  line-height: 1.45;
}

.cluster-btn:hover {
  color: rgba(255,255,255,0.75);
  background: rgba(255,255,255,0.06);
}

.cluster-btn.active {
  color: #a8c8e8;
  background: rgba(168,200,232,0.10);
}

/* ── CONTENT AREA ── */
.content-area { overflow-y: auto; background: var(--bg); }

/* ── SUBJECT HEADER ── */
.subject-header {
  padding: 24px 32px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  box-shadow: var(--shadow-sm);
}

.subject-eyebrow {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 4px;
}

.subject-title {
  font-family: var(--serif);
  font-size: 22px;
  font-weight: 400;
  color: var(--navy);
  line-height: 1.2;
}

/* ── CLUSTER TABS ── */
.cluster-tabs {
  display: flex;
  gap: 6px;
  padding: 12px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  overflow-x: auto;
  scrollbar-width: none;
}

.cluster-tabs::-webkit-scrollbar { display: none; }

.cluster-tab {
  flex-shrink: 0;
  padding: 5px 16px;
  font-size: 12px;
  font-weight: 500;
  color: var(--text3);
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}

.cluster-tab:hover {
  color: var(--navy);
  border-color: var(--accent-border);
  background: var(--bg4);
}

.cluster-tab.active {
  color: var(--accent);
  background: var(--accent-dim);
  border-color: var(--accent-border);
  font-weight: 600;
}

/* ── RULE GRID ── */
.rule-grid-wrap { padding: 24px 32px; }

.rule-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

/* ── RULE CARD ── */
.rule-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: pointer;
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

.rule-card:hover {
  border-color: var(--accent-border);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.rule-card.mastered {
  border-color: var(--green-border);
  background: #f8fdf9;
}

.rule-card.needs-review {
  border-color: var(--amber-border);
  background: #fdfbf6;
}

/* Card header */
.card-header {
  padding: 13px 14px 8px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.card-title {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--navy);
  line-height: 1.4;
  flex: 1;
}

.card-citation {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent-border);
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
  flex-shrink: 0;
  margin-top: 1px;
}

/* Card image zone */
.card-image {
  height: 110px;
  background: var(--bg3);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
  margin: 0 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.card-image img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.card-image.mastered-img img { opacity: 0.40; }
.card-emoji { font-size: 38px; line-height: 1; opacity: 0.40; }

.mastered-badge {
  position: absolute; top: 8px; right: 8px;
  font-family: var(--mono); font-size: 8px;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--green-text);
  background: rgba(58,112,85,0.10);
  border: 1px solid var(--green-border);
  padding: 2px 7px; border-radius: 3px;
}

.review-badge {
  position: absolute; top: 8px; right: 8px;
  font-family: var(--mono); font-size: 8px;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--amber);
  background: var(--amber-dim);
  border: 1px solid var(--amber-border);
  padding: 2px 7px; border-radius: 3px;
}

/* Card actions — forward-looking language, not grading language */
.card-actions {
  display: flex;
  gap: 6px;
  padding: 10px 14px 13px;
}

.btn-got-it, .btn-review {
  flex: 1;
  padding: 6px 0;
  font-size: 10px;
  font-family: var(--mono);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 5px;
  border: 1px solid;
  cursor: pointer;
  transition: all var(--transition);
  background: transparent;
}

.btn-got-it {
  color: var(--green-text);
  border-color: var(--green-border);
}

.btn-got-it:hover, .btn-got-it.active { background: var(--green-dim); }

.btn-review {
  color: var(--amber);
  border-color: var(--amber-border);
}

.btn-review:hover, .btn-review.active { background: var(--amber-dim); }

/* ── DRILL-DOWN PANEL ── */
.drill-overlay {
  position: fixed; inset: 0;
  background: rgba(30,45,74,0.30);
  backdrop-filter: blur(2px);
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.22s ease;
}

.drill-overlay.open { opacity: 1; pointer-events: all; }

.drill-panel {
  position: fixed;
  top: 54px; bottom: 0; right: 0;
  width: 52%; max-width: 640px;
  background: var(--bg2);
  border-left: 1px solid var(--border2);
  z-index: 210;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  overflow: hidden;
  box-shadow: var(--shadow-lg);
}

.drill-panel.open { transform: translateX(0); }

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

.drill-title {
  font-family: var(--serif);
  font-size: 19px;
  font-weight: 400;
  color: #ffffff;
  line-height: 1.3;
  flex: 1;
  padding-right: 16px;
}

.drill-close {
  width: 32px; height: 32px;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.16);
  border-radius: 6px;
  cursor: pointer;
  color: rgba(255,255,255,0.60);
  font-size: 16px; flex-shrink: 0;
  transition: all var(--transition);
}

.drill-close:hover { color: #ffffff; background: rgba(255,255,255,0.15); }

.drill-body { overflow-y: auto; flex: 1; }

.drill-section {
  padding: 22px 24px;
  border-bottom: 1px solid var(--border);
}

.drill-section:last-child { border-bottom: none; }

.drill-section-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text4);
  margin-bottom: 12px;
}

.drill-rule-text {
  font-size: 16px;
  color: var(--text2);
  line-height: 1.80;   /* generous for fatigued readers */
}

.drill-rule-text strong { color: var(--text); font-weight: 600; }

/* Flowchart */
.flowchart { display: flex; flex-direction: column; gap: 0; }

.flow-item { display: flex; align-items: flex-start; gap: 12px; }

.flow-connector {
  display: flex; flex-direction: column;
  align-items: center; flex-shrink: 0;
}

.flow-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0; margin-top: 7px;
}

.flow-line {
  width: 1px; flex: 1;
  min-height: 16px;
  background: var(--border2);
  margin: 2px 0;
}

.flow-text {
  font-size: 15px;
  color: var(--text2);
  line-height: 1.70;
  padding-bottom: 14px;
}

.flow-text strong { color: var(--text); font-weight: 600; }

/* Watch For (formerly Exam Traps — renamed to reduce anxiety) */
.trap-item {
  display: flex;
  gap: 10px; align-items: flex-start;
  padding: 11px 14px;
  background: var(--caution-dim);
  border: 1px solid var(--caution-border);
  border-left: 3px solid var(--caution);
  border-radius: 7px;
  margin-bottom: 8px;
}

.trap-icon { font-size: 14px; flex-shrink: 0; margin-top: 2px; }

.trap-text { font-size: 15px; color: var(--text2); line-height: 1.60; }

/* Common Mistakes (formerly Wrong Answers) */
.wrong-item {
  display: flex;
  gap: 10px; align-items: flex-start;
  padding: 11px 14px;
  background: var(--amber-dim);
  border: 1px solid var(--amber-border);
  border-left: 3px solid var(--amber);
  border-radius: 7px;
  margin-bottom: 8px;
}

/* Memory hook — warm, inviting, not clinical */
.memory-hook {
  background: #f4f8f4;
  border: 1px solid var(--green-border);
  border-left: 3px solid var(--green);
  border-radius: 8px;
  padding: 18px 20px;
}

.hook-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--green-text);
  margin-bottom: 10px;
}

.hook-text {
  font-family: var(--serif);
  font-style: italic;
  font-size: 16px;
  color: var(--navy);
  line-height: 1.65;
}

/* Citation */
.citation-tag {
  display: inline-block;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--navy);
  background: var(--navy-dim);
  border: 1px solid var(--navy-border);
  padding: 4px 12px;
  border-radius: 4px;
  text-decoration: none;
  transition: background var(--transition);
}

a.citation-tag:hover { background: rgba(30,45,74,0.12); }

/* ── AI TUTOR ── */
.ai-tutor-section {
  padding: 18px 24px;
  border-top: 2px solid var(--border);
  background: var(--bg3);
  flex-shrink: 0;
}

.ai-tutor-label {
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text4);
  margin-bottom: 10px;
}

.ai-chat-window {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 60px; max-height: 180px;
  overflow-y: auto;
  padding: 12px 14px;
  font-size: 15px;
  color: var(--text2);
  line-height: 1.70;
  margin-bottom: 10px;
}

.ai-chat-window.empty {
  color: var(--text4);
  font-style: italic;
  font-size: 12px;
}

.ai-input-row { display: flex; gap: 8px; }

.ai-input {
  flex: 1;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 7px;
  padding: 9px 12px;
  font-size: 15px;
  color: var(--text);
  font-family: var(--sans);
  transition: border-color var(--transition);
  outline: none;
}

.ai-input:focus { border-color: var(--accent-border); }
.ai-input::placeholder { color: var(--text4); }

.ai-send-btn {
  padding: 9px 16px;
  background: var(--navy);
  border: none;
  border-radius: 7px;
  color: #ffffff;
  font-size: 12px;
  font-family: var(--mono);
  letter-spacing: 0.08em;
  cursor: pointer;
  transition: background var(--transition);
}

.ai-send-btn:hover { background: var(--navy2); }
.ai-send-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ── LOADING / ERROR STATES ── */
.state-loading, .state-empty, .state-error {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px 32px;
  text-align: center; color: var(--text3); gap: 12px;
}

.state-loading .spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.state-label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.state-error .state-label { color: var(--caution); }

/* ── EMPTY SELECTION ── */
.empty-selection {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; color: var(--text3); gap: 16px;
}

.empty-glyph { font-size: 48px; opacity: 0.20; }

.empty-title {
  font-family: var(--serif);
  font-size: 20px; font-weight: 400;
  color: var(--text2);
}

.empty-sub {
  font-size: 15px; color: var(--text3);
  max-width: 300px; text-align: center;
  line-height: 1.70;
}

/* ── PROGRESS STRIP ── */
.progress-bar-strip {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 32px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  font-size: 12px; color: var(--text3);
}

.pbs-label {
  font-family: var(--mono);
  font-size: 9px; letter-spacing: 0.12em;
  text-transform: uppercase; color: var(--text4);
}

.pbs-bar {
  flex: 1; max-width: 200px;
  height: 4px; background: var(--bg4);
  border-radius: 2px; overflow: hidden;
}

.pbs-fill {
  height: 100%; background: var(--green);
  border-radius: 2px; transition: width 0.5s ease;
}

.pbs-count { font-family: var(--mono); font-size: 11px; }
.pbs-count .got { color: var(--green-text); }
.pbs-count .review { color: var(--amber); }

/* ── RESPONSIVE ── */
@media (max-width: 1100px) {
  .rule-grid { grid-template-columns: repeat(2, 1fr); }
  .drill-panel { width: 65%; }
}

@media (max-width: 768px) {
  .main-layout { grid-template-columns: 1fr; }
  .sidebar {
    display: none; position: fixed;
    top: 54px; left: 0; bottom: 0;
    z-index: 150; width: 260px;
    box-shadow: 8px 0 32px rgba(30,45,74,0.18);
  }
  .sidebar.mobile-open { display: block; }
  .rule-grid { grid-template-columns: 1fr 1fr; }
  .drill-panel { width: 92%; }
}

@media (max-width: 520px) {
  .rule-grid { grid-template-columns: 1fr; }
  .rule-grid-wrap { padding: 16px; }
  .subject-header, .cluster-tabs, .progress-bar-strip { padding-left: 16px; padding-right: 16px; }
}
