/* ===================================================================
   Learner — "Precision Instruments" theme
   Day: architect's drafting table. Night: midnight lab.
   =================================================================== */

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

/* --- Dark theme (default) --- */
:root, [data-theme="dark"] {
  --font-body: 'Inter', system-ui, -apple-system, sans-serif;
  --font-code: 'JetBrains Mono', monospace;

  --bg:              #080b14;
  --bg-warm:         #0a0d17;
  --surface:         rgba(210, 180, 120, 0.04);
  --surface-hover:   rgba(210, 180, 120, 0.07);
  --surface-border:  rgba(210, 180, 120, 0.10);
  --surface-border-hover: rgba(210, 180, 120, 0.22);

  --text-primary:    #f0ece4;
  --text-body:       #c4bfb4;
  --text-secondary:  #7e7a70;
  --text-muted:      #4a4740;

  --accent:          #d4a04a;
  --accent-bright:   #e8b65c;
  --accent-dim:      rgba(212, 160, 74, 0.12);
  --accent-glow:     rgba(212, 160, 74, 0.06);

  --cyan:            #4ecdc4;
  --cyan-dim:        rgba(78, 205, 196, 0.10);

  --correct:         #50c878;
  --correct-dim:     rgba(80, 200, 120, 0.08);
  --incorrect:       #e85d5d;
  --incorrect-dim:   rgba(232, 93, 93, 0.08);
  --info:            #4ecdc4;
  --warning:         #e8b65c;

  --grid-color:      rgba(210, 180, 120, 0.035);
  --grid-size:       48px;

  --code-bg:         rgba(0, 0, 0, 0.35);
  --sidebar-bg:      rgba(10, 13, 23, 0.85);
  --focus-ring:      rgba(212, 160, 74, 0.5);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);

  color-scheme: dark;
}

/* --- Light theme: "Architect's Drafting Table" --- */
[data-theme="light"] {
  --bg:              #f5f0e6;
  --bg-warm:         #ede8dc;
  --surface:         rgba(120, 100, 60, 0.06);
  --surface-hover:   rgba(120, 100, 60, 0.10);
  --surface-border:  rgba(120, 100, 60, 0.15);
  --surface-border-hover: rgba(120, 100, 60, 0.30);

  --text-primary:    #1c1a16;
  --text-body:       #3d3a34;
  --text-secondary:  #6b665c;
  --text-muted:      #a09a8e;

  --accent:          #b07c28;
  --accent-bright:   #c48a2a;
  --accent-dim:      rgba(176, 124, 40, 0.10);
  --accent-glow:     rgba(176, 124, 40, 0.06);

  --cyan:            #1a8a82;
  --cyan-dim:        rgba(26, 138, 130, 0.08);

  --correct:         #2d8f4e;
  --correct-dim:     rgba(45, 143, 78, 0.08);
  --incorrect:       #c44040;
  --incorrect-dim:   rgba(196, 64, 64, 0.08);
  --info:            #1a8a82;
  --warning:         #c48a2a;

  --grid-color:      rgba(120, 100, 60, 0.08);

  --code-bg:         rgba(0, 0, 0, 0.04);
  --sidebar-bg:      rgba(237, 232, 220, 0.9);
  --focus-ring:      rgba(176, 124, 40, 0.5);

  color-scheme: light;
}

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

html { scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text-body);
  line-height: 1.65;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background 0.4s var(--ease-out), color 0.3s var(--ease-out);
}

/* === ACCESSIBILITY === */

/* Skip to content link */
.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  background: var(--accent);
  color: var(--bg);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  z-index: 200;
  text-decoration: none;
  transition: top 0.2s;
}
.skip-link:focus {
  top: 12px;
}

/* Focus-visible for keyboard nav */
*:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 2px;
}

/* Remove outline for mouse clicks */
*:focus:not(:focus-visible) {
  outline: none;
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  .grid-bg { opacity: 1; animation: none; }
}

/* === THEME TOGGLE === */

.theme-toggle {
  position: fixed;
  top: 14px;
  right: 18px;
  z-index: 150;
  width: 44px;
  height: 44px;
  border: 1px solid var(--surface-border);
  border-radius: 50%;
  background: var(--surface);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, border-color 0.2s, transform 0.3s var(--ease-spring);
  -webkit-tap-highlight-color: transparent;
}
.theme-toggle:hover {
  background: var(--surface-hover);
  border-color: var(--surface-border-hover);
  transform: scale(1.08);
}
.theme-toggle:active {
  transform: scale(0.95);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
  transition: transform 0.5s var(--ease-spring), opacity 0.3s;
}

/* Sun icon (shown in dark mode) */
.theme-toggle .icon-sun {
  color: var(--accent);
}
.theme-toggle .icon-moon {
  color: var(--accent);
  display: none;
}

[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

/* Toggle animation */
.theme-toggle.animating svg {
  transform: rotate(360deg) scale(0.5);
  opacity: 0;
}

/* Theme transition overlay */
.theme-transition-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
}
.theme-transition-overlay.active {
  opacity: 1;
  background: var(--bg);
}

/* --- Grid background --- */
.grid-bg {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image:
    linear-gradient(var(--grid-color) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-color) 1px, transparent 1px);
  background-size: var(--grid-size) var(--grid-size);
  mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, black 20%, transparent 100%);
  -webkit-mask-image: radial-gradient(ellipse 70% 60% at 50% 40%, black 20%, transparent 100%);
  opacity: 0;
  animation: gridFadeIn 1.5s var(--ease-out) 0.3s forwards;
}
@keyframes gridFadeIn { to { opacity: 1; } }

/* --- Screens --- */
.screen { display: none; width: 100%; height: 100vh; position: relative; z-index: 1; }
.screen.active { display: flex; animation: screenIn 0.4s var(--ease-out); }
@keyframes screenIn {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ===================================================================
   COURSE BROWSER
   =================================================================== */

#course-browser-screen {
  justify-content: center;
  align-items: flex-start;
  overflow-y: auto;
}

