:root {
  --paper: #f7eeec;
  --paper-2: #f1e2df;
  --paper-3: #e8d0cc;
  --card: #fffaf9;
  --ink: #3b2b31;
  --muted: #9a8288;
  --red: #b9646f;
  --red-deep: #8a3d4b;
  --blue: #7d4a58;
  --stripe-a: #d39ca3;
  --stripe-b: #93566a;
  --line: rgba(125, 74, 88, 0.14);
  --notes-accent: #dba22c;
  --sys: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', system-ui, sans-serif;
  --hand: 'Caveat', 'Bradley Hand', cursive;
  --mono: 'Courier Prime', 'Courier New', monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; background-color: #f7eeec; }

body {
  margin: 0;
  background: var(--paper);
  background-image:
    radial-gradient(circle at 20% 10%, rgba(255, 255, 255, 0.6), transparent 40%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='160' height='160'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.4 0 0 0 0 0.3 0 0 0 0 0.2 0 0 0 .06 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  line-height: 1.5;
  overflow-x: hidden;
}

html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }

h1, h2 { font-family: var(--hand); font-weight: 700; margin: 0; line-height: 1; }
h2 { font-size: 2.6rem; color: var(--blue); }

.label, .bl {
  font-family: var(--mono);
  font-size: 0.7rem;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.hand { font-family: var(--hand); font-size: 1.9rem; line-height: 1; }
.hand.small { font-size: 1.3rem; }

/* ================= envelope screen ================= */
#envelope-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2.5rem;
  padding: 16px;
  background: inherit;
  background-color: var(--paper);
  transition: opacity 0.7s ease, visibility 0.7s;
}
#envelope-screen.gone { opacity: 0; visibility: hidden; pointer-events: none; }

.envelope {
  position: relative;
  width: min(88vw, 420px);
  aspect-ratio: 3 / 2;
  perspective: 1400px;
  animation: float 4s ease-in-out infinite;
}
.envelope.open { animation: none; }

@keyframes float {
  0%, 100% { transform: translateY(0) rotate(-1deg); }
  50% { transform: translateY(-8px) rotate(0.5deg); }
}

.env-body {
  position: absolute;
  inset: 0;
  border-radius: 6px;
  background: repeating-linear-gradient(-45deg,
    var(--stripe-a) 0 14px, var(--card) 14px 22px,
    var(--stripe-b) 22px 36px, var(--card) 36px 44px);
  box-shadow: 0 18px 40px -18px rgba(90, 45, 58, 0.45), 0 2px 6px rgba(90, 45, 58, 0.15);
}

.env-pocket {
  position: absolute;
  inset: 9px;
  z-index: 2;
  border-radius: 3px;
  background: var(--paper-2);
}

.address {
  position: absolute;
  left: 7%;
  bottom: 12%;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transform: rotate(-2deg);
}
.from {
  position: absolute;
  left: 7%;
  top: 8%;
  display: flex;
  flex-direction: column;
  opacity: 0.8;
}

.stamp {
  position: absolute;
  right: 7%;
  bottom: 12%;
  width: 58px;
  height: 70px;
  padding: 5px;
  background: var(--card);
  -webkit-mask: radial-gradient(circle 3.5px at 50% 50%, transparent 95%, #000) -3.5px -3.5px / 9px 9px, linear-gradient(#000, #000) center / calc(100% - 9px) calc(100% - 9px) no-repeat;
  mask: radial-gradient(circle 3.5px at 50% 50%, transparent 95%, #000) -3.5px -3.5px / 9px 9px, linear-gradient(#000, #000) center / calc(100% - 9px) calc(100% - 9px) no-repeat;
  transform: rotate(4deg);
}
.stamp-inner {
  height: 100%;
  background: var(--red);
  color: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: var(--hand);
  line-height: 1;
}
.stamp-heart { font-size: 1.6rem; }
.stamp-val { font-size: 1.1rem; font-weight: 700; }

.postmark {
  position: absolute;
  right: calc(7% + 32px);
  bottom: calc(12% + 22px);
  width: 78px;
  transform: rotate(-14deg);
  opacity: 0.55;
  pointer-events: none;
}
.postmark svg { display: block; }
.postmark circle { fill: none; stroke: var(--ink); stroke-width: 2; }
.postmark text { font-family: var(--mono); font-size: 10.5px; fill: var(--ink); letter-spacing: 0.06em; }
.postmark .pm-date { font-size: 13px; font-weight: 700; }

.env-flap {
  position: absolute;
  top: 9px;
  left: 9px;
  right: 9px;
  height: 58%;
  z-index: 3;
  transform-origin: top center;
  transition: transform 0.7s cubic-bezier(0.6, 0, 0.3, 1);
  filter: drop-shadow(0 3px 3px rgba(90, 45, 58, 0.18));
}
.env-flap::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, var(--paper-3), var(--paper-2));
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.envelope.open .env-flap { transform: rotateX(180deg); }
.envelope.flap-back .env-flap { z-index: 0; }

.letter-peek {
  position: absolute;
  left: 9%;
  right: 9%;
  top: 9%;
  height: 82%;
  z-index: 1;
  border-radius: 3px;
  box-shadow: 0 2px 8px rgba(90, 45, 58, 0.12);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  background: #fff;
  border-top: 3px solid var(--notes-accent);
  transition: transform 0.9s cubic-bezier(0.3, 0.7, 0.2, 1);
}
.envelope.letter-out .letter-peek { transform: translateY(-62%); }
.peek-title { font-family: var(--sys); font-weight: 700; font-size: 1.05rem; color: #1c1c1e; }
.peek-line { height: 7px; border-radius: 4px; background: #e9e9ec; }
.peek-line.short { width: 60%; }

.seal {
  position: absolute;
  left: 50%;
  top: calc(58% + 9px);
  z-index: 4;
  width: 68px;
  height: 68px;
  margin: -34px 0 0 -34px;
  border: 0;
  border-radius: 46% 54% 50% 50% / 52% 48% 52% 48%;
  background: radial-gradient(circle at 35% 30%, #d4848c, var(--red) 45%, var(--red-deep));
  box-shadow:
    inset 0 0 0 6px rgba(255, 255, 255, 0.08),
    inset 0 -4px 8px rgba(0, 0, 0, 0.25),
    0 4px 10px rgba(110, 40, 55, 0.35);
  color: rgba(255, 240, 230, 0.92);
  font-family: var(--hand);
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.35s ease, opacity 0.35s ease;
  -webkit-tap-highlight-color: transparent;
}
.seal::after {
  content: '';
  position: absolute;
  inset: -10px;
  border-radius: 50%;
  border: 2px solid var(--red);
  opacity: 0;
  animation: pulse 2.2s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(0.8); opacity: 0.6; }
  100% { transform: scale(1.35); opacity: 0; }
}
.seal:active { transform: scale(0.94); }
.envelope.open .seal { transform: scale(1.4) rotate(20deg); opacity: 0; pointer-events: none; }

.hint {
  margin: 0;
  font-family: var(--hand);
  font-size: 1.5rem;
  color: var(--muted);
  transition: opacity 0.3s;
}
.hint.hide { opacity: 0; }

/* ================= main ================= */
main {
  position: fixed;
  inset: 0;
  opacity: 0;
  transition: opacity 0.9s ease 0.2s;
}
body.opened main { opacity: 1; }

/* ---- pager: one page per section, swipe or tap ---- */
.pager {
  display: flex;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.pager::-webkit-scrollbar { display: none; }
.page {
  flex: 0 0 100%;
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  -webkit-overflow-scrolling: touch;
}
.page-inner {
  max-width: 560px;
  min-height: 100%;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 36px) 16px calc(env(safe-area-inset-bottom) + 96px);
}
.page-inner.center { display: flex; flex-direction: column; justify-content: center; }

.pager-nav {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 18px);
  z-index: 5;
  display: flex;
  gap: 2px;
  padding: 4px 8px;
  border-radius: 999px;
  background: rgba(255, 250, 249, 0.78);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 18px -10px rgba(90, 45, 58, 0.45);
  transform: translateX(-50%);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease 0.6s;
}
body.opened .pager-nav { opacity: 1; pointer-events: auto; }
.pager-nav .bar {
  display: grid;
  place-items: center;
  width: 40px;
  height: 32px;
  padding: 0;
  border: 0;
  background: none;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.pager-nav .bar::before {
  content: '';
  width: 22px;
  height: 7px;
  border-radius: 2px;
  background: var(--paper-3);
  transition: width 0.3s ease, background 0.3s ease;
}
.pager-nav .bar[aria-current="true"]::before { width: 32px; background: var(--red-deep); }
.pager-nav { align-items: center; }
.pager-nav .arrow {
  display: grid;
  place-items: center;
  width: 30px;
  height: 32px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--red-deep);
  cursor: pointer;
  transition: opacity 0.3s ease;
  -webkit-tap-highlight-color: transparent;
}
.pager-nav .arrow[disabled] { opacity: 0; pointer-events: none; }
.pager-nav .arrow.nudge svg { animation: nudge 1.3s ease-in-out infinite; }
@keyframes nudge { 0%, 100% { transform: translateX(0); } 50% { transform: translateX(5px); } }

.section-sub { color: var(--muted); font-size: 0.82rem; margin: 6px 0 0; }

.hero {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 14px;
  padding-top: 8px;
  text-align: left;
}
.eyebrow {
  font-size: 0.7rem;
  letter-spacing: 0.14em;
  color: var(--red);
  margin: 0 0 14px;
}
.hero h1 { font-size: clamp(2.5rem, 10.5vw, 3.8rem); }
.hero h1 { background: linear-gradient(transparent 62%, rgba(185, 100, 111, 0.2) 62%); display: inline; }
.hero .sub { color: var(--muted); margin: 14px 0 0; font-size: 0.9rem; }
.hero .eyebrow { grid-column: 1 / -1; margin-bottom: 0; white-space: nowrap; }
.polaroid {
  position: relative;
  width: clamp(96px, 27vw, 150px);
  margin: 0;
  padding: 6px 6px 22px;
  background: var(--card);
  box-shadow: 0 10px 22px -12px rgba(90, 45, 58, 0.55);
  transform: rotate(5deg);
}
.polaroid img { display: block; width: 100%; aspect-ratio: 4 / 5; object-fit: cover; background: var(--paper-2); }
.polaroid::before {
  content: '';
  position: absolute;
  top: -9px;
  left: 50%;
  width: 54px;
  height: 18px;
  margin-left: -27px;
  background: rgba(220, 190, 190, 0.6);
  transform: rotate(-4deg);
}

/* letter */
.letter-wrap { margin-top: 36px; }
.notes {
  overflow: hidden;
  background: #fff;
  border-radius: 22px;
  box-shadow: 0 1px 2px rgba(90, 45, 58, 0.08), 0 24px 48px -24px rgba(90, 45, 58, 0.45);
  font-family: var(--sys);
  color: #1c1c1e;
  -webkit-font-smoothing: antialiased;
}
.notes-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px 8px 12px;
  color: var(--notes-accent);
  font-size: 17px;
}
.notes-back { display: flex; align-items: center; gap: 5px; }
.notes-icons { display: flex; align-items: center; gap: 18px; }
.notes-body { padding: 4px 20px 8px; font-size: 17px; line-height: 1.4; letter-spacing: -0.01em; }
.notes-date { margin: 0 0 14px; text-align: center; font-size: 13px; color: #8e8e93; }
.notes h3 { margin: 0 0 6px; font-size: 28px; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
.notes p { margin: 0 0 1.2em; }
.notes ol { margin: 0 0 1.2em; padding-left: 1.6em; }
.notes li { margin-bottom: 0.35em; padding-left: 0.15em; }
.notes-tools {
  display: flex;
  justify-content: space-between;
  padding: 12px 26px 18px;
  border-top: 0.5px solid #e5e5ea;
  color: var(--notes-accent);
}

.r { opacity: 0; transform: translateY(10px); transition: opacity 0.7s ease, transform 0.7s ease; }
.r.in { opacity: 1; transform: none; }

/* tracker */
.labels { display: flex; flex-direction: column; gap: 22px; margin-top: 26px; }
.loading { color: var(--muted); font-size: 0.85rem; }

.ship {
  position: relative;
  background: var(--card);
  border: 1.5px solid var(--ink);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 4px 4px 0 rgba(90, 45, 58, 0.12);
}
.ship:nth-child(odd) { transform: rotate(-0.5deg); }
.ship:nth-child(even) { transform: rotate(0.6deg); }

.ship-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 14px;
  border-bottom: 1.5px dashed var(--ink);
  font-size: 0.78rem;
  letter-spacing: 0.1em;
}
.ship-head b { font-size: 0.95rem; }
.barcode {
  width: 88px;
  height: 22px;
  background: repeating-linear-gradient(90deg,
    var(--ink) 0 2px, transparent 2px 4px, var(--ink) 4px 5px, transparent 5px 8px,
    var(--ink) 8px 11px, transparent 11px 12px, var(--ink) 12px 13px, transparent 13px 16px);
}

.ship-body { padding: 14px; display: grid; gap: 12px; }
.row { display: grid; gap: 2px; }
.clue { font-family: var(--hand); font-size: 1.6rem; line-height: 1.1; }
.clue::before { content: '“'; color: var(--muted); }
.clue::after { content: '”'; color: var(--muted); }
.reveal { font-family: var(--hand); font-size: 1.55rem; line-height: 1.15; color: var(--red-deep); }

.progress { display: grid; grid-template-columns: repeat(4, 1fr); margin-top: 4px; }
.step {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  font-size: 0.62rem;
  color: var(--muted);
  text-align: center;
  line-height: 1.2;
}
.step::before {
  content: '';
  position: absolute;
  top: 6px;
  left: -50%;
  width: 100%;
  height: 2px;
  background: var(--paper-3);
}
.step:first-child::before { display: none; }
.step .dot {
  position: relative;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--paper-3);
}
.step.done::before { background: var(--blue); }
.step.done .dot { background: var(--blue); border-color: var(--blue); }
.step.done { color: var(--ink); }
.step.now .dot { box-shadow: 0 0 0 5px rgba(125, 74, 88, 0.18); animation: now 1.6s ease-in-out infinite; }
.step.now { font-weight: 700; }
@keyframes now { 50% { box-shadow: 0 0 0 8px rgba(125, 74, 88, 0.05); } }

.meta { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 16px; font-size: 0.78rem; }
.meta .missed { color: var(--red); font-weight: 700; }

.delivered-stamp {
  position: absolute;
  right: 12px;
  top: 52px;
  padding: 4px 10px;
  border: 3px solid var(--red);
  border-radius: 6px;
  color: var(--red);
  font-family: var(--mono);
  font-weight: 700;
  font-size: 1rem;
  letter-spacing: 0.12em;
  transform: rotate(-12deg);
  opacity: 0.85;
  animation: thunk 0.45s cubic-bezier(0.3, 1.6, 0.5, 1) both;
  pointer-events: none;
}
@keyframes thunk {
  from { transform: rotate(-12deg) scale(2.2); opacity: 0; }
  to { transform: rotate(-12deg) scale(1); opacity: 0.85; }
}

.updated { font-size: 0.72rem; color: var(--muted); margin-top: 14px; text-align: center; }

/* distance */
.distance { text-align: center; }
.km { font-family: var(--hand); font-size: clamp(4rem, 20vw, 5.5rem); font-weight: 700; line-height: 1; margin-top: 14px; color: var(--red); }
.km span { font-variant-numeric: tabular-nums; }

.route { display: block; width: 100%; max-width: 360px; margin: 18px auto 0; overflow: visible; }
.route path { fill: none; stroke: var(--blue); stroke-width: 1.5; stroke-dasharray: 4 6; }
.route circle { fill: var(--red); }
.route text { font-family: var(--hand); font-size: 18px; fill: var(--ink); }
.route .plane text { fill: var(--blue); font-family: sans-serif; }

.clocks { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
.clock {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 14px 10px;
  background: var(--card);
  border-radius: 6px;
  box-shadow: 0 1px 2px rgba(90, 45, 58, 0.08), 0 8px 20px -14px rgba(90, 45, 58, 0.4);
}
.clock .time { font-size: 1.9rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.clock .date { font-size: 0.75rem; color: var(--muted); }

.board {
  margin-top: 28px;
  padding: 18px 16px 16px;
  background: #2f2328;
  color: #f6e8e6;
  border-radius: 10px;
  text-align: left;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05), 0 14px 30px -16px rgba(0, 0, 0, 0.6);
}
.board-head { font-size: 0.72rem; letter-spacing: 0.2em; color: #e9a8ae; margin-bottom: 12px; }
.board-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.board-row > div { display: flex; flex-direction: column; gap: 6px; }
.board .bl { color: #a8949a; }
.flap { display: flex; gap: 3px; min-height: 34px; }
.flap .ch {
  position: relative;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 32px;
  background: #1f171b;
  border-radius: 3px;
  font-size: 1.15rem;
  font-weight: 700;
  color: #f6e8e6;
}
.flap .ch::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 1px;
  background: rgba(0, 0, 0, 0.7);
}
.flap.blink .ch { color: #e9a8ae; animation: blink 1.4s steps(2, start) infinite; }
@keyframes blink { 50% { opacity: 0.35; } }
.board-foot { margin: 4px 0 0; font-family: var(--hand); font-size: 1.35rem; color: #f6e8e6; }



@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition-duration: 0.01ms !important; }
  .r { opacity: 1; transform: none; }
}
