/* scene: simulator ("Simulate a blast"). Prefix: sim- */

.bay.sim {
  /* the pinned section must fit under the header: the stage is the flexible part */
  --sim-stage-h: clamp(250px, calc(100svh - var(--header-h) - 300px), 560px);
  --sim-strip-h: 112px;
  padding: clamp(14px, 3vh, 30px) 0 clamp(8px, 1.6vh, 16px);
  overflow: clip;
  isolation: isolate;
}
.sim::before {
  content: ""; position: absolute; inset: 0; z-index: -2; pointer-events: none;
  background:
    radial-gradient(48% 60% at 76% 40%, rgba(54, 173, 224, .13), transparent 72%),
    radial-gradient(40% 42% at 70% 104%, rgba(201, 120, 196, .12), transparent 70%),
    radial-gradient(36% 46% at 6% 96%, rgba(252, 115, 77, .07), transparent 70%);
}
.sim-rain {
  /* kept off the copy column and faded out before the strip chart, so it never sits under small text */
  --sim-rain-a: radial-gradient(46% 92% at 78% 44%, #000 34%, transparent 100%);
  --sim-rain-b: linear-gradient(180deg, #000 0, #000 72%, transparent 84%);
  position: absolute; inset: 0; width: 100%; height: 100%; z-index: -1; pointer-events: none; opacity: .9;
  -webkit-mask-image: var(--sim-rain-a), var(--sim-rain-b); mask-image: var(--sim-rain-a), var(--sim-rain-b);
  -webkit-mask-composite: source-in; mask-composite: intersect;
}
.sim-wrap { position: relative; }
.sim-grid { display: grid; gap: clamp(18px, 3.4vw, 48px); align-items: center; }
@media (min-width: 960px) { .sim-grid { grid-template-columns: minmax(0, .8fr) minmax(0, 1.2fr); } }

/* ---------- copy ---------- */
.sim-copy { display: grid; gap: 20px; justify-items: start; min-width: 0; }
.sim-copy .tag, .sim-copy .h2, .sim-copy .lede { margin: 0; }
.sim-copy .h2 { font-size: clamp(2rem, 4vw, 3.3rem); }
/* gradient text survives the per-word decode spans */
.sim-copy .h2 .grad .w { background: linear-gradient(100deg, #fff 0%, #fff 40%, var(--peach) 100%); -webkit-background-clip: text; background-clip: text; color: transparent; padding-bottom: .12em; margin-bottom: -.12em; }
.sim-lede { max-width: 44ch; }
.sim-pick { display: grid; gap: 9px; justify-self: stretch; }
.sim-tiers { display: flex; gap: 6px; }
.sim-tier {
  flex: 1 1 0; min-width: 0; font: inherit; cursor: pointer; text-align: left; display: grid; gap: 5px; align-content: start;
  padding: 11px 10px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface-2); color: var(--ink-3);
  position: relative; overflow: hidden; -webkit-tap-highlight-color: transparent;
  transition: transform .35s var(--e-spring), border-color .2s ease, background .2s ease, box-shadow .25s ease, color .2s ease;
}
.sim-tier b { font-size: 1.24rem; line-height: 1; font-weight: 600; color: var(--ink-2); letter-spacing: -.02em; font-variant-numeric: tabular-nums; transition: color .2s ease; }
.sim-tier span { font-family: var(--f-mono); font-size: .56rem; letter-spacing: 0; white-space: nowrap; }
.sim-tier::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 2px; background: var(--spectrum); transform: scaleX(0); transform-origin: 0 50%; transition: transform .5s var(--e-out); }
.sim-tier:hover { transform: translateY(-2px); border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); }
.sim-tier:active { transform: scale(.96); }
.sim-tier[aria-checked="true"] { border-color: var(--brand); background: var(--brand-soft); color: var(--brand-light); box-shadow: 0 8px 22px -6px rgba(54, 173, 224, .35); }
.sim-tier[aria-checked="true"] b { color: var(--ink); }
.sim-tier[aria-checked="true"]::after { transform: scaleX(1); }
.sim-tier:focus-visible, .sim-replay:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }
.sim-points { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.sim-points li { display: flex; align-items: center; gap: 10px; font-size: .95rem; color: var(--ink); }
.sim-points svg { flex: none; width: 20px; height: 20px; padding: 3px; border-radius: 50%; color: var(--brand-light); background: var(--brand-soft); }
.sim-cta { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.sim-fine { flex-basis: 100%; }

/* ---------- chamber ---------- */
.sim-chamber { position: relative; overflow: clip; min-width: 0; box-shadow: var(--shadow-2); }
/* the card's edge and glow follow the phase of the blast */
.sim .sim-chamber { transition: opacity .8s ease, transform .8s var(--e-out), border-color .6s ease, box-shadow .6s ease; }
.sim-chamber[data-state="sending"] { border-color: color-mix(in srgb, var(--brand) 45%, var(--line)); box-shadow: var(--shadow-1), 0 26px 72px -10px rgba(54, 173, 224, .32); }
.sim-chamber[data-state="engaging"] { border-color: color-mix(in srgb, var(--mint) 42%, var(--line)); box-shadow: var(--shadow-1), 0 26px 72px -10px rgba(95, 212, 154, .2); }
.sim-stage {
  position: relative; height: calc(var(--sim-stage-h) - var(--sim-trim, 0px));
  background:
    radial-gradient(64% 70% at 60% 50%, rgba(54, 173, 224, .08), transparent 72%),
    radial-gradient(60% 44% at 60% 112%, rgba(201, 120, 196, .12), transparent 72%);
}
.sim-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.sim-hud { position: absolute; display: grid; gap: 3px; pointer-events: none; line-height: 1.35; }
.sim-hud > span { display: block; }
.sim-tl { top: 18px; left: 22px; justify-items: start; }
.sim-tr { top: 18px; right: 22px; text-align: right; justify-items: end; }
.sim-bl { bottom: 16px; left: 22px; }
.sim-br { bottom: 16px; right: 22px; text-align: right; justify-items: end; }
.sim-big { font-family: var(--f-sans); font-size: clamp(2.7rem, 5.2vw, 4.5rem); font-weight: 600; line-height: 1; letter-spacing: -.04em; text-transform: none; width: max-content; padding: 0 .06em .06em 0; }
.sim-big.sim-glitch { animation: sim-glitch .4s steps(2, end); }
.sim-val { font-size: .68rem; white-space: nowrap; }
.sim-val b { text-transform: none; font-family: var(--f-sans); font-size: 1.65rem; font-weight: 600; letter-spacing: -.03em; line-height: 1.1; margin-right: 2px; font-variant-numeric: tabular-nums; }
.sim-status { display: inline-flex !important; align-items: center; gap: 8px; white-space: nowrap; }
.sim-status b { color: var(--brand-light); min-width: 9ch; }
.sim-led { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-3); box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 12%, transparent); flex: none; transition: background .3s ease; }
.sim-chamber[data-state="sending"] .sim-led { background: var(--brand); animation: fx-pulse .9s ease-in-out infinite; }
.sim-chamber[data-state="delivered"] .sim-led { background: var(--brand); }
.sim-chamber[data-state="engaging"] .sim-led { background: var(--mint); animation: fx-pulse 1.8s ease-in-out infinite; }
.sim-chamber[data-state="queued"] .sim-status b { color: var(--ink-2); }
.sim-chamber[data-state="engaging"] .sim-status b { color: var(--mint); }

