/* Stutter. One sheet, two hands: yours sets the words large, in outline; the voice fills in each word once it has
   said it, and writes above it, small, what it actually pronounced on the way there: false starts first. */

:root {
  --paper: #ffd21f;
  --ink: #0c0b07;
  --quiet: color-mix(in srgb, var(--ink) 66%, var(--paper));
  --faint: color-mix(in srgb, var(--ink) 38%, var(--paper));
  --gutter: clamp(20px, 4.4vw, 64px);
  --fs: 96px;
  --gs: max(13px, calc(var(--fs) * .2));      /* the voice's hand */
  --display: "Bricolage Grotesque", "Helvetica Neue", Arial, sans-serif;
  --phon: "Gentium Book Plus", "Charis SIL", "Doulos SIL", "Times New Roman", serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root { --paper: #0d0c08; --ink: #ffd21f; --quiet: color-mix(in srgb, var(--ink) 62%, var(--paper)); --faint: color-mix(in srgb, var(--ink) 40%, var(--paper)); color-scheme: dark; }
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; position: fixed; inset: 0; overflow: hidden;
  background: var(--paper); color: var(--ink);
  font-family: var(--display); font-size: 14px; line-height: 1.35;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}

#stage {
  position: fixed; left: 0; top: 0; width: 100%;
  height: var(--vvh, 100dvh);
  transform: translateY(var(--vvt, 0px));
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 18px) 0 calc(env(safe-area-inset-bottom) + 14px);
}

/* ── the little there is to read ─────────────────────────────── */

header {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: baseline;
  column-gap: 22px; padding: 0 var(--gutter); flex: none;
}
h1 { margin: 0; font-size: 14px; font-weight: 750; letter-spacing: .01em; }
.what { margin: 0; max-width: 44ch; color: var(--quiet); font-weight: 450; text-wrap: balance; }

button { font: inherit; color: inherit; background: none; border: 0; padding: 0; margin: 0; cursor: pointer; border-radius: 0; }
a { color: inherit; text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; }
#tune { font-weight: 600; padding: 6px 0 6px 12px; margin: -6px 0; }
#tune::after { content: " +"; }
#tune[aria-expanded="true"]::after { content: " \2212"; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }
#field:focus-visible { outline: 0; }

/* ── the knobs ───────────────────────────────────────────────── */

#knobs {
  flex: none; display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px 36px;
  padding: 22px var(--gutter) 0;
}
#knobs[hidden] { display: none; }
.knob { display: grid; grid-template-columns: 1fr auto; align-items: baseline; row-gap: 4px; font-weight: 600; }
.knob output { font-variant-numeric: tabular-nums; font-weight: 450; color: var(--quiet); }
.knob input, .knob .pick { grid-column: 1 / -1; }
.pick { display: flex; gap: 18px; height: 22px; align-items: center; }
.pick button { font-weight: 450; color: var(--quiet); padding: 4px 0; }
.pick button[aria-pressed="true"] { color: var(--ink); font-weight: 750; box-shadow: 0 2px 0 var(--ink); }

input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; margin: 0; background: none; cursor: pointer; display: block; }
input[type="range"]::-webkit-slider-runnable-track { height: 2px; background: var(--ink); }
input[type="range"]::-moz-range-track { height: 2px; background: var(--ink); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 14px; height: 14px; margin-top: -6px; border-radius: 50%; background: var(--ink); border: 0; }
input[type="range"]::-moz-range-thumb { width: 14px; height: 14px; border-radius: 50%; background: var(--ink); border: 0; }

/* ── the sheet: a real textarea, and its drawing underneath ──── */

/* the text stands on the rule and grows upward from it */
#page { flex: 1 1 auto; min-height: 0; margin-top: 6px; display: flex; flex-direction: column; justify-content: flex-end; cursor: text; }
#sheet { position: relative; flex: none; height: 100%; max-height: 100%; }
#sheet.scrolled { -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 calc(var(--fs) * .5)); mask-image: linear-gradient(to bottom, transparent 0, #000 calc(var(--fs) * .5)); }

/* the rule is also the loading bar: it is drawn across as the voice arrives */
#rule { flex: none; height: 2px; margin: 0 var(--gutter); background: var(--faint); }
#rule i { display: block; height: 100%; background: var(--ink); transform-origin: 0 50%; transform: scaleX(var(--load, 0)); transition: transform .25s linear; }

