/* kiokura.app. Colour and material come from tokens.css; this file holds no colour literal.
   Sizes are in rem so the page follows the reader's text size. Order: base, header and footer,
   document pages (privacy, support), not found, home, motion, print. */

*, *::before, *::after { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 1.5rem;
}

body {
  --gutter: clamp(1.25rem, 5vw, 3rem);
  --wide: 75rem;
  margin: 0;
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--ground) var(--ground-light) no-repeat;
  color: var(--ink);
  font: 1.0625rem/1.6 var(--font);
  -webkit-font-smoothing: antialiased;
  overflow-wrap: break-word;
}

main { flex: 1 0 auto; }

::selection { background: var(--selection); }

h1, h2, h3, p, dl, dd, figure { margin: 0; }
p, dd { text-wrap: pretty; }

h1, h2, .wordmark {
  font-weight: 700;
  font-stretch: var(--expanded);
  word-spacing: .08em;
  text-wrap: balance;
}

a { color: inherit; text-decoration-thickness: .0625rem; text-underline-offset: .2em; }
a:hover { text-decoration-thickness: .125rem; }

:focus-visible {
  outline: .125rem solid var(--ink);
  outline-offset: .1875rem;
  border-radius: .125rem;
}

img, video { display: block; max-width: 100%; height: auto; }

/* ---------- header and footer ---------- */

.top, .foot-in, .doc, .lost, .wrap {
  width: 100%;
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0 1rem;
  padding-block: .875rem;
}

.wordmark {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  font-size: 1.3125rem;
  line-height: 1;
  text-decoration: none;
  text-shadow: var(--engraved);
}

nav { display: flex; gap: clamp(.25rem, 2vw, 1.25rem); }

nav a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  padding-inline: .5rem;
  font-size: .9375rem;
  font-weight: 500;
  text-decoration: none;
}
nav a:hover, nav a[aria-current] { text-decoration: underline; }
.top nav { margin-inline-end: -.5rem; }

.foot {
  flex: none;
  background: var(--band) var(--band-image) 0 0 / 43.75rem 28.125rem;
  box-shadow: var(--band-inlay);
  color: var(--band-ink);
}
.foot-in {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .25rem 2rem;
  padding-block: 2rem;
}
.foot .wordmark { text-shadow: var(--stamped); }
.foot nav { margin-inline-start: -.5rem; }
.foot p {
  margin-inline-start: auto;
  color: var(--band-ink-secondary);
  font-size: .875rem;
}
.foot :focus-visible { outline-color: var(--band-ink); }

/* ---------- document pages ---------- */

.doc { padding-block: clamp(2.5rem, 7vw, 5.5rem) clamp(4rem, 9vw, 7rem); }

.stamp {
  color: var(--red);
  font-size: clamp(2rem, 1.6rem + 1.6vw, 2.75rem);
  font-weight: 700;
  font-stretch: var(--condensed);
  letter-spacing: .02em;
  line-height: 1;
}

.doc h1 {
  margin-top: .25rem;
  font-size: clamp(2.5rem, 1.7rem + 3.6vw, 4.5rem);
  line-height: 1.05;
  letter-spacing: -.01em;
  text-shadow: var(--engraved);
}

.doc-head > p:not(.stamp) {
  max-width: 40rem;
  margin-top: 1.25rem;
  font-size: 1.1875rem;
  line-height: 1.55;
}
.doc-head > h1 + p { margin-top: clamp(1.75rem, 4vw, 3rem); }
.doc-head { padding-bottom: clamp(2.5rem, 6vw, 4rem); }

.doc section {
  border-top: .0625rem solid var(--hairline);
  padding-block: 2rem 2.5rem;
  scroll-margin-top: 1rem;
}

.doc h2 {
  margin-bottom: .875rem;
  font-size: 1.3125rem;
  line-height: 1.2;
}

.doc-body { max-width: 40rem; }
.doc-body p + p { margin-top: 1rem; }

