/* Letters to the Future — the keepsake register.
 *
 * base.css supplies the tokens, the type and the buttons. Everything here is the desk and the
 * letter, and two rules run through the whole file:
 *
 *   1. **The paper is a set of custom properties, set once, in JavaScript.** `--lt-*` is written
 *      onto :root by whichever page is showing (letter/app.js, read.js, manage.js) from the single
 *      palette in shared/letters.js. So the desk, the sealed page and the opened page cannot drift
 *      apart, and "Midnight" is a data attribute rather than a second stylesheet.
 *   2. **Nothing is defined only inside a media query.** Dusk is a dark PAPER, not a dark mode —
 *      a letter written late looks the same on both of your phones, whatever your system says.
 *
 * Type follows BRAND §3: Gowun Batang for the letter itself, because a letter is exactly the
 * keepsake moment that face is reserved for; Pretendard for the desk around it; Space Mono for
 * labels and the countdown.
 */

:root {
  /* Fallbacks, so a page that has not applied a paper yet is still legible rather than white. */
  --lt-bg: #F3EDE3;
  --lt-paper: #FFFDF8;
  --lt-border: #E7E2DA;
  --lt-ink: #17181C;
  --lt-soft: #5B5E68;
  --lt-accent: #14A3AF;
  --lt-accent-text: #FFFFFF;
  --lt-seal: #E4C79A;
  --lt-rule: rgba(23, 24, 28, .07);
}

body.letters {
  background: var(--lt-bg);
  color: var(--lt-ink);
  transition: background .35s ease, color .35s ease;
}
body.letters .page { background: transparent; }
body.letters ::selection { background: var(--lt-seal); color: var(--lt-ink); }

/* ── the desk ─────────────────────────────────────────────────────────────────────────────── */
.desk {
  width: min(720px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 28px 0 120px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.desk-head { display: flex; flex-direction: column; gap: 10px; }
.desk-back {
  font: 600 13px var(--mono);
  color: var(--lt-soft);
  text-decoration: underline;
  text-underline-offset: 3px;
  letter-spacing: .04em;
  align-self: flex-start;
}
.desk-title { color: var(--lt-ink); max-width: 16ch; }
.desk-lead { color: var(--lt-soft); }

/* the 01 / 02 / 03 rhythm from the front of house
 *
 * --lt-accent is the paper's IDENTITY colour — the seal, the send button, the hue you picked. At
 * 12px uppercase on the desk it was 2.68:1 on Dawn and 2.91 on Fern (REALUSE-1 §2, Cause B),
 * against the 4.5 AA asks of small text. The shell's answer to exactly this is --teal-deep, "the
 * small-text member" (STYLE-GUIDE §02) — but that token belongs to the cream face and this page has
 * four papers, one of them dark, so a single teal would be wrong on three of them. The same idea,
 * expressed in this page's own tokens: the accent walked partway towards the paper's own ink, which
 * is the colour that is readable on that paper by construction.
 *
 * Measured on the desk through the paper picker, 2026-09-05 — Dawn 2.68 → 5.86, Airmail 5.58 →
 * 8.59, Dusk 9.50 → 11.76, Fern 2.91 → 5.61. Two of the four already passed and still gain; the
 * hue survives on all four, which is the thing a flat darkening would have cost.
 *
 * The number was opacity: .55 on that same accent, which is a contrast cut no probe can see in a
 * computed colour: the probe read the un-faded 2.68 while the eye got about 1.8:1 on Dawn. It is
 * quieter now by being the paper's own soft ink — a real token with a measured pairing (Dawn 5.56,
 * Airmail 5.19, Dusk 6.73, Fern 4.64) — rather than by being faded. */
.label { font: 700 12px/1 var(--mono); letter-spacing: .14em; text-transform: uppercase; color: color-mix(in srgb, var(--lt-accent) 55%, var(--lt-ink)); margin: 0; }
.label__num { color: var(--lt-soft); margin-right: 6px; }

.rail { display: flex; gap: 6px; flex-wrap: wrap; }
.rail-step {
  display: inline-flex; align-items: baseline; gap: 6px;
  padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--lt-border);
  font: 600 12px var(--mono); letter-spacing: .08em; text-transform: uppercase;
  color: var(--lt-soft); opacity: .6;
}
.rail-step.is-now { opacity: 1; color: var(--lt-accent-text); background: var(--lt-accent); border-color: var(--lt-accent); }
.rail-step.is-done { opacity: 1; color: var(--lt-ink); }
.rail-num { opacity: .6; }
@media (max-width: 520px) { .rail-label { display: none; } }

.step { display: flex; flex-direction: column; gap: 20px; }
.step-head { display: flex; flex-direction: column; gap: 8px; }
.step-sub { margin: 0; color: var(--lt-soft); font-size: 16px; max-width: 52ch; }
.step-actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding-top: 4px; }
.step-actions .next { flex: 1 1 240px; }
.field-label { color: var(--lt-soft); }

