/* Scroll story. The stage is pinned while the page scrolls through
   --scenes screens: 0 hero (chaos), 1 logo, 2-8 feature chapters.
   scroll.js sets data-scene on #stage and the chapter on #story. */

.progress { position: fixed; z-index: 20; top: 0; left: 0; right: 0; height: 3px; background: transparent; }
.progress i { display: block; height: 100%; background: var(--green-2); transform-origin: 0 50%; transform: scaleX(var(--p, 0)); }

.scroller { position: relative; height: calc((var(--scenes) + .5) * 100vh); }
.seg { position: absolute; left: 0; width: 1px; height: 1px; top: calc(var(--i) * 100vh); }

.stage { position: sticky; top: 0; height: 100vh; height: 100svh; overflow: hidden; display: grid; align-items: center; }
.stage-inner {
  width: min(1160px, calc(100% - 48px)); margin-inline: auto;
  display: grid; grid-template-columns: minmax(0, 4.3fr) minmax(0, 6.7fr); align-items: center; gap: clamp(32px, 4.5vw, 64px);
}

/* Left column: one pane per scene, stacked in the same cell */
.copy { display: grid; }
.pane { grid-area: 1 / 1; align-self: center; visibility: hidden; pointer-events: none; }
.pane > * { opacity: 0; transform: translateY(22px); transition: opacity .45s ease, transform .6s cubic-bezier(.2,.8,.2,1); }
.pane.on { visibility: visible; pointer-events: auto; }
.pane.on > * { opacity: 1; transform: none; }
.pane.on > :nth-child(2) { transition-delay: .07s; }
.pane.on > :nth-child(3) { transition-delay: .14s; }
.pane.on > :nth-child(4) { transition-delay: .21s; }
.pane.on > :nth-child(5) { transition-delay: .28s; }
.pane.leaving { visibility: visible; }
.pane.leaving > * { opacity: 0; transform: translateY(-18px); transition-duration: .3s; }

.pane .eyebrow { margin-bottom: 16px; }
.pane h2 { margin: 0 0 16px; font-size: clamp(2.2rem, 4.2vw, 3.5rem); line-height: 1.06; letter-spacing: -.03em; font-weight: 800; color: var(--green-deep); }
.pane h2 em { font-style: normal; color: var(--green); }
.pane-text { margin: 0 0 22px; max-width: 460px; font-size: 1.1rem; line-height: 1.6; color: var(--muted); }
.pane-chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.pane-chips li { padding: 6px 13px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); font-size: .9rem; font-weight: 700; color: var(--ink-2); }
.pane-hero h1 { margin: 0 0 clamp(24px, 3.5vh, 40px); line-height: 0; }

/* Scroll cue on the hero */
.cue { position: absolute; left: 50%; bottom: 22px; margin: 0; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: .85rem; font-weight: 700; transition: opacity .4s ease; white-space: nowrap; }
.stage:not([data-scene="0"]) .cue { opacity: 0; }
.mouse { width: 20px; height: 30px; border: 2px solid currentColor; border-radius: 12px; display: grid; justify-items: center; padding-top: 5px; }
.mouse i { width: 3px; height: 6px; border-radius: 2px; background: currentColor; animation: wheel 1.6s ease-in-out infinite; }
@keyframes wheel { 0% { transform: translateY(0); opacity: 1; } 70% { transform: translateY(8px); opacity: 0; } 100% { opacity: 0; } }

/* Laptop screen: fixed top bar so the views below can sit under it */
.app-top { height: 3.3em; }
.nav.on { background: var(--mint-soft); color: var(--green); font-weight: 800; }
.nav.on svg { color: var(--green); }
.sub:not(.on) { background: none; color: var(--ink-2); font-weight: 600; }

