:root {
  /* 720px on laptops; on big screens the page grows with the desk photo,
     up to about the window's height. */
  --sheet-w: min(calc(100vw - 28px), max(720px, min(45vw, 73vh)));
  --ink: #1f1c1a;
  --ink-red: #a3261d;
  --paper: #f6f1e5;
  /* Uneven rubber-stamp ink: noise punches small gaps in the print. */
  --worn-ink: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='200' height='80'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2'/><feComponentTransfer><feFuncA type='table' tableValues='0 0 0 0 1'/></feComponentTransfer><feColorMatrix values='0 0 0 0 0  0 0 0 0 0  0 0 0 0 0  0 0 0 -1 1'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: #d8bd98; /* shown only before the desk photo loads */
  color: var(--ink);
}

body {
  /* Height is set by desk.js so the scrollbar tracks both sheets. */
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Desk ---------- */

.desk {
  position: fixed;
  inset: 0;
  overflow: hidden;
  z-index: 0;
  /* Cover keeps the clear middle under the paper; wide screens see the props
     at the edges, phones only see wood. */
  background: #d8bd98 url("desk.jpg") center / cover no-repeat;
}

/* A soft vignette so the desk falls off into shadow around the paper. */
.desk__light {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse 120% 95% at 50% 45%, transparent 60%, rgba(60, 35, 10, .22) 100%);
}

/* ---------- Paper ---------- */

.stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none; /* re-enabled on the sheets */
}

.sheet {
  position: absolute;
  left: 50%;
  top: 0;
  width: var(--sheet-w);
  /* US letter, always: text that doesn't fit goes on to the next sheet. */
  height: calc(var(--sheet-w) * 11 / 8.5);
  overflow: hidden;
  /* Margins set a ~65-character line, like pica type on a letter page.
     Everything on the page is sized from --sheet-w so it scales as one. They
     scale with the sheet, but shrink faster below 720px so phones keep
     slim margins. */
  --pad-x: max(22px, min(calc(var(--sheet-w) * .222), calc(var(--sheet-w) * .32 - 70px)));
  padding:
    max(24px, min(calc(var(--sheet-w) * .189), calc(var(--sheet-w) * .27 - 58px)))
    var(--pad-x)
    max(46px, min(calc(var(--sheet-w) * .167), calc(var(--sheet-w) * .24 - 53px)));
  pointer-events: auto;
  transform-origin: 50% 0;
  will-change: transform;
  background-color: var(--paper);
  /* Paper fibre + a gentle light falloff across the sheet. */
  background-image:
    radial-gradient(ellipse 90% 70% at 35% 20%, rgba(255, 255, 255, .55), transparent 70%),
    linear-gradient(180deg, transparent 85%, rgba(120, 95, 60, .06)),
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='300' height='300'><filter id='f'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 .45  0 0 0 0 .38  0 0 0 0 .28  0 0 0 .09 0'/></filter><rect width='100%' height='100%' filter='url(%23f)'/></svg>");
  box-shadow:
    0 0 0 .5px rgba(80, 60, 30, .18),
    0 1px 1px rgba(0, 0, 0, .25),
    0 3px 6px rgba(0, 0, 0, .22),
    0 calc(var(--lift, 0) * 30px + 14px) calc(var(--lift, 0) * 40px + 28px) rgba(0, 0, 0, calc(.35 + var(--lift, 0) * .1));
}

/* The words before desk.js lays them out on sheets. */
.source { display: none; }

/* ---------- Typewriter text ---------- */

.typed, .folio, .typed-plain {
  font-family: "Special Elite", "Courier New", Courier, monospace;
}

.typed {
  /* 12pt pica on letter paper, single spaced with a blank line between paragraphs */
  font-size: max(12.5px, calc(var(--sheet-w) * .01736)); /* 12.5px on a 720px page */
  line-height: 1.32;
  color: var(--ink);
}

.typed p { margin: 0 0 1.32em; }

/* Typewriters had no bold: headings are typed in caps and underscored. */
.typed h1, .typed h2 {
  font-weight: normal;
  font-size: 1em;
  text-transform: uppercase;
  letter-spacing: .04em;
  margin: 0 0 1.32em;
}

.typed h1 {
  text-align: center;
  margin: 1.32em 0 1.98em;
  text-decoration: underline;
  text-decoration-thickness: .06em;
  text-underline-offset: .32em;
  /* struck twice, slightly offset — how a typist made something "bold" */
  text-shadow: .5px 0 0 currentColor;
}

.typed h2 {
  margin-top: 2.64em;
  text-decoration: underline;
  text-decoration-thickness: .05em;
  text-underline-offset: .3em;
}

.typed .signoff { margin-top: 1.32em; margin-bottom: 0; padding-left: 50%; }
.typed .bio { padding-left: 50%; font-size: .85em; }

/* Characters wrapped by desk.js: each strike lands a little differently. */
.k { display: inline-block; white-space: pre; }

/* Underlines don't reach into inline-blocks, so each struck letter carries its own. */
.typed h1 .k, .typed h2 .k {
  text-decoration: inherit;
  text-decoration-line: underline;
  text-decoration-thickness: inherit;
  text-underline-offset: inherit;
}

.folio {
  position: absolute;
  bottom: max(16px, calc(var(--sheet-w) * .0278));
  left: 0;
  right: 0;
  margin: 0;
  text-align: center;
  font-size: max(12px, calc(var(--sheet-w) * .01667));
  opacity: .8;
}