.course-browser {
  max-width: 640px;
  width: 100%;
  margin: 0 auto;
  padding: 80px 28px 60px;
}

.course-browser-header {
  margin-bottom: 48px;
}

.course-browser-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
}

.app-logo-mark {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent) 0%, #b07c28 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 8px rgba(212, 160, 74, 0.15);
  opacity: 0;
  animation: brandPop 0.5s var(--ease-spring) 0.2s forwards;
}
@keyframes brandPop {
  from { opacity: 0; transform: scale(0.7) rotate(-10deg); }
  to   { opacity: 1; transform: scale(1) rotate(0deg); }
}

.app-logo-mark svg {
  stroke: var(--bg);
  stroke-width: 2.5;
}

.course-browser-title {
  font-family: var(--font-body);
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.02em;
  opacity: 0;
  animation: fadeSlideUp 0.5s var(--ease-out) 0.3s forwards;
}

.course-browser-tagline {
  font-size: 14px;
  font-weight: 400;
  color: var(--text-secondary);
  letter-spacing: 0.04em;
  text-transform: lowercase;
  font-variant: small-caps;
  opacity: 0;
  animation: fadeSlideUp 0.5s var(--ease-out) 0.45s forwards;
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* --- Course list --- */
.course-list {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.course-card {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 22px 24px;
  cursor: pointer;
  transition: border-color 0.25s var(--ease-out), background 0.25s var(--ease-out), box-shadow 0.25s var(--ease-out);
  position: relative;
  overflow: hidden;
  opacity: 0;
  animation: cardIn 0.5s var(--ease-out) 0.5s forwards;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.course-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--accent);
  transform: scaleY(0);
  transform-origin: top;
  transition: transform 0.3s var(--ease-out);
  border-radius: 0 2px 2px 0;
}

.course-card:hover, .course-card.expanded {
  border-color: var(--surface-border-hover);
  background: var(--surface-hover);
  box-shadow: 0 4px 24px rgba(212, 160, 74, 0.04);
}
.course-card:hover::before, .course-card.expanded::before {
  transform: scaleY(1);
}

.course-card-header {
  display: flex;
  align-items: center;
  gap: 12px;
}

.course-card-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.course-card-icon svg {
  width: 22px;
  height: 22px;
}

.course-card-header-text {
  flex: 1;
  min-width: 0;
}

.course-card-title {
  font-weight: 700;
  font-size: 16px;
  color: var(--text-primary);
  letter-spacing: -0.01em;
}

.course-card-meta {
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-code);
  font-weight: 500;
}

.course-card-desc {
  font-size: 13px;
  color: var(--text-body);
  margin-top: 8px;
  line-height: 1.55;
}

/* --- Progress bar --- */
.course-progress {
  margin-top: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}

.course-progress-bar {
  flex: 1;
  height: 3px;
  background: rgba(210, 180, 120, 0.08);
  border-radius: 2px;
  overflow: hidden;
}

.course-progress-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s var(--ease-out);
}

.course-progress-text {
  font-size: 11px;
  color: var(--text-secondary);
  white-space: nowrap;
  font-family: var(--font-code);
  font-weight: 500;
}

/* --- Module tree --- */
.course-modules {
  margin-top: 18px;
  border-top: 1px solid var(--surface-border);
  padding-top: 14px;
}

.course-module {
  margin-bottom: 14px;
}

.course-module-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 8px;
  opacity: 0.7;
}

.course-lesson {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-body);
  transition: background 0.15s, color 0.15s, transform 0.15s;
}
.course-lesson:hover {
  background: var(--surface-hover);
  color: var(--text-primary);
  transform: translateX(2px);
}

.lesson-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  border: 1.5px solid var(--text-muted);
  background: transparent;
  flex-shrink: 0;
  transition: all 0.2s;
}
.lesson-dot.completed {
  background: var(--correct);
  border-color: var(--correct);
  box-shadow: 0 0 6px rgba(80, 200, 120, 0.3);
}

.lesson-name { flex: 1; }

.lesson-score {
  font-size: 11px;
  color: var(--text-secondary);
  font-family: var(--font-code);
  font-weight: 500;
}

/* ===================================================================
   STUDY SCREEN
   =================================================================== */

#study-screen {
  flex-direction: row;
  height: 100vh;
}

/* === 3D Visualization Panel === */

.viz-panel {
  width: 0;
  flex-shrink: 0;
  display: none;
  flex-direction: column;
  background: rgba(0, 0, 0, 0.2);
  border-left: 1px solid rgba(212, 160, 74, 0.06);
  position: relative;
  overflow: hidden;
}

.viz-panel.active {
  display: flex;
  width: 42%;
  min-width: 340px;
  z-index: 160;
  animation: vizSlideIn 0.4s var(--ease-out);
}

@keyframes vizSlideIn {
  from { width: 0; opacity: 0; }
  to   { width: 42%; opacity: 1; }
}

/* --- Viz Header (Glass) --- */
.viz-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: rgba(255, 255, 255, 0.025);
  border-bottom: 1px solid rgba(212, 160, 74, 0.07);
  flex-shrink: 0;
}

.viz-header .viz-logo { flex: 1; }

/* Theme toggle inside viz header */
.viz-theme-toggle {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.04);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.viz-theme-toggle:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.1);
}

.viz-theme-toggle svg {
  width: 14px;
  height: 14px;
  color: var(--accent);
}

.viz-theme-toggle .icon-moon { display: none; }
[data-theme="light"] .viz-theme-toggle .icon-sun { display: none; }
[data-theme="light"] .viz-theme-toggle .icon-moon { display: block; }

