/* iNKMOTH: the extra layer. The cursor, Moth Shell, and the hard cut
   between pages. Everything here is optional; site.css stands alone. */

/* ---------------------------------------------------- cursor */
.has-mcur, .has-mcur * { cursor: none !important; }
.mcur {
  position: fixed; left: 0; top: 0; z-index: 300; pointer-events: none;
  will-change: transform; contain: layout style;
}
.mcur svg { position: absolute; display: none; image-rendering: pixelated; }
.mcur[data-s="arrow"] .c-arrow,
.mcur[data-s="link"] .c-link,
.mcur[data-s="text"] .c-text { display: block; }
.mcur.down svg { transform: translate(1px, 1px); }
.mcur.down .c-link { transform: translate(0, 2px); }
.mcur.gone { visibility: hidden; }
.mcur[data-s="text"] .c-text { animation: mcur-blink 1.06s steps(1) infinite; }
@keyframes mcur-blink { 50% { opacity: .35; } }

/* ---------------------------------------------------- Moth Shell */
.sh-open {
  font: inherit; color: var(--dim); background: none; border: 0; padding: 0 2px;
  letter-spacing: inherit;
}
.sh-open:hover, .sh-open:focus-visible { color: var(--paper); outline: none; }
.sh-open .k { border: 1px solid currentColor; padding: 0 4px; margin-right: 6px; }

