/* RedKnot AI — the app's palette (charcoal, paper, moonlit silver, thread red) over a dream world.
   Motion: entrances ease out, exits ease in, controls spring with a slight overshoot. Nothing linear. */
:root {
  --charcoal: #2A2A2A;
  --paper: #3B3B3B;
  --surface: #353535;
  --silver: #C0C0C0;
  --cloud: #F2EFEA;
  --muted: #A6A6A6;
  --red: #E10600;           /* thread and fills only, never text */
  --ink: #161412;

  --serif: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --hand: "Noteworthy", "Bradley Hand", "Segoe Print", "Comic Sans MS", cursive;

  --ease-out: cubic-bezier(.16, 1, .3, 1);
  --ease-in: cubic-bezier(.7, 0, .84, 0);
  --spring: linear(0, .009, .035 2.1%, .141 4.4%, .723 12.9%, .938 16.7%, 1.017, 1.077 22.4%, 1.121, 1.149 28.3%,
                   1.159 30.2%, 1.14 34.1%, 1.088 39.4%, 1.012 47.5%, .989 52.2%, .981 56.6%, 1.002 72.9%, 1);
  --gutter: clamp(16px, 4vw, 56px);
  --thread-x: clamp(18px, 3vw, 40px);
}

*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--charcoal);
  color: var(--silver);
  font: 400 clamp(1.0625rem, .25vw + 1rem, 1.1875rem)/1.55 var(--sans);
  overflow-x: hidden;
}
img { display: block; max-width: 100%; }
a { color: inherit; }
:focus-visible { outline: 2px solid var(--cloud); outline-offset: 3px; border-radius: 6px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; left: var(--gutter); top: -60px; z-index: 20; background: var(--cloud); color: var(--ink); padding: 10px 14px; border-radius: 10px; }
.skip:focus { top: 12px; }

/* Squircles: native where the browser has corner-shape; site.js clips the rest with a superellipse path. */
.sq { border-radius: 22px; }
@supports (corner-shape: squircle) { .sq { corner-shape: squircle; border-radius: 30px; } }