[data-theme="light"] .viz-theme-toggle {
  border-color: rgba(0, 0, 0, 0.08);
  background: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] .viz-theme-toggle:hover {
  background: rgba(0, 0, 0, 0.06);
}

/* Hide global theme toggle when viz panel is open (toggled by JS) */
.theme-toggle.viz-hidden {
  display: none;
}

.viz-logo {
  display: flex;
  align-items: center;
  gap: 8px;
}

.viz-logo-mark {
  width: 16px;
  height: 16px;
  border-radius: 4px;
  animation: none;
  opacity: 1;
}

.viz-logo-text {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.03em;
}

/* --- Viz Tab Group (Pill Toggle) --- */
.viz-tab-group {
  display: flex;
  gap: 2px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 6px;
  padding: 2px;
}

.viz-tab {
  padding: 4px 12px;
  border-radius: 4px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: none;
  cursor: pointer;
  transition: all 0.15s;
}

.viz-tab:hover {
  color: var(--text-secondary);
}

.viz-tab.active {
  background: rgba(212, 160, 74, 0.12);
  color: var(--accent-bright);
}

/* --- Floating Info Pill --- */
.viz-info-pill {
  position: absolute;
  bottom: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(12px);
  border-radius: 20px;
  padding: 5px 16px;
  font-family: var(--font-code);
  font-size: 10px;
  line-height: 1.5;
  color: rgba(240, 236, 228, 0.6);
  white-space: nowrap;
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  border: 1px solid rgba(255, 255, 255, 0.04);
  pointer-events: none;
  z-index: 2;
}

.viz-info-pill:empty {
  display: none;
}

.viz-canvas-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
}

.viz-code-wrap {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  background: rgba(0, 0, 0, 0.4);
}

.viz-code-block {
  margin: 0;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
}

.viz-code-block code {
  font-family: var(--font-code) !important;
  font-size: 12px !important;
  line-height: 1.6 !important;
  color: var(--text-body) !important;
  background: transparent !important;
  border: none !important;
  padding: 0 !important;
  white-space: pre-wrap;
  word-break: break-word;
}

.viz-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
}

.viz-controls {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.015);
  border-top: 1px solid rgba(255, 255, 255, 0.04);
  max-height: 240px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.viz-slider-row {
  display: grid;
  grid-template-columns: 72px 1fr 48px;
  align-items: center;
  gap: 8px;
}

.viz-slider-label {
  font-size: 10px;
  font-weight: 500;
  color: var(--text-muted);
  font-family: var(--font-body);
  white-space: nowrap;
}

.viz-slider-value {
  font-size: 10px;
  color: rgba(212, 160, 74, 0.7);
  font-family: var(--font-code);
  font-weight: 500;
  text-align: right;
}

.viz-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  background: rgba(212, 160, 74, 0.08);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

.viz-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(212, 160, 74, 0.25);
  cursor: pointer;
  border: none;
}

.viz-slider::-moz-range-thumb {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 8px rgba(212, 160, 74, 0.25);
  cursor: pointer;
  border: none;
}

.viz-toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 2px 0;
}

.viz-toggle-switch {
  width: 28px;
  height: 16px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
  flex-shrink: 0;
}

.viz-toggle-switch.active {
  background: rgba(212, 160, 74, 0.25);
}

.viz-toggle-switch::after {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: rgba(240, 236, 228, 0.4);
  position: absolute;
  top: 2px;
  left: 2px;
  transition: transform 0.2s, background 0.2s;
}

.viz-toggle-switch.active::after {
  transform: translateX(12px);
  background: var(--accent);
}

.viz-toggle-label {
  font-size: 11px;
  font-weight: 400;
  color: var(--text-muted);
  font-family: var(--font-body);
  cursor: pointer;
}

@media (max-width: 1100px) {
  .viz-panel.active { width: 38%; min-width: 300px; }
}

@media (max-width: 900px) {
  .viz-panel { display: none !important; }
}

/* --- Sidebar --- */
.study-sidebar {
  width: 240px;
  flex-shrink: 0;
  padding: 28px 18px 24px;
  background: var(--sidebar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-right: 1px solid var(--surface-border);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.study-sidebar .toc-label {
  font-size: 10px;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 16px;
  padding-left: 2px;
}

.study-sidebar .toc-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.study-sidebar .toc-item {
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 5px 8px;
  text-decoration: none;
  display: block;
  border-radius: var(--radius-sm);
  transition: color 0.15s, background 0.15s;
  line-height: 1.4;
}
.study-sidebar .toc-item:hover {
  color: var(--text-primary);
  background: var(--surface);
}
.study-sidebar .toc-item.depth-2 {
  padding-left: 20px;
  font-size: 12px;
  color: var(--text-muted);
}
.study-sidebar .toc-item.depth-2:hover {
  color: var(--text-secondary);
}

/* --- Button icons --- */
.btn-icon {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-icon svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

/* --- Sidebar buttons --- */
.study-sidebar .btn-quiz {
  margin-top: 20px;
  text-align: center;
  width: 100%;
  justify-content: center;
}
.study-sidebar .btn-new-topic {
  margin-top: 8px;
  text-align: center;
  width: 100%;
}

/* --- Study content --- */
.study-content {
  flex: 1;
  padding: 48px 40px 48px 40px;
  overflow-y: auto;
  min-width: 0;
}

.study-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 24px;
  font-family: var(--font-code);
}

/* --- Typography in study view --- */
.study-content h1 {
  font-size: 28px;
  font-weight: 800;
  color: var(--text-primary);
  margin: 0 0 10px;
  letter-spacing: -0.02em;
  line-height: 1.25;
}
.study-content h2 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 36px 0 14px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--surface-border);
  letter-spacing: -0.01em;
}
.study-content h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-body);
  margin: 24px 0 10px;
}
.study-content p {
  font-size: 15px;
  line-height: 1.8;
  margin-bottom: 16px;
}
.study-content ul, .study-content ol {
  padding-left: 24px;
  margin-bottom: 16px;
}
.study-content li {
  margin-bottom: 6px;
  font-size: 15px;
  line-height: 1.7;
}
.study-content strong {
  color: var(--text-primary);
  font-weight: 600;
}

