/* ---------- Font: display type only (headline, big numerals) ---------- */

@font-face {
  font-family: 'Instrument Serif';
  src: url('fonts/InstrumentSerif-Regular.woff2') format('woff2');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304,
    U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* ---------- Tokens ---------- */

:root {
  --ink: #0a0a0a;
  --paper: #ffffff;
  --pivot: #ff3b30;

  --fg: var(--ink);
  --bg: var(--paper);
  --muted: #5e5e5e;
  --rule: rgb(10 10 10 / 0.1);
  --rule-strong: rgb(10 10 10 / 0.22);
  --wash: rgb(10 10 10 / 0.04);

  /* The reading window is always off-white on charcoal. Pure white on
     pure black smears for many readers, so neither end is pure. */
  --win-bg: #1c1c1c;
  --win-fg: #f2f2f2;
  --win-muted: rgb(255 255 255 / 0.62);
  --win-faint: rgb(255 255 255 / 0.3);
  --win-rule: rgb(255 255 255 / 0.14);
  --win-border: transparent;

  --serif: 'Instrument Serif', 'Iowan Old Style', Georgia, 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', 'Helvetica Neue', Helvetica, Arial, sans-serif;

  --gutter: clamp(16px, 3.2vw, 40px);
  --max: 1280px;
  --ease: cubic-bezier(0.215, 0.61, 0.355, 1);
  --fade: 240ms;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fg: #f5f5f5;
    --bg: #121212;
    --muted: #a6a6a6;
    --rule: rgb(255 255 255 / 0.12);
    --rule-strong: rgb(255 255 255 / 0.24);
    --wash: rgb(255 255 255 / 0.05);
    --win-border: rgb(255 255 255 / 0.14);
    color-scheme: dark;
  }
}

@media (prefers-reduced-motion: reduce) {
  :root {
    --fade: 0ms;
  }
  html {
    scroll-behavior: auto !important;
  }
}

/* ---------- Base ---------- */

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-behavior: smooth;
  scroll-padding-top: 24px;
}

button,
a,
label,
.window {
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 400 1rem/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.2em;
}

h1,
h2,
h3,
p {
  margin: 0;
}

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 3px;
}

::selection {
  background: var(--fg);
  color: var(--bg);
}

kbd {
  display: inline-block;
  min-width: 1.6em;
  padding: 0.1em 0.4em;
  border: 1px solid var(--rule-strong);
  font: inherit;
  text-align: center;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  z-index: 10;
  padding: 0.75rem 1rem;
  background: var(--fg);
  color: var(--bg);
}
.skip:focus {
  top: 12px;
}

.wrap {
  width: 100%;
  max-width: var(--max);
  margin-inline: auto;
  padding-inline: var(--gutter);
}

/* ---------- Type ---------- */

.display {
  font: 400 clamp(2.75rem, min(7vw, 10vh), 6.5rem) / 0.95 var(--serif);
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.display-2 {
  font: 400 clamp(2.25rem, 5vw, 4.25rem) / 1 var(--serif);
  letter-spacing: -0.02em;
  text-wrap: balance;
}

.lede {
  max-width: 34em;
  font-size: clamp(1.0625rem, 1.5vw, 1.3125rem);
  line-height: 1.45;
  color: var(--muted);
  text-wrap: pretty;
}

.label {
  font: 600 0.75rem/1.2 var(--sans);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.numeral {
  font: 400 clamp(2.75rem, 5.4vw, 4.75rem) / 0.9 var(--serif);
  letter-spacing: -0.02em;
  font-variant-numeric: lining-nums tabular-nums;
}

/* ---------- Links and buttons ---------- */

.arrow::after {
  content: '\2197';
  display: inline-block;
  margin-left: 0.3em;
  transition: transform var(--fade) var(--ease);
}
.arrow:hover::after {
  transform: translate(2px, -2px);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  min-height: 44px;
  padding: 0.9rem 1.25rem;
  border: 1px solid var(--fg);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font: 600 0.8125rem/1 var(--sans);
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
  cursor: pointer;
  transition: opacity var(--fade) var(--ease);
}
.btn:hover {
  opacity: 0.72;
}
.btn:disabled,
.btn[aria-disabled='true'] {
  opacity: 0.32;
  cursor: not-allowed;
}

.btn-primary {
  min-width: 13.5rem;
  padding: 1.15rem 2rem;
  background: var(--fg);
  color: var(--bg);
}

.btn-quiet {
  border-color: transparent;
  padding-inline: 0.75rem;
}
.btn-quiet:hover {
  opacity: 1;
  text-decoration: underline;
  text-underline-offset: 0.3em;
}

/* ---------- Header / footer ---------- */

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 20px;
  border-bottom: 1px solid var(--rule);
}

/* Two faces, one word: "read" in the sans, "maxxing" in the serif. */
.wordmark {
  display: inline-flex;
  align-items: baseline;
  text-decoration: none;
}
.wordmark b {
  font: 700 1.0625rem/1 var(--sans);
  letter-spacing: -0.01em;
}
.wordmark span {
  font: 400 1.4375rem/1 var(--serif);
  letter-spacing: -0.01em;
}

.site-nav {
  display: flex;
  gap: 1.5rem;
}
.site-nav a {
  text-decoration: none;
}
.site-nav a:hover {
  text-decoration: underline;
}

.site-footer {
  margin-top: clamp(80px, 12vw, 160px);
  padding-block: 28px 40px;
  border-top: 1px solid var(--rule);
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2rem;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.875rem;
}

/* ---------- Hero ---------- */

.hero {
  padding-top: clamp(24px, 3.5vw, 56px);
}

.hero-copy {
  display: grid;
  gap: clamp(16px, 2vw, 24px);
  margin-bottom: clamp(20px, 2.2vw, 32px);
  transition: opacity 600ms var(--ease);
}

/* Dim the page around the reader while it plays. */
body.is-playing .hero-copy,
body.is-playing .site-header {
  opacity: 0.12;
}

/* ---------- Reader ---------- */

.reader {
  --word-scale: 1;
  display: grid;
  gap: 16px;
}

.reader-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  min-height: 32px;
}

