/* ==========================================================================
   ZENTRALES STYLESHEET: MATHEMATIK FACHHOCHSCHULREIFE (KAI / KAF 25)
   Für Lernportal (index.html), Predia-Tafelbilder, Trainer & A4-Arbeitsblätter
   ========================================================================== */

:root {
  --bg-main: #f1f5f9;
  --bg-card: #ffffff;
  --bg-dark: #0f172a;
  --primary: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-border: #93c5fd;
  --secondary: #0f766e;
  --secondary-light: #f0fdfa;
  --secondary-border: #5eead4;
  --accent: #d97706;
  --accent-light: #fffbeb;
  --accent-border: #fcd34d;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --purple: #7c3aed;
  --purple-light: #f5f3ff;
  --success: #059669;
  --success-light: #ecfdf5;
  --text-main: #0f172a;
  --text-muted: #475569;
  --border: #cbd5e1;
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg-main);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ==========================================================================
   1. MATHEMATISCHE TYPOGRAFIE (FÜR ALLE MODULE)
   ========================================================================== */
.math {
  font-family: 'Cambria Math', 'Times New Roman', Georgia, serif;
  font-weight: 700;
  font-size: 1.12em;
  letter-spacing: 0.2px;
}

.frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  vertical-align: middle;
  margin: 0 4px;
  line-height: 1.15;
}

.frac .num {
  border-bottom: 2px solid currentColor;
  padding: 0 5px 2px 5px;
}

.frac .den {
  padding: 2px 5px 0 5px;
}

.cancel {
  position: relative;
  display: inline-block;
  color: var(--danger);
}

.cancel::after {
  content: "";
  position: absolute;
  left: -2px;
  right: -2px;
  top: 50%;
  border-top: 2.5px solid var(--danger);
  transform: rotate(-18deg);
}