/* --- Code --- */
.study-content code {
  font-family: var(--font-code);
  font-size: 13px;
  background: rgba(212, 160, 74, 0.08);
  color: var(--accent-bright);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid rgba(212, 160, 74, 0.1);
}
.study-content pre {
  background: var(--code-bg);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  margin-bottom: 18px;
  overflow-x: auto;
  position: relative;
}
.study-content pre code {
  background: none;
  padding: 0;
  font-size: 13px;
  line-height: 1.65;
  color: var(--text-body);
  border: none;
}

/* --- Blockquotes --- */
.study-content blockquote {
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
  padding: 14px 18px;
  border-radius: 0 var(--radius-md) var(--radius-md) 0;
  margin-bottom: 18px;
}
.study-content blockquote p { margin-bottom: 0; }

/* --- Tables --- */
.study-content table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 18px;
  font-size: 14px;
}
.study-content th {
  text-align: left;
  font-weight: 600;
  color: var(--text-primary);
  padding: 10px 14px;
  border-bottom: 2px solid var(--surface-border);
  font-size: 13px;
}
.study-content td {
  padding: 9px 14px;
  border-bottom: 1px solid var(--surface-border);
}
.study-content tr:last-child td { border-bottom: none; }

/* --- Exercises (details/summary) --- */
.study-content details {
  background: rgba(78, 205, 196, 0.04);
  border: 1px solid rgba(78, 205, 196, 0.15);
  border-radius: var(--radius-md);
  padding: 0;
  margin: 20px 0;
  transition: border-color 0.2s;
}
.study-content details:hover {
  border-color: rgba(78, 205, 196, 0.25);
}
.study-content details summary {
  padding: 14px 18px;
  cursor: pointer;
  font-weight: 600;
  color: var(--text-primary);
  list-style: none;
  font-size: 14px;
  transition: color 0.15s;
}
.study-content details summary::-webkit-details-marker { display: none; }
.study-content details summary::before {
  content: '\25B6';
  font-size: 9px;
  margin-right: 8px;
  color: var(--cyan);
  display: inline-block;
  transition: transform 0.2s var(--ease-out);
}
.study-content details[open] summary::before {
  transform: rotate(90deg);
}
.study-content details[open] summary {
  border-bottom: 1px solid rgba(78, 205, 196, 0.1);
}
.study-content details > :not(summary) { padding: 0 18px; }
.study-content details > p:last-child { padding-bottom: 14px; }

/* --- Mermaid --- */
.study-content .mermaid { margin: 20px 0; }

/* --- Lesson navigation --- */
.lesson-nav {
  display: flex;
  justify-content: space-between;
  margin-top: 56px;
  padding-top: 24px;
  border-top: 1px solid var(--surface-border);
}

.lesson-nav-btn {
  max-width: 45%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ===================================================================
   QUIZ SCREEN
   =================================================================== */

#quiz-screen {
  flex-direction: column;
  padding: 48px 40px;
  padding-top: 80px;
  max-width: 700px;
  margin: 0 auto;
  width: 100%;
}

.quiz-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 32px;
}

.quiz-progress-text {
  font-size: 13px;
  color: var(--text-secondary);
  font-family: var(--font-code);
  font-weight: 500;
}
.quiz-progress-text strong { color: var(--accent-bright); }

.quiz-progress-bar {
  display: flex;
  gap: 6px;
}
.quiz-progress-bar .bar {
  width: 32px;
  height: 3px;
  border-radius: 2px;
  background: rgba(210, 180, 120, 0.1);
  transition: background 0.3s, box-shadow 0.3s;
}
.quiz-progress-bar .bar.correct {
  background: var(--correct);
  box-shadow: 0 0 6px rgba(80, 200, 120, 0.25);
}
.quiz-progress-bar .bar.current {
  background: var(--accent);
  box-shadow: 0 0 6px rgba(212, 160, 74, 0.25);
}
.quiz-progress-bar .bar.incorrect {
  background: var(--incorrect);
  box-shadow: 0 0 6px rgba(232, 93, 93, 0.2);
}

.quiz-type-label {
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--cyan);
  margin-bottom: 12px;
}

.quiz-question {
  font-size: 17px;
  font-weight: 500;
  color: var(--text-primary);
  line-height: 1.7;
  margin-bottom: 24px;
}
.quiz-question code {
  font-family: var(--font-code);
  font-size: 15px;
  background: rgba(212, 160, 74, 0.08);
  color: var(--accent-bright);
  padding: 2px 7px;
  border-radius: 4px;
  border: 1px solid rgba(212, 160, 74, 0.1);
}

/* --- Answer input --- */
.quiz-answer-input {
  width: 100%;
  min-height: 88px;
  padding: 16px;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  color: var(--text-body);
  font-size: 14px;
  font-family: var(--font-body);
  resize: vertical;
  outline: none;
  line-height: 1.65;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.quiz-answer-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212, 160, 74, 0.08);
}

/* --- Multiple choice --- */
.mc-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 20px;
}
.mc-option {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  font-size: 14px;
  color: var(--text-body);
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
}
.mc-option:hover {
  border-color: var(--surface-border-hover);
  background: var(--surface);
  transform: translateX(2px);
}
.mc-option.selected {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text-primary);
}
.mc-option input[type="radio"] { accent-color: var(--accent); }

/* --- Buttons --- */
.quiz-submit-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}

.btn-submit {
  background: var(--accent);
  border: none;
  color: var(--bg);
  padding: 10px 28px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  transition: opacity 0.15s, transform 0.15s;
}
.btn-submit:hover { opacity: 0.9; transform: translateY(-1px); }
.btn-submit:active { transform: translateY(0); }
.btn-submit:disabled { opacity: 0.3; cursor: not-allowed; transform: none; }

