/* === Video Codecs: From Why to Wow === */
/* PerThirtySix-inspired dark theme, mobile-first */

:root {
  --bg: #0e0e12;
  --bg-card: #1a1a22;
  --bg-accent: #22222e;
  --text: #e0e0ea;
  --text-muted: #88889c;
  --accent: #ff6b35;
  --accent-glow: rgba(255, 107, 53, 0.2);
  --accent2: #00bcd4;
  --accent3: #76ff03;
  --border: #2a2a3e;
  --danger: #ff1744;
  --success: #69f0ae;
  --radius: 12px;
  --radius-sm: 8px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'SF Mono', 'Fira Code', 'JetBrains Mono', monospace;
  --max-width: 760px;
  --shadow: 0 2px 16px rgba(0,0,0,0.4);
  --transition: 0.25s ease;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { scroll-behavior: smooth; }

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

/* === Navigation === */
.top-nav {
  position: sticky; top: 0; z-index: 100;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
}

.nav-brand {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--text);
  text-decoration: none;
}
.nav-brand .emoji { font-size: 1.2rem; }

.nav-lesson {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: none;
}
@media (min-width: 500px) { .nav-lesson { display: block; } }

.menu-btn {
  background: none; border: none; color: var(--text);
  font-size: 1.4rem; cursor: pointer; padding: 0.3rem;
  line-height: 1;
}

/* Slide-out lesson drawer */
.lesson-drawer {
  position: fixed; top: 0; right: 0; z-index: 200;
  width: 300px; max-width: 85vw; height: 100dvh;
  background: var(--bg-card);
  border-left: 1px solid var(--border);
  transform: translateX(100%);
  transition: transform var(--transition);
  padding: 1.2rem;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.lesson-drawer.open { transform: translateX(0); }

.drawer-overlay {
  position: fixed; inset: 0; z-index: 199;
  background: rgba(0,0,0,0.5);
  display: none;
}
.drawer-overlay.active { display: block; }

.drawer-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.2rem;
}
.drawer-header h3 { font-size: 1.05rem; font-weight: 600; }
.drawer-close {
  background: none; border: none; color: var(--text); font-size: 1.4rem;
  cursor: pointer;
}
.drawer-progress-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-bottom: 0.8rem;
}

.lesson-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.lesson-list li a {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.7rem 0.8rem;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  text-decoration: none;
  font-size: 0.88rem;
  transition: all var(--transition);
}
.lesson-list li a:hover, .lesson-list li a.active {
  color: var(--text); background: var(--bg-accent);
}
.lesson-list li a.active {
  border-left: 3px solid var(--accent);
  padding-left: calc(0.8rem - 3px);
  font-weight: 600;
}
.lesson-num {
  font-size: 0.67rem;
  font-weight: 700;
  color: var(--accent);
  width: 1.4rem;
  text-align: center;
  font-family: var(--font-mono);
}
.lesson-check {
  margin-left: auto;
  font-size: 0.8rem;
  opacity: 0;
  transition: opacity var(--transition);
}
.lesson-check.done { opacity: 1; }

/* === Main content === */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 2rem 1.2rem 4rem;
}

.lesson-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}

.lesson-meta {
  font-size: 0.73rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.lesson-header h1 {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 0.5rem;
}

.lesson-subtitle {
  font-size: 1rem;
  color: var(--text-muted);
  line-height: 1.5;
}

/* Story hook */
.story-hook {
  background: var(--bg-card);
  border-left: 4px solid var(--accent);
  padding: 1.2rem 1.4rem;
  border-radius: 0 var(--radius) var(--radius) 0;
  margin: 1.5rem 0;
  font-size: 1.05rem;
  color: var(--text);
  font-style: normal;
  line-height: 1.6;
}
.story-hook em { color: var(--accent2); font-style: normal; }

/* TL;DR box */
.tldr {
  background: var(--bg-accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
}
.tldr-label {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.3rem;
}
.tldr p { font-size: 0.92rem; color: var(--text-muted); line-height: 1.6; }

/* Section headers */
h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin: 2.5rem 0 0.8rem;
  letter-spacing: -0.02em;
  line-height: 1.3;
  color: var(--text);
}

h3 {
  font-size: 1.12rem;
  font-weight: 650;
  margin: 1.6rem 0 0.5rem;
  color: var(--text);
}

h4 {
  font-size: 1rem;
  font-weight: 600;
  margin: 1.2rem 0 0.4rem;
  color: var(--text);
}

p {
  margin: 0.7rem 0;
  font-size: 1rem;
  line-height: 1.75;
  color: var(--text);
}

/* Inline emphasis */
.key-term {
  color: var(--accent2);
  font-weight: 600;
}

.code-ref {
  font-family: var(--font-mono);
  background: var(--bg-accent);
  padding: 0.1em 0.4em;
  border-radius: 4px;
  font-size: 0.9em;
}

/* Lists */
.content-list {
  list-style: none;
  padding: 0;
  margin: 0.8rem 0;
}
.content-list li {
  padding: 0.3rem 0;
  padding-left: 1.2rem;
  position: relative;
  font-size: 0.95rem;
}
.content-list li::before {
  content: '→';
  position: absolute; left: 0;
  color: var(--accent3);
  font-weight: 700;
}

/* Ordered list */
ol.content-list {
  counter-reset: step-counter;
}
ol.content-list li {
  counter-increment: step-counter;
  padding-left: 1.8rem;
}
ol.content-list li::before {
  content: counter(step-counter) '.';
  position: absolute; left: 0;
  color: var(--accent);
  font-weight: 700;
  font-family: var(--font-mono);
}

/* Step numbers (inline) */
.step {
  display: flex; align-items: baseline; gap: 0.4rem;
  margin: 0.3rem 0;
}
.step-num {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--accent);
  font-weight: 700;
  min-width: 1.2rem;
}

