/* =============================================
   WebCodex — Programació Web
   Styles + 4 Themes (dark, light, dark-blue, terminal)
   ============================================= */

/* === CSS VARIABLES (default: dark) === */
:root {
  --bg-primary:    #111827;
  --bg-secondary:  #1f2937;
  --bg-tertiary:   #374151;
  --bg-code:       #0d1117;
  --text-primary:  #f9fafb;
  --text-secondary:#9ca3af;
  --text-muted:    #6b7280;
  --accent:        #22d3ee;
  --accent-hover:  #67e8f9;
  --accent-dim:    rgba(34,211,238,0.15);
  --border:        #374151;
  --border-light:  #4b5563;
  --success:       #22c55e;
  --success-dim:   rgba(34,197,94,0.15);
  --error:         #ef4444;
  --error-dim:     rgba(239,68,68,0.15);
  --warning:       #f59e0b;
  --warning-dim:   rgba(245,158,11,0.15);
  --shadow:        rgba(0,0,0,0.4);
  --shadow-lg:     rgba(0,0,0,0.6);
  --sidebar-w:     240px;
  --header-h:      60px;
  --radius:        8px;
  --radius-lg:     12px;
  --transition:    0.2s ease;
  --font-mono:     'Courier New', 'Consolas', monospace;
  --font-body:     system-ui, -apple-system, 'Segoe UI', sans-serif;
}

[data-theme="light"] {
  --bg-primary:    #ffffff;
  --bg-secondary:  #f8fafc;
  --bg-tertiary:   #e2e8f0;
  --bg-code:       #f1f5f9;
  --text-primary:  #1e293b;
  --text-secondary:#475569;
  --text-muted:    #94a3b8;
  --accent:        #3b82f6;
  --accent-hover:  #2563eb;
  --accent-dim:    rgba(59,130,246,0.1);
  --border:        #e2e8f0;
  --border-light:  #cbd5e1;
  --success:       #16a34a;
  --success-dim:   rgba(22,163,74,0.1);
  --error:         #dc2626;
  --error-dim:     rgba(220,38,38,0.1);
  --warning:       #d97706;
  --warning-dim:   rgba(217,119,6,0.1);
  --shadow:        rgba(0,0,0,0.08);
  --shadow-lg:     rgba(0,0,0,0.15);
}

[data-theme="dark-blue"] {
  --bg-primary:    #0a1628;
  --bg-secondary:  #0d1f3c;
  --bg-tertiary:   #132a4e;
  --bg-code:       #060f1e;
  --text-primary:  #e2eaf4;
  --text-secondary:#8ba3c0;
  --text-muted:    #5d7a99;
  --accent:        #4fc3f7;
  --accent-hover:  #81d4fa;
  --accent-dim:    rgba(79,195,247,0.15);
  --border:        #1a3a5c;
  --border-light:  #254d72;
  --success:       #4ade80;
  --success-dim:   rgba(74,222,128,0.12);
  --error:         #f87171;
  --error-dim:     rgba(248,113,113,0.12);
  --warning:       #fbbf24;
  --warning-dim:   rgba(251,191,36,0.12);
  --shadow:        rgba(0,0,0,0.5);
  --shadow-lg:     rgba(0,0,0,0.7);
}

[data-theme="terminal"] {
  --bg-primary:    #000000;
  --bg-secondary:  #0a0a0a;
  --bg-tertiary:   #111111;
  --bg-code:       #000800;
  --text-primary:  #00ff41;
  --text-secondary:#00cc33;
  --text-muted:    #008822;
  --accent:        #00ff41;
  --accent-hover:  #33ff66;
  --accent-dim:    rgba(0,255,65,0.12);
  --border:        #003300;
  --border-light:  #004400;
  --success:       #00ff41;
  --success-dim:   rgba(0,255,65,0.15);
  --error:         #ff4444;
  --error-dim:     rgba(255,68,68,0.15);
  --warning:       #ffff00;
  --warning-dim:   rgba(255,255,0,0.12);
  --shadow:        rgba(0,255,65,0.05);
  --shadow-lg:     rgba(0,0,0,0.8);
  --font-body:     'Courier New', monospace;
}

/* === RESET & BASE === */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: var(--font-body);
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