.sim-hint {
  position: absolute; left: 50%; bottom: 15px; display: inline-flex; align-items: center; gap: 7px; white-space: nowrap; pointer-events: none;
  padding: 6px 12px; border-radius: 999px; color: var(--brand-light); background: color-mix(in srgb, var(--surface-solid) 82%, transparent); border: 1px solid color-mix(in srgb, var(--brand) 30%, transparent);
  transform: translate(-50%, 8px); opacity: 0; transition: opacity .45s ease, transform .5s var(--e-out);
}
.sim-hint svg { animation: sim-nudge 1.4s ease-in-out infinite; }
.sim-idle .sim-hint { opacity: 1; transform: translate(-50%, 0); }
.sim-replay {
  pointer-events: auto; display: inline-flex; align-items: center; gap: 7px; cursor: pointer; margin-bottom: 7px;
  font-family: var(--f-mono); font-size: .68rem; font-weight: 500; letter-spacing: 0; line-height: 1;
  padding: 8px 13px 8px 10px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--brand) 32%, transparent);
  background: var(--surface-solid); color: var(--brand-light); box-shadow: var(--shadow-1);
  transition: transform .3s var(--e-spring), box-shadow .25s ease, background .2s ease;
  animation: sim-pop .5s var(--e-spring) both;
}
.sim-replay[hidden] { display: none; }
.sim-replay:hover { transform: translateY(-2px); background: var(--brand-soft); box-shadow: 0 10px 24px -6px rgba(54, 173, 224, .35); }
.sim-replay:active { transform: scale(.95); }
.sim-replay svg { flex: none; }
.sim-playing .sim-replay { pointer-events: none; background: var(--brand-soft); }
.sim-playing .sim-replay svg { animation: fx-spin 1.1s linear infinite reverse; }

