/* Layout: one centred column read top to bottom: the burning 22, the title and byline,
   the emblem (play button), a line about the score, the chapter picker between Prev and
   Next, the track's progress, Download and Repeat, then the reading speed. */
:root {
  --void: #060505;
  --stripe: rgba(255, 244, 232, 0.07);
  --bone: #ece6dc;
  --ash: #948b82;
  --smoke: #3b3633;
  --hairline: rgba(236, 230, 220, 0.16);
  --ember: #ec7a2c;
  --flame: #d8381c;
  --glow: rgba(160, 34, 14, 0.6);

  --font-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-serif: "Gelasio", Georgia, "Times New Roman", serif;
  --track-wide: 0.42em;
  --track: 0.24em;

  /* The 22 and the emblem are the same size here as on bradythomasmott.com: keep these
     in step with that site's styles.css. On bigger screens the 22 shrinks to leave room
     for the player, so the whole page fits on one screen. */
  --vh: 1vh;
  /* The height of everything on the soundtrack page except the 22. With the reading-speed
     slider showing it's 548px (488px on short screens); with "200 words per minute" instead, 498px. */
  --reserve: 498px;
  --art-w: min(100%, calc(64 * var(--vh)));
  --emblem: clamp(104px, 28vw, 116px);
  /* How far down the page the 22's frame starts: the column is centred when there's room.
     bradythomasmott.com sends its 22 here when the emblem is clicked. */
  --stage-top: max(10px, (100 * var(--vh) - var(--reserve) - var(--art-w) / 1.55) / 2 + 10px);

  /* Spacing between the player's parts: large, medium, small. */
  --gap-l: 26px;
  --gap-m: 22px;
  --gap-s: 10px;

  --thumb: 14px; /* slider handle; app.js reads this too */

  color-scheme: dark;
  box-sizing: border-box;
  height: 100%;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--void);
}
@supports (height: 1svh) { :root { --vh: 1svh; } }
@media (min-width: 600px) {
  :root { --art-w: min(100%, clamp(260px, (100 * var(--vh) - var(--reserve)) * 1.55, 620px)); }
}
@media (min-width: 600px) and (max-height: 760px) {
  :root { --reserve: 438px; --emblem: 100px; --gap-l: 18px; --gap-m: 16px; --gap-s: 6px; }
}

/* Whole pixels for the 22: an even width (so it centres on a whole pixel) and a whole-pixel
   top. Its canvas never sits between pixels, and both sites' 22s land on exactly the
   same pixels. Keep in step with the other site's styles.css. */
@supports (width: round(1.5px, 1px)) {
  :root {
    --art-w-px: round(down, var(--art-w), 2px);
    --stage-top: round(max(10px, (100 * var(--vh) - var(--reserve) - var(--art-w-px) / 1.55) / 2 + 10px), 1px);
  }
  :root .art { width: var(--art-w-px); } /* :root wins over the .art rule further down */
}

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

body {
  display: flex;
  flex-direction: column;
  margin: 0;
  min-height: 100%;
  background-color: var(--void);
  /* The cover's soft vertical bars. */
  background-image: linear-gradient(90deg, transparent 0 16%, var(--stripe) 40% 56%, transparent 80% 100%);
  background-size: clamp(56px, 8.7vw, 118px) 100%;
  background-position: center top;
  color: var(--bone);
  font-family: var(--font-display);
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}

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

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  flex: 1 0 auto;
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  overflow-x: clip; /* glows and tooltips never cause sideways scrolling */
  padding-block: var(--stage-top) var(--gap-m);
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  text-align: center;
}

/* Title and byline, in widely spaced capitals as on the cover. */
.credits {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
}
.kicker, .byline {
  margin: 0;
  font-weight: 650;
  font-stretch: 115%;
  text-transform: uppercase;
  letter-spacing: var(--track-wide);
  /* Tracking adds space after the last letter; pad the start to re-centre. */
  padding-inline-start: var(--track-wide);
}
.kicker { font-size: clamp(12px, 3.3vw, 14px); }
.byline { font-size: clamp(10px, 2.6vw, 11px); color: var(--ash); }

/* The byline links back to bradythomasmott.com. */
a.byline { text-decoration: none; transition: color 0.2s ease; }
a.byline:hover { color: var(--ember); }
a.byline:focus-visible { outline: 1px solid var(--ember); outline-offset: 6px; }

/* The 22. A dark halo knocks the stripes back behind it, as on the cover. */
.art {
  position: relative;
  width: var(--art-w);
  max-width: 100%;
  aspect-ratio: 1.55;
  margin: 0;
  flex: none;
}
.art::before {
  content: "";
  position: absolute;
  inset: 2% -6% -4%;
  background: radial-gradient(closest-side, var(--void) 62%, transparent);
  pointer-events: none;
}
.art canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