code, pre {
  font-family: var(--font-mono);
  background: var(--bg-code);
  border-radius: 4px;
}
code { padding: 2px 6px; font-size: 0.875em; color: var(--accent); }
pre { padding: 1rem; overflow-x: auto; border: 1px solid var(--border); }
pre code { background: none; padding: 0; color: var(--text-primary); font-size: 0.875rem; }

[data-theme="terminal"] pre,
[data-theme="terminal"] code { color: var(--text-primary); }

img { max-width: 100%; height: auto; }
button { cursor: pointer; font-family: var(--font-body); }
input, textarea, select { font-family: var(--font-body); }

.sr-only {
  position: absolute; width: 1px; height: 1px;
  padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}
.hidden { display: none !important; }

/* === APP LAYOUT === */
#app {
  display: grid;
  grid-template-areas:
    "header header"
    "sidebar main";
  grid-template-rows: var(--header-h) 1fr;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

#app.sidebar-collapsed {
  grid-template-columns: 60px 1fr;
  --sidebar-w: 60px;
}

/* === HEADER === */
#header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 1rem;
  box-shadow: 0 2px 8px var(--shadow);
}

.header-left { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }
.header-center { flex: 1; max-width: 500px; }
.header-right { display: flex; align-items: center; gap: 0.75rem; flex-shrink: 0; }

/* Logo */
.logo { display: flex; align-items: center; gap: 0.5rem; }
.logo-icon { font-size: 1.5rem; }
.logo-text {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--accent);
  letter-spacing: -0.5px;
}
.logo-text span { color: var(--text-secondary); font-weight: 400; font-size: 0.8rem; display: block; line-height: 1; }

#app.sidebar-collapsed .logo-text { display: none; }

/* Sidebar toggle */
#sidebar-toggle {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  width: 36px; height: 36px;
  border-radius: var(--radius);
  font-size: 1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
#sidebar-toggle:hover { background: var(--bg-tertiary); color: var(--text-primary); }

/* Search bar */
.search-bar { position: relative; width: 100%; }
#search-input {
  width: 100%;
  padding: 0.5rem 0.75rem 0.5rem 2.25rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}
#search-input::placeholder { color: var(--text-muted); }
#search-input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.search-bar::before {
  content: "🔍";
  position: absolute;
  left: 0.6rem; top: 50%;
  transform: translateY(-50%);
  font-size: 0.8rem;
  pointer-events: none;
}

.search-dropdown {
  position: absolute;
  top: calc(100% + 8px);
  left: 0; right: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px var(--shadow-lg);
  z-index: 200;
  max-height: 300px;
  overflow-y: auto;
}
.search-item {
  padding: 0.6rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
}
.search-item:last-child { border-bottom: none; }
.search-item:hover { background: var(--accent-dim); }
.search-item-type {
  font-size: 0.7rem;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 4px;
}
.search-no-results { padding: 1rem; text-align: center; color: var(--text-muted); font-size: 0.875rem; }

/* Language selector */
.lang-selector {
  display: flex;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
}
.lang-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.5px;
  transition: all var(--transition);
}
.lang-btn:hover { color: var(--text-primary); }
.lang-btn.active {
  background: var(--accent);
  color: #000;
  border-radius: 20px;
}
[data-theme="light"] .lang-btn.active { color: #fff; }

/* Theme selector */
.theme-selector { display: flex; gap: 4px; }
.theme-btn {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  width: 32px; height: 32px;
  font-size: 0.85rem;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  color: var(--text-secondary);
}
.theme-btn:hover { border-color: var(--accent); transform: scale(1.1); }
.theme-btn.active { border-color: var(--accent); background: var(--accent-dim); }

/* === SIDEBAR === */
#sidebar {
  grid-area: sidebar;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition);
  position: sticky;
  top: var(--header-h);
  height: calc(100vh - var(--header-h));
  overflow-y: auto;
}

.nav-list {
  list-style: none;
  padding: 0.75rem 0.5rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
  overflow: hidden;
}
.nav-item:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}
.nav-icon { font-size: 1.1rem; flex-shrink: 0; width: 20px; text-align: center; }
.nav-label { overflow: hidden; text-overflow: ellipsis; }

#app.sidebar-collapsed .nav-label { display: none; }
#app.sidebar-collapsed .nav-item { justify-content: center; padding: 0.625rem; }

