/* Here be Monsters: the essay, one beat of text at a time over the scene. */
@property --wash { syntax: '<color>'; inherits: true; initial-value: #000; }   /* (so it can fade) */
#essay { position: fixed; inset: 0; pointer-events: none; --wash: #000; transition: --wash 2s ease; }
#essay::before { /* a dark wash behind the text so it reads over the sea (pale on paper) */
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, color-mix(in srgb, var(--wash) 78%, transparent) 0%, color-mix(in srgb, var(--wash) 50%, transparent) 34%, transparent 62%);
}
#essay .beat p, #essay .beat h1, #essay .beat h2 { transition: color 2s ease; }
.beat {
  /* anchored near the top, so the text grows downward as lines arrive; touches pass through to the
     water (you row by holding on it), except on links and buttons */
  position: absolute; left: max(16px, 6vw); top: clamp(56px, 16vh, 200px); width: min(40rem, calc(100% - 32px));
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: opacity .9s ease, visibility 0s linear .9s;
}
.beat.on { opacity: 1; visibility: visible; transition: opacity .6s ease, visibility 0s; }
.beat a, .beat button { pointer-events: auto; }
.beat .pending { display: none; }          /* a line not yet reached */
/* the title and end screens: centred while there's room, from the top when there isn't */
.beat.title-card { top: 0; bottom: 0; display: flex; flex-direction: column; justify-content: safe center; align-items: flex-start; padding: 24px 0; box-sizing: border-box; }
#essay::after { /* the end: everything goes dark behind the last words */
  content: ""; position: absolute; inset: 0; background: #000; opacity: 0; transition: opacity 3.5s ease; z-index: -1;
}
#essay.dark::after { opacity: 1; }
#essay.white::after { background: #f4f4f2; transition-duration: 1.2s; }   /* going over the falls: quickly to white (the paper's white) */
#essay.dark::before { opacity: 0; }   /* (the wash behind the text goes when the screen does: no shadow on the white) */
#essay::before { transition: opacity 1s ease; }
/* the paper world after the fall (the scene's own is in the shaders): dark words, a pale wash
   behind them, and a white screen where it would go dark */
