:root {
  --wall: #18120e;
  --wall-2: #2a1f17;
  --wood: #5b3c26;
  --wood-light: #84593a;
  --wood-dark: #2f1d0e;
  --cream: #efe6d2;
  --muted: #a8977b;
  --gold: #c9a45c;
  --gold-light: #ead39a;
  --paper: #f4eddc;
  --card: #fbf7ec;
  --ink: #1c1915;
  --red-ink: #b3261e;
  --chrome: #d4d7da;
  --chrome-dark: #868b90;

  /* The typewriter: a 1950s portable in seafoam enamel. */
  --enamel: #8fbaa8;
  --enamel-hi: #c6e0d4;
  --enamel-lo: #5f8c7b;
  --enamel-deep: #2f4b41;
  --keycap: #f4ecda;

  --fell: "IM Fell English", Georgia, "Times New Roman", serif;
  --type: "Special Elite", "Courier Prime", "Courier New", monospace;
  --mono: "Courier Prime", "Courier New", monospace;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 70% 55% at 30% -8%, rgba(255, 196, 120, 0.17), transparent 65%),
    linear-gradient(var(--wall-2), var(--wall) 70%);
  background-attachment: fixed;
  color: var(--cream);
  font-family: var(--mono);
  -webkit-font-smoothing: antialiased;
}

[hidden] {
  display: none !important;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

button {
  font: inherit;
  color: inherit;
}

:focus-visible {
  outline: 2px solid var(--gold-light);
  outline-offset: 4px;
}

/* ---- The shelf ---- */

.shelf-screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 28px;
  padding: 48px 16px 64px;
}