/* Sidebar footer - progress */
.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
}
.progress-mini { display: flex; flex-direction: column; gap: 4px; }
.progress-mini-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
}
.progress-mini-bar {
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}
.progress-mini-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.5s ease;
  width: 0%;
}
#app.sidebar-collapsed .sidebar-footer { display: none; }

/* === MAIN CONTENT === */
#main {
  grid-area: main;
  overflow-y: auto;
  min-height: calc(100vh - var(--header-h));
}

.view { display: none; padding: 2rem; max-width: 1200px; margin: 0 auto; }
.view.active { display: block; }

/* === PAGE TITLES === */
.page-header {
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
}
.page-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}
.page-subtitle { color: var(--text-secondary); font-size: 0.95rem; }

/* === HOME VIEW === */
#view-home { padding: 0; max-width: none; }

.hero {
  text-align: center;
  padding: 4rem 2rem 3rem;
  background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
  border-bottom: 1px solid var(--border);
  position: relative;
  overflow: hidden;
}
.hero::before {
  content: '';
  position: absolute;
  top: -50%; left: -50%;
  width: 200%; height: 200%;
  background: radial-gradient(ellipse at 50% 50%, var(--accent-dim) 0%, transparent 60%);
  pointer-events: none;
}
.hero-title {
  font-size: clamp(2rem, 4vw, 3rem);
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  position: relative;
}
.hero-title span { color: var(--accent); }
.hero-subtitle {
  font-size: 1.1rem;
  color: var(--text-secondary);
  margin-bottom: 2rem;
  letter-spacing: 2px;
  position: relative;
}
.hero-actions { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; position: relative; }

.hero-progress {
  max-width: 400px;
  margin: 2rem auto 0;
  position: relative;
}
.hero-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 6px;
}
.hero-progress-bar {
  height: 8px;
  background: var(--bg-tertiary);
  border-radius: 4px;
  overflow: hidden;
}
.hero-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: 4px;
  transition: width 0.6s ease;
}

/* Stats row */
.home-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  padding: 2rem;
  max-width: 1200px;
  margin: 0 auto;
}
.stat-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  text-align: center;
  transition: transform var(--transition), box-shadow var(--transition);
}
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 4px 16px var(--shadow); }
.stat-icon { font-size: 1.75rem; margin-bottom: 0.5rem; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* Units grid */
.home-units {
  padding: 0 2rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
}
.section-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-bottom: 1rem;
}
.units-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.25rem;
}
.unit-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}
.unit-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--unit-color, var(--accent));
}
.unit-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px var(--shadow); border-color: var(--accent); }
.unit-card-header { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; }
.unit-card-icon { font-size: 2rem; }
.unit-card-title { font-size: 1.1rem; font-weight: 700; }
.unit-card-desc { font-size: 0.875rem; color: var(--text-secondary); margin-bottom: 1rem; }
.unit-card-progress { font-size: 0.75rem; color: var(--text-muted); }
.unit-progress-bar { height: 4px; background: var(--bg-tertiary); border-radius: 2px; margin-top: 4px; overflow: hidden; }
.unit-progress-fill { height: 100%; background: var(--unit-color, var(--accent)); border-radius: 2px; transition: width 0.5s ease; }

/* === BUTTONS === */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-weight: 500;
  border: 1px solid transparent;
  transition: all var(--transition);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
[data-theme="light"] .btn-primary { color: #fff; }
[data-theme="terminal"] .btn-primary { color: #000; font-weight: 700; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); transform: translateY(-1px); }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border);
}
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-tertiary); color: var(--text-primary); }

