:root {
  --ink: #032523;          /* the night water, sampled from the PFP */
  --ink-deep: #011816;
  --ring: #244946;         /* the ripple lines */
  --paper: #f2eee3;        /* folded paper */
  --paper-shade: #d3ccba;  /* the far side of a crease */
  --purr-blue: #94d2f0;    /* Purr's cheek shading */
  --purr-pink: #f9acc8;    /* inside his ears */

  --font-mark: 'Dela Gothic One', 'Arial Black', sans-serif;
  --font-text: 'Shippori Mincho', 'Hiragino Mincho ProN', Georgia, serif;

  --gutter: clamp(16px, 3.2vw, 48px);
  color-scheme: dark;
}

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

html,
body {
  margin: 0;
  height: 100%;
  background: var(--ink);
  color: var(--paper);
}

body {
  font-family: var(--font-text);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

p { margin: 0; }

.stage {
  position: relative;
  width: 100%;
  height: 100svh;
  min-height: 520px;
  overflow: hidden;
  isolation: isolate;
}

.scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  opacity: 0;
  transition: opacity 1.4s ease;
  touch-action: none; /* a sideways drag turns the boat */
  cursor: grab;
}

.scene.is-turning { cursor: grabbing; }

.is-ready .scene { opacity: 1; }

/* Keeps the story readable where it sits over the water. */
.stage::after {
  content: '';
  position: absolute;
  inset: auto 0 0 0;
  height: 46%;
  background: linear-gradient(to bottom, rgb(3 37 35 / 0), rgb(1 24 22 / 0.72));
  pointer-events: none;
  z-index: 1;
}

/* ---------- masthead ---------- */

.mast {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 2;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 24px;
  padding: calc(var(--gutter) + env(safe-area-inset-top)) var(--gutter) 0;
  pointer-events: none;
}

.mark {
  margin: 0;
  font-family: var(--font-mark);
  font-weight: 400;
  font-size: clamp(3.1rem, 1.6rem + 6.4vw, 8.75rem);
  line-height: 0.86;
  letter-spacing: -0.015em;
  perspective: 900px;
}

/* One sheet with a crease across it: the lower part sits on the shaded side of the fold.
   js/mark.js reads --crease (in deg) and --crease-at to fold Purr's heads along the same line. */
