/* ── THE UNREASONABLE EFFECTIVENESS OF KRISH KATYAL ─────────────
   engineering-zine design: machine collage, orange squiggle,
   iso blocks, exploded stack, sticker record, blueprint exit.  */

:root {
  --paper: #F6F5F1;
  --ink: #17171B;
  --grey: #8B8B90;
  --red: #D8352A;
  --orange: #F07818;
  --blue: #2C4FA3;
  --black: 'Archivo Black', system-ui, sans-serif;
  --mono: 'Plex Mono', ui-monospace, monospace;
  --hand: 'Caveat', cursive;
  --serif: Georgia, 'Times New Roman', serif;
  --spring: cubic-bezier(.34, 1.56, .64, 1);
}
* { margin:0; box-sizing:border-box; }
html { scroll-behavior: smooth; }
body { background: var(--paper); color: var(--ink); font-family: var(--serif); font-size: 14px;
  line-height: 1.7; overflow-x: clip; }
.wrap { max-width: 940px; margin-inline: auto; padding: 0 20px; position: relative; }
@media (min-width: 760px) { .wrap { padding: 0 44px; } }
a { color: inherit; }
::selection { background: var(--orange); color: #fff; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 3px; }

.skip-link { position: fixed; top: 8px; left: 8px; z-index: 200; background: var(--ink); color: var(--paper);
  font-family: var(--mono); font-size: 12px; padding: 8px 14px; text-decoration: none; transform: translateY(-70px); }
.skip-link:focus { transform: none; }

/* ── ambient moving parts — fixed in the page margins, behind content ── */
.decor { position: fixed; inset: 0; z-index: 0; pointer-events: none; color: var(--ink); }
.decor > * { position: absolute; opacity: .09; }
.d-gear { width: 84px; height: 84px; }
.d-spin { transform-box: view-box; transform-origin: 50px 50px; animation: spin 34s linear infinite; }
.d-spin.rev { animation-direction: reverse; animation-duration: 42s; }
.d-gear.tl { top: 8%; left: 3.5vw; }
.d-gear.br { bottom: 9%; right: 3.5vw; width: 64px; height: 64px; }
.d-x { font-family: var(--mono); font-size: 30px; color: var(--red); }
.d-x.tr { top: 20%; right: 5vw; animation: floaty 7s ease-in-out infinite; }
.d-x.bl { bottom: 22%; left: 5vw; color: var(--blue); animation: floaty 9s ease-in-out 1.5s infinite; }
.d-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--orange); opacity: .16; }
.d-dot.dr { top: 46%; right: 4vw; animation: floaty 6s ease-in-out infinite; }
.d-dot.ml { top: 62%; left: 4.5vw; background: var(--red); animation: floaty 8s ease-in-out .8s infinite; }
@keyframes floaty { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-16px); } }
@media (max-width: 1160px) { .decor { display: none; } }

.mono-lbl { font-family: var(--mono); font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--ink); }
.mono-lbl.dim { color: var(--grey); }
.hand-note { font-family: var(--hand); font-weight: 700; font-size: 20px; color: var(--red); line-height: 1.2; }

/* ── HERO ── */
.hero { position: relative; padding: 54px 0 46px; z-index: 2; }
.hero-top { display: flex; justify-content: space-between; align-items: baseline; gap: 14px;
  flex-wrap: wrap; margin-bottom: 22px; }