.btn-sm { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-lg { padding: 0.8rem 2rem; font-size: 1rem; }
.btn-icon { padding: 0.5rem; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

/* === THEORY / ACCORDION === */
.theory-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.unit-filter {
  display: flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: 20px;
  overflow: hidden;
  flex-shrink: 0;
}
.unit-filter-btn {
  background: none;
  border: none;
  color: var(--text-secondary);
  padding: 6px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.unit-filter-btn:hover { color: var(--text-primary); }
.unit-filter-btn.active {
  background: var(--accent);
  color: #000;
  border-radius: 20px;
}
[data-theme="light"] .unit-filter-btn.active { color: #fff; }

.accordion { display: flex; flex-direction: column; gap: 8px; }
.accordion-item {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition);
}
.accordion-item:hover { border-color: var(--border-light); }
.accordion-item.open { border-color: var(--accent); }

.accordion-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem;
  cursor: pointer;
  user-select: none;
  transition: background var(--transition);
}
.accordion-header:hover { background: var(--bg-tertiary); }
.accordion-icon { font-size: 1.25rem; flex-shrink: 0; }
.accordion-title { font-weight: 600; font-size: 0.95rem; flex: 1; }
.accordion-badge {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
  flex-shrink: 0;
}
.accordion-badge.read {
  background: var(--success-dim);
  color: var(--success);
}
.accordion-chevron {
  color: var(--text-muted);
  font-size: 0.75rem;
  transition: transform var(--transition);
  flex-shrink: 0;
}
.accordion-item.open .accordion-chevron { transform: rotate(180deg); }

.accordion-body {
  display: none;
  padding: 0 1.25rem 1.25rem;
  border-top: 1px solid var(--border);
}
.accordion-item.open .accordion-body { display: block; }

.topic-content { padding-top: 1rem; }
.topic-content p { margin-bottom: 0.875rem; color: var(--text-secondary); line-height: 1.7; }
.topic-content strong { color: var(--text-primary); }
.topic-content ul, .topic-content ol { margin: 0.5rem 0 0.875rem 1.5rem; color: var(--text-secondary); }
.topic-content li { margin-bottom: 0.25rem; }
.topic-content h3 { font-size: 1rem; color: var(--text-primary); margin: 1rem 0 0.5rem; }
.topic-content h4 { font-size: 0.9rem; color: var(--accent); margin: 0.75rem 0 0.25rem; }

.code-block {
  margin: 1rem 0;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--bg-tertiary);
  font-size: 0.75rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
}
.code-block pre {
  margin: 0;
  border: none;
  border-radius: 0;
  padding: 1rem;
  background: var(--bg-code);
  font-size: 0.85rem;
}
.copy-code-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.7rem;
  cursor: pointer;
  transition: all var(--transition);
}
.copy-code-btn:hover { color: var(--accent); border-color: var(--accent); }

.topic-actions { margin-top: 1.25rem; display: flex; gap: 0.75rem; align-items: center; flex-wrap: wrap; }

.subtopics { margin-top: 1rem; }
.subtopic {
  border-left: 3px solid var(--border);
  padding-left: 1rem;
  margin-bottom: 1rem;
  transition: border-color var(--transition);
}
.subtopic:hover { border-color: var(--accent); }
.subtopic-title { font-weight: 600; font-size: 0.9rem; color: var(--text-primary); margin-bottom: 0.5rem; }

/* === TUTORIALS VIEW === */
.tutorials-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.25rem;
  margin-bottom: 2rem;
}
.tutorial-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.tutorial-card:hover { transform: translateY(-3px); box-shadow: 0 8px 24px var(--shadow); border-color: var(--accent); }
.tutorial-card-icon { font-size: 2rem; margin-bottom: 0.75rem; }
.tutorial-card-title { font-size: 1rem; font-weight: 700; margin-bottom: 0.5rem; }
.tutorial-card-desc { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 1rem; }
.tutorial-card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.difficulty-badge {
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 600;
}
.difficulty-easy   { background: var(--success-dim); color: var(--success); }
.difficulty-medium { background: var(--warning-dim); color: var(--warning); }
.difficulty-hard   { background: var(--error-dim);   color: var(--error); }

/* Tutorial player */
#tutorial-player { display: none; }
#tutorial-player.active { display: block; }

.tutorial-player-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.tutorial-player-title { font-size: 1.25rem; font-weight: 700; flex: 1; }
.tutorial-step-counter {
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 4px 12px;
  border-radius: 20px;
  border: 1px solid var(--border);
}

.tutorial-progress-steps {
  display: flex;
  gap: 6px;
  margin-bottom: 1.5rem;
}
.step-dot {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
}
.step-dot.active { background: var(--accent); border-color: var(--accent); color: #000; }
.step-dot.done { background: var(--success-dim); border-color: var(--success); color: var(--success); }

.tutorial-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
}
@media (max-width: 900px) { .tutorial-layout { grid-template-columns: 1fr; } }

.tutorial-instructions {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
}
.tutorial-step-title { font-size: 1rem; font-weight: 700; margin-bottom: 1rem; color: var(--accent); }
.tutorial-step-content { font-size: 0.9rem; color: var(--text-secondary); line-height: 1.7; }
.tutorial-step-content p { margin-bottom: 0.75rem; }
.tutorial-step-content code { font-size: 0.875em; }
.tutorial-goal {
  margin-top: 1rem;
  padding: 0.75rem 1rem;
  background: var(--accent-dim);
  border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.875rem;
}
.tutorial-goal strong { color: var(--accent); }