@media (min-width: 62rem) {
  .doc-head, .doc section {
    display: grid;
    grid-template-columns: minmax(0, 19rem) minmax(0, 40rem);
    column-gap: clamp(2.5rem, 6vw, 6rem);
  }
  .doc-head > * { grid-column: 2; }
  .doc-head > .stamp, .doc-head > h1 { grid-column: 1 / -1; }
  .doc h2 {
    position: sticky;
    top: 1.5rem;
    align-self: start;
    margin-bottom: 0;
    padding-top: .125rem;
  }
}

/* ---------- not found ---------- */

.lost {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding-block: 4rem 6rem;
}
.lost h1 {
  font-size: clamp(2.75rem, 1.6rem + 5.6vw, 6rem);
  line-height: 1;
  letter-spacing: -.015em;
  text-shadow: var(--engraved);
}
.lost p { margin-top: 1.25rem; max-width: 30rem; font-size: 1.1875rem; }

/* ---------- home: the pictures ---------- */

/* A tablet and a phone as plain shapes: a dark bezel, a screen. The corner radii are given per axis so they
   stay round at any width (a percentage alone would follow the box's proportions). */
.device {
  background: var(--bezel);
  box-shadow: var(--bezel-edge), var(--device-shadow);
}
.device.pad { padding: 2.1%; border-radius: 4% / 5.7%; }
.device.phone { padding: 3.2%; border-radius: 15% / 7.15%; }

/* The screen holds a still, and over it the clip of the same screen in use. The still is the clip's first
   frame, so it is what shows until the clip has loaded, what shows when no clip is offered, and what prints. */
.screen { position: relative; overflow: clip; background: var(--screen); }
.pad .screen { aspect-ratio: 1320 / 910; border-radius: 1.98% / 2.88%; }
.phone .screen { aspect-ratio: 600 / 1304; border-radius: 12.6% / 5.8%; }
.screen picture, .screen img, .screen video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* ---------- home: the first screen ---------- */

.home { overflow-x: clip; }

.hero, .feature, .feed, .tail {
  width: 100%;
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.hero { padding-top: clamp(1.5rem, 4vw, 3.5rem); }

.hero h1 {
  font-size: clamp(2.375rem, 1.1rem + 5.6vw, 5.25rem);
  line-height: 1;
  letter-spacing: -.02em;
  text-shadow: var(--engraved);
}
.hero h1 span { white-space: nowrap; }

.pitch {
  max-width: 33rem;
  margin-top: clamp(1.25rem, 2.5vw, 2rem);
  font-size: clamp(1.125rem, 1rem + .4vw, 1.25rem);
  line-height: 1.5;
}

/* The one red mark on the page that is not a date: where the App Store button will be. */
.coming {
  display: flex;
  align-items: baseline;
  gap: .625rem;
  margin-top: 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  text-wrap: balance;
}
.coming::before {
  content: "";
  flex: none;
  width: .625rem;
  height: .625rem;
  border-radius: 50%;
  background: var(--red);
}

.hero-stage {
  position: relative;
  margin-top: clamp(2.5rem, 5vw, 3.5rem);
}
.hero-stage .pad { width: 132%; margin-inline-start: 14%; }
/* On a phone the tablet bleeds off the right edge and the phone hangs from its lower left, below the note
   the tablet's page shows (the note ends a little past half way down the screen), so it never covers a word. */
.hero-stage { margin-bottom: 32%; }
.hero-stage .phone {
  position: absolute;
  left: 0;
  top: 66%;
  width: 31%;
}

@media (min-width: 48rem) {
  .hero-stage { margin-bottom: 0; }
  .hero-stage .pad { width: 86%; margin: 0; }
  .hero-stage .phone { left: auto; right: 0; top: auto; bottom: 6%; width: 19%; }
}
@media (min-width: 62rem) {
  .hero-text {
    display: grid;
    grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr);
    column-gap: clamp(2rem, 5vw, 5rem);
    align-items: end;
  }
  .hero-text h1 { grid-row: 1 / span 2; }
  .pitch { margin-top: 0; }
}

/* One switch stops every clip: checked, the clips are taken away and the stills under them show. It is offered
   only where clips play (not to a visitor who asked for reduced motion, who is sent none, and not on paper). It is
   part of the first picture's stage and hangs from its trailing lower corner, which does not move when the phone does. */