/* summary row: fills in as each phase arrives, the complete read-out at the end */
.sim-stats { position: relative; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-top: 1px solid var(--line); background: var(--surface-2); overflow: clip; }
.sim-stat { position: relative; display: grid; grid-template-columns: auto minmax(0, 1fr); column-gap: 13px; row-gap: 1px; align-items: baseline; padding: 11px 18px 12px; min-width: 0; opacity: .4; transition: opacity .45s ease; }
.sim-stat + .sim-stat { border-left: 1px solid var(--line); }
.sim-stat.on { opacity: 1; }
.sim-stat .hud { grid-column: 1 / -1; display: flex; align-items: center; gap: 7px; }
.sim-stat .hud i { width: 7px; height: 7px; border-radius: 50%; background: var(--sim-c); flex: none; }
.sim-stat b { font-size: 1.5rem; font-weight: 600; letter-spacing: -.025em; line-height: 1.15; color: var(--ink); font-variant-numeric: tabular-nums; transform-origin: 0 80%; transition: transform .5s var(--e-spring), color .4s ease; }
.sim-stat em { font-style: normal; font-family: var(--f-mono); font-size: .64rem; letter-spacing: 0; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sim-stat::before { content: ""; position: absolute; left: 0; right: 0; top: -1px; height: 2px; background: var(--sim-c); transform: scaleX(var(--sim-f, 0)); transform-origin: 0 50%; }
.sim-s-d { --sim-c: var(--brand); --sim-ct: var(--brand-light); }
.sim-s-c { --sim-c: var(--mint); --sim-ct: var(--mint); }
.sim-s-r { --sim-c: var(--violet); --sim-ct: var(--violet); }
.sim-final .sim-stat b { color: var(--sim-ct); transform: scale(1.05); }
.sim-final .sim-stat:nth-child(2) b { transition-delay: .08s; }
.sim-final .sim-stat:nth-child(3) b { transition-delay: .16s; }
.sim-stats::after { content: ""; position: absolute; inset: 0; pointer-events: none; background: linear-gradient(105deg, transparent 38%, rgba(124, 203, 236, .16) 50%, transparent 62%); transform: translateX(-110%); }
.sim-final .sim-stats::after { transform: translateX(110%); transition: transform 1.1s var(--e-out); }

/* ---------- strip chart ---------- */
.sim-strip { position: relative; margin-top: clamp(10px, 1.8vh, 18px); border-top: 1px solid var(--line); }
.sim-trace { display: block; width: 100%; height: var(--sim-strip-h); }
.sim-foot { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding-top: 4px; }
.sim-keys { display: flex; flex-wrap: wrap; gap: 4px 18px; }
.sim-k { white-space: nowrap; }
.sim-k::before { content: ""; display: inline-block; width: 14px; height: 2px; border-radius: 2px; vertical-align: middle; margin: -2px 7px 0 0; background: var(--sim-c); }
.sim-k-d { --sim-c: var(--brand); }
.sim-k-u { --sim-c: repeating-linear-gradient(90deg, var(--ink-2) 0 4px, transparent 4px 7px); }
.sim-k-c { --sim-c: var(--mint); }
.sim-k-r { --sim-c: var(--violet); }
.sim-note { text-align: right; white-space: nowrap; }

@keyframes sim-glitch { 20% { transform: translate(-3px, 1px) skewX(-6deg); } 40% { transform: translate(3px, -1px); } 60% { transform: translate(-1px, 2px) skewX(4deg); } 80% { transform: translate(2px, 0); } }
@keyframes sim-nudge { 0%, 100% { transform: translateY(-2px); } 50% { transform: translateY(3px); } }
@keyframes sim-pop { from { opacity: 0; transform: translateY(6px) scale(.8); } }

/* short desktop windows */
@media (min-width: 960px) and (max-height: 760px) {
  .bay.sim { --sim-strip-h: 88px; --sim-stage-h: clamp(230px, calc(100svh - var(--header-h) - 248px), 500px); }
  .sim-copy { gap: 14px; }
  .sim-big { font-size: clamp(2.4rem, 4vw, 3rem); }
  .sim-fine { display: none; }
}

/* narrower two-column desktops: the summary read-outs stack */
@media (min-width: 960px) and (max-width: 1180px) {
  .sim-stat { grid-template-columns: minmax(0, 1fr); padding: 9px 14px 10px; }
  .sim-tier { padding: 10px 8px 9px; }
  .sim-tier span { letter-spacing: 0; }
}

/* tablets and phones: stacked, compact enough to sit under the header */
@media (max-width: 959px) {
  .bay.sim { --sim-stage-h: clamp(200px, calc(100svh - var(--header-h) - 482px), 430px); --sim-strip-h: 84px; }
  .sim-rain { --sim-rain-a: radial-gradient(120% 30% at 50% 60%, #000 40%, transparent 100%); --sim-rain-b: linear-gradient(180deg, #000 0, #000 80%, transparent 88%); }
  .sim-copy { gap: 13px; }
  .sim-lede { max-width: 60ch; }
  .sim-fine { flex-basis: auto; }
}
@media (max-width: 719px) {
  .bay.sim { --sim-stage-h: clamp(170px, calc(100svh - var(--header-h) - 428px), 400px); --sim-strip-h: 80px; padding: 10px 0 6px; }
  .sim-grid { gap: 12px; }
  .sim-copy { gap: 10px; }
  .sim-copy .tag { font-size: .64rem; }
  .sim-copy .h2 { font-size: 1.62rem; }
  .sim-lede { font-size: .88rem; line-height: 1.45; }
  .sim-label, .sim-fine { display: none; }
  .sim-points { display: none; }   /* the lede already says it; keeps the pin inside the screen */
  .sim-tier { padding: 8px 8px 7px; border-radius: 10px; gap: 0; }
  .sim-tier b { font-size: 1.02rem; }
  .sim-tier span { display: none; }
  .sim-cta { gap: 8px; }
  .sim-cta .btn { padding: 9px 16px; font-size: .86rem; }
  .sim-hud { font-size: .56rem; gap: 2px; }
  .sim-tl { top: 11px; left: 13px; }
  .sim-tr { top: 11px; right: 13px; }
  .sim-bl { bottom: 10px; left: 13px; }
  .sim-br { bottom: 10px; right: 13px; }
  .sim-big { font-size: 2.3rem; }
  .sim-val { font-size: .56rem; }
  .sim-val b { font-size: 1.2rem; }
  .sim-x, .sim-hint { display: none !important; }
  .sim-status { gap: 6px; }
  .sim-status b { min-width: 0; }
  .sim-led { width: 7px; height: 7px; }
  .sim-replay { font-size: .6rem; padding: 7px 11px 7px 9px; margin-bottom: 5px; }
  .sim-stat { padding: 7px 10px 8px; grid-template-columns: minmax(0, 1fr); }
  .sim-stat .hud { font-size: .54rem; gap: 5px; }
  .sim-stat b { font-size: 1.06rem; }
  .sim-stat em { font-size: .54rem; }
  .sim-strip { margin-top: 8px; }
  .sim-keys { display: none; }
  .sim-foot { justify-content: flex-end; padding-top: 1px; }
  .sim-note { font-size: .54rem; }
}
@media (max-width: 719px) and (max-height: 780px) {
  .sim-more { display: none; }
  .bay.sim { --sim-stage-h: clamp(170px, calc(100svh - var(--header-h) - 374px), 400px); --sim-strip-h: 68px; }
}

/* very short phones: drop the eyebrow and slim the strip so the chamber keeps its room */
@media (max-width: 719px) and (max-height: 680px) {
  .sim-copy .tag { display: none; }
  .bay.sim { --sim-stage-h: clamp(160px, calc(100svh - var(--header-h) - 322px), 400px); --sim-strip-h: 56px; padding-top: 8px; }
  .sim-grid, .sim-copy { gap: 8px; }
}
@media (max-width: 719px) and (max-height: 600px) {
  .sim-cta, .sim-tl > span:last-child { display: none; }
  .bay.sim { --sim-stage-h: clamp(160px, calc(100svh - var(--header-h) - 274px), 400px); }
}

@media (prefers-reduced-motion: reduce) {
  .sim-tier, .sim-tier::after, .sim-stat, .sim-stat b, .sim-replay, .sim .sim-chamber { transition: none; animation: none; }
  .sim-led { animation: none !important; }
  .sim-stats::after { display: none; }
  .sim-big.sim-glitch { animation: none; }
  .sim-hint { display: none; }
}

/* phones on their side: copy and chamber share one short row, the strip slims down */
@media (max-height: 520px) and (min-width: 600px) {
  .bay.sim { --sim-stage-h: clamp(140px, calc(100svh - var(--header-h) - 142px), 300px); --sim-strip-h: 52px; padding: 8px 0 4px; }
  .sim-grid { grid-template-columns: minmax(0, .72fr) minmax(0, 1.28fr); gap: 16px; }
  .sim-copy { gap: 8px; }
  .sim-copy .tag, .sim-lede, .sim-label, .sim-fine, .sim-foot, .sim-hint, .sim-cta .btn-outline, .sim-points { display: none !important; }
  .sim-copy .h2 { font-size: 1.5rem; }
  .sim-tiers { gap: 4px; }
  .sim-tier { padding: 7px 6px 6px; border-radius: 9px; gap: 0; }
  .sim-tier b { font-size: .92rem; }
  .sim-tier span { display: none; }
  .sim-cta .btn { padding: 8px 14px; font-size: .84rem; }
  .sim-hud { font-size: .56rem; gap: 1px; }
  .sim-tl { top: 9px; left: 12px; } .sim-tr { top: 9px; right: 12px; } .sim-bl { bottom: 8px; left: 12px; } .sim-br { bottom: 8px; right: 12px; }
  .sim-big { font-size: 1.9rem; }
  .sim-val { font-size: .56rem; }
  .sim-val b { font-size: 1.1rem; }
  .sim-x, .sim-tl > span:last-child { display: none !important; }
  .sim-replay { font-size: .58rem; padding: 6px 10px 6px 8px; margin-bottom: 4px; }
  .sim-stat { padding: 5px 10px 6px; grid-template-columns: auto minmax(0, 1fr); column-gap: 8px; }
  .sim-stat .hud { font-size: .52rem; }
  .sim-stat b { font-size: 1rem; }
  .sim-stat em { font-size: .54rem; }
  .sim-strip { margin-top: 6px; }
}