.tutorial-hint {
  margin-top: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--warning-dim);
  border-left: 3px solid var(--warning);
  border-radius: 0 var(--radius) var(--radius) 0;
  font-size: 0.875rem;
  display: none;
}
.tutorial-hint.visible { display: block; }

.tutorial-editor-pane {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.mini-editor-tabs {
  display: flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  overflow: hidden;
}
.mini-editor-tab {
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  border-right: 1px solid var(--border);
}
.mini-editor-tab:last-child { border-right: none; }
.mini-editor-tab.active { background: var(--bg-tertiary); color: var(--text-primary); }
.mini-editor-tab:hover:not(.active) { color: var(--text-primary); }

.mini-editor-code {
  background: var(--bg-code);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius) var(--radius);
  font-family: var(--font-mono);
  font-size: 0.85rem;
  color: var(--text-primary);
  padding: 1rem;
  resize: vertical;
  min-height: 200px;
  outline: none;
  width: 100%;
}
.mini-editor-code:focus { border-color: var(--accent); }

.tutorial-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.tutorial-preview-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}
.preview-dot { width: 10px; height: 10px; border-radius: 50%; }
.preview-dot:nth-child(1) { background: #ff5f57; }
.preview-dot:nth-child(2) { background: #febc2e; }
.preview-dot:nth-child(3) { background: #28c840; }
.tutorial-preview iframe {
  width: 100%;
  height: 250px;
  background: #fff;
  border: none;
  display: block;
}

.tutorial-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 0.75rem;
}
.tutorial-nav-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

/* === EDITOR VIEW === */
.editor-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.editor-layout {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  overflow: hidden;
  height: calc(100vh - var(--header-h) - 200px);
  min-height: 300px;
}
@media (max-width: 900px) {
  .editor-layout { grid-template-columns: 1fr 1fr; height: auto; }
}

.editor-pane {
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}
.editor-pane:last-child { border-right: none; }

.editor-pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  flex-shrink: 0;
}
.editor-pane-lang { font-size: 0.7rem; color: var(--text-muted); background: var(--bg-tertiary); padding: 2px 6px; border-radius: 4px; }

.code-editor {
  flex: 1;
  background: var(--bg-code);
  color: var(--text-primary);
  font-family: var(--font-mono);
  font-size: 0.875rem;
  line-height: 1.6;
  padding: 1rem;
  border: none;
  outline: none;
  resize: none;
  width: 100%;
  tab-size: 2;
}
.code-editor::placeholder { color: var(--text-muted); }

/* ── Editor resize handle ── */
#editor-resize-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 14px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  cursor: ns-resize;
  user-select: none;
  transition: background 0.15s;
}
#editor-resize-handle:hover,
#editor-resize-handle.dragging {
  background: var(--accent);
}
.resize-handle-dots {
  width: 32px;
  height: 4px;
  border-radius: 2px;
  background: var(--text-muted);
  opacity: 0.5;
  transition: opacity 0.15s;
  pointer-events: none;
}
#editor-resize-handle:hover .resize-handle-dots,
#editor-resize-handle.dragging .resize-handle-dots {
  opacity: 1;
  background: white;
}

.preview-pane {
  display: flex;
  flex-direction: column;
}
.preview-pane iframe {
  flex: 1;
  background: #fff;
  border: none;
  width: 100%;
  min-height: 400px;
}

.editor-status {
  font-size: 0.75rem;
  color: var(--text-muted);
}

/* Font size select */
.font-size-select {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 4px 8px;
  border-radius: var(--radius);
  font-size: 0.8rem;
  outline: none;
}

