/* Registered so the chip bob can be interpolated inside a transform. */
@property --bob {
  syntax: '<length>';
  inherits: false;
  initial-value: 0px;
}

/* ============================================================================
   Notely landing — 3D workspace motion
   ----------------------------------------------------------------------------
   One stage, two acts, driven by a single CSS custom property --t:

     act 1 (t 0 → .5)  the chat is happening   — prompt types, answer streams
     act 2 (t .5 → 1)  the tools are building  — cards, quiz, deck, map appear

   The camera does a slow dolly-back while the plane unwinds from 42° to 26°
   so the workspace is seen *in* perspective rather than as a flat card.

   Everything is derived from --t, so the only thing the driver has to do is
   set one number per frame. That keeps the timeline scrub-able, pausable and
   easy to freeze under prefers-reduced-motion.
   ========================================================================== */

/* Card surface is declared explicitly per theme: on dark the tray is recessed
   and the cards must read lighter than it, on light they must read whiter than
   the window. */
html[data-theme='dark'] {
  --n-stage-card: #171d27;
  --n-stage-face: #0e131b;
  --n-stage-card-line: rgba(255, 255, 255, 0.13);
  --n-stage-tray: #0b0e13;
  /* one key light from upper-left, one cool bounce from lower-right */
  --n-stage-key: rgba(255, 255, 255, 0.1);
  --n-stage-bounce: rgba(143, 232, 248, 0.14);
  --n-stage-edge: rgba(255, 255, 255, 0.28);
  --n-stage-depth: 0 42px 90px -34px rgba(0, 0, 0, 0.95), 0 8px 26px -12px rgba(0, 0, 0, 0.8);
  --n-stage-floor: rgba(143, 232, 248, 0.2);
  --n-stage-grid: rgba(255, 255, 255, 0.09);
  --n-stage-grid-size: 38px;
}
html[data-theme='light'] {
  --n-stage-card: #ffffff;
  --n-stage-face: #ffffff;
  --n-stage-card-line: rgba(11, 18, 32, 0.12);
  --n-stage-tray: #eceff5;
  --n-stage-key: rgba(255, 255, 255, 0.62);
  --n-stage-bounce: rgba(31, 111, 181, 0.07);
  --n-stage-edge: rgba(255, 255, 255, 0.95);
  --n-stage-depth: 0 44px 80px -30px rgba(16, 32, 58, 0.34), 0 10px 24px -14px rgba(16, 32, 58, 0.22);
  --n-stage-floor: rgba(31, 111, 181, 0.22);
  --n-stage-grid: rgba(11, 18, 32, 0.12);
  --n-stage-grid-size: 38px;
}

.n-stage-section {
  position: relative;
  overflow: clip;
  border-top: 1px solid var(--n-line);
  background: color-mix(in srgb, var(--n-bg-elev) 46%, transparent);
}

.n-stage {
  /* camera + timeline defaults */
  --t: 0;
  --plane-rot: 20deg;
  --plane-scale: 1;
  --plane-lift: 0px;
  --persp: 1800px;

  position: relative;
  margin-top: clamp(10px, 1.4vw, 20px);
  height: clamp(340px, 37vw, 430px);
  perspective: var(--persp);
  perspective-origin: 50% 40%;
}

/* --- floor ---------------------------------------------------------------
   No grid. A perspective grid behind a translucent window either disappears
   behind it or bleeds through it. Depth is carried by the plane's tilt, the
   key/bounce lighting on the glass, and the cast shadow underneath.
   ---------------------------------------------------------------------- */

/* --- the workspace plane ------------------------------------------------- */
.n-stage__plane {
  position: absolute;
  inset: 0;
  margin: auto;
  width: min(940px, 92%);
  height: fit-content;
  max-height: 100%;
  transform-style: preserve-3d;
  transform:
    translateY(calc(var(--cam-y) + (1 - clamp(0, var(--t) * 2.2, 1)) * 26px))
    rotateX(var(--plane-rot))
    scale(var(--plane-scale));
  transform-origin: 50% 42%;
  will-change: transform;
}

