/* BenChemie4-1 — Main CSS: Dark/Light Theme, Layout, Typography */

/* ─── Dark theme (default) ─── */
:root {
  --bg-primary:   #0f1117;
  --bg-secondary: #1a1d2e;
  --bg-tertiary:  #252841;
  --bg-card:      #1e2135;
  --text-primary: #e8eaf6;
  --text-secondary: #9fa8da;
  --text-muted:   #6272a4;
  --border:       #2d3158;
  --border-light: #3d4370;

  --s-block:   #3d6fd4;
  --p-block:   #c8a800;
  --d-block:   #c0392b;
  --success:   #27ae60;
  --warning:   #e67e22;
  --error:     #e74c3c;
  --accent:    #7c83fd;

  --sidebar-width: 240px;
  --header-height: 56px;
  --progress-height: 3px;

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

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.5);

  --transition: 0.2s ease;
  --font-mono: 'JetBrains Mono', 'Fira Mono', Consolas, monospace;
}

/* ─── Light theme ─── */
[data-theme="light"] {
  --bg-primary:   #f5f6fa;
  --bg-secondary: #ffffff;
  --bg-tertiary:  #eef0f8;
  --bg-card:      #ffffff;
  --text-primary: #1a1d2e;
  --text-secondary: #3d4370;
  --text-muted:   #6272a4;
  --border:       #d8dce8;
  --border-light: #c2c8dc;

  --s-block:   #2558b8;
  --p-block:   #9a7800;
  --d-block:   #a93226;
  --success:   #1e8449;
  --warning:   #d35400;
  --error:     #c0392b;
  --accent:    #5058d4;

  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.12);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.16);
}

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

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

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: 'Fira Sans', system-ui, -apple-system, sans-serif;
  line-height: 1.65;
  min-height: 100vh;
}

/* ─── Progress Bar ─── */
#progress-bar-top {
  position: fixed;
  top: 0;
  left: 0;
  height: var(--progress-height);
  background: linear-gradient(90deg, var(--s-block), var(--accent), var(--success));
  z-index: 1000;
  width: 0%;
  transition: width 0.5s ease;
}

/* ─── Header ─── */
#site-header {
  position: fixed;
  top: var(--progress-height);
  left: 0;
  right: 0;
  height: var(--header-height);
  background: color-mix(in srgb, var(--bg-primary) 95%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  z-index: 900;
  gap: 16px;
}

#site-header .logo {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.02em;
}

#site-header .logo span {
  color: var(--accent);
}

#menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  font-size: 1.2rem;
}

.header-progress-text {
  margin-left: auto;
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* ─── Layout ─── */
#app-layout {
  display: flex;
  padding-top: calc(var(--header-height) + var(--progress-height));
  min-height: 100vh;
}

/* ─── Sidebar ─── */
#sidebar {
  width: var(--sidebar-width);
  position: fixed;
  top: calc(var(--header-height) + var(--progress-height));
  bottom: 0;
  left: 0;
  overflow-y: auto;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  z-index: 800;
  transition: transform var(--transition);
}

#sidebar::-webkit-scrollbar { width: 4px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 2px; }

.sidebar-label {
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 4px 20px 8px;
}

.sidebar-nav {
  list-style: none;
}

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 0.875rem;
  border-left: 3px solid transparent;
  transition: all var(--transition);
}

.sidebar-nav a:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.sidebar-nav a.active {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  border-left-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

.sidebar-nav .check-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1.5px solid var(--border-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.6rem;
  flex-shrink: 0;
  transition: all var(--transition);
}

.sidebar-nav li.completed .check-icon {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.sidebar-nav li.completed .check-icon::after {
  content: '✓';
}

/* ─── Main Content ─── */
#main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  min-width: 0;
}

/* ─── Sections ─── */
.content-section {
  max-width: 900px;
  margin: 0 auto;
  padding: 60px 40px 80px;
  border-bottom: 1px solid var(--border);
}

.section-header {
  margin-bottom: 40px;
}

.section-tag {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 3px 10px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
}

.tag-s { background: color-mix(in srgb, var(--s-block) 20%, transparent); color: var(--s-block); }
.tag-p { background: color-mix(in srgb, var(--p-block) 20%, transparent); color: var(--p-block); }
.tag-d { background: color-mix(in srgb, var(--d-block) 20%, transparent); color: var(--d-block); }
.tag-intro { background: color-mix(in srgb, var(--accent) 20%, transparent); color: var(--accent); }

.section-title {
  font-size: 2rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-primary);
  line-height: 1.2;
  margin-bottom: 8px;
}

.section-subtitle {
  font-size: 1rem;
  color: var(--text-muted);
}

/* ─── Typography ─── */
h3 { font-size: 1.4rem; font-weight: 700; margin: 32px 0 16px; color: var(--text-primary); }
h4 { font-size: 1.1rem; font-weight: 600; margin: 24px 0 12px; color: var(--text-secondary); }

p { margin-bottom: 1em; color: var(--text-primary); }
p:last-child { margin-bottom: 0; }

ul, ol { padding-left: 1.5em; margin-bottom: 1em; }
li { margin-bottom: 0.35em; }