.sh {
  position: fixed; z-index: 90;
  left: 50%; bottom: calc(var(--frame) + 44px); transform: translateX(-50%);
  width: min(780px, calc(100vw - 2 * var(--frame) - 16px));
  height: min(440px, calc(100svh - 120px));
  display: flex; flex-direction: column;
  background: var(--ink); color: var(--paper);
  border: 2px solid var(--paper);
  box-shadow: 8px 8px 0 rgba(0, 0, 0, .7);
  font: 21px/1.25 var(--f-term);
}
.sh[hidden] { display: none; }
.sh.opening { animation: sh-in .22s steps(4) backwards; }
@keyframes sh-in {
  from { clip-path: inset(100% 0 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}
.sh-bar {
  display: flex; align-items: center; gap: 10px; padding: 4px 6px 4px 12px;
  background: var(--paper); color: var(--ink); font: 15px/1.4 var(--f-pixel);
  user-select: none;
}
.sh-bar .sp { flex: 1; }
.sh-bar button {
  font: 18px/1 var(--f-term); width: 26px; height: 22px; padding: 0;
  background: var(--ink); color: var(--paper); border: 0;
}
.sh-bar button:hover, .sh-bar button:focus-visible { background: var(--red); outline: none; }
.sh-out {
  flex: 1; overflow-y: auto; padding: 10px 14px 4px; white-space: pre-wrap; word-break: break-word;
  scrollbar-width: thin; scrollbar-color: var(--dim) transparent;
}
.sh-out .ln { min-height: 1.25em; }
.sh-out .cmd { color: var(--paper); }
.sh-out .dim { color: var(--dim); }
.sh-out .th { color: var(--thought); }
.sh-out .err { color: var(--red); }
.sh-out .her { color: var(--paper); font-family: var(--f-pixel); font-size: 17px; }
.sh-out a { color: var(--paper); text-decoration: underline; text-underline-offset: 3px; }
.sh-line { display: flex; align-items: baseline; gap: 8px; padding: 2px 14px 10px; }
.sh-line .p { color: var(--dim); white-space: nowrap; }
.sh-line input {
  flex: 1; min-width: 0; font: inherit; color: var(--paper); background: none;
  border: 0; outline: none; padding: 0; caret-color: var(--paper);
}
@media (max-width: 560px) {
  .sh { font-size: 19px; height: min(70svh, 460px); }
  .sh-line .p .host { display: none; }
}

/* the whole page goes quiet for a moment */
.hush main, .hush .statusbar { visibility: hidden; }
.hush-word {
  position: fixed; inset: 0; z-index: 95; display: grid; place-items: center;
  font: 22px var(--f-pixel); color: var(--thought); pointer-events: none;
}

/* ---------------------------------------------------- hard cut between pages
   Like the game: no fades. The old page drops away in four steps, the new
   one is there. */
@view-transition { navigation: auto; }
::view-transition-old(root) { animation: vt-out .16s steps(4) both; }
::view-transition-new(root) { animation: vt-in .2s steps(5) both; }
@keyframes vt-out {
  to { clip-path: inset(0 0 100% 0); filter: brightness(.4); }
}
@keyframes vt-in {
  from { clip-path: inset(100% 0 0 0); }
  to   { clip-path: inset(0 0 0 0); }
}

@media (prefers-reduced-motion: reduce) {
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
  .sh.opening, .mcur[data-s="text"] .c-text { animation: none; }
}

/* ======================================================================
   ADVANCED LAYER v2 (fx.js, sfx.js). Same rules as the game: no smooth
   fades, every move happens in hard steps, only Ink and Paper. All of it
   sits behind .fx, which fx.js sets: without scripts nothing here applies.
   ====================================================================== */

/* ---------------------------------------------------- arriving on a new page
   head script sets .arriving before first paint so there is no flash */
html.arriving body::after { content: ""; position: fixed; inset: 0; z-index: 260; background: var(--paper); animation: arr-fb 0s 1.6s forwards; }
@keyframes arr-fb { to { visibility: hidden; } }
.fx::view-transition-old(root), .fx::view-transition-new(root) { animation: none; }

/* ---------------------------------------------------- transition 1: blinds */
.shutter { position: fixed; inset: 0; z-index: 250; pointer-events: none; display: grid; grid-template-rows: repeat(12, 1fr); visibility: hidden; }
.shutter i { display: block; background: var(--paper); transform: scaleX(0); transform-origin: left center; }
.shutter i:nth-child(even) { transform-origin: right center; }
.shutter.in, .shutter.hold, .shutter.out { visibility: visible; }
.shutter.in i { animation: sh-close .32s steps(5) forwards; animation-delay: calc(var(--i) * 18ms); }
.shutter.hold i { transform: scaleX(1); }
.shutter.out i { transform: scaleX(1); animation: sh-open .36s steps(5) forwards; animation-delay: calc(var(--i) * 18ms); }
.shutter .lbl, .ink .lbl {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 1;
  font: 26px/1 var(--f-term); color: var(--ink); letter-spacing: .12em; opacity: 0; white-space: nowrap;
}
.shutter.in .lbl, .shutter.hold .lbl, .ink.in .lbl { opacity: 1; animation: lbl-blink .5s steps(1) infinite; }
@keyframes sh-close { from { transform: scaleX(0); } to { transform: scaleX(1); } }
@keyframes sh-open  { from { transform: scaleX(1); } to { transform: scaleX(0); } }
@keyframes lbl-blink { 50% { opacity: .2; } }

/* ---------------------------------------------------- transition 2: ink bleed (into a game)
   a paper drop spreads from where you clicked, in nine steps; the new page
   opens a hole from the same point. */
.ink { position: fixed; inset: 0; z-index: 251; pointer-events: none; visibility: hidden; background: var(--paper); clip-path: circle(0 at var(--x, 50%) var(--y, 50%)); }
.ink.in { visibility: visible; animation: ink-in .56s steps(9) forwards; }
.ink.hold { visibility: visible; clip-path: none; }
@keyframes ink-in { from { clip-path: circle(0 at var(--x) var(--y)); } to { clip-path: circle(150vmax at var(--x) var(--y)); } }
.hole { position: fixed; z-index: 251; left: var(--x, 50%); top: var(--y, 50%); width: 0; height: 0; border-radius: 50%;
  transform: translate(-50%, -50%); box-shadow: 0 0 0 250vmax var(--paper); pointer-events: none; visibility: hidden; }
.hole.out { visibility: visible; animation: hole-out .66s steps(9) forwards; }
@keyframes hole-out { from { width: 0; height: 0; } to { width: 320vmax; height: 320vmax; } }

/* ---------------------------------------------------- entrance: hero lines scan in, top to bottom */
.fx .cx { clip-path: inset(0 0 100% 0); }
.fx .cx.go { clip-path: inset(-24px); transition: clip-path .5s steps(7); transition-delay: calc(var(--d, 0) * 110ms); }

/* ---------------------------------------------------- scroll meter, HUD, section rail */
.meter-top { position: fixed; left: var(--frame); right: var(--frame); top: var(--frame); height: 3px; z-index: 42; pointer-events: none; transform-origin: left center; transform: scaleX(0); background: var(--paper); }
.statusbar .hud { color: var(--dim); font-variant-numeric: tabular-nums; }
.eyebrow[data-n]::before { content: attr(data-n); color: var(--thought); }

.rail { position: fixed; left: calc(var(--frame) + 14px); top: 50%; transform: translateY(-50%); z-index: 43; display: none; flex-direction: column; gap: 2px; font: 20px/1 var(--f-term); }
@media (min-width: 1360px) { .fx .rail { display: flex; } }
.rail a { display: flex; align-items: center; gap: 10px; color: var(--dim); padding: 6px 4px; }
.rail a i { width: 8px; height: 8px; border: 1px solid currentColor; flex: none; }
.rail a b { font-weight: 400; max-width: 0; overflow: hidden; white-space: nowrap; opacity: 0; background: var(--ink); padding-right: 6px; transition: max-width .25s steps(5), opacity .25s steps(2); }
.rail a:hover, .rail a:focus-visible { color: var(--thought); outline: none; }
.rail a:hover b, .rail a:focus-visible b, .rail a.on b { max-width: 12em; opacity: 1; }
.rail a.on { color: var(--paper); }
.rail a.on i { background: var(--paper); }

/* ---------------------------------------------------- scroll-lit words */
.fx .wd { opacity: .26; transition: opacity .22s steps(2); }
.fx .wd.lit { opacity: 1; }

/* ---------------------------------------------------- decode headings, staggers, dithered pictures */
.dec { font-variant-ligatures: none; }
.js.fx .stag > * { opacity: 0; transform: translateY(10px); transition: opacity .4s steps(4), transform .4s steps(4); transition-delay: calc(var(--d, 0) * 70ms); }
.js.fx .stag.in > * { opacity: 1; transform: none; }
.js.fx .dith {
  -webkit-mask: conic-gradient(#000 25%, transparent 0 50%, #000 0 75%, transparent 0) 0 0 / 8px 8px;
  mask: conic-gradient(#000 25%, transparent 0 50%, #000 0 75%, transparent 0) 0 0 / 8px 8px;
  clip-path: inset(0 100% 0 0);
}
.js.fx .dith.in { animation: dith-in .6s steps(10) forwards; }
.js.fx .dith.done { -webkit-mask: none; mask: none; clip-path: none; animation: none; }
@keyframes dith-in { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.fx .screen img { will-change: transform; transform: scale(1.14); }
.js.fx .term .t { visibility: hidden; }
.js.fx .term .t.on { visibility: visible; }

/* ---------------------------------------------------- hover: a one-step jolt, a pixel underline */
.btn:hover, .btn:focus-visible { animation: jolt .18s steps(2) 1; }
@keyframes jolt { 0% { transform: translate(3px, 0); } 50% { transform: translate(-3px, 0); } 100% { transform: none; } }
.member, .cell { position: relative; }
.member::after, .cell::after { content: ""; position: absolute; left: 0; top: 0; width: 0; height: 2px; background: var(--paper); }
.member:hover::after, .cell:hover::after { width: 100%; transition: width .24s steps(6); }
.member:hover .sil, .cell:hover .n { animation: flick .3s steps(1) 1; }
@keyframes flick { 0%, 40% { opacity: .2; } 20%, 60% { opacity: 1; } 100% { opacity: .85; } }
.scan { position: fixed; inset: 0; z-index: 60; pointer-events: none; background: repeating-linear-gradient(0deg, rgba(232,232,232,.16) 0 2px, transparent 2px 6px); animation: scan .28s steps(6) forwards; }
@keyframes scan { 0% { clip-path: inset(0 0 100% 0); } 50% { clip-path: inset(0 0 0 0); } 100% { clip-path: inset(100% 0 0 0); } }

/* ---------------------------------------------------- the band: a ticker that rides your scrolling */
.band { display: none; border-block: 1px solid var(--line); overflow: hidden; padding: 16px 0 14px; background: var(--ink); position: relative; z-index: 1; }
.fx .band { display: block; }
.band .track { display: flex; width: max-content; white-space: nowrap; font: 28px/1 var(--f-term); color: var(--dim); will-change: transform; }
.band .track span { display: flex; align-items: center; }
.band .track span::after { content: ""; width: 8px; height: 8px; margin: 0 40px; background: var(--line); }
.band .track span:nth-child(3n+1) { color: var(--paper); }

/* ---------------------------------------------------- the moth */
.fx .flight { display: none; }
.moth-fly, .moth-fx { position: fixed; pointer-events: none; }
.moth-fx { left: 0; top: 0; width: 100vw; height: 100vh; height: 100dvh; z-index: 43; image-rendering: pixelated; }
.moth-fly {
  left: 0; top: 0; z-index: 44; width: 56px; height: 32px; visibility: hidden; will-change: transform;
  background: url("../img/studio/moth_a.png") center / 56px 32px no-repeat; image-rendering: pixelated;
  mix-blend-mode: difference;
}
.moth-fly.on { visibility: visible; }
.moth-fly[data-f="b"] { background-image: url("../img/studio/moth_b.png"); }
@media (max-width: 700px) { .moth-fly { width: 42px; height: 24px; background-size: 42px 24px; } }
.hush .moth-fly, .hush .moth-fx, .hush .rail, .hush .meter-top { visibility: hidden; }

/* ---------------------------------------------------- debug panel (press ?) */
.dbg { position: fixed; right: calc(var(--frame) + 12px); top: calc(var(--frame) + 12px); z-index: 120; background: var(--ink);
  border: 1px solid var(--paper); padding: 8px 12px; font: 18px/1.3 var(--f-term); color: var(--thought); white-space: pre; box-shadow: 4px 4px 0 rgba(0,0,0,.7); }
.dbg[hidden] { display: none; }

/* ---------------------------------------------------- boot waits for your first touch, so the sound can play */
.boot.wait *, .boot.wait { animation-play-state: paused !important; }
.boot.wait .skip { animation: lbl-blink 1s steps(1) infinite; color: var(--paper); }
.statusbar .snd .st { white-space: nowrap; }

@media (prefers-reduced-motion: reduce) {
  .shutter, .ink, .hole, .meter-top, .scan, .moth-fly, .moth-fx, .rail, .band { display: none !important; }
  .fx .cx, .fx .wd { clip-path: none !important; opacity: 1 !important; }
  html.arriving body::after { display: none; }
}

/* ======================================================================
   ROUND 3: replays in both directions, pixel dissolve, button fills
   ====================================================================== */

/* direction-aware: things arrive from below when you scroll down, from above when you scroll up */
.js.fx .stag > * { transform: translateY(var(--ty, 10px)); }
.js.fx .stag.in > * { transform: none; }
.js.fx .reveal:not(.in) { transform: translateY(var(--ty, 12px)); }
.js.fx .dith { clip-path: var(--cp, inset(0 100% 0 0)); }
@keyframes dith-in { from { clip-path: var(--cp, inset(0 100% 0 0)); } to { clip-path: inset(0 0 0 0); } }

/* the dither rule beside each eyebrow redraws with it */
.fx .eyebrow.dec::after { transform: scaleX(0); transform-origin: left center; }
.fx .eyebrow.dec.in::after { transform: scaleX(1); transition: transform .6s steps(10) .12s; }

/* pixel dissolve between pages */
.dz { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; height: 100dvh; z-index: 252; pointer-events: none; visibility: hidden; image-rendering: pixelated; }
.dz-lbl { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 253; pointer-events: none; opacity: 0; white-space: nowrap;
  font: 28px/1 var(--f-term); letter-spacing: .14em; color: var(--ink); }
.dz-lbl.on { opacity: 1; animation: lbl-blink .5s steps(1) infinite; }

/* click burst */
.pop { position: fixed; z-index: 46; width: 0; height: 0; pointer-events: none; mix-blend-mode: difference; }
.pop i { position: absolute; left: -2px; top: -2px; width: 4px; height: 4px; background: var(--paper); animation: pop .4s steps(4) forwards; }
@keyframes pop { from { transform: rotate(var(--a)) translateX(4px); } to { transform: rotate(var(--a)) translateX(32px); opacity: 0; } }

/* buttons and menu rows fill with paper in steps instead of snapping */
.fx .btn, .fx .thoughts li a {
  background: linear-gradient(var(--paper), var(--paper)) no-repeat 0 0 / 0 100%, var(--ink);
  transition: background-size .22s steps(5), color .1s steps(1) .1s;
}
.fx .btn:hover, .fx .btn:focus-visible, .fx .thoughts li a:hover, .fx .thoughts li a:focus-visible, .fx .thoughts li.on a {
  background: linear-gradient(var(--paper), var(--paper)) no-repeat 0 0 / 100% 100%, var(--ink); color: var(--ink);
}
.fx .btn.ghost-btn:hover { background-size: 0 100%; color: var(--paper); border-color: var(--paper); }
.fx .thoughts li a .n, .fx .thoughts li a .meta { transition: color .1s steps(1) .1s; }

@media (prefers-reduced-motion: reduce) { .dz, .dz-lbl, .pop { display: none !important; } }
