/* ==========================================================================
   Home: "How SciMLStudio works"
   --------------------------------------------------------------------------
   Sits between the hero and the Learn / Lab cards. Uses only the tokens from
   omega.css (--ink, --accent, --butter, --line ...), so it follows the brand.

   Progressive enhancement: with no JavaScript every step is expanded and
   every code pane is shown. how-it-works.js adds `.is-js` to the section,
   and only then do the dimming, the step-through and the reveal apply.
   ========================================================================== */

.how {
  --how-dur: 4800ms;
  position: relative;
  padding-block: clamp(3.5rem, 8vw, 6.5rem);
  background-color: #F6EFDC;
  background-image: radial-gradient(rgba(6, 62, 58, .075) 1px, transparent 1.2px);
  background-size: 24px 24px;
  border-block: 1px solid var(--line);
}
.how__inner { display: grid; gap: clamp(3.5rem, 8vw, 6rem); }

/* --- Shared: flowing wires, pulsing nodes ---------------------------------- */
.how-wire {
  fill: none; stroke: rgba(244, 235, 207, .3); stroke-width: 1.7;
  stroke-dasharray: 5 7; animation: how-flow 1.7s linear infinite;
  transition: stroke .35s ease, stroke-width .35s ease, opacity .35s ease;
}
@keyframes how-flow { to { stroke-dashoffset: -24; } }
.how-pulse {
  animation: how-pulse 2.4s ease-in-out infinite;
  transform-box: fill-box; transform-origin: center;
}
@keyframes how-pulse { 50% { transform: scale(1.22); opacity: .7; } }

/* --- 1. Intro --------------------------------------------------------------- */
.how__intro {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.08fr);
  gap: clamp(2rem, 5vw, 4.5rem); align-items: center;
}
.how__title {
  font-size: clamp(1.8rem, 1rem + 2.3vw, 3rem);
  line-height: 1.1; letter-spacing: -.022em; margin-bottom: var(--sp-5);
}
.how__title span, .how__title em { display: block; }
.how__title em { font-style: italic; color: var(--accent-text); }
.how__lead { color: var(--muted); font-size: var(--step-1); line-height: 1.6; max-width: 46ch; }
.how__actions { display: flex; flex-wrap: wrap; gap: var(--sp-3); margin-top: var(--sp-5); }
.how__note { margin: var(--sp-4) 0 0; font-size: var(--step--1); color: var(--muted-2); }