.quiz-next-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 24px;
}

.btn-next {
  background: var(--accent-dim);
  border: 1px solid rgba(212, 160, 74, 0.3);
  color: var(--accent-bright);
  padding: 10px 24px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  transition: background 0.15s, transform 0.15s;
}
.btn-next:hover { background: rgba(212, 160, 74, 0.18); transform: translateY(-1px); }

.link-study-material {
  color: var(--text-secondary);
  font-size: 13px;
  cursor: pointer;
  text-decoration: none;
  background: none;
  border: none;
  font-family: var(--font-body);
  transition: color 0.15s;
  position: relative;
}
.link-study-material::after {
  content: '';
  position: absolute;
  bottom: -2px; left: 0;
  width: 0; height: 1px;
  background: var(--text-secondary);
  transition: width 0.2s var(--ease-out);
}
.link-study-material:hover { color: var(--text-body); }
.link-study-material:hover::after { width: 100%; }

/* --- Feedback --- */
.feedback-card {
  margin-top: 24px;
  padding: 18px 20px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  animation: feedbackIn 0.35s var(--ease-out);
}
@keyframes feedbackIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.feedback-card.correct {
  background: var(--correct-dim);
  border-color: rgba(80, 200, 120, 0.2);
}
.feedback-card.incorrect {
  background: var(--incorrect-dim);
  border-color: rgba(232, 93, 93, 0.2);
}

.feedback-verdict {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  font-weight: 700;
  font-size: 15px;
}
.feedback-verdict.correct { color: var(--correct); }
.feedback-verdict.incorrect { color: var(--incorrect); }

.feedback-explanation {
  font-size: 14px;
  color: var(--text-secondary);
  line-height: 1.65;
}

/* --- Quiz complete --- */
.quiz-complete {
  text-align: center;
  padding-top: 72px;
  animation: feedbackIn 0.5s var(--ease-out);
}
.quiz-complete h2 {
  font-size: 24px;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 8px;
  letter-spacing: -0.02em;
}
.quiz-score {
  font-size: 56px;
  font-weight: 800;
  color: var(--accent);
  margin: 24px 0;
  font-family: var(--font-code);
  letter-spacing: -0.02em;
}
.quiz-score-label {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 36px;
}

/* ===================================================================
   SHARED COMPONENTS
   =================================================================== */

/* --- Buttons --- */
.btn-secondary {
  background: rgba(210, 180, 120, 0.05);
  border: 1px solid var(--surface-border);
  color: var(--text-secondary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--font-body);
  font-weight: 500;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.btn-secondary:hover {
  background: rgba(210, 180, 120, 0.08);
  color: var(--text-body);
  border-color: var(--surface-border-hover);
}

.btn-quiz {
  background: var(--accent-dim);
  border: 1px solid rgba(212, 160, 74, 0.25);
  color: var(--accent-bright);
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  transition: background 0.15s, border-color 0.15s, transform 0.15s;
}
.btn-quiz:hover {
  background: rgba(212, 160, 74, 0.18);
  border-color: rgba(212, 160, 74, 0.4);
  transform: translateY(-1px);
}

.btn-study {
  background: var(--accent);
  border: none;
  color: var(--bg);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font-body);
  transition: opacity 0.15s;
}
.btn-study:hover { opacity: 0.9; }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--bg);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-lg);
  padding: 36px;
  width: 420px;
  animation: modalIn 0.3s var(--ease-out);
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.modal h2 { color: var(--text-primary); font-size: 18px; font-weight: 700; margin-bottom: 8px; }
.modal p { color: var(--text-secondary); font-size: 14px; margin-bottom: 20px; }
.modal input {
  width: 100%; padding: 11px 14px; background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--surface-border); border-radius: var(--radius-sm);
  color: var(--text-primary); font-size: 14px; font-family: var(--font-code);
  outline: none; margin-bottom: 16px;
  transition: border-color 0.2s;
}
.modal input:focus { border-color: var(--accent); }
.modal button {
  width: 100%; padding: 11px; background: var(--accent);
  border: none; border-radius: var(--radius-sm); color: var(--bg);
  font-size: 14px; font-weight: 600; cursor: pointer;
  font-family: var(--font-body);
}
.modal button:hover { opacity: 0.9; }

/* --- Error / Notice --- */
.error-card {
  background: var(--incorrect-dim); border: 1px solid rgba(232, 93, 93, 0.2);
  border-radius: var(--radius-md); padding: 16px; margin-top: 16px;
}
.error-card p { color: var(--text-secondary); font-size: 14px; margin-bottom: 10px; }
.btn-retry {
  background: rgba(232, 93, 93, 0.1); border: 1px solid rgba(232, 93, 93, 0.25);
  color: var(--incorrect); padding: 7px 14px; border-radius: var(--radius-sm);
  font-size: 13px; cursor: pointer; font-family: var(--font-body);
}

.truncation-notice {
  background: rgba(232, 182, 92, 0.08); border: 1px solid rgba(232, 182, 92, 0.18);
  border-radius: var(--radius-md); padding: 10px 14px; margin-bottom: 16px;
  font-size: 13px; color: var(--warning);
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  padding: 48px;
  font-size: 14px;
}

.loading-text {
  text-align: center;
  color: var(--text-muted);
  padding: 48px;
  font-size: 13px;
  font-family: var(--font-code);
}

.settings-icon {
  position: fixed; top: 12px; right: 52px;
  background: none; border: none; color: var(--text-muted);
  font-size: 18px; cursor: pointer; z-index: 10; padding: 4px;
  transition: color 0.15s;
}
.settings-icon:hover { color: var(--text-secondary); }