.collage { position: relative; }
.machines { width: 100%; height: auto; display: block; }
.machines * { stroke: #3F3F45; fill: none; stroke-width: 1.6; stroke-linecap: round; stroke-linejoin: round; }
.machines .fillg { fill: #D8D8D4; }
.machines .filld { fill: #3F3F45; stroke: none; }
.machines .ht { fill: url(#htp); stroke: none; }

/* — living machines — */
.gear { transform-box: fill-box; transform-origin: center; animation: spin 26s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.arm-swing { transform-box: fill-box; transform-origin: 12% 95%; animation: swingarm 5.5s ease-in-out infinite; }
@keyframes swingarm { 0%,100% { transform: rotate(0deg); } 50% { transform: rotate(-4deg); } }
.bob { animation: bobf 4.6s ease-in-out infinite; }
@keyframes bobf { 50% { transform: translateY(-7px); } }
.bot-eyes { transform-box: fill-box; transform-origin: center; animation: blink 4.4s steps(1) infinite; }
@keyframes blink { 0%,91%,100% { transform: scaleY(1); } 93%,96% { transform: scaleY(.1); } }
.antenna { transform-box: fill-box; transform-origin: 50% 100%; animation: wob 3.2s ease-in-out infinite; }
@keyframes wob { 0%,100% { transform: rotate(0); } 50% { transform: rotate(7deg); } }
.drift { animation: driftf 7s ease-in-out infinite; }
@keyframes driftf { 0%,100% { transform: translate(0,0) } 50% { transform: translate(-8px,6px) } }
.pupil { transform-box: fill-box; transform-origin: center; animation: look 6s ease-in-out infinite; }
@keyframes look { 0%,34%,100% { transform: translateX(0) } 42%,58% { transform: translateX(-13px) } 66%,88% { transform: translateX(9px) } }
.pulse { animation: pulsef 3.4s ease-in-out infinite; }
.pulse.d2 { animation-delay: 1.4s; }
@keyframes pulsef { 0%,100% { opacity: 1 } 50% { opacity: .3 } }
.shimmer { animation: pulsef 5s ease-in-out infinite; }
.shimmer.d2 { animation-delay: 2.2s; }

/* — essay title over the art — */
.essay-title { position: relative; margin-top: -10vw; z-index: 3; font-family: 'Instrument Serif', Georgia, serif;
  font-weight: 400; font-size: clamp(40px, 9vw, 88px); line-height: 1.0; letter-spacing: .002em; }
.essay-title em { font-style: italic; }
@media (min-width: 940px) { .essay-title { margin-top: -110px; } }
.et-line { display: block; overflow: hidden; padding-bottom: .06em; }
.et-line > span { display: inline-block;
  text-shadow: -3px -3px 0 var(--paper), 3px -3px 0 var(--paper), -3px 3px 0 var(--paper),
    3px 3px 0 var(--paper), -3px 0 0 var(--paper), 3px 0 0 var(--paper), 0 -3px 0 var(--paper), 0 3px 0 var(--paper); }
.et-name { color: var(--red); position: relative; }
.underline { position: absolute; left: 2%; bottom: -.08em; width: 96%; height: .13em; background: var(--ink);
  transform: scaleX(0); transform-origin: left; }
.js .et-line > span { transform: translateY(112%); }
.js .loaded .et-line > span { animation: riseUp .8s var(--spring) forwards; }
.js .loaded .et-line:nth-child(2) > span { animation-delay: .1s; }
.js .loaded .et-line:nth-child(3) > span { animation-delay: .2s; }
.js .loaded .underline { transition: transform .7s var(--spring) .75s; transform: scaleX(1); }
@keyframes riseUp { to { transform: translateY(0); } }

.hero-strip { margin-top: 26px; display: flex; flex-wrap: wrap; gap: 12px 14px; align-items: center; }
.strip-black { background: var(--ink); color: var(--paper); font-family: var(--mono); font-size: 11.5px;
  letter-spacing: .18em; padding: 8px 15px; }
.strip-red { background: var(--red); color: #fff; font-family: var(--mono); font-size: 11.5px;
  letter-spacing: .18em; padding: 8px 15px; rotate: -1.2deg; }
.js .stamp-in { opacity: 0; scale: 1.5; }
.js .loaded .stamp-in { opacity: 1; scale: 1; transition: opacity .3s, scale .45s var(--spring); }
.js .loaded .stamp-in:nth-child(1) { transition-delay: .9s; }
.js .loaded .stamp-in:nth-child(2) { transition-delay: 1.05s; }
.js .loaded .stamp-in:nth-child(3) { transition-delay: 1.25s; }

/* ── sections ── */
section { position: relative; padding: 60px 0 0; z-index: 2; }
.sec-h { display: flex; align-items: baseline; gap: 16px; margin-bottom: 24px; }
.sec-h h2 { font-family: var(--black); font-size: clamp(19px, 3.4vw, 26px); letter-spacing: .02em; text-transform: uppercase; }
.sec-h .rule { flex: 1; height: 3px; background: var(--ink); transform-origin: left; }
.js .sec-h .rule { transform: scaleX(0); transition: transform .9s var(--spring) .2s; }
.js .sec-h.in .rule { transform: scaleX(1); }
.sec-h .no { font-family: var(--mono); font-size: 12px; color: var(--red); }

/* reveal primitives */
.js .rise { opacity: 0; transform: translateY(18px); }
.js .rise.in { opacity: 1; transform: none; transition: opacity .5s, transform .6s var(--spring); }
.js .pop { opacity: 0; transform: translateY(22px) scale(.95) rotate(.6deg); }
.js .pop.in { opacity: 1; transform: none; transition: opacity .45s, transform .6s var(--spring); }

/* diagrams are ALWAYS visible (never depend on a scroll-reveal that can misfire).
   NOTE: don't set stroke-dasharray here — it would out-specify the edge-flow. */
.js .draw path[pathLength] { stroke-dashoffset: 0; }

/* pulsing nodes (loss-curve points + knowledge-graph centres) */
.duo .df { transform-box: fill-box; transform-origin: center; animation: nodePulse 2.6s ease-in-out infinite; }
.duo svg .df:nth-of-type(2) { animation-delay: .5s; }
.duo svg .df:nth-of-type(3) { animation-delay: 1s; }
.duo svg .df:nth-of-type(4) { animation-delay: 1.5s; }
.duo svg .df:nth-of-type(5) { animation-delay: .8s; }
@keyframes nodePulse { 0%,100% { transform: scale(1); opacity: 1; } 50% { transform: scale(2); opacity: .6; } }

/* knowledge-graph edges: data flowing along the relationships */
.duo .edge { stroke-dasharray: 5 6; animation: flow 1s linear infinite; }
@keyframes flow { to { stroke-dashoffset: -22; } }

/* cyclone swirls around its eye (view-box coords → correct pivot) */
.duo .spiral { transform-box: view-box; transform-origin: 126px 76px; animation: spin 14s linear infinite; }

/* a red dot rolls down the loss curve, forever */
.duo .tracer { fill: var(--red); offset-path: path('M40 110c20-40 60-62 92-54s48 40 42 66');
  offset-rotate: 0deg; animation: trace 3.4s ease-in-out infinite; }
@keyframes trace { 0% { offset-distance: 0%; } 62%,100% { offset-distance: 100%; } }

/* ── study of systems ── */
.duo-grid { display: grid; grid-template-columns: 1fr; gap: 24px; }
@media (min-width: 720px) { .duo-grid { grid-template-columns: 1fr 1fr 1fr; } }
.duo svg { width: 100%; height: auto; display: block; }
.duo .d1 { stroke: #B03A64; stroke-width: 1.8; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.duo .d2 { stroke: #5C4FA3; stroke-width: 1.8; fill: none; stroke-linecap: round; }
.duo .df { fill: #C64D6E; stroke: none; }
.duo .dg { fill: url(#grad1); stroke: none; }
.duo .klbl { font-family: var(--hand); font-size: 15px; fill: #B03A64; }
.duo .klbl.b { fill: #5C4FA3; }
.duo figcaption { margin-top: 9px; font-size: 12.5px; color: #4A4A50; line-height: 1.6; }
.duo figcaption b { font-family: var(--mono); font-size: 10.5px; color: var(--red); letter-spacing: .08em; }

/* ── form derivation ── */
.derive { display: grid; grid-template-columns: repeat(2, 1fr); gap: 28px 18px; }
@media (min-width: 720px) { .derive { grid-template-columns: repeat(3, 1fr); } }
.dv { text-align: center; }
.dv svg { width: min(150px, 72%); height: auto; transition: transform .35s var(--spring); }
.dv:hover svg { transform: translateY(-7px) rotate(-2deg); }
.dv .iso-t { fill: #E4574A; stroke: #8E241C; stroke-width: 1.2; }
.dv .iso-l { fill: #B93327; stroke: #8E241C; stroke-width: 1.2; }
.dv .iso-r { fill: #D8483B; stroke: #8E241C; stroke-width: 1.2; }
.dv .cutout { fill: var(--paper); stroke: #8E241C; stroke-width: 1.2; }
.js .dv.in .iso-t { animation: dropTop .55s var(--spring) both .15s; }
@keyframes dropTop { from { transform: translateY(-14px); opacity: 0; } to { transform: none; opacity: 1; } }
.dv p { font-family: var(--mono); font-size: 11px; letter-spacing: .04em; color: #4A4A50; margin-top: 8px; line-height: 1.7; }
.dv p b { color: var(--ink); font-weight: 400; display: block; font-size: 12px; }
.dv p .m { color: var(--red); }
/* gentle idle float, staggered */
.dv:nth-child(odd) svg { animation: isoFloat 5s ease-in-out infinite; }
.dv:nth-child(even) svg { animation: isoFloat 5s ease-in-out 2.5s infinite; }
@keyframes isoFloat { 50% { translate: 0 -4px; } }

/* ── axonometry ── */
.axo-wrap { display: grid; grid-template-columns: 1fr; gap: 22px; align-items: center; }
@media (min-width: 760px) { .axo-wrap { grid-template-columns: 1.1fr .9fr; } }
.axo svg { width: min(420px, 100%); margin-inline: auto; display: block; overflow: visible; }
.axo .ptop { stroke-width: 1.4; stroke-linejoin: round; }
.axo .pside { stroke: none; }
.axo .ptop.dark { fill: #3F3F45; stroke: #17171B; }
.axo .pside.dark { fill: #33333A; } .axo .pside.dark2 { fill: #26262B; }
.axo .ptop.red { fill: #E4574A; stroke: #8E241C; }
.axo .pside.red { fill: #C43C30; } .axo .pside.red2 { fill: #A32E24; }
.axo .ptop.alt { fill: #EFB4AC; stroke: #C77A6E; }
.axo .pside.alt { fill: #E19A8F; } .axo .pside.alt2 { fill: #CE8175; }
.axo .wire { stroke: #8B8B90; stroke-width: 1; fill: none; stroke-dasharray: 3 4; }
.axo .lead { stroke: var(--ink); stroke-width: 1.1; fill: none; }
.axo text { font-family: var(--mono); font-size: 11px; fill: var(--ink); letter-spacing: .06em; }
/* collapsed → exploded on scroll into view; then a slow breathing */
.js .pl { transition: transform 1s var(--spring); }
.js .pl1 { transform: translateY(120px); }
.js .pl2 { transform: translateY(60px); }
.js .pl4 { transform: translateY(-60px); }
.js .axo.in .pl1, .js .axo.in .pl2, .js .axo.in .pl4 { transform: none; }
.js .axo.in .pl1 { transition-delay: .1s; } .js .axo.in .pl2 { transition-delay: .2s; }
.js .axo.in .pl4 { transition-delay: .3s; }
.axo.in .pl1 { animation: breathe 6s ease-in-out 1.4s infinite; }
.axo.in .pl4 { animation: breathe 6s ease-in-out 2.6s infinite; }
@keyframes breathe { 50% { transform: translateY(-5px); } }
.axo-notes { font-size: 13.5px; color: #4A4A50; max-width: 44ch; }
.axo-notes ul { list-style: none; padding: 0; margin-top: 10px; }
.axo-notes li { font-family: var(--mono); font-size: 11.5px; padding: 7px 0;
  border-bottom: 1px solid rgba(23,23,27,.18); display: flex; justify-content: space-between; gap: 12px; }
.axo-notes li span:last-child { color: var(--grey); }

/* ── halftone band: dots slide forever ── */
.htband { height: 74px; margin-top: 66px;
  background-image: radial-gradient(circle, rgba(225,61,124,.5) 0 1.6px, transparent 2.2px),
                    radial-gradient(circle, rgba(216,53,42,.4) 0 1.2px, transparent 1.9px);
  background-size: 9px 9px, 15px 15px;
  animation: dots 14s linear infinite;
  -webkit-mask-image: linear-gradient(180deg, transparent, black 30%, black 72%, transparent);
          mask-image: linear-gradient(180deg, transparent, black 30%, black 72%, transparent); }
@keyframes dots { to { background-position: 90px 0, -90px 6px; } }

/* ── the record ── */
.dark-band { background: var(--ink); padding: 56px 0 66px; position: relative; z-index: 2; }
.resume-card { background: #F3EEDF; border-radius: 14px; padding: 26px 24px 26px; max-width: 680px;
  margin-inline: auto; position: relative; rotate: -.8deg;
  box-shadow: 10px 12px 0 rgba(216,53,42,.85); }
.js .pop-card { opacity: 0; transform: translateY(40px) rotate(2deg); }
.js .pop-card.in { opacity: 1; transform: none; transition: opacity .5s, transform .7s var(--spring); }
.resume-card h2 { font-family: var(--black); color: var(--red); font-size: clamp(26px, 6vw, 40px);
  text-transform: uppercase; text-shadow: 2px 2px 0 #F3EEDF, 4px 4px 0 rgba(23,23,27,.8);
  margin-bottom: 16px; rotate: -1deg; }
.rc-row { display: grid; grid-template-columns: 82px 1fr; gap: 14px; padding: 11px 0;
  border-top: 1.6px solid rgba(23,23,27,.65); }
.rc-row .yr { font-family: var(--mono); font-size: 11px; color: var(--red); padding-top: 4px; }
.rc-row b { font-family: var(--black); font-size: 14.5px; text-transform: uppercase; letter-spacing: .02em; }
.rc-row p { font-size: 13px; color: #45413A; line-height: 1.65; margin-top: 3px; }
.rc-foot { font-family: var(--mono); font-size: 10.5px; color: #7A7468; letter-spacing: .04em;
  border-top: 1.6px solid rgba(23,23,27,.65); padding-top: 12px; margin-top: 2px; line-height: 1.8; }

.badge-stop { position: absolute; right: -16px; top: -28px; width: 106px; rotate: 9deg; }
.badge-burst { position: absolute; left: -20px; bottom: -22px; width: 92px; rotate: -8deg; }
.badge-txt { font-family: var(--black); font-size: 17px; fill: #fff; }
.badge-txt.sm { font-size: 15px; }
.js .swing { opacity: 0; scale: .2; }
.js .swing.in { opacity: 1; scale: 1; transition: opacity .3s .3s, scale .6s var(--spring) .3s; }
.js .swing.d2.in { transition-delay: .55s; }
.swing.in { animation: sway 4.2s ease-in-out 1.2s infinite; }
@keyframes sway { 50% { rotate: 4deg; } }
.badge-stop.swing.in { animation: sway2 4.2s ease-in-out 1.2s infinite; }
@keyframes sway2 { 0%,100% { rotate: 9deg; } 50% { rotate: 13deg; } }

/* ── blueprint exit ── */
.blueprint { border: 2px solid var(--blue); margin-top: 66px; padding: 24px 22px 30px; position: relative;
  background:
    linear-gradient(rgba(44,79,163,.06) 1px, transparent 1px) 0 0 / 100% 26px,
    linear-gradient(90deg, rgba(44,79,163,.05) 1px, transparent 1px) 0 0 / 26px 100%;
  color: var(--blue); }
.blueprint::before { content: 'DWG № 07 — EXIT PLAN'; position: absolute; top: -11px; left: 18px;
  background: var(--paper); padding: 0 10px; font-family: var(--mono); font-size: 10.5px; letter-spacing: .18em; }
.bp-grid { display: grid; grid-template-columns: 1fr; gap: 20px; }
@media (min-width: 720px) { .bp-grid { grid-template-columns: 1fr 1fr; align-items: center; } }
.blueprint svg { width: min(300px, 92%); display: block; margin-inline: auto; overflow: visible; }
.blueprint .bp { stroke: var(--blue); stroke-width: 1.5; fill: none; stroke-linecap: round; }
.blueprint .bpd { stroke-dasharray: 4 5; }
.ants { animation: march 1.6s linear infinite; }
@keyframes march { to { stroke-dashoffset: -18; } }
.blueprint text { font-family: var(--mono); font-size: 10px; fill: var(--blue); letter-spacing: .06em; }
.bp-links { display: grid; gap: 10px; margin: 14px 0 12px; }
.bp-links a { font-family: var(--black); font-size: clamp(14px, 2.8vw, 19px); color: var(--blue);
  text-decoration: none; width: fit-content; position: relative; }
.bp-links a::after { content: ''; position: absolute; left: 0; bottom: -3px; width: 100%; height: 2.5px;
  background: var(--blue); transform: scaleX(.25); transform-origin: left; transition: transform .35s var(--spring); }
.bp-links a:hover::after { transform: scaleX(1); }
.bp-sub { font-family: var(--mono); font-size: 11px; color: rgba(44,79,163,.75); letter-spacing: .06em; }
.bp-note { position: absolute; right: 18px; bottom: 10px; color: var(--blue); }

footer { font-family: var(--mono); font-size: 10px; letter-spacing: .16em; color: var(--grey);
  text-transform: uppercase; text-align: center; padding: 44px 12px 38px; line-height: 2; }

/* ── reduced motion: everything static & visible ── */
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  .js .rise, .js .pop, .js .pop-card, .js .swing, .js .stamp-in { opacity: 1; transform: none; scale: 1; transition: none; }
  .js .et-line > span { transform: none; animation: none; }
  .js .underline { transform: scaleX(1); transition: none; }
  .js .draw path[pathLength], .js .draw:not(.in) path[pathLength] { stroke-dasharray: none; stroke-dashoffset: 0; animation: none; }
  .js .pl, .js .pl1, .js .pl2, .js .pl4 { transform: none; transition: none; animation: none; }
  .js .sec-h .rule { transform: none; transition: none; }
  .gear, .arm-swing, .bob, .bot-eyes, .antenna, .drift, .pupil, .pulse, .shimmer,
  .htband, .ants, .swing.in, .badge-stop.swing.in, .dv svg, .axo.in .pl1, .axo.in .pl4,
  .decor .d-spin, .d-x, .d-dot, .duo .df, .duo .edge, .duo .spiral, .duo .tracer { animation: none; }
  .duo .edge { stroke-dasharray: none; }
}