.player {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 400px;
  margin-top: var(--gap-l);
}

/* The emblem from the cover, used as the play button. */
.emblem {
  position: relative;
  isolation: isolate;
  width: var(--emblem);
  aspect-ratio: 1;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: none;
  color: var(--bone);
  cursor: pointer;
  transition: transform 0.25s ease;
}
.emblem::before {
  content: "";
  position: absolute;
  inset: -55%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--glow), transparent 72%);
  opacity: 0.55;
  transition: opacity 1s ease;
  pointer-events: none; /* the glow is bigger than the button; don't let it catch taps */
}
.emblem::after {
  content: "";
  position: absolute;
  inset: -22%;
  z-index: -1;
  border-radius: 50%;
  background: radial-gradient(closest-side, var(--void) 70%, transparent);
  pointer-events: none;
}
.emblem:hover { transform: scale(1.03); }
.emblem:active { transform: scale(0.97); }
.emblem:focus-visible { outline: 1px solid var(--ember); outline-offset: 8px; }
.emblem:disabled { cursor: default; opacity: 0.5; transform: none; }
.emblem svg { display: block; width: 100%; height: 100%; overflow: visible; }

.ring { fill: none; stroke: currentColor; stroke-width: 1.6; }
.ring-inner { stroke-width: 1.1; opacity: 0.85; }
.ring-progress {
  fill: none;
  stroke: var(--ember);
  stroke-width: 2.6;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  filter: drop-shadow(0 0 3px var(--flame));
}
.ticks { fill: none; stroke: currentColor; stroke-width: 1.6; }
.bars { fill: none; stroke: currentColor; stroke-width: 3.6; }
.glyph-play { fill: currentColor; }
.glyph-pause, .glyph-load { fill: none; stroke: currentColor; stroke-width: 4; }
.glyph-load { stroke-width: 3.6; transform-origin: 60px 60px; animation: spin 1.8s linear infinite; }
.glyph-pause, .glyph-load { display: none; }

.player[data-state="playing"] .glyph-play,
.player[data-state="loading"] .glyph-play { display: none; }
.player[data-state="playing"] .glyph-pause,
.player[data-state="loading"] .glyph-load { display: inline; }
.player[data-state="playing"] .emblem::before,
.player[data-state="loading"] .emblem::before { opacity: 1; animation: breathe 3.6s ease-in-out infinite; }

@keyframes spin { to { transform: rotate(90deg); } }
@keyframes breathe { 50% { transform: scale(1.08); opacity: 0.8; } }

/* "The novel 22 was written with an accompanying soundtrack / Listen as you read". */
.intro {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-top: var(--gap-m);
}
.lede, .cue {
  margin: 0;
  font-size: 11px;
  font-weight: 650;
  font-stretch: 112%;
  line-height: 1.75;
  text-transform: uppercase;
  text-wrap: balance;
}
.lede {
  max-width: 31em;
  letter-spacing: var(--track);
  padding-inline-start: var(--track);
  color: var(--ash);
}
.cue {
  letter-spacing: 0.34em;
  padding-inline-start: 0.34em;
  color: var(--ember);
}

/* Player messages are read out to screen readers, and only shown when they matter
   (a chapter link waiting for a tap, or a track that won't load). Then they stand in for the cue. */
.status {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.player[data-notice] .cue-text { display: none; }
.player[data-notice] .status {
  position: static;
  display: block;
  width: auto; height: auto;
  overflow: visible; clip: auto; white-space: normal;
  max-width: 34em;
  letter-spacing: var(--track);
  padding-inline-start: var(--track);
  margin-inline-start: calc(-1 * 0.34em);
  color: var(--bone);
}
.player[data-waiting] .status { color: var(--ember); }

/* Prev, the chapter picker and Next, as one bar between two hairlines. */
.chapter {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 46px;
  align-items: stretch;
  width: 100%;
  margin-top: var(--gap-m);
  border-block: 1px solid var(--hairline);
}

/* A styled face over a native <select>, so phones get their own picker wheel. */
.picker { position: relative; min-width: 0; }
.picker-face {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 46px;
  height: 100%;
  padding: 8px 4px;
  pointer-events: none;
}
.face-line { display: inline-flex; align-items: center; gap: 10px; }
.face-label {
  font-size: 13px;
  font-weight: 650;
  font-stretch: 115%;
  letter-spacing: var(--track);
  padding-inline-start: calc(var(--track) + 20px); /* balances the chevron on the right */
  text-transform: uppercase;
  transition: color 0.2s ease;
}
.face-title { font-family: var(--font-serif); font-style: italic; font-size: 16px; color: var(--ash); }
.chevron {
  width: 10px;
  height: 7px;
  fill: none;
  stroke: var(--ash);
  stroke-width: 1.5;
  transition: stroke 0.2s ease;
}
.picker:hover .face-label, .picker:focus-within .face-label { color: var(--ember); }
.picker:hover .chevron, .picker:focus-within .chevron { stroke: var(--ember); }
.picker:focus-within { outline: 1px solid var(--ember); outline-offset: -1px; }
.picker:has(select:focus:not(:focus-visible)) { outline: none; }
.picker select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
  font-size: 16px; /* 16px stops iOS from zooming on focus */
  color: var(--bone);
  background: var(--void);
  -webkit-appearance: none;
  appearance: none;
}

