/* ============================================================
   KompanyOS — SCROLLYTELLING BEATS (story.css)
   Behaviour in story.js. Three beats, each a different mechanic:

     1. GATHER  (progress) — every scattered app/file you use flies into one
                folder, which fills, counts up, then opens as the system
     2. ASK     (trigger)  — a panel unfolds and builds a report row by row
     3. RESOLVE (progress) — the six things you're stuck doing flip to fixed,
                one at a time, as you scroll

   Token-independent: --cube-* -> the page's --green/--ink/... -> brand hex,
   so this renders on any ground.
   ============================================================ */
:root {
  --s-face:  var(--cube-white,    var(--white,    #fff));
  --s-ink:   var(--cube-ink,      var(--ink,      #0a0a0a));
  --s-dim:   var(--cube-gray-500, var(--gray-500, #5b5b5b));
  --s-line:  var(--cube-gray-200, var(--gray-200, #d9d9d9));
  --s-black: var(--black, #000);
  --s-green: var(--cube-green,  var(--green,  #00ed71));
  --s-pink:  var(--cube-pink,   var(--pink,   #f70087));
  --s-yellow:var(--cube-yellow, var(--yellow, #ffd100));
  --s-font:  var(--cube-font-primary,   var(--font, 'Poppins', system-ui, sans-serif));
  --s-mono:  var(--cube-font-secondary, var(--mono, 'Anonymous Pro', ui-monospace, monospace));
  --s-ease:  var(--ease-bounce, cubic-bezier(0.34, 1.56, 0.64, 1));
}

/* ---------- shared section furniture ---------- */
.st-wrap { width: min(1080px, 92vw); margin: 0 auto; }
.st-kicker {
  font-family: var(--s-mono); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .14em; color: var(--s-dim);
}
.st-h2 {
  margin-top: 14px; font-size: clamp(28px, 3.6vw, 52px); font-weight: 800;
  letter-spacing: -0.02em; line-height: 1.06; color: var(--s-ink);
}
.st-h2 .hl { background: var(--s-green); padding: 0.03em 0.28em; }
.st-lead { margin-top: 20px; max-width: 54ch; font-size: 17px; line-height: 1.6; color: var(--s-dim); }

/* a caption that fades up when its beat fires */
[data-beat] .st-rise {
  opacity: 0; transform: translateY(16px);
  transition: opacity .6s ease, transform .7s var(--s-ease);
  transition-delay: calc(var(--i, 0) * .1s);
}
[data-beat].is-on .st-rise { opacity: 1; transform: none; }

/* ---------- stages: tall section + sticky viewport ---------- */
[data-stage] { position: relative; }
.stage-pin {
  position: sticky; top: 0; height: 100vh;
  display: grid; place-items: center; overflow: hidden;
}

/* ============================================================
   BEAT 1 — GATHER: scattered apps + files converge into one folder
   ============================================================ */
.gather { height: 340vh; }
.gather-field { position: relative; width: min(980px, 92vw); height: min(620px, 74vh); }

/* the caption sits over the field and hands off as the beat completes */
.gather-say {
  position: absolute; z-index: 3; left: 0; right: 0; top: 0; text-align: center;
  pointer-events: none;
}
.gather-say .a, .gather-say .b { transition: opacity .5s ease, transform .6s var(--s-ease); }
.gather-say .b { position: absolute; left: 0; right: 0; top: 0; opacity: 0; transform: translateY(10px); }
.gather.is-done .gather-say .a { opacity: 0; transform: translateY(-10px); }
.gather.is-done .gather-say .b { opacity: 1; transform: none; }

/* each icon starts scattered (--sx/--sy/--sr) and travels in as --t goes 0->1 */
.gather-ic {
  --t: 0;
  position: absolute; left: 50%; top: 50%; z-index: 2;
  width: 92px; display: flex; flex-direction: column; align-items: center; gap: 7px;
  text-align: center; pointer-events: none;
  transform:
    translate(-50%, -50%)
    translate(calc(var(--sx) * (1 - var(--t))), calc(var(--sy) * (1 - var(--t))))
    rotate(calc(var(--sr) * (1 - var(--t))))
    scale(calc(1 - 0.68 * var(--t)));
}
.gather-ic img { width: 52px; height: 52px; object-fit: contain; image-rendering: pixelated; }
.gather-ic span {
  font-family: var(--s-mono); font-size: 10px; line-height: 1.3; color: var(--s-dim);
  background: rgba(255,255,255,0.78); border: 1px solid var(--s-line);
  padding: 2px 7px; border-radius: 4px; word-break: break-word;
  opacity: calc(1 - var(--t) * 2.2);          /* the label drops away as it flies */
}

/* the target: one folder that fills, counts, then opens as the system */
.gather-drop {
  position: absolute; left: 50%; top: 50%; z-index: 1;
  transform: translate(-50%, -50%);
  display: grid; place-items: center; width: 210px; height: 190px;
}
.gather-folder {
  position: relative; width: 118px; height: 118px;
  display: grid; place-items: center;
  transition: transform .5s var(--s-ease), opacity .4s ease;
}
.gather-folder img { width: 100px; height: 100px; object-fit: contain; image-rendering: pixelated; }
.gather-drop.is-full .gather-folder { transform: scale(1.09); }
.gather-count {
  position: absolute; right: -6px; top: -4px; min-width: 30px; height: 30px; padding: 0 7px;
  display: grid; place-items: center;
  font-family: var(--s-mono); font-size: 13px; font-weight: 700; color: #0a0a0a;
  background: var(--s-yellow); border: 2px solid var(--s-black); border-radius: 15px;
  box-shadow: 3px 3px 0 0 var(--s-black);
}
.gather-drop-label {
  margin-top: 16px; font-family: var(--s-mono); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em; color: var(--s-dim);
}
/* the payoff: the folder becomes ONE system */
.gather-one {
  position: absolute; left: 50%; top: 50%; z-index: 4;
  transform: translate(-50%, -50%) scale(.86); opacity: 0;
  width: min(520px, 84vw);
  background: var(--s-face); border: 3px solid var(--s-black); border-radius: 18px;
  box-shadow: var(--win-shadow, 12px 12px 0 0 #000); overflow: hidden;
  transition: opacity .45s ease, transform .6s var(--s-ease);
  pointer-events: none;
}
.gather-drop.is-open ~ .gather-one,
.gather.is-done .gather-one { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.gather.is-done .gather-drop { opacity: 0; transition: opacity .35s ease; }
.gather-one-bar {
  display: flex; align-items: center; gap: 8px; padding: 13px 16px;
  border-bottom: 1px solid var(--s-line);
}
.gather-one-bar .l { width: 12px; height: 12px; border-radius: 50%; }
.gather-one-bar .l.r { background: #ff5f57; } .gather-one-bar .l.y { background: #febc2e; } .gather-one-bar .l.g { background: #28c840; }
.gather-one-name {
  margin-left: 6px; font-family: var(--s-mono); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em; color: var(--s-ink);
}
.gather-one-body { padding: 30px 28px 32px; text-align: center; }
.gather-one-body h3 { font-size: clamp(22px, 2.3vw, 32px); font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.gather-one-body p { margin-top: 12px; font-size: 15px; line-height: 1.55; color: var(--s-dim); }

/* ============================================================
   BEAT 2 — ASK: a panel unfolds and builds the report row by row
   ============================================================ */
.ask-sec { padding: 130px 0; }
.ask-grid { margin-top: 44px; display: grid; grid-template-columns: 1fr 1.15fr; gap: 46px; align-items: center; }
.ask-panel {
  background: var(--s-face); border: 3px solid var(--s-black); border-radius: 18px;
  box-shadow: var(--win-shadow, 12px 12px 0 0 #000); overflow: hidden;
}
.ask-bar {
  display: flex; align-items: center; gap: 8px; padding: 13px 16px;
  border-bottom: 1px solid var(--s-line);
}
.ask-bar .l { width: 12px; height: 12px; border-radius: 50%; }
.ask-bar .l.r { background: #ff5f57; } .ask-bar .l.y { background: #febc2e; } .ask-bar .l.g { background: #28c840; }
.ask-name {
  margin-left: 6px; font-family: var(--s-mono); font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .12em; color: var(--s-ink);
}
/* the question types itself in */
.ask-q {
  display: flex; align-items: center; gap: 10px; padding: 18px 20px;
  border-bottom: 1px solid var(--s-line); background: #fafafa;
}
.ask-q-ic {
  flex: none; width: 22px; height: 22px; display: grid; place-items: center;
  font-family: var(--s-mono); font-size: 12px; font-weight: 700; color: #0a0a0a;
  background: var(--s-green); border: 2px solid var(--s-black); border-radius: 50%;
}
.ask-q-txt {
  font-size: 15px; font-weight: 600; color: var(--s-ink); white-space: nowrap; overflow: hidden;
  max-width: 0; transition: max-width 1.1s steps(38, end) .25s;   /* typewriter */
}
[data-beat].is-on .ask-q-txt { max-width: 34ch; }   /* > the question's natural width, so it can't clip */
.ask-caret {
  width: 2px; height: 17px; background: var(--s-ink); opacity: 0;
  animation: ask-blink 1s steps(2, end) infinite;
}
[data-beat].is-on .ask-caret { opacity: 1; animation-delay: .25s; }
@keyframes ask-blink { 0%,49% { opacity: 1 } 50%,100% { opacity: 0 } }

/* the panel body unfolds, then the rows land one after another */
.ask-body {
  max-height: 0; overflow: hidden;
  transition: max-height .75s var(--s-ease) 1.25s;
}
[data-beat].is-on .ask-body { max-height: 460px; }
.ask-rows { padding: 16px 20px 8px; display: grid; gap: 9px; }
.ask-row {
  display: grid; grid-template-columns: 1fr auto; gap: 14px; align-items: center;
  padding: 12px 14px; background: #f5f5f5; border: 1px solid var(--s-line); border-radius: 10px;
  font-size: 14px; color: var(--s-ink);
  opacity: 0; transform: translateY(10px);
  transition: opacity .4s ease, transform .5s var(--s-ease);
  transition-delay: calc(1.5s + var(--i, 0) * .13s);
}
[data-beat].is-on .ask-row { opacity: 1; transform: none; }
.ask-row b { font-family: var(--s-mono); font-weight: 700; }
.ask-src { font-family: var(--s-mono); font-size: 11px; color: var(--s-dim); }
.ask-total {
  margin: 6px 20px 20px; padding: 15px 16px;
  display: flex; align-items: baseline; gap: 12px;
  background: var(--s-green); border: 2px solid var(--s-black); border-radius: 12px;
  opacity: 0; transform: translateY(12px) scale(.97);
  transition: opacity .45s ease 2.35s, transform .6s var(--s-ease) 2.35s;
}
[data-beat].is-on .ask-total { opacity: 1; transform: none; }
.ask-total-k { font-family: var(--s-mono); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .12em; }
.ask-total-v { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.ask-foot {
  padding: 0 20px 18px; font-family: var(--s-mono); font-size: 11px; color: var(--s-dim);
  opacity: 0; transition: opacity .5s ease 2.7s;
}
[data-beat].is-on .ask-foot { opacity: 1; }

/* ============================================================
   BEAT 3 — RESOLVE: the stuck rows flip to fixed, one at a time
   ============================================================ */
.resolve { height: 300vh; }
.rz-panel { width: min(880px, 92vw); }
.rz-head { display: flex; align-items: baseline; justify-content: space-between; gap: 20px; margin-bottom: 22px; }
.rz-done {
  font-family: var(--s-mono); font-size: 12px; font-weight: 700; color: #0a0a0a;
  background: var(--s-yellow); border: 2px solid var(--s-black); border-radius: 20px;
  padding: 5px 13px; box-shadow: 3px 3px 0 0 var(--s-black); white-space: nowrap;
}
.rz-rows { display: grid; gap: 11px; }
.rz-row {
  position: relative; overflow: hidden;
  display: grid; grid-template-columns: 26px 1fr; gap: 14px; align-items: start;
  padding: 16px 18px; border-radius: 12px;
  background: var(--s-face); border: 2px solid var(--s-line);
  transition: background .45s ease, border-color .45s ease, transform .45s var(--s-ease);
}
/* the mark itself flips: pink cross -> black tick, one crossfading into the other */
.rz-mark {
  position: relative; display: block; width: 26px; height: 22px;
  font-family: var(--s-mono); font-size: 15px; font-weight: 700;
  transition: transform .45s var(--s-ease);
}
.rz-mark .m-x, .rz-mark .m-t {
  position: absolute; inset: 0; transition: opacity .3s ease, transform .4s var(--s-ease);
}
.rz-mark .m-x { color: var(--s-pink); }
.rz-mark .m-t { color: #0a0a0a; opacity: 0; transform: scale(.6); }
.rz-txt { font-size: 15px; line-height: 1.5; color: var(--s-ink); }
/* the fix slides in over the problem, on the same line */
.rz-fix {
  display: block; margin-top: 0; max-height: 0; opacity: 0;
  font-size: 15px; line-height: 1.5; color: #0a0a0a;
  transition: max-height .5s var(--s-ease), opacity .4s ease, margin-top .4s ease;
}
.rz-fix b { font-weight: 700; }
.rz-row.is-fixed {
  background: var(--s-green); border-color: var(--s-black); transform: translateX(6px);
}
.rz-row.is-fixed .rz-mark { transform: scale(1.15); }
.rz-row.is-fixed .rz-mark .m-x { opacity: 0; transform: scale(.6); }
.rz-row.is-fixed .rz-mark .m-t { opacity: 1; transform: none; }
.rz-row.is-fixed .rz-txt { color: rgba(0,0,0,.55); text-decoration: line-through; }
.rz-row.is-fixed .rz-fix { max-height: 90px; opacity: 1; margin-top: 8px; }

/* ============================================================
   Small screens / reduced motion: no sticky stages, no flying.
   Everything lands in its FINISHED state — the story is told by layout.
   ============================================================ */
@media (max-width: 820px) {
  .gather, .resolve { height: auto; }
  .stage-pin { position: static; height: auto; padding: 70px 0; }
  .gather-field { height: auto; min-height: 0; display: grid; place-items: center; gap: 26px; }
  .gather-say { position: static; }
  .gather-say .b { position: static; opacity: 1; transform: none; }
  .gather-say .a { display: none; }
  .gather-ic { display: none; }                 /* the flight is the point; skip it */
  .gather-drop { display: none; }
  .gather-one { position: static; transform: none; opacity: 1; width: 100%; }
  .ask-grid { grid-template-columns: 1fr; gap: 30px; }
  /* these have to out-specify the [data-beat].is-on rules, or the panel keeps
     its animated max-height cap and can clip its own content on a narrow phone */
  .ask-body, [data-beat].is-on .ask-body { max-height: none; }
  .ask-q-txt, [data-beat].is-on .ask-q-txt { max-width: none; transition: none; }
  .ask-caret { display: none; }
  .ask-row, .ask-total, .ask-foot { opacity: 1; transform: none; transition: none; }
  .rz-row { transform: none; }
  .rz-head { flex-direction: column; align-items: flex-start; }
}