/* --- window chrome ------------------------------------------------------- */
.n-stage__window {
  position: relative;
  transform-style: preserve-3d;
  background: var(--n-stage-face);
  border: 1px solid color-mix(in srgb, var(--n-stage-edge) 60%, transparent);
  box-shadow: var(--n-stage-depth);
}

/* Key light: a soft diagonal wash across the face of the window, so the
   surface has a light side and a shadow side instead of one flat colour. */
.n-stage__window::before {
  content: '';
  position: absolute;
  inset: 0;
  background:
    linear-gradient(128deg, var(--n-stage-key) 0%, transparent 42%),
    linear-gradient(315deg, var(--n-stage-bounce) 0%, transparent 46%);
  opacity: 0.75;
  pointer-events: none;
  z-index: 0;
}

/* Specular top edge: a 1px highlight that reads as a bevelled lip. */
.n-stage__window::after {
  content: '';
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--n-stage-edge) 18%, var(--n-stage-edge) 82%, transparent);
  opacity: 0.8;
  pointer-events: none;
  z-index: 3;
}

.n-stage__bar,
.n-stage__body { position: relative; z-index: 1; }

.n-stage__bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 13px;
  border-bottom: 1px solid var(--n-line);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9.5px;
  letter-spacing: 0.06em;
  color: var(--n-muted);
  text-transform: uppercase;
}

.n-stage__dots { display: inline-flex; gap: 5px; }
.n-stage__dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--n-line-strong);
}
.n-stage__dots i:nth-child(1) { background: color-mix(in srgb, var(--n-danger) 70%, transparent); }
.n-stage__dots i:nth-child(2) { background: color-mix(in srgb, var(--n-success) 70%, transparent); }

.n-stage__url { flex: 1; letter-spacing: 0.04em; text-transform: none; font-size: 10px; }
.n-stage__rec {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--n-accent-strong);
}
.n-stage__rec i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--n-cyan) 16%, transparent);
  animation: n-stage-rec 1.8s ease-in-out infinite;
}

/* --- body: chat ledger on the left, build tray on the right -------------- */
.n-stage__body {
  display: grid;
  grid-template-columns: minmax(0, 1.04fr) minmax(0, 0.96fr);
  align-items: start;
  min-height: 300px;
}

.n-stage__chat {
  padding: 16px 18px 18px;
  border-right: 1px solid var(--n-line);
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: visible;
}

.n-stage__thread-label,
.n-stage__tray-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--n-muted);
}
.n-stage__thread-label b,
.n-stage__tray-label b {
  font-weight: 500;
  color: var(--n-ink-2);
}

.n-stage__msg { display: flex; flex-direction: column; gap: 4px; }

.n-stage__who {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--n-muted);
}

.n-stage__bubble {
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--n-ink-2);
  background: var(--n-panel);
  border: 1px solid var(--n-line);
  padding: 10px 12px;
  max-width: 96%;
}

.n-stage__bubble--me {
  align-self: flex-end;
  color: var(--n-ink);
  background: var(--n-cyan-soft);
  border-color: color-mix(in srgb, var(--n-cyan) 28%, transparent);
}

/* typed prompt: width is the timeline */
.n-stage__typed {
  display: inline-block;
  overflow: hidden;
  white-space: nowrap;
  vertical-align: bottom;
  width: clamp(0ch, calc(var(--t) * 2 * 44ch), 44ch);
  border-right: 1px solid var(--n-cyan);
  animation: n-stage-caret 900ms steps(1) infinite;
}

/* Streamed answer. A mask (not a clip) so nothing beneath it can be cut off,
   and the reveal finishes early enough that the citations are always visible. */
.n-stage__answer {
  --a-o: clamp(0, calc((var(--t) - 0.16) * 4.4), 1);
  opacity: var(--a-o);
  transform: translateY(calc((1 - var(--a-o)) * 6px));
  will-change: opacity, transform;
}
.n-stage__answer p { margin: 0 0 6px; }
.n-stage__answer p:last-of-type { margin-bottom: 0; }