/* Templates dropdown */
.templates-dropdown { position: relative; }
.templates-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px var(--shadow-lg);
  z-index: 50;
  min-width: 160px;
  display: none;
}
.templates-menu.open { display: block; }
.template-option {
  display: block;
  padding: 0.6rem 1rem;
  cursor: pointer;
  font-size: 0.875rem;
  color: var(--text-secondary);
  transition: background var(--transition);
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.template-option:hover { background: var(--accent-dim); color: var(--text-primary); }

/* === EXERCISES VIEW === */
.exercises-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.filter-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.filter-label { font-size: 0.8rem; color: var(--text-muted); white-space: nowrap; }
.filter-chips { display: flex; gap: 4px; flex-wrap: wrap; }
.chip {
  padding: 4px 12px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.active { background: var(--accent); border-color: var(--accent); color: #000; }
[data-theme="light"] .chip.active { color: #fff; }

.exercises-score-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 1.25rem;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.score-item { display: flex; align-items: center; gap: 0.5rem; font-size: 0.875rem; }
.score-icon { font-size: 1.1rem; }
.score-value { font-weight: 700; color: var(--accent); }
.score-label { color: var(--text-muted); }

.exercises-grid {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.exercise-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  transition: border-color var(--transition);
}
.exercise-card.answered-correct { border-color: var(--success); }
.exercise-card.answered-wrong   { border-color: var(--error); }

.exercise-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}
.exercise-number {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 2px 8px;
  border-radius: 4px;
}
.exercise-meta { display: flex; gap: 0.5rem; margin-left: auto; align-items: center; }
.exercise-points {
  font-size: 0.75rem;
  color: var(--accent);
  font-weight: 700;
}

.exercise-question {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 1.25rem;
  line-height: 1.5;
}
.exercise-question code { font-size: 0.9em; }

.options-grid { display: flex; flex-direction: column; gap: 0.5rem; }
.option-btn {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all var(--transition);
  text-align: left;
  width: 100%;
}
.option-btn:hover:not(:disabled) { border-color: var(--accent); color: var(--text-primary); background: var(--accent-dim); }
.option-btn.selected { border-color: var(--accent); background: var(--accent-dim); color: var(--accent); }
.option-btn.correct  { border-color: var(--success); background: var(--success-dim); color: var(--success); }
.option-btn.wrong    { border-color: var(--error); background: var(--error-dim); color: var(--error); }
.option-btn:disabled { cursor: default; }
.option-letter {
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  flex-shrink: 0;
}
.option-btn.correct .option-letter  { background: var(--success); color: #fff; }
.option-btn.wrong   .option-letter  { background: var(--error); color: #fff; }
.option-btn.selected .option-letter { background: var(--accent); color: #000; }

.exercise-feedback {
  margin-top: 1rem;
  padding: 0.875rem 1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  display: none;
}
.exercise-feedback.show { display: block; }
.exercise-feedback.correct { background: var(--success-dim); border-left: 3px solid var(--success); }
.exercise-feedback.wrong   { background: var(--error-dim);   border-left: 3px solid var(--error); }
.feedback-icon { font-size: 1rem; margin-right: 0.5rem; }
.feedback-explanation { color: var(--text-secondary); margin-top: 0.5rem; }

/* === REFERENCE VIEW === */
.reference-tabs {
  display: flex;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 1.5rem;
  width: fit-content;
}
.ref-tab {
  padding: 0.6rem 1.5rem;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}
.ref-tab.active { background: var(--accent); color: #000; }
[data-theme="light"] .ref-tab.active { color: #fff; }
.ref-tab:hover:not(.active) { color: var(--text-primary); }

.reference-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.ref-search {
  flex: 1;
  max-width: 400px;
  padding: 0.5rem 0.75rem;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-primary);
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--transition);
}
.ref-search:focus { border-color: var(--accent); }

.reference-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}
.ref-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  transition: border-color var(--transition), transform var(--transition);
}
.ref-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.ref-card-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}
.ref-tag {
  font-family: var(--font-mono);
  font-size: 1rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--bg-code);
  padding: 2px 8px;
  border-radius: 4px;
}
.ref-category-badge {
  margin-left: auto;
  font-size: 0.65rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--bg-secondary);
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.ref-card-body { padding: 0.875rem 1rem; }
.ref-description { font-size: 0.85rem; color: var(--text-secondary); margin-bottom: 0.75rem; line-height: 1.5; }
.ref-example {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  background: var(--bg-code);
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius);
  color: var(--text-primary);
  border: 1px solid var(--border);
  overflow-x: auto;
  white-space: pre;
}
.ref-attrs { margin-top: 0.75rem; }
.ref-attrs-title { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.ref-attr { font-size: 0.75rem; color: var(--text-secondary); display: flex; gap: 0.5rem; margin-bottom: 2px; }
.ref-attr-name { color: var(--accent); font-family: var(--font-mono); }

/* === TOAST === */
#toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 1000;
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 8px 32px var(--shadow-lg);
  max-width: 320px;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}
#toast.show {
  transform: translateY(0);
  opacity: 1;
}
#toast.success { background: var(--success-dim); border: 1px solid var(--success); color: var(--success); }
#toast.error   { background: var(--error-dim);   border: 1px solid var(--error);   color: var(--error); }
#toast.info    { background: var(--accent-dim);   border: 1px solid var(--accent);  color: var(--accent); }
#toast.warning { background: var(--warning-dim); border: 1px solid var(--warning); color: var(--warning); }