/* ── the sheet you write on ───────────────────────────────────────────────────────────────── */
.lt-sheet {
  position: relative;
  background: var(--lt-paper);
  border: 1px solid var(--lt-border);
  border-radius: var(--r8);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 14px 40px rgba(0, 0, 0, .06);
  padding: 10px;
}
/* Airmail earns its border: the two of you, as the stripe on a par-avion envelope. It frames the
   sheet you write on and the two ENVELOPE faces (sealed, waiting) — never the opened letter, which
   already has the framed sheet inside it and would otherwise be wearing two borders. */
body.paper-edge .lt-sheet::before,
body.paper-edge .letter--sealed::before,
body.paper-edge .letter--waiting::before {
  content: '';
  position: absolute; inset: 0;
  border-radius: inherit;
  padding: 4px;
  background: repeating-linear-gradient(45deg, var(--pink) 0 10px, transparent 10px 20px, var(--blue) 20px 30px, transparent 30px 40px);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  mask-composite: exclude;
  opacity: .5;
  pointer-events: none;
}

.body-input.input {
  background: transparent;
  border: 0;
  min-height: 320px;
  padding: 14px 16px;
  color: var(--lt-ink);
  font-family: var(--serif);
  font-size: 18px;
  line-height: 32px;
  /* ruled paper, drawn rather than tiled, so it lines up with the leading above */
  background-image: repeating-linear-gradient(to bottom, transparent 0 31px, var(--lt-rule) 31px 32px);
  background-attachment: local;
  resize: vertical;
}
.body-input.input:focus { border: 0; outline: none; box-shadow: none; }
.lt-sheet:focus-within { border-color: var(--lt-accent); }
.subject-input.input { background: var(--lt-paper); border-color: var(--lt-border); color: var(--lt-ink); }
.subject-input.input:focus { border-color: var(--lt-accent); }

.body-head { align-items: center; gap: 12px; }
.body-foot { align-items: baseline; min-height: 20px; }
.saved-note { font: 12px var(--mono); color: var(--lt-soft); opacity: .7; }
.body-count { color: var(--lt-soft); }
.body-count.is-short { color: var(--lt-accent); }
.body-count.is-full { color: var(--red); }