.masthead {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.masthead h1 {
  margin: 0;
  font-family: var(--fell);
  font-weight: 400;
  font-size: clamp(48px, 9vw, 92px);
  line-height: 1;
  letter-spacing: -0.01em;
}

.masthead p {
  margin: 18px 0 0;
  font-family: var(--type);
  font-size: 17px;
  line-height: 1.65;
  color: var(--muted);
}

/* The book you were last typing, one click away. */
.resume {
  display: inline-flex;
  align-items: baseline;
  gap: 10px;
  margin-top: 24px;
  padding: 9px 18px;
  border: 1px solid rgba(239, 230, 210, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  font-family: var(--type);
  font-size: 15px;
  color: var(--cream);
  cursor: pointer;
  transition: border-color 150ms, background 150ms;
}

.resume:hover {
  border-color: var(--gold-light);
  background: rgba(255, 255, 255, 0.07);
}

.resume em {
  font-family: var(--fell);
  font-size: 18px;
}

.resume-pct {
  color: var(--gold-light);
}

.shelves {
  display: flex;
  flex-direction: column;
  gap: 24px;
  width: min(920px, 100%);
}

/* Each shelf scrolls sideways on its own when it's wider than the screen.
   The top padding leaves room for the hover labels. */
.shelf-scroll {
  overflow-x: auto;
  padding-top: 64px;
  scrollbar-width: thin;
}

.shelf-inner {
  min-width: 100%;
  width: max-content;
}

.books {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  min-height: 290px;
  padding: 0 40px;
}

/* A brass bookend holding up each row. */
.books::after {
  content: "";
  flex: none;
  width: 16px;
  height: 128px;
  margin-left: 8px;
  border-radius: 3px 3px 0 0;
  background: linear-gradient(90deg, #7b5a22, #e3c174 38%, #b58c3e 62%, #6e4f1c);
  box-shadow: 4px 0 10px -4px rgba(0, 0, 0, 0.6);
}

.board {
  position: relative;
  height: 24px;
  border-radius: 3px;
  background: linear-gradient(var(--wood-light), var(--wood) 30%, var(--wood-dark));
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 22px 34px -14px rgba(0, 0, 0, 0.8);
}

/* The shelf's little brass label. */
.plaque {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 1px 10px 0;
  border-radius: 2px;
  font-family: var(--type);
  font-size: 11px;
  letter-spacing: 0.06em;
  white-space: nowrap;
  color: #3a2810;
  background: linear-gradient(#e9cd85, #b8913f);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.5),
    0 1px 2px rgba(0, 0, 0, 0.5);
}

.note {
  margin: 12px 0 0;
  font-family: var(--type);
  color: var(--muted);
}

.spine {
  --cloth: #8b2a22;
  --gilt: #d9b464;
  flex: none;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  width: 64px;
  height: 272px;
  padding: 0;
  border: 0;
  border-radius: 5px 5px 2px 2px;
  color: var(--gilt);
  cursor: pointer;
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.38), rgba(255, 255, 255, 0.1) 22%, rgba(255, 255, 255, 0.02) 52%, rgba(0, 0, 0, 0.22) 84%, rgba(0, 0, 0, 0.48)),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 3px),
    var(--cloth);
  box-shadow:
    0 2px 0 rgba(0, 0, 0, 0.35),
    8px 0 16px -8px rgba(0, 0, 0, 0.7);
  transition: transform 320ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.spine:hover,
.spine:focus-visible {
  transform: translateY(-16px);
}

/* Picked: it slides up off the shelf. */
.spine.pulled {
  transform: translateY(-46px);
  transition-duration: 280ms;
}

.band {
  display: block;
  width: 100%;
  height: 12px;
  border-top: 2px solid var(--gilt);
  border-bottom: 2px solid var(--gilt);
}

.band.top {
  margin-top: 18px;
}

.band.bottom {
  margin-bottom: 16px;
}

/* In vertical writing, a flex column lays each title line down the spine
   as its own column, side by side. */
.spine-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  writing-mode: vertical-rl;
  font-family: var(--fell);
  font-size: var(--spine-fs, 17px);
  white-space: nowrap;
  letter-spacing: 0.03em;
  line-height: 1.15;
}

.spine-author {
  max-width: 100%;
  overflow: hidden;
  font-family: var(--fell);
  font-size: var(--name-fs, 10px);
  letter-spacing: 0.04em;
  white-space: nowrap;
  text-transform: uppercase;
}

/* How far along you are, on hover, for books you've started. */
.tip {
  position: absolute;
  bottom: calc(100% + 30px);
  left: 50%;
  z-index: 2;
  padding: 4px 9px 3px;
  border-radius: 2px;
  font-family: var(--type);
  font-size: 12px;
  white-space: nowrap;
  color: var(--ink);
  background: var(--card);
  box-shadow: 0 6px 14px -4px rgba(0, 0, 0, 0.6);
  opacity: 0;
  transform: translate(-50%, 4px);
  transition:
    opacity 160ms,
    transform 160ms;
  pointer-events: none;
}

.spine:hover .tip,
.spine:focus-visible .tip {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---- The cover ---- */

.cover-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  overflow-y: auto;
  background: rgba(12, 9, 7, 0.8);
  backdrop-filter: blur(3px);
  animation: fade 220ms ease-out;
  transition: opacity 220ms;
}

.cover-backdrop.closing {
  opacity: 0;
}

.cover-dialog {
  display: flex;
  align-items: center;
  gap: 44px;
  width: min(780px, 100%);
}

/* The cover sits over the book's title page and swings open to it. */
.cover {
  position: relative;
  flex: none;
  width: 264px;
  aspect-ratio: 3 / 4.3;
  perspective: 1400px;
  animation: pull 520ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.title-page {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 28px 22px;
  border-radius: 2px 6px 6px 2px;
  text-align: center;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(60, 40, 10, 0.18), transparent 8%),
    var(--paper);
  box-shadow: 0 34px 60px -22px rgba(0, 0, 0, 0.85);
}

.tp-title {
  margin: 0;
  font-family: var(--fell);
  font-size: 24px;
  line-height: 1.15;
}

.tp-by {
  margin: 14px 0 2px;
  font-family: var(--fell);
  font-style: italic;
  font-size: 14px;
}

.tp-author {
  margin: 0;
  font-family: var(--fell);
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.title-page .rule {
  color: var(--ink);
  opacity: 0.6;
}

.cloth {
  position: absolute;
  inset: 0;
  z-index: 1;
  padding: 18px;
  border-radius: 3px 8px 8px 3px;
  color: var(--gilt);
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.42), rgba(0, 0, 0, 0) 7%, rgba(255, 255, 255, 0.07) 9%, rgba(0, 0, 0, 0) 16%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.025) 0 1px, transparent 1px 3px),
    repeating-linear-gradient(-45deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 3px),
    var(--cloth);
  box-shadow: 0 34px 60px -22px rgba(0, 0, 0, 0.85);
  transform-origin: left center;
  backface-visibility: hidden;
  transition: transform 720ms cubic-bezier(0.55, 0.05, 0.3, 1);
}

