:root {
  --paper: #f6efe6;
  --paper-deep: #efe4d6;
  --cream: #fffaf3;
  --ink: #3b332c;
  --ink-soft: #7a6e63;
  --ink-faint: #b8ada0;
  --rose: #c9736b;
  --rose-soft: #e8b4ae;
  --sage: #8ea58c;
  --gold: #d2a85a;
  --shadow: 0 18px 40px rgba(76, 58, 40, 0.18);
  --font-body: "Gowun Dodum", "Apple SD Gothic Neo", sans-serif;
  --font-hand: "Nanum Pen Script", cursive;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  background-image:
    radial-gradient(circle at 20% 10%, rgba(255,255,255,0.7), transparent 45%),
    radial-gradient(circle at 80% 90%, rgba(201,115,107,0.08), transparent 40%);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
/* 종이 결 */
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0; opacity: .35;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.4 0 0 0 0 0.33 0 0 0 0 0.25 0 0 0 .08 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

#app {
  position: relative; z-index: 1;
  max-width: 430px; margin: 0 auto; height: 100dvh;
}

.scene {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: max(24px, env(safe-area-inset-top)) 20px max(24px, env(safe-area-inset-bottom));
  opacity: 0; pointer-events: none; transform: translateY(12px);
  transition: opacity .7s ease, transform .7s ease;
}
.scene.active { opacity: 1; pointer-events: auto; transform: none; }
.scene.scroll { justify-content: flex-start; overflow-y: auto; -webkit-overflow-scrolling: touch; }

.scene-caption {
  color: var(--ink-soft); font-size: 15px; letter-spacing: .02em; margin: 0 0 28px;
}

/* ---------- 버튼 ---------- */
button { font-family: inherit; cursor: pointer; }
.primary-btn, .ghost-btn {
  border-radius: 999px; padding: 14px 26px; font-size: 15px; letter-spacing: .02em;
  transition: transform .15s ease, box-shadow .15s ease, opacity .3s;
}
.primary-btn {
  border: 0; color: #fff; background: var(--rose);
  box-shadow: 0 10px 24px rgba(201,115,107,.35);
}
.primary-btn:active { transform: scale(.97); }
.ghost-btn {
  border: 1px solid var(--ink-faint); background: transparent; color: var(--ink-soft);
}
.ghost-btn:active { transform: scale(.97); }

/* ---------- 1. 비밀번호 ---------- */
.lock { display: flex; flex-direction: column; align-items: center; width: 100%; }
.lock-hint { color: var(--ink-soft); font-size: 15px; margin: 0 0 26px; }
.dots { display: flex; gap: 16px; margin-bottom: 44px; }
.dots i {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--ink-faint); transition: background .2s, border-color .2s, transform .2s;
}
.dots i.on { background: var(--rose); border-color: var(--rose); transform: scale(1.15); }
.dots.shake { animation: shake .45s; }
@keyframes shake {
  20%, 60% { transform: translateX(-8px); } 40%, 80% { transform: translateX(8px); }
}
.keypad {
  display: grid; grid-template-columns: repeat(3, 76px); gap: 16px 22px; justify-content: center;
}
.keypad button {
  width: 76px; height: 76px; border-radius: 50%; border: 0;
  background: var(--cream); color: var(--ink); font-size: 26px; font-family: var(--font-body);
  box-shadow: 0 6px 16px rgba(76,58,40,.08), inset 0 -2px 0 rgba(76,58,40,.06);
  transition: transform .1s, background .1s;
}
.keypad button:active { transform: scale(.94); background: var(--paper-deep); }
.keypad button[data-key="del"] { font-size: 20px; color: var(--ink-soft); background: transparent; box-shadow: none; }
.lock-error { color: var(--rose); font-size: 14px; margin: 26px 0 0; opacity: 0; transition: opacity .3s; height: 18px; }
.lock-error.show { opacity: 1; }

/* ---------- 3. 촛불 ---------- */
.cake-wrap { position: relative; width: 300px; }
.cake { width: 100%; height: auto; overflow: visible; }
.flame { transform-origin: 0 81px; animation: flicker 1.1s ease-in-out infinite alternate; transition: opacity .35s, transform .35s; }
#c2 .flame { animation-delay: .3s; } #c3 .flame { animation-delay: .6s; }
@keyframes flicker {
  0%   { transform: scaleY(1) skewX(0deg); }
  50%  { transform: scaleY(1.08) skewX(3deg); }
  100% { transform: scaleY(.94) skewX(-3deg); }
}
.candle.out .flame { opacity: 0; transform: scaleY(.2); }
.smoke { opacity: 0; transform: translateY(0); }
.candle.out .smoke { animation: smoke 2.2s ease-out forwards; }
@keyframes smoke {
  0% { opacity: .9; transform: translateY(0); } 100% { opacity: 0; transform: translateY(-50px); }
}
.mic-meter {
  margin: 16px auto 0; width: 160px; height: 4px; border-radius: 4px; background: rgba(76,58,40,.08); overflow: hidden;
}
.mic-meter i { display: block; height: 100%; width: 0; background: var(--rose-soft); transition: width .08s; }
.candle-done {
  font-family: var(--font-hand); font-size: 46px; margin: 24px 0 0; color: var(--ink);
  opacity: 0; transform: translateY(10px); transition: opacity .8s, transform .8s;
}
.candle-done.show { opacity: 1; transform: none; }
#candle-fallback { margin-top: 18px; }