strong { color: var(--text-primary); font-weight: 700; }
em { color: var(--text-secondary); }
code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  background: var(--bg-tertiary);
  padding: 2px 6px;
  border-radius: 4px;
  color: var(--accent);
}

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

/* ─── Canvas containers ─── */
.canvas-wrapper {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin: 20px 0;
  overflow: hidden;
}

canvas {
  display: block;
  max-width: 100%;
}

/* ─── Lernziele ─── */
.lernziele {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px 24px;
  margin-bottom: 32px;
}

.lernziele h3 {
  margin-top: 0;
  color: var(--accent);
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.lernziele ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.lernziele li {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.lernziele li::before {
  content: '→';
  color: var(--accent);
  flex-shrink: 0;
  margin-top: 1px;
}

/* ─── Section Complete Button ─── */
.section-footer {
  margin-top: 56px;
  padding-top: 32px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
}

.btn-complete {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--success);
  color: white;
  border: none;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--transition);
  font-family: inherit;
}

.btn-complete:hover {
  background: #2ecc71;
  transform: translateY(-1px);
  box-shadow: 0 4px 16px rgba(39, 174, 96, 0.4);
}

.btn-complete.completed {
  background: var(--bg-tertiary);
  color: var(--success);
  border: 1.5px solid var(--success);
}

/* ─── Images ─── */
.content-image {
  width: 100%;
  max-width: 600px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin: 16px auto;
  display: block;
  opacity: 0.9;
}

.image-caption {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* ─── Grid layouts ─── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  margin: 20px 0;
}

.three-col {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 20px 0;
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
  #menu-toggle { display: flex; }

  #sidebar {
    transform: translateX(-100%);
  }

  #sidebar.open {
    transform: translateX(0);
  }

  #main-content {
    margin-left: 0;
  }

  .content-section {
    padding: 40px 20px 60px;
  }

  .section-title {
    font-size: 1.5rem;
  }

  .two-col, .three-col {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 480px) {
  .content-section {
    padding: 32px 16px 48px;
  }
}

/* ─── Intro section ─── */
#intro {
  background: linear-gradient(160deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
}

.intro-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
  margin-top: 32px;
}

@media (max-width: 600px) {
  .intro-grid { grid-template-columns: 1fr; }
}

.intro-stat {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: center;
}

.intro-stat .number {
  font-size: 2.5rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1;
}

.intro-stat .label {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ─── Zusammenfassung checklist ─── */
.checklist {
  list-style: none;
  padding: 0;
}

.checklist li {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.checklist li:last-child { border-bottom: none; }

.checklist input[type="checkbox"] {
  width: 18px;
  height: 18px;
  margin-top: 2px;
  flex-shrink: 0;
  accent-color: var(--success);
  cursor: pointer;
}

.checklist label {
  cursor: pointer;
  color: var(--text-secondary);
  transition: color var(--transition);
}

.checklist input:checked + label {
  color: var(--success);
  text-decoration: line-through;
  text-decoration-color: rgba(39,174,96,0.5);
}

/* ─── Quiz ─── */
.quiz-question {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  margin-bottom: 16px;
}

.quiz-question p {
  font-weight: 600;
  margin-bottom: 12px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.quiz-option:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

.quiz-option.correct {
  border-color: var(--success);
  background: rgba(39,174,96,0.12);
  color: var(--success);
}

.quiz-option.wrong {
  border-color: var(--error);
  background: rgba(231,76,60,0.12);
  color: var(--error);
}

.quiz-result {
  text-align: center;
  padding: 24px;
  font-size: 1.2rem;
  font-weight: 700;
}

/* ─── Phet link ─── */
.phet-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  background: rgba(124,131,253,0.15);
  border: 1px solid rgba(124,131,253,0.4);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 0.875rem;
  font-weight: 600;
  transition: all var(--transition);
}

.phet-link:hover {
  background: rgba(124,131,253,0.25);
  text-decoration: none;
}

/* ─── Theme toggle button ─── */
#theme-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 1.5px solid var(--border-light);
  background: var(--bg-secondary);
  color: var(--text-primary);
  font-size: 1.25rem;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition);
}

#theme-toggle:hover {
  transform: scale(1.1);
  box-shadow: var(--shadow-lg);
}

/* Smooth theme transition — scoped to avoid performance hit on every element */
body,
#site-header, #sidebar, #main-content, #theme-toggle, #progress-bar-top,
.content-section, .concept-card, .formula-block, .merkbox, .lernziele,
.canvas-wrapper, .aufgabe-block, .aufgabe-content, .info-box,
.quiz-option, .tab-btn, .flame-box, .section-tag, code,
.sidebar-nav a, .check-icon, button, a, input, select {
  transition: background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease;
}

/* Skip link */
.skip-link {
  position: absolute;
  top: -100%;
  left: 8px;
  background: var(--accent);
  color: #fff;
  padding: 8px 16px;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  font-weight: 600;
  font-size: 0.875rem;
  z-index: 9999;
  text-decoration: none;
}
.skip-link:focus { top: 0; }

/* Screen-reader only */
.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;
}