.doc-title {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segmented {
  display: inline-flex;
  border: 1px solid var(--rule-strong);
  flex: none;
}
.segmented button {
  min-height: 32px;
  padding: 0.4rem 0.9rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.segmented button[aria-pressed='true'] {
  background: var(--fg);
  color: var(--bg);
}

.window {
  position: relative;
  /* Sized so the window and the Start button fit on a laptop screen. */
  height: clamp(190px, min(32vw, 28vh), 420px);
  overflow: hidden;
  background: var(--win-bg);
  color: var(--win-fg);
  outline: 1px solid var(--win-border);
  outline-offset: -1px;
  container-type: size;
}
.window :focus-visible {
  outline-color: var(--win-fg);
}

.reader[data-mode='focus'] .window {
  height: clamp(360px, 52vw, 560px);
}

/* Sharp mode: one word, pivot pinned to the centre line. */

.sharp {
  position: absolute;
  inset: 0;
  --word-size: calc(var(--word-scale) * min(7.8cqw, 13cqh, 5.75rem));
}

.guides {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 1px;
  height: calc(var(--word-size) * 2.1);
  transform: translate(-50%, -50%);
  background: linear-gradient(
    var(--win-faint) 0 14px,
    transparent 14px calc(100% - 14px),
    var(--win-faint) calc(100% - 14px)
  );
}

.word {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  align-items: center;
  padding-inline: 2%;
  font: 500 var(--word-size) / 1 var(--sans);
  white-space: pre;
  font-kerning: none;
  font-variant-ligatures: none;
  font-feature-settings: 'liga' 0, 'kern' 0;
}
.w-before {
  display: flex;
  justify-content: flex-end;
  overflow: hidden;
}
.w-after {
  overflow: hidden;
}
.w-pivot {
  color: var(--pivot);
}

.context {
  position: absolute;
  left: 50%;
  bottom: 9%;
  width: min(92%, 44rem);
  max-height: 4.5em;
  overflow: hidden;
  transform: translateX(-50%);
  color: var(--win-muted);
  font-size: clamp(0.9375rem, 1.6cqw, 1.125rem);
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  transition: opacity var(--fade) var(--ease);
}
.context mark {
  background: none;
  color: var(--win-fg);
  text-decoration: underline;
  text-decoration-color: var(--pivot);
  text-decoration-thickness: 2px;
  text-underline-offset: 0.25em;
}
.reader[data-state='paused'] .context,
.reader[data-state='ready'] .context {
  opacity: 1;
}

/* Focus mode: the full text, bold word starts, a moving highlight. */

.reader[data-mode='focus'] .sharp {
  display: none;
}

.focus {
  position: absolute;
  inset: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 6% max(6%, calc(50% - 20em));
  color: rgb(255 255 255 / 0.8);
  font: 400 calc(var(--word-scale) * clamp(1.0625rem, 2cqw, 1.4rem)) / 1.75 var(--sans);
  color-scheme: dark;
  cursor: text;
}
.focus p + p {
  margin-top: 1.1em;
}
.focus b {
  font-weight: 700;
}
.focus [data-w] {
  cursor: pointer;
  border-radius: 1px;
}
.focus .is-current {
  color: var(--win-fg);
  background: rgb(255 255 255 / 0.2);
  box-shadow: 0 0 0 0.14em rgb(255 255 255 / 0.2);
}
.focus:focus-visible {
  outline-offset: -3px;
}

/* Done: the window becomes the end card. */

.done {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: clamp(12px, 2.5cqh, 24px);
  padding: 6%;
  background: var(--win-bg);
  text-align: center;
}
.done-title {
  font: 400 clamp(2.5rem, 11cqh, 5rem) / 1 var(--serif);
  letter-spacing: -0.02em;
}
.done-summary {
  color: var(--win-muted);
}
.done-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px 4px;
}
.done .btn {
  border-color: var(--win-fg);
  color: var(--win-fg);
}
.done .btn-quiet {
  border-color: transparent;
}
.done .btn-primary {
  background: var(--win-fg);
  color: var(--win-bg);
}

/* Progress: a hairline track that is also the scrubber. */

.progress {
  position: relative;
  height: 24px;
  cursor: pointer;
  touch-action: none;
}
.progress::before,
.progress-fill {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 11px;
  height: 2px;
}
.progress::before {
  background: var(--rule-strong);
}
.progress-fill {
  background: var(--fg);
  transform-origin: left center;
  transform: scaleX(0);
}

/* Controls */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 8px;
  transition: opacity 400ms var(--ease);
}
.controls .spacer {
  flex: 1;
}