.n-stage__points {
  margin: 7px 0 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 2px;
}
.n-stage__points li {
  display: flex;
  align-items: baseline;
  gap: 7px;
  font-size: 12px;
  color: var(--n-ink-2);
}
.n-stage__points li::before {
  content: '';
  width: 14px;
  height: 1px;
  flex: none;
  transform: translateY(-3px);
  background: var(--n-line-strong);
}

.n-stage__cite-row {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 8px;
}
.n-stage__cite {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9.5px;
  letter-spacing: 0.05em;
  padding: 4px 7px;
  color: var(--n-ink-2);
  border: 1px solid var(--n-line);
  background: var(--n-panel);
}
.n-stage__cite svg { width: 9px; height: 9px; }

/* trace line tying the answer back to the file it used */
.n-stage__trace {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 8px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 8px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--n-muted);
  opacity: clamp(0, calc((var(--t) - 0.3) * 6), 1);
}
.n-stage__trace i {
  flex: 1;
  height: 1px;
  background: linear-gradient(90deg, var(--n-line-strong), transparent);
}

/* --- build tray ---------------------------------------------------------- */
.n-stage__tray {
  position: relative;
  padding: 16px 16px 18px;
  display: grid;
  align-content: start;
  gap: 9px;
  background:
    linear-gradient(var(--n-grid) 1px, transparent 1px) 0 0 / 100% var(--n-grid-size),
    linear-gradient(90deg, var(--n-grid) 1px, transparent 1px) 0 0 / var(--n-grid-size) 100%;
  background-color: var(--n-stage-tray);
}

/* Each artefact rises out of the plane on its own window of the timeline.
   --in is the moment it starts. The ramp is eased (see --ease below) so the
   cards decelerate into place instead of snapping, and each one carries a
   different depth so the tray reads as a stack, not a list. */
.n-stage__card {
  --o: clamp(0, calc((var(--t) - var(--in, 0.5)) * 9), 1);
  /* ease-out cubic, done arithmetically so it stays scrub-able */
  --e: calc(1 - (1 - var(--o)) * (1 - var(--o)) * (1 - var(--o)));
  position: relative;
  transform-style: preserve-3d;
  background: var(--n-stage-card);
  border: 1px solid var(--n-stage-card-line);
  padding: 10px 11px;
  opacity: var(--o);
  transform:
    translateZ(calc(var(--dz, 0px) + var(--e) * 30px))
    translateY(calc((1 - var(--e)) * 22px))
    rotateX(calc((1 - var(--e)) * -14deg));
  transform-origin: 50% 100%;
  will-change: transform, opacity;
  box-shadow: 0 10px 22px -14px rgba(0, 0, 0, 0.55);
}
html[data-theme='light'] .n-stage__card {
  box-shadow: 0 10px 22px -16px rgba(16, 32, 58, 0.3);
}

.n-stage__card--deck  { --in: 0.34; --dz: 0px; }
.n-stage__card--quiz  { --in: 0.44; --dz: 10px; }
.n-stage__card--notes { --in: 0.54; --dz: 20px; }

.n-stage__card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--n-muted);
  margin-bottom: 7px;
}
.n-stage__card-head b { font-weight: 500; color: var(--n-ink-2); }
.n-stage__tag {
  padding: 2px 5px;
  border: 1px solid color-mix(in srgb, var(--n-cyan) 30%, transparent);
  color: var(--n-accent-strong);
  background: var(--n-cyan-soft);
}

/* flashcards */
.n-stage__deck { display: flex; gap: 5px; }
.n-stage__flash {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--n-line);
  background: var(--n-panel);
  padding: 7px 7px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  opacity: clamp(0, calc((var(--t) - 0.34) * 8), 1);
}
.n-stage__flash i {
  display: block;
  height: 2px;
  background: var(--n-line-strong);
  opacity: 0.5;
}
.n-stage__flash i:first-child { background: var(--n-cyan); opacity: 0.75; }
.n-stage__flash i:nth-child(2) { width: 78%; }
.n-stage__flash i:nth-child(3) { width: 58%; }