/* The dark cards (SciML picture, Lab demo) */
.howviz {
  position: relative; isolation: isolate; margin: 0; overflow: hidden;
  color: var(--on-dark); border-radius: var(--radius-lg); box-shadow: var(--shadow-lift);
  background:
    radial-gradient(90% 70% at 88% 0%, rgba(255, 103, 79, .20), transparent 60%),
    radial-gradient(80% 70% at 0% 100%, rgba(255, 103, 79, .10), transparent 60%),
    var(--ink);
}
.howviz::before {
  content: ""; position: absolute; inset: 0; z-index: -1; pointer-events: none;
  background-image:
    linear-gradient(rgba(244, 235, 207, .05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(244, 235, 207, .05) 1px, transparent 1px);
  background-size: 32px 32px;
  -webkit-mask-image: radial-gradient(ellipse at center, #000 35%, transparent 85%);
          mask-image: radial-gradient(ellipse at center, #000 35%, transparent 85%);
}
.howviz svg { display: block; width: 100%; height: auto; max-width: none; }
.howviz text { font-family: var(--font-label); text-anchor: middle; }
.howviz__cap {
  padding: 0 clamp(1.1rem, 3vw, 1.75rem) clamp(1rem, 2.5vw, 1.4rem);
  font-size: var(--step--1); line-height: 1.5; color: var(--on-dark-2);
}

/* SciML picture */
.howfield { padding: clamp(.6rem, 2vw, 1.2rem) clamp(.4rem, 1.5vw, .8rem) 0; }
.hf-halo { transform-origin: center; }
.hf-edges { fill: none; stroke: rgba(244, 235, 207, .14); stroke-width: 1; }
.hf-box rect { fill: var(--ink-2); stroke: rgba(244, 235, 207, .42); stroke-width: 1.2; }
.hf-box text { fill: var(--on-dark); font-size: 12.5px; font-weight: 500; }
.hf-nodes circle { fill: var(--butter); }
.hf-pred { fill: var(--on-accent); font-size: 12px; font-weight: 700; }
.hf-loop { stroke: var(--accent); stroke-width: 1.6; }
.hf-loop-label { fill: var(--accent-bright); font-size: 11.5px; font-weight: 500; letter-spacing: .02em; }
#hf-w1, #hf-w2, #hf-w3 { stroke: rgba(244, 235, 207, .5); }
#hf-w4 { stroke: var(--accent); }

/* --- 2. Walkthrough ---------------------------------------------------------- */
.how__stage { display: grid; gap: var(--sp-6); }
.how__stage-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--sp-4); }
.how__stage-head .eyebrow { margin-bottom: var(--sp-2); }
.how__sub { margin: 0; font-size: var(--step-3); letter-spacing: -.015em; }

.how__play {
  display: inline-flex; align-items: center; gap: .55rem; cursor: pointer;
  font: 500 var(--step--1)/1 var(--font-body); color: var(--ink);
  padding: .6rem .95rem; border-radius: 99px;
  background: var(--surface); border: 1px solid var(--line);
  transition: border-color .15s, background-color .15s;
}
.how__play:hover { border-color: var(--ink); }
.how__play svg { width: 14px; height: 14px; fill: currentColor; }
.how__play [data-icon="play"] { display: none; }
.how__play[aria-pressed="true"] [data-icon="play"] { display: block; }
.how__play[aria-pressed="true"] [data-icon="pause"] { display: none; }
/* Nothing to pause until the script is running */
.how:not(.is-js) .how__play { display: none; }

.how__stage-body {
  display: grid; grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr);
  gap: clamp(1.5rem, 4vw, 3rem); align-items: start;
}

/* Steps */
.how__steps { list-style: none; margin: 0; padding: 0; display: grid; gap: .5rem; }
.hstep {
  position: relative; overflow: hidden; width: 100%; text-align: left; cursor: pointer;
  display: grid; grid-template-columns: auto minmax(0, 1fr); gap: .95rem; align-items: start;
  padding: .95rem 1.05rem; font: inherit; color: var(--ink);
  background: transparent; border: 1px solid transparent; border-radius: var(--radius-lg);
  transition: background-color .25s, border-color .25s, box-shadow .25s;
}
.hstep:hover { background: rgba(255, 254, 250, .6); }
.hstep__num {
  display: grid; place-items: center; width: 34px; height: 34px; flex: none; border-radius: 50%;
  font: 600 .86rem/1 var(--font-label);
  background: var(--paper); color: var(--muted); border: 1px solid var(--line);
  transition: background-color .25s, color .25s, border-color .25s, transform .25s;
}
.hstep__title { display: block; font: 600 var(--step-1)/1.3 var(--font-label); letter-spacing: -.01em; padding-top: .25rem; }
.hstep__fold { display: block; }
.hstep__text { display: block; color: var(--muted); font-size: var(--step--1); line-height: 1.6; padding-top: .35rem; }
.hstep__bar { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; }
.hstep__bar::after { content: ""; display: block; height: 100%; width: 0; background: var(--accent); }

.is-js .hstep__fold { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .4s ease; }
.is-js .hstep__text { min-height: 0; overflow: hidden; opacity: 0; transition: opacity .3s ease; }
.is-js .hstep.is-active { background: var(--surface); border-color: var(--line); box-shadow: var(--shadow); }
.is-js .hstep.is-active .hstep__fold { grid-template-rows: 1fr; }
.is-js .hstep.is-active .hstep__text { opacity: 1; transition-delay: .1s; }
.is-js .hstep.is-active .hstep__num { background: var(--accent); border-color: var(--accent); color: var(--on-accent); transform: scale(1.06); }
.is-js .hstep.is-done .hstep__num { background: var(--ink); border-color: var(--ink); color: var(--paper-2); }
.is-js .is-playing .hstep.is-active .hstep__bar::after { animation: how-fill var(--how-dur) linear forwards; }
@keyframes how-fill { to { width: 100%; } }