.mark-sheet {
  --crease: 173deg;
  --crease-at: 55%;
  position: relative;
  display: inline-block;
  background: linear-gradient(var(--crease), var(--paper) 0 var(--crease-at), var(--paper-shade) var(--crease-at) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  transform-origin: 50% 0%;
}

.is-ready .mark-sheet { animation: unfold 1.1s cubic-bezier(.2, .9, .25, 1) both; }

/* PURR is written in Purr's heads, drawn by js/mark.js on a canvas over the word, so they unfold
   with the sheet. The text keeps the layout, and stays on the sheet until the heads are drawn:
   only then is the word positioned, as a positioned word paints apart from the sheet's text. */
.mark-heads { position: absolute; display: none; }
.has-heads .mark-purr { position: relative; visibility: hidden; }
.has-heads .mark-heads { display: block; visibility: visible; }

.ticker {
  text-align: right;
  padding-top: 0.5em;
}

.ticker-symbol {
  font-family: var(--font-mark);
  font-size: clamp(1.1rem, 0.9rem + 0.6vw, 1.5rem);
  line-height: 1.1;
  color: var(--paper);
}

/* The contract address on a slip of paper: the address anyone can select, and a copy tab at its
   folded end. The masthead lets pointers through to the boat, so the slip takes them back. */
.ca {
  position: relative;
  display: flex;
  width: fit-content;
  margin: 10px 0 0 auto;
  border: 1px solid rgb(242 238 227 / 0.22);
  background: rgb(1 24 22 / 0.88); /* cranes fly behind it; the address stays readable */
  pointer-events: auto;
}

/* The slip's top corner, folded down. */
.ca::after {
  content: '';
  position: absolute;
  top: -1px;
  right: -1px;
  width: 9px;
  height: 9px;
  background: linear-gradient(to bottom left, var(--ink) 50%, rgb(211 204 186 / 0.6) 50%);
  pointer-events: none;
}

.ca-address {
  align-self: center;
  padding: 7px 12px;
  font-size: clamp(0.58rem, 1.95vw - 0.3rem, 0.8rem); /* narrow windows squeeze it beside the wordmark */
  line-height: 1.2;
  letter-spacing: 0.02em;
  white-space: nowrap; /* split, an address is easy to misread */
  color: rgb(242 238 227 / 0.92);
  user-select: all;
}

.ca-copy {
  display: grid;
  place-items: center;
  width: 34px;
  margin: 0;
  padding: 0;
  border: 0;
  border-left: 1px solid rgb(242 238 227 / 0.22);
  background: none;
  color: var(--paper);
  cursor: pointer;
  transition: background-color 0.18s ease, color 0.18s ease;
}

.ca-copy:hover { background: rgb(242 238 227 / 0.1); }
.ca-copy.is-copied { color: var(--purr-blue); }

.ca-copy:focus-visible {
  outline: 2px solid var(--purr-blue);
  outline-offset: 2px;
}

/* Both icons share one cell; copying swaps the sheets for a tick. */
.ca-icon {
  grid-area: 1 / 1;
  width: 15px;
  height: 15px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.ca-icon-done,
.is-copied .ca-icon-copy { opacity: 0; transform: scale(0.6); }
.is-copied .ca-icon-done { opacity: 1; transform: none; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ---------- the story ---------- */

.lore {
  position: absolute;
  left: 0;
  bottom: 0;
  z-index: 2;
  width: min(100%, 37rem);
  padding: 0 var(--gutter) calc(var(--gutter) + env(safe-area-inset-bottom));
}

.poem {
  font-size: clamp(1.02rem, 0.88rem + 0.55vw, 1.4rem);
  line-height: 1.5;
  perspective: 700px;
}

.line {
  color: rgb(242 238 227 / 0.84);
  transform-origin: 50% 0%;
  opacity: 0;
}

/* One sentence per line; the long ones wrap, so a little air keeps the sentences apart. */
.line + .line { margin-top: 0.3em; }

.is-told .line { animation: unfold-line 0.9s cubic-bezier(.2, .9, .25, 1) both; }
.is-told .line:nth-child(1) { animation-delay: 0.10s; }
.is-told .line:nth-child(2) { animation-delay: 0.50s; }
.is-told .line:nth-child(3) { animation-delay: 0.90s; }
.is-told .line:nth-child(4) { animation-delay: 1.40s; }

.fold {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px 20px;
  margin-top: clamp(18px, 2.6vh, 28px);
  opacity: 0;
  transition: opacity 0.8s ease 2.4s;
}

.is-told .fold { opacity: 1; }

/* The paper sheet is the ::before so the focus ring outside it is not clipped. */
.fold-button {
  --ear: 14px;
  position: relative;
  border: 0;
  margin: 0;
  padding: 0.78rem 1.5rem 0.78rem 1.25rem;
  background: none;
  color: var(--ink);
  font: 700 1rem/1.2 var(--font-text);
  cursor: pointer;
  isolation: isolate;
  transition: transform 0.18s ease;
}

.fold-button::before,
.fold-button::after {
  content: '';
  position: absolute;
  z-index: -1;
  transition: all 0.22s ease;
}

.fold-button::before {
  inset: 0;
  background: var(--paper);
  clip-path: polygon(0 0, calc(100% - var(--ear)) 0, 100% var(--ear), 100% 100%, 0 100%);
}

/* The folded-down corner. */
.fold-button::after {
  top: 0;
  right: 0;
  width: var(--ear);
  height: var(--ear);
  background: linear-gradient(to bottom left, transparent 50%, var(--paper-shade) 50%);
}

.fold-button:hover { --ear: 20px; }
.fold-button:active { transform: translateY(1px); }

.fold-button:focus-visible {
  outline: 2px solid var(--purr-blue);
  outline-offset: 4px;
}

.fold-hint {
  flex-basis: 100%;
  font-size: 0.875rem;
  color: rgb(242 238 227 / 0.5);
}

.fold-count {
  font-size: 0.95rem;
  color: rgb(242 238 227 / 0.7);
  font-variant-numeric: tabular-nums;
}

/* ---------- loading ---------- */

.loading {
  position: absolute;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  z-index: 3;
  font-size: 0.95rem;
  color: rgb(242 238 227 / 0.6);
  transition: opacity 0.6s ease;
}

.is-ready .loading { opacity: 0; pointer-events: none; }

.has-failed .loading { color: var(--paper); max-width: 22rem; text-align: center; }

/* ---------- motion ---------- */

@property --ear {
  syntax: '<length>';
  inherits: false;
  initial-value: 14px;
}

@keyframes unfold {
  from { transform: rotateX(-86deg); opacity: 0; }
  40% { opacity: 1; }
  to { transform: rotateX(0deg); opacity: 1; }
}

@keyframes unfold-line {
  from { transform: rotateX(-75deg); opacity: 0; }
  to { transform: rotateX(0deg); opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .is-ready .mark-sheet,
  .is-told .line { animation: none; opacity: 1; }
  .fold { transition: none; }
  .scene { transition: none; }
  .ca-copy, .ca-icon { transition: none; }
}

/* Landscape: the story keeps to the left so Purr has room beside it. */
@media (min-width: 721px) and (min-aspect-ratio: 23/20) {
  .lore { width: min(37rem, 46vw); }
}

/* ---------- phones ---------- */

@media (max-width: 720px) {
  .mast { flex-direction: column; gap: 10px; }
  .ticker { text-align: left; padding-top: 0; }
  .ticker-symbol { font-size: 1.05rem; }
  .ca { margin: 8px 0 0; }
  .ca-address { padding: 6px 10px; font-size: min(0.68rem, 3vw); letter-spacing: 0; }
  .ca-copy { width: 30px; }
  .stage::after { height: 58%; }
  .poem { font-size: 1rem; line-height: 1.45; }
  .fold-button { padding: 0.72rem 1.35rem 0.72rem 1.1rem; }
  .fold-hint {
  flex-basis: 100%;
  font-size: 0.875rem;
  color: rgb(242 238 227 / 0.5);
}

.fold-count { font-size: 0.875rem; }
}

@media (max-height: 640px) and (max-width: 720px) {
  .poem { font-size: 0.92rem; line-height: 1.38; }
}