/* === MODAL === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition);
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  max-width: 500px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(0.95);
  transition: transform var(--transition);
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; }
.modal-title { font-size: 1.25rem; font-weight: 700; }
.modal-close { background: none; border: none; color: var(--text-muted); font-size: 1.25rem; cursor: pointer; padding: 4px; }
.modal-close:hover { color: var(--text-primary); }

/* === ANIMATIONS === */
@keyframes fadeIn   { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }
@keyframes bounceIn { 0% { transform: scale(0.3); opacity: 0; } 60% { transform: scale(1.1); } 100% { transform: scale(1); opacity: 1; } }
@keyframes pulse    { 0%, 100% { opacity: 1; } 50% { opacity: 0.5; } }
@keyframes scanline { 0% { top: 0; } 100% { top: 100%; } }

.view.active { animation: fadeIn 0.2s ease; }
.bounce-in { animation: bounceIn 0.4s ease; }

/* Terminal theme scanline effect */
[data-theme="terminal"] #app::after {
  content: '';
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 2px;
  background: rgba(0,255,65,0.08);
  animation: scanline 8s linear infinite;
  pointer-events: none;
  z-index: 9999;
}

/* Terminal theme: blinking cursor */
[data-theme="terminal"] .code-editor { caret-color: var(--accent); }

/* ══════════════════════════════════════════
   SYNTAX HIGHLIGHTING  (VS Code Dark+ palette)
   ══════════════════════════════════════════ */
