/* Shared motion + diagram styles for the portfolio pages (automation, 3d-printing).
   Status colours are only used for state (ok / warn / fault), never decoration. */
:root {
  --ok: #4ade80;
  --warn: #fbbf24;
  --fault: #f87171;
  --wire: #334155;
  --panel: #0b111d;
  --grid-line: rgba(148, 163, 184, 0.07);
  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
}

/* ---------- scroll reveal ---------- */
.js .reveal {
  opacity: 0;
  transform: translateY(14px);
  transition: opacity 0.6s var(--ease-out), transform 0.6s var(--ease-out);
}
.js .reveal.is-in { opacity: 1; transform: none; }
.js .reveal-stagger > * {
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.5s var(--ease-out), transform 0.5s var(--ease-out);
}
.js .reveal-stagger.is-in > * { opacity: 1; transform: none; }
.js .reveal-stagger.is-in > *:nth-child(2) { transition-delay: 70ms; }
.js .reveal-stagger.is-in > *:nth-child(3) { transition-delay: 140ms; }
.js .reveal-stagger.is-in > *:nth-child(4) { transition-delay: 210ms; }
.js .reveal-stagger.is-in > *:nth-child(5) { transition-delay: 280ms; }

/* subtle lift on cards that already exist on both pages */
.domain-card, .solution-card, .hw-card {
  transition: border-color 0.25s ease, transform 0.25s var(--ease-out), background 0.25s ease;
}
.domain-card:hover, .solution-card:hover, .hw-card:hover {
  border-color: var(--border-accent);
  transform: translateY(-2px);
}

/* ---------- reading progress bar ---------- */
.read-progress {
  position: fixed; inset: 0 0 auto 0; height: 2px; z-index: 50;
  background: var(--accent); transform-origin: 0 50%; transform: scaleX(0);
  pointer-events: none;
}

/* ---------- diagram panel (the "bench" look) ---------- */
.viz {
  background:
    linear-gradient(var(--grid-line) 1px, transparent 1px) 0 0 / 24px 24px,
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px) 0 0 / 24px 24px,
    var(--panel);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1rem;
  margin: 1rem 0 0.75rem;
  position: relative;
}
.viz svg { display: block; width: 100%; height: auto; overflow: visible; }
.viz-head {
  display: flex; justify-content: space-between; align-items: center; gap: 0.75rem;
  flex-wrap: wrap; margin-bottom: 0.75rem;
}
.viz-label {
  font-family: var(--mono-font); font-size: 0.72rem; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-muted);
}
.viz-note {
  font-size: 0.78rem; color: var(--text-muted); margin-top: 0.6rem; line-height: 1.45;
}
.viz-note b { color: #cbd5e1; font-weight: 600; }

.viz-btn {
  font: 600 0.8rem/1 var(--mono-font);
  color: var(--text-main); background: #111827;
  border: 1px solid var(--border-accent); border-radius: 6px;
  padding: 0.55rem 0.8rem; cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
  min-height: 36px;
}
.viz-btn:hover { border-color: var(--accent); color: #fff; }
.viz-btn:focus-visible, .viz-range:focus-visible, .seg button:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.viz-btn[disabled] { opacity: 0.5; cursor: default; }
.viz-btn.danger:hover { border-color: var(--fault); color: var(--fault); }

/* segmented control */
.seg { display: inline-flex; border: 1px solid var(--border-accent); border-radius: 6px; overflow: hidden; }
.seg button {
  font: 600 0.75rem/1 var(--mono-font); color: var(--text-muted);
  background: transparent; border: 0; padding: 0.5rem 0.7rem; cursor: pointer; min-height: 34px;
}
.seg button + button { border-left: 1px solid var(--border-accent); }
.seg button[aria-pressed="true"] { background: var(--accent-glow); color: var(--accent); }

/* range slider */
.viz-range { width: 100%; accent-color: var(--accent); margin: 0.4rem 0; height: 28px; }

/* small readout chips inside diagrams */
.readouts { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 0.5rem; margin-top: 0.75rem; }
.readout {
  font-family: var(--mono-font); border: 1px solid var(--border-color); border-radius: 6px;
  padding: 0.45rem 0.6rem; background: rgba(9, 13, 22, 0.7);
}
.readout span { display: block; font-size: 0.66rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.06em; }
.readout b { font-size: 0.95rem; color: var(--text-main); font-variant-numeric: tabular-nums; }
.readout b.ok { color: var(--ok); }
.readout b.warn { color: var(--warn); }
.readout b.fault { color: var(--fault); }

/* terminal-style event log */
.evlog {
  font: 0.72rem/1.55 var(--mono-font); color: #94a3b8;
  background: #05080f; border: 1px solid var(--border-color); border-radius: 6px;
  padding: 0.6rem 0.75rem; margin-top: 0.75rem; height: 7.6rem; overflow: hidden;
  display: flex; flex-direction: column; justify-content: flex-end;
}
.evlog div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; animation: logIn 0.25s ease; }
.evlog .t { color: #475569; margin-right: 0.5rem; }
.evlog .ok { color: var(--ok); }
.evlog .warn { color: var(--warn); }
.evlog .fault { color: var(--fault); }
.evlog .info { color: #7dd3fc; }
@keyframes logIn { from { opacity: 0; transform: translateY(4px); } }

/* SVG building blocks */
.node rect, .node circle { fill: #0f172a; stroke: var(--wire); stroke-width: 1.2; transition: stroke 0.3s ease, fill 0.3s ease; }
.node text, .svg-t { fill: #cbd5e1; font: 600 11px var(--mono-font); }
.svg-sub { fill: #64748b; font: 10px var(--mono-font); }
.node.on rect, .node.on circle { stroke: var(--ok); }
.node.warn rect, .node.warn circle { stroke: var(--warn); }
.node.down rect, .node.down circle { stroke: var(--fault); }
.node.off { opacity: 0.45; }
.wire { fill: none; stroke: var(--wire); stroke-width: 1.5; transition: stroke 0.3s ease, opacity 0.3s ease; }
.flow {
  fill: none; stroke: var(--accent); stroke-width: 2; stroke-linecap: round;
  stroke-dasharray: 2 10; animation: flow 0.9s linear infinite; transition: stroke 0.3s ease, opacity 0.3s ease;
}
.flow.ok { stroke: var(--ok); }
.flow.warn { stroke: var(--warn); }
.flow.idle { opacity: 0; }
@keyframes flow { to { stroke-dashoffset: -24; } }
.paused .flow, .paused .spin, .paused .pulse { animation-play-state: paused; }

.led { transition: fill 0.25s ease; fill: #1e293b; }
.led.ok { fill: var(--ok); }
.led.warn { fill: var(--warn); }
.led.fault { fill: var(--fault); }
.pulse { animation: pulse 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
@keyframes pulse { 50% { opacity: 0.35; } }

/* ---------- respect reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  .js .reveal, .js .reveal-stagger > * { opacity: 1; transform: none; transition: none; }
  .flow, .pulse, .spin { animation: none; }
  .flow { stroke-dasharray: none; opacity: 0.8; }
  .flow.idle { opacity: 0; }
  .domain-card:hover, .solution-card:hover, .hw-card:hover { transform: none; }
  html { scroll-behavior: auto; }
}
