/* 한겨울 밤하늘 위에 종이 편지를 올려 두는 구성. 색은 밤(배경), 종이, 잉크, 밀랍 도장 네 가지로 정한다. */
:root {
  --night: #0f1b2d;
  --night-soft: #172a45;
  --paper: #fbf5e6;
  --paper-edge: #e6dcc3;
  --ink: #2b2118;
  --ink-soft: #6f6250;
  --seal: #b3262e;
  --seal-dark: #8a1a21;
  --text: #e9eef6;
  --text-soft: #9fb0c8;
  --font-title: "Gowun Batang", "Noto Serif KR", "Malgun Gothic", serif;
  --font-body: "Gowun Dodum", "Noto Sans KR", "Malgun Gothic", system-ui, sans-serif;
  --font-hand: "Gaegu", "Gowun Dodum", "Malgun Gothic", cursive;
  color-scheme: dark;
}

/* 편지함 종류마다 밤하늘 색만 조금 바꾼다. 기본과 연말은 남색 밤이다. */
body[data-occasion="birthday"] { --night: #1b1530; --night-soft: #34264f; }
body[data-occasion="graduation"] { --night: #0e2230; --night-soft: #1c3d50; }
body[data-occasion="thanks"] { --night: #1d1622; --night-soft: #3b2a36; }
body { transition: background-color .4s; }

* { box-sizing: border-box; }

html { min-height: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 17px;
  line-height: 1.65;
  background-color: var(--night);
  background-image:
    radial-gradient(1.5px 1.5px at 12% 18%, rgba(255,255,255,.7), transparent),
    radial-gradient(1px 1px at 78% 12%, rgba(255,255,255,.6), transparent),
    radial-gradient(1.5px 1.5px at 40% 42%, rgba(255,255,255,.5), transparent),
    radial-gradient(1px 1px at 88% 56%, rgba(255,255,255,.6), transparent),
    radial-gradient(1.5px 1.5px at 22% 78%, rgba(255,255,255,.5), transparent),
    radial-gradient(1px 1px at 64% 88%, rgba(255,255,255,.6), transparent),
    radial-gradient(120% 70% at 50% 0%, var(--night-soft), var(--night) 70%);
  background-attachment: fixed;
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.page {
  position: relative;
  z-index: 1;
  max-width: 560px;
  margin: 0 auto;
  padding-block: max(32px, env(safe-area-inset-top, 0px)) max(48px, env(safe-area-inset-bottom, 0px));
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  display: grid;
  gap: 20px;
}

h1, h2 { font-family: var(--font-title); line-height: 1.35; margin: 0; text-wrap: balance; }
h1 { font-size: clamp(26px, 7vw, 34px); }
h2 { font-size: 20px; }
p { margin: 0; }
a { color: #f1c97a; text-underline-offset: 3px; }
a:focus-visible, button:focus-visible, input:focus-visible, textarea:focus-visible { outline: 2px solid #f1c97a; outline-offset: 2px; }

.eyebrow { font-size: 13px; letter-spacing: .08em; color: var(--text-soft); }
.lede { color: var(--text-soft); }
.small { font-size: 14px; }
.soft { color: var(--text-soft); }

/* 도장 */
.seal {
  width: 52px; height: 52px; border-radius: 50%;
  display: grid; place-items: center; flex: none;
  background: radial-gradient(circle at 35% 30%, #d8434b, var(--seal) 55%, var(--seal-dark));
  box-shadow: 0 3px 8px rgba(0,0,0,.45), inset 0 -3px 5px rgba(0,0,0,.25);
  color: #ffe9e6; font-family: var(--font-title); font-weight: 700; font-size: 22px;
}
.head { display: flex; gap: 16px; align-items: center; }

/* 종이 */
.paper {
  background: var(--paper);
  color: var(--ink);
  border-radius: 6px;
  padding: 22px 20px;
  box-shadow: 0 10px 28px rgba(0,0,0,.4), 0 0 0 1px var(--paper-edge) inset;
  display: grid;
  gap: 14px;
}
.paper .soft { color: var(--ink-soft); }
.paper h2 { color: var(--ink); }

label, .label { font-weight: 700; font-size: 15px; }
.field { display: grid; gap: 6px; }

input[type="text"], input[type="date"], textarea {
  width: 100%;
  font: inherit;
  color: var(--ink);
  background: #fffdf6;
  border: 1px solid var(--paper-edge);
  border-radius: 6px;
  padding: 10px 12px;
}
input[readonly] { font-size: 14px; background: #f3ecd8; }
textarea {
  resize: vertical;
  min-height: 190px;
  font-family: var(--font-hand);
  font-size: 22px;
  line-height: 32px;
  padding-block: 4px;
  background-image: repeating-linear-gradient(transparent 0 31px, #ddd3b8 31px 32px);
  background-attachment: local;
}
.counter { text-align: right; font-size: 13px; color: var(--ink-soft); }
.check { display: flex; gap: 10px; align-items: center; font-weight: 400; }
.check input { width: 18px; height: 18px; accent-color: var(--seal); }

.btn {
  font: inherit; font-weight: 700; cursor: pointer;
  color: #fff; background: var(--seal);
  border: 0; border-radius: 999px; padding: 12px 22px;
  text-decoration: none; text-align: center; display: inline-block;
}
.btn:hover { background: var(--seal-dark); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--paper-edge); font-weight: 400; }
.btn.ghost:hover { background: #f3ecd8; }
.btn.small { padding: 6px 14px; font-size: 14px; }
.btn.danger { background: var(--seal-dark); }
.on-night { color: var(--text); border-color: #3a4f6e; }
.on-night:hover { background: var(--night-soft); }

.error { color: var(--seal-dark); font-size: 15px; font-weight: 700; min-height: 1.4em; }
.notice { font-size: 14px; color: var(--ink-soft); border-top: 1px dashed var(--paper-edge); padding-top: 12px; }
.warn { background: #f7e3d4; border-radius: 6px; padding: 10px 12px; font-size: 14px; color: #5b2a17; }

.linkrow { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.linkrow .label { grid-column: 1 / -1; font-size: 14px; font-weight: 700; }
.linkrow input { min-width: 0; }

[hidden] { display: none !important; }
.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

/* 받은 편지 */
.letter {
  background: var(--paper); color: var(--ink);
  border-radius: 4px; padding: 20px 20px 14px;
  box-shadow: 0 8px 22px rgba(0,0,0,.4);
  font-family: var(--font-hand); font-size: 22px; line-height: 1.5;
  display: grid; gap: 10px;
}
.letter:nth-child(odd) { transform: rotate(-.6deg); }
.letter:nth-child(even) { transform: rotate(.5deg); }
.letter .body { white-space: pre-wrap; }
.letter .foot { display: flex; justify-content: space-between; align-items: center; font-size: 17px; color: var(--ink-soft); }

.envelope {
  text-align: center; display: grid; gap: 10px; justify-items: center;
}
.dday { font-family: var(--font-title); font-size: 34px; color: var(--seal); }

.mine { display: grid; gap: 8px; }
.mine a { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; background: #f3ecd8; border-radius: 6px; color: var(--ink); text-decoration: none; }
.mine a:hover { background: #ece2c7; }

@media (prefers-reduced-motion: no-preference) {
  .letter, .paper { animation: rise .45s ease-out both; }
  @keyframes rise { from { opacity: .6; translate: 0 10px; } to { opacity: 1; translate: 0 0; } }
}

/* ---------- 장면: 우체통 (편지 쓰기) ---------- */
.rule { border: 0; border-top: 1px dashed var(--paper-edge); width: 100%; margin: 0; }

.mailbox-btn {
  display: block; width: 100%; max-width: 440px; margin: 0 auto; padding: 0;
  background: none; border: 0; border-radius: 12px; cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.mailbox-btn:disabled { cursor: default; }
.mailbox-scene { display: block; width: 100%; height: auto; overflow: visible; }
.mailbox-scene .door { transform-box: fill-box; transform-origin: 50% 100%; }
.mailbox-scene .flag { transform-origin: 275px 172px; }
.mailbox-scene .inside { opacity: 0; }

.mailbox-btn.is-open .door { transform: scaleY(.07); }
.mailbox-btn.is-open .inside { opacity: 1; }
.mailbox-btn.is-sent .flag { transform: rotate(180deg); }

.hint { text-align: center; color: var(--text-soft); }

/* 눈, 색종이, 꽃잎, 반딧불은 편지지 뒤에 깔린다. .page가 위에 있고 편지지는 불투명해서 편지 영역에는 보이지 않는다. */
.ambience { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.ambience i { position: absolute; top: -12px; border-radius: 50%; background: #fff; opacity: 0; }
.confetti i { border-radius: 1px; height: auto !important; aspect-ratio: 2 / 1; }
.confetti .c0 { background: #e0565b; } .confetti .c1 { background: #f0c24e; } .confetti .c2 { background: #5aa9c9; } .confetti .c3 { background: #7cc08a; }
.petals i { background: #f3b6c9; border-radius: 100% 0; }
.petals .c1, .petals .c3 { background: #f9d3df; }
.fireflies i { top: auto; bottom: -12px; background: #ffd98a; box-shadow: 0 0 8px 2px rgba(255, 210, 122, .55); }


@media (prefers-reduced-motion: no-preference) {
  .mailbox-scene .door { transition: transform .55s cubic-bezier(.3, 1.5, .5, 1); }
  .mailbox-scene .flag { transition: transform .8s cubic-bezier(.3, 1.4, .5, 1); }
  .mailbox-scene .inside { transition: opacity .3s .15s; }
  .ambience i { animation: snow var(--fall) linear var(--delay) infinite; }
  .confetti i, .petals i { animation-name: flutter; }
  .fireflies i { animation: firefly var(--fall) ease-in-out var(--delay) infinite; }
  .mailbox-scene .balloons { animation: bob 3.2s ease-in-out infinite alternate; }
  .mailbox-scene .bulb:nth-of-type(odd) { animation: twinkle 1.8s ease-in-out infinite alternate; }
  @keyframes flutter {
    0% { transform: translate(0, 0) rotate(0); opacity: 0; }
    8% { opacity: var(--alpha); }
    90% { opacity: var(--alpha); }
    100% { transform: translate(var(--drift), calc(100vh + 20px)) rotate(540deg); opacity: 0; }
  }
  @keyframes firefly {
    0% { transform: translate(0, 0); opacity: 0; }
    30%, 70% { opacity: .9; }
    100% { transform: translate(var(--drift), -70vh); opacity: 0; }
  }
  @keyframes bob { from { transform: translateY(0); } to { transform: translateY(-6px); } }
  @keyframes twinkle { from { opacity: 1; } to { opacity: .35; } }
  .hint { animation: nudge 2.2s ease-in-out infinite; }
  @keyframes snow {
    0% { transform: translate(0, 0); opacity: 0; }
    8% { opacity: var(--alpha); }
    90% { opacity: var(--alpha); }
    100% { transform: translate(var(--drift), calc(100vh + 20px)); opacity: 0; }
  }
  @keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-4px); } }
}

/* ---------- 장면: 벽난로 (편지 읽기) ---------- */
body.hearth {
  background-color: #1d110b;
  background-image:
    radial-gradient(ellipse 70% 60% at 25% 90%, rgba(255, 140, 50, .16), transparent),
    linear-gradient(#22140e, #3a2317);
}
.hearth-scene { position: fixed; inset: 0; z-index: 0; pointer-events: none; }
.hearth-scene svg { display: block; width: 100%; height: 100%; }

/* 넓은 화면에서는 왼쪽에 벽난로, 오른쪽에 편지를 두어 불꽃이 글자를 가리지 않게 한다. */
@media (min-width: 760px) {
  .hearth-scene { right: 46%; -webkit-mask-image: linear-gradient(to right, #000 78%, transparent); mask-image: linear-gradient(to right, #000 78%, transparent); }
  body.hearth .page { margin: 0 0 0 auto; width: 50%; max-width: 600px; padding-right: max(24px, env(safe-area-inset-right, 0px)); }
}
.hearth-art .flame, .hearth-art .cflame, .hearth-art .glow { transform-box: fill-box; transform-origin: 50% 100%; }
.hearth-art .glow { transform-origin: 50% 50%; }

@media (prefers-reduced-motion: no-preference) {
  .hearth-art .f1 { animation: flicker 1.7s ease-in-out infinite alternate; }
  .hearth-art .f2 { animation: flicker 1.3s ease-in-out -.4s infinite alternate; }
  .hearth-art .f3 { animation: flicker 1.9s ease-in-out -.9s infinite alternate; }
  .hearth-art .cflame { animation: flicker 1s ease-in-out infinite alternate; }
  .hearth-art .glow { animation: glow 3.4s ease-in-out infinite alternate; }
  .hearth-art .ember { opacity: 0; animation: ember-rise var(--rise) ease-out var(--delay) infinite; }
  .letter.unfold { transform-origin: top center; animation: unfold .6s ease-out both; }
  .envelope-btn:hover .envelope-art { transform: translateY(-4px) rotate(-1deg); }
  .envelope-art { transition: transform .25s ease-out; }
  @keyframes flicker {
    0% { transform: scale(1, 1) skewX(0); }
    35% { transform: scale(.94, 1.08) skewX(2.5deg); }
    70% { transform: scale(1.04, .95) skewX(-2deg); }
    100% { transform: scale(.97, 1.1) skewX(1deg); }
  }
  @keyframes glow { from { opacity: .78; transform: scale(1); } to { opacity: 1; transform: scale(1.05); } }
  @keyframes ember-rise {
    0% { transform: translate(0, 0); opacity: 0; }
    15% { opacity: 1; }
    100% { transform: translate(var(--sway), -160px); opacity: 0; }
  }
  @keyframes unfold { from { opacity: .6; transform: scaleY(.15); } to { opacity: 1; transform: none; } }
}

.share {
  background: rgba(20, 10, 5, .6); border: 1px solid rgba(255, 217, 160, .28);
  border-radius: 10px; padding: 10px 14px; color: #ffe9c9;
}
.share summary { cursor: pointer; font-size: 15px; }
.hearth-tools { display: grid; gap: 10px; justify-items: start; }
.nickname-note { margin: 0; color: #ffe9c9; opacity: .8; }
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }
.share-box { display: grid; gap: 8px; justify-items: start; }
.share-text { width: 100%; font: inherit; font-size: 15px; color: var(--ink); background: #fffdf6; border: 1px solid var(--paper-edge); border-radius: 6px; padding: 8px 10px; resize: none; }
.book-box { display: grid; gap: 6px; justify-items: end; justify-self: end; margin-top: 12px; text-align: right; }
.manage { display: grid; gap: 8px; justify-items: start; margin-top: 10px; }
.letter .actions { display: flex; gap: 8px; }
.sound-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.carol { display: grid; gap: 6px; }
.ad { display: grid; gap: 4px; justify-items: center; min-width: 0; }
.ad-label { font-size: 11px; color: var(--text-soft); }
.ad ins.adsbygoogle { display: block; width: 100%; min-height: 0; }
.legal { margin: 0; text-align: center; font-size: 12px; }
.legal a { color: var(--text-soft); }
.carol-credit { margin: 0; font-size: 12px; color: var(--text-soft); text-align: center; }
/* 편지 쓰는 화면: 내용이 짧아도 출처 표기가 화면 맨 아래에 붙고, 길면 내용 바로 뒤에 온다. */
.page.with-footer { display: flex; flex-direction: column; min-height: 100vh; min-height: 100dvh; }
.page.with-footer .site-foot { margin-top: auto; padding-top: 24px; }
.sound-note { flex: 1 1 100%; order: 3; margin: 0; font-size: 13px; color: #ffe9c9; opacity: .85; }
.hearth-tools .share { justify-self: stretch; }
.share .linkrow { margin-top: 10px; }

.stage { display: grid; gap: 14px; }
.stage .letter { max-height: 44vh; overflow: auto; }

.envelope-btn {
  display: grid; justify-items: center; gap: 6px; padding: 8px;
  background: none; border: 0; cursor: pointer; font: inherit; color: #ffe9c9; text-align: center;
}
.envelope-art { width: min(240px, 70vw); height: auto; filter: drop-shadow(0 10px 18px rgba(0, 0, 0, .55)); }
.envelope-label { font-family: var(--font-title); font-size: 20px; }
.paper.envelope .envelope-art { width: 150px; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .25)); }

.reader-nav { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: #ffe9c9; font-size: 15px; }
.btn.night { background: rgba(20, 10, 5, .65); color: #ffe9c9; border: 1px solid rgba(255, 217, 160, .4); font-weight: 400; }
.btn.night:hover:not(:disabled) { background: rgba(70, 36, 18, .85); }

/* ---------- 편지함을 만든 직후 화면 ---------- */
.step { display: flex; align-items: center; gap: 10px; }
.step h2 { font-size: 19px; margin: 0; color: var(--ink); }
.step .n { width: 24px; height: 24px; border-radius: 50%; background: var(--seal); color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center; flex: none; font-family: var(--font-body); }
.send-row {
  display: flex; align-items: center; gap: 14px; width: 100%; min-height: 68px; padding: 10px 14px;
  background: #fffdf6; border: 1px solid var(--paper-edge); border-radius: 12px;
  color: var(--ink); text-decoration: none; font: inherit; text-align: left; cursor: pointer;
}
.send-row:hover { background: #f8f0dc; }
.send-row:focus-visible { outline: 2px solid var(--seal); outline-offset: 2px; }
.send-row .chip { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.send-row .chip svg { width: 24px; height: 24px; }
.chip-kakao { background: #fee500; color: #3b1e1e; }
.chip-sms { background: #dcebdc; color: #2c5a3a; }
.send-row .rt { flex: 1; min-width: 0; display: grid; gap: 1px; }
.send-row .rt b { font-size: 18px; font-weight: 700; line-height: 1.3; }
.send-row .rt span { font-size: 14px; color: var(--ink-soft); line-height: 1.4; }
.send-row .go { color: #a39682; display: grid; flex: none; }
.sub { display: flex; justify-content: center; }
.text-link { background: none; border: 0; padding: 8px 12px; font: inherit; font-size: 15px; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.send-status { margin: 0; font-size: 15px; line-height: 1.55; color: #6b3a14; background: #f7e3d4; border-radius: 8px; padding: 10px 12px; }
.key-card { border: 1px dashed #d9a67f; border-radius: 8px; padding: 16px; display: grid; gap: 10px; }
.key-card h2 { display: flex; align-items: center; gap: 8px; margin: 0; font-size: 18px; color: #f0c9a0; }
.key-card p { margin: 0; font-size: 15px; line-height: 1.6; color: #c9d3e2; }
.key-card em { font-style: normal; font-weight: 700; color: #ffb8a8; }
.key-btn { width: 100%; min-height: 48px; border-radius: 12px; border: 1px solid #d9a67f; background: transparent; color: #f0c9a0; font: inherit; font-size: 16px; font-weight: 700; cursor: pointer; }
.key-btn:hover { background: rgba(217, 166, 127, .12); }
.key-card .share-box { gap: 8px; }
.key-card .share-box .share-text { background: #fbf5e6; }
.btn.cta { display: block; width: 100%; min-height: 54px; line-height: 30px; font-size: 18px; padding: 12px 22px; }

/* ---------- 우체통을 열면 나오는 편지지 (배경이 어두워진다) ---------- */
body.sheet-open { overflow: hidden; }
.sheet-backdrop {
  position: fixed; inset: 0; z-index: 30; display: flex; justify-content: center; align-items: center; overflow-y: auto;
  padding: max(16px, env(safe-area-inset-top, 0px)) max(16px, env(safe-area-inset-right, 0px)) max(16px, env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px));
  background: rgba(6, 12, 22, .8);
}
.sheet-backdrop .writer { position: relative; width: min(100%, 500px); margin: auto; padding-top: 28px; }
.sheet-backdrop.leaving { opacity: 0; transition: opacity .25s ease-in; }
.sheet-close {
  position: absolute; top: 4px; right: 4px; width: 48px; height: 48px; border: 0; border-radius: 50%;
  background: none; color: var(--ink-soft); font-size: 32px; line-height: 1; cursor: pointer;
}
.sheet-close:hover { background: #f3ecd8; }
.sheet-backdrop .writer label { font-family: var(--font-title); font-size: 20px; }

@media (prefers-reduced-motion: no-preference) {
  .sheet-backdrop:not([hidden]) { animation: sheet-fade .35s ease-out both; }
  .sheet-backdrop:not([hidden]) .writer { animation: sheet-rise .5s cubic-bezier(.2, .9, .3, 1) both; }
  .sheet-backdrop.posting { opacity: 0; transition: opacity .7s ease-in; }
  .sheet-backdrop.posting .writer { transform: translateY(-38vh) scale(.12); opacity: 0; transition: transform .7s ease-in, opacity .7s ease-in; }
  @keyframes sheet-fade { from { opacity: .5; } to { opacity: 1; } }
  @keyframes sheet-rise { from { opacity: .5; transform: translateY(46px) scale(.92); } to { opacity: 1; transform: none; } }
}

/* ---------- 편지함 종류 고르기, 홈의 상황별 안내, 맨 아래 링크 ---------- */
.themes { display: flex; flex-wrap: wrap; gap: 8px; }
.theme-chip {
  position: relative; display: inline-flex; align-items: center; min-height: 44px; padding: 8px 16px;
  border: 1px solid var(--paper-edge); border-radius: 999px; background: #fffdf6;
  font-weight: 400; cursor: pointer;
}
.theme-chip input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.theme-chip:has(input:checked) { background: var(--seal); border-color: var(--seal); color: #fff; font-weight: 700; }
.theme-chip:has(input:focus-visible) { outline: 2px solid var(--seal); outline-offset: 2px; }

.occasions { display: grid; gap: 10px; }
.occasions ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.occasions a {
  display: flex; align-items: baseline; gap: 12px; padding: 12px 14px; border-radius: 10px;
  background: rgba(255, 255, 255, .05); border: 1px solid rgba(255, 255, 255, .1);
  color: var(--text); text-decoration: none;
}
.occasions a:hover { background: rgba(255, 255, 255, .1); }
.occasions b { color: #f1c97a; min-width: 2.5em; }

.site-foot { display: grid; gap: 10px; }
.site-foot .legal a { white-space: nowrap; }

/* 안내 글(소개, 자주 묻는 질문, 편지 쓰는 법) */
.article { gap: 16px; }
.article h2 { margin-top: 6px; }
.article h3 { font-family: var(--font-title); font-size: 17px; margin: 4px 0 0; color: var(--ink); }
.article ul, .article ol { margin: 0; padding-left: 1.3em; display: grid; gap: 6px; }
.article a { color: var(--seal-dark); }
.article .example {
  margin: 0; padding: 12px 14px; border-left: 3px solid var(--paper-edge); background: #f6efdc;
  font-family: var(--font-hand); font-size: 20px; line-height: 1.5; color: var(--ink);
}
.article .examples { display: grid; gap: 10px; }
.article .cta-row { display: flex; flex-wrap: wrap; gap: 10px; }
.article dt { font-weight: 700; margin-top: 10px; }
.article dd { margin: 4px 0 0; color: var(--ink-soft); }
.crumbs { font-size: 14px; color: var(--text-soft); }
.crumbs a { color: var(--text-soft); }