/* Chapter views over the list + chat area */
.view {
  position: absolute; z-index: 1; left: 17%; right: 0; top: 3.3em; bottom: 0;
  background: #fff; border-left: 1px solid var(--line);
  opacity: 0; transform: translateY(1.4em); transition: opacity .4s ease, transform .55s cubic-bezier(.2,.8,.2,1);
  pointer-events: none; overflow: hidden;
}
.view.on { opacity: 1; transform: none; }
.v-title { display: flex; align-items: center; justify-content: space-between; gap: 1em; padding: .9em 1.1em; border-bottom: 1px solid var(--line); }
.v-title strong { font-size: 1.15em; }
.steps, .tabs2 { display: flex; gap: .4em; font-size: .8em; font-weight: 700; }
.steps i, .tabs2 i { font-style: normal; padding: .25em .7em; border-radius: 99px; border: 1px solid var(--line); color: var(--muted); }
.steps .done { background: var(--mint-soft); border-color: #b9e5cb; color: var(--green); }
.steps .cur, .tabs2 .cur { background: var(--green); border-color: var(--green); color: #fff; }

/* Multi-agen chapter */
.who { display: none; place-items: center; width: 1.9em; height: 1.9em; border-radius: 50%; background: var(--mint); color: var(--green); font-style: normal; font-weight: 800; font-size: .85em; }
.who.d { background: #e1f0fb; color: #1a77b8; }
.who.s { background: #fdeee3; color: #a4521b; }
.who.q { background: #fff6d8; color: #8a6500; }
.btn-assign { margin-left: auto; padding: .35em .8em; border-radius: .5em; border: 1px solid var(--line); font-size: .8em; font-weight: 700; color: var(--ink-2); background: #fff; }
.btn-assign + .btn-done { margin-left: .4em; }
.assign-pop {
  position: absolute; z-index: 2; right: 6.4em; top: 3.4em; display: grid; gap: .15em; min-width: 11em; padding: .55em;
  background: #fff; border: 1px solid var(--line); border-radius: .7em; box-shadow: 0 1.2em 2.4em -1.2em #1d2e2655;
  font-size: .85em; opacity: 0; transform: translateY(-.5em) scale(.97); transform-origin: top right; transition: opacity .3s ease, transform .35s ease;
}
.assign-pop strong { padding: .15em .5em .35em; font-size: .78em; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.assign-pop span { display: flex; align-items: center; gap: .5em; padding: .3em .5em; border-radius: .45em; font-weight: 700; }
.assign-pop span:nth-of-type(1) { background: var(--mint-soft); color: var(--green); }
.assign-pop small { margin-left: auto; color: var(--muted); font-weight: 600; }
.assign-pop i { width: .55em; height: .55em; border-radius: 50%; background: #c3cdc8; }
.assign-pop i.dot-on { background: var(--green-2); }
.chat { position: relative; }
.msgs .note svg { width: 1em; height: 1em; vertical-align: -.12em; }
.story[data-ch="agen"] .who { display: grid; }
.story[data-ch="agen"] .row time { flex-direction: column; }
.story[data-ch="agen"] .assign-pop { opacity: 1; transform: none; transition-delay: .45s; }
.story[data-ch="agen"] .btn-assign { background: var(--mint-soft); border-color: #b9e5cb; color: var(--green); }
.story[data-ch="agen"] .msgs .note { background: var(--green); color: #fff; animation: nudge 1.2s ease .4s 2; }
@keyframes nudge { 50% { transform: scale(1.08); } }

/* Inbox chapter: channel badges pop in turn */
.story[data-ch="inbox"] .list .ch { animation: pop .6s cubic-bezier(.3,1.6,.5,1) both; }
.story[data-ch="inbox"] .list .row:nth-of-type(2) .ch { animation-delay: .5s; }
.story[data-ch="inbox"] .list .row:nth-of-type(3) .ch { animation-delay: .65s; }
.story[data-ch="inbox"] .list .row:nth-of-type(4) .ch { animation-delay: .8s; }
.story[data-ch="inbox"] .list .row:nth-of-type(5) .ch { animation-delay: .95s; }
.story[data-ch="inbox"] .list .row:nth-of-type(6) .ch { animation-delay: 1.1s; }
@keyframes pop { 0% { transform: scale(.4); } 60% { transform: scale(1.25); } 100% { transform: scale(1); } }
.story[data-ch="inbox"] .health i { animation: blink 1.4s ease-in-out infinite; }
@keyframes blink { 50% { opacity: .35; } }

/* AI chapter */
.ai-msg { display: none; }
.ai-label { display: flex; align-items: center; gap: .3em; margin-bottom: .25em; font-size: .78em; font-weight: 800; color: var(--green); }
.ai-label svg { width: 1.1em; height: 1.1em; }
.story[data-ch="ai"] .ai-msg { display: block; animation: rise-in .5s ease .3s both; }
.story[data-ch="ai"] .ai-suggest { animation: glow 1.6s ease-in-out .9s 2; }
@keyframes rise-in { from { opacity: 0; transform: translateY(.8em); } to { opacity: 1; transform: none; } }
@keyframes glow { 50% { box-shadow: inset .25em 0 0 var(--green-2), 0 0 0 .35em #16a34a33; } }

/* Grup & channel view */
.view-grup { display: grid; grid-template-columns: 37% 1fr; }
.g-list { padding: .8em .6em; border-right: 1px solid var(--line); min-width: 0; }
.g-list .chips .c-on { background: var(--green); border-color: var(--green); color: #fff; }
.g-list .chips .m { color: #1a77b8; border-color: #bcdcf3; }
.g-list .chips b { font-weight: 800; }
.g-list .row time b { padding: 0 .45em; border-radius: 99px; background: var(--green); color: #fff; }
.g-thread { display: grid; grid-template-rows: auto 1fr auto; grid-template-columns: minmax(0, 1fr); background: #f3f8f5; min-width: 0; }
.g-thread .msgs p b { display: block; font-size: .85em; margin-bottom: .1em; }
.who-a { color: #a4521b; }
.who-b { color: #7a4fc0; }
.who-me { color: var(--green); }
.g-thread .at { color: #1a77b8; font-weight: 800; margin-right: .25em; }
.story[data-ch="grup"] .g-thread .mention { box-shadow: 0 0 0 .2em #2a9fe055; animation: nudge 1.2s ease .9s 2; }
.g-thread .composer { margin: .7em; }

/* Broadcast view */
.bc-grid { display: grid; grid-template-columns: 1.15fr 1fr; gap: 1em; padding: 1em 1.1em; }
.card { border: 1px solid var(--line); border-radius: .8em; padding: .9em 1em; }
.card dl { margin: 0 0 .9em; display: grid; grid-template-columns: auto 1fr; gap: .55em 1em; align-items: center; font-size: .9em; }
.card dt { color: var(--muted); font-weight: 700; }
.card dd { margin: 0; display: flex; align-items: center; gap: .4em; font-weight: 700; }
.card dd em { font-style: normal; color: var(--green); }
.card dd .ch { width: 1.7em; height: 1.7em; }
.card dd svg { width: 1.1em; height: 1.1em; color: var(--green); }
.bc-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5em; margin-bottom: .7em; }
.bc-stats span { display: grid; padding: .5em .6em; border-radius: .6em; background: #f5f8f6; font-size: .78em; color: var(--muted); font-weight: 700; }
.bc-stats b { font-size: 1.6em; color: var(--ink); font-variant-numeric: tabular-nums; }
.bc-stats span:last-child b { color: #d23c2b; }
.bar { height: .55em; border-radius: 99px; background: #e6eee9; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--green-2); border-radius: inherit; transition: width 1.4s cubic-bezier(.2,.8,.2,1) .3s; }
.view-bc.on .bar i { width: 90%; }
.bc-preview { display: flex; flex-direction: column; gap: .55em; padding: .9em; border-radius: .8em; background: #f3f8f5; }
.bc-preview p { margin: 0; max-width: 92%; padding: .55em .8em; border-radius: .9em; font-size: .86em; }
.bc-preview .out { align-self: flex-end; background: #d7f4e1; border-bottom-right-radius: .25em; }
.bc-preview .in { background: #fff; border-bottom-left-radius: .25em; font-weight: 800; }
.bc-preview .note { align-self: center; max-width: none; background: #fde3df; color: #b4382d; font-size: .74em; font-weight: 700; border-radius: 99px; }
.view-bc .bc-preview p { opacity: 0; transform: translateY(.6em); transition: opacity .4s ease, transform .4s ease; }
.view-bc.on .bc-preview p { opacity: 1; transform: none; }
.view-bc.on .bc-preview p:nth-child(2) { transition-delay: .9s; }
.view-bc.on .bc-preview p:nth-child(3) { transition-delay: 1.4s; }

/* Laporan view */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: .7em; padding: 1em 1.1em .4em; }
.kpis div { display: grid; padding: .7em .8em; border: 1px solid var(--line); border-radius: .8em; }
.kpis small { color: var(--muted); font-weight: 700; font-size: .8em; }
.kpis b { font-size: 1.7em; font-variant-numeric: tabular-nums; }
.kpis .of { font-size: .55em; color: var(--muted); }
.kpis em { font-style: normal; font-size: .78em; font-weight: 800; color: var(--green); }
.rep-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: .7em; padding: .4em 1.1em 1em; }
.chart, .table { border: 1px solid var(--line); border-radius: .8em; padding: .7em .9em; }
.chart small, .table small { display: block; margin-bottom: .5em; color: var(--muted); font-weight: 700; font-size: .8em; }
.bars { height: 9em; display: flex; align-items: flex-end; gap: .55em; }
.bars i { flex: 1; height: 4%; border-radius: .35em .35em .1em .1em; background: var(--mint); transition: height .9s cubic-bezier(.2,.8,.2,1); }
.bars i:nth-child(6) { background: var(--green-2); }
.view-rep.on .bars i { height: var(--h); }
.view-rep.on .bars i:nth-child(2) { transition-delay: .06s; }
.view-rep.on .bars i:nth-child(3) { transition-delay: .12s; }
.view-rep.on .bars i:nth-child(4) { transition-delay: .18s; }
.view-rep.on .bars i:nth-child(5) { transition-delay: .24s; }
.view-rep.on .bars i:nth-child(6) { transition-delay: .3s; }
.view-rep.on .bars i:nth-child(7) { transition-delay: .36s; }
.days { display: flex; gap: .55em; margin-top: .35em; font-size: .7em; color: var(--muted); }
.days span { flex: 1; text-align: center; }
.table p { margin: 0; display: grid; grid-template-columns: auto 1fr auto auto auto; align-items: center; gap: .7em; padding: .45em 0; border-top: 1px solid var(--line); font-size: .88em; font-weight: 700; }
.table p .who { display: grid; }
.table em { font-style: normal; color: var(--muted); }
.table p i { font-style: normal; color: var(--green); }

/* Server view */
.conns { display: grid; grid-template-columns: 1fr 1fr; gap: .7em; padding: 1em 1.1em .6em; }
.conns div { display: flex; align-items: center; gap: .7em; padding: .7em .8em; border: 1px solid var(--line); border-radius: .8em; opacity: 0; transform: translateY(.6em); transition: opacity .4s ease, transform .4s ease; }
.view-srv.on .conns div { opacity: 1; transform: none; }
.view-srv.on .conns div:nth-child(2) { transition-delay: .12s; }
.view-srv.on .conns div:nth-child(3) { transition-delay: .24s; }
.view-srv.on .conns div:nth-child(4) { transition-delay: .36s; }
.conns p { margin: 0; flex: 1; min-width: 0; }
.conns strong, .conns small { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conns small { color: var(--muted); font-size: .8em; }
.conns em { font-style: normal; font-size: .78em; font-weight: 800; color: var(--green); padding: .15em .6em; border-radius: 99px; background: var(--mint-soft); }
.ch.meta { background: #1f9e50; }
.srv-box { display: flex; align-items: center; gap: .9em; margin: .4em 1.1em .8em; padding: .9em 1em; border-radius: .8em; background: var(--green-deep); color: #fff; }
.srv-box .lock { display: grid; place-items: center; flex: none; width: 2.6em; height: 2.6em; border-radius: .7em; background: #ffffff1f; }
.srv-box .lock svg { width: 1.4em; height: 1.4em; }
.view-srv.on .srv-box .lock { animation: nudge 1.2s ease .7s 2; }
.srv-box p { margin: 0; }
.srv-box small { display: block; color: #ffffffb3; font-size: .82em; }
.os-row { display: flex; justify-content: center; gap: 1.6em; color: var(--ink-2); font-weight: 700; font-size: .9em; }
.os-row span { display: flex; align-items: center; gap: .4em; }
.os-row svg { width: 1.2em; height: 1.2em; }

/* Chapter tabs beside the laptop, like a book's tabs */
.tabs-side {
  position: absolute; z-index: 5; right: 0; top: 14cqw; transform: translateX(calc(100% + 10px));
  display: flex; flex-direction: column; gap: 6px;
  opacity: 0; pointer-events: none; transition: opacity .4s ease;
}
.is-calm .tabs-side { opacity: 1; pointer-events: auto; }
.tabs-side button {
  font: inherit; font-size: .78rem; font-weight: 800; text-align: left; white-space: nowrap; cursor: pointer;
  padding: 7px 12px; border-radius: 0 10px 10px 0; border: 1px solid var(--line); border-left: 3px solid transparent;
  background: var(--mint-soft); color: var(--muted); transition: background .25s ease, color .25s ease, transform .25s ease, border-color .25s ease;
}
.tabs-side button:hover { color: var(--green); transform: translateX(3px); }
.tabs-side button.on { background: var(--paper); color: var(--green); border-left-color: var(--green-2); transform: translateX(4px); }

.cap-text { font-weight: inherit; transition: opacity .25s ease; }
.cap-text.swap { opacity: 0; }

@media (max-width: 1320px) {
  .tabs-side { position: static; transform: none; flex-direction: row; flex-wrap: wrap; justify-content: center; margin-top: 14px; gap: 6px; }
  .tabs-side button { border-radius: 99px; border-left-width: 1px; padding: 5px 11px; }
  .tabs-side button.on { transform: none; border-color: var(--green-2); }
}

@media (prefers-reduced-motion: reduce) {
  .pane > *, .view, .bars i, .bar i, .conns div, .bc-preview p { transition: none !important; }
  .mouse i, .story * { animation: none !important; }
}

@media (max-width: 980px) {
  .stage-inner { display: flex; flex-direction: column; align-items: center; gap: 18px; width: calc(100% - 32px); text-align: center; }
  .copy { width: 100%; }
  .pane { justify-self: center; }
  .pane-text { margin-inline: auto; font-size: 1rem; margin-bottom: 14px; }
  .pane-chips { justify-content: center; }
  .pane h2 { font-size: clamp(1.8rem, 7vw, 2.4rem); margin-bottom: 10px; }
  .pane-hero h1 { margin-bottom: 16px; }
  .pane-hero .lockup { width: 200px; }
  .pane-hero .lead { margin: 0 auto 16px; font-size: 1.15rem; }
  .pane-hero .platforms { justify-content: center; margin-bottom: 18px; }
  .pane-hero .actions { justify-content: center; }
  .devices { width: min(640px, 100%); margin: 0; }
  .cue { bottom: 12px; }
}
@media (max-width: 600px) {
  .pane-hero .label, .pane-hero .platforms { display: none; }
  .pane-chips li { font-size: .8rem; padding: 4px 10px; }
  .tabs-side button { font-size: .7rem; padding: 4px 9px; }
}

/* Chapters fill in faster than the autoplay hero did */
.is-calm .chips { transition-delay: .2s; }
.is-calm .row:nth-of-type(2) { transition-delay: .25s; }
.is-calm .row:nth-of-type(3) { transition-delay: .3s; }
.is-calm .row:nth-of-type(4) { transition-delay: .35s; }
.is-calm .row:nth-of-type(5) { transition-delay: .4s; }
.is-calm .row:nth-of-type(6) { transition-delay: .45s; }
.is-calm .chat-head { transition-delay: .3s; }
.is-calm .msgs p:nth-child(1) { transition-delay: .4s; }
.is-calm .msgs p:nth-child(2) { transition-delay: .55s; }
.is-calm .msgs p:nth-child(3) { transition-delay: .7s; }
.is-calm .msgs p:nth-child(4) { transition-delay: .85s; }
.is-calm .ai-suggest { transition-delay: 1s; }

/* ---- Problem first, then the logo, then the logo becomes the navbar ---- */
.topbar {
  position: fixed; z-index: 15; inset: 0 0 auto 0; top: 0; right: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px max(24px, calc((100% - 1160px) / 2));
  background: transparent; border-bottom: 1px solid transparent;
  transition: background .35s ease, border-color .35s ease;
}
.brand { display: block; width: 150px; transform-origin: 50% 50%; transition: transform .9s cubic-bezier(.65,0,.25,1), opacity .45s ease; }
.brand img { display: block; width: 100%; height: auto; }
html[data-scene="0"] .brand { opacity: 0; pointer-events: none; transform: translate(var(--cx, 0), var(--cy, 0)) scale(calc(var(--cs, 1) * .6)); }
html[data-scene="1"] .brand { transform: translate(var(--cx, 0), var(--cy, 0)) scale(var(--cs, 1)); transition-delay: .35s; }
html[data-scene="1"] .brand img { animation: beat 1.2s ease-in-out 1.1s; }

.slogan {
  position: fixed; z-index: 14; left: 50%; top: var(--sy, 60%); margin: 0;
  transform: translate(-50%, 10px); opacity: 0; pointer-events: none;
  font-size: clamp(1.05rem, 1.6vw, 1.35rem); font-weight: 800; color: var(--muted); white-space: nowrap;
  transition: opacity .4s ease, transform .5s ease;
}
html[data-scene="1"] .slogan { opacity: 1; transform: translate(-50%, 0); transition-delay: .8s; }

/* Hero and logo scenes: one centred column, no text on the left */
.copy { min-width: 0; }
.devices { justify-self: center; width: 100%; transform-origin: 50% 50%; transition: transform 1.1s cubic-bezier(.45, 0, .2, 1); will-change: transform; }
html[data-scene="0"] .copy, html[data-scene="1"] .copy { opacity: 0; visibility: hidden; }
/* problem and logo: the animation is slid to the middle and enlarged (transform only, no layout change) */
html[data-scene="0"] .devices, html[data-scene="1"] .devices { transform: translateX(var(--fx, 0)) scale(var(--fk, 1)); }
.copy { transition: opacity .4s ease; }
.captions { display: flex; justify-content: center; }
.cap { left: 50%; transform: translate(-50%, 6px); }
.is-chaos .cap-chaos, .is-calm .cap-calm { transform: translateX(-50%); }

@media (max-width: 980px) {
  html[data-scene="0"] .copy, html[data-scene="1"] .copy { display: none; }
  .topbar { padding: 10px 16px; }
  .brand { width: 120px; }
}
@media (prefers-reduced-motion: reduce) {
  .brand, .slogan, .stage-inner, .devices, .copy { transition: none !important; }
}
@media (max-width: 980px) {
  /* keep chapter text clear of the fixed navbar */
  html:not([data-scene="0"]):not([data-scene="1"]) .stage { padding-top: 52px; }
}

/* ---- Hero escalation, driven by --heat (0..1 = how far into the hero) ---- */
.stage { --heat: 0; --haze: 0; --fire: 0; background-color: color-mix(in srgb, #fff0e6 calc(var(--haze) * 100%), var(--bg)); transition: background-color .5s ease; }
.stage-inner { position: relative; z-index: 2; }

/* items show up one by one instead of all at once */
.is-chaos .ci { opacity: 0; transform: translate(0, 0) scale(.6) rotate(var(--r)); transition-delay: 0s; }
.is-chaos .ci.in { opacity: 1; transform: scale(1) rotate(var(--r)); }
.is-chaos .win:not(.in) { pointer-events: none; }
.agent .float { animation: none; }
.is-stress .agent .float { animation: jitter-hard .45s ease-in-out infinite; }
.face { background: color-mix(in srgb, #ff9b85 calc(var(--heat) * 100%), var(--mint)); color: color-mix(in srgb, #a3261a calc(var(--heat) * 100%), var(--green)); }
.cap-chaos { color: var(--ink-2); }
.cap-chaos i { background: var(--green-2); }
.cap-chaos.hot { color: #b4382d; }
.cap-chaos.hot i { background: #e5533f; animation: blink .7s ease-in-out infinite; }
.cap-chaos-text { font-weight: inherit; }

/* the whole stage trembles when it is about to blow */
.is-critical .chaos { animation: quake .18s linear infinite; }
@keyframes quake {
  0% { transform: translate(0, 0); } 25% { transform: translate(-.5cqw, .3cqw); }
  50% { transform: translate(.4cqw, -.4cqw); } 75% { transform: translate(-.3cqw, -.2cqw); } 100% { transform: translate(.3cqw, .4cqw); }
}
.is-hot .chaos { filter: url(#heat); }

/* notifications that keep coming */
.toasts { position: absolute; inset: 7.8cqw 0 0 0; z-index: 4; pointer-events: none; }
.toast {
  position: absolute; display: flex; align-items: center; gap: .5em; max-width: 34cqw;
  padding: .5em .8em .5em .5em; border-radius: 1.2cqw; background: var(--paper); border: 1px solid var(--line);
  box-shadow: 0 1.2cqw 2.4cqw -1.2cqw #1d2e2655; font-size: 1.6cqw; white-space: nowrap;
  animation: toast 2.2s cubic-bezier(.2,.9,.3,1.2) forwards;
}
.toast .ch { width: 1.9em; height: 1.9em; }
.toast b { margin-right: .25em; }
.toast span:last-child { overflow: hidden; text-overflow: ellipsis; color: var(--ink-2); }
@keyframes toast {
  0% { opacity: 0; transform: translateY(1.5cqw) scale(.85); }
  12% { opacity: 1; transform: none; }
  80% { opacity: 1; transform: none; }
  100% { opacity: 0; transform: translateY(-1cqw) scale(.95); }
}

/* heat haze from below and warm edges */
.heat {
  position: absolute; inset: 0; z-index: 1; pointer-events: none; opacity: calc(var(--haze) * .7);
  background:
    radial-gradient(120% 60% at 50% 115%, #ff6a1a88, transparent 62%),
    radial-gradient(150% 110% at 50% 45%, transparent 58%, #d23c2b33 100%);
  animation: throb 1.4s ease-in-out infinite;
  transition: opacity .6s ease;
}
@keyframes throb { 50% { filter: brightness(1.15) saturate(1.2); } }

.embers { position: absolute; inset: 0; z-index: 1; pointer-events: none; opacity: var(--fire); transition: opacity .6s ease; }
.embers i {
  position: absolute; bottom: -10px; width: 4px; height: 4px; border-radius: 50%;
  background: #ffb02e; box-shadow: 0 0 8px 2px #ff7a1a99;
  animation: ember var(--t, 3s) linear infinite; animation-delay: var(--dl, 0s);
}
@keyframes ember {
  0% { transform: translate(0, 0) scale(1); opacity: 0; }
  10% { opacity: 1; }
  100% { transform: translate(var(--dx, 20px), -70vh) scale(.3); opacity: 0; }
}

/* the moment it blows: a white flash, then the logo */
.flash { position: fixed; inset: 0; z-index: 13; pointer-events: none; background: #fffaf0; opacity: 0; }
.flash.go { animation: flash .7s ease-out; }
@keyframes flash { 0% { opacity: 0; } 15% { opacity: .95; } 100% { opacity: 0; } }

@media (prefers-reduced-motion: reduce) {
  .heat, .embers, .toasts { display: none; }
  .is-hot .chaos { filter: none; }
  .is-critical .chaos { animation: none; }
}

/* The scroll hint and a button wait until the problem has peaked */
.cue {
  display: flex; align-items: center; gap: 10px;
  opacity: 0; visibility: hidden; transform: translate(-50%, 10px);
  transition: opacity .5s ease, transform .5s ease, visibility 0s linear .5s;
}
.stage.peak[data-scene="0"] .cue { opacity: 1; visibility: visible; transform: translateX(-50%); transition-delay: 0s; }
.cue-pill {
  display: inline-flex; align-items: center; gap: 10px; height: 48px; padding: 0 4px 0 14px;
  border-radius: 999px; border: 1px solid var(--line); background: var(--paper); color: var(--green);
  font: inherit; font-size: .9rem; font-weight: 800; white-space: nowrap; cursor: pointer;
  box-shadow: 0 10px 24px -14px #1d2e2666; transition: border-color .2s ease, box-shadow .2s ease;
}
.cue-arrow {
  display: grid; place-items: center; width: 40px; height: 40px; margin-left: 4px; border-radius: 50%;
  background: var(--green); color: #fff; transition: background .2s ease, transform .2s ease;
}
.cue-arrow svg { width: 18px; height: 18px; stroke-width: 2.4; }
.cue-pill:hover { border-color: #a8d9bb; }
.cue-pill:hover .cue-arrow { background: #0d6633; transform: translateY(2px); }
.stage.peak[data-scene="0"] .cue-arrow { animation: cue-pulse 1.6s ease-in-out .6s infinite; }
@keyframes cue-pulse { 50% { transform: translateY(3px); } }
@media (max-width: 600px) {
  .cue-pill { font-size: .8rem; height: 44px; }
  .cue-arrow { width: 36px; height: 36px; }
}


/* ---- The logo settles above the chapter title and stays there ---- */
.copy { display: flex; flex-direction: column; }
.copy-logo { flex: none; width: 190px; aspect-ratio: 605 / 126; margin-bottom: 28px; }
.panes { display: grid; min-height: 330px; }
.pane { align-self: start; }
html:not([data-scene="0"]):not([data-scene="1"]) .brand { transform: translate(var(--hx, 0), var(--hy, 0)) scale(var(--hs, 1)); }

@media (max-width: 980px) {
  .copy-logo { width: 140px; margin: 0 auto 12px; }
  .panes { min-height: 0; }
}

/* ---- Logo flight: one smooth move, then it becomes part of the page ---- */
/* The logo element is drawn at its big size and only ever scaled down, so it stays sharp */
.topbar { justify-content: flex-end; }
.brand { position: absolute; left: max(24px, calc((100% - 1160px) / 2)); top: 14px; will-change: transform; backface-visibility: hidden; }
.brand { transition: transform 1.1s cubic-bezier(.45, 0, .2, 1), opacity 0s; }
html[data-scene="0"] .brand { transition: transform 1.1s cubic-bezier(.45, 0, .2, 1), opacity .4s ease; }
html[data-scene="1"] .brand { transition: transform 1.1s cubic-bezier(.45, 0, .2, 1), opacity .5s ease .35s; }
html[data-scene="1"].from-chapter .brand { transition: transform 1.1s cubic-bezier(.45, 0, .2, 1), opacity 0s; }
.copy-logo img { display: block; width: 100%; height: auto; opacity: 0; }
/* once landed, the logo in the page takes over so it scrolls with the title */
html.docked .copy-logo img { opacity: 1; }
html.docked .brand { opacity: 0; pointer-events: none; }
/* measuring the final layout without animating it */
html.measuring .stage-inner, html.measuring .copy, html.measuring .devices { transition: none !important; }
/* arriving from the logo: the title waits until the logo has nearly landed */
html.arriving .pane.on > :nth-child(1) { transition-delay: .6s; }
html.arriving .pane.on > :nth-child(2) { transition-delay: .68s; }
html.arriving .pane.on > :nth-child(3) { transition-delay: .76s; }
html.arriving .pane.on > :nth-child(4) { transition-delay: .84s; }

/* the logo above the title is the way home */
a.copy-logo { display: block; border-radius: 8px; }
html.docked a.copy-logo:hover img { opacity: .8; }

/* WhatsApp call to action */
.topbar { gap: 10px; }
.wa-cta {
  display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 16px 0 12px;
  border-radius: 999px; background: #1f9e50; color: #fff; font-weight: 800; font-size: .88rem; white-space: nowrap;
  box-shadow: 0 10px 22px -14px #10783e99; transition: background .2s ease, transform .2s ease;
}
.wa-cta:hover { background: #17863f; transform: translateY(-1px); }
.wa-cta svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; }
.wa-cta[hidden], [data-wa-wrap][hidden] { display: none; }
.cta .cta-wa { display: flex; flex-direction: column; align-items: center; gap: 16px; margin: 30px auto 0; color: #ffffffd9; font-weight: 700; }
.wa-big { min-height: 54px; padding: 0 24px 0 18px; font-size: 1.05rem; background: #25d366; color: #0c3a24; }
.wa-big:hover { background: #3be07a; }
@media (max-width: 600px) {
  .topbar .pill { display: none; }
  .wa-top { min-height: 36px; font-size: .8rem; }
}

/* ---- Sound switch: on by default, in the navbar on the right ---- */
.snd {
  display: grid; place-items: center; width: 40px; height: 40px; padding: 0; flex: none;
  border-radius: 50%; border: 1px solid var(--line); background: var(--paper); color: var(--green);
  cursor: pointer; transition: color .2s ease, border-color .2s ease;
}
.snd[hidden] { display: none; }
.snd svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.snd .snd-off, .snd[aria-pressed="false"] .snd-on { display: none; }
.snd[aria-pressed="false"] .snd-off { display: block; }
.snd[aria-pressed="false"] { color: var(--muted); }
.snd:hover { border-color: #a8d9bb; }
@media (max-width: 600px) { .snd { width: 36px; height: 36px; } }
/* on, but the browser is still holding the sound back until a click */
.snd.waiting { animation: snd-wait 1.8s ease-out infinite; }
@keyframes snd-wait { 0% { box-shadow: 0 0 0 0 #10783e55; } 70%, 100% { box-shadow: 0 0 0 10px #10783e00; } }
