/* EP Math Lab v4 motion layer. Only fx- classes; nothing here changes the app's layout.
   Overlays are pointer-events:none and sit below content; nothing clips focus rings. */

@property --fx-r { syntax: '<length>'; inherits: false; initial-value: 0px; }

/* ---------- depolarisation press: a circular wavefront from the press point (sodium, then refractory fade) ---------- */
.fx-press-host { position: relative; isolation: isolate; overflow: hidden; }
.fx-press-host::after {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none; border-radius: inherit; opacity: 0;
  background:
    radial-gradient(circle at var(--fx-px) var(--fx-py), transparent calc(var(--fx-r) - 18px), color-mix(in srgb, var(--na) 40%, #fff) calc(var(--fx-r) - 3px), transparent var(--fx-r)),
    radial-gradient(circle at var(--fx-px) var(--fx-py), color-mix(in srgb, var(--on-na) 12%, transparent) calc(var(--fx-r) - 40px), transparent calc(var(--fx-r) - 18px));
}
.fx-press-host.fx-fire::after { animation: fx-dep 620ms cubic-bezier(.2,.7,.2,1) forwards; }
@keyframes fx-dep { 0% { --fx-r: 0px; opacity: 1; } 65% { opacity: 1; } 100% { --fx-r: var(--fx-far, 240px); opacity: 0; } }

/* correct answer: one wave across the whole sheet */
.fx-wave-host { position: relative; }
.fx-sheetwave {
  position: absolute; inset: 0; z-index: 3; pointer-events: none; border-radius: inherit; opacity: 0;
  background: radial-gradient(circle at var(--fx-px) var(--fx-py), transparent calc(var(--fx-r) - 90px), color-mix(in srgb, var(--na) 22%, transparent) calc(var(--fx-r) - 4px), transparent var(--fx-r));
  mix-blend-mode: multiply; animation: fx-sweep 1.2s cubic-bezier(.25,.6,.3,1) forwards;
}
:root[data-theme="dark"] .fx-sheetwave { mix-blend-mode: screen; }
@keyframes fx-sweep { 0% { --fx-r: 0px; opacity: 1; } 80% { opacity: .9; } 100% { --fx-r: var(--fx-far, 900px); opacity: 0; } }

/* ---------- ink bleed on rows: a masked patch of flow-field hairlines under the cursor ---------- */
.fx-ink { position: relative; isolation: isolate; }
.fx-ink::before {
  content: ''; position: absolute; inset: 0; z-index: -1; pointer-events: none; border-radius: inherit;
  background: var(--ink); opacity: 0; transition: opacity .4s cubic-bezier(.2,.7,.2,1);
  -webkit-mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' fill='none' stroke='%23000' stroke-width='1' stroke-linecap='round'%3E%3Cpath d='M1 9c5-3 9-3 13 0M17 4c4-2 8-1 11 2M27 14c4-3 8-3 12 0M3 22c4-2 8-2 11 1M15 17c5-3 9-3 13 1M23 27c5-2 9-2 13 1M2 35c5-3 9-3 13 0M14 31c4-2 7-1 10 2M30 37c3-2 6-2 9 0'/%3E%3C/svg%3E"), radial-gradient(circle 150px at var(--fx-mx, 50%) var(--fx-my, 50%), #000 0, rgba(0,0,0,.5) 45%, transparent 100%);
  mask-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='40' height='40' fill='none' stroke='%23000' stroke-width='1' stroke-linecap='round'%3E%3Cpath d='M1 9c5-3 9-3 13 0M17 4c4-2 8-1 11 2M27 14c4-3 8-3 12 0M3 22c4-2 8-2 11 1M15 17c5-3 9-3 13 1M23 27c5-2 9-2 13 1M2 35c5-3 9-3 13 0M14 31c4-2 7-1 10 2M30 37c3-2 6-2 9 0'/%3E%3C/svg%3E"), radial-gradient(circle 150px at var(--fx-mx, 50%) var(--fx-my, 50%), #000 0, rgba(0,0,0,.5) 45%, transparent 100%);
  -webkit-mask-size: 40px 40px, 100% 100%; mask-size: 40px 40px, 100% 100%;
  -webkit-mask-repeat: repeat, no-repeat; mask-repeat: repeat, no-repeat;
  -webkit-mask-composite: source-in; mask-composite: intersect;
}
.fx-ink.fx-ink-on::before { opacity: .22; }
.fx-ink:focus-visible::before { opacity: .16; --fx-mx: 50%; --fx-my: 50%; }

/* ---------- h1 line rise ---------- */
.fx-w { display: inline-block; clip-path: inset(-.5em -.3em 0 -.3em); }
.fx-wi { display: inline-block; }

/* ---------- view transitions ---------- */
@media (prefers-reduced-motion: no-preference) {
  .fx-vt #view { view-transition-name: fx-view; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  ::view-transition-old(fx-view) { animation: fx-vt-out 150ms cubic-bezier(.4,0,1,1) both; }
  ::view-transition-new(fx-view) { animation: fx-vt-in 340ms cubic-bezier(.2,.8,.2,1) both; }
  ::view-transition-group(fx-title) { animation-duration: 420ms; animation-timing-function: cubic-bezier(.2,.8,.2,1); }
}
@keyframes fx-vt-out { to { opacity: 0; transform: translateY(-6px); } }
@keyframes fx-vt-in { from { opacity: 0; transform: translateY(12px); } }

/* ---------- phase field ---------- */
.fx-main { position: relative; }
.fx-field {
  position: absolute; left: 0; width: 100%; z-index: -1; pointer-events: none; display: block;
  -webkit-mask-image: linear-gradient(to bottom, #000 0, #000 70%, transparent 100%); mask-image: linear-gradient(to bottom, #000 0, #000 70%, transparent 100%);
}
.fx-field-path { -webkit-mask-image: linear-gradient(to bottom, transparent, #000 18%, #000 78%, transparent); mask-image: linear-gradient(to bottom, transparent, #000 18%, #000 78%, transparent); }
.fx-field-eq {
  position: absolute; top: 52px; right: 48px; z-index: 0; pointer-events: none;
  display: grid; justify-items: end; gap: 2px; text-align: right;
  font-family: var(--f-math); font-size: 21px; line-height: 1.35; color: var(--ink);
}
.fx-field-eq i { font-style: italic; }
.fx-field-eq small { font-family: var(--f-text); font-size: 14px; line-height: 1.4; color: var(--ink-2); max-width: 26ch; margin-top: 8px; }
.fx-field-eq[hidden] { display: none; }

/* ---------- orbit: tooltip, tilt, stimulus glow ---------- */
.fx-tip {
  position: fixed; left: 0; top: 0; z-index: 70; pointer-events: none;
  display: grid; gap: 2px; max-width: 280px; padding: 9px 14px 11px; border-radius: 12px;
  background: var(--ink); color: var(--sheet); box-shadow: 4px 4px 0 color-mix(in srgb, var(--ink) 16%, transparent);
  font: 500 14px/1.3 var(--f-text); opacity: 0; transition: opacity .14s;
}
.fx-tip.on { opacity: 1; }
.fx-tip-k { display: flex; align-items: center; gap: 7px; opacity: .82; }
.fx-tip-t { font: 17px/1.25 var(--f-display); letter-spacing: -.01em; }
.fx-tip.is-current .fx-tip-k::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--na); }
.fx-orbit .fig-orbit { transform-origin: 50% 50%; }
.fx-orbit.fx-tilting { cursor: grabbing; user-select: none; -webkit-user-select: none; }
.fx-orbit.fx-tilting .fig-orbit { will-change: transform; }
.fx-glow { pointer-events: none; }
.fx-glow path { fill: none; stroke: var(--na); stroke-width: 5; stroke-linecap: round; filter: drop-shadow(0 0 4px color-mix(in srgb, var(--na) 80%, transparent)); }

/* ---------- paper shelf ---------- */
.fx-shelf {
  list-style: none; margin: 0 0 12px; padding: 26px 10px 0; display: flex; align-items: flex-end; gap: 5px;
  overflow-x: auto; scrollbar-width: thin; position: relative;
  background: linear-gradient(to top, color-mix(in srgb, var(--ink) 18%, transparent) 0 3px, transparent 3px);
}
.fx-shelf li { flex: none; display: flex; }
.fx-spine {
  --w: 44px; --hgt: 220px; --sc: var(--ink-2);
  display: flex; flex-direction: column; justify-content: space-between; align-items: center; gap: 10px;
  width: var(--w); height: var(--hgt); padding: 18px 0 14px; overflow: hidden;
  color: var(--ink); text-decoration: none; border-radius: 5px 5px 2px 2px;
  border: 1.5px solid color-mix(in srgb, var(--sc) 50%, transparent);
  background:
    linear-gradient(var(--sc), var(--sc)) 0 8px / 100% 3px no-repeat,
    linear-gradient(var(--sc), var(--sc)) 0 calc(100% - 8px) / 100% 2px no-repeat,
    color-mix(in srgb, var(--sc) 13%, var(--sheet));
  transform-origin: 30% 100%;
  transition: transform .42s cubic-bezier(.3,1.45,.5,1), box-shadow .3s;
}
.fx-spine-t, .fx-spine-m { writing-mode: vertical-rl; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fx-spine-t { font: 16px/1.1 var(--f-display); max-height: calc(var(--hgt) - 100px); }
.fx-spine-m { font: 500 14px/1.1 var(--f-text); color: var(--ink-2); max-height: 84px; }
.fx-spine:hover, .fx-spine:focus-visible { transform: translateY(-16px) rotate(-3deg); box-shadow: 5px 6px 0 color-mix(in srgb, var(--ink) 12%, transparent); }
.fx-spine:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; }
.fx-shelf-fallback { display: none !important; }

@media (prefers-reduced-motion: reduce) {
  .fx-press-host.fx-fire::after { animation: none; opacity: 1; background: color-mix(in srgb, #fff 22%, transparent); }
  .fx-sheetwave { display: none; }
  .fx-ink::before { transition: none; }
  .fx-spine { transition: none; }
  .fx-spine:hover, .fx-spine:focus-visible { transform: translateY(-8px); }
}

/* =================== the story: "One heartbeat, four scales" (Benches hub) =================== */
.fx-story-on { display: block !important; position: relative; height: 600vh; }
.fx-story-on > .fx-spent { display: none; }
.fx-st { position: sticky; top: var(--topbar, 0px); height: calc(100svh - var(--topbar, 0px)); overflow: hidden; touch-action: pan-y; isolation: isolate; }
.fx-st > canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; pointer-events: none; }
.fx-st-mist { opacity: .9; }
.fx-st-bar { position: absolute; z-index: 6; left: 0; right: 0; top: 0; height: 2px; background: var(--na); transform-origin: 0 50%; transform: scaleX(0); }
.fx-l { position: absolute; inset: 0; z-index: 2; pointer-events: none; color: var(--ink); }
.fx-l a, .fx-l button { pointer-events: auto; }
.fx-off, .fx-off a, .fx-off button { pointer-events: none !important; }
.fx-l .fx-w, .fx-vw, .fx-cw { display: inline-block; }
.fx-l .fx-w { clip-path: inset(-.5em -.3em -.05em -.3em); }

/* hero */
.fx-hero-text { position: absolute; left: clamp(20px, 5vw, 72px); top: 11vh; width: min(640px, 54%); transform-origin: 0 40%; will-change: transform, filter, opacity; }
.fx-l-hero h1 { font-size: clamp(44px, 5.6vw, 88px); line-height: 1.0; letter-spacing: -.02em; margin: 0 0 20px; max-width: 9.2em; text-wrap: balance; }
.fx-l-hero .story-chip { margin-bottom: 18px; background: color-mix(in srgb, var(--sheet) 70%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.fx-l-hero .story-intro { max-width: 36ch; color: var(--ink-2); margin: 0; }
.fx-hud {
  position: absolute; left: 0; top: 0; width: 228px; padding: 14px 16px 13px; border-radius: 12px;
  background: color-mix(in srgb, var(--sheet) 60%, transparent); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent);
  font: 500 14px/1.35 var(--f-text); font-variant-numeric: tabular-nums; color: var(--ink);
}
.fx-br { position: absolute; width: 12px; height: 12px; border: 0 solid var(--ink); }
.fx-br.tl { left: -7px; top: -7px; border-width: 1.5px 0 0 1.5px; } .fx-br.tr { right: -7px; top: -7px; border-width: 1.5px 1.5px 0 0; }
.fx-br.bl { left: -7px; bottom: -7px; border-width: 0 0 1.5px 1.5px; } .fx-br.br { right: -7px; bottom: -7px; border-width: 0 1.5px 1.5px 0; }
.fx-hud-chip { display: inline-flex; align-items: center; gap: 8px; margin: 0 0 10px; padding: 3px 11px 3px 9px; border-radius: 999px; background: var(--ink); color: var(--sheet); font-weight: 650; }
.fx-beat { width: 8px; height: 8px; border-radius: 50%; background: var(--na); }
.fx-hud dl { margin: 0; display: grid; gap: 3px; }
.fx-hud dl div { display: flex; justify-content: space-between; gap: 12px; }
.fx-hud dt { color: var(--ink-2); } .fx-hud dd { margin: 0; font-weight: 650; }
.fx-hud-note { margin: 8px 0 0; padding-top: 8px; border-top: 1px solid color-mix(in srgb, var(--ink) 12%, transparent); color: var(--ink-2); }
.fx-caption { position: absolute; left: clamp(20px, 5vw, 72px); bottom: 28px; margin: 0; max-width: 30ch; font-size: 15px; color: var(--ink-2); }
.fx-hint { position: absolute; right: clamp(20px, 5vw, 72px); bottom: 26px; margin: 0; display: flex; align-items: center; gap: 12px; font-size: 15px; color: var(--ink-2); }
.fx-hint i { width: 1.5px; height: 30px; background: linear-gradient(var(--ink-2), transparent); transform-origin: 50% 0; animation: fx-hint 1.8s cubic-bezier(.6,0,.3,1) infinite; }
@keyframes fx-hint { 0% { transform: scaleY(0); } 50% { transform: scaleY(1); opacity: 1; } 100% { transform: scaleY(1); opacity: 0; } }

/* vision */
.fx-l-vision .story-vision {
  position: absolute; left: clamp(20px, 5vw, 72px); top: 50%; transform: translateY(-50%); margin: 0; width: min(15em, 50%);
  font: clamp(30px, 3.5vw, 54px)/1.12 var(--f-display); letter-spacing: -.015em; color: var(--ink);
  text-shadow: 0 0 22px var(--paper), 0 0 3px var(--paper);
}
.fx-l-vision .story-vision > span { display: block; }
.fx-l-vision .story-vision .fx-vw { display: inline-block; }
.fx-l-vision .story-vision > span + span { margin-top: .35em; color: var(--ink); }
.fx-l-vision .story-vision > span:first-child, .fx-l-vision .story-vision > span:first-child .fx-vw { color: var(--ink-2); }
.fx-s2 { position: absolute; right: clamp(20px, 5vw, 72px); bottom: 26px; margin: 0; font-size: 15px; color: var(--ink-2); }

/* cell */
.fx-cell-p { position: absolute; left: clamp(20px, 5vw, 72px); top: 9vh; margin: 0; max-width: 30ch; font: 400 clamp(20px, 1.75vw, 26px)/1.42 var(--f-text); color: var(--ink); text-shadow: 0 0 16px var(--paper); }
.fx-trace { position: absolute; left: 0; top: 0; overflow: visible; }
.fx-trace-ink { fill: none; stroke: var(--ink); stroke-width: 1.75; stroke-linejoin: round; stroke-linecap: round; }
.fx-trace-base { stroke: color-mix(in srgb, var(--ink) 25%, transparent); stroke-width: 1; stroke-dasharray: 2 5; }
.fx-trace-pen { fill: var(--na); }
.fx-hots { position: absolute; inset: 0; margin: 0; padding: 0; list-style: none; pointer-events: none; }
.fx-hots > li { position: absolute; left: 0; top: 0; width: 0; height: 0; transform-origin: 0 0; }
.fx-l .fx-hot.story-hot {
  position: absolute; left: -17px; top: -24px; white-space: nowrap; gap: 9px; padding-right: 14px;
  background: color-mix(in srgb, var(--sheet) 62%, transparent); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-color: color-mix(in srgb, var(--ink) 18%, transparent);
  transition: border-color .2s, background-color .2s;
}
.fx-hots > li:not(.fx-below) .fx-hot { transform: translateY(-34px); }
.fx-hots > li.fx-below .fx-hot { transform: translateY(34px); }
.fx-l .fx-hot.story-hot::before { animation: fx-ping 2.4s cubic-bezier(.2,.7,.2,1) infinite; box-shadow: 0 0 0 0 color-mix(in srgb, var(--na) 60%, transparent); }
@keyframes fx-ping { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--na) 60%, transparent); } 100% { box-shadow: 0 0 0 14px color-mix(in srgb, var(--na) 0%, transparent); } }
.fx-hot .story-hot-s { display: inline-block; max-width: 0; opacity: 0; overflow: hidden; vertical-align: bottom; transition: max-width .4s cubic-bezier(.2,.8,.2,1), opacity .25s; }
.fx-hot.on .story-hot-s, .fx-hot:focus-visible .story-hot-s { max-width: 20em; opacity: 1; }
.fx-hot.on { border-color: var(--ink); background: color-mix(in srgb, var(--sheet) 88%, transparent); }

/* channel */
.fx-chan-col { position: absolute; left: clamp(20px, 5vw, 72px); top: 6vh; width: min(470px, 46%); display: grid; gap: 16px; }
.fx-l .fx-chan-h { font-size: clamp(30px, 3vw, 46px); line-height: 1.06; margin: 0; letter-spacing: -.015em; }
.fx-card {
  padding: 16px 18px 14px; border-radius: 16px; transform-style: preserve-3d;
  background: color-mix(in srgb, var(--sheet) 64%, transparent); -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px);
  border: 1px solid color-mix(in srgb, var(--ink) 12%, transparent); box-shadow: var(--shadow);
}
.fx-card p { margin: 0; }
.fx-card-k { font-weight: 650; font-size: 15px; }
.fx-card-v { display: flex; align-items: baseline; gap: 8px; margin: 2px 0 4px !important; }
.fx-card-n { font: 46px/1 var(--f-display); font-variant-numeric: tabular-nums; min-width: 1.3em; }
.fx-card-u { color: var(--ink-2); font-size: 15px; }
.fx-spark { display: block; width: 100%; height: 56px; overflow: visible; }
.fx-spark-base { stroke: color-mix(in srgb, var(--ink) 20%, transparent); stroke-width: 1; }
.fx-spark-line { fill: none; stroke: var(--na); stroke-width: 2.25; stroke-linejoin: round; stroke-dasharray: 1 1; stroke-dashoffset: 1; }
.fx-spark-dot { fill: var(--ink); }
.fx-card-s { margin-top: 8px !important; font-size: 14px; line-height: 1.4; color: var(--ink-2); }
.fx-l .fx-features { pointer-events: auto; background: color-mix(in srgb, var(--paper) 70%, transparent); border-radius: 14px; }
.fx-l .fx-features a { min-height: 58px; padding: 4px; transition: transform .25s cubic-bezier(.2,.8,.2,1); }
.fx-l .fx-features a:hover { transform: translateX(4px); }
.fx-l .fx-features a:hover .zoom-chev svg { transform: translateX(3px); }
.fx-l .fx-features .zoom-chev svg { transition: transform .25s cubic-bezier(.2,.8,.2,1); }

/* the panel slides up over the end of the pinned stage */
.fx-panel-up {
  position: relative; z-index: 3; margin-top: -30vh;
  background: var(--sheet); border: 1.5px solid var(--line); border-radius: 18px; box-shadow: var(--shadow);
  padding: 26px clamp(16px, 3vw, 30px) 30px;
}

/* reduced motion: stills */
.fx-still { margin: 14px 0 18px; }
.fx-still canvas { display: block; max-width: 100%; border-radius: 12px; border: 1.5px solid var(--line); background: var(--sheet); }
.fx-still figcaption { font-size: 14px; color: var(--ink-2); margin-top: 6px; }

@media (max-width: 820px) {
  .fx-story-on { height: 480vh; }
  .fx-hero-text { left: 16px; right: 16px; top: 22px; width: auto; }
  .fx-l-hero h1 { font-size: clamp(40px, 11vw, 54px); }
  .fx-hero-text .fx-hud { position: relative; margin-top: 16px; width: 220px; }
  .fx-l-hero .story-intro { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .fx-hud { padding: 10px 12px; } .fx-hud-note { display: none; }
  .fx-caption { left: 16px; bottom: calc(var(--tabbar) + 14px); max-width: 22ch; }
  .fx-hint, .fx-s2 { right: 16px; bottom: calc(var(--tabbar) + 14px); }
  .fx-l-vision .story-vision { left: 16px; right: 16px; width: auto; top: 22px; transform: none; font-size: clamp(28px, 8vw, 36px); }
  .fx-cell-p { left: 16px; right: 16px; top: 18px; font-size: 19px; }
  .fx-l .fx-hot .story-hot-l, .fx-l .fx-hot .story-hot-s { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .fx-l .fx-hot.on .story-hot-l { position: static; width: auto; height: auto; overflow: visible; clip-path: none; }
  .fx-l .fx-hot.on .story-hot-s { display: inline-block; }
  .fx-l .fx-hot.story-hot { padding-right: 12px; min-width: 44px; }
  .fx-chan-col { left: 16px; right: 16px; top: auto; bottom: calc(var(--tabbar) + 10px); width: auto; gap: 10px; }
  .fx-l .fx-chan-h { font-size: 28px; }
  .fx-card { padding: 12px 14px; }
  .fx-card-s, .fx-l .fx-features .zoom-glyph, .fx-l .fx-features .zoom-sub { display: none; }
  .fx-l .fx-features a { min-height: 46px; grid-template-columns: minmax(0, 1fr) auto 22px; }
  .fx-panel-up { margin-top: -20vh; }
}
@media (prefers-reduced-motion: reduce) {
  .fx-hint i, .fx-l .fx-hot.story-hot::before { animation: none; }
}