#mirror, #field {
  position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; border: 0;
  padding: calc(var(--fs) * .2 + var(--gs) * 1.5) var(--gutter) calc(var(--fs) * .1);
  font-family: var(--display); font-size: var(--fs); font-weight: 680; line-height: 1.42; letter-spacing: .012em;
  font-optical-sizing: auto; font-kerning: none; font-variant-ligatures: none; font-feature-settings: "kern" 0, "liga" 0, "calt" 0;
  white-space: pre-wrap; overflow-wrap: break-word; word-break: normal; text-align: left; tab-size: 4;
  -webkit-text-size-adjust: 100%;
}
#mirror { overflow: hidden; pointer-events: none; user-select: none; }
#ink { position: relative; }
#field {
  display: block; resize: none; outline: 0; background: transparent; border-radius: 0;
  color: transparent; caret-color: var(--ink); overflow-x: hidden; overflow-y: auto;
  scrollbar-width: none; -webkit-appearance: none; appearance: none; overscroll-behavior: contain;
}
#field::-webkit-scrollbar { display: none; }
#field::selection { background: color-mix(in srgb, var(--ink) 24%, transparent); color: transparent; }

/* every letter carries the same outline, so filling one in never moves it */
#ink span {
  --sw: max(1.5px, .032em);
  -webkit-text-stroke: var(--sw) var(--ink); paint-order: stroke fill;
  color: var(--paper);
}
#ink .s1, #ink .s2 { color: var(--ink); }                 /* said; being said */
#ink .ph { -webkit-text-stroke-color: var(--faint); }     /* the invitation is nobody's writing yet */
@media (prefers-color-scheme: dark) { #ink span { --sw: max(2px, .04em); } }

/* ── the voice's hand: above each word, what was actually pronounced ── */

#gloss { position: absolute; left: 0; top: 0; width: 0; height: 0; }
.g {
  position: absolute; left: 0; top: 0; white-space: nowrap;
  font-family: var(--phon); font-size: var(--gs); font-weight: 400; line-height: 1.2; letter-spacing: .01em;
  font-kerning: normal; font-feature-settings: normal; color: var(--ink);
}
.g span { margin-right: .5em; }
.g .try { color: var(--quiet); }                          /* a false start */
.g.tight .try { display: none; }

/* where the voice is: the full stop that travels with its writing, and swells with the sound */
#ball {
  position: absolute; left: 0; top: 0; width: var(--fs); height: var(--fs); margin: calc(var(--fs) * -.5) 0 0 calc(var(--fs) * -.5);
  border-radius: 50%; background: var(--ink); will-change: transform; transform: scale(0);
}

/* ── below the rule ──────────────────────────────────────────── */

footer {
  flex: none; display: flex; align-items: baseline; gap: 20px; padding: 10px var(--gutter) 0; min-height: 28px;
  font-size: 12px; color: var(--quiet); font-weight: 450;
}
footer i { font-style: normal; }
#status { margin: 0; color: var(--ink); font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; transition: opacity .5s; min-width: 0; }
#status b { font-weight: 450; font-variant-numeric: tabular-nums; margin-left: .6em; }
#status.gone { display: none; }
footer .credit:first-of-type { margin-right: auto; }
#status:not(.gone) { margin-right: auto; }
#status:not(.gone) + .credit { margin-right: 0; }

/* ── small sheets ────────────────────────────────────────────── */

@media (max-width: 760px) {
  header { grid-template-columns: 1fr auto; row-gap: 5px; }
  .what { grid-column: 1 / -1; grid-row: 2; font-size: 13px; max-width: 40ch; }
  #knobs { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 26px; padding-top: 14px; }
  .knob.voice { grid-column: 1 / -1; grid-template-columns: auto 1fr; column-gap: 26px; }
  .knob.voice .pick { grid-column: 2; }
  footer { font-size: 11px; }
  footer i { display: none; }
  #status:not(.gone) + .credit { display: none; }
}
/* the soft keyboard is up, or the window is short: only the sheet */
@media (max-height: 560px) {
  #stage { padding-top: calc(env(safe-area-inset-top) + 10px); padding-bottom: 6px; }
  .what, footer .credit { display: none; }
  footer { min-height: 0; padding-top: 4px; }
  #knobs { gap: 4px 26px; padding-top: 8px; }
}
@media (prefers-reduced-motion: reduce) { #rule i { transition: none; } }
