/* ---------- letters page ---------- */
.letters-page { --hand: "Caveat", "Segoe Print", cursive; }
.letters-page .ed-account { margin-left: 12px; }

.lt-page { max-width: 980px; margin: 0 auto; padding: 36px 16px 64px; }
.lt-head { text-align: center; }
.lt-head h1 { margin: 4px 0 0; font-size: clamp(3rem, 10vw, 4.4rem); color: var(--rose-deep); line-height: 1.05; }
.lt-lead { margin: 4px 0 0; color: var(--muted); }
.lt-write { margin-top: 18px; padding: 12px 24px; font-size: 1rem; }

.lt-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px; margin: 32px 0 8px; }
.lt-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--card-border);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.8);
  box-shadow: var(--shadow);
}
.lt-tabs button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 18px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--navy);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}
.lt-tabs button[aria-selected="true"] { background: linear-gradient(90deg, var(--rose), var(--blue-500)); color: #fff; }
.lt-tabs button:focus-visible { outline: 2px solid var(--navy); outline-offset: 2px; }
.lt-count:empty { display: none; }
.lt-count {
  min-width: 22px;
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(47, 74, 128, 0.1);
  font-size: 0.75rem;
}
[aria-selected="true"] .lt-count { background: rgba(255, 255, 255, 0.25); }
.lt-count.new { background: var(--rose); color: #fff; }
.lt-filter {
  padding: 8px 14px;
  border: 1px dashed var(--rose);
  border-radius: 999px;
  background: #fff;
  color: var(--rose-deep);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}

.lt-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 28px 22px;
  margin-top: 24px;
}
.lt-empty { margin-top: 32px; padding: 32px 20px; border: 2px dashed var(--pink-200); border-radius: 24px; text-align: center; color: var(--muted); }
.lt-empty-art { margin: 0; font-size: 2.6rem; }
.lt-empty p { margin: 6px auto 0; max-width: 420px; }

/* ---------- envelope ---------- */
.envelope {
  --env: #fbd3e3;
  --env-dark: #f3aec9;
  --env-flap: #f7bfd5;
  --seal: var(--rose);
  display: flex;
  flex-direction: column;
  animation: rise 0.5s ease-out both calc(var(--i, 0) * 60ms);
}
.envelope.from-him { --seal: var(--blue-500); }
.envelope.sealed { --env: #f6dde8; --env-flap: #f0cbdb; }

.env {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 2;
  margin-top: 26px;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: none;
  cursor: pointer;
  perspective: 900px;
  -webkit-tap-highlight-color: transparent;
}
.env:focus-visible { outline: 3px solid var(--navy); outline-offset: 4px; }
.env > span { position: absolute; }
.env-back { inset: 0; border-radius: 16px; background: var(--env-dark); box-shadow: var(--shadow); }
.env-paper {
  z-index: 1;
  left: 8%;
  right: 8%;
  top: 8%;
  bottom: 8%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 9%;
  padding: 0 12%;
  border-radius: 8px;
  background: #fffdf8;
  transition: transform 0.5s cubic-bezier(0.3, 1.3, 0.5, 1) 0.25s;
}
.env-paper span { display: block; height: 3px; border-radius: 3px; background: var(--pink-200); }
.env-paper span:nth-child(2) { width: 80%; }
.env-paper span:nth-child(3) { width: 55%; }
.env-front {
  z-index: 2;
  inset: 0;
  border-radius: 16px;
  background: linear-gradient(160deg, var(--env), var(--env-dark));
  clip-path: polygon(0 0, 50% 54%, 100% 0, 100% 100%, 0 100%);
}
.env-flap {
  z-index: 3;
  top: 0;
  left: 0;
  right: 0;
  height: 60%;
  border-radius: 16px 16px 0 0;
  background: var(--env-flap);
  clip-path: polygon(0 0, 100% 0, 50% 100%);
  transform-origin: top center;
  transition: transform 0.45s ease, z-index 0s 0.2s;
  filter: drop-shadow(0 2px 2px rgba(196, 61, 108, 0.15));
}
.env-seal {
  z-index: 4;
  top: 58%;
  left: 50%;
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.45), transparent 45%), var(--seal);
  color: #fff;
  font-size: 1.2rem;
  box-shadow: 0 3px 8px rgba(47, 74, 128, 0.25), inset 0 0 0 3px rgba(255, 255, 255, 0.25);
  translate: -50% -50%;
  transition: opacity 0.25s ease, scale 0.25s ease;
}
.sealed .env-seal { font-size: 1rem; }
.env-badge {
  z-index: 5;
  top: -8px;
  right: -6px;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--rose);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}

/* hover: the flap lifts a little */
.new .env:hover .env-flap { transform: rotateX(18deg); }
.new .env { animation: bob 2.6s ease-in-out infinite; }
.new .env-back { box-shadow: 0 0 0 4px rgba(232, 98, 143, 0.25), 0 12px 30px rgba(232, 98, 143, 0.35); }

/* opened: flap folded back, letter peeking out */
.opening .env-flap { z-index: 0; transform: rotateX(180deg); }
/* folded back, it pokes up only a little so it never covers the card above */
.opened .env-flap { z-index: 0; transform: rotateX(180deg) scaleY(0.45); }
.opened .env-seal, .opening .env-seal { opacity: 0; scale: 0.4; }
.opened .env-paper { transform: translateY(-22%); }
.opening .env-paper { transform: translateY(-45%); }
.opened .env:hover .env-paper { transform: translateY(-30%); }

.shake .env { animation: shake 0.45s ease; }

