/* ============ 색 ============ */
:root {
  --bg: #FBEFF1;
  --ink: #3A1F3D;
  --muted: #7A5A7C;
  --accent: #C9304F;
  --cherry: #E8476A;
  --mint: #4FA58E;
  --mint-ink: #2F6B5B;
  --mint-soft: #DDF1EA;
  --soft: #F3DCE2;
  --line: #E3C6CF;
  --dot-line: #D7B5C0;
  --card: #FFFFFF;
  --paper: #FFFDF8;
  --btn-bg: #3A1F3D;
  --btn-ink: #FBEFF1;
  --shadow: rgba(58, 31, 61, .12);
  --sheet-bg: #2B1630;
  --env-flap: #FFF7F9;
  --env-fold: #F0DCE2;
  --seal-dark: #3A1F3D;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1E1221;
    --ink: #F6E6EA;
    --muted: #BFA3C1;
    --accent: #F0708C;
    --cherry: #F0708C;
    --mint: #7FC8B4;
    --mint-ink: #8FD6C1;
    --mint-soft: #22403A;
    --soft: #33213A;
    --line: #4A3150;
    --dot-line: #4F3656;
    --card: #2A1A2E;
    --paper: #2E1F31;
    --btn-bg: #F6E6EA;
    --btn-ink: #1E1221;
    --shadow: rgba(0, 0, 0, .4);
    --sheet-bg: #120A14;
    --env-flap: #33223A;
    --env-fold: #3E2A44;
    --seal-dark: #C9304F;
    color-scheme: dark;
  }
}

/* ============ 기본 ============ */
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Gowun Batang', 'Apple SD Gothic Neo', serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
p { margin: 0; }
h2 { margin: 0; font-size: 24px; font-weight: 700; letter-spacing: -.5px; }
[hidden] { display: none !important; }

.hand { font-family: 'Gaegu', cursive; }
.muted { color: var(--muted); }
.accent { color: var(--accent); }
.mint { color: var(--mint-ink); }
.small { font-size: 15px; }

#app {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: env(safe-area-inset-bottom);
}