/* Icon buttons: Prev, Next, Download and Repeat. */
.icon {
  position: relative;
  display: inline-grid;
  place-items: center;
  min-width: 46px;
  min-height: 46px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ash);
  cursor: pointer;
  transition: color 0.2s ease;
}
.icon svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
}
.icon:hover { color: var(--bone); }
.icon:focus-visible { outline: 1px solid var(--ember); outline-offset: -4px; }
.icon[aria-pressed="true"] { color: var(--ember); }
.icon:disabled, .icon[aria-disabled="true"] { opacity: 0.3; cursor: default; color: var(--ash); }

/* The words for each icon, shown when it's hovered or reached with the keyboard. */
.tip::after {
  content: attr(data-tip);
  position: absolute;
  z-index: 2;
  bottom: calc(100% + 2px);
  left: 50%;
  translate: -50% 4px;
  padding: 7px 10px 7px calc(10px + var(--track));
  font-size: 10px;
  font-weight: 650;
  font-stretch: 112%;
  letter-spacing: var(--track);
  line-height: 1;
  text-transform: uppercase;
  white-space: nowrap;
  color: var(--bone);
  background: rgba(10, 8, 8, 0.94);
  border: 1px solid var(--hairline);
  border-radius: 3px;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transition: opacity 0.15s ease, translate 0.15s ease, visibility 0s linear 0.15s;
}
.tip-start::after { left: 0; translate: 0 4px; }
.tip-end::after { left: auto; right: 0; translate: 0 4px; }
#repeat[aria-pressed="true"]::after { content: "Repeat: on"; }
#repeat[aria-pressed="false"]::after { content: "Repeat: off"; }
.tip:focus-visible::after { opacity: 1; visibility: visible; translate: -50% 0; transition-delay: 0s; }
@media (hover: hover) {
  .tip:hover::after { opacity: 1; visibility: visible; translate: -50% 0; transition-delay: 0.3s, 0.3s, 0.3s; }
}
.tip-start:focus-visible::after, .tip-end:focus-visible::after { translate: 0 0; }
@media (hover: hover) {
  .tip-start:hover::after, .tip-end:hover::after { translate: 0 0; }
}

/* Elapsed, the position slider, and the track's length. */
.scrub {
  display: grid;
  grid-template-columns: 3.6em minmax(0, 1fr) 3.6em;
  align-items: center;
  gap: 10px;
  width: 100%;
  margin-top: var(--gap-s);
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--ash);
  font-variant-numeric: tabular-nums;
}
.scrub span:first-child { text-align: left; }
.scrub span:last-child { text-align: right; }

.controls {
  display: flex;
  justify-content: center;
  gap: 28px;
}

/* Sliders. app.js makes a touch or click anywhere along one move it. */
input[type="range"] {
  --p: 0; /* how far along, 0 to 1 */
  display: block;
  width: 100%;
  height: 30px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: none;
  -webkit-appearance: none;
  appearance: none;
}
input[type="range"]:disabled { cursor: default; }
input[type="range"]::-webkit-slider-runnable-track {
  height: 2px;
  background: linear-gradient(90deg, var(--ember) calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--p)), var(--smoke) 0);
}
input[type="range"]::-webkit-slider-thumb {
  width: var(--thumb);
  height: var(--thumb);
  margin-top: calc(1px - var(--thumb) / 2);
  border: 0;
  border-radius: 50%;
  background: var(--bone);
  box-shadow: 0 0 10px var(--ember);
  -webkit-appearance: none;
  appearance: none;
}
input[type="range"]::-moz-range-track { height: 2px; background: var(--smoke); }
input[type="range"]::-moz-range-progress { height: 2px; background: var(--ember); }
input[type="range"]::-moz-range-thumb {
  width: var(--thumb); height: var(--thumb); border: 0; border-radius: 50%;
  background: var(--bone); box-shadow: 0 0 10px var(--ember);
}
input[type="range"]:disabled::-webkit-slider-thumb { background: var(--smoke); box-shadow: none; }
input[type="range"]:disabled::-moz-range-thumb { background: var(--smoke); box-shadow: none; }
input[type="range"]:focus-visible { outline: 1px solid var(--ember); outline-offset: 2px; }
input[type="range"][data-pointer]:focus-visible { outline: none; }