.numerals {
  display: flex;
  gap: clamp(20px, 3vw, 40px);
  align-items: flex-end;
}
.num {
  display: grid;
  gap: 6px;
  justify-items: end;
}
#wpm-value {
  min-width: 3ch;
  text-align: right;
}
#time-left {
  min-width: 4.2ch;
  text-align: right;
}

.speed {
  display: flex;
  align-items: center;
  gap: 12px;
}
.speed input {
  width: clamp(110px, 14vw, 180px);
}

/* Step buttons either side of the slider: a small, predictable nudge. */
.step {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font: 400 1.25rem/1 var(--sans);
  cursor: pointer;
  transition: opacity var(--fade) var(--ease), border-color var(--fade) var(--ease);
}
.step:hover {
  border-color: var(--fg);
}
.step:disabled {
  opacity: 0.32;
  cursor: not-allowed;
}
.speed .num {
  margin-left: 4px;
}

input[type='range'] {
  accent-color: var(--fg);
  height: 24px;
  margin: 0;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 18px;
  color: var(--muted);
  font-size: 0.8125rem;
  transition: opacity 400ms var(--ease);
}

.reader[data-state='playing'] .controls,
.reader[data-state='playing'] .legend,
.reader[data-state='playing'] .reader-meta {
  opacity: 0.28;
}
/* A countdown ticking every second pulls the eye off the word. Hide it
   while reading; it comes back the moment you pause. */
.time-left {
  transition: opacity var(--fade) var(--ease);
}
.reader[data-state='playing'] .time-left {
  opacity: 0;
}

.reader[data-state='playing'] .controls:hover,
.reader[data-state='playing'] .controls:focus-within,
.reader[data-state='playing'] .reader-meta:hover,
.reader[data-state='playing'] .reader-meta:focus-within {
  opacity: 1;
}

.note {
  font-size: 0.875rem;
  color: var(--muted);
}

/* Editor: long pasted text opens in a full-size sheet. */

.editor {
  width: min(1100px, calc(100vw - 2 * var(--gutter)));
  height: min(900px, calc(100dvh - 2 * var(--gutter)));
  max-width: none;
  max-height: none;
  margin: auto;
  padding: 0;
  border: 1px solid var(--rule-strong);
  border-radius: 0;
  background: var(--bg);
  color: var(--fg);
}
.editor[open] {
  animation: editor-in var(--fade) var(--ease);
}
.editor::backdrop {
  background: rgb(10 10 10 / 0.6);
}
@keyframes editor-in {
  from {
    opacity: 0;
  }
}
html:has(.editor[open]) {
  overflow: hidden;
}

.editor-sheet {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.editor-bar {
  display: flex;
  align-items: center;
  gap: 12px 24px;
  min-height: 64px;
  padding: 10px clamp(16px, 3vw, 32px);
  border-bottom: 1px solid var(--rule);
}
.editor-bar:last-child {
  border-top: 1px solid var(--rule);
  border-bottom: 0;
}
.editor-bar h2 {
  flex: 1;
}
.editor-bar #editor-count {
  flex: 1;
}
.editor-bar .btn-primary {
  min-width: 9rem;
}

