/* TPU evolution timeline — chip stepper + Bottleneck/Fix panels + perf chart.
 * On LMS design tokens, theme-aware, no CDNs. */
:root {
  --bg: #ffffff; --fg: #0f172a; --muted: #475569; --surface: #f1f5f9;
  --border: #e2e8f0; --primary: #2563eb; --primary-contrast: #ffffff;
  --accent: #0f766e; --danger: #b91c1c; --warning: #b45309;
  --train: #7c3aed; --infer: #0369a1;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f172a; --fg: #f8fafc; --muted: #a5b1c2; --surface: #1e293b;
    --border: #334155; --primary: #60a5fa; --primary-contrast: #0b1220;
    --accent: #2dd4bf; --danger: #f87171; --warning: #fbbf24;
    --train: #a78bfa; --infer: #38bdf8;
  }
}
[data-theme="light"] { --bg:#fff; --fg:#0f172a; --muted:#475569; --surface:#f1f5f9; --border:#e2e8f0; --primary:#2563eb; --primary-contrast:#fff; --accent:#0f766e; --danger:#b91c1c; --warning:#b45309; --train:#7c3aed; --infer:#0369a1; }
[data-theme="dark"] { --bg:#0f172a; --fg:#f8fafc; --muted:#a5b1c2; --surface:#1e293b; --border:#334155; --primary:#60a5fa; --primary-contrast:#0b1220; --accent:#2dd4bf; --danger:#f87171; --warning:#fbbf24; --train:#a78bfa; --infer:#38bdf8; }

* { box-sizing: border-box; }
body { background: var(--bg); color: var(--fg); font-family: ui-sans-serif, system-ui, sans-serif; margin: 0; }
#app { padding: 16px; display: flex; flex-direction: column; gap: 22px; max-width: 900px; margin: 0 auto; }

/* --- Timeline Stepper (Chip Design) --- */
.timeline-track { display: flex; align-items: center; justify-content: space-between; position: relative; margin-bottom: 10px; padding: 0 10px; }
.timeline-line { position: absolute; top: 13px; left: 17px; right: 17px; height: 3px; background: var(--border); z-index: 0; border-radius: 2px; }
.timeline-progress { position: absolute; top: 13px; left: 17px; height: 3px; background: var(--primary); z-index: 1; border-radius: 2px; transition: width 0.4s cubic-bezier(0.4, 0, 0.2, 1); }
.node { position: relative; z-index: 2; display: flex; flex-direction: column; align-items: center; gap: 12px; cursor: pointer; border: none; background: transparent; padding: 0; outline: none; }
.node-chip { width: 26px; height: 26px; border-radius: 4px; background: var(--surface); border: 2px solid var(--border); transition: all 0.3s ease; display: grid; place-items: center; position: relative; }
.node-chip::before { content: ''; position: absolute; top: -5px; left: -5px; right: -5px; bottom: -5px; border: 2px dashed var(--border); border-radius: 6px; z-index: -1; transition: all 0.3s ease; }
.node-chip::after { content: ''; width: 10px; height: 10px; background: var(--border); border-radius: 2px; transition: all 0.3s ease; }
.node.active .node-chip { border-color: var(--primary); background: var(--bg); box-shadow: inset 0 0 0 2px color-mix(in srgb, var(--primary) 15%, transparent), 0 0 14px color-mix(in srgb, var(--primary) 40%, transparent); }
.node.active .node-chip::before { border-color: var(--primary); opacity: 0.6; }
.node.active .node-chip::after { background: var(--primary); box-shadow: 0 0 6px var(--primary); }
.node.past .node-chip { border-color: var(--primary); background: var(--surface); }
.node.past .node-chip::before { border-color: color-mix(in srgb, var(--primary) 40%, transparent); }
.node.past .node-chip::after { background: var(--primary); }
.node:focus-visible .node-chip { outline: 2px solid var(--primary); outline-offset: 6px; }
.node-label { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; transition: color 0.3s ease; }
.node.active .node-label { color: var(--fg); }
/* Eight generations don't fit one row in a 286 px lesson frame: the nodes pushed past it and each chip overlapped its
   neighbour's focus ring. On a narrow screen they're two rows of four, without the connecting line (LMS-content#130). */
@media (max-width: 480px) {
  .timeline-track { display: grid; grid-template-columns: repeat(4, 1fr); row-gap: 16px; padding: 0; }
  .timeline-line, .timeline-progress { display: none; }
  .node { gap: 10px; }
  .node-label { text-transform: none; letter-spacing: 0; }
}

/* --- The Wall vs The Fix Panels --- */
.story-container { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 600px) { .story-container { grid-template-columns: 1fr; } }
.panel { padding: 22px; border-radius: 16px; border: 1px solid var(--border); background: var(--surface); position: relative; overflow: hidden; display: flex; flex-direction: column; gap: 12px; }
.panel.wall { border-top: 4px solid var(--danger); background: linear-gradient(to bottom, color-mix(in srgb, var(--danger) 5%, transparent), transparent 40%), var(--surface); }
.panel.fix { border-top: 4px solid var(--accent); background: linear-gradient(to bottom, color-mix(in srgb, var(--accent) 5%, transparent), transparent 40%), var(--surface); }
.panel-header { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 800; text-transform: uppercase; letter-spacing: 0.05em; }
.wall .panel-header { color: var(--danger); }
.fix .panel-header { color: var(--accent); }
.panel-icon { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; }
.wall .panel-icon { background: color-mix(in srgb, var(--danger) 15%, transparent); }
.fix .panel-icon { background: color-mix(in srgb, var(--accent) 15%, transparent); }
.panel-text { font-size: 15px; line-height: 1.6; color: var(--fg); font-weight: 500; }
.panel-sub { margin-top: auto; font-size: 12px; color: var(--muted); font-family: ui-monospace, SFMono-Regular, Menlo, monospace; padding-top: 12px; border-top: 1px dashed var(--border); }

/* --- Performance Chart --- */
.chart-section { background: var(--bg); border: 1px solid var(--border); border-radius: 16px; padding: 22px; display: flex; flex-direction: column; gap: 16px; }
.chart-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; }
.chart-title { font-size: 14px; font-weight: 700; color: var(--fg); }
.chart-axis { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.chart-area { position: relative; height: 160px; display: flex; align-items: flex-end; gap: 10px; padding-top: 20px; border-bottom: 2px solid var(--border); }
.chart-bar-group { flex: 1; height: 100%; display: flex; flex-direction: column; justify-content: flex-end; position: relative; align-items: center; }
.bar { width: 100%; max-width: 48px; border-radius: 6px 6px 0 0; background: color-mix(in srgb, var(--primary) 20%, var(--surface)); display: flex; flex-direction: column; justify-content: flex-start; align-items: center; padding-top: 6px; transition: height 0.5s cubic-bezier(0.4, 0, 0.2, 1), background 0.3s; position: relative; }
.bar.active { background: var(--primary); box-shadow: 0 0 20px color-mix(in srgb, var(--primary) 40%, transparent); }
.bar-val { font-size: 11px; font-weight: 800; color: var(--fg); position: absolute; opacity: 0; transition: opacity 0.3s; white-space: nowrap; }
.bar.active ~ .bar-val, .split-container.active ~ .bar-val { opacity: 1; }
.chart-bar-group .bar-val { opacity: 0; }
.chart-bar-group:has(.active) .bar-val { opacity: 1; }

/* 8th Gen Split */
.split-container { width: 100%; max-width: 64px; height: 100%; display: flex; align-items: flex-end; justify-content: center; gap: 4px; }
.bar.split-train { background: color-mix(in srgb, var(--train) 20%, var(--surface)); max-width: 30px; }
.bar.split-infer { background: color-mix(in srgb, var(--infer) 20%, var(--surface)); max-width: 30px; }
.split-container.active .bar.split-train { background: var(--train); box-shadow: 0 0 16px color-mix(in srgb, var(--train) 40%, transparent); }
.split-container.active .bar.split-infer { background: var(--infer); box-shadow: 0 0 16px color-mix(in srgb, var(--infer) 40%, transparent); }
.split-container.active .split-label { color: var(--primary-contrast); }
.split-label { font-size: 10px; font-weight: 800; color: var(--fg); writing-mode: vertical-rl; transform: rotate(180deg); margin-bottom: 8px; letter-spacing: 1px; }

/* --- Controls --- */
.controls { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.btn-group { display: flex; gap: 12px; }
button.btn { font: inherit; padding: 9px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--fg); cursor: pointer; font-weight: 600; font-size: 14px; transition: filter 0.2s; }
button.btn.primary { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }
button.btn:disabled { opacity: 0.4; cursor: not-allowed; }
button.btn:not(:disabled):hover { filter: brightness(.92); }
:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

@keyframes slideUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
.animate-content { animation: slideUp 0.4s ease forwards; }
@media (prefers-reduced-motion: reduce) {
  .animate-content { animation: none; }
  .timeline-progress, .bar, .node-chip, .node-chip::before, .node-chip::after { transition: none; }
}