/* ===================================================================
   SCROLLBAR
   =================================================================== */

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgba(210, 180, 120, 0.12);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(210, 180, 120, 0.2);
}

/* ===================================================================
   QUIZ SETUP
   =================================================================== */

.quiz-setup {
  display: flex;
  flex-direction: column;
  max-width: 520px;
  margin: 0 auto;
  padding: 80px 28px 40px;
  width: 100%;
  animation: screenIn 0.4s var(--ease-out);
}

.quiz-setup-header {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 6px;
  letter-spacing: -0.01em;
}

.quiz-setup-lesson {
  font-size: 14px;
  color: var(--accent);
  font-weight: 500;
  margin-bottom: 32px;
}

.quiz-setup-section {
  margin-bottom: 24px;
}

.quiz-setup-label {
  font-size: 10px;
  text-transform: uppercase;
  font-weight: 700;
  letter-spacing: 0.1em;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

/* Mode selector */
.quiz-mode-selector {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 14px 10px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  font-family: var(--font-body);
  color: var(--text-secondary);
}
.mode-btn:hover {
  border-color: var(--surface-border-hover);
  background: var(--surface);
  transform: translateY(-1px);
}
.mode-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--text-primary);
}
.mode-icon { font-size: 20px; }
.mode-name { font-size: 13px; font-weight: 600; }
.mode-desc { font-size: 10px; color: var(--text-muted); text-align: center; line-height: 1.3; }
.mode-btn.active .mode-desc { color: var(--text-secondary); }

/* Count selector */
.quiz-count-selector {
  display: flex;
  gap: 8px;
}
.count-btn {
  padding: 8px 18px;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 600;
  font-family: var(--font-code);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.count-btn:hover { border-color: var(--surface-border-hover); }
.count-btn.active {
  border-color: var(--accent);
  background: var(--accent-dim);
  color: var(--accent-bright);
}

/* Review toggle */
.quiz-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text-secondary);
}
.quiz-toggle input[type="checkbox"] {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

/* Start button */
.btn-start-quiz {
  margin-top: 12px;
  padding: 12px 32px;
  background: var(--accent);
  border: none;
  color: var(--bg);
  font-size: 15px;
  font-weight: 700;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: var(--font-body);
  transition: opacity 0.15s, transform 0.15s;
  align-self: center;
}
.btn-start-quiz:hover { opacity: 0.9; transform: translateY(-1px); }

/* ===================================================================
   QUIZ ACTIVE OVERRIDES
   =================================================================== */

#quiz-active {
  display: flex;
  flex-direction: column;
  max-width: 700px;
  margin: 0 auto;
  padding: 48px 40px;
  padding-top: 80px;
  width: 100%;
}

/* Badges row */
.quiz-badges {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.quiz-difficulty-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 4px;
}
.badge-easy { background: rgba(80, 200, 120, 0.12); color: var(--correct); }
.badge-medium { background: var(--accent-dim); color: var(--accent-bright); }
.badge-hard { background: var(--incorrect-dim); color: var(--incorrect); }

.quiz-review-badge {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--cyan-dim);
  color: var(--cyan);
}

/* Action row (hint + submit) */
.quiz-action-row {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 12px;
  margin-top: 20px;
}

/* Hint button */
.btn-hint {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(78, 205, 196, 0.08);
  border: 1px solid rgba(78, 205, 196, 0.2);
  color: var(--cyan);
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-family: var(--font-body);
  transition: background 0.15s, border-color 0.15s;
}
.btn-hint:hover { background: rgba(78, 205, 196, 0.14); border-color: rgba(78, 205, 196, 0.35); }
.btn-hint:disabled { opacity: 0.4; cursor: default; }

/* Hint card */
.hint-card {
  background: rgba(78, 205, 196, 0.06);
  border: 1px solid rgba(78, 205, 196, 0.15);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  margin-top: 16px;
  font-size: 14px;
  color: var(--text-body);
  line-height: 1.6;
  animation: feedbackIn 0.3s var(--ease-out);
}
.hint-icon { margin-right: 4px; }
.hint-penalty { font-size: 12px; color: var(--text-muted); font-weight: 400; }

/* Multi-step questions */
.multi-step-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.multi-step-item {
  background: rgba(0, 0, 0, 0.15);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}
.multi-step-label { margin-bottom: 6px; }
.step-number {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
}
.multi-step-prompt {
  font-size: 14px;
  color: var(--text-body);
  margin-bottom: 10px;
  line-height: 1.6;
}
.multi-step-prompt p { margin-bottom: 4px; }
.multi-step-input {
  width: 100%;
  padding: 9px 12px;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--surface-border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  font-family: var(--font-code);
  outline: none;
  transition: border-color 0.2s;
}
.multi-step-input:focus { border-color: var(--accent); }
.multi-step-input.step-input-correct { border-color: var(--correct); }
.multi-step-input.step-input-incorrect { border-color: var(--incorrect); }
.multi-step-feedback {
  margin-top: 8px;
  font-size: 13px;
}
.step-correct { color: var(--correct); }
.step-incorrect { color: var(--incorrect); }

/* Quiz complete extras */
.quiz-hints-used {
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 8px;
}
.quiz-mode-tag {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
}

/* ===================================================================
   KaTeX overrides
   =================================================================== */

.katex { color: var(--text-primary); }
.katex .base { color: var(--text-primary); }

/* ===================================================================
   Selection
   =================================================================== */

::selection {
  background: rgba(212, 160, 74, 0.25);
  color: var(--text-primary);
}

/* ===================================================================
   Light theme specific overrides
   =================================================================== */

[data-theme="light"] .grid-bg {
  mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, black 10%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse 80% 70% at 50% 40%, black 10%, transparent 80%);
}

[data-theme="light"] .study-content code {
  background: rgba(176, 124, 40, 0.08);
  color: #8b6914;
  border-color: rgba(176, 124, 40, 0.12);
}