.editor textarea {
  flex: 1;
  min-height: 0;
  width: 100%;
  padding: clamp(20px, 4vw, 48px) max(clamp(16px, 3vw, 32px), calc(50% - 22em));
  border: 0;
  resize: none;
  background: transparent;
  font: 400 clamp(1.0625rem, 1.3vw, 1.1875rem) / 1.7 var(--sans);
  white-space: pre-wrap;
}
.editor textarea:focus-visible {
  outline: none;
}

@media (hover: none) {
  .editor-keys {
    display: none;
  }
}

@media (max-width: 720px) {
  .editor {
    width: 100vw;
    height: 100dvh;
    border: 0;
  }
}

/* Video export status: its own line under the controls. */

.export-status {
  order: 10;
  flex: 1 1 100%;
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 12px;
  min-height: 44px;
  color: var(--muted);
}
.export-status .btn {
  min-height: 32px;
  padding-block: 0.4rem;
}
.export-bar {
  position: relative;
  display: inline-block;
  width: 96px;
  height: 2px;
  background: var(--rule-strong);
}
.export-fill {
  position: absolute;
  inset: 0;
  background: var(--fg);
  transform-origin: left center;
  transform: scaleX(0);
}
.export-percent {
  min-width: 3.5ch;
  font-variant-numeric: tabular-nums;
  color: var(--fg);
}

/* ---------- Sections ---------- */

.section {
  padding-top: clamp(80px, 11vw, 160px);
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 20px;
  padding-top: 20px;
  border-top: 1px solid var(--rule-strong);
}

.section-head {
  grid-column: 1 / 4;
}

.section-body {
  grid-column: 4 / 13;
  display: grid;
  gap: clamp(28px, 3.5vw, 44px);
  max-width: 52rem;
}

/* ---------- Source field: paste text or a link ---------- */

.source {
  display: grid;
  gap: 10px;
  margin-bottom: clamp(24px, 3vw, 36px);
  transition: opacity 600ms var(--ease);
}
.source-row {
  display: flex;
  gap: 8px;
}
.source textarea {
  flex: 1;
  height: 52px;
  resize: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.source .btn-primary {
  min-width: 7.5rem;
}
body.is-playing .source:not(:focus-within) {
  opacity: 0.12;
}

textarea {
  width: 100%;
  min-height: 48px;
  padding: 0.85rem 1rem;
  border: 1px solid var(--rule-strong);
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  font: 400 1.0625rem/1.5 var(--sans);
}
input:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: -1px;
  border-color: var(--fg);
}
::placeholder {
  color: var(--muted);
  opacity: 0.8;
}

.message {
  min-height: 1.5em;
  font-weight: 500;
}
.message:empty {
  min-height: 0;
}
.message.is-error {
  padding-left: 0.85rem;
  border-left: 2px solid var(--fg);
}
.message.is-loading::before {
  content: '';
  display: inline-block;
  width: 0.8em;
  height: 0.8em;
  margin-right: 0.6em;
  border: 1.5px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  vertical-align: -0.05em;
  animation: spin 0.8s linear infinite;
}
@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}
@media (prefers-reduced-motion: reduce) {
  .message.is-loading::before {
    animation: none;
  }
}

/* ---------- How it works ---------- */

.stat {
  display: grid;
  gap: 12px;
}
.stat-figure {
  font: 400 clamp(4.5rem, 13vw, 11rem) / 0.85 var(--serif);
  letter-spacing: -0.03em;
}

.about {
  max-width: 40em;
  font-size: clamp(1.0625rem, 1.5vw, 1.25rem);
  line-height: 1.55;
  text-wrap: pretty;
}

/* ---------- Mobile ---------- */

@media (max-width: 860px) {
  .section-head,
  .section-body {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .site-nav {
    display: none;
  }
  .controls .btn-primary {
    flex: 1 1 100%;
  }
  .controls .spacer {
    display: none;
  }
  .controls,
  .numerals {
    min-width: 0;
  }
  .numerals {
    flex: 1 1 100%;
    justify-content: space-between;
  }
  .num {
    justify-items: start;
  }
  .speed {
    flex: 1 1 100%;
  }
  .speed {
    gap: 8px;
    min-width: 0;
  }
  .speed input {
    flex: 1;
    width: auto;
    min-width: 0;
  }
  .step {
    width: 36px;
    height: 36px;
  }
  .legend {
    display: none;
  }
}

@media (hover: none) {
  .legend {
    display: none;
  }
}

/* Very narrow phones: the speed row keeps the full width, time drops below. */
@media (max-width: 380px) {
  .numerals {
    flex-wrap: wrap;
    row-gap: 12px;
  }
}
