:root {
  --bg: #f6dfe3;
  --dot: #e9c3cb;
  --ink: #3e4a78;
  --accent: #d9485f;
  --chip: rgba(255, 250, 244, 0.86);
}

* { box-sizing: border-box; }
html { overflow: hidden; }
html.can-scroll { overflow-y: auto; }
body { margin: 0; min-height: 100%; }
body {
  background-color: var(--bg);
  background-image: radial-gradient(var(--dot) 1.4px, transparent 1.6px);
  background-size: 22px 22px;
  font-family: 'Fredoka', system-ui, sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
#stage, #stage canvas { position: fixed; inset: 0; display: block; touch-action: none; }

.overlay {
  position: fixed; top: max(28px, env(safe-area-inset-top)); left: 0; right: 0;
  text-align: center; pointer-events: none; padding: 0 16px;
}
#title {
  margin: 0; font-size: clamp(30px, 6vw, 56px); font-weight: 700; letter-spacing: 0.01em;
  color: var(--accent);
  text-shadow: 0 2px 0 #fff4f0, 0 6px 18px rgba(217, 72, 95, 0.18);
}
#note {
  margin: 8px 0 0; font-family: 'Gaegu', cursive; font-weight: 700; font-size: 14px; opacity: 0;
  transition: opacity 0.6s ease;
}
#note.show { opacity: 0.6; }
#hint {
  position: fixed; left: 0; right: 0; bottom: max(28px, env(safe-area-inset-bottom));
  text-align: center; pointer-events: none; padding: 0 16px;
  margin: 0; font-family: 'Gaegu', cursive; font-size: clamp(18px, 3.4vw, 24px); font-weight: 700;
}
#title, #hint {
  opacity: 0; transform: translateY(-8px) scale(0.96);
  transition: opacity 0.35s ease, transform 0.5s cubic-bezier(.2, 1.6, .4, 1);
}
#title.show, #hint.show { opacity: 1; transform: none; }
#hint.show { animation: bob 2.2s ease-in-out infinite 0.6s; }
@keyframes bob { 50% { transform: translateY(4px); } }

.icon-btn, #controls {
  background: var(--chip); border: 2px dashed #e7a1ae; box-shadow: 0 6px 18px rgba(120, 60, 80, 0.12);
  backdrop-filter: blur(6px);
}
.icon-btn {
  position: fixed; top: max(16px, env(safe-area-inset-top)); right: 16px;
  width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; padding: 0;
}
.icon-btn svg { width: 22px; height: 22px; fill: var(--ink); stroke: var(--ink); stroke-width: 1.8; stroke-linecap: round; }
.icon-btn .cross { display: none; }
.icon-btn.muted .wave { display: none; }
.icon-btn.muted .cross { display: block; }

#controls {
  position: fixed; top: max(16px, env(safe-area-inset-top)); right: 70px; height: 44px;
  transform: translateY(-8px); opacity: 0; pointer-events: none;
  display: flex; align-items: center; gap: 10px; padding: 0 5px; border-radius: 999px;
  font-family: 'Gaegu', cursive; font-weight: 700; font-size: 18px;
  transition: opacity 0.4s ease, transform 0.5s cubic-bezier(.2, 1.4, .4, 1);
  max-width: calc(100vw - 32px);
}
#controls.show { opacity: 1; transform: none; pointer-events: auto; }
#replay {
  font: inherit; color: #fff; background: var(--accent); border: 0; border-radius: 999px;
  padding: 6px 14px; cursor: pointer;
}
/* phones: a button (same pill as replay, in the same dashed chip) instead of the scroll hint */
#read {
  position: fixed; left: 50%; bottom: max(28px, env(safe-area-inset-bottom));
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none;
  font-family: 'Gaegu', cursive; font-weight: 700; font-size: 18px; color: #fff;
  background: var(--accent); border: 0; border-radius: 999px; padding: 6px 16px; cursor: pointer; white-space: nowrap;
  outline: 2px dashed #e7a1ae; outline-offset: 6px;
  box-shadow: 0 0 0 8px var(--chip), 0 6px 18px 8px rgba(120, 60, 80, 0.12);
  transition: opacity 0.4s ease, transform 0.5s cubic-bezier(.2, 1.4, .4, 1);
}
#read.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }

#loader {
  position: fixed; inset: 0; display: grid; place-items: center;
  font-family: 'Gaegu', cursive; font-size: 22px; font-weight: 700; pointer-events: none;
  transition: opacity 0.4s;
}
body:not(.loading) #loader { opacity: 0; }