/* ---------- 4. 편지 ---------- */
#scene-letter { justify-content: flex-start; padding-top: max(20px, env(safe-area-inset-top)); }
.paper {
  position: relative; width: 100%; flex: 1; min-height: 0;
  background: var(--cream);
  background-image: repeating-linear-gradient(transparent 0 35px, rgba(76,58,40,.07) 35px 36px);
  background-position: 0 42px;
  border-radius: 6px; box-shadow: var(--shadow);
  overflow: hidden;
}
.paper::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(135deg, rgba(255,255,255,.35), transparent 40%);
}
.hand-letter {
  position: absolute; inset: 0; overflow-y: auto; padding: 44px 26px 60px;
  font-family: var(--font-hand); font-size: var(--hand-size, 30px); line-height: 36px; color: var(--ink);
  word-break: keep-all;
}
.hand-letter .word { display: inline-block; white-space: nowrap; }
.hand-letter p { margin: 0; min-height: 36px; }
.hand-letter .ch {
  display: inline-block; opacity: 0; transform: translateY(2px) rotate(-2deg); filter: blur(1px);
  transition: opacity .18s ease, transform .22s ease, filter .22s ease;
}
.hand-letter .ch.on { opacity: 1; transform: none; filter: none; }
.letter-video { width: 100%; height: 100%; object-fit: cover; display: block; }
/* 이미지 손글씨: 위에서 아래로 번지듯 드러남 */
.letter-image { position: absolute; inset: 0; overflow-y: auto; }
.letter-image[hidden] { display: none; }
.letter-image img {
  width: 100%; display: block;
  --p: 0%;
  -webkit-mask-image: linear-gradient(to bottom, #000 calc(var(--p) - 6%), transparent var(--p));
  mask-image: linear-gradient(to bottom, #000 calc(var(--p) - 6%), transparent var(--p));
}
.letter-actions {
  display: flex; gap: 10px; margin-top: 16px; width: 100%; justify-content: center;
  animation: rise .6s ease both;
}
.letter-actions[hidden] { display: none; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

/* ---------- 5. 사진 연표 ---------- */
.tl-head { text-align: center; padding: 28px 0 16px; }
.tl-head h2 { font-family: var(--font-hand); font-size: 40px; margin: 0; font-weight: 400; }
.tl-head p { margin: 4px 0 0; color: var(--ink-soft); font-size: 14px; }
.timeline {
  list-style: none; margin: 0; padding: 12px 0 0; width: 100%; position: relative;
}
.timeline::before {
  content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 1px;
  background: repeating-linear-gradient(var(--ink-faint) 0 6px, transparent 6px 12px);
}
.polaroid {
  position: relative; width: 240px; margin: 0 auto 34px; padding: 12px 12px 50px;
  background: #fff; box-shadow: var(--shadow);
  opacity: 0; transform: translateY(40px) rotate(var(--rot, -3deg)) scale(.96);
  transition: opacity .8s ease, transform .8s cubic-bezier(.2,.8,.2,1);
}
.polaroid.in { opacity: 1; transform: translateY(0) rotate(var(--rot, -3deg)); }
.polaroid:nth-child(even) { --rot: 2.5deg; }
.polaroid:nth-child(3n) { --rot: -1.5deg; }
.polaroid .pic {
  aspect-ratio: 4 / 5; width: 100%; background: var(--paper-deep); overflow: hidden;
  display: grid; place-items: center;
}
.polaroid .pic img { width: 100%; height: 100%; object-fit: cover; object-position: var(--focus, 50% 50%); display: block; }
.polaroid .pic.placeholder {
  background: linear-gradient(135deg, var(--c1), var(--c2));
  color: rgba(255,255,255,.85); font-family: var(--font-hand); font-size: 30px;
}
.polaroid .meta { position: absolute; left: 12px; right: 12px; bottom: 12px; text-align: center; }
.polaroid .cap { font-family: var(--font-hand); font-size: 23px; color: var(--ink); line-height: 1.15; }
.polaroid .tape {
  position: absolute; top: -10px; left: 50%; width: 70px; height: 20px;
  transform: translateX(-50%) rotate(-2deg);
  background: rgba(210,168,90,.35); backdrop-filter: blur(1px);
}
.tl-foot { display: flex; justify-content: center; padding: 10px 0 40px; }

/* ---------- 6. 마무리 ---------- */
.end { width: 100%; padding: 40px 0; text-align: center; }
.end h2 { font-family: var(--font-hand); font-size: 44px; font-weight: 400; margin: 0 0 10px; }
.end p { color: var(--ink-soft); line-height: 1.75; margin: 0 0 32px; font-size: 15px; }

#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 50; }

/* ---------- 보관함 ---------- */
.year-badge {
  align-self: flex-start; margin: 0 0 10px; font-size: 12px; letter-spacing: .14em; color: var(--ink-faint);
}
.archive { margin-top: 48px; text-align: left; }
.archive h3 { font-family: var(--font-hand); font-size: 32px; font-weight: 400; margin: 0; }
.archive-hint { font-size: 13px; color: var(--ink-faint); margin: 2px 0 14px !important; }
.archive-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.archive-item {
  width: 100%; display: flex; align-items: center; gap: 14px; text-align: left;
  border: 0; border-radius: 14px; padding: 14px 16px; background: var(--cream);
  box-shadow: 0 8px 20px rgba(76,58,40,.08); color: var(--ink);
  transition: transform .15s;
}
.archive-item:active { transform: scale(.98); }
.archive-item .yr { font-family: var(--font-hand); font-size: 30px; line-height: 1; min-width: 70px; }
.archive-item .sub { font-size: 13px; color: var(--ink-soft); }
.archive-item.current { outline: 1.5px solid var(--rose-soft); }
.archive-item .stamp {
  margin-left: auto; font-size: 11px; color: var(--rose); border: 1px solid var(--rose-soft);
  border-radius: 999px; padding: 3px 8px;
}
