:root {
  /* Quantum Dark Theme - Copper Accent */
  --primary: #927052;
  --primary-hover: #7a5d44;
  
  --bg: #030712;       /* Slate 950 */
  --surface: #1e293b;  /* Slate 800 */
  --surface-highlight: #334155; /* Slate 700 */
  
  --text-main: #f8fafc; /* Slate 50 */
  --text-muted: #94a3b8; /* Slate 400 */
  
  --border: #334155;   /* Slate 700 */
  
  --sidebar-bg: #0f172a; /* Slate 900 */
  --sidebar-text: #e2e8f0; /* Slate 200 */
  --sidebar-hover: #1e293b; /* Slate 800 */
  
  --accent: #10b981;   /* Emerald 500 */
  --danger: #ef4444;   /* Red 500 */
  --wire-color: #475569; /* Slate 600 */
}

body, html {
  margin: 0;
  padding: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  height: 100%;
  background: var(--bg);
  color: var(--text-main);
}

* { box-sizing: border-box; }

/* Layout */
.app-layout {
  display: flex;
  height: 100vh;
  flex-direction: column;
}

@media (min-width: 768px) {
  .app-layout {
    flex-direction: row;
  }
}

/* Sidebar */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  border-right: 1px solid var(--border);
}

.sidebar.active {
  transform: translateX(0);
  box-shadow: 0 0 20px rgba(0,0,0,0.5);
}

.mobile-menu-toggle {
  display: block;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 900;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.mobile-menu-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.5rem;
  cursor: pointer;
  padding: 5px;
}

.sidebar .brand {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

@media (min-width: 768px) {
  .sidebar {
    position: static;
    width: 260px;
    height: 100%;
    transform: none;
    border-right: 1px solid var(--border);
    border-bottom: none;
    max-height: none;
  }
  
  .mobile-menu-toggle {
    display: none;
  }
  
  .mobile-menu-close {
    display: none;
  }
}


.sidebar .brand {
  padding: 20px;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.025em;
  border-bottom: 1px solid var(--border);
}
.sidebar .brand a { color: inherit; text-decoration: none; }

.sidebar .course-title {
  padding: 16px 20px;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  font-weight: 600;
}

.lesson-list {
  list-style: none;
  padding: 0;
  margin: 0;
  overflow-y: auto;
  flex: 1;
}

.lesson-list li a {
  display: flex;
  padding: 12px 20px;
  color: var(--text-muted);
  text-decoration: none;
  border-left: 3px solid transparent;
  gap: 12px;
  align-items: center;
  transition: background 0.2s, color 0.2s;
}

.lesson-list li a:hover {
  background: var(--sidebar-hover);
  color: white;
}

.lesson-list li.active a {
  background: var(--sidebar-hover);
  border-left-color: var(--primary);
  color: white;
}

.lesson-list .num {
  font-family: monospace;
  opacity: 0.6;
}

/* Main Content */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

@media (min-width: 1024px) {
  .main-content {
    flex-direction: row;
  }
}

/* Lesson Pane */
.lesson-pane {
  padding: 30px;
  overflow-y: auto;
  border-bottom: 1px solid var(--border);
  flex: 1;
  max-width: 100%;
  background: var(--bg);
}

@media (min-width: 1024px) {
  .lesson-pane {
    max-width: 40%;
    border-right: 1px solid var(--border);
    border-bottom: none;
  }
}

.lesson-pane h1 {
  margin-top: 0;
  font-size: 1.8rem;
  line-height: 1.2;
  margin-bottom: 1.5rem;
  color: white;
}

.prose {
  line-height: 1.6;
  color: var(--text-main);
}

.prose h2 { font-size: 1.25rem; margin-top: 1.5em; color: white; }
.prose p { margin-bottom: 1em; }
.prose code { 
  background: var(--surface); 
  padding: 2px 4px; 
  border-radius: 4px; 
  font-family: monospace;
  color: #e2e8f0;
}

.lesson-nav {
  margin-top: 40px;
  display: flex;
  justify-content: space-between;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

/* Editor Pane */
.editor-pane {
  flex: 1.5;
  display: flex;
  flex-direction: column;
  background: #0b1121; /* Slightly lighter than bg */
  overflow-y: auto;
  padding: 20px;
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
  flex-wrap: wrap;
  gap: 10px;
}

.control-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Quiz Styles */
.quiz-box {
  background: rgba(30, 41, 59, 0.5);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin: 20px 0;
}

.quiz-box h3 {
  margin-top: 0;
  color: var(--accent);
  font-size: 1.2rem;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  padding-bottom: 0.5rem;
}

.quiz-box h4 {
  color: var(--text-main);
  margin-top: 0;
  margin-bottom: 1rem;
}

.quiz-question {
  margin-bottom: 1.5rem;
  background: rgba(15, 23, 42, 0.3);
  padding: 15px;
  border-radius: 6px;
}

.quiz-question p {
  font-weight: 500;
  margin-bottom: 1rem;
  color: var(--text-main);
  margin-top: 0;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 0.8rem;
}

.quiz-options label {
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px;
  border-radius: 4px;
  transition: background 0.2s;
  color: var(--text-muted);
}

.quiz-options label:hover {
  background: rgba(255,255,255,0.05);
  color: var(--text-main);
}

.quiz-options input[type="radio"] {
  accent-color: var(--primary);
}

#quiz-result {
  margin-top: 1rem;
  padding: 1rem;
  background: rgba(0,0,0,0.2);
  border-radius: 6px;
  text-align: center;
}

#quiz-result p {
  margin: 0;
  font-size: 1.1rem;
}