.cover.opening .cloth {
  transform: rotateY(-165deg);
}

.frame {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  height: 100%;
  padding: 20px 14px;
  text-align: center;
  border: 2px solid currentColor;
  outline: 1px solid currentColor;
  outline-offset: -8px;
}

.cover-small {
  margin: 0;
  font-family: var(--fell);
  font-style: italic;
  font-size: 19px;
}

.cover-big {
  margin: 0 0 6px;
  font-family: var(--fell);
  font-size: 31px;
  line-height: 1.05;
}

.watch {
  width: 62px;
  margin: 8px 0 14px;
}

.rule {
  width: 110px;
  margin: 10px 0 16px;
}

.cover-author {
  margin: 0;
  font-family: var(--fell);
  font-size: 13px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.cover-info h2 {
  margin: 0 0 8px;
  font-family: var(--fell);
  font-weight: 400;
  font-size: 36px;
  line-height: 1.08;
}

.byline {
  margin: 0 0 20px;
  font-family: var(--fell);
  font-style: italic;
  font-size: 19px;
  color: var(--muted);
}

.facts,
.progress {
  margin: 0 0 6px;
  font-family: var(--type);
  font-size: 15px;
  line-height: 1.6;
  opacity: 0.88;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 24px;
}

.btn {
  padding: 10px 18px;
  border: 1px solid rgba(239, 230, 210, 0.35);
  border-radius: 4px;
  background: transparent;
  font-family: var(--type);
  font-size: 16px;
  color: var(--cream);
  cursor: pointer;
  transition: border-color 150ms, background 150ms;
}

.btn:hover {
  border-color: var(--gold-light);
}

.btn.primary {
  border-color: var(--cream);
  background: var(--cream);
  color: var(--wall);
}

.btn.primary:hover {
  background: #fff8e6;
}

.btn.quiet {
  border-color: transparent;
  color: var(--muted);
}

.btn.quiet:hover {
  color: var(--cream);
}

/* A quiet text button: the link to your place. */
.share {
  margin-top: 16px;
  padding: 0;
  border: 0;
  background: none;
  font-family: var(--type);
  font-size: 14px;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.share:hover {
  color: var(--cream);
}

.index-card .share {
  color: rgba(28, 25, 21, 0.6);
}

.index-card .share:hover {
  color: var(--ink);
}

.share-field {
  width: 100%;
  margin-top: 14px;
  padding: 8px 10px;
  border: 1px solid rgba(239, 230, 210, 0.35);
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 13px;
  color: inherit;
  background: rgba(0, 0, 0, 0.2);
}

@media (max-width: 680px) {
  .cover-dialog {
    flex-direction: column;
    gap: 28px;
    text-align: center;
  }

  .cover {
    width: 200px;
  }

  .actions {
    justify-content: center;
  }

  .books {
    justify-content: flex-start;
    padding: 0 20px;
  }

  .plaque {
    left: 20px;
    transform: translateY(-50%);
  }
}

/* ---- The desk ---- */

.desk-screen {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

.deskbar {
  position: relative;
  z-index: 8;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 16px;
  padding: 14px 20px;
  font-size: 14px;
  color: var(--muted);
}

.chapter {
  margin: 0;
  overflow: hidden;
  font-family: var(--fell);
  font-style: italic;
  font-size: 19px;
  color: var(--cream);
  text-align: center;
  white-space: pre;
  text-overflow: ellipsis;
}

.deskbar-right {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 20px;
}

.stats {
  margin: 0;
  white-space: pre;
}

.link {
  padding: 4px 0;
  border: 0;
  background: none;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--muted);
  white-space: nowrap;
  cursor: pointer;
  justify-self: start;
}

.link:hover {
  color: var(--cream);
}

@media (max-width: 820px) {
  .deskbar {
    grid-template-columns: auto 1fr;
    grid-template-areas:
      "back sound"
      "stats stats"
      "chapter chapter";
    row-gap: 6px;
    padding: 12px 16px;
  }

  #back {
    grid-area: back;
  }

  .deskbar-right {
    display: contents;
  }

  .stats {
    grid-area: stats;
    font-size: 12px;
    text-align: center;
  }

  #sound {
    grid-area: sound;
    justify-self: end;
  }

  .chapter {
    grid-area: chapter;
    font-size: 16px;
  }
}