.clips {
  display: none;
  justify-content: flex-end;
  position: absolute;
  right: 0;
  top: calc(100% + .5rem);
}
.clips input {
  -webkit-appearance: none;
  appearance: none;
  display: grid;
  place-items: center;
  width: 2.75rem;
  height: 2.75rem;
  margin: 0;
  border: .0625rem solid var(--hairline);
  border-radius: 50%;
  background: none;
  cursor: pointer;
}
.clips input::before {
  content: "";
  width: .6875rem;
  height: .8125rem;
  background: linear-gradient(90deg, var(--ink) 0 34%, transparent 34% 66%, var(--ink) 66%);
}
.clips input:checked::before {
  background: var(--ink);
  clip-path: polygon(10% 0, 100% 50%, 10% 100%);
}
.home:has(.clips input:checked) .screen video { display: none; }
@media (prefers-reduced-motion: reduce) {
  .screen video { display: none; }
}
@media screen and (prefers-reduced-motion: no-preference) {
  .clips { display: flex; }
}

/* ---------- home: the thesis, one paragraph of text between the first screen and the Book ---------- */

.thesis {
  width: 100%;
  max-width: calc(var(--wide) + 2 * var(--gutter));
  margin-inline: auto;
  padding: clamp(6rem, 14vw, 9rem) var(--gutter) 0;
}
.thesis p {
  max-width: 26em;
  margin-inline: auto;
  font-size: clamp(1.375rem, 1.1rem + 1.1vw, 1.875rem);
  line-height: 1.4;
  text-wrap: pretty;
}
.thesis + .feature { padding-top: clamp(4.5rem, 11vw, 9rem); }
@media (min-width: 56rem) {
  .thesis { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: 1.5rem; }
  .thesis p { grid-column: 3 / span 8; max-width: none; margin-inline: 0; }
}

/* ---------- home: Book, Page, Moment ---------- */

.feature {
  display: grid;
  gap: clamp(2rem, 5vw, 3.5rem);
  padding-top: clamp(5rem, 13vw, 11rem);
}

.home h2 {
  font-size: clamp(1.75rem, 1.15rem + 2.6vw, 3.25rem);
  line-height: 1.06;
  letter-spacing: -.015em;
  text-shadow: var(--engraved);
}
.feature-text p, .feed p, .tail p:not(.coming) {
  max-width: 31rem;
  margin-top: 1rem;
  color: var(--ink-secondary);
  font-size: 1.1875rem;
  line-height: 1.55;
}

.feature-media { min-width: 0; }
.book .device { width: 124%; }
.moment .device { width: min(100%, 22rem); margin-inline: auto; }
.moments { display: grid; grid-template-columns: 1fr; gap: clamp(1.25rem, 3vw, 1.75rem); }
.moments figure { min-width: 0; }

/* One Page set as text and a photograph. Below 40rem it is one column, in the order it reads on iPhone; from
   40rem it is an open spread, as on iPad: the date, title and note on the left page, the photograph and its
   caption on the right, a fold between them. */
.leaf {
  position: relative;
  max-width: 30rem;
  margin-inline: auto;
  padding: clamp(1.5rem, 5vw, 2.75rem);
  border-radius: var(--radius-leaf);
  background: var(--leaf);
  box-shadow: var(--leaf-edge), var(--leaf-shadow);
}
.print {
  width: 100%;
  border-radius: var(--radius-print);
  box-shadow: var(--print-shadow);
}
.caption {
  margin-top: .625rem;
  color: var(--ink-secondary);
  font-size: .8125rem;
  line-height: 1.4;
}
.leaf .stamp { margin-top: 1.5rem; font-size: clamp(2.25rem, 1.8rem + 2vw, 3rem); }
.leaf-title {
  margin-top: .25rem;
  font-size: clamp(1.625rem, 1.3rem + 1.4vw, 2.25rem);
  font-weight: 700;
  font-stretch: var(--expanded);
  line-height: 1.15;
}
.leaf-note { margin-top: .875rem; }
.page figcaption {
  margin-top: 1.25rem;
  color: var(--ink-secondary);
  font-size: .875rem;
  text-align: center;
}