.btn {
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-main);
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.9rem;
  transition: all 0.2s;
}

.btn:hover {
  background: var(--surface-highlight);
  border-color: var(--text-muted);
}

.btn.primary {
  background: var(--primary);
  color: white;
  border-color: transparent;
}

.btn.primary:hover {
  background: var(--primary-hover);
}

.btn.danger {
  color: #fca5a5;
  border-color: rgba(239, 68, 68, 0.3);
  background: rgba(239, 68, 68, 0.1);
}

.btn.danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.btn.sm {
  padding: 4px 10px;
  font-size: 0.8rem;
}

/* Gate Palette */
.gate-palette {
  display: flex;
  gap: 8px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center; /* Center gates on small screens */
}

.gate-btn {
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: white;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  cursor: grab;
  user-select: none;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  touch-action: none;
}

.gate-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.gate-btn[data-type="MEASURE"] { background: #4b5563; }
.gate-btn[data-type="CNOT"] { background: var(--accent); }

/* Circuit Editor */
.circuit-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  min-height: 200px;
  overflow-x: auto;
  position: relative;
}

.circuit-editor.dragging-active .drop-zone {
  background: rgba(146, 112, 82, 0.1);
}

.circuit-grid {
  position: relative;
  display: inline-block; /* Grow with content */
}

.qubit-row {
  display: flex;
  align-items: center;
  height: 60px;
}

.qubit-label {
  width: 40px;
  font-weight: 600;
  color: var(--text-muted);
  text-align: right;
  padding-right: 10px;
}

.wire-container {
  display: flex;
  align-items: center;
  position: relative;
}

.wire-line {
  position: absolute;
  top: 50%;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--wire-color);
  z-index: 0;
}

.drop-zone {
  width: 50px;
  height: 50px;
  position: relative;
  z-index: 1;
  margin: 0 2px;
  border: 1px dashed transparent;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.drop-zone.drag-over {
  background: rgba(16, 185, 129, 0.2);
  border-color: var(--accent);
}

.placed-gate {
  width: 40px;
  height: 40px;
  background: var(--primary);
  color: white;
  font-size: 0.8rem;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.placed-gate.control {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: transparent;
  opacity: 0; /* Hidden hit target for SVG dot */
}

/* SVG Overlay */
.circuit-overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 2;
}

.cnot-line {
  stroke: var(--text-main);
  stroke-width: 2;
}

.cnot-control {
  fill: var(--text-main);
}

/* Simulation Controls */
.simulation-controls {
  margin-top: 20px;
  display: flex;
  align-items: center;
  gap: 15px;
}

#loading {
  color: var(--text-muted);
  font-style: italic;
}

.hidden { display: none; }

/* Results */
.results-container {
  margin-top: 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
}

.output-console {
  font-family: monospace;
  white-space: pre-wrap;
  color: #e2e8f0;
  font-size: 0.9rem;
  max-height: 300px;
  overflow-y: auto;
}

.placeholder {
  color: var(--text-muted);
  font-style: italic;
}

/* Bloch Sphere */
.bloch-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Task Box */
.task-box {
  background: rgba(30, 41, 59, 0.5); /* Slate 800 alpha */
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 15px;
  margin: 20px 0;
}

.task-box h3 {
  margin-top: 0;
  color: #60a5fa; /* Blue 400 */
  font-size: 1.1rem;
  margin-bottom: 0.5rem;
}

.task-box p {
  margin-bottom: 0.5rem;
  color: #bfdbfe; /* Blue 200 */
}

#task-status {
  font-weight: bold;
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
}

.status-pending {
  background: rgba(59, 130, 246, 0.2);
  color: #93c5fd;
}

.status-success {
  background: rgba(16, 185, 129, 0.2);
  color: #6ee7b7;
}

.status-fail {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

/* Modal Styles */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal.hidden {
  display: none;
}

.modal-content {
  background: var(--surface);
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--border);
  width: 350px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
}

.modal-content h3 {
  margin-top: 0;
  margin-bottom: 20px;
  color: var(--primary);
  text-align: center;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 15px;
  margin-bottom: 20px;
}

.slider-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.slider-group label {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.slider-group input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.input-group {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
}

.input-group input {
  background: var(--sidebar-bg);
  border: 1px solid var(--border);
  color: var(--text-main);
  padding: 8px;
  border-radius: 4px;
  width: 100px;
  text-align: center;
  font-family: 'Courier New', monospace;
}

.unit {
  color: var(--text-muted);
}

.preset-buttons {
  display: flex;
  justify-content: space-between;
  gap: 5px;
}

.preset-buttons button {
  flex: 1;
  font-size: 0.8rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Lesson List Sections */
.section-group {
  /* No special style for the li container */
}

.section-title {
  padding: 12px 20px;
  color: var(--text-muted);
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: color 0.2s;
}

.section-title:hover {
  color: var(--text-main);
}

.toggle-icon {
  font-size: 0.7rem;
  transition: transform 0.2s;
}

.section-group.expanded .toggle-icon {
  transform: rotate(90deg);
}

.section-lessons {
  list-style: none;
  padding: 0;
  margin: 0;
  display: none; /* Hidden by default */
  background: rgba(0,0,0,0.2); /* Slightly darker for nested */
}

.section-group.expanded .section-lessons {
  display: block;
}

.section-lessons li a {
  padding-left: 40px; /* Indent nested lessons */
  font-size: 0.95em;
}
