/*
 * training-compat.css
 * Maps the legacy SI-Copy CSS variable names → Rising Edge design tokens.
 * Loaded after shared/styles.css so the tokens are already defined.
 *
 * Legacy var           →  New token
 * --text-primary       →  --text-base
 * --text-secondary     →  --text-sub
 * --text-muted         →  --text-faint
 * --bg-secondary       →  --bg-muted
 * --bg-tertiary        →  --bg-alt
 * --cyan               →  #22d3ee  (--cyan-500 equivalent)
 * --cyan-dim           →  rgba(34,211,238,.12)
 * --success            →  #34d399
 * --warning            →  #fb923c
 * --error / --danger   →  #f87171
 * --badge-text         →  --text-base
 * --border-radius      →  8px
 */

:root {
  --text-primary: var(--text-base);
  --text-secondary: var(--text-sub);
  --bg-primary: var(--bg-page); /* used by SVG diagram container backgrounds */
  --bg-secondary: var(--bg-muted);
  --bg-tertiary: var(--bg-alt);
  --cyan: #22d3ee;
  --cyan-dim: rgba(34, 211, 238, 0.12);
  --success: #34d399;
  --warning: #fb923c;
  --error: #f87171;
  --danger: #f87171;
  --badge-text: var(--text-base);
  --border-radius: 8px;
  --text-muted-compat: var(--text-faint);
}

/* Light-mode overrides — improve contrast for SVG signal colours */
html.light {
  --text-primary: var(--text-base);
  --text-secondary: var(--text-sub);
  --bg-primary: var(--bg-page);
  --bg-secondary: var(--bg-muted);
  --bg-tertiary: var(--bg-alt);
  --cyan: #0891b2; /* darker cyan for light backgrounds */
  --cyan-dim: rgba(8, 145, 178, 0.1);
  --success: #059669; /* darker green */
  --warning: #d97706; /* darker amber */
  --error: #dc2626;
  --danger: #dc2626; /* darker red */
  --badge-text: var(--text-base);
  --text-muted-compat: var(--text-faint);
}

/* ── Widget container (legacy .widget-container) ── */
.widget-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow-card);
}

.widget-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 8px;
}

.widget-header h3 {
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-base);
  margin: 0;
}

/* ── Metrics / stat grid ── */
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.metric-card {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 14px 16px;
  text-align: center;
}

.metric-value {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--text-base);
  margin-bottom: 4px;
}

.metric-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── Badge (legacy .badge without modifier) ── */
.badge {
  display: inline-flex;
  align-items: center;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 3px 8px;
  border-radius: 20px;
  background: rgba(37, 99, 235, 0.15);
  color: var(--primary-400);
  white-space: nowrap;
}

/* ── Hero section within lesson ── */
.hero {
  background: var(--gradient-hero, linear-gradient(135deg, var(--bg-alt) 0%, var(--bg-card) 100%));
  border-bottom: 1px solid var(--border);
}

.hero-content {
  max-width: 900px;
}

.hero h1 {
  font-size: clamp(1.5rem, 3.5vw, 2.25rem);
  font-weight: 900;
  color: var(--text-base);
  margin: 8px 0;
}

.hero .subtitle {
  font-size: 0.9375rem;
  color: var(--text-sub);
  line-height: 1.75;
  margin-top: 8px;
}

/* ── Section ── */
.section {
  padding: 32px 0 60px;
}
.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ── Knowledge check / quiz widgets ── */
.quiz-slide {
  display: block;
}
.quiz-slide[style*='display: none'] {
  display: none !important;
}

.quiz-container,
.knowledge-check {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 24px;
  margin: 20px 0;
}

.question-card {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  margin-bottom: 12px;
}

.answer-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-alt);
  cursor: pointer;
  margin-bottom: 6px;
  font-size: 0.875rem;
  color: var(--text-sub);
  transition: all 0.15s;
}

.answer-option:hover {
  border-color: var(--primary-500);
  background: rgba(37, 99, 235, 0.06);
}

.answer-option.correct {
  border-color: #059669;
  background: rgba(5, 150, 105, 0.1);
  color: #34d399;
}
.answer-option.incorrect {
  border-color: #dc2626;
  background: rgba(220, 38, 38, 0.08);
  color: #f87171;
}

/* ── Canvas / simulation wrappers ── */
canvas {
  display: block;
  border-radius: var(--radius-lg);
  background: var(--bg-alt);
  max-width: 100%;
}

.sim-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin: 12px 0;
}