/* The Lab diagram */
.howviz--flow { align-self: stretch; display: grid; }
.howflow {
  display: grid; grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr);
  align-items: center; align-content: center; padding: clamp(1rem, 2.6vw, 1.75rem);
}
.hb rect { fill: var(--ink-2); stroke: rgba(244, 235, 207, .4); stroke-width: 1.2; transition: fill .3s, stroke .3s; }
.hb text { fill: var(--on-dark); font-size: 13px; font-weight: 500; transition: fill .3s; }
.hb--net rect { fill: var(--ink-3); }
.hb--net circle { fill: var(--butter); }
.hchip rect { fill: var(--butter); }
.hchip text { fill: var(--ink); font-size: 10.5px; font-weight: 600; }
.hw { stroke: rgba(244, 235, 207, .45); }

/* Dimmed until their step arrives (script running only) */
.is-js .hb, .is-js .hw, .is-js .hdots circle, .is-js .hchip { opacity: .3; transition: opacity .35s ease, filter .35s ease; }
.is-js .hb.is-done, .is-js .hw.is-done, .is-js .hchip.is-done { opacity: .85; }
.is-js .hb.is-on, .is-js .hw.is-on, .is-js .hdots circle.is-on, .is-js .hchip.is-on { opacity: 1; }
.is-js .hdots circle { opacity: 0; }
.is-js .hdots circle.is-on { opacity: 1; }
.is-js .hchip { transform-box: fill-box; transform-origin: center; transform: scale(.85); }
.is-js .hchip.is-on, .is-js .hchip.is-done { transform: none; }
.is-js .hchip { transition: opacity .35s ease, transform .35s cubic-bezier(.2, 1.4, .4, 1); }

.hb.is-on rect { fill: var(--accent); stroke: var(--accent); }
.hb.is-on text { fill: var(--on-accent); font-weight: 700; }
.hb--net.is-on circle { fill: var(--on-accent); }
.hb.is-on { filter: drop-shadow(0 0 12px rgba(255, 103, 79, .55)); }
.hb.is-done rect { fill: var(--ink-3); stroke: rgba(244, 235, 207, .6); }
.hw.is-on { stroke: var(--accent); stroke-width: 2.2; }
.hw.is-done { stroke: rgba(255, 124, 102, .75); }

/* Code window */
.howcode {
  position: relative; overflow: hidden; background: #04211E;
  border: 1px solid rgba(244, 235, 207, .3); border-radius: 12px;
  font-family: var(--font-mono); box-shadow: 0 14px 36px -14px rgba(0, 0, 0, .55);
}
.howcode { transition: border-color .4s ease, box-shadow .4s ease; }
.is-js [data-step="5"] .howcode { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 14px 44px -10px rgba(255, 103, 79, .45); }
.howcode__bar {
  display: flex; align-items: center; gap: .38rem; padding: .55rem .8rem;
  border-bottom: 1px solid rgba(244, 235, 207, .14);
  font-size: .72rem; color: var(--on-dark-3);
}
.howcode__bar i { width: 8px; height: 8px; border-radius: 50%; background: rgba(244, 235, 207, .22); display: block; }
.howcode__file { margin-left: .45rem; color: var(--accent-bright); letter-spacing: .02em; }
.howcode__dl {
  margin-left: auto; display: inline-flex; align-items: center; gap: .3rem;
  padding: .12rem .5rem; border-radius: 99px; font-size: .66rem;
  background: var(--accent); color: var(--on-accent); font-weight: 600;
}
.howcode__dl svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.is-js .howcode__dl { opacity: 0; transform: scale(.8); transition: opacity .3s, transform .3s; }
.is-js .howcode__dl.is-on { opacity: 1; transform: none; animation: how-ready 1.6s ease-in-out infinite; }
@keyframes how-ready { 50% { box-shadow: 0 0 0 5px rgba(255, 103, 79, .25); } }

