/* Captions that read aloud: an invented graphic novel told in four engraved panels. Each caption box unrolls from its
   left edge when it comes on screen, its lines slide in one after another, and then a narrator reads it: every word
   turns red as it is read and goes back to ink after. The narrator reads one caption at a time and waits while you
   scroll fast. */
:root {
  --paper: #f4f3ef;         /* the page */
  --ink: #121212;           /* text, frames, the engravings */
  --red: #c82924;           /* the word being read */
  --box: #ffffff;           /* inside the caption boxes */
  --muted: rgba(18, 18, 18, 0.62);
  --edge: clamp(18px, 3.4vw, 52px);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  overflow-x: clip;
}

body {
  background: var(--paper);
  color: var(--ink);
  font-family: 'Archivo Variable', 'Archivo', system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ---------------------------------------------------------------- the bar */
.bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 20px var(--edge);
  background: linear-gradient(to bottom, rgba(244, 243, 239, 0.95), rgba(244, 243, 239, 0));
}

.brand {
  font-family: 'IM Fell English', Georgia, serif;
  font-size: 23px;
}

.bar__nav {
  display: flex;
  gap: clamp(16px, 2.4vw, 32px);
  font-size: 12px;
  font-weight: 600;
  font-stretch: 112%;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.bar__nav a {
  transition: color 0.25s ease;
}

@media (hover: hover) {
  .bar__nav a:hover {
    color: var(--red);
  }
}

/* ---------------------------------------------------------------- the opening */
.intro {
  min-height: 92svh;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 120px var(--edge) 9vh;
}

.kicker {
  margin: 0 0 18px;
  font-size: 12px;
  font-weight: 600;
  font-stretch: 118%;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.title {
  margin: 0;
  font-family: 'IM Fell English', Georgia, serif;
  font-weight: 400;
  font-size: clamp(72px, 13.5vw, 214px);
  line-height: 0.86;
  letter-spacing: -0.02em;
}

.title .char {
  display: inline-block;
  white-space: pre;
}

.lede {
  max-width: 34ch;
  margin: 30px 0 0;
  font-size: clamp(15px, 1.25vw, 17px);
  line-height: 1.55;
  color: var(--muted);
}

/* ---------------------------------------------------------------- the panels */
.strip {
  display: flex;
  flex-direction: column;
  gap: clamp(120px, 20vh, 220px);
  max-width: 1180px;
  margin: 0 auto;
  padding: 90px var(--edge) 120px;
}

.panel {
  position: relative;
  margin: 0;
  aspect-ratio: 16 / 10;
}

.panel--wide {
  width: 100%;
}

.panel--right {
  width: 78%;
  margin-left: auto;
}

.panel--left {
  width: 70%;
}

.panel__art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: var(--paper);
}

/* ---------------------------------------------------------------- the captions */
.caption {
  position: absolute;
  z-index: 2;
  left: clamp(-26px, -2vw, -10px);
  max-width: min(540px, 82%);
  padding: 14px 20px 15px 18px;
  font-size: clamp(12.5px, 1.2vw, 15px);
  font-weight: 560;
  font-stretch: 112%;
  line-height: 1.7;
  letter-spacing: 0.015em;
  text-transform: uppercase;
  color: var(--ink);
}

.caption--top {
  top: clamp(-34px, -2.6vw, -18px);
}

.caption--bottom {
  bottom: clamp(-38px, -2.8vw, -20px);
  left: auto;
  right: clamp(-26px, -2vw, -10px);
}

.caption--end {
  left: auto;
  right: clamp(-40px, -3vw, -14px);
}

/* the box is its own layer: it unrolls from the left edge (scaleX) while the words stay their size */
.caption__box {
  position: absolute;
  inset: 0;
  background: var(--box);
  border: 2px solid var(--ink);
  box-shadow: 4px 5px 0 var(--ink);
  transform-origin: 0 50%;
}

/* the text is cut where the box has got to, and at its own left edge, where the lines come in from */
.caption__text {
  position: relative;
  display: block;
  clip-path: inset(-4px calc((1 - var(--unroll, 1)) * 100%) -4px 0);
}

.caption__line {
  display: block;
  white-space: nowrap;
}

.caption__clip {
  display: block;
  overflow: hidden;
  padding-right: 2px;
}

.caption__word {
  display: inline;
}

/* ---------------------------------------------------------------- the end */
.end {
  padding: 40px var(--edge) 22vh;
  text-align: center;
}

.end__title {
  margin: 0;
  font-family: 'IM Fell English', Georgia, serif;
  font-weight: 400;
  font-style: italic;
  font-size: clamp(44px, 7vw, 104px);
  line-height: 1;
}

.end__actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 40px;
}