/* ============ 상단 바 ============ */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  height: 56px; padding: 0 8px;
  padding-top: env(safe-area-inset-top);
  height: calc(56px + env(safe-area-inset-top));
  background: var(--bg);
}
.icon-btn {
  width: 44px; height: 44px; border: 0; background: transparent;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.icon-btn:disabled { visibility: hidden; }
#muteBtn .ic-off { display: none; }
#muteBtn.off .ic-on { display: none; }
#muteBtn.off .ic-off { display: block; }
.dots { display: flex; gap: 8px; }
.dots span { width: 8px; height: 8px; border-radius: 50%; background: var(--line); transition: background .3s; }
.dots span.on { background: var(--ink); }

/* ============ 화면 전환 ============ */
.screen { flex: 1; display: flex; flex-direction: column; }
.screen.enter { animation: screenIn .45s cubic-bezier(.2,.7,.2,1); }
@keyframes screenIn { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.screen.leave { animation: screenOut .25s ease forwards; }
@keyframes screenOut { to { opacity: 0; transform: translateY(-8px); } }

.next-wrap { margin-top: auto; padding: 24px 24px 32px; }
.btn-next {
  display: flex; align-items: center; justify-content: center; width: 100%;
  height: 56px; border-radius: 28px; border: 0;
  background: var(--btn-bg); color: var(--btn-ink); font-size: 18px;
  transition: transform .12s;
}
.btn-next:active { transform: scale(.97); }
.btn-outline {
  height: 52px; padding: 0 32px; border-radius: 26px;
  border: 1.5px solid var(--ink); background: transparent; font-size: 17px;
  transition: transform .12s, background .2s;
}
.btn-outline:active { transform: scale(.96); background: var(--soft); }
.link-btn {
  display: flex; align-items: center; height: 44px; padding: 0 8px;
  border: 0; background: transparent; font-size: 15px;
  text-decoration: underline; text-underline-offset: 3px;
}

/* ============ 사진 ============ */
.photo {
  border-radius: 6px; overflow: hidden; background: var(--soft);
  min-height: 200px; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: 15px;
}
.photo img { width: 100%; height: auto; display: block; }
.photo.has-img { min-height: 0; }
.polaroid {
  align-self: center; margin-top: 16px; padding: 10px 10px 32px;
  background: #FFFFFF; box-shadow: 0 6px 18px var(--shadow);
}
.polaroid .ph {
  background: #F3DCE2; display: flex; align-items: center; justify-content: center;
  color: #7A5A7C; font-size: 14px; overflow: hidden;
}
.polaroid .ph img { width: 100%; height: 100%; object-fit: cover; object-position: center 20%; display: block; }
.tilt-r { transform: rotate(2deg); }
.tilt-l { transform: rotate(-2deg); }

/* ============ 자정 전 ============ */
.waiting {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 28px; padding: 0 32px 60px; text-align: center;
}
.envelope-sm { width: 240px; height: 160px; animation: float 3.5s ease-in-out infinite; }
@keyframes float { 50% { transform: translateY(-8px) rotate(-1deg); } }
.env-body { fill: var(--card); stroke: var(--line); stroke-width: 2; }
.env-flap { fill: var(--env-flap); stroke: var(--line); stroke-width: 2; stroke-linejoin: round; }
.env-fold { stroke: var(--env-fold); stroke-width: 2; }
.seal-dark { fill: var(--seal-dark); }
.seal-line { stroke: #FBEFF1; }
.waiting-text { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.waiting-title { font-size: 20px; font-weight: 700; }
.countdown {
  font-size: 52px; font-weight: 700; letter-spacing: 1px; color: var(--accent);
  font-variant-numeric: tabular-nums; line-height: 1.1;
}
.countdown .days { display: block; font-size: 22px; letter-spacing: 0; }
.waiting .hand { font-size: 21px; }

/* ============ 잠금화면 ============ */
.lock {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  padding: calc(72px + env(safe-area-inset-top)) 32px 48px;
}
.lock-icon { stroke: var(--accent); overflow: visible; }
.lock-icon .shackle { transition: transform .5s cubic-bezier(.3,1.6,.5,1); transform-origin: 16px 11px; }
.lock-icon.open .shackle { transform: translate(5px, -3px) rotate(28deg); }
.lock-icon.open { animation: pop .6s ease; }
@keyframes pop { 40% { transform: scale(1.2); } }
.lock-q { margin-top: 24px; font-size: 24px; font-weight: 700; letter-spacing: -.5px; text-align: center; }
.lock-sub { margin-top: 8px; font-size: 15px; color: var(--muted); }
.pin { display: flex; gap: 16px; margin-top: 40px; }
.pin span {
  width: 14px; height: 14px; border-radius: 50%;
  border: 1.5px solid var(--ink); transition: background .12s, transform .12s;
}
.pin span.on { background: var(--ink); transform: scale(1.1); }
.pin.shake { animation: shake .5s; }
.pin.ok span { background: var(--mint); border-color: var(--mint); }
@keyframes shake {
  10%, 90% { transform: translateX(-2px); }
  20%, 80% { transform: translateX(5px); }
  30%, 50%, 70% { transform: translateX(-10px); }
  40%, 60% { transform: translateX(10px); }
}
.lock-msg { margin-top: 20px; min-height: 33px; font-size: 22px; color: var(--accent); text-align: center; }
.lock-hint { font-size: 20px; color: var(--muted); animation: screenIn .4s; }
.keypad {
  display: grid; grid-template-columns: repeat(3, 72px); gap: 18px 28px;
  margin-top: auto; padding-top: 24px;
}
.keypad button {
  width: 72px; height: 72px; border-radius: 50%; border: 0;
  background: var(--soft); font-size: 28px;
  transition: background .1s, transform .1s;
}
.keypad button:active { background: var(--line); transform: scale(.94); }
.keypad .key-del { background: transparent; display: flex; align-items: center; justify-content: center; }
@media (max-height: 700px) {
  .lock { padding-top: 40px; }
  .pin { margin-top: 24px; }
  .keypad { gap: 12px 24px; grid-template-columns: repeat(3, 64px); }
  .keypad button { width: 64px; height: 64px; }
}

/* ============ 카운터 ============ */
.counter { display: flex; flex-direction: column; align-items: center; padding: 40px 24px 48px; text-align: center; }
.names { font-size: 22px; color: var(--muted); }
.counter-lead { margin-top: 20px; font-size: 18px; }
.big-num {
  font-size: 132px; line-height: 1; font-weight: 700; letter-spacing: -6px;
  color: var(--accent); font-variant-numeric: tabular-nums;
}
.counter-unit { margin-top: 6px; font-size: 22px; font-weight: 700; }
#liveTime { margin-top: 28px; font-variant-numeric: tabular-nums; }
@media (max-width: 360px) { .big-num { font-size: 108px; } }
.dash-line { margin: 0 24px; border-top: 1.5px dashed var(--line); }
.stats { display: flex; flex-direction: column; padding: 36px 24px 0; gap: 20px; }
.stat-list { display: flex; flex-direction: column; }
.stat-row {
  display: flex; justify-content: space-between; gap: 16px;
  padding: 14px 0; border-bottom: 1px dotted var(--dot-line);
}
.stat-row b { font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.stat-row b.hl { color: var(--accent); }
.stats .note { font-size: 20px; margin-top: -8px; }

/* ============ 이유 ============ */
.sec-head { display: flex; flex-direction: column; padding: 24px 24px 0; gap: 12px; }
.progress { display: flex; align-items: center; gap: 12px; }
.bar { flex: 1; height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.bar-fill { height: 100%; width: 0; border-radius: 3px; background: var(--mint); transition: width .5s ease; }
.reason-card {
  margin: 32px 24px 0; padding: 28px 24px 32px; min-height: 170px;
  background: var(--card); border-radius: 4px;
  box-shadow: 0 10px 28px var(--shadow);
  transform: rotate(-1.5deg);
  display: flex; flex-direction: column; gap: 16px;
}
.reason-card.draw { animation: draw .55s cubic-bezier(.2,.8,.3,1.2); }
@keyframes draw {
  0% { transform: rotate(-1.5deg) translateY(0) scale(1); }
  35% { transform: rotate(4deg) translateY(-16px) scale(.94); opacity: .2; }
  100% { transform: rotate(-1.5deg) translateY(0) scale(1); opacity: 1; }
}
.reason-no { font-size: 15px; color: var(--accent); font-weight: 700; }
.reason-text { font-size: 34px; line-height: 1.25; word-break: keep-all; }
.reason-card.empty .reason-text { font-size: 26px; color: var(--muted); }
.reason-card.done { background: var(--mint-soft); }
.reason-actions { display: flex; flex-direction: column; align-items: center; gap: 8px; margin-top: 32px; }

.seen-sheet { background: rgba(20, 8, 22, .55); display: flex; align-items: flex-end; justify-content: center; }
.seen-panel {
  width: 100%; max-width: 560px; max-height: 80vh; max-height: 80dvh;
  background: var(--bg); border-radius: 20px 20px 0 0;
  display: flex; flex-direction: column;
  animation: sheetUp .35s cubic-bezier(.2,.8,.2,1);
  padding-bottom: env(safe-area-inset-bottom);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
.seen-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 4px 24px; }
.seen-head h3 { margin: 0; font-size: 20px; }
.seen-list { list-style: none; margin: 0; padding: 0 24px 24px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.seen-list li { display: flex; gap: 12px; padding: 12px 0; border-bottom: 1px dotted var(--dot-line); }
.seen-list .n { flex: 0 0 40px; color: var(--accent); font-weight: 700; font-size: 15px; padding-top: 3px; }
.seen-list .t { font-family: 'Gaegu', cursive; font-size: 21px; line-height: 1.35; word-break: keep-all; }
.seen-list .empty { color: var(--muted); padding: 24px 0; }

/* ============ 쿠폰 ============ */
.sec-head + .coupon-list { margin-top: 20px; }
.coupon-list { display: flex; flex-direction: column; gap: 12px; padding: 0 24px; }
.coupon {
  display: flex; align-items: stretch; min-height: 96px; padding: 0; border: 0;
  border-radius: 10px; background: var(--card); text-align: left;
  box-shadow: 0 4px 14px var(--shadow);
  transition: transform .15s;
}
.coupon:active { transform: scale(.97) rotate(-.5deg); }
.coupon-art {
  flex: 0 0 80px; display: flex; align-items: center; justify-content: center;
  background: var(--mint-soft); border-radius: 10px 0 0 10px;
  border-right: 2px dashed var(--bg);
}
.coupon-art svg { stroke: var(--ink); }
.coupon-body { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 3px; padding: 12px 18px; }
.coupon-no { font-size: 12px; color: var(--mint-ink); }
.coupon-title { font-size: 18px; font-weight: 700; }
.coupon-desc { font-size: 14px; color: var(--muted); word-break: keep-all; }
.coupon-actions { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 28px 24px 0; text-align: center; }
.coupon-actions .hand { font-size: 20px; word-break: keep-all; }

.sheet { position: fixed; inset: 0; z-index: 50; }
.coupon-viewer {
  background: var(--sheet-bg); color: #FBEFF1;
  display: flex; flex-direction: column; align-items: center;
  padding: calc(8px + env(safe-area-inset-top)) 24px calc(32px + env(safe-area-inset-bottom));
  animation: fadeIn .25s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.viewer-top { align-self: stretch; display: flex; justify-content: space-between; align-items: center; height: 56px; max-width: 512px; width: 100%; margin: 0 auto; }
.viewer-top span { font-size: 15px; color: #D7B5C0; }
.viewer-img-wrap { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; width: 100%; }
.viewer-img-wrap img {
  max-width: min(100%, 320px); max-height: 100%; height: auto;
  border-radius: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.4);
  -webkit-touch-callout: default; user-select: auto;
}
.viewer-img-wrap img.slide { animation: slideIn .3s ease; }
@keyframes slideIn { from { opacity: 0; transform: translateX(var(--dx, 24px)); } }
.viewer-hint { display: flex; align-items: center; gap: 10px; margin-top: 18px; font-size: 16px; }
.viewer-nav { margin-top: 16px; align-self: stretch; display: flex; justify-content: space-between; max-width: 512px; width: 100%; margin-left: auto; margin-right: auto; }
.round-btn {
  width: 52px; height: 52px; border-radius: 50%; border: 1.5px solid #6E4F72;
  background: transparent; color: #FBEFF1; display: flex; align-items: center; justify-content: center;
}
.round-btn:disabled { opacity: .3; }

/* ============ 편지 ============ */
.envelope-stage {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 28px; padding-bottom: 80px;
}
.envelope-btn { border: 0; background: transparent; padding: 0; }
.envelope { width: 300px; max-width: calc(100vw - 48px); height: auto; overflow: visible; display: block; }
.envelope-btn:not(.opening) .envelope { animation: wiggle 3s ease-in-out infinite; }
@keyframes wiggle { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-2deg); } 90% { transform: rotate(2deg); } 95% { transform: rotate(-1deg); } }
.envelope .flap { transform-origin: 150px 6px; transition: transform .6s ease; transform-box: view-box; }
.envelope-btn.opening .flap { transform: scaleY(-1); }
.envelope-btn.opening { animation: envDrop .9s .5s ease forwards; }
@keyframes envDrop { to { transform: translateY(40px) scale(.9); opacity: 0; } }
.seal { fill: #C9304F; }
.seal-text { font-family: 'Gowun Batang', serif; font-size: 18px; font-weight: 700; fill: #FBEFF1; }
.env-hint { font-size: 24px; }

.letter-stage { display: flex; flex-direction: column; padding: 24px 20px 40px; flex: 1; }
.letter {
  background: var(--paper); border-radius: 4px;
  box-shadow: 0 12px 32px var(--shadow);
  padding: 36px 28px 32px;
  display: flex; flex-direction: column; gap: 18px;
  font-family: 'Gaegu', cursive; font-size: 21px; line-height: 1.6; word-break: keep-all;
  background-image: repeating-linear-gradient(transparent, transparent 33px, var(--soft) 33px, var(--soft) 34px);
  animation: letterUp .9s cubic-bezier(.2,.8,.2,1);
}
@keyframes letterUp { from { transform: translateY(60vh) rotate(3deg); } to { transform: none; } }
.letter .to { font-size: 24px; font-weight: 700; }
.letter .sign { margin-top: 8px; text-align: right; }
.letter .date { text-align: right; font-size: 17px; color: var(--muted); margin-top: -12px; }
.letter p { opacity: 0; transform: translateY(6px); transition: opacity .9s ease, transform .9s ease; }
.letter p.show, .reveal.show { opacity: 1; transform: none; }
.reveal { opacity: 0; transition: opacity .9s ease; }
.reveal.polaroid { transform: rotate(-2deg); margin-top: 32px; }
.to-index { align-self: center; margin-top: 24px; font-size: 16px; }

/* ============ 목차 ============ */
.index { display: flex; flex-direction: column; padding: calc(72px + env(safe-area-inset-top)) 24px 40px; }
.index-day { display: flex; align-items: baseline; gap: 8px; margin-top: 8px; }
.index-num { font-size: 72px; font-weight: 700; letter-spacing: -3px; color: var(--accent); line-height: 1; }
.index-unit { font-size: 20px; font-weight: 700; }
.index .small { margin-top: 10px; }
.index-list { display: flex; flex-direction: column; gap: 12px; margin-top: 40px; }
.index-list button {
  display: flex; justify-content: space-between; align-items: center;
  height: 68px; padding: 0 22px; border: 0; border-radius: 12px;
  background: var(--card); font-size: 18px; text-align: left;
  box-shadow: 0 2px 8px var(--shadow);
  transition: transform .12s;
}
.index-list button:active { transform: scale(.98); }
.index-list button .small { margin-top: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