/* ---------- the dream ---------- */
#dream, .dream-still { position: fixed; inset: 0; width: 100%; height: 100%; z-index: -2; }
.dream-still {
  z-index: -3;
  background:
    radial-gradient(ellipse 18% 14% at 62% 38%, #bcd7ea 0 55%, transparent 70%),
    radial-gradient(ellipse 80% 70% at 62% 40%, #9a7355 0%, #4a3326 45%, #1d1612 80%),
    var(--charcoal);
}
body::before, body::after {  /* a soft wash behind the words, on whichever side they are (site.js sets --text-side) */
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(90deg, rgba(18, 15, 13, .72) 0%, rgba(18, 15, 13, .38) 42%, rgba(18, 15, 13, 0) 70%);
  opacity: calc(1 - var(--text-side, 0));
}
body::after { transform: scaleX(-1); opacity: var(--text-side, 0); }

/* ---------- the red thread down the page ---------- */
.thread { position: absolute; left: 0; top: 0; width: 100%; pointer-events: none; z-index: 1; overflow: visible; }
.thread path { fill: none; stroke: var(--red); stroke-width: 2; stroke-linecap: round; filter: drop-shadow(0 1px 1px rgba(0,0,0,.45)); }
.knot {
  --turn: -45deg;
  position: absolute; left: calc(var(--thread-x) - 9px); top: 50%; width: 18px; height: 18px; z-index: 2;
  border: 2px solid var(--red); border-radius: 50% 50% 50% 0; transform: rotate(var(--turn)) scale(.2); opacity: 0;
  transition: transform .5s var(--ease-in), opacity .25s var(--ease-in);
}
[data-side="right"] > .knot { --turn: 45deg; left: auto; right: calc(var(--thread-x) - 9px); border-radius: 50% 50% 0 50%; }
[data-side="center"] > .knot { left: calc(50% - 9px); top: 96px; }
.chapter.in .knot { transform: rotate(var(--turn)) scale(1); opacity: 1; transition: transform .7s var(--spring), opacity .3s var(--ease-out); }

/* ---------- navigation ---------- */
.nav {
  position: fixed; top: 0; left: 0; right: 0; z-index: 10;
  display: flex; align-items: center; gap: clamp(10px, 2vw, 28px);
  padding: 14px var(--gutter);
  background: linear-gradient(rgba(30, 27, 25, .55), rgba(30, 27, 25, 0));
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; font: 600 1.15rem/1 var(--serif); color: var(--cloud); margin-right: auto; }
.nav nav { display: flex; gap: clamp(12px, 2vw, 24px); }
.nav nav a { text-decoration: none; color: var(--silver); font-size: .95rem; }
.nav nav a:hover { color: var(--cloud); }
.sound {
  width: 44px; height: 44px; display: grid; place-items: center; border: 0; cursor: pointer;
  background: rgba(59, 59, 59, .72); color: var(--silver);
  transition: transform .45s var(--spring), background .2s var(--ease-out);
}
.sound svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.sound .wave { display: none; }
.sound[aria-pressed="true"] .wave { display: block; }
.sound[aria-pressed="true"] .mute { display: none; }
.sound:active { transform: scale(.9); }

.cta {
  display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 0 20px;
  background: var(--red); color: #fff; text-decoration: none; font-weight: 600; font-size: .98rem; white-space: nowrap;
  transition: transform .5s var(--spring), filter .2s var(--ease-out);
}
.cta:hover { filter: brightness(1.08); transform: translateY(-1px); }
.cta:active { transform: scale(.95); transition-duration: .15s; }
.cta.big { min-height: 56px; padding: 0 28px; font-size: 1.06rem; }
.cta.soon { background: rgba(242, 239, 234, .92); color: var(--ink); cursor: default; }
.quiet { color: var(--cloud); text-underline-offset: 4px; text-decoration-thickness: 1px; }

/* ---------- chapters ---------- */
main { position: relative; z-index: 2; }
.chapter { position: relative; min-height: 100vh; min-height: 100svh; display: grid; align-items: center; padding: 120px var(--gutter) 96px calc(var(--thread-x) + 44px); }
.copy { max-width: 34rem; }
.chapter[data-side="right"] { padding-left: var(--gutter); padding-right: calc(var(--thread-x) + 44px); justify-items: end; }
h1, h2 { font-family: var(--serif); font-weight: 600; color: var(--cloud); letter-spacing: -.015em; margin: 0 0 .45em; text-wrap: balance; }
h1 { font-size: clamp(3rem, 7.4vw, 6.6rem); line-height: .98; }
h2 { font-size: clamp(2.3rem, 5vw, 4.4rem); line-height: 1.02; }
.lede, .feature p { max-width: 32rem; margin: 0 0 1.6em; text-wrap: pretty; }
.lede { font-size: clamp(1.08rem, .5vw + 1rem, 1.3rem); color: #d6d3cf; }
.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 22px; }
h1, h2, .lede, .feature p, .actions { text-shadow: 0 1px 18px rgba(0, 0, 0, .45); }

/* Entrances ease out; leaving the screen eases in, faster. site.js toggles .in. */
.copy > *, .feature > :not(.knot) {
  opacity: 0; transform: translateY(26px);
  transition: opacity .35s var(--ease-in), transform .35s var(--ease-in);
}
.chapter.in .copy > *, .chapter.in.feature > :not(.knot) {
  opacity: 1; transform: none;
  transition: opacity .9s var(--ease-out), transform 1.1s var(--ease-out);
}
.chapter.in .copy > :nth-child(2), .chapter.in.feature > :nth-child(3) { transition-delay: .12s; }
.chapter.in .copy > :nth-child(3), .chapter.in.feature > :nth-child(4) { transition-delay: .24s; }

.hero .scroll-hint {
  position: absolute; left: 50%; bottom: 28px; transform: translateX(-50%); margin: 0;
  font: 1.05rem var(--hand); color: var(--cloud); opacity: calc(.85 - var(--p, 0) * 3);
}

/* "Dreams fade by morning": the words blur and thin as you scroll past them. */
.statement .fades { filter: blur(calc(max(var(--p, 0) - .5, 0) * 16px)); opacity: calc(1.4 - var(--p, 0) * 1.3); }
.chapter.in.statement .copy > .fades { opacity: calc(1.4 - var(--p, 0) * 1.3); }

/* The elephant drifts and tilts as the chapter crosses the screen. */
.elephant-chapter { grid-template-columns: minmax(0, 1fr) minmax(0, .8fr); gap: 4vw; }
.elephant { margin: 0; position: relative; width: min(38vw, 420px); justify-self: center; transform: translateY(calc((.5 - var(--p, .5)) * 60px)) rotate(calc((var(--p, .5) - .5) * -8deg)); }
.elephant img { width: 100%; filter: drop-shadow(0 24px 40px rgba(0, 0, 0, .5)); }

/* ---------- features: one idea per screen, one phone that turns in your hand ---------- */
.features { position: relative; display: grid; }
.features-copy, .phone-stage { grid-area: 1 / 1; }
.features-copy { position: relative; z-index: 2; }
.feature { padding-top: 0; padding-bottom: 0; align-content: center; grid-template-columns: minmax(0, 34rem); }
.feature[data-side="right"] { justify-content: end; }
.feature h2 { max-width: 13ch; }
.phone-stage { position: sticky; top: 0; align-self: start; height: 100vh; height: 100svh; display: grid; place-items: center; perspective: 1400px; pointer-events: none; z-index: 1; }
.phone {
  --ry: 0deg; --rx: 0deg; --side: 1;  /* -1 left half, 1 right half: site.js moves it with the scroll */
  width: min(330px, 34vw, 84svh * 9 / 19.5); aspect-ratio: 9 / 19.5;  /* never taller than the window */
  transform: translateX(calc(var(--side) * min(25vw, 380px))) rotateY(var(--ry)) rotateX(var(--rx)); transform-style: preserve-3d;
  filter: drop-shadow(0 40px 60px rgba(0, 0, 0, .55));
  transition: transform .45s var(--ease-out);
}
.phone-body {
  position: relative; width: 100%; height: 100%; overflow: hidden; border-radius: 48px;
  background:
    linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px) 0 0 / 100% 16px,
    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px) 0 0 / 16px 100%,
    var(--charcoal);
  box-shadow: inset 0 0 0 9px #111, inset 0 0 0 11px #4a4a4a;
  font-size: 13.5px; line-height: 1.4; color: var(--silver);
}
@supports (corner-shape: squircle) { .phone-body.sq { border-radius: 64px; } }
.island { position: absolute; top: 16px; left: 50%; width: 30%; height: 26px; transform: translateX(-50%); background: #000; border-radius: 20px; z-index: 3; }
.status { position: absolute; top: 18px; left: 34px; right: 34px; display: flex; justify-content: space-between; font: 600 13px var(--sans); color: var(--cloud); z-index: 3; }
.status .air { opacity: 0; transform: scale(.4); transition: opacity .25s var(--ease-in), transform .3s var(--ease-in); }
.offline-on .status .air { opacity: 1; transform: none; transition: opacity .3s var(--ease-out), transform .6s var(--spring); }

.screen {
  position: absolute; inset: 56px 18px 22px; display: flex; flex-direction: column; gap: 10px;
  opacity: 0; transform: translateY(14px) scale(.98); pointer-events: none;
  transition: opacity .22s var(--ease-in), transform .26s var(--ease-in);
}
.screen.on { opacity: 1; transform: none; transition: opacity .5s var(--ease-out) .08s, transform .7s var(--ease-out) .08s; }
.bar { display: flex; justify-content: center; padding: 4px 0 8px; }
.bar .title { font: 600 1.1em var(--serif); color: var(--cloud); }
.chat { flex: 1; display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
.bubble {
  align-self: flex-end; max-width: 84%; margin: 0; padding: 9px 13px; background: var(--surface);
  border: 1.5px dashed var(--red); border-radius: 18px;
}
.answer { margin: 0; color: var(--cloud); position: relative; padding-left: 16px; }
.answer::before { content: ""; position: absolute; left: 0; top: .5em; width: 7px; height: 7px; border-radius: 50%; background: var(--red); }
.from { margin: -4px 0 0 16px; font-size: .89em; color: var(--muted); }
.note {
  position: relative; padding: .9em .95em .95em; background: var(--paper); font-size: .96em; color: var(--silver);
  clip-path: polygon(0 0, 100% 0, 100% 92%, 94% 100%, 82% 94%, 66% 100%, 50% 95%, 34% 100%, 18% 94%, 6% 100%, 0 93%);
  transform: rotate(-.8deg);
}
.note.red { box-shadow: inset 3px 0 0 var(--red); }
.note .date { display: block; font: 1.15em var(--hand); color: var(--muted); }
.taped::before { content: ""; position: absolute; top: -7px; left: 50%; width: 52px; height: 15px; transform: translateX(-50%) rotate(-3deg); background: rgba(192, 192, 192, .28); }
.toast { align-self: center; font: 1.18em var(--hand); padding: 7px 16px; transform: rotate(-2deg); clip-path: none; }
.composer { margin-top: auto; padding: 11px 14px; border: 1.5px dashed var(--red); border-radius: 20px; color: var(--muted); }
.composer.action { border: 0; background: var(--red); color: #fff; text-align: center; font-weight: 600; }
.receipt { display: grid; gap: 2px; padding: 14px; background: #ECE8E1; color: #333; font: .93em var(--sans); transform: rotate(1.2deg); position: relative; }
.receipt .total { font-weight: 700; margin-top: 6px; box-shadow: 0 -1px 0 #bbb; padding-top: 6px; }
.timer { margin: 0; color: var(--cloud); font-weight: 600; }
.timer::first-letter { color: var(--red); }
.split { display: grid; grid-template-rows: 1fr auto auto 1fr; place-items: center; height: 100%; text-align: center; font: 600 1.48em var(--serif); color: var(--cloud); }
.split .upside { transform: rotate(180deg); align-self: end; margin: 0; }
.split p:last-child { align-self: start; margin: 0; }
.seam { width: 100%; height: 2px; background: var(--red); }
.talking { width: 96px; margin: 14px 0; animation: talk 1.6s var(--ease-out) infinite; }
@keyframes talk { 0%, 100% { transform: scale(1); } 40% { transform: scale(1.06); } }
.map { position: relative; flex: 1; }
.map-threads { position: absolute; inset: 0; width: 100%; height: 100%; }
.map-threads path { fill: none; stroke: var(--red); stroke-width: 2; stroke-dasharray: 220; stroke-dashoffset: 220; }
.screen.on .map-threads path { stroke-dashoffset: 0; transition: stroke-dashoffset 1.4s var(--ease-out) .4s; }
.topic { position: absolute; left: var(--x); top: var(--y); width: 44%; padding: 12px; background: var(--paper); font: 1.26em var(--hand); color: var(--cloud); transform: rotate(-1deg); }
.topic:nth-child(odd) { transform: rotate(1.2deg); }
.topic small { display: block; font: .68em var(--sans); color: var(--muted); }
.locked { height: 100%; display: grid; place-content: center; justify-items: center; gap: 16px; text-align: center; }
.locked img { width: 110px; }
.faceid { width: 44px; height: 44px; border: 2px solid var(--silver); border-radius: 12px; position: relative; }
.faceid::after { content: ""; position: absolute; inset: 12px 11px; border-bottom: 2px solid var(--silver); border-radius: 0 0 10px 10px; }

/* The airplane switch in the copy: a real control, so it springs. */
.airplane { justify-self: start; display: inline-flex; align-items: center; gap: 12px; padding: 10px 16px 10px 10px; border: 0; cursor: pointer; background: rgba(59, 59, 59, .8); color: var(--cloud); font: 600 1rem var(--sans); }
.airplane .track { width: 52px; height: 32px; border-radius: 16px; background: #5a5a5a; position: relative; transition: background .25s var(--ease-out); }
.airplane .thumb { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; transition: transform .55s var(--spring); }
.airplane[aria-checked="true"] .track { background: #F09A00; }
.airplane[aria-checked="true"] .thumb { transform: translateX(20px); }

/* ---------- the end ---------- */
.finale { text-align: center; justify-items: center; }
.finale .copy { max-width: 40rem; }
.finale .actions { justify-content: center; }
.footer {
  position: relative; z-index: 2; display: grid; justify-items: center; gap: 12px; text-align: center;
  padding: 56px var(--gutter) calc(40px + env(safe-area-inset-bottom)); background: rgba(24, 21, 19, .92); font-size: .95rem;
}
.footer p { margin: 0; max-width: 36rem; color: var(--muted); }
.footer nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 22px; }

/* ---------- legal pages ---------- */
.doc { position: relative; z-index: 2; max-width: 46rem; margin: 0 auto; padding: 120px var(--gutter) 80px; }
.doc h1 { font-size: clamp(2.4rem, 5vw, 3.6rem); }
.doc h2 { font-size: 1.5rem; margin-top: 2.2em; }
.doc p, .doc li { color: #d6d3cf; line-height: 1.65; }
.doc .updated { font: 1.05rem var(--hand); color: var(--muted); }
.doc .summary { background: rgba(59, 59, 59, .85); padding: 22px 26px; margin: 28px 0; }
.doc .summary p { margin: 0; }
.doc-page body::before { background: rgba(18, 15, 13, .78); }

/* ---------- small screens: words first, the phone after each idea ---------- */
@media (max-width: 820px) {
  body::before { background: linear-gradient(0deg, rgba(18, 15, 13, .78) 0%, rgba(18, 15, 13, .42) 55%, rgba(18, 15, 13, .2) 100%); }
  .nav nav { display: none; }
  .nav .cta { padding: 0 14px; font-size: .9rem; }
  .chapter, .chapter[data-side="right"] { padding-left: calc(var(--thread-x) + 30px); padding-right: var(--gutter); justify-items: start; }
  .feature[data-side="right"] { justify-content: start; }
  [data-side="right"] > .knot { --turn: -45deg; right: auto; left: calc(var(--thread-x) - 9px); border-radius: 50% 50% 50% 0; }
  body::after { display: none; }
  body::before { opacity: 1; }
  .elephant-chapter { grid-template-columns: 1fr; }
  .elephant { width: min(64vw, 300px); }
  .features { display: block; }
  .phone { --side: 0; }
  .phone-stage { position: sticky; top: auto; bottom: 0; height: auto; padding: 0 0 3svh; z-index: 3; pointer-events: none; }
  .feature { min-height: 90svh; align-content: start; padding-top: 13svh; }
  .feature p { margin-bottom: 1em; }
  .phone { width: auto; height: min(42svh, 360px); }  /* leaves the top half of the screen to the words */
  .phone-body { font-size: 9px; border-radius: 30px; box-shadow: inset 0 0 0 6px #111, inset 0 0 0 7px #4a4a4a; }
  .screen { inset: 38px 11px 14px; gap: 6px; }
  .island { top: 10px; height: 17px; }
  .status { top: 11px; left: 20px; right: 20px; font-size: 9px; }
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: .01ms !important; animation: none !important; }
  .copy > *, .feature > :not(.knot) { opacity: 1; transform: none; }
  .statement .fades { filter: none; opacity: 1; }
  .elephant, .phone { transform: none; }
}
.no-webgl #dream { display: none; }