/* ------------------------------------------------------------------ letter */
#veil {
  position: fixed; inset: 0; pointer-events: none; opacity: 0;
  background: rgba(246, 223, 227, 0.88); backdrop-filter: blur(3px);
}
#scroller { display: none; position: relative; pointer-events: none; }
html.can-scroll #scroller { display: block; }
.spacer { height: 100vh; height: 100svh; }
#letter { pointer-events: auto; padding: 5vh 16px 8vh; display: grid; justify-items: center; gap: 44px; cursor: pointer; }

/* felt: the same fibre texture the 3D card uses (--fibre is set from js), blended over a flat colour */
.felt-frame {
  pointer-events: auto; position: relative; cursor: auto;
  width: min(880px, 100%); padding: 12px; border-radius: 36px;
  background: var(--fibre) 0 0 / 256px, #eaa3b3;
  background-blend-mode: overlay;
  box-shadow: inset 0 0 0 1px rgba(150, 70, 90, 0.25), 0 22px 50px rgba(120, 60, 80, 0.25);
}
.paper {
  position: relative;
  min-height: 86vh; min-height: 86svh;
  padding: clamp(124px, 16vh, 156px) clamp(28px, 7vw, 88px) clamp(56px, 8vh, 88px);
  background: var(--fibre) 0 0 / 256px, #f6ecdc;
  background-blend-mode: overlay;
  border-radius: 26px;
  box-shadow: 0 3px 5px rgba(90, 40, 50, 0.3), 0 1px 1px rgba(90, 40, 50, 0.2);
  outline: 2px dashed #e7a1ae; outline-offset: -14px;
  color: var(--ink); font-family: 'Gaegu', cursive;
}
.bunting { position: absolute; top: 20px; left: 50%; width: 78%; aspect-ratio: 320 / 40; transform: translateX(-50%); }
.bunting svg { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }
.flag { position: absolute; width: 7%; aspect-ratio: 1 / 0.92; transform: translateX(-50%); filter: drop-shadow(0 2px 1.5px rgba(90, 40, 50, 0.35)); }
.flag::before {
  content: ''; position: absolute; inset: 0;
  background: var(--fibre) 0 0 / 128px, var(--c); background-blend-mode: overlay;
  clip-path: polygon(0 0, 100% 0, 50% 100%);
}
.greeting { margin: 0 0 22px; font-family: 'Fredoka', sans-serif; font-weight: 700; font-size: clamp(32px, 5vw, 50px); color: var(--accent); }
.message { font-size: clamp(21px, 2.2vw + 10px, 30px); line-height: 1.5; font-weight: 700; word-break: keep-all; overflow-wrap: break-word; }
.message p { margin: 0 0 0.8em; }
.signoff { margin: 36px 0 0; text-align: right; font-size: clamp(21px, 2.2vw + 10px, 30px); font-weight: 700; }
.from { font-family: 'Fredoka', sans-serif; color: var(--accent); }
.back-up { margin: 0; font-family: 'Gaegu', cursive; font-weight: 700; font-size: 18px; opacity: 0.7; }

/* little felt appliqués: the shadow sits on the span, the clipped felt shape on ::before */
.deco { position: absolute; display: block; filter: drop-shadow(0 2px 1.5px rgba(90, 40, 50, 0.35)); }
.deco::before {
  content: ''; position: absolute; inset: 0;
  background: var(--fibre) 0 0 / 128px, var(--c); background-blend-mode: overlay;
  clip-path: var(--clip, none); border-radius: var(--round, 0);
}
.deco.star { width: 34px; height: 34px; --c: #f6e39a;
  --clip: polygon(50% 0, 62% 35%, 98% 37%, 69% 59%, 79% 95%, 50% 74%, 21% 95%, 31% 59%, 2% 37%, 38% 35%); }
.deco.s1 { top: 30px; right: 30px; transform: rotate(12deg); }
.deco.s2 { bottom: 34px; left: 30px; width: 26px; height: 26px; --c: #a8dccb; transform: rotate(-10deg); }
.deco.heart { width: 30px; height: 28px; bottom: 30px; left: 66px; --c: #e05a6a;
  --clip: path('M15 27 C6 20 0 14 0 8 C0 3 4 0 8 0 C11 0 13 2 15 5 C17 2 19 0 22 0 C26 0 30 3 30 8 C30 14 24 20 15 27 Z'); }
.deco.dot { width: 12px; height: 12px; --round: 50%; --c: #f2b2bd; }
.deco.d1 { top: 76px; left: 34px; }
.deco.d2 { top: 52%; right: 26px; --c: #b9c7f2; }

/* phones: tighter top of the letter, and drop the dot that sat in that gap */
@media (max-width: 600px) {
  .paper { padding-top: 92px; }
  .bunting { top: 16px; }
  .deco.d1 { display: none; }
}
