/* ─────────────────────────────────────────────
   Dear Stranger — a desk lined in velvet, covered in mail
   ───────────────────────────────────────────── */

:root {
  --velvet: #4a1520;
  --velvet-deep: #340e17;
  --velvet-soft: #5e1f2b;
  --ivory: #fbf7ee;
  --gold: #d9b36c;
  --seal: #9e2235;
  --ink: #23306a;          /* handwriting ink */
  --muted-on-velvet: #e3c5c8;

  /* stationery */
  --p-ivory: #fbf6ea;
  --p-blush: #f6d9d4;
  --p-airmail: #e4e9f3;
  --p-kraft: #d8bf98;
  --p-lilac: #ece2f1;
  --p-butter: #f6edc6;
  --p-sage: #dfe7d6;

  --rule: #b8cce6;
  --margin-line: #e49aa3;

  --display: 'Times New Roman', Times, 'Liberation Serif', Tinos, serif;
  --body: 'Times New Roman', Times, 'Liberation Serif', Tinos, serif;
  --line: 32px;            /* notebook rule height */

  /* paper textures, generated, no image files */
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .42 0 0 0 0 .36 0 0 0 0 .3 0 0 0 .16 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  --mottle: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='1400' height='1400'%3E%3Cfilter id='m'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.008' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .5 0 0 0 0 .42 0 0 0 0 .32 0 0 0 .22 -.06'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23m)'/%3E%3C/svg%3E");
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--velvet); }
body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--body);
  font-size: 18px;
  line-height: 1.6;
  color: var(--ivory);
  background-color: var(--velvet);
  background-image:
    var(--grain),
    radial-gradient(ellipse 120% 900px at 50% -200px, rgba(255, 210, 200, .14), transparent 70%),
    linear-gradient(transparent, rgba(0,0,0,.18));
}