.howcode__body { padding: .85rem 1rem .5rem; }
.howcode__pane + .howcode__pane { margin-top: .85rem; padding-top: .85rem; border-top: 1px dashed rgba(244, 235, 207, .14); }
.cl {
  display: block; white-space: pre; overflow: hidden;
  font-size: clamp(.64rem, .58rem + .2vw, .74rem); line-height: 1.8; color: var(--on-dark);
}
.cm { color: var(--on-dark-3); }
.kw { color: var(--accent-bright); }
.howcode__foot { margin: 0; padding: .35rem 1rem .6rem; font: 400 .66rem/1.3 var(--font-body); color: var(--on-dark-3); }

.is-js .howcode__body { display: grid; min-height: 12.2rem; align-content: start; }
.is-js .howcode__pane { grid-area: 1 / 1; opacity: 0; visibility: hidden; margin: 0; padding: 0; border: 0; transition: opacity .25s ease, visibility .25s; }
.is-js .howcode__pane.is-on { opacity: 1; visibility: visible; }
.is-js .howcode__pane.is-on .cl { animation: how-type .5s steps(26, end) both; animation-delay: calc(var(--i, 0) * 150ms); }
@keyframes how-type { from { clip-path: inset(0 100% 0 0); opacity: .2; } to { clip-path: inset(0 0 0 0); opacity: 1; } }

/* --- 3. Feature cards --------------------------------------------------------- */
.how__features {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: var(--sp-4);
}
.hfeat {
  position: relative; padding: var(--sp-5) var(--sp-5) var(--sp-5);
  background: var(--surface); border: 1px solid var(--line-soft); border-top: 3px solid var(--accent);
  border-radius: var(--radius-lg); box-shadow: var(--shadow);
  transition: transform .2s ease, box-shadow .2s ease;
}
.hfeat:hover { transform: translateY(-4px); box-shadow: var(--shadow-lift); }
.hfeat__icon { width: 26px; height: 26px; color: var(--accent-text); margin-bottom: var(--sp-3); }
.hfeat h3 { margin: 0 0 .35rem; font: 600 var(--step-1)/1.3 var(--font-label); letter-spacing: -.01em; }
.hfeat p { margin: 0; color: var(--muted); font-size: var(--step--1); line-height: 1.6; }

/* --- Scroll reveal (script running only) --------------------------------------- */
.is-js [data-reveal] { opacity: 0; transform: translateY(22px); transition: opacity .7s ease, transform .7s cubic-bezier(.2, .7, .2, 1); }
.is-js [data-reveal].is-in { opacity: 1; transform: none; }
.is-js .how__features.is-in .hfeat { animation: how-rise .6s cubic-bezier(.2, .7, .2, 1) both; animation-delay: calc(var(--d, 0) * 90ms); }
@keyframes how-rise { from { opacity: 0; transform: translateY(14px); } }

/* --- Responsive ------------------------------------------------------------------ */
@media (max-width: 960px) {
  .how__intro { grid-template-columns: 1fr; }
  .how__stage-body { grid-template-columns: 1fr; }
  .how__lead { max-width: 60ch; }
}
@media (max-width: 620px) {
  .howflow { grid-template-columns: 1fr; gap: var(--sp-3); }
  .howflow__svg { max-width: 380px; margin-inline: auto; }
  .hw[id="hw-5"], .hdots circle:last-child { display: none; }
  .is-js .howcode__body { min-height: 11.4rem; }
  .hstep { padding: .8rem .75rem; }
}

@media (prefers-reduced-motion: reduce) {
  .is-js [data-reveal] { opacity: 1; transform: none; }
  .is-js .how__features.is-in .hfeat { animation: none; }
}