.env-meta { padding: 12px 4px 0; text-align: center; }
.env-title { margin: 0; color: var(--navy); font-weight: 700; }
.env-name { margin: 2px 0 0; color: var(--rose-deep); font-family: var(--hand); font-size: 1.3rem; line-height: 1.1; overflow-wrap: anywhere; }
.env-sub { margin: 2px 0 0; color: var(--muted); font-size: 0.86rem; }
.new .env-sub { color: var(--rose-deep); font-weight: 700; }
.env-actions { display: flex; justify-content: center; gap: 14px; margin-top: 6px; }
.link-btn {
  padding: 4px 2px;
  border: 0;
  background: none;
  color: var(--blue-500);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 700;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--rose-deep); }
.link-btn:focus-visible { outline: 2px solid var(--navy); border-radius: 4px; }

/* ---------- sheets (reader + composer) ---------- */
.sheet {
  width: min(640px, calc(100% - 20px));
  max-height: calc(100dvh - 32px);
  padding: 0;
  border: 0;
  border-radius: 26px;
  background: transparent;
  color: var(--ink);
  overflow: visible;
}
.sheet::backdrop { background: rgba(47, 74, 128, 0.4); backdrop-filter: blur(4px); }
.sheet[open] { animation: unfold 0.45s cubic-bezier(0.2, 1.2, 0.4, 1); }
.sheet-close {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 50%;
  background: rgba(248, 200, 220, 0.6);
  color: var(--navy);
  font-size: 1.4rem;
  line-height: 1;
  cursor: pointer;
}
.sheet-close:focus-visible { outline: 2px solid var(--navy); }
.sheet-actions { display: flex; align-items: center; justify-content: flex-end; gap: 10px; margin-top: 14px; }

/* the letter itself: lined paper, handwriting */
.paper {
  position: relative;
  max-height: calc(100dvh - 120px);
  overflow-y: auto;
  padding: 40px 34px 30px;
  border-radius: 22px;
  background:
    linear-gradient(90deg, transparent 26px, rgba(232, 98, 143, 0.25) 26px, rgba(232, 98, 143, 0.25) 28px, transparent 28px),
    repeating-linear-gradient(180deg, #fffdf8 0 35px, #e7eef8 35px 36px);
  background-attachment: local;
  box-shadow: 0 24px 60px rgba(47, 74, 128, 0.3);
}
.paper-meta { margin: 0; color: var(--blue-500); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase; }
.paper-to { margin: 6px 0 0; color: var(--rose-deep); font-size: 2.6rem; line-height: 1.1; }
.paper-title { margin: 6px 0 0; color: var(--navy); font-family: var(--hand); font-size: 1.8rem; font-weight: 600; line-height: 1.1; }
.paper-body {
  margin-top: 14px;
  color: #3b3552;
  font-family: var(--hand);
  font-size: 1.55rem;
  line-height: 36px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.paper-sign { margin: 18px 0 0; text-align: right; color: var(--rose-deep); font-size: 2.2rem; }
.paper-foot { margin: 8px 0 0; text-align: right; color: var(--muted); font-size: 0.8rem; }
.reader .sheet-actions { justify-content: center; }

/* composer */
.composer form {
  position: relative;
  max-height: calc(100dvh - 32px);
  overflow-y: auto;
  padding: 26px 24px 20px;
  border-radius: 26px;
  background: var(--bg);
  box-shadow: 0 24px 60px rgba(47, 74, 128, 0.3);
}
.sheet-head h2 { margin: 0; padding-right: 44px; color: var(--rose-deep); font-size: 2.4rem; line-height: 1.1; }
.field select,
.field textarea {
  display: block;
  width: 100%;
  border: 1.5px solid var(--pink-200);
  border-radius: 14px;
  background: #fffafc;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field select { height: 48px; padding: 0 12px; cursor: pointer; }
.field textarea {
  min-height: 260px;
  padding: 6px 16px;
  resize: vertical;
  font-family: var(--hand);
  font-size: 1.45rem;
  font-weight: 500;
  line-height: 34px;
  background: repeating-linear-gradient(180deg, #fffdf8 0 33px, #e7eef8 33px 34px);
  background-attachment: local;
}
.field select:focus, .field textarea:focus { outline: none; border-color: var(--rose); box-shadow: 0 0 0 4px rgba(232, 98, 143, 0.15); }
.field-label small { color: var(--muted); font-weight: 600; }
.field-hint { margin: 6px 0 0; color: var(--muted); font-size: 0.82rem; }
.c-note { margin-right: auto; color: var(--muted); font-size: 0.8rem; }

@keyframes rise { from { opacity: 0; translate: 0 14px; } }
@keyframes bob { 0%, 100% { translate: 0 0; } 50% { translate: 0 -5px; } }
@keyframes shake {
  0%, 100% { rotate: 0deg; }
  20% { rotate: -4deg; }
  40% { rotate: 4deg; }
  60% { rotate: -3deg; }
  80% { rotate: 2deg; }
}
@keyframes unfold { from { opacity: 0; scale: 0.92; translate: 0 16px; } }

@media (max-width: 560px) {
  .lt-page { padding-top: 24px; }
  .lt-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 30px 14px; }
  .env-seal { width: 36px; height: 36px; font-size: 0.95rem; }
  .env-sub { font-size: 0.78rem; }
  .paper { padding: 36px 20px 24px; }
  .paper-body { font-size: 1.4rem; }
  .composer form { padding: 22px 16px 16px; }
  .sheet-actions .btn { padding: 10px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .envelope, .new .env, .shake .env, .sheet[open] { animation: none; }
  .env-flap, .env-paper, .env-seal { transition: none; }
}