/* The foot of a sheet turns the page: "← back", the number, "continued →". */
.folio button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: .4em 0;
  cursor: pointer;
}
.folio__back, .folio__over { position: absolute; }
.folio__back { left: var(--pad-x); }
.folio__over { right: var(--pad-x); }
/* Per letter: underlines do not reach into the typed inline-blocks. */
.folio button:hover .k { text-decoration: underline; text-underline-offset: .25em; }
.folio button:focus-visible { outline: 2px dashed var(--ink-red); outline-offset: 2px; }

/* On first load the top sheet lifts and settles, to show the paper moves. */
.sheet.is-nudged { animation: nudge 1.3s cubic-bezier(.3, .7, .3, 1); }
@keyframes nudge {
  0% { translate: 0 0; }
  30% { translate: 0 -46px; }
  45% { translate: 0 -40px; }
  100% { translate: 0 0; }
}

/* ---------- Contact ---------- */

.contact {
  margin: 1.5em 0 2em;
  text-align: center;
}

/* A rubber stamp: red ink, worn edges, pressed on the page. */
.stamp-button {
  font-family: "Special Elite", "Courier New", monospace;
  font-size: max(15px, calc(var(--sheet-w) * .0208));
  letter-spacing: .18em;
  text-transform: uppercase;
  color: var(--ink-red);
  background: transparent;
  border: 3px solid currentColor;
  border-radius: 6px;
  padding: .55em 1.3em .5em;
  cursor: pointer;
  rotate: -2deg;
  opacity: .88;
  -webkit-mask-image: var(--worn-ink);
          mask-image: var(--worn-ink);
  transition: rotate .2s ease, scale .12s ease, opacity .2s ease;
}

.stamp-button:hover { rotate: -1deg; opacity: 1; }
.stamp-button:active { scale: .96; }
.stamp-button:focus-visible { outline: 2px dashed var(--ink-red); outline-offset: 6px; }

.stamp-button--small { font-size: 15px; border-width: 2.5px; }

/* ---------- Index card ---------- */

.card-layer {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(15, 7, 2, .35);
  opacity: 0;
  transition: opacity .35s ease;
}

/* display: grid above beats the browser's own [hidden] rule; without this the
   invisible layer would sit over the page and swallow every click. */
.card-layer[hidden] { display: none; }

.card-layer.is-open { opacity: 1; }

.index-card {
  position: relative;
  width: min(520px, 100%);
  aspect-ratio: 3 / 2; /* a 6×4 index card, with room for a note */
  padding: 26px 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  color: var(--ink);
  background-color: #fbf8f0;
  /* Ruled card: one red header line, blue lines below. */
  background-image:
    linear-gradient(transparent 58px, rgba(200, 60, 60, .55) 58px, rgba(200, 60, 60, .55) 59.5px, transparent 59.5px),
    repeating-linear-gradient(transparent 0 29px, rgba(80, 130, 190, .28) 29px 30px);
  background-position: 0 0, 0 60px;
  box-shadow:
    0 1px 1px rgba(0, 0, 0, .25),
    0 18px 40px rgba(0, 0, 0, .45);
  transform: translateY(70vh) rotate(8deg);
  transition: transform .55s cubic-bezier(.2, .9, .25, 1);
}

.card-layer.is-open .index-card { transform: translateY(0) rotate(-1.5deg); }

.index-card__head { margin: 0 0 14px; font-size: 16px; }
.index-card__label { font-size: 15px; }

/* Typing onto the card: no box, just the ruled line. */
.index-card__input {
  font-family: "Special Elite", "Courier New", monospace;
  font-size: 18px;
  color: var(--ink);
  background: transparent;
  border: 0;
  border-bottom: 1.5px solid rgba(31, 28, 26, .55);
  padding: 4px 2px;
  outline: none;
  caret-color: var(--ink-red);
}

.index-card__note {
  font-family: "Special Elite", "Courier New", monospace;
  font-size: 16px;
  line-height: 30px;
  color: var(--ink);
  border: 0;
  padding: 0 2px;
  resize: none;
  outline: none;
  caret-color: var(--ink-red);
  /* Its own ruled lines, so the writing sits on them and they scroll with it. */
  background: #fbf8f0 repeating-linear-gradient(transparent 0 29px, rgba(80, 130, 190, .28) 29px 30px) local;
}

.index-card__status { min-height: 1.3em; margin: 2px 0 0; font-size: 14px; color: var(--ink-red); }

.index-card__actions {
  margin-top: auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.index-card__cancel {
  background: none;
  border: 0;
  padding: 4px 0;
  font-size: 14px;
  color: rgba(31, 28, 26, .7);
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

/* The SENT stamp lands with a thump once the note is away. */
.index-card__stamp {
  position: absolute;
  right: 34px;
  top: 40%;
  font-family: "Special Elite", monospace;
  font-size: 46px;
  letter-spacing: .15em;
  color: var(--ink-red);
  border: 4px solid currentColor;
  border-radius: 8px;
  padding: 2px 16px;
  rotate: -14deg;
  opacity: 0;
  scale: 2.2;
  pointer-events: none;
  mix-blend-mode: multiply;
  -webkit-mask-image: var(--worn-ink);
          mask-image: var(--worn-ink);
}

.index-card.is-sent .index-card__stamp {
  opacity: .82;
  scale: 1;
  transition: scale .18s cubic-bezier(.5, 0, .9, .4), opacity .1s ease;
}

@media (prefers-reduced-motion: reduce) {
  .index-card, .card-layer, .stamp-button { transition: none; }
}