.sim-controls label {
  font-size: 0.8125rem;
  color: var(--text-sub);
}
.sim-controls input[type='range'] {
  accent-color: var(--primary-500);
}

/* ── Warning / info / tip callouts ── */
.callout,
.tip-box,
.warning-box,
.info-box {
  padding: 14px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.875rem;
  line-height: 1.65;
  margin: 16px 0;
}

.warning-box {
  background: rgba(251, 146, 60, 0.08);
  border: 1px solid rgba(251, 146, 60, 0.3);
  color: var(--text-sub);
}

.info-box {
  background: rgba(37, 99, 235, 0.06);
  border: 1px solid rgba(37, 99, 235, 0.25);
  color: var(--text-sub);
}

.tip-box {
  background: rgba(16, 185, 129, 0.07);
  border: 1px solid rgba(16, 185, 129, 0.25);
  color: var(--text-sub);
}

/* ── Tables ── */
.data-table th {
  white-space: nowrap;
}
.data-table td {
  vertical-align: top;
}

/* ── Calculator inputs ── */
.calc-wrap {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 20px;
  margin: 16px 0;
}

.calc-wrap input[type='number'],
.calc-wrap select {
  background: var(--bg-alt);
  border: 1px solid var(--border-med);
  color: var(--text-base);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  font-size: 0.875rem;
  width: 100%;
  max-width: 240px;
}

.calc-result {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--primary-400);
  margin: 12px 0 4px;
}

/* ── Responsive: narrow screens ── */
@media (max-width: 640px) {
  .widget-container {
    padding: 16px;
  }
  .metrics-grid {
    grid-template-columns: repeat(2, 1fr);
  }
  .hero h1 {
    font-size: 1.375rem;
  }
  .hero {
    padding: 28px 16px !important;
  }
  .section {
    padding: 20px 0 40px;
  }
  .container {
    padding: 0 14px;
  }
}

/* ── Quiz slide options (checkbox-style) ── */
.quiz-options {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.quiz-question {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-base);
  line-height: 1.6;
  margin-bottom: 1rem;
}

.quiz-option {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  border: 1.5px solid var(--border);
  background: var(--bg-alt);
  cursor: pointer;
  margin-bottom: 8px;
  font-size: 0.875rem;
  color: var(--text-sub);
  transition:
    border-color 0.15s,
    background 0.15s;
  list-style: none;
  user-select: none;
}

.quiz-option::before {
  content: '';
  display: block;
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1.5px solid var(--border);
  background: transparent;
  transition: all 0.15s;
  margin-top: 1px;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  color: #fff;
}

.quiz-option:not(.correct):not(.incorrect):hover {
  border-color: #3b82f6;
  background: rgba(37, 99, 235, 0.06);
}

.quiz-option:not(.correct):not(.incorrect):hover::before {
  border-color: #3b82f6;
}

.quiz-option.correct {
  border-color: var(--success) !important;
  background: rgba(52, 211, 153, 0.1) !important;
  color: var(--success);
  cursor: default;
}

.quiz-option.correct::before {
  content: '✓';
  background: var(--success);
  border-color: var(--success);
}

.quiz-option.incorrect {
  border-color: var(--danger) !important;
  background: rgba(248, 113, 113, 0.08) !important;
  cursor: default;
}

.quiz-option.incorrect::before {
  content: '✕';
  background: var(--danger);
  border-color: var(--danger);
}

.quiz-feedback {
  display: none;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 0.84rem;
  line-height: 1.6;
  margin-top: 8px;
}

.quiz-feedback.show {
  display: block;
}

.quiz-feedback.correct {
  background: rgba(52, 211, 153, 0.08);
  border: 1px solid var(--success);
  color: var(--success);
}

.quiz-feedback.incorrect {
  background: rgba(248, 113, 113, 0.08);
  border: 1px solid var(--danger);
  color: var(--text-sub);
}

/* ── Section collapsible accordion ── */
.section-collapsible {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  margin-bottom: 1rem;
  overflow: hidden;
}

.section-header-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 1rem 1.25rem;
  background: var(--bg-card);
  border: none;
  border-bottom: 1px solid var(--border);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.section-header-btn:hover {
  background: var(--bg-muted);
}

.section-header-btn h2 {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin: 0;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--text-base);
}

.section-header-btn .chevron {
  font-size: 0.7rem;
  color: var(--text-muted);
  transition: transform 0.25s;
  flex-shrink: 0;
}

.section-header-btn.collapsed .chevron {
  transform: rotate(-90deg);
}