.stage {
  --platen-h: calc(var(--lh) * 1.45);
  --machine-h: clamp(170px, 38vh, 340px);
  --machine-w: min(980px, calc(100% - 24px));
  --platen-top: calc(100% - var(--machine-h) - var(--platen-h) * 0.5);
  position: relative;
  flex: 1;
  overflow: hidden;
  cursor: text;
}

/* The walnut desk the machine sits on. */
.desktop {
  position: absolute;
  inset: auto 0 0;
  height: calc(var(--machine-h) * 0.46);
  background:
    repeating-linear-gradient(178deg, rgba(255, 220, 180, 0.035) 0 2px, transparent 2px 11px),
    linear-gradient(#5e3c24, #432917 55%, #2b1a0e);
  box-shadow:
    inset 0 2px 0 rgba(255, 210, 160, 0.2),
    0 -1px 0 rgba(0, 0, 0, 0.5);
}

/* The carriage is a point on the platen's top edge, centered on the stage.
   It slides the paper and platen left as you type. */
.carriage {
  position: absolute;
  left: 50%;
  top: var(--platen-top);
  z-index: 2;
  width: 0;
  height: 0;
  transition: transform 70ms ease-out;
}

.carriage.returning {
  transition: transform 340ms cubic-bezier(0.3, 0.7, 0.2, 1);
}

/* The paper only shows above the roller; below it, it's inside the
   machine. The feed is the window it shows through. */
.feed {
  position: absolute;
  left: -48px;
  bottom: calc(var(--platen-h) * -0.5);
  width: calc(var(--paper-w) + 96px);
  height: 140vh;
  overflow: hidden;
  pointer-events: none;
}

.paper {
  position: absolute;
  left: 48px;
  top: calc(100% - var(--platen-h) * 0.5);
  width: var(--paper-w);
  height: var(--paper-h);
  padding: calc(var(--lh) * 3) calc(var(--cw) * 5) 0;
  font-family: var(--type);
  font-size: var(--fs);
  color: var(--ink);
  background-color: var(--paper);
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .45 0 0 0 0 .37 0 0 0 0 .24 0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    linear-gradient(90deg, rgba(60, 40, 10, 0.06), transparent 5%, transparent 95%, rgba(60, 40, 10, 0.06));
  box-shadow:
    0 0 0 1px rgba(0, 0, 0, 0.06),
    0 24px 48px -12px rgba(0, 0, 0, 0.6);
  transition: transform 260ms cubic-bezier(0.3, 0.7, 0.2, 1);
}

/* A fresh sheet starts down inside the machine and rolls up. */
.paper.arriving {
  transform: translateY(calc(var(--lh) * 10)) !important;
  transition: none;
}

.paper.rolling {
  transition: transform 820ms cubic-bezier(0.2, 0.7, 0.2, 1);
}

/* A finished sheet, on its way to the stack. */
.paper.flying {
  z-index: 7;
  transform-origin: center;
  pointer-events: none;
  transition:
    transform 760ms cubic-bezier(0.5, 0.05, 0.25, 1),
    opacity 280ms ease-in 520ms;
}

.line {
  display: flex;
  align-items: center;
  height: var(--lh);
  white-space: pre;
}

/* Every character sits in its own fixed-width cell, like a typewriter's. */
.c {
  position: relative;
  flex: none;
  width: var(--cw);
  line-height: var(--lh);
  text-align: center;
}

.ink {
  color: var(--ink);
  opacity: var(--o, 0.9);
  transform: translateY(var(--dy, 0)) rotate(var(--rot, 0));
}

.fresh {
  animation: strike 140ms ease-out;
}

.ghost {
  color: rgba(28, 25, 21, 0.27);
}

.now {
  color: rgba(28, 25, 21, 0.6);
}

/* Where the next letter will land. */
.now::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 16%;
  height: 2px;
  background: var(--ink);
  animation: blink 1.1s steps(1) infinite;
}

.ret {
  font-family: var(--mono);
}