@media (min-width: 40rem) {
  .moments { grid-template-columns: 1fr 1fr; }
  .leaf {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: clamp(2rem, 6vw, 3.5rem);
    align-items: start;
    max-width: 46rem;
  }
  .leaf-photo { grid-column: 2; grid-row: 1; }
  .leaf-words { grid-column: 1; grid-row: 1; }
  .leaf .stamp { margin-top: 0; }
  .leaf-title { font-size: clamp(1.375rem, .9rem + 1.5vw, 1.875rem); }
  .leaf::before {
    content: "";
    position: absolute;
    inset-block: 0;
    left: 50%;
    width: 3.5rem;
    transform: translateX(-50%);
    background: linear-gradient(90deg, transparent, var(--leaf-fold) 55%, transparent);
    pointer-events: none;
  }
}

.feature h2 { font-size: clamp(1.75rem, 1rem + 2.2vw, 2.75rem); }

@media (min-width: 56rem) {
  .feature { grid-template-columns: repeat(12, minmax(0, 1fr)); align-items: center; column-gap: 1.5rem; }
  .book .feature-text { grid-column: 1 / span 6; }
  .book .feature-media { grid-column: 7 / -1; }
  .book .device { width: 150%; }
  .page .feature-media { grid-column: 1 / span 7; grid-row: 1; }
  .page .feature-text { grid-column: 8 / -1; }
  .moment { grid-template-rows: auto auto; row-gap: clamp(2.5rem, 5vw, 4rem); }
  .moment .feature-text { grid-column: 1 / span 6; grid-row: 1; }
  .moment .feature-media { grid-column: 8 / -1; grid-row: 1; }
  .moment .moments { grid-column: 1 / -1; grid-row: 2; }
}
@media (min-width: 72rem) {
  .page .feature-text { grid-column: 9 / -1; }
}

/* ---------- home: the promise, on leatherette ---------- */

.promise {
  margin-top: clamp(5rem, 13vw, 11rem);
  padding-block: clamp(4rem, 10vw, 8rem);
  background: var(--band) var(--band-image) 0 0 / 43.75rem 28.125rem;
  box-shadow: var(--band-inlay);
  color: var(--band-ink);
}
.promise .wrap { display: grid; gap: clamp(2.5rem, 6vw, 4rem); }
.promise h2 {
  max-width: 13em;
  font-size: clamp(2rem, 1.1rem + 4.4vw, 4.5rem);
  line-height: 1.03;
  text-shadow: var(--stamped);
}
.promise dl > div {
  display: grid;
  gap: .25rem 2rem;
  padding-block: 1.25rem;
  border-top: .0625rem solid var(--band-hairline);
}
.promise dt { font-weight: 700; font-stretch: var(--expanded); }
.promise dd { color: var(--band-ink-secondary); }
.promise dl + p { border-top: .0625rem solid var(--band-hairline); padding-top: .75rem; }
.promise a {
  display: inline-flex;
  align-items: center;
  min-height: 2.75rem;
  font-weight: 600;
}
.promise :focus-visible { outline-color: var(--band-ink); }

@media (min-width: 40rem) {
  .promise dl > div { grid-template-columns: 9.5rem minmax(0, 1fr); }
}
@media (min-width: 62rem) {
  .promise .wrap { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); align-items: start; }
  .promise h2 { position: sticky; top: 2rem; }
}

/* ---------- home: what it is not, and the close ---------- */

.feed { padding-top: clamp(5rem, 13vw, 11rem); }
.tail { padding-block: clamp(4.5rem, 11vw, 9rem); }
.close h2 { max-width: 14em; font-size: clamp(2rem, 1.1rem + 4.4vw, 4.5rem); line-height: 1.03; }
.close .coming { margin-top: 2rem; }
.close .print { margin-top: clamp(2.5rem, 6vw, 4.5rem); }