.section-body {
  padding: 1.5rem 1.25rem;
  background: var(--bg-page);
}

.section-divider {
  height: 1px;
  background: var(--border);
  margin: 1.5rem 0;
}

/* ── Viewer rows (side-by-side canvas panels) ── */
.s-viewer-row,
.s1-viewer-row,
.s2-viewer-row,
.s3-viewer-row,
.s4-viewer-row,
.s5-viewer-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

/* ── Settings rows (side-by-side control panels) ── */
.s-settings-row,
.s1-settings-row,
.s2-settings-row,
.s3-settings-row,
.s4-settings-row,
.s5-settings-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

/* ── Plot area (canvas container) ── */
.plot-area {
  position: relative;
  width: 100%;
  min-height: 200px;
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.plot-area canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: var(--radius-lg);
}

/* ── Slider controls ── */
.slider-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
}

.slider-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.78rem;
  color: var(--text-sub);
  font-weight: 500;
}

.slider-value {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--cyan, #22d3ee);
  font-family: monospace;
}

.slider-group input[type='range'] {
  width: 100%;
  accent-color: var(--cyan, #22d3ee);
}

/* ── Hero grid ── */
.hero-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.5rem;
  align-items: center;
}

/* ── Progress / lesson progress ── */
.lesson-progress {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.75rem;
}

.module-progress-label {
  display: flex;
  justify-content: space-between;
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.progress-bar-wrapper,
.progress-bar {
  flex: 1;
  width: 100%;
  height: 6px;
  background: var(--bg-muted);
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--cyan, #22d3ee), #818cf8);
  border-radius: 3px;
  transition: width 0.4s ease;
}

/* ── Eye diagram metrics ── */
.eye-metric {
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  text-align: center;
}

.eye-metric-value {
  font-size: 1.1rem;
  font-weight: 800;
  color: var(--text-base);
  margin-bottom: 2px;
  font-family: monospace;
}

.eye-metric-label {
  font-size: 0.7rem;
  color: var(--text-muted);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── PCB diagram container ── */
.pcb-diagram {
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: #0d2818;
}

/* ── Iface spec table ── */
.iface-spec-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.iface-spec-table th,
.iface-spec-table td {
  padding: 6px 10px;
  border: 1px solid var(--border);
  color: var(--text-sub);
}

.iface-spec-table th {
  background: var(--bg-muted);
  font-weight: 700;
  color: var(--text-base);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ── Design task / matrix row ── */
.design-task {
  display: flex;
  gap: 1rem;
  padding: 12px 16px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  align-items: flex-start;
}

.task-num {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: var(--primary-500, #3b82f6);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.task-answer {
  font-size: 0.82rem;
  color: var(--text-sub);
  margin-top: 4px;
  padding: 6px 10px;
  background: var(--bg-alt);
  border-radius: var(--radius-sm);
  display: none;
}

.matrix-row {
  /* Used on <tr> elements — let the browser render as a normal table row */
  transition: background 0.15s;
}
.matrix-row:hover {
  background: var(--bg-muted);
}

/* ── Calc grid ── */
.calc-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.calc-inputs,
.calc-results {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.calc-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.calc-result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bg-muted);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.calc-result-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.calc-result-value {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--cyan, #22d3ee);
  font-family: monospace;
}

/* ── PDN block (power integrity) ── */
.s2-pdn-block {
  padding: 1rem;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
}

/* ── Tab system (impedance matching) ── */
.tab {
  padding: 6px 14px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  background: var(--bg-muted);
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-sub);
  font-family: inherit;
  transition: all 0.15s;
}

.tab.active,
.tab:hover {
  background: var(--primary-500, #3b82f6);
  color: #fff;
  border-color: var(--primary-500, #3b82f6);
}

.tab-content {
  display: none;
}

.tab-content.active {
  display: block;
}

/* ── Responsive: collapse 2-col grids on narrow screens ── */
@media (max-width: 700px) {
  .s-viewer-row,
  .s1-viewer-row,
  .s2-viewer-row,
  .s3-viewer-row,
  .s4-viewer-row,
  .s5-viewer-row {
    grid-template-columns: 1fr;
  }

  .s-settings-row,
  .s1-settings-row,
  .s2-settings-row,
  .s3-settings-row,
  .s4-settings-row,
  .s5-settings-row {
    grid-template-columns: 1fr;
  }

  .hero-grid,
  .calc-grid {
    grid-template-columns: 1fr;
  }
}