/* quiz */
.n-stage__quiz { display: grid; gap: 5px; }
.n-stage__opt {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 11.5px;
  color: var(--n-ink-2);
  padding: 6px 8px;
  border: 1px solid var(--n-line);
  background: var(--n-panel);
  opacity: clamp(0, calc((var(--t) - 0.44) * 9), 1);
}
.n-stage__opt span {
  flex: none;
  width: 11px;
  height: 11px;
  display: grid;
  place-items: center;
  border: 1px solid var(--n-line-strong);
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 7px;
  color: var(--n-muted);
}
.n-stage__opt.is-right {
  border-color: color-mix(in srgb, var(--n-success) 45%, transparent);
  background: color-mix(in srgb, var(--n-success) 8%, transparent);
  color: var(--n-ink);
}
.n-stage__opt.is-right span {
  border-color: var(--n-success);
  background: color-mix(in srgb, var(--n-success) 22%, transparent);
  color: var(--n-success);
}

/* notes */
.n-stage__note-lines { display: grid; gap: 4px; }
.n-stage__note-lines i {
  display: block;
  height: 2px;
  background: var(--n-line-strong);
  opacity: 0.45;
  transform-origin: 0 50%;
  transform: scaleX(clamp(0, calc((var(--t) - 0.54) * 7), 1));
}
.n-stage__note-lines i:nth-child(1) { width: 92%; background: var(--n-cyan); opacity: 0.6; }
.n-stage__note-lines i:nth-child(2) { width: 74%; }
.n-stage__note-lines i:nth-child(3) { width: 85%; }
.n-stage__note-lines i:nth-child(4) { width: 46%; }

/* --- floating tool chips, on their own 3D layers ------------------------- */
.n-stage__chip {
  position: absolute;
  z-index: 4;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 9px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--n-ink);
  background: var(--n-surface);
  border: 1px solid color-mix(in srgb, var(--n-stage-edge) 55%, transparent);
  box-shadow:
    0 14px 26px -12px rgba(0, 0, 0, 0.6),
    inset 0 1px 0 color-mix(in srgb, var(--n-stage-edge) 70%, transparent);
  white-space: nowrap;
  --o: clamp(0, calc((var(--t) - var(--in, 0.42)) * 6), 1);
  opacity: var(--o);
  /* float, plus a slow bob so they read as suspended rather than pinned */
  transform:
    translateZ(var(--cz, 90px))
    translate3d(0, calc((1 - var(--o)) * 16px + var(--bob, 0px)), 0);
  will-change: transform, opacity;
}
html[data-theme='light'] .n-stage__chip {
  box-shadow: 0 14px 26px -14px rgba(16, 32, 58, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.9);
}

.n-stage__chip svg { width: 10px; height: 10px; color: var(--n-accent-strong); }
.n-stage__chip--a { top: -11%; right: 2%; --cz: 70px; --in: 0.28; animation: n-stage-bob 7.2s ease-in-out infinite; }
.n-stage__chip--b { animation-delay: -2.4s; }
.n-stage__chip--c { animation-delay: -4.8s; }
@keyframes n-stage-bob {
  0%, 100% { --bob: 0px; }
  50% { --bob: -5px; }
}
.n-stage__chip--b { bottom: -30%; left: -1%; --cz: 105px; --in: 0.40; }
.n-stage__chip--c { bottom: -30%; right: 2%; --cz: 60px; --in: 0.48; }

/* --- caption strip ------------------------------------------------------- */
.n-stage__legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 18px;
  margin-top: clamp(22px, 3vw, 34px);
}
.n-stage__phase {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--n-muted);
  border: 1px solid var(--n-line);
  padding: 6px 10px;
  transition: color 220ms ease, border-color 220ms ease, background 220ms ease;
}
.n-stage__phase i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.5;
}
.n-stage__phase.is-on {
  color: var(--n-accent-strong);
  border-color: color-mix(in srgb, var(--n-cyan) 34%, transparent);
  background: var(--n-cyan-soft);
}
.n-stage__phase.is-on i { opacity: 1; box-shadow: 0 0 0 3px color-mix(in srgb, var(--n-cyan) 14%, transparent); }