.prompt-btn { border-color: var(--lt-border); background: var(--lt-paper); color: var(--lt-ink); }
.prompt-line {
  margin: 0;
  padding: 14px 16px;
  border-left: 3px solid var(--lt-accent);
  background: color-mix(in srgb, var(--lt-accent) 7%, transparent);
  border-radius: 0 var(--r8) var(--r8) 0;
  font-family: var(--serif);
  font-size: 17px;
  color: var(--lt-ink);
}
.prompt-line.is-new { animation: lt-rise .32s ease both; }
@keyframes lt-rise { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ── the four papers ──────────────────────────────────────────────────────────────────────── */
.paper-row { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 640px) { .paper-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.paper-pick {
  display: flex; flex-direction: column; align-items: flex-start; gap: 4px;
  padding: 12px; border-radius: var(--r8);
  border: 1px solid var(--lt-border);
  background: var(--lt-paper);
  color: var(--lt-ink);
  text-align: left;
  min-height: var(--tap);
  transition: border-color .15s ease, transform .08s ease;
}
.paper-pick:hover { transform: translateY(-1px); }
.paper-pick[aria-checked="true"] { border-color: var(--lt-accent); box-shadow: inset 0 0 0 1px var(--lt-accent); }
.paper-swatch {
  width: 100%; aspect-ratio: 3 / 2; border-radius: var(--r4); border: 1px solid;
  display: grid; place-items: center; font-size: 20px; margin-bottom: 4px;
}
.paper-name { font-weight: 700; font-size: 14px; }
.paper-sub { font-size: 12px; color: var(--lt-soft); line-height: 1.3; }

/* ── when ─────────────────────────────────────────────────────────────────────────────────── */
.window-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
@media (max-width: 640px) { .window-row { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 380px) { .window-row { grid-template-columns: 1fr; } }
.window-opt, .pick {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-start; text-align: left;
  padding: 14px; border-radius: var(--r8);
  border: 1px solid var(--lt-border); background: var(--lt-paper); color: var(--lt-ink);
  min-height: var(--tap);
  transition: border-color .15s ease, transform .08s ease;
}
.window-opt:hover, .pick:hover { transform: translateY(-1px); }
.window-opt[aria-checked="true"], .pick[aria-checked="true"] {
  border-color: var(--lt-accent);
  box-shadow: inset 0 0 0 1px var(--lt-accent);
}
.window-label, .pick-label { font-weight: 700; font-size: 16px; }
.window-sub, .pick-sub { font-size: 13px; color: var(--lt-soft); line-height: 1.35; }

.custom-box { display: flex; flex-direction: column; gap: 6px; }
.custom-date.input { background: var(--lt-paper); border-color: var(--lt-border); color: var(--lt-ink); max-width: 260px; }
.when-line { margin: 0; font-family: var(--serif); font-size: 18px; color: var(--lt-ink); }
.zone-note { margin: 0; font: 12px var(--mono); color: var(--lt-soft); opacity: .75; }
.err { margin: 0; color: var(--red); font-size: 14px; font-weight: 600; }
.ok { margin: 0; color: var(--green); font-size: 14px; font-weight: 600; }

/* ── who ──────────────────────────────────────────────────────────────────────────────────── */
.pick-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.step--who .pick-row + .field .pick-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 640px) { .pick-row { grid-template-columns: 1fr; } }
.excerpt-box { display: flex; flex-direction: column; gap: 8px; }
.excerpt-preview {
  margin: 0; padding: 14px 16px;
  background: var(--lt-paper); border: 1px dashed var(--lt-border); border-radius: var(--r8);
  font-family: var(--serif); font-size: 16px; line-height: 1.55; color: var(--lt-ink);
}
.excerpt-note { margin: 0; font-size: 13px; color: var(--lt-soft); }

/* ── confirm ──────────────────────────────────────────────────────────────────────────────── */
.summary {
  border: 1px solid var(--lt-border); border-radius: var(--r8);
  background: var(--lt-paper); overflow: hidden;
}
.summary-row { display: flex; justify-content: space-between; gap: 16px; padding: 12px 16px; }
.summary-row + .summary-row { border-top: 1px solid var(--lt-border); }
.summary-k { font: 700 12px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--lt-soft); }
.summary-v { font-weight: 600; text-align: right; }

.readback {
  background: var(--lt-paper); border: 1px solid var(--lt-border); border-radius: var(--r8);
  padding: 20px; max-height: 340px; overflow-y: auto;
}
.readback-title { margin: 0 0 10px; font-family: var(--serif); font-size: 20px; font-weight: 700; }
.readback-body, .letter-body {
  font-family: var(--serif); font-size: 17px; line-height: 1.75;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.delivery-note {
  margin: 0; padding: 14px 16px; border-radius: var(--r8);
  background: color-mix(in srgb, var(--lt-accent) 8%, transparent);
  border: 1px solid color-mix(in srgb, var(--lt-accent) 25%, transparent);
  font-size: 15px; line-height: 1.5;
}

/* ── sealed / read / manage ───────────────────────────────────────────────────────────────── */
.read-wrap, .sealed {
  width: min(660px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 40px 0 100px;
  display: flex; flex-direction: column; gap: 20px;
}
.sealed { align-items: stretch; text-align: center; }
.letter { display: flex; flex-direction: column; gap: 16px; position: relative; }
/* Room for the airmail frame to sit in without landing on the last line of text. */
body.paper-edge .letter--sealed, body.paper-edge .letter--waiting { padding: 28px 24px; }
.letter--sealed, .letter--waiting, .letter--gone, .letter--manage { align-items: center; text-align: center; }
.letter--manage { align-items: stretch; text-align: left; }
.letter--manage .letter-title, .letter--manage .eyebrow, .letter--manage .wax { align-self: center; text-align: center; }
.letter-title { color: var(--lt-ink); }

.wax {
  width: 56px; height: 56px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--lt-seal); color: var(--lt-paper);
  font-size: 24px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
  align-self: center;
}
.wax--big { width: 84px; height: 84px; font-size: 36px; }
.wax.is-cracked { animation: lt-pulse 2.6s ease-in-out infinite; }
@keyframes lt-pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.05); } }