.hl-comment  { color: #6a9955; font-style: italic; }
.hl-keyword  { color: #569cd6; font-weight: 600; }
.hl-tag      { color: #4ec9b0; }
.hl-bracket  { color: #808080; }
.hl-attr     { color: #9cdcfe; }
.hl-val      { color: #ce9178; }
.hl-number   { color: #b5cea8; }
.hl-selector { color: #d7ba7d; }
.hl-prop     { color: #9cdcfe; }
.hl-punct    { color: #d4d4d4; }

/* Light theme overrides (VS Code Light+ palette) */
[data-theme="light"] .hl-comment  { color: #008000; }
[data-theme="light"] .hl-keyword  { color: #0000ff; }
[data-theme="light"] .hl-tag      { color: #0d7377; }
[data-theme="light"] .hl-bracket  { color: #666; }
[data-theme="light"] .hl-attr     { color: #0451a5; }
[data-theme="light"] .hl-val      { color: #a31515; }
[data-theme="light"] .hl-number   { color: #098658; }
[data-theme="light"] .hl-selector { color: #a0522d; }
[data-theme="light"] .hl-prop     { color: #0451a5; }
[data-theme="light"] .hl-punct    { color: #333; }

/* ══════════════════════════════════════════
   DEMO HEADER BUTTON  (accordion header)
   ══════════════════════════════════════════ */
.demo-header-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 20px;
  cursor: pointer;
  transition: all var(--transition);
  flex-shrink: 0;
  font-family: var(--font-body);
}
.demo-header-btn:hover {
  background: var(--accent);
  color: var(--bg-primary);
  transform: scale(1.04);
}

/* ══════════════════════════════════════════
   DEMO MODAL  (<dialog>)
   ══════════════════════════════════════════ */
/* <dialog> is hidden by default — only apply layout when open */
.demo-dialog {
  width: min(94vw, 1100px);
  max-height: min(90vh, 720px);
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--bg-secondary);
  color: var(--text-primary);
  box-shadow: 0 24px 64px var(--shadow-lg);
  overflow: hidden;
  /* Center in viewport for browsers that don't auto-center <dialog> */
  margin: auto;
}
/* Only apply flex layout when the dialog is actually open */
.demo-dialog[open] {
  display: flex;
  flex-direction: column;
  height: min(90vh, 720px);
}
.demo-dialog::backdrop {
  background: rgba(0, 0, 0, 0.65);
}

/* Header */
.demo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  gap: 1rem;
  flex-shrink: 0;
}
.demo-header-left  { display: flex; align-items: center; gap: 0.6rem; min-width: 0; }
.demo-header-right { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.demo-label {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-dim);
  border: 1px solid var(--accent);
  border-radius: 20px;
  padding: 2px 8px;
  flex-shrink: 0;
}
.demo-title {
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.demo-speed-label {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.8rem; color: var(--text-muted);
}
.demo-speed-select {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2px 4px;
  font-size: 0.78rem;
  cursor: pointer;
}
.demo-ctrl-btn {
  width: 32px; height: 32px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.85rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}
.demo-ctrl-btn:hover { background: var(--bg-tertiary); color: var(--text-primary); }
.demo-close:hover { background: var(--error-dim); color: var(--error); border-color: var(--error); }

/* Body: code + preview split */
.demo-body {
  display: grid;
  grid-template-columns: 1fr 1fr;
  flex: 1;
  min-height: 0;
  border-bottom: 1px solid var(--border);
}
.demo-pane {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.demo-code-pane  { border-right: 1px solid var(--border); }
.demo-pane-label {
  padding: 0.4rem 1rem;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}
.demo-pre {
  flex: 1;
  margin: 0;
  padding: 1.1rem 1.25rem;
  background: var(--bg-code);
  overflow: auto;
  border: none;
  border-radius: 0;
  font-size: 0.88rem;
  line-height: 1.65;
}
.demo-pre code {
  background: none;
  padding: 0;
  color: var(--text-primary);
  font-size: inherit;
  white-space: pre-wrap;
  word-break: break-all;
}
#demo-preview {
  flex: 1;
  border: none;
  background: #fff;
  width: 100%;
}

/* Blinking cursor inside demo code */
.demo-cursor-blink {
  display: inline-block;
  color: var(--accent);
  animation: blink 1s step-end infinite;
  font-weight: 400;
}
@keyframes blink { 0%,100%{ opacity:1 } 50%{ opacity:0 } }

/* Footer: explanation + navigation */
.demo-footer {
  padding: 0.85rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  flex-shrink: 0;
  min-height: 100px;
}
.demo-explanation {
  font-size: 0.88rem;
  color: var(--text-secondary);
  line-height: 1.55;
  min-height: 2.5em;
}
.demo-explanation strong { color: var(--text-primary); }
.demo-explanation code {
  background: var(--bg-tertiary);
  color: var(--accent);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
}
.demo-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}
.demo-step-dots { display: flex; align-items: center; gap: 6px; }
.demo-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--bg-tertiary);
  border: 1px solid var(--border-light);
  transition: all 0.2s;
  cursor: default;
}
.demo-dot.done   { background: var(--success); border-color: var(--success); }
.demo-dot.active { background: var(--accent);  border-color: var(--accent); transform: scale(1.3); }
.demo-nav-btns   { display: flex; gap: 0.5rem; }

/* Responsive: stack on small screens */
@media (max-width: 640px) {
  .demo-dialog { width: 100vw; height: 100vh; border-radius: 0; border: none; }
  .demo-body   { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .demo-code-pane { border-right: none; border-bottom: 1px solid var(--border); }
}

/* === RESPONSIVE === */
@media (max-width: 768px) {
  #app {
    grid-template-areas: "header" "main";
    grid-template-columns: 1fr;
    grid-template-rows: var(--header-h) 1fr;
  }
  #sidebar {
    position: fixed;
    left: -240px;
    top: var(--header-h);
    height: calc(100vh - var(--header-h));
    z-index: 200;
    transition: left var(--transition);
    box-shadow: 4px 0 24px var(--shadow-lg);
  }
  #sidebar.mobile-open { left: 0; }
  #main { grid-column: 1; }
  .view { padding: 1rem; }
  .editor-layout { grid-template-columns: 1fr; }
  .header-center { display: none; }
  .lang-selector .lang-btn { padding: 4px 6px; }
  .hero { padding: 2rem 1rem; }
  .hero-title { font-size: 1.75rem; }
}

@media (max-width: 480px) {
  .theme-selector { display: none; }
  .home-stats { grid-template-columns: repeat(2, 1fr); }
}