@media (min-width: 56rem) {
  .feed { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: 1.5rem; align-items: first baseline; }
  .feed h2 { grid-column: 1 / span 6; }
  .feed p { grid-column: 8 / -1; margin-top: 0; }

  .close { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); column-gap: 1.5rem; }
  .close h2 { grid-column: 1 / span 7; grid-row: 1 / span 2; max-width: none; }
  .close p:not(.coming) { grid-column: 8 / -1; align-self: start; }
  .close h2 + p { margin-top: 1.5rem; }
  .close .print, .close .coming { grid-column: 1 / -1; }
}

/* ---------- motion ----------
   Scroll-driven and nothing else: each piece is tied to how far it has come into the window, so nothing plays on
   a timer and nothing waits on a script. Everything above this block is the finished page. A browser without
   animation-timeline, a visitor who asked for reduced motion, and paper all get that page, whole and still.

   One move is the page's own: on the first screen the tablet grows to its full size and the phone climbs past
   it as the visitor starts to scroll. After that each picture arrives once, its own way, and words only fade.
   The note on what it is not and the close do not move. */

@media screen and (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) and (animation-range: entry 0% entry 100%) {
    @keyframes grow { from { transform: scale(.955); } }
    @keyframes climb { to { transform: translateY(-18%); } }
    @keyframes fade { from { opacity: 0; } }
    @keyframes arrive { from { opacity: 0; transform: translateX(3.5rem); } }
    @keyframes turn {
      from { opacity: 0; clip-path: inset(-4rem calc(100% + 4rem) -4rem -4rem); }
      to { opacity: 1; clip-path: inset(-4rem); }
    }
    @keyframes settle { from { opacity: 0; transform: scale(.965); } }
    @keyframes place { from { opacity: 0; transform: translateY(1rem); } }

    .hero-stage .pad {
      transform-origin: 0 0;
      animation: grow cubic-bezier(.3, 0, .2, 1) both;
      animation-timeline: scroll(root block);
      animation-range: 0 55vh;
    }
    .hero-stage .phone {
      animation: climb linear both;
      animation-timeline: scroll(root block);
      animation-range: 0 110vh;
    }

    /* on a phone the phone stays where it hangs: climbing would carry it up over the tablet's note */
    @media (max-width: 47.9375rem) {
      .hero-stage .phone { animation: none; }
    }

    .feature-text, .thesis p, .promise dl > div, .promise dl + p {
      animation: fade cubic-bezier(.16, 1, .3, 1) both;
      animation-timeline: view(block 0% 6%);
      animation-range: entry 0% entry 100%;
    }

    /* the tablet comes in from the edge it runs off */
    .book .device {
      animation: arrive cubic-bezier(.16, 1, .3, 1) both;
      animation-timeline: view(block 0% 6%);
      animation-range: entry 0% entry 55%;
    }
    /* the leaf is uncovered from its spine, as a page turns */
    .page .leaf {
      animation: turn cubic-bezier(.3, 0, .2, 1) both;
      animation-timeline: view(block 0% 6%);
      animation-range: entry 10% entry 75%;
    }
    /* the phone settles; the two prints are put down one after the other */
    .moment .device {
      animation: settle cubic-bezier(.16, 1, .3, 1) both;
      animation-timeline: view(block 0% 6%);
      animation-range: entry 0% entry 50%;
    }
    .moments figure {
      animation: place cubic-bezier(.16, 1, .3, 1) both;
      animation-timeline: view(block 0% 6%);
      animation-range: entry 0% entry 70%;
    }
    .moments figure + figure { animation-range: entry 30% entry 100%; }
  }
}

/* ---------- print ---------- */

@media print {
  body { display: block; min-height: 0; background: var(--ground); font-size: 11pt; }
  .top nav, .foot nav { display: none; }
  .top { padding-block: 0 1rem; }
  .doc { padding-block: 0; max-width: none; }
  .doc-head, .doc section { display: block; }
  .doc h2 { position: static; margin-bottom: .5rem; break-after: avoid; }
  .doc section { padding-block: 1rem; break-inside: auto; }
  .doc-body, .doc-head > p:not(.stamp) { max-width: none; }
  .doc p { orphans: 3; widows: 3; }
  .screen video { display: none; }
  .foot { box-shadow: none; border-top: .0625rem solid var(--hairline); }
  .foot-in { padding-block: 1rem 0; }
  .foot p { margin-inline-start: 0; }
}