/* Reading speed: five notches from slower (cool, like the top of the 22) to faster (burning). */
.speed[hidden] { display: none; }
.speed {
  display: flex;
  flex-direction: column;
  width: 100%;
  margin-top: var(--gap-s);
}
.speed-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  font-size: 11px;
  font-weight: 650;
  font-stretch: 112%;
  letter-spacing: var(--track);
  text-transform: uppercase;
  color: var(--ash);
}
.speed-head label, .speed-head output { white-space: nowrap; }
.speed-head output { color: var(--bone); font-variant-numeric: tabular-nums; }
.speed-help {
  margin: 8px 0 2px;
  font-family: var(--font-serif);
  font-style: italic;
  font-size: 15px;
  line-height: 1.4;
  color: var(--ash);
}
.speed-track { position: relative; }
#speed::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(236, 230, 220, 0.5), #f8b24c 45%, var(--ember) 72%, var(--flame));
}
#speed::-webkit-slider-thumb { margin-top: calc(1.5px - var(--thumb) / 2); }
#speed::-moz-range-track {
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(90deg, rgba(236, 230, 220, 0.5), #f8b24c 45%, var(--ember) 72%, var(--flame));
}
#speed::-moz-range-progress { background: transparent; }
/* One notch under each stop on the slider. */
.speed-marks { position: absolute; inset: 0; pointer-events: none; }
.speed-marks span {
  position: absolute;
  top: 50%;
  left: calc(var(--thumb) / 2 + (100% - var(--thumb)) * var(--at));
  width: 1px;
  height: 11px;
  translate: -50% -50%;
  background: var(--ash);
  opacity: 0.55;
  transition: opacity 0.2s ease, background-color 0.2s ease;
}
.speed-marks span.on { background: var(--bone); opacity: 1; }

/* Arriving from the emblem on bradythomasmott.com (index.html). That page ends on the 22 and
   the stripes exactly as they sit here, so the rest fades in beneath them, in reading order,
   and the emblem draws itself in as it does there. */
.arriving .credits,
.arriving .player > * { animation: arrive 0.9s cubic-bezier(0.2, 0.6, 0.2, 1) backwards; }
.arriving .credits { animation-delay: 0.05s; }
.arriving .emblem { animation-delay: 0.2s; }
.arriving .intro { animation-delay: 0.45s; }
.arriving .chapter { animation-delay: 0.55s; }
.arriving .scrub { animation-delay: 0.62s; }
.arriving .controls { animation-delay: 0.68s; }
.arriving .speed, .arriving .pace { animation-delay: 0.74s; }
.arriving .emblem .ring:not(.ring-inner) { stroke-dasharray: 327; animation: draw 1.4s 0.2s cubic-bezier(0.3, 0.6, 0.2, 1) backwards; }
.arriving .emblem .ring-inner { stroke-dasharray: 286; animation: draw 1.4s 0.4s cubic-bezier(0.3, 0.6, 0.2, 1) backwards; }
@keyframes arrive { from { opacity: 0; transform: translateY(8px); } }
@keyframes draw { from { stroke-dashoffset: 327; } }

/* The pace the score is written for, shown instead of the reading-speed slider until
   the slower and faster versions are posted. */
.pace {
  margin: var(--gap-m) 0 0;
  font-size: 11px;
  font-weight: 650;
  font-stretch: 112%;
  letter-spacing: var(--track);
  padding-inline-start: var(--track);
  text-transform: uppercase;
  color: var(--ash);
}

/* Opened from a QR code and waiting for the first tap: the whole page is the play button. */
.tap-to-play body { cursor: pointer; }
.player[data-waiting] .emblem::before { opacity: 1; animation: beckon 1.8s ease-in-out infinite; }
@keyframes beckon { 50% { transform: scale(1.16); opacity: 0.7; } }

.noscript {
  margin: 0 auto;
  padding: 0 16px 24px;
  font-size: 12.5px;
  color: var(--ash);
  text-align: center;
}

/* Narrow phones: tighten the small capitals so lines don't break. */
@media (max-width: 380px) {
  .speed-head { letter-spacing: 0.14em; font-size: 10.5px; }
}
@media (max-width: 340px) {
  .speed-head { gap: 8px; letter-spacing: 0.08em; font-size: 10px; }
  .lede { letter-spacing: 0.16em; padding-inline-start: 0.16em; }
}

@media (prefers-reduced-motion: reduce) {
  .emblem, .icon, .face-label, .chevron, a.byline, .speed-marks span, .tip::after { transition: none; }
  .player[data-state] .emblem::before, .player[data-waiting] .emblem::before { animation: none; }
  .glyph-load { animation: none; }
  .arriving .credits, .arriving .player > *, .arriving .emblem .ring { animation: none; }
}