/* A wrong key strikes in red, then fades. */
.missed::before {
  content: attr(data-miss);
  position: absolute;
  inset: 0;
  color: var(--red-ink);
  opacity: 0;
  transform: translate(0.05em, -0.04em) rotate(-3deg);
  animation: misstrike 520ms ease-out;
}

.platen {
  position: absolute;
  top: 0;
  left: calc(var(--cw) * -7);
  z-index: 1;
  width: calc(var(--paper-w) + var(--cw) * 14);
  height: var(--platen-h);
  border-radius: calc(var(--platen-h) / 2);
  background: linear-gradient(#4b4b4b, #171717 28%, #050505 55%, #1e1e1e 80%, #0a0a0a);
  box-shadow: 0 12px 20px -8px rgba(0, 0, 0, 0.75);
}

/* The paper bail, with its two little rollers. */
.bail {
  position: absolute;
  top: 5px;
  left: 6%;
  right: 6%;
  height: 3px;
  border-radius: 2px;
  background: linear-gradient(var(--chrome), var(--chrome-dark));
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
}

.bail::before,
.bail::after {
  content: "";
  position: absolute;
  top: -3px;
  width: 22px;
  height: 9px;
  border-radius: 4px;
  background: linear-gradient(#3a3a3a, #111);
}

.bail::before {
  left: 28%;
}

.bail::after {
  right: 28%;
}

/* Chrome platen knobs. */
.knob {
  position: absolute;
  top: 50%;
  width: calc(var(--platen-h) * 1.15);
  height: calc(var(--platen-h) * 1.15);
  margin-top: calc(var(--platen-h) * -0.575);
  border: 2px solid #6d7378;
  border-radius: 50%;
  background:
    repeating-conic-gradient(rgba(0, 0, 0, 0.12) 0 6deg, transparent 6deg 12deg),
    radial-gradient(circle at 35% 32%, #ffffff, #c9ced2 45%, #7d8388 80%);
}

.knob.left {
  left: calc(var(--platen-h) * -0.95);
}

.knob.right {
  right: calc(var(--platen-h) * -0.95);
}

/* The carriage return lever, which kicks over on every return. */
.lever {
  position: absolute;
  top: calc(var(--platen-h) * 0.1);
  left: calc(var(--platen-h) * -0.95 - 70px);
  width: 76px;
  height: 7px;
  border-radius: 4px;
  background: linear-gradient(#fafafa, #9aa0a4);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.45);
  transform: rotate(-18deg);
  transform-origin: right center;
}

.lever::before {
  content: "";
  position: absolute;
  top: 50%;
  left: -9px;
  width: 17px;
  height: 17px;
  margin-top: -8.5px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #ffffff, #a5abaf 70%);
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.4);
}

.lever.pull {
  animation: pull-lever 420ms cubic-bezier(0.3, 0.7, 0.3, 1);
}

/* The type guide: the little chrome notch the letters strike through. */
.guide {
  position: absolute;
  left: 50%;
  top: calc(var(--platen-top) - 3px);
  z-index: 3;
  width: 30px;
  height: 11px;
  margin-left: -15px;
  background: linear-gradient(var(--chrome), var(--chrome-dark));
  clip-path: polygon(0 100%, 12% 0, 40% 0, 50% 60%, 60% 0, 88% 0, 100% 100%);
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.5));
  pointer-events: none;
  transition: transform 70ms ease-out;
}

.guide.returning {
  transition: transform 340ms cubic-bezier(0.3, 0.7, 0.2, 1);
}

/* ---- The machine ---- */

.machine {
  --k: clamp(20px, min(3.6vw, 4vh), 40px);
  position: absolute;
  bottom: 0;
  left: 50%;
  z-index: 4;
  width: var(--machine-w);
  height: var(--machine-h);
  transform: translateX(-50%);
  border-radius: 64px 64px 26px 26px / 48px 48px 26px 26px;
  background:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='120' height='120'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='1.2' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .14 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>"),
    radial-gradient(ellipse 70% 50% at 50% 0%, rgba(255, 255, 255, 0.42), transparent 70%),
    linear-gradient(var(--enamel-hi), var(--enamel) 22%, var(--enamel-lo));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.6),
    inset 0 -16px 26px rgba(0, 0, 0, 0.2),
    0 34px 50px -20px rgba(0, 0, 0, 0.85);
}