a { color: var(--gold); }
a:hover { color: #f0d39b; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 2px; }

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

/* ── handwriting ─────────────────────────── */
.hand-caveat               { font-family: 'Caveat', cursive;               --hand-size: 25px; --hn: 25; }
.hand-homemade-apple       { font-family: 'Homemade Apple', cursive;       --hand-size: 16px; --hn: 16; }
.hand-reenie-beanie        { font-family: 'Reenie Beanie', cursive;        --hand-size: 28px; --hn: 28; }
.hand-patrick-hand         { font-family: 'Patrick Hand', cursive;         --hand-size: 21px; --hn: 21; }
.hand-nothing-you-could-do { font-family: 'Nothing You Could Do', cursive; --hand-size: 17px; --hn: 17; }

/* ── top of page ─────────────────────────── */
.masthead {
  max-width: 1000px;
  margin: 0 auto;
  padding: 72px 20px 40px;
  text-align: center;
}
.masthead h1 {
  font-family: var(--display);
  font-weight: 400;
  font-size: clamp(56px, 11vw, 120px);
  line-height: .95;
  letter-spacing: -.01em;
  margin: 0;
  color: var(--ivory);
}
.masthead h1.logo { line-height: 0; }
.masthead .logo img { display: block; width: min(720px, 92%); height: auto; margin: 0 auto; }
.masthead p {
  font-style: italic;
  font-size: 20px;
  color: var(--muted-on-velvet);
  max-width: 34ch;
  margin: 20px auto 32px;
}

.button {
  display: inline-block;
  font-family: var(--body);
  font-size: 18px;
  font-weight: 500;
  color: var(--velvet);
  background: var(--ivory);
  border: 0;
  padding: 14px 30px;
  border-radius: 2px;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 0 0 1px var(--gold) inset, 0 6px 18px rgba(0,0,0,.3);
  transition: transform .15s ease, box-shadow .15s ease;
}
.button:hover { color: var(--velvet); transform: translateY(-1px); box-shadow: 0 0 0 1px var(--gold) inset, 0 10px 24px rgba(0,0,0,.35); }
.button:disabled { opacity: .6; cursor: wait; transform: none; }
.button.seal { background: var(--seal); color: var(--ivory); box-shadow: 0 0 0 1px #c9505f inset, 0 6px 18px rgba(0,0,0,.3); }
.button.seal:hover { color: var(--ivory); }

.donate-banner {
  background: var(--ivory);
  color: var(--velvet);
  text-align: center;
  padding: 10px 16px;
  font-size: 16px;
  line-height: 1.4;
}
.donate-banner p { margin: 0; }
.donate-banner a { color: var(--seal); font-weight: bold; text-underline-offset: 3px; }
.donate-banner a:hover { color: var(--velvet); }
.donate-banner a:focus-visible { outline-color: var(--seal); }

.demo-banner {
  text-align: center;
  font-size: 14px;
  background: var(--velvet-deep);
  color: var(--muted-on-velvet);
  padding: 8px 16px;
}

/* the pencil is the write-a-letter button */
.pencil-link {
  display: inline-block;
  width: min(460px, 86vw);
  padding: 10px 0;
  transform: rotate(-2deg);
  filter: drop-shadow(0 2px 2px rgba(20, 5, 8, .4)) drop-shadow(0 10px 12px rgba(15, 0, 4, .4));
  transition: transform .25s ease;
}
.pencil-link img { display: block; width: 100%; height: auto; }
.pencil-link:hover, .pencil-link:focus-visible { transform: rotate(0deg) translate(-6px, -4px); }
.pencil-link:focus-visible { outline-offset: 6px; }

/* ── the pile of letters ─────────────────── */
.pile {
  max-width: 980px;
  margin: 0 auto;
  padding: 16px 24px 96px;
  display: flex;
  align-items: flex-start;
  gap: 48px;
}
.pile-col { flex: 1; min-width: 0; }
.pile-empty { text-align: center; font-style: italic; color: var(--muted-on-velvet); padding: 40px 20px 96px; }

.letter {
  --tilt: 0deg;
  display: block;
  width: 100%;
  margin: 0 0 44px;
  border: 0;
  padding: 0;
  background: transparent;
  cursor: pointer;
  transform: rotate(var(--tilt));
  filter: drop-shadow(0 1px 1px rgba(20, 5, 8, .35)) drop-shadow(0 10px 14px rgba(15, 0, 4, .42));
  transition: transform .25s ease;
}
.letter:hover, .letter:focus-visible { transform: rotate(calc(var(--tilt) * .3)) translateY(-6px); }
.letter:focus-visible { outline-offset: 8px; }
.letter img { display: block; width: 100%; height: auto; }

/* ── notebook paper (reader + writer) ────── */
.sheet-wrap { filter: drop-shadow(0 1px 1px rgba(20,5,8,.35)) drop-shadow(0 16px 24px rgba(15,0,4,.5)); }
.paper {
  --margin-x: 64px;
  --hole-x: 30px;
  position: relative;
  color: #1e2a5e;
  background-color: #fbfaf4;
  background-image:
    var(--grain),
    var(--mottle),
    linear-gradient(135deg, rgba(255,255,255,.55), rgba(255,255,255,0) 38%, rgba(0,0,0,0) 70%, rgba(110,85,60,.07)),
    linear-gradient(90deg, transparent calc(var(--margin-x) - 1px), rgba(226,118,128,.7) calc(var(--margin-x) - 1px) calc(var(--margin-x) + 1px), transparent calc(var(--margin-x) + 1px)),
    repeating-linear-gradient(180deg, transparent 0 calc(var(--line) - 1px), rgba(110,150,205,.55) calc(var(--line) - 1px) var(--line));
  background-size: 200px 200px, 1400px 1400px, auto, auto, 100% calc(100% - var(--line) * 2);
  background-position: 0 0, 0 0, 0 0, 0 0, 0 calc(var(--line) * 2);
  background-repeat: repeat, repeat, no-repeat, no-repeat, no-repeat;
  padding: calc(var(--line) * 2) 28px calc(var(--line) * 1.5) calc(var(--margin-x) + 20px);
  line-height: var(--line);
  /* punched holes you can see the desk through */
  -webkit-mask:
    radial-gradient(circle 8px at var(--hole-x) 12%, #0000 96%, #000),
    radial-gradient(circle 8px at var(--hole-x) 50%, #0000 96%, #000),
    radial-gradient(circle 8px at var(--hole-x) 88%, #0000 96%, #000);
  -webkit-mask-composite: source-in;
  mask:
    radial-gradient(circle 8px at var(--hole-x) 12%, #0000 96%, #000),
    radial-gradient(circle 8px at var(--hole-x) 50%, #0000 96%, #000),
    radial-gradient(circle 8px at var(--hole-x) 88%, #0000 96%, #000);
  mask-composite: intersect;
}
.paper::after {   /* worn edges */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  box-shadow: inset 0 0 22px rgba(120, 90, 60, .1), inset 0 0 1px rgba(90, 60, 40, .3);
}
.paper.creased::after {   /* it was folded in thirds to fit the envelope */
  background: linear-gradient(180deg,
    rgba(0,0,0,0) 0, rgba(0,0,0,.018) 31%, rgba(0,0,0,.05) 33.25%, rgba(255,255,255,.35) 33.4%, rgba(255,255,255,0) 34.6%,
    rgba(0,0,0,.02) 63%, rgba(0,0,0,.055) 66.6%, rgba(255,255,255,.35) 66.75%, rgba(255,255,255,0) 68%);
}
.paper .salutation,
.paper .letter-body,
.paper .signoff,
.paper textarea {
  font-size: var(--hand-size);
  line-height: var(--line);
  margin: 0;
}
.paper .salutation, .paper .letter-body, .paper .signoff { filter: url(#f-ink); }
.paper .letter-body { white-space: pre-wrap; overflow-wrap: anywhere; position: relative; top: 4px; }
.paper .salutation { position: relative; top: 4px; }
.paper .signoff { text-align: right; padding-top: var(--line); position: relative; top: 4px; }

/* ── reader ──────────────────────────────── */
dialog.reader {
  width: min(680px, 100vw - 24px);
  max-height: calc(100vh - 24px);
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--ivory);
  overflow: visible;
}
dialog.reader::backdrop { background: rgba(30, 6, 12, .93); backdrop-filter: blur(3px); }
.reader-scroll { max-height: calc(100vh - 24px); overflow-y: auto; padding: 56px 12px 40px; }
.reader .paper { transform-origin: 50% 0; }
.reader[open] .paper { animation: unfold .6s cubic-bezier(.2,.8,.2,1); }
@keyframes unfold {
  0%   { transform: perspective(1200px) rotateX(-80deg) scaleY(.4); opacity: 0; }
  60%  { opacity: 1; }
  100% { transform: perspective(1200px) rotateX(0) scaleY(1); }
}
.close {
  position: absolute; top: 8px; right: 8px;
  width: 44px; height: 44px; border-radius: 50%;
  border: 1px solid rgba(251,247,238,.4); background: var(--velvet-deep); color: var(--ivory);
  font-size: 24px; line-height: 1; cursor: pointer; z-index: 2;
}
.close:hover { border-color: var(--gold); }

.notes { margin-top: 48px; }
.notes h2 { font-family: var(--display); font-weight: 400; font-size: 30px; margin: 0 0 4px; }
.notes > p { margin: 0 0 24px; color: var(--muted-on-velvet); font-style: italic; }
.note-list { display: flex; flex-wrap: wrap; gap: 18px; margin-bottom: 32px; }
.sticky {
  position: relative;
  width: 190px; min-height: 150px; padding: 18px 16px;
  background: var(--p-butter); color: #1e2a5e;
  background-image: var(--grain), linear-gradient(170deg, rgba(255,255,255,.35), rgba(0,0,0,0) 40%, rgba(0,0,0,.05));
  background-size: 160px, auto;
  transform: rotate(-1.2deg);
  font-family: 'Caveat', cursive; font-size: 21px; line-height: 1.2;
  box-shadow: 0 8px 16px rgba(20,0,6,.35);
  overflow-wrap: anywhere;
}
.sticky:nth-child(3n+2) { background-color: #f9d6df; transform: rotate(1.4deg); }
.sticky:nth-child(3n+3) { background-color: #dfeedd; transform: rotate(-.4deg); }
.note-form { display: grid; gap: 12px; max-width: 420px; }
.note-form textarea {
  width: 100%; min-height: 120px; resize: vertical;
  padding: 16px; border: 0; border-radius: 0;
  background: var(--p-butter); color: var(--ink);
  font-family: 'Caveat', cursive; font-size: 22px; line-height: 1.25;
}
.note-form .button { justify-self: start; }

.status { font-style: italic; margin: 0; min-height: 1.6em; }
.status.error { color: #ffc9c9; }

/* ── write page ──────────────────────────── */
.topbar { max-width: 1120px; margin: 0 auto; padding: 24px 24px 0; }
.topbar a { font-style: italic; text-decoration: none; }
.topbar a:hover { text-decoration: underline; }

.write-head { max-width: 1120px; margin: 0 auto; padding: 32px 24px 32px; }
.write-head h1 { font-family: var(--display); font-weight: 400; font-size: clamp(42px, 7vw, 72px); line-height: 1; margin: 0 0 12px; }
.write-head p { margin: 0; color: var(--muted-on-velvet); font-style: italic; max-width: 48ch; }

.desk {
  max-width: 1120px; margin: 0 auto; padding: 0 24px 96px;
  display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 48px; align-items: start;
}
.desk .paper textarea {
  display: block; width: 100%; min-height: calc(var(--line) * 12);
  border: 0; padding: 0; background: transparent; color: var(--ink);
  resize: none; overflow: hidden; outline: none;
  font-family: inherit;
  position: relative; top: 4px;
}
.desk .paper-col:focus-within { outline: 2px solid var(--gold); outline-offset: 6px; }
.desk .paper textarea::placeholder { color: rgba(35, 48, 106, .38); }
.counter { position: absolute; right: 16px; bottom: 6px; font-family: var(--body); font-size: 12px; line-height: 1; color: rgba(35,48,106,.5); }

.side { display: grid; gap: 36px; position: sticky; top: 24px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
legend, .field-label { font-family: var(--display); font-size: 22px; padding: 0; margin: 0 0 12px; color: var(--ivory); }

.pens { display: grid; gap: 8px; }
.pen input, .signoffs input { position: absolute; opacity: 0; pointer-events: none; }
.pen label, .signoffs label {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 8px 14px; cursor: pointer;
  background: rgba(251,247,238,.06);
  border: 1px solid rgba(251,247,238,.16);
  color: var(--ivory);
}
.pen .sample { font-size: var(--hand-size); line-height: 1.3; }
.pen .name { font-family: var(--body); font-size: 13px; font-style: italic; color: var(--muted-on-velvet); white-space: nowrap; }
.pen input:checked + label, .signoffs input:checked + label { background: var(--ivory); color: var(--ink); border-color: var(--gold); }
.pen input:checked + label .name { color: rgba(35,48,106,.7); }
.pen input:focus-visible + label, .signoffs input:focus-visible + label { outline: 2px solid var(--gold); outline-offset: 2px; }
.signoffs { display: grid; gap: 6px; }
.signoffs label { font-size: calc(var(--hand-size) * .85); }

.envelope {
  background-color: var(--p-kraft); background-image: var(--grain), var(--mottle); background-size: 180px, 1400px;
  color: #3b2a1e; padding: 24px 22px 26px; position: relative;
  box-shadow: 0 12px 28px rgba(20,0,6,.45);
}
.envelope .field-label { color: #3b2a1e; }
.envelope input[type=email] {
  width: 100%; padding: 10px 12px; font: inherit; font-size: 17px;
  border: 1px solid rgba(59,42,30,.35); background: #f6ecd9; color: #2a1d14; border-radius: 0;
}
.envelope .check { display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: start; margin-top: 14px; font-size: 15px; line-height: 1.45; }
.envelope .check input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--seal); }
.envelope .fine { font-size: 13px; line-height: 1.5; margin: 14px 0 20px; color: #5a4636; }
.envelope .fine a { color: #7a1f2b; }
.envelope .status.error { color: #8a1525; font-style: normal; font-weight: 500; }
.honeypot { position: absolute; left: -9999px; }

.result { max-width: 640px; margin: 0 auto; padding: 0 24px 120px; }
.result .paper .letter-body { font-size: var(--hand-size); }
.result-actions { display: flex; flex-wrap: wrap; gap: 16px; margin-top: 32px; align-items: center; }
.result-actions a:not(.button) { font-style: italic; }

/* ── admin + small pages ─────────────────── */
.plain { max-width: 760px; margin: 0 auto; padding: 24px 24px 96px; }
.plain h1 { font-family: var(--display); font-weight: 400; font-size: 48px; margin: 24px 0 8px; }
.plain h2 { font-family: var(--display); font-weight: 400; font-size: 28px; margin: 40px 0 12px; }
.card { background: var(--ivory); color: #2b1d22; padding: 20px 22px; margin-bottom: 16px; }
.card .body { white-space: pre-wrap; margin: 0 0 10px; }
.card .why { font-size: 14px; font-style: italic; color: #6f5560; margin: 0 0 14px; }
.card .row { display: flex; gap: 10px; flex-wrap: wrap; }
.card .button { padding: 8px 18px; font-size: 15px; }
.card .button.ghost { background: transparent; box-shadow: 0 0 0 1px #6f5560 inset; color: #2b1d22; }
.plain input[type=password] { padding: 12px; font: inherit; width: min(320px, 100%); border: 0; margin-right: 8px; margin-bottom: 8px; }

footer.site { text-align: center; padding: 0 24px 48px; font-size: 14px; color: var(--muted-on-velvet); }

/* ── responsive ──────────────────────────── */
@media (max-width: 900px) {
  .desk { grid-template-columns: 1fr; gap: 36px; }
  .side { position: static; }
}
@media (max-width: 560px) {
  :root { --line: 30px; }
  .masthead { padding-top: 48px; }
  .pile { padding: 8px 16px 72px; gap: 18px; }
  .letter { margin-bottom: 26px; }
  .paper { --margin-x: 44px; --hole-x: 18px; padding-right: 18px; }
  .desk, .write-head, .topbar { padding-left: 16px; padding-right: 16px; }
  .sticky { width: 100%; min-height: 0; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