/* === Interactive Widgets === */
.widget {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin: 1.5rem 0;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.widget-header {
  padding: 0.7rem 1rem;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-accent);
  border-bottom: 1px solid var(--border);
}

.widget-body {
  padding: 1rem;
}

.widget canvas {
  display: block;
  width: 100%;
  touch-action: manipulation;
  margin: 0 auto;
}

.widget-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 0.8rem;
  align-items: center;
}

.widget-controls label {
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

.widget-controls select {
  background: var(--bg-accent);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.6rem;
  font-size: 0.85rem;
  font-family: var(--font);
  max-width: 180px;
}

.widget-controls input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 120px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}
.widget-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-card);
}
.widget-controls input[type="range"]::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
  border: 2px solid var(--bg-card);
}

.widget-controls button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.9rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  font-family: var(--font);
  transition: background var(--transition);
  white-space: nowrap;
}
.widget-controls button:hover { background: #e55a28; }
.widget-controls button:active { background: #cc4d20; }

.widget-controls .value-display {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--accent2);
  min-width: 1.5rem;
  text-align: center;
}

.widget-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
  margin: 0.6rem 0 0;
}

/* === Callout boxes === */
.callout {
  background: var(--bg-accent);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
  font-size: 0.92rem;
}
.callout strong { color: var(--accent); }

.callout-info {
  background: rgba(0, 188, 212, 0.08);
  border: 1px solid rgba(0, 188, 212, 0.25);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
  font-size: 0.92rem;
}
.callout-info strong { color: var(--accent2); }

.callout-warn {
  background: rgba(255, 107, 53, 0.08);
  border: 1px solid rgba(255, 107, 53, 0.25);
  border-radius: var(--radius);
  padding: 1rem 1.2rem;
  margin: 1.5rem 0;
  font-size: 0.92rem;
}
.callout-warn strong { color: var(--accent); }

.experiment-callout {
  background: var(--bg-card);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  padding: 0.9rem 1.1rem;
  margin: 1.5rem 0;
  font-size: 0.88rem;
  color: var(--text-muted);
}
.experiment-callout::before {
  content: '🖥️ Try it: ';
  font-weight: 600;
  color: var(--accent3);
}

/* === Bottom navigation === */
.lesson-nav-bottom {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--border);
  gap: 1rem;
}

.nav-btn {
  padding: 0.6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 500;
  transition: all var(--transition);
  display: flex; align-items: center; gap: 0.3rem;
}
.nav-btn:hover { border-color: var(--accent); background: var(--bg-accent); }
.nav-btn.next { margin-left: auto; background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.nav-btn.prev { margin-right: auto; }

/* Completion checkbox style */
.completion-box {
  display: flex; align-items: center; gap: 0.6rem;
  padding: 0.8rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-top: 1.5rem;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text-muted);
  transition: all var(--transition);
  user-select: none;
}
.completion-box:hover { border-color: var(--accent); }
.completion-box.checked {
  border-color: var(--success);
  color: var(--success);
}
.completion-box .check-icon {
  font-size: 1.1rem;
  width: 1.4rem;
  text-align: center;
}
.completion-box .check-text { flex: 1; }

/* Progress bar under nav */
.progress-bar {
  height: 2px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 0.5rem;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
}

/* Animations */
.fade-in {
  animation: fadeIn 0.6s ease both;
}
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin: 1rem 0;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}
table th {
  text-align: left;
  padding: 0.5rem 0.7rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  background: var(--bg-accent);
  white-space: nowrap;
}
table td {
  padding: 0.5rem 0.7rem;
  border-bottom: 1px solid var(--border);
}
table tr:hover td { background: var(--bg-accent); }

/* Code / formula */
.formula {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  background: var(--bg-accent);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius-sm);
  display: block;
  letter-spacing: 0.02em;
  overflow-x: auto;
  margin: 0.8rem 0;
  line-height: 1.5;
  text-align: center;
}

.formula-block {
  font-family: var(--font-mono);
  font-size: 0.83rem;
  background: var(--bg-accent);
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  display: block;
  letter-spacing: 0.02em;
  overflow-x: auto;
  margin: 0.8rem 0;
  line-height: 1.6;
}

/* Code block */
.code-block {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  background: #111118;
  padding: 0.8rem 1rem;
  border-radius: var(--radius-sm);
  display: block;
  overflow-x: auto;
  margin: 0.8rem 0;
  line-height: 1.5;
  border: 1px solid var(--border);
}

/* Comparison cards */
.comparison-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.8rem;
  margin: 1.2rem 0;
}
.comparison-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
}
.comparison-card h4 {
  margin: 0 0 0.3rem;
  font-size: 0.95rem;
}
.comparison-card p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin: 0;
}

/* Two-column for desktop */
@media (min-width: 600px) {
  .two-col {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
  }
}

/* Responsive */
@media (max-width: 500px) {
  .lesson-header h1 { font-size: 1.55rem; }
  h2 { font-size: 1.2rem; }
  .story-hook { font-size: 0.95rem; padding: 1rem 1.1rem; }
  .widget-controls { flex-direction: column; align-items: flex-start; }
  .widget-controls input[type="range"] { width: 100%; }
  .comparison-grid { grid-template-columns: 1fr; }
}