.countdown { margin: 0; font-size: clamp(28px, 7vw, 44px); font-weight: 700; letter-spacing: .02em; color: var(--lt-accent); }
.sealed-line, .waiting-line, .sealed-when { color: var(--lt-soft); }
.letter-written, .sealed-fine, .sealed-where, .sealed-note, .opened-at, .wall-sub {
  margin: 0; font-size: 14px; color: var(--lt-soft); line-height: 1.5;
}
.arrived-eyebrow, .opened-eyebrow { color: var(--lt-accent); }

.lt-sheet--read { padding: 32px clamp(20px, 5vw, 44px) 40px; text-align: left; }
.letter-date { margin: 0 0 20px; font: 12px var(--mono); letter-spacing: .12em; text-transform: uppercase; color: var(--lt-soft); }
.letter-body { color: var(--lt-ink); }

.link-box { gap: 6px; }
.link-field.input { background: var(--lt-paper); border-color: var(--lt-border); color: var(--lt-ink); font: 13px var(--mono); }
.copy-btn { flex: none; border-color: var(--lt-border); background: var(--lt-paper); color: var(--lt-ink); }
.desk-link { align-self: center; color: var(--lt-soft); }

/* ── the wall of openings ─────────────────────────────────────────────────────────────────── */
.wall { display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--lt-border); padding-top: 24px; }
.wall-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.wall-item {
  padding: 16px 18px; border-radius: var(--r8);
  background: var(--lt-paper); border: 1px solid var(--lt-border);
}
.wall-quote { margin: 0; font-family: var(--serif); font-size: 16px; line-height: 1.6; color: var(--lt-ink); }
.wall-held { margin: 8px 0 0; font: 11px var(--mono); letter-spacing: .1em; text-transform: uppercase; color: var(--lt-soft); }

/* ── dark paper ───────────────────────────────────────────────────────────────────────────── */
/* Dusk swaps the roles of ink and paper rather than inverting, so the pink accent still reads as
   a person and not as an alert. */
body.paper-dark .btn-ghost { background: var(--lt-paper); border-color: var(--lt-border); color: var(--lt-ink); }
body.paper-dark .btn-primary { background: var(--lt-accent); color: var(--lt-accent-text); }
body.paper-dark .btn-primary:hover { background: var(--lt-accent); filter: brightness(1.06); }
body.paper-dark .btn-link { color: var(--lt-soft); }
body.paper-dark .rail-step.is-done { color: var(--lt-ink); }
body.paper-dark .toast { background: var(--lt-paper); color: var(--lt-ink); }

@media (prefers-reduced-motion: reduce) {
  .wax.is-cracked { animation: none; }
  .prompt-line.is-new { animation: none; }
  .paper-pick:hover, .window-opt:hover, .pick:hover { transform: none; }
}