/* Chrome trim along the front. */
.machine::after {
  content: "";
  position: absolute;
  left: 5%;
  right: 5%;
  bottom: 12px;
  height: 5px;
  border-radius: 3px;
  background: linear-gradient(#fdfdfd, #9aa1a6);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}

/* The typebars, fanned in their basket under the type guide. Each one
   thrusts up toward the paper when its letter is typed. */
.basket {
  position: absolute;
  top: 0;
  left: 50%;
  width: min(34%, 320px);
  height: 52px;
  transform: translateX(-50%);
  border-radius: 0 0 50% 50% / 0 0 100% 100%;
  background: radial-gradient(ellipse 60% 120% at 50% 0%, #2a302d, #0e1210 75%);
  box-shadow:
    inset 0 8px 12px rgba(0, 0, 0, 0.65),
    0 1px 0 rgba(255, 255, 255, 0.45);
}

.bar {
  position: absolute;
  top: 0;
  left: 50%;
  width: 3px;
  height: 42px;
  margin-left: -1.5px;
  border-radius: 2px;
  background: linear-gradient(#59605c 0 5px, #e5e9eb 5px, #8a9094);
  transform: rotate(var(--a)) translateY(9px);
  transform-origin: top center;
}

.bar.strike {
  animation: typebar 130ms ease-out;
}

/* Two-tone ribbon spools, red and black, under their covers. */
.spool {
  position: absolute;
  top: 9px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: radial-gradient(
    circle,
    #cfd3d6 0 12%,
    #1d1d1d 13% 21%,
    #b3261e 22% 40%,
    #151515 41% 58%,
    #dfe3e6 59% 65%,
    #7d8489 66% 71%,
    transparent 72%
  );
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.35));
}

.spool.left {
  right: calc(50% + min(17%, 160px) + 20px);
}

.spool.right {
  left: calc(50% + min(17%, 160px) + 20px);
}

/* The bell that rings near the end of a line. */
.bell {
  position: absolute;
  top: 20px;
  right: 9%;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff4c8, #e2b54d 45%, #8a6420 82%);
  box-shadow:
    0 2px 3px rgba(0, 0, 0, 0.45),
    inset 0 -2px 3px rgba(0, 0, 0, 0.25);
}

.bell::after {
  content: "";
  position: absolute;
  top: 9px;
  left: 9px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff4c8, #b88a2e);
}

.bell.ring {
  animation: ring 650ms ease-out;
}

.plate {
  position: absolute;
  top: 62px;
  left: 50%;
  transform: translateX(-50%);
  padding: 2px 18px 1px;
  border-radius: 999px;
  font-family: var(--fell);
  font-style: italic;
  font-size: 16px;
  white-space: nowrap;
  color: var(--enamel-deep);
  background: linear-gradient(#ffffff, #b6bdc1);
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.35),
    inset 0 1px 0 #ffffff;
}

/* The keyboard sits in a dark well, cream keys in chrome rings. */
.keys {
  position: absolute;
  inset: 94px 6% 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: calc(var(--k) * 0.2);
  border-radius: 22px 22px 12px 12px;
  background: linear-gradient(#2f4b41, #213730);
  box-shadow:
    inset 0 4px 10px rgba(0, 0, 0, 0.5),
    0 1px 0 rgba(255, 255, 255, 0.4);
}

.row {
  display: flex;
  gap: calc(var(--k) * 0.24);
}

.row.r1 {
  margin-left: calc(var(--k) * 0.6);
}

.row.r2 {
  margin-left: calc(var(--k) * 0.9);
}

.key {
  display: grid;
  place-items: center;
  width: var(--k);
  height: var(--k);
  border: calc(var(--k) * 0.08) solid #c8cdd1;
  border-radius: 50%;
  font-family: var(--mono);
  font-weight: 700;
  font-size: calc(var(--k) * 0.36);
  color: #2a2622;
  background: radial-gradient(circle at 50% 34%, #fffaf0, var(--keycap) 55%, #dccfb2);
  box-shadow:
    0 calc(var(--k) * 0.12) 0 #14231d,
    0 calc(var(--k) * 0.15) 5px rgba(0, 0, 0, 0.55);
  transition:
    transform 60ms,
    box-shadow 60ms;
}

.key.down {
  transform: translateY(calc(var(--k) * 0.1));
  box-shadow:
    0 calc(var(--k) * 0.02) 0 #14231d,
    0 2px 3px rgba(0, 0, 0, 0.55);
}

.k-shift,
.k-return {
  width: calc(var(--k) * 1.75);
  border-radius: calc(var(--k) / 2);
  font-size: calc(var(--k) * 0.24);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.k-space {
  width: calc(var(--k) * 8);
  height: calc(var(--k) * 0.5);
  border-radius: calc(var(--k) * 0.25);
  font-size: 0;
  background: linear-gradient(#fbfbfb, #a9b0b4);
}

/* ---- Typed pages, stacked on the desk ---- */

.stack {
  position: absolute;
  right: calc(50% + var(--machine-w) / 2 + 40px);
  bottom: calc(var(--machine-h) * 0.1);
  z-index: 3;
  width: 150px;
}

.sheets {
  position: relative;
  height: 194px;
  transform: perspective(700px) rotateX(58deg) rotateZ(-8deg);
  transform-origin: bottom center;
}

.sheet {
  position: absolute;
  inset: 0;
  background: var(--paper);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  transform: translate(calc(var(--i) * -1px), calc(var(--i) * -2.5px)) rotate(var(--r));
}

/* The top sheet shows a page of typing. */
.sheet:last-child {
  background:
    repeating-linear-gradient(transparent 0 9px, rgba(28, 25, 21, 0.28) 9px 11px, transparent 11px 13px) 18px 26px / 114px 140px no-repeat,
    var(--paper);
}

.stack-label {
  margin: 10px 0 0;
  font-family: var(--type);
  font-size: 14px;
  text-align: center;
  color: var(--cream);
  opacity: 0.8;
}

.stack.empty .sheets,
.stack.empty .stack-label {
  opacity: 0;
}

@media (max-width: 1279px) {
  .stack {
    display: none;
  }
}

/* ---- The first-time how-to card ---- */

.hint {
  position: absolute;
  top: 28px;
  left: max(24px, calc(50% - var(--paper-w) / 2 - 300px));
  z-index: 6;
  width: 270px;
  padding: 16px 20px 14px;
  font-family: var(--type);
  font-size: 14px;
  line-height: 24px;
  color: var(--ink);
  background:
    linear-gradient(transparent 0 46px, rgba(200, 70, 60, 0.45) 46px 47px, transparent 47px),
    var(--card);
  box-shadow: 0 18px 34px -12px rgba(0, 0, 0, 0.7);
  transform: rotate(-2deg);
  animation: card-in 420ms cubic-bezier(0.2, 0.8, 0.2, 1);
  transition:
    opacity 300ms,
    transform 300ms;
}

/* A paper clip holding it. */
.hint::before {
  content: "";
  position: absolute;
  top: -14px;
  right: 30px;
  width: 14px;
  height: 40px;
  border: 2px solid #9aa0a4;
  border-radius: 8px;
  box-shadow: inset 0 0 0 3px transparent;
}

.hint.leaving {
  opacity: 0;
  transform: translateY(-12px) rotate(-5deg);
}

.hint-title {
  margin: 0 0 14px;
  font-size: 16px;
}

.hint ul {
  margin: 0;
  padding-left: 18px;
}

.hint-close {
  margin-top: 8px;
  padding: 0;
  border: 0;
  background: none;
  font-family: var(--type);
  font-size: 14px;
  color: var(--red-ink);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.tap {
  position: absolute;
  bottom: calc(var(--machine-h) + 24px);
  left: 50%;
  z-index: 5;
  transform: translateX(-50%);
  padding: 10px 18px;
  border: 1px solid var(--cream);
  border-radius: 4px;
  background: rgba(24, 18, 14, 0.85);
  font-family: var(--type);
  font-size: 16px;
  color: var(--cream);
}

/* Phones bring their own keyboard, so the machine shrinks to its body. */
@media (pointer: coarse), (max-height: 560px) {
  .stage {
    --machine-h: 64px;
  }

  .keys,
  .plate,
  .spool,
  .bell,
  .basket {
    display: none;
  }

  .hint {
    top: 10px;
    left: 12px;
    right: 12px;
    width: auto;
    transform: none;
  }

  .card-tip {
    display: none;
  }
}

.input {
  position: fixed;
  bottom: 0;
  left: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  font-size: 16px;
  resize: none;
}

/* ---- Index cards: a finished chapter, and the end ---- */

.card-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(12, 9, 7, 0.55);
  animation: fade 240ms ease-out;
}

.index-card {
  position: relative;
  width: min(480px, 100%);
  padding: 26px 30px 22px;
  font-family: var(--type);
  color: var(--ink);
  background: var(--card);
  box-shadow: 0 30px 60px -20px rgba(0, 0, 0, 0.85);
  transform: rotate(-1deg);
  animation: card-in 480ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.card-kicker {
  margin: 0;
  font-family: var(--mono);
  font-size: 13px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--red-ink);
}

/* The card's red header rule sits under the title. */
.card-title {
  margin: 6px 0 0;
  max-width: 300px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(200, 70, 60, 0.5);
  font-family: var(--fell);
  font-weight: 400;
  font-size: 30px;
  line-height: 1.1;
}

/* The library-style date stamp. */
.stamp {
  position: absolute;
  top: 22px;
  right: 24px;
  margin: 0;
  padding: 6px 12px 5px;
  border: 3px double var(--red-ink);
  border-radius: 4px;
  font-family: var(--mono);
  font-weight: 700;
  font-size: 20px;
  letter-spacing: 0.12em;
  line-height: 1;
  text-align: center;
  text-transform: uppercase;
  color: var(--red-ink);
  opacity: 0.86;
  transform: rotate(-12deg);
  animation: stamp 420ms cubic-bezier(0.3, 1.4, 0.5, 1) 260ms both;
}

.stamp small {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  letter-spacing: 0.06em;
}

.card-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin: 22px 0 0;
  padding-bottom: 18px;
  border-bottom: 1px solid rgba(70, 110, 170, 0.25);
}

.card-stats dt {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.6;
}

.card-stats dd {
  margin: 4px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 26px;
}

.index-card .btn.primary {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--card);
}

.index-card .btn.quiet {
  color: rgba(28, 25, 21, 0.6);
}

.index-card .btn.quiet:hover {
  color: var(--ink);
}

.card-tip {
  margin: 12px 0 0;
  font-size: 13px;
  opacity: 0.55;
}

@media (max-width: 480px) {
  .card-stats dd {
    font-size: 19px;
  }

  .stamp {
    top: auto;
    bottom: 96px;
    font-size: 16px;
  }
}

/* ---- Motion ---- */

@keyframes fade {
  from {
    opacity: 0;
  }
}

@keyframes pull {
  from {
    opacity: 0;
    transform: translateY(24px) rotate(-3deg) scale(0.94);
  }
}

@keyframes strike {
  from {
    transform: translateY(calc(var(--dy, 0) - 0.12em)) scale(1.18);
    opacity: 1;
  }
}

@keyframes typebar {
  45% {
    transform: rotate(var(--a)) translateY(-12px);
  }
}

@keyframes ring {
  12% {
    transform: rotate(16deg);
    box-shadow: 0 0 0 6px rgba(234, 211, 154, 0.35), 0 2px 3px rgba(0, 0, 0, 0.45);
  }
  28% {
    transform: rotate(-13deg);
  }
  44% {
    transform: rotate(9deg);
  }
  60% {
    transform: rotate(-5deg);
  }
  76% {
    transform: rotate(2deg);
  }
}

@keyframes pull-lever {
  35% {
    transform: rotate(-2deg);
  }
}

@keyframes card-in {
  from {
    opacity: 0;
    transform: translateY(26px) rotate(-4deg);
  }
}

@keyframes stamp {
  from {
    opacity: 0;
    transform: rotate(-12deg) scale(1.8);
  }
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

@keyframes misstrike {
  0% {
    opacity: 0.95;
  }
  100% {
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .carriage,
  .carriage.returning,
  .guide,
  .paper,
  .spine,
  .key,
  .cloth,
  .tip {
    transition: none !important;
  }

  .fresh,
  .now::after,
  .missed::before,
  .bar.strike,
  .bell.ring,
  .lever.pull,
  .cover,
  .cover-backdrop,
  .card-backdrop,
  .index-card,
  .hint,
  .stamp {
    animation: none;
  }

  .missed::before {
    opacity: 0.9;
  }
}