.button {
  display: inline-flex;
  align-items: center;
  min-height: 50px;
  padding: 0 24px;
  font-size: 13px;
  font-weight: 650;
  font-stretch: 112%;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  background: var(--ink);
  color: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 4px 5px 0 var(--red);
  transition: transform 0.2s cubic-bezier(0.2, 0, 0, 1), box-shadow 0.2s cubic-bezier(0.2, 0, 0, 1);
}

@media (hover: hover) {
  .button:hover {
    transform: translate(-2px, -2px);
    box-shadow: 6px 7px 0 var(--red);
  }
}

.button:active {
  transform: translate(2px, 3px);
  box-shadow: 1px 1px 0 var(--red);
}

.button--ghost {
  background: var(--box);
  color: var(--ink);
  box-shadow: 4px 5px 0 var(--ink);
}

@media (hover: hover) {
  .button--ghost:hover {
    box-shadow: 6px 7px 0 var(--ink);
  }
}

.button--ghost:active {
  box-shadow: 1px 1px 0 var(--ink);
}

/* ---------------------------------------------------------------- the narrator */
.narrator {
  position: fixed;
  left: var(--edge);
  bottom: 18px;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 10px 9px 14px;
  font-size: 11px;
  font-weight: 600;
  font-stretch: 112%;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  background: var(--box);
  border: 2px solid var(--ink);
  box-shadow: 3px 4px 0 var(--ink);
  white-space: nowrap;
}

.narrator__bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
}

.narrator__bars i {
  width: 3px;
  height: 100%;
  background: var(--ink);
  transform: scaleY(0.45);
  transform-origin: 50% 100%;
}

.narrator.is-reading .narrator__bars i {
  background: var(--red);
}

.narrator__voice {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 0 10px;
  font: inherit;
  letter-spacing: inherit;
  text-transform: inherit;
  color: var(--ink);
  background: transparent;
  border: 1.5px solid var(--ink);
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease;
}

.narrator__voice[aria-pressed='true'] {
  background: var(--ink);
  color: var(--box);
}

.narrator__voice:focus-visible,
.button:focus-visible,
.bar a:focus-visible {
  outline: 2px solid var(--red);
  outline-offset: 3px;
}

/* ---------------------------------------------------------------- phones */
@media (max-width: 720px) {
  .strip {
    gap: 118px;
    padding-top: 70px;
  }

  .panel {
    aspect-ratio: 4 / 5;
  }

  .panel--right,
  .panel--left {
    width: 92%;
  }

  .caption {
    max-width: 88%;
    padding: 11px 14px 12px 13px;
    line-height: 1.6;
  }

  .caption,
  .caption--end {
    left: -8px;
    right: auto;
  }

  .caption--bottom {
    left: auto;
    right: -8px;
  }

  .narrator {
    left: 12px;
    right: 12px;
    bottom: 12px;
    justify-content: flex-start;
  }

  /* la fila sta tutta dentro il riquadro anche a 341 px: spazi più stretti, lo stato si accorcia prima del pulsante */
  .narrator {
    gap: 8px;
    padding: 7px 7px 7px 10px;
    letter-spacing: 0.05em;
  }

  .narrator__state {
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .narrator__voice {
    flex-shrink: 0;
    gap: 5px;
    margin-left: auto;
    padding: 0 8px;
  }
}

@media (max-width: 380px) {
  .narrator {
    gap: 7px;
    font-size: 10.5px;
    letter-spacing: 0.03em;
  }
}

/* schermi bassi (la casella dell'anteprima sul telefono, 341 per 410): il titolo su due righe, l'apertura in uno schermo */
@media (max-height: 520px) {
  .intro {
    padding-top: 74px;
    padding-bottom: 72px;
  }

  .kicker {
    margin-bottom: 12px;
  }

  .title {
    font-size: clamp(54px, min(13.5vw, 15vh), 214px);
  }

  .lede {
    margin-top: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .button,
  .bar__nav a {
    transition: none;
  }
}