.hl-exp { color: #dc2626; font-weight: 800; }
.hl-newexp { color: #2563eb; font-weight: 800; }
.hl-h { color: #d97706; font-weight: 800; }
.hl-x { color: #0f766e; font-weight: 800; }

/* ==========================================================================
   2. NAVIGATION & PORTAL-LAYOUT (index.html & Unterseiten)
   ========================================================================== */
header.portal-header {
  background: var(--bg-dark);
  color: #ffffff;
  padding: 14px 24px;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.25);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-inner {
  max-width: 1440px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
}

.brand-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-logo {
  width: 50px;
  height: 50px;
  border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #0f766e);
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: 'Cambria Math', Georgia, serif;
  font-size: 1.45rem;
  font-weight: 800;
  color: #fff;
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
  flex-shrink: 0;
  text-decoration: none;
}

.brand-titles h1 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: -0.3px;
}

.brand-subtitle {
  font-size: 0.88rem;
  color: #94a3b8;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 2px;
}

.course-badge {
  background: #1e293b;
  color: #38bdf8;
  border: 1px solid #0284c7;
  padding: 2px 8px;
  border-radius: 6px;
  font-weight: 700;
  font-size: 0.78rem;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.mode-switch {
  background: #1e293b;
  padding: 4px;
  border-radius: 10px;
  display: flex;
  gap: 4px;
  border: 1px solid #334155;
}

.mode-btn {
  background: transparent;
  color: #cbd5e1;
  border: none;
  padding: 8px 14px;
  border-radius: 7px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.mode-btn:hover { color: #fff; }
.mode-btn.active {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.util-btn {
  background: #1e293b;
  color: #fff;
  border: 1px solid #475569;
  padding: 9px 14px;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-decoration: none;
  transition: all 0.15s;
}

.util-btn:hover { background: #334155; }
.util-btn.cheatsheet-btn {
  background: var(--accent);
  border-color: #fbbf24;
  color: #fff;
}

.portal-main {
  max-width: 1400px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
  flex: 1;
}

/* TOP WELCOME & PROGRESS BANNER */
.top-banner {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 20px;
  margin-bottom: 24px;
}

@media (max-width: 960px) {
  .top-banner { grid-template-columns: 1fr; }
}

.welcome-card {
  background: linear-gradient(135deg, #1e3a8a 0%, #0f172a 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.welcome-card h2 {
  margin: 0 0 8px 0;
  font-size: 1.25rem;
}

.welcome-card p {
  margin: 0 0 14px 0;
  color: #dbeafe;
  font-size: 0.96rem;
}

.workflow-steps {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.wf-step {
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.2);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
}

.progress-card {
  background: var(--bg-card);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.progress-header h3 { margin: 0; font-size: 1.1rem; }
.progress-pct { font-size: 1.35rem; font-weight: 800; color: var(--success); }

.progress-bar-bg {
  width: 100%;
  height: 14px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 12px 0;
}

.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #2563eb, #059669);
  transition: width 0.3s ease;
}

.progress-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.reset-link {
  background: none;
  border: none;
  color: var(--danger);
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  font-size: 0.85rem;
  padding: 0;
}

/* CHEATSHEET DRAWER */
.cheatsheet-drawer {
  display: none;
  background: #ffffff;
  border: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 24px;
  box-shadow: 0 8px 24px rgba(217, 119, 6, 0.12);
}

.cheatsheet-drawer.open { display: block; }

.cs-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(290px, 1fr));
  gap: 16px;
  margin-top: 12px;
}

.cs-box {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-left: 5px solid var(--primary);
  border-radius: 10px;
  padding: 12px 16px;
}

.cs-box h4 { margin: 0 0 6px 0; color: var(--bg-dark); font-size: 1rem; }

/* MODULE CARDS */
.modules-list {
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.module-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 2px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.module-header {
  padding: 16px 24px;
  background: #f8fafc;
  border-bottom: 2px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}

.module-title-group {
  display: flex;
  align-items: center;
  gap: 14px;
}

.module-number {
  padding: 6px 14px;
  border-radius: 8px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  background: var(--primary);
  white-space: nowrap;
}

.module-title-group h2 { margin: 0; font-size: 1.25rem; }

.module-goals {
  padding: 14px 24px;
  background: #ffffff;
  border-bottom: 1px solid #e2e8f0;
  font-size: 0.95rem;
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
}

.goal-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: #f1f5f9;
  color: var(--text-main);
  padding: 4px 12px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
}

.resource-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  padding: 20px 24px;
}

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

.res-item {
  border: 2px solid #e2e8f0;
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: #ffffff;
  transition: all 0.2s;
}

.res-item:hover {
  border-color: #94a3b8;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.06);
}

.res-item.type-board { border-top: 5px solid var(--primary); }
.res-item.type-sheet { border-top: 5px solid var(--secondary); }
.res-item.type-trainer { border-top: 5px solid var(--accent); }
.res-item.completed { background: #f0fdf4; border-color: #86efac; }

.res-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}

.res-badge {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 3px 8px;
  border-radius: 6px;
}

.badge-board { background: var(--primary-light); color: var(--primary); }
.badge-sheet { background: var(--secondary-light); color: var(--secondary); }
.badge-trainer { background: var(--accent-light); color: #b45309; }

.check-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
}

.check-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--success);
  cursor: pointer;
}

.res-title { font-size: 1.08rem; font-weight: 700; margin: 0 0 6px 0; color: var(--bg-dark); }
.res-desc { font-size: 0.9rem; color: var(--text-muted); margin: 0 0 16px 0; }

.res-actions { display: flex; gap: 8px; align-items: center; margin-top: auto; }

.btn-launch {
  flex: 1;
  text-align: center;
  text-decoration: none;
  padding: 10px 14px;
  border-radius: 9px;
  font-weight: 700;
  font-size: 0.92rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-board { background: var(--primary); color: #fff; }
.btn-board:hover { background: #1e40af; }
.btn-sheet { background: var(--secondary); color: #fff; }
.btn-sheet:hover { background: #115e59; }
.btn-trainer { background: var(--accent); color: #fff; }
.btn-trainer:hover { background: #b45309; }

body.view-intern .intern-highlight { outline: 3px solid var(--accent); }

/* ==========================================================================
   3. PREDIA-TAFELBILD KOMPONENTEN (FÜR STUNDE 3, 4, ...)
   ========================================================================== */
.phase-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.phase-btn {
  background: #1e293b;
  color: #cbd5e1;
  border: 2px solid #334155;
  padding: 9px 15px;
  border-radius: 10px;
  font-size: 0.98rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}

.phase-btn:hover { background: #334155; color: #fff; }
.phase-btn.active {
  background: var(--primary);
  color: #fff;
  border-color: #60a5fa;
  box-shadow: 0 0 10px rgba(59, 130, 246, 0.4);
}

.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  padding: 16px 20px;
  margin-bottom: 16px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 2px solid #f1f5f9;
  flex-wrap: wrap;
  gap: 8px;
}

.card-title {
  font-size: 1.18rem;
  font-weight: 700;
  margin: 0;
  color: var(--bg-dark);
}

.grid-2 {
  display: grid;
  grid-template-columns: 1.15fr 1fr;
  gap: 18px;
  align-items: start;
}

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

.btn {
  background: #e2e8f0;
  color: var(--text-main);
  border: 2px solid #cbd5e1;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.btn:hover { background: #cbd5e1; }
.btn.active, .btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-secondary { background: var(--secondary); color: #fff; border-color: var(--secondary); }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-sm { padding: 6px 11px; font-size: 0.88rem; }

.reveal-box {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 110px;
  min-height: 42px;
  padding: 7px 14px;
  border-radius: 10px;
  background: #fef3c7;
  border: 2px dashed #d97706;
  color: #92400e;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  text-align: center;
}

.reveal-box.revealed {
  background: #ecfdf5;
  border: 2px solid #059669;
  color: #065f46;
}

.reveal-box .placeholder-text { display: inline; font-size: 0.92rem; }
.reveal-box .secret-content { display: none; font-size: 1.08rem; }
.reveal-box.revealed .placeholder-text { display: none; }
.reveal-box.revealed .secret-content { display: inline-block; }

.merksatz {
  background: linear-gradient(135deg, #eff6ff 0%, #dbeafe 100%);
  border-left: 6px solid var(--primary);
  padding: 14px 18px;
  border-radius: 10px;
  margin-top: 12px;
}

.aha-banner {
  background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
  border-left: 6px solid var(--accent);
  padding: 14px 18px;
  border-radius: 10px;
  margin-top: 12px;
}

.canvas-wrap {
  width: 100%;
  background: #ffffff;
  border: 2px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

canvas.graph-canvas {
  display: block;
  width: 100%;
  height: auto;
}

/* ==========================================================================
   4. SELBSTLERN-TRAINER KOMPONENTEN (trainer_stunde2 / trainer_stunde3)
   ========================================================================== */
.step-box {
  background: #f8fafc;
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  margin-bottom: 12px;
  transition: all 0.2s;
}

.step-box.locked {
  opacity: 0.5;
  pointer-events: none;
}

.step-box.active-step {
  border-color: var(--primary);
  background: #ffffff;
  box-shadow: 0 3px 10px rgba(29, 78, 216, 0.08);
}

.step-box.completed-step {
  border-color: var(--success);
  background: var(--success-light);
}

.trainer-input {
  width: 85px;
  height: 40px;
  font-size: 1.1rem;
  font-weight: 700;
  text-align: center;
  border: 2px solid #64748b;
  border-radius: 8px;
  padding: 4px 8px;
  font-family: 'Cambria Math', monospace;
}

.trainer-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.trainer-input.input-ok {
  border-color: var(--success);
  background: #d1fae5;
  color: #065f46;
}

.trainer-input.input-err {
  border-color: var(--danger);
  background: #fee2e2;
  color: #991b1b;
}

.feedback-msg {
  font-size: 0.92rem;
  font-weight: 600;
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 8px;
  display: none;
}

.feedback-msg.ok { display: block; background: #d1fae5; color: #065f46; }
.feedback-msg.err { display: block; background: #fee2e2; color: #991b1b; }

/* ==========================================================================
   5. DIN-A4 ARBEITSBLATT & DRUCK-STYLES (Für alle Arbeitsblätter)
   ========================================================================== */
body.worksheet-body {
  background: #cbd5e1;
  font-size: 10pt;
  line-height: 1.35;
}

.screen-toolbar {
  position: sticky;
  top: 0;
  z-index: 100;
  background: var(--bg-dark);
  color: #fff;
  padding: 10px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3);
}

.page {
  width: 210mm;
  min-height: 297mm;
  padding: 12mm 14mm;
  margin: 12px auto;
  background: #ffffff;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.18);
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.ws-header {
  border-bottom: 2.5px solid var(--primary);
  padding-bottom: 6px;
  margin-bottom: 10px;
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.ws-title-block h1 { margin: 0; font-size: 14pt; color: var(--primary); }
.ws-title-block .subtitle { font-size: 9.5pt; color: var(--text-muted); font-weight: 600; }

.section-title {
  background: #1e293b;
  color: #ffffff;
  padding: 4px 10px;
  border-radius: 5px;
  font-size: 10.5pt;
  font-weight: 700;
  margin: 8px 0 6px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

table.ws-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 9.5pt;
  margin: 4px 0;
}

table.ws-table th {
  background: #e2e8f0;
  color: var(--text-main);
  border: 1px solid #64748b;
  padding: 4px 6px;
  font-weight: 700;
  text-align: center;
}

table.ws-table td {
  border: 1px solid #64748b;
  padding: 5px 6px;
  text-align: center;
  vertical-align: middle;
}

.blank {
  display: inline-block;
  min-width: 24mm;
  border-bottom: 1.5px dotted #334155;
  height: 14pt;
  vertical-align: bottom;
  text-align: center;
  font-weight: 700;
  color: var(--success);
}

.blank-sm { min-width: 12mm; }
.blank-lg { min-width: 42mm; }

.sol-text { display: none; color: var(--success); font-weight: 700; }
body.show-solutions .sol-text { display: inline; }

@page {
  size: A4 portrait;
  margin: 0;
}

@media print {
  * {
    -webkit-print-color-adjust: exact !important;
    print-color-adjust: exact !important;
  }
  body.worksheet-body { background: #ffffff; }
  .screen-toolbar { display: none !important; }
  .page {
    margin: 0;
    box-shadow: none;
    width: 210mm;
    height: 297mm;
    page-break-after: always;
    break-after: page;
  }
  .page:last-child {
    page-break-after: auto;
    break-after: auto;
  }
}

footer.portal-footer {
  text-align: center;
  padding: 18px;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  background: #fff;
  margin-top: 30px;
}