.n-stage__scrub {
  flex: 1;
  min-width: 140px;
  height: 2px;
  background: var(--n-line);
  position: relative;
}
.n-stage__scrub span {
  position: absolute;
  inset: 0 auto 0 0;
  width: calc(var(--t) * 100%);
  background: var(--n-accent-strong);
}

.n-stage__pause {
  font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--n-muted);
  background: transparent;
  border: 1px solid var(--n-line);
  padding: 6px 10px;
  cursor: pointer;
  transition: color 160ms ease, border-color 160ms ease;
}
.n-stage__pause:hover { color: var(--n-ink); border-color: var(--n-line-strong); }
.n-stage__pause:focus-visible { outline: 2px solid var(--n-accent-strong); outline-offset: 2px; }

@keyframes n-stage-caret {
  0%, 49% { border-right-color: var(--n-cyan); }
  50%, 100% { border-right-color: transparent; }
}
@keyframes n-stage-rec {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.35; }
}

/* --- responsive ---------------------------------------------------------- */
@media (max-width: 900px) {
  .n-stage { height: clamp(360px, 82vw, 460px); perspective: 1300px; }
  .n-stage__body { grid-template-columns: minmax(0, 1fr); min-height: 0; }
  .n-stage__tray { display: none; }
  .n-stage__chat { border-right: 0; }
  .n-stage__plane { width: 94%; transform-origin: 50% 46%; }

  /* chips: only the two that sit inside the frame, and only horizontally */
  .n-stage__chip--a { top: -3%; right: 4%; }
  .n-stage__chip--b { bottom: -8%; left: 4%; }
  .n-stage__chip--c { display: none; }
}

@media (max-width: 560px) {
  .n-stage { height: 400px; perspective: 1350px; --plane-rot: 14deg; }
  .n-stage__bubble { font-size: 12px; padding: 8px 10px; }
  .n-stage__points li { font-size: 11px; }
  .n-stage__bar { font-size: 8.5px; }
  .n-stage__url { font-size: 9px; }

  .n-stage__chip { font-size: 7.5px; padding: 4px 6px; }
  .n-stage__chip--a { top: -5%; right: 2%; --cz: 40px; }
  .n-stage__chip--b { bottom: -9%; left: 2%; --cz: 34px; }

  /* legend: phases on row 1, the scrub bar on its own full-width row */
  .n-stage__legend { gap: 10px; }
  .n-stage__phase { font-size: 8.5px; padding: 5px 8px; }
  .n-stage__scrub { order: 3; flex: 1 0 100%; min-width: 0; height: 2px; }
  .n-stage__pause { margin-left: auto; font-size: 8.5px; padding: 5px 9px; }
}

/* --- reduced motion: no dolly, no scrub, everything settled --------------- */
@media (prefers-reduced-motion: reduce) {
  .n-stage {
    --t: 1;
    --plane-rot: 0deg;
    --plane-scale: 1;
  }
  .n-stage__plane { transform: none; }
  .n-stage__rec i,
  .n-stage__typed { animation: none; }
  .n-stage__typed { width: auto; border-right: 0; }
  .n-stage__chip { transform: none; }
  .n-stage__chip--a { top: auto; bottom: -12%; right: 3%; }
  .n-stage__card { transform: none; }
  .n-stage__pause,
  .n-stage__scrub { display: none; }
}

@media (prefers-reduced-motion: reduce) and (max-width: 900px) {
  .n-stage__tray { display: grid; }
  .n-stage { height: auto; perspective: none; }
  .n-stage__plane { width: 100%; }
  .n-stage__body { grid-template-columns: minmax(0, 1fr); }
  .n-stage__chat { border-right: 0; border-bottom: 1px solid var(--n-line); }
  .n-stage__chip { display: none; }
}