#essay.paper { --wash: #f2f2f0; --ink: #141414; --dim: #6a6a6a; }
#essay.paper::after { background: #f4f4f2; }
.play.again { color: var(--ink); background: transparent; border: 1px solid #444; }
.play.again:hover, .play.again:focus-visible { background: transparent; border-color: var(--ink); }
.beat p { margin: 0 0 .9em; font: 300 clamp(26px, 2.4vw, 36px)/1.35 var(--body); color: var(--ink); text-wrap: pretty; }
.beat strong, .beat b { font-weight: 700; }   /* emphasis: wrap words in <strong> */
.beat a { display: inline-block; color: inherit; text-decoration-color: var(--dim); text-underline-offset: .18em; }   /* (inline-block so it can rise with the words) */
.beat a:hover { text-decoration-color: var(--ink); }
.beat .kicker { font: 700 12px/1.6 var(--body); letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.beat h1, .beat h2 { margin: 0 0 .6em; font: 400 clamp(40px, 6vw, 68px)/1.05 var(--title); text-transform: uppercase; letter-spacing: .01em; color: var(--ink); }
.beat h2 { font-size: clamp(26px, 3.4vw, 38px); }
/* the O of MONSTERS is an eye: its hole filled white, with a slit pupil that watches the pointer.
   --lx/--ly (-1..1) are set by the script (it fades in with its word). The --eye-y/w/h values
   place it in the letter's hole (in em, so it scales with the title). */
.word { white-space: nowrap; }   /* keeps MONSTERS whole */
/* the eye sits behind its letter: it's its own element (<i>) before the O in the markup, both positioned,
   so the O (later) always paints over it (no negative z-index: mobile Safari gets that wrong) */
.eye-o > i { position: absolute; inset: 0; pointer-events: none; }
.eye-o > span { position: relative; }
.eye-o { position: relative; display: inline-block; --eye-y: calc(50% - .12em); --eye-w: .53em; --eye-h: .59em; --lx: 0; --ly: 0; }
.eye-o > i::before, .eye-o > i::after {
  content: ""; position: absolute; left: 50%; top: var(--eye-y); translate: -50% -50%; border-radius: 50%;
  pointer-events: none;
}
.eye-o > i::before { width: var(--eye-w); height: var(--eye-h); background: #dedede; }   /* (the letters' own pale grey) */
.eye-o > i::after {
  width: calc(var(--eye-w)*0.2); height: calc(var(--eye-h)*0.82); background: #050505;
  translate: calc(-50% + var(--lx)*var(--eye-w)*0.24) calc(-50% + var(--ly)*var(--eye-h)*0.14);
  transition: translate .35s cubic-bezier(.2, .7, .3, 1);
}
.beat .claim { margin: 1.3em 0; padding-left: 1em; border-left: 1px solid #555; font-style: italic; font-size: clamp(28px, 2.6vw, 40px); }
.beat .ask { font-size: clamp(30px, 2.9vw, 44px); }
/* the title and end cards (the primer) keep the smaller, original sizes */
.beat.title-card { width: min(31rem, calc(100% - 32px)); }
.beat.title-card p:not(.kicker) { margin-bottom: 1em; font-size: 19px; line-height: 1.5; }
.beat.title-card .ask { font-size: 23px; }
.play {
  margin-top: .6em; font: 700 13px/1.4 var(--body); letter-spacing: .12em; text-transform: uppercase;
  color: var(--bg); background: var(--ink); border: 0; border-radius: 3px; padding: .9em 1.8em; cursor: pointer;
}
.play:hover, .play:focus-visible { background: #fff; outline: 2px solid var(--dim); outline-offset: 3px; }
@media (max-width: 720px) {
  /* narrow screens: the text sits at the top, over the sky or the sea, with the wash from above */
  #essay::before { background: linear-gradient(180deg, color-mix(in srgb, var(--wash) 82%, transparent) 0%, color-mix(in srgb, var(--wash) 55%, transparent) 45%, transparent 72%); }
  .beat { top: max(20px, env(safe-area-inset-top, 0px)); }
  .beat.title-card { top: 0; padding-top: max(20px, env(safe-area-inset-top, 0px)); justify-content: flex-start; }
  .beat p { font-size: 25px; }
  .beat .claim { font-size: 27px; }
  .beat .ask { font-size: 29px; }
  .beat.title-card p:not(.kicker) { font-size: 17px; }
  .beat.title-card .ask { font-size: 20px; }
}
@media (prefers-reduced-motion: reduce) {
  .beat, .beat.on { transition-duration: .2s; }
}

/* the gallery's placards: each clip's label in the water under it (placed by visions.js) */
.vision-label {
  position: absolute; left: 0; top: 0; transform: translate(-50%, 0); white-space: nowrap;
  font: 700 13px/1.4 var(--body); letter-spacing: .12em; text-transform: uppercase; color: var(--ink);
  opacity: 0; pointer-events: none; transition: color 2s ease;
}

/* The monster's eye, on the white after the fall: the whole screen is the eye, a huge pointed slit of
   a pupil in the middle. It appears, blinks (narrows to a sliver), opens back to its own shape (never
   bigger), and fades. (2.2s; started by world.js once the white is complete.) The words go as the
   white comes. */
#essay.white .beat { opacity: 0; transition: opacity .8s ease; }
#bigEye { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#bigEye .pupil {
  position: absolute; left: 50%; top: 50%; width: 13vmin; height: 70vmin; margin: -35vmin 0 0 -6.5vmin;
  background: #0b0b0b; opacity: 0;
  clip-path: polygon(50.0% 0.0%, 61.5% 4.2%, 69.4% 8.3%, 75.8% 12.5%, 81.2% 16.7%, 85.8% 20.8%, 89.7% 25.0%, 92.9% 29.2%, 95.5% 33.3%, 97.5% 37.5%, 98.9% 41.7%, 99.7% 45.8%, 100.0% 50.0%, 99.7% 54.2%, 98.9% 58.3%, 97.5% 62.5%, 95.5% 66.7%, 92.9% 70.8%, 89.7% 75.0%, 85.8% 79.2%, 81.2% 83.3%, 75.8% 87.5%, 69.4% 91.7%, 61.5% 95.8%, 50.0% 100.0%, 38.5% 95.8%, 30.6% 91.7%, 24.2% 87.5%, 18.8% 83.3%, 14.2% 79.2%, 10.3% 75.0%, 7.1% 70.8%, 4.5% 66.7%, 2.5% 62.5%, 1.1% 58.3%, 0.3% 54.2%, 0.0% 50.0%, 0.3% 45.8%, 1.1% 41.7%, 2.5% 37.5%, 4.5% 33.3%, 7.1% 29.2%, 10.3% 25.0%, 14.2% 20.8%, 18.8% 16.7%, 24.2% 12.5%, 30.6% 8.3%, 38.5% 4.2%);   /* pointed at top and bottom */
}
#bigEye.show .pupil { animation: bigPupil 2.2s ease-in-out forwards; }
@keyframes bigPupil {
  0% { opacity: 0; transform: scaleX(.85); }
  16%, 46% { opacity: 1; transform: scaleX(1); }
  49% { transform: scaleX(.05); animation-timing-function: ease-out; }   /* the blink: a snap to a sliver... */
  55%, 86% { opacity: 1; transform: scaleX(1); }   /* ...and straight back (reptilian: about a fifth of a second) */
  100% { opacity: 0; transform: scaleX(1); }
}
@media (prefers-reduced-motion: reduce) { #bigEye.show .pupil { animation-duration: .01s; } }

/* sound: music and voice toggles, small, in the corner, out of the way */
#sound {
  position: fixed; top: max(12px, env(safe-area-inset-top, 0px)); right: max(12px, env(safe-area-inset-right, 0px));
  display: flex; gap: 2px;
}
#sound button {
  width: 36px; height: 36px; padding: 7px; border: 0; border-radius: 50%; background: transparent; color: var(--dim);
  cursor: pointer; opacity: .75; transition: opacity .3s ease, color .3s ease;
}
#sound button:hover, #sound button:focus-visible { opacity: 1; color: var(--ink); outline: none; }
#sound svg { display: block; width: 100%; height: 100%; }
#sound .x { display: none; }
#sound button[aria-pressed="false"] .x { display: inline; }
#sound button[aria-pressed="false"] { opacity: .45; }

/* handwritten notes: scrawled on, over everything (the film's under them) */
.note {
  position: fixed; z-index: 50; pointer-events: none; color: var(--ink, #eee);
  font-family: "Pecita", cursive;
  opacity: 0; transition: opacity .8s ease;
}
.note.show { opacity: .92; }
.note p { margin: 0; font-size: clamp(15px, 1.6vw, 20px); line-height: 1.25; transform: rotate(-4deg); }
.note .arrow { display: block; overflow: visible; }
.note .arrow path { fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 200; stroke-dashoffset: 200; }
.note.show .arrow path { transition: stroke-dashoffset 1.1s cubic-bezier(.5, 0, .3, 1) .3s; stroke-dashoffset: 0; }
.note.show .arrow path + path { transition-delay: 1.3s; transition-duration: .35s; }
/* the settings one: under the corner, its arrow curling up to it */
#settingsNote { top: calc(max(12px, env(safe-area-inset-top, 0px)) + 40px); right: calc(max(12px, env(safe-area-inset-right, 0px)) + 96px); }
#settingsNote .arrow { position: absolute; width: 84px; height: 63px; right: -78px; top: -30px; }
/* the rowing one: above the hint, to its left, its arrow curling down onto it */
#rowNote { bottom: calc(86px + env(safe-area-inset-bottom, 0px)); right: calc(50% + 60px); text-align: right; }
#rowNote .arrow { position: absolute; width: 76px; height: 57px; right: -80px; bottom: -22px; }   /* (its tip just over the hint's words) */
@media (max-width: 720px) { #rowNote { right: auto; left: 16px; bottom: calc(120px + env(safe-area-inset-bottom, 0px)); } }
@media (prefers-reduced-motion: reduce) { .note.show .arrow path { transition: none; } }

/* skip, bottom right: small, handwritten, out of the way */
#skip {
  position: fixed; z-index: 40;
  right: max(16px, env(safe-area-inset-right, 0px)); bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  font: 400 clamp(16px, 1.6vw, 19px)/1 "Pecita", cursive; color: var(--ink, #eee);
  background: none; border: 0; padding: .4em .6em; cursor: pointer; opacity: .55; transition: opacity .3s ease;
}
#skip:hover, #skip:focus-visible { opacity: 1; outline: none; text-decoration: underline; text-underline-offset: .2em; }
#skip[hidden] { display: none; }

/* the two ways in on the title card: with sound, or without */
.begin { display: flex; flex-wrap: wrap; gap: 12px; margin-top: .6em; }
.begin .play { margin-top: 0; }
.play.quiet { color: var(--ink); background: transparent; border: 1px solid #444; }
.play.quiet:hover, .play.quiet:focus-visible { background: transparent; border-color: var(--ink); }