[data-theme="light"] .study-content pre code {
  color: var(--text-body);
  background: none;
  border: none;
}

[data-theme="light"] .app-logo-mark {
  background: linear-gradient(135deg, var(--accent) 0%, #8a5f1e 100%);
}
[data-theme="light"] .app-logo-mark svg {
  stroke: var(--bg);
}

[data-theme="light"] .quiz-answer-input {
  background: rgba(0, 0, 0, 0.03);
}

[data-theme="light"] .mc-option {
  background: rgba(0, 0, 0, 0.02);
}

[data-theme="light"] .viz-header {
  background: rgba(0, 0, 0, 0.02);
  border-bottom-color: rgba(176, 124, 40, 0.08);
}

[data-theme="light"] .viz-tab-group {
  background: rgba(0, 0, 0, 0.04);
}

[data-theme="light"] .viz-tab.active {
  background: rgba(176, 124, 40, 0.1);
}

[data-theme="light"] .viz-info-pill {
  background: rgba(255, 255, 255, 0.75);
  color: rgba(28, 26, 22, 0.6);
  border-color: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .viz-controls {
  background: rgba(0, 0, 0, 0.015);
  border-top-color: rgba(0, 0, 0, 0.06);
}

[data-theme="light"] .viz-toggle-switch {
  background: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .viz-toggle-switch::after {
  background: rgba(28, 26, 22, 0.3);
}

[data-theme="light"] .viz-toggle-switch.active {
  background: rgba(176, 124, 40, 0.2);
}

[data-theme="light"] .viz-toggle-switch.active::after {
  background: var(--accent);
}

[data-theme="light"] .viz-panel {
  background: rgba(0, 0, 0, 0.02);
  border-left-color: rgba(176, 124, 40, 0.08);
}

[data-theme="light"] .viz-code-wrap {
  background: rgba(0, 0, 0, 0.03);
}

/* Light theme scrollbar */
[data-theme="light"] ::-webkit-scrollbar-thumb {
  background: rgba(120, 100, 60, 0.2);
}
[data-theme="light"] ::-webkit-scrollbar-thumb:hover {
  background: rgba(120, 100, 60, 0.3);
}

/* Light theme highlight.js override */
[data-theme="light"] .hljs {
  color: var(--text-body) !important;
  background: transparent !important;
}

/* ===================================================================
   Responsive
   =================================================================== */

@media (max-width: 768px) {
  .study-sidebar { width: 200px; padding: 20px 12px; }
  .study-content { padding: 32px 24px; }
  .course-browser { padding: 48px 20px 40px; }
  #quiz-screen { padding: 36px 24px; padding-top: 64px; }
  .theme-toggle { top: 10px; right: 12px; width: 38px; height: 38px; }
}

@media (max-width: 600px) {
  .study-sidebar { display: none; }
  .study-content { padding: 24px 18px; }
  .course-browser { padding: 36px 16px 32px; }
}

/* ============================
   SHADER EDITOR — Vis-first layout
   User's shader output is THE hero. Code beside it. Challenge below.
   ============================ */

.shader-editor {
  display: flex;
  height: 100vh;
  width: 100%;
  background: var(--bg);
  font-family: var(--font-body);
  overflow: hidden;
}

/* -- Editor Panel (left ~45%) -- */

.se-editor-panel {
  flex: 0 0 45%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
  border-right: 1px solid var(--surface-border);
}

.se-editor-tabs {
  display: flex;
  align-items: center;
  gap: 0;
  padding: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--surface-border);
  flex-shrink: 0;
}

.se-tab {
  padding: 10px 20px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-family: var(--font-code);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s var(--ease-out), border-color 0.2s var(--ease-out), background 0.2s;
}

.se-tab:hover {
  color: var(--text-body);
  background: var(--surface-hover);
}

.se-tab.active {
  color: var(--accent-bright);
  border-bottom-color: var(--accent);
  background: var(--accent-dim);
}

.se-editor-wrap {
  flex: 1;
  overflow: hidden;
  background: var(--bg);
}

.se-editor-wrap .cm-editor {
  height: 100%;
  font-size: 13.5px;
}

.se-editor-wrap .cm-scroller { overflow: auto; }

.se-editor-wrap .cm-gutters {
  border-right: 1px solid var(--surface-border) !important;
}

.se-error-bar {
  padding: 0 16px;
  min-height: 0;
  font-family: var(--font-code);
  font-size: 0.72rem;
  color: var(--text-muted);
  background: var(--bg);
  border-top: 1px solid var(--surface-border);
  transition: min-height 0.25s var(--ease-out), padding 0.25s var(--ease-out);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.se-error-bar.has-error {
  min-height: 32px;
  padding: 8px 16px;
  color: var(--incorrect);
  background: var(--incorrect-dim);
  border-top-color: var(--incorrect);
}

/* -- Right Panel: Vis Hero + Challenge -- */

.se-side-panel {
  flex: 1 1 55%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg);
}

/* -- Canvas Hero: user output fills available space -- */

.se-preview {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: #000;
  position: relative;
  min-height: 0;
}

.se-canvas-hero {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* User canvas: fills the hero area */
.se-canvas-hero > canvas {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: contain;
  image-rendering: auto;
}

/* Target: small overlay thumbnail in bottom-right */
.se-target-overlay {
  position: absolute;
  bottom: 12px;
  right: 12px;
  text-align: center;
  z-index: 2;
  opacity: 0.9;
  transition: opacity 0.2s, transform 0.2s var(--ease-out);
}

.se-target-overlay:hover {
  opacity: 1;
  transform: scale(1.08);
}

.se-target-label {
  font-family: var(--font-code);
  font-size: 0.55rem;
  font-weight: 700;
  letter-spacing: 0.16em;
  color: rgba(255,255,255,0.6);
  margin-bottom: 4px;
  text-shadow: 0 1px 4px rgba(0,0,0,0.8);
}

.se-target-overlay canvas {
  width: 90px;
  height: 90px;
  border-radius: var(--radius-sm);
  border: 2px solid var(--accent);
  box-shadow: 0 0 16px rgba(212,160,74,0.25), 0 2px 8px rgba(0,0,0,0.5);
  display: block;
  background: #000;
}

/* Match badge: floating on canvas */
.se-match {
  position: absolute;
  bottom: 12px;
  left: 12px;
  font-family: var(--font-code);
  font-size: 0.78rem;
  font-weight: 700;
  color: rgba(255,255,255,0.5);
  letter-spacing: 0.06em;
  padding: 4px 10px;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(8px);
  border-radius: 4px;
  z-index: 2;
  transition: color 0.3s, background 0.3s;
}

.se-match.match-pass {
  color: var(--correct);
  background: rgba(80,200,120,0.15);
  text-shadow: 0 0 10px var(--correct-dim);
}
.se-match.match-mid {
  color: var(--accent-bright);
  background: rgba(212,160,74,0.15);
}
.se-match.match-fail {
  color: var(--incorrect);
  background: rgba(232,93,93,0.15);
}

/* -- Challenge Panel: compact info bar below canvas -- */

.se-challenge {
  flex-shrink: 0;
  padding: 14px 18px;
  border-top: 1px solid var(--surface-border);
  overflow-y: auto;
  max-height: 40vh;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.se-challenge-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.se-challenge-num {
  font-family: var(--font-code);
  font-size: 0.68rem;
  color: var(--accent);
  font-weight: 600;
  letter-spacing: 0.04em;
  padding: 2px 8px;
  background: var(--accent-dim);
  border-radius: 4px;
  flex-shrink: 0;
}

.se-challenge-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: -0.01em;
  flex: 1;
}

.se-challenge-desc {
  font-size: 0.8rem;
  color: var(--text-body);
  line-height: 1.55;
}

/* Hints */

.se-hint {
  font-size: 0.76rem;
  color: var(--cyan);
  padding: 6px 10px;
  background: var(--cyan-dim);
  border-radius: var(--radius-sm);
  border-left: 2px solid var(--cyan);
  margin-bottom: 3px;
  animation: hintReveal 0.3s var(--ease-out);
}

@keyframes hintReveal {
  from { opacity: 0; transform: translateY(-4px); }
  to { opacity: 1; transform: translateY(0); }
}

.se-hint-btn {
  border: 1px dashed var(--surface-border);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem;
  padding: 5px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
}

.se-hint-btn:hover {
  color: var(--cyan);
  border-color: var(--cyan);
  background: var(--cyan-dim);
}

/* Primer */

.se-primer-toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.76rem;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}

.se-primer-toggle:hover { color: var(--text-body); }

.se-primer-arrow {
  font-size: 0.6rem;
  transition: transform 0.2s var(--ease-out);
}

.se-primer {
  font-size: 0.76rem;
  color: var(--text-body);
  line-height: 1.6;
  padding: 8px 12px;
  background: var(--accent-dim);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius-sm);
  animation: hintReveal 0.3s var(--ease-out);
}

/* Theory unlock */

.se-theory {
  font-size: 0.8rem;
  color: var(--text-primary);
  line-height: 1.6;
  padding: 10px 12px;
  background: var(--correct-dim);
  border-left: 3px solid var(--correct);
  border-radius: var(--radius-sm);
  animation: theoryReveal 0.5s var(--ease-out);
}

@keyframes theoryReveal {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

.se-theory-label {
  font-size: 0.6rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--correct);
  margin-bottom: 4px;
}

/* Footer: actions + nav in one row */

.se-challenge-footer {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-top: 6px;
  border-top: 1px solid var(--surface-border);
  margin-top: 2px;
}

.se-actions {
  display: flex;
  gap: 6px;
}

.se-btn {
  padding: 7px 16px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-body);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s var(--ease-out);
}

