/* ============================================================
   Machine Learning - Mission 01
   Self-contained module stylesheet.
   Inherits root tokens + topbar from ../styles.css only.
   Accent identity: muted amber (#9a6d2e / #7d5722) "Data Workshop".
   ============================================================ */
@import url("../styles.css");

:root {
  --ml-orange: #9a6d2e;
  --ml-orange-2: #7d5722;
  --ml-soft: #f1ead7;
  --ml-line: #f3cba6;
  --ml-deep: #6e4e1c;
  --ml-blue: #466f96;
  --ml-green: #2f7d5b;
  --ml-rose: #b0533f;
  --ml-grey: #8a978c;
}

/* tint the brand square orange for this module */
.mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 7px;
  color: #fff;
  background: linear-gradient(150deg, var(--ml-orange), var(--ml-orange-2));
}

nav a:hover { color: var(--ml-orange); }
footer a { color: var(--ml-orange); }

main { overflow: hidden; }

/* ---------- shared section rhythm ---------- */
.hero,
.level { padding: clamp(40px, 6vw, 84px) clamp(18px, 4vw, 56px); }
.level { border-top: 1px solid var(--line); }
.level[data-level="2"] { background: #f4f0e2; }
.level[data-level="3"] { background: var(--paper); }
.level[data-level="4"] { background: #f4f0e2; }

/* ===================== HERO ===================== */
.hero {
  display: grid;
  grid-template-columns: minmax(0, 0.95fr) minmax(320px, 1.05fr);
  gap: clamp(28px, 5vw, 70px);
  align-items: center;
  min-height: 560px;
  background:
    radial-gradient(1100px 500px at 88% -10%, var(--ml-soft), transparent 60%),
    var(--paper);
}
.hero h1 {
  margin: 0 0 6px;
  max-width: 820px;
  line-height: 1.03;
  font-size: clamp(2.2rem, 5.4vw, 4.6rem);
  font-weight: 900;
  letter-spacing: -0.01em;
}
.lead {
  max-width: 740px;
  color: var(--muted);
  font-size: clamp(1rem, 1.7vw, 1.18rem);
  line-height: 1.7;
}
.eyebrow {
  margin: 0 0 12px;
  color: var(--ml-orange);
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 0.78rem;
}
.actions { display: flex; flex-wrap: wrap; gap: 12px; margin: 26px 0 22px; }

.outcomes { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 8px; }
.outcomes strong { width: 100%; margin-bottom: 4px; font-size: .95rem; }
.outcomes span {
  border: 1px solid var(--ml-line);
  border-radius: 999px;
  padding: 6px 12px;
  background: #fff;
  color: var(--ml-deep);
  font-size: .82rem;
  font-weight: 800;
}

.stage {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: 12px;
}

/* ===================== BUTTONS ===================== */
.button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 16px;
  color: var(--ink);
  background: #fff;
  font-weight: 850;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.button:hover { transform: translateY(-1px); box-shadow: 0 8px 20px rgba(154,109,46,.18); border-color: var(--ml-line); }
.button:active { transform: translateY(0); }
.button.primary {
  border-color: var(--ml-orange);
  color: #fff;
  background: linear-gradient(180deg, #b9923f, var(--ml-orange));
}
.button.primary:hover { box-shadow: 0 10px 26px rgba(154,109,46,.34); }
.button.small { min-height: 36px; padding-inline: 12px; }
.button:disabled { opacity: .5; cursor: default; transform: none; box-shadow: none; }
.button.selected { border-color: var(--ml-orange); background: var(--ml-soft); color: var(--ml-deep); }

/* ===================== PANELS ===================== */
.panel {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 28px);
}
.panel.wide { width: min(100%, 1120px); margin-inline: auto; }
.panel + .panel,
.grid-section + .panel,
.math-card + .panel,
.panel + .math-card,
.panel + .grid-section,
.math-card + .math-card { margin-top: 22px; }
.grid-section + .grid-section { margin-top: 22px; }
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.panel h3 { margin: 0; font-size: 1.25rem; }
.panel.lab { margin-top: 24px; }

.metric {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  border-radius: 999px;
  padding: 4px 14px;
  color: var(--ml-deep);
  background: var(--ml-soft);
  border: 1px solid var(--ml-line);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.note { margin-top: 14px; color: var(--muted); line-height: 1.6; font-size: .95rem; }
.note code, .worked code { background: #eef1e7; border-radius: 5px; padding: 1px 6px; font-size: .9em; }
.narration { margin: 0 0 16px; color: var(--muted); line-height: 1.66; max-width: 880px; }
.hint { color: var(--muted); font-size: .9rem; font-style: italic; }

/* ===================== LEVEL HEADS + BADGES ===================== */
.level-head { margin: 0 auto 26px; max-width: 1120px; }
.level-head h2 {
  margin: 10px 0 6px;
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  font-weight: 900;
  letter-spacing: -0.01em;
}
.level-badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 14px;
  background: linear-gradient(150deg, var(--ml-orange), var(--ml-orange-2));
  color: #fff;
  font-weight: 900;
  font-size: .78rem;
  letter-spacing: .06em;
  text-transform: uppercase;
}

/* ===================== STICKY LEVEL RAIL ===================== */
.level-rail {
  position: fixed;
  top: 50%;
  right: max(10px, 2vw);
  transform: translateY(-50%);
  z-index: 9;
  display: grid;
  gap: 8px;
}
.level-rail a {
  display: block;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 14px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(8px);
  color: var(--muted);
  font-weight: 800;
  font-size: .82rem;
  box-shadow: 0 6px 16px rgba(23,32,43,.08);
  transition: all .18s ease;
}
.level-rail a:hover { border-color: var(--ml-line); color: var(--ml-deep); }
.level-rail a.active {
  border-color: var(--ml-orange);
  background: linear-gradient(150deg, var(--ml-orange), var(--ml-orange-2));
  color: #fff;
  transform: scale(1.04);
  box-shadow: 0 8px 22px rgba(154,109,46,.32);
}

/* ===================== GRID / COPY ===================== */
.grid-section {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(300px, 1fr);
  gap: clamp(24px, 4vw, 56px);
  align-items: start;
  max-width: 1120px;
  margin-inline: auto;
}
.copy h3 { margin: 0 0 10px; font-size: clamp(1.4rem, 3vw, 2.1rem); font-weight: 850; line-height: 1.12; }
.copy p { color: var(--muted); line-height: 1.7; font-size: 1.02rem; }
.copy b, .copy strong { color: var(--ink); }

/* ===================== CANVAS ===================== */
canvas {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.7);
}
.stage canvas { border: none; box-shadow: none; }

.control-row { display: flex; flex-wrap: wrap; align-items: center; gap: 14px; margin-top: 16px; }
.lab-twin { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ===================== SLIDERS / INPUTS ===================== */
.slider { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-weight: 800; font-size: .92rem; }
.slider input[type="range"] { width: clamp(120px, 22vw, 220px); accent-color: var(--ml-orange); }
.slider output {
  min-width: 44px;
  text-align: center;
  border-radius: 6px;
  padding: 2px 6px;
  background: var(--ml-soft);
  color: var(--ml-deep);
  font-variant-numeric: tabular-nums;
}
.toggle { display: inline-flex; align-items: center; gap: 10px; font-weight: 800; color: var(--ink); cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--ml-orange); cursor: pointer; }

/* ===================== ANALOGY / EXAMPLE CARDS ===================== */
.analogy-card {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  margin-top: 18px;
  border: 1px solid var(--ml-line);
  border-radius: 12px;
  padding: 16px;
  background: var(--ml-soft);
}
.analogy-card strong { color: var(--ml-deep); }
.analogy-card p { margin: 6px 0 0; color: #7a5638; line-height: 1.6; }
.analogy-icon { flex: 0 0 auto; border-radius: 10px; overflow: hidden; border: 1px solid var(--ml-line); background: #fff; }

.example-list { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 10px; }
.example-list li {
  border: 1px solid var(--line);
  border-left: 4px solid var(--ml-orange);
  border-radius: 8px;
  padding: 10px 14px;
  background: #fff;
  color: var(--muted);
  line-height: 1.55;
}
.example-list.tight li { padding: 8px 12px; }
.example-list strong { color: var(--ink); }

.svg-figure { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: #fff; margin-top: 6px; }

/* ===================== DATA TABLE ===================== */
.data-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.data-table th, .data-table td {
  border: 1px solid var(--line);
  padding: 8px 10px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.data-table th { background: #f1f4ea; color: var(--ink); font-weight: 800; }
.data-table .label-col { background: var(--ml-soft); color: var(--ml-deep); font-weight: 800; }

/* ===================== FEATURE GRID (build dataset game) ===================== */
.feature-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 200px), 1fr)); gap: 12px; }
.feature-chip {
  display: flex;
  flex-direction: column;
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px 14px;
  background: #fff;
  cursor: pointer;
  text-align: left;
  font: inherit;
  transition: all .14s ease;
}
.feature-chip:hover { border-color: var(--ml-line); transform: translateY(-1px); }
.feature-chip.on { border-color: var(--ml-orange); background: var(--ml-soft); }
.feature-chip strong { color: var(--ink); }
.feature-chip span { color: var(--muted); font-size: .85rem; font-weight: 600; }
.feature-chip .badge { align-self: flex-start; font-size: .72rem; font-weight: 800; padding: 2px 8px; border-radius: 999px; }
.feature-chip.on.good .badge { background: #e3f4ef; color: var(--ml-green); }
.feature-chip.on.bad .badge { background: #fdeaf1; color: var(--ml-rose); }
.feature-chip .badge.hidden { visibility: hidden; }

/* ===================== WORKED EXAMPLES ===================== */
.worked { background: linear-gradient(180deg, #fff, #f4f0e2); }
.worked p { color: var(--muted); line-height: 1.7; }
.step-track { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin: 16px 0; }
.step-track span {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  background: #fff;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.step-track .arrow { border: none; background: none; color: var(--ml-orange); font-size: 1.1rem; padding: 0; }
.step-track .goal { border-color: var(--ml-green); background: #e7f5f1; color: var(--ml-green); }

/* ===================== MATH CARDS (KaTeX) ===================== */
.formulas-intro { max-width: 1120px; margin: 0 auto 8px; }
.formulas-intro p { color: var(--muted); line-height: 1.7; }
.math-card {
  max-width: 1120px;
  margin: 22px auto 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.math-render {
  padding: 22px 18px;
  background: linear-gradient(180deg, var(--ml-soft), #fff);
  border-bottom: 1px solid var(--line);
  font-size: 1.18rem;
  overflow-x: auto;
}
.math-card figcaption { padding: 16px 18px 18px; }
.math-card figcaption p { margin: 0 0 12px; color: var(--ink); line-height: 1.6; }
.math-card figcaption strong { color: var(--ml-deep); }
.legend { margin: 0; padding-left: 0; list-style: none; display: grid; gap: 6px; }
.legend li { color: var(--muted); line-height: 1.5; padding-left: 14px; border-left: 3px solid var(--ml-line); }
.legend strong { color: var(--ink); }

/* ===================== METRICS / CONFUSION MATRIX ===================== */
.metric-layout { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(220px, 1fr); gap: 16px; align-items: start; }
.confusion { display: grid; gap: 14px; }
.cm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cm-cell {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  text-align: center;
  display: grid;
  gap: 4px;
}
.cm-cell .cm-label { font-size: .72rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.cm-cell strong { font-size: 1.5rem; font-variant-numeric: tabular-nums; }
.cm-cell.tp { background: #e7f5f1; border-color: #b7e3d7; color: var(--ml-green); }
.cm-cell.tn { background: #e7eddc; border-color: #b9cbda; color: var(--ml-blue); }
.cm-cell.fp { background: #f1ead7; border-color: var(--ml-line); color: var(--ml-deep); }
.cm-cell.fn { background: #f6e3dc; border-color: #e0b5a8; color: var(--ml-rose); }
.metric-list { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.metric-list li {
  display: flex;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 12px;
  background: #fff;
  font-weight: 700;
  color: var(--muted);
}
.metric-list strong { color: var(--ink); font-variant-numeric: tabular-nums; }

/* ===================== MINI CONCEPT GRID ===================== */
.mini-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 300px), 1fr)); gap: 16px; max-width: 1120px; margin: 22px auto 0; }
.panel.mini { margin: 0; }
.panel.mini h3 { font-size: 1.08rem; }

/* ===================== CODE PANEL ===================== */
.code-panel { max-width: 1120px; margin: 22px auto 0; }
.code-tabs { display: flex; gap: 8px; }
.code-tabs .button.active { border-color: var(--ml-orange); background: var(--ml-soft); color: var(--ml-deep); }
.code-block {
  margin-top: 8px;
  border-radius: 10px;
  padding: 16px;
  background: #1f2a22;
  color: #eef4ec;
  overflow-x: auto;
  line-height: 1.55;
  font-size: .9rem;
}
.code-explanation { display: grid; gap: 10px; margin-top: 14px; }
.code-explanation p { margin: 0; color: var(--muted); line-height: 1.6; }
.code-explanation code { background: #eef1e7; border-radius: 5px; padding: 1px 6px; }

/* ===================== QUIZ ===================== */
.quiz-panel { max-width: 1120px; margin: 22px auto 0; }
.quiz-list { display: grid; gap: 16px; }
.quiz-q { border: 1px solid var(--line); border-radius: 10px; padding: 16px; background: #fff; }
.quiz-q .q-text { margin: 0 0 12px; font-weight: 800; line-height: 1.5; }
.quiz-options { display: flex; flex-wrap: wrap; gap: 8px; }
.quiz-options button {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 14px;
  background: #fff;
  color: var(--ink);
  font-weight: 750;
  cursor: pointer;
  transition: all .14s ease;
}
.quiz-options button:hover:not(:disabled) { border-color: var(--ml-line); }
.quiz-options button.correct { border-color: var(--ml-green); background: #e7f5f1; color: var(--ml-green); }
.quiz-options button.wrong { border-color: var(--ml-rose); background: #fdeaf1; color: var(--ml-deep); }
.quiz-options button:disabled { cursor: default; }
.quiz-fb { margin: 12px 0 0; font-weight: 700; line-height: 1.5; min-height: 1.2em; }
.quiz-fb.ok { color: var(--ml-green); }
.quiz-fb.no { color: var(--ml-deep); }

/* ===================== ANIMATIONS ===================== */
@keyframes ml-rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}
.level-head, .grid-section, .math-card, .panel.lab, .worked, .code-panel, .quiz-panel, .mini-grid, .formulas-intro {
  animation: ml-rise .6s ease both;
}

/* Animated hero glow: a slow drifting warm light behind the stage.
   Purely decorative; collapses under prefers-reduced-motion below. */
@keyframes ml-hero-drift {
  0%   { background-position: 88% -10%, 0 0; }
  50%  { background-position: 70% 4%, 0 0; }
  100% { background-position: 88% -10%, 0 0; }
}
.hero {
  background-size: 1100px 500px, auto;
  animation: ml-hero-drift 14s ease-in-out infinite;
}

/* Gentle pulse on the active rail step so the current level feels alive */
@keyframes ml-rail-pulse {
  0%, 100% { box-shadow: 0 8px 22px rgba(154,109,46,.32); }
  50%      { box-shadow: 0 8px 30px rgba(154,109,46,.55); }
}
.level-rail a.active { animation: ml-rail-pulse 2.4s ease-in-out infinite; }

/* Soft hover lift on lab canvases for a more tactile feel */
.lab canvas { transition: box-shadow .2s ease, transform .2s ease; }
.lab canvas:hover { box-shadow: 0 12px 30px rgba(154,109,46,.14); }

/* ===================== FOOTER ===================== */
footer {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 16px;
  padding: 28px clamp(18px, 4vw, 56px);
  border-top: 1px solid var(--line);
  color: var(--muted);
}
footer a { color: var(--ml-orange); font-weight: 800; }

/* ===================== RESPONSIVE ===================== */
canvas { width: 100%; max-width: 100%; height: auto; }

@media (max-width: 980px) {
  /* vertical rail -> horizontal sticky strip under the topbar */
  .level-rail {
    position: sticky;
    top: 0;
    right: auto;
    transform: none;
    display: flex;
    flex-wrap: nowrap;
    gap: 6px;
    justify-content: center;
    padding: 8px clamp(12px, 3vw, 24px);
    background: rgba(255,255,255,.92);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .level-rail::-webkit-scrollbar { display: none; }
  .level-rail a { flex: 0 0 auto; padding: 6px 12px; font-size: .8rem; box-shadow: none; white-space: nowrap; }
  .level-rail a.active { transform: none; }
}

@media (max-width: 860px) {
  .topbar { flex-direction: column; align-items: flex-start; }
  .hero { grid-template-columns: 1fr; min-height: auto; }
  .grid-section { grid-template-columns: 1fr; }
  .lab-twin { grid-template-columns: 1fr; }
  .metric-layout { grid-template-columns: 1fr; }
  .analogy-card { flex-wrap: wrap; }
}

/* ---- Phones: single column everywhere, tighter rhythm ---- */
@media (max-width: 600px) {
  .hero, .level { padding: clamp(32px, 7vw, 48px) clamp(14px, 4vw, 22px); }
  .panel { padding: clamp(14px, 4vw, 20px); }
  .panel-head { align-items: flex-start; }
  .panel h3 { font-size: 1.12rem; }
  .level-rail a { overflow: hidden; text-overflow: ellipsis; max-width: 22vw; }
  .slider { width: 100%; flex-wrap: wrap; }
  .slider input[type="range"] { flex: 1 1 140px; width: auto; }
  .control-row { gap: 10px; }
  .hint { width: 100%; }
  .feature-grid { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
  .hero h1 { font-size: clamp(1.9rem, 8.5vw, 2.4rem); }
  .level-head h2 { font-size: clamp(1.5rem, 7vw, 2rem); }
  .copy h3 { font-size: clamp(1.25rem, 6vw, 1.6rem); }
  .lead { font-size: 1rem; }
  .outcomes span { font-size: .78rem; padding: 5px 10px; }
  .math-render { font-size: 1.02rem; padding: 18px 14px; }
  .control-row .button { flex: 1 1 auto; }
  .lab .control-row .button { flex: 1 1 140px; }
  .level-rail { gap: 4px; padding: 7px 10px; }
  .level-rail a { padding: 5px 9px; font-size: .74rem; max-width: 26vw; }
  .data-table { font-size: .82rem; }
  .data-table th, .data-table td { padding: 6px 6px; }
  .quiz-options button { flex: 1 1 auto; }
}

@media (max-width: 360px) {
  .hero, .level { padding-inline: 12px; }
  .panel { padding: 13px; }
  .panel h3 { font-size: 1.04rem; }
  .step-track { gap: 7px; }
  .step-track span { padding: 6px 10px; font-size: .9rem; }
  .metric { font-size: .82rem; padding: 4px 10px; }
  .slider { font-size: .86rem; }
  .cm-cell strong { font-size: 1.2rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
    scroll-behavior: auto !important;
  }
}

/* ============================================================
   Beautiful-math callouts, the "✦ Beautiful math" highlight asides.
   Sage Biophilic: soft panel fill, accent left border, calm.
   ============================================================ */
.beauty-note {
  margin: 26px 0;
  padding: 18px clamp(16px, 3vw, 26px) 20px;
  background: linear-gradient(180deg, var(--ml-soft, #f1ead7), var(--panel, #fbfcf5));
  border: 1px solid var(--ml-line, #f3cba6);
  border-left: 4px solid var(--ml-orange, #9a6d2e);
  border-radius: 14px;
}
.beauty-note .beauty-label {
  display: inline-block;
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ml-deep, #6e4e1c);
  background: rgba(154, 109, 46, .12);
  padding: 3px 10px;
  border-radius: 999px;
  margin-bottom: 8px;
}
.beauty-note h4 {
  margin: 4px 0 10px;
  font-size: 1.12rem;
  color: var(--ink, #1f2a22);
}
.beauty-note .math-render {
  background: rgba(251, 252, 245, .7);
  border: 1px solid var(--ml-line, #f3cba6);
  border-radius: 10px;
  padding: 14px 12px;
  margin: 0 0 12px;
  overflow-x: auto;
  text-align: center;
}
.beauty-note p {
  margin: 0;
  color: var(--muted, #54655a);
  line-height: 1.62;
}
@media (max-width: 480px) {
  .beauty-note { padding: 14px 14px 16px; }
  .beauty-note .math-render { font-size: .98rem; padding: 12px 8px; }
}

/* PCA scree companion canvas: second bar chart sits in the existing .lab-twin grid */
#pcaScreeCanvas {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--ml-line, var(--line));
  border-radius: 14px;
}

/* ===================== POLISH: ACCESSIBLE FOCUS ===================== */
/* Keyboard-only focus rings in the room's amber; mouse interaction stays
   ring-free. Outline (not box-shadow on layout) so nothing reflows. */
.button:focus-visible,
.feature-chip:focus-visible,
.toggle input:focus-visible,
.quiz-options button:focus-visible,
.code-tabs .button:focus-visible,
.level-rail a:focus-visible,
nav a:focus-visible,
footer a:focus-visible {
  outline: 2.5px solid var(--ml-orange);
  outline-offset: 2px;
  border-radius: 8px;
}
.slider input[type="range"]:focus-visible {
  outline: 2.5px solid var(--ml-orange);
  outline-offset: 3px;
}

/* ===================== POLISH: STATIC-CARD HOVER ===================== */
/* Subtle tactile feedback on read-heavy cards. Each shift is <=2px and
   reversible; collapses under the existing reduced-motion guard. */
.example-list li { transition: border-color .16s ease, transform .16s ease, box-shadow .16s ease; }
.example-list li:hover {
  transform: translateX(2px);
  border-left-color: var(--ml-deep);
  box-shadow: 0 6px 16px rgba(154,109,46,.10);
}
.legend li { transition: border-color .16s ease, color .16s ease; }
.legend li:hover { border-left-color: var(--ml-orange); color: var(--ink); }
.metric { transition: background .18s ease, border-color .18s ease; }
.cm-cell { transition: transform .16s ease, box-shadow .16s ease; }
.cm-cell:hover { transform: translateY(-2px); box-shadow: 0 8px 18px rgba(31,42,34,.10); }
.step-track span { transition: transform .14s ease; }
.step-track span:hover { transform: translateY(-1px); }
.data-table tbody tr { transition: background .14s ease; }
.data-table tbody tr:hover td:not(.label-col) { background: #faf6ea; }

/* ===================== POLISH: TYPE & MATH-CARD ===================== */
.math-card { transition: box-shadow .2s ease, transform .2s ease; }
.math-card:hover { box-shadow: 0 14px 34px rgba(154,109,46,.12); transform: translateY(-1px); }
.math-render { scrollbar-width: thin; }
.code-block { scrollbar-width: thin; }
.legend li, .metric-list li, .quiz-fb { text-wrap: pretty; }
.metric-list li, .metric-list strong { font-variant-numeric: tabular-nums; }
/* tighten optical rhythm between a math-card and the prose that follows it */
.math-card + .formulas-intro { margin-top: 26px; }

/* ===================== POLISH: WIDE-MEDIA HARDENING ===================== */
/* Stop horizontally-scrollable blocks from forcing the whole page wide on
   narrow screens. They keep their own internal scroll; the page stays put. */
.math-render, .code-block, .data-table { max-width: 100%; }
.math-card, .code-panel, .quiz-panel { min-width: 0; }
.metric-layout > * { min-width: 0; }
.grid-section > .copy, .grid-section > .panel { min-width: 0; }
@media (max-width: 600px) {
  .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .code-block { font-size: .82rem; }
  .step-track { row-gap: 8px; }
}

/* ===================== POLISH: MINI-GRID STAGGER ===================== */
/* Reuses the existing @keyframes ml-rise. The prefers-reduced-motion guard
   already in this file zeroes the duration, so this is motion-safe. */
.mini-grid .panel.mini { animation: ml-rise .55s ease both; }
.mini-grid .panel.mini:nth-child(2) { animation-delay: .07s; }
.mini-grid .panel.mini:nth-child(3) { animation-delay: .14s; }
.mini-grid .panel.mini:nth-child(n+4) { animation-delay: .2s; }