.se-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.se-btn-submit {
  background: var(--accent);
  color: var(--bg);
  box-shadow: 0 1px 6px var(--accent-dim);
}

.se-btn-submit:hover:not(:disabled) {
  background: var(--accent-bright);
  box-shadow: 0 2px 12px var(--accent-dim);
  transform: translateY(-1px);
}

.se-btn-reset {
  background: var(--surface);
  color: var(--text-secondary);
  border: 1px solid var(--surface-border);
}

.se-btn-reset:hover {
  color: var(--text-primary);
  border-color: var(--surface-border-hover);
}

.se-btn-back {
  background: transparent;
  color: var(--text-muted);
  font-size: 0.72rem;
  padding: 4px 8px;
  margin-left: auto;
}

.se-btn-back:hover { color: var(--text-body); }

/* Nav: compact arrows */

.se-nav {
  display: flex;
  align-items: center;
  gap: 4px;
}

.se-nav-btn {
  background: var(--surface);
  border: 1px solid var(--surface-border);
  color: var(--text-muted);
  font-size: 0.72rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 4px;
  transition: all 0.15s;
}

.se-nav-btn:disabled { opacity: 0.2; cursor: not-allowed; }
.se-nav-btn:hover:not(:disabled) {
  color: var(--accent);
  border-color: var(--accent);
}

/* Dots: inline in header */

.se-dots {
  display: flex;
  gap: 6px;
  margin-left: auto;
  align-items: center;
}

.se-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--surface-border);
  cursor: pointer;
  transition: all 0.2s var(--ease-spring);
}

.se-dot:hover { background: var(--text-muted); }

.se-dot.current {
  background: var(--accent);
  transform: scale(1.4);
  box-shadow: 0 0 6px var(--accent-dim);
}

.se-dot.completed {
  background: var(--correct);
  box-shadow: 0 0 4px var(--correct-dim);
}
