/* 트리레터 화면 스타일. 모바일 우선, 가운데 한 열 */
:root {
  --night-900: #071a33;
  --night-800: #0c2a52;
  --paper: #f8f1e4;
  --paper-alt: #fbf4e7;
  --paper-input: #fffcf6;
  --gold: #d7b26d;
  --gold-text: #e3bf84;
  --gold-deep: #8f6a39;
  --red: #a9151b;
  --red-dark: #7f0d16;
  --red-text: #9f1c21;
  --ink: #5a3a22;
  --ink-soft: #7a5a3c;
  --ivory: #fff2dc;
  --radius-panel: 28px;
  --radius-btn: 22px;
  --radius-input: 14px;
  --display: 'Gowun Batang', 'Apple SD Gothic Neo', serif;
  --body: 'Gowun Dodum', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  --hand: 'Nanum Pen Script', 'Gowun Dodum', cursive;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--body);
  color: var(--ink);
  background: var(--night-900);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.bg {
  position: fixed; inset: 0; z-index: -2;
  background:
    linear-gradient(180deg, rgba(7, 26, 51, .55) 0%, rgba(7, 26, 51, .1) 30%, rgba(7, 26, 51, .15) 70%, rgba(7, 26, 51, .7) 100%),
    url('/bg.webp') center 62% / cover no-repeat,
    linear-gradient(var(--night-900), var(--night-800));
}
#snow { position: fixed; inset: 0; z-index: -1; pointer-events: none; width: 100%; height: 100%; }

#app {
  max-width: 480px; margin: 0 auto; min-height: 100dvh;
  display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top, 0px) + 18px) 16px calc(var(--safe-b) + 18px);
}
.noscript { color: var(--ivory); text-align: center; padding: 40px 20px; }

/* 상단 브랜드와 제목 */
.brand {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  color: var(--gold-text); font-family: var(--display); font-size: 14px; letter-spacing: .35em;
  text-decoration: none;
}
.brand::before, .brand::after { content: ''; width: 46px; height: 1px; background: linear-gradient(90deg, transparent, var(--gold)); }
.brand::after { transform: scaleX(-1); }
.brand img { width: 14px; height: 14px; }

.title {
  position: relative; margin: 10px auto 0; text-align: center;
  font-family: var(--display); font-weight: 700; color: var(--gold-text);
  font-size: clamp(26px, 8vw, 34px); line-height: 1.28;
  text-shadow: 0 2px 10px rgba(0, 0, 0, .55);
  word-break: keep-all;
}
.title.small { font-size: clamp(22px, 6.6vw, 28px); }
.title .num { color: #fff3d6; }
.title-wrap { position: relative; display: flex; align-items: center; justify-content: center; gap: 6px; }
.title-wrap .holly { width: 40px; flex: none; filter: drop-shadow(0 2px 4px rgba(0,0,0,.4)); }
.title-wrap .holly.flip { transform: scaleX(-1); }
.eyebrow { text-align: center; color: var(--gold-text); font-family: var(--display); font-size: 15px; letter-spacing: .08em; margin-top: 4px; }

.pill {
  display: inline-flex; align-items: center; gap: 10px;
  margin: 12px auto 0; padding: 7px 16px;
  border: 1px solid rgba(215, 178, 109, .8); border-radius: 999px;
  background: rgba(7, 26, 51, .55); color: var(--gold-text);
  font-size: 13px; backdrop-filter: blur(4px);
}
.pill b { font-family: var(--display); color: #fff3d6; font-variant-numeric: tabular-nums; }
.center { display: flex; justify-content: center; }

/* 트리 무대 */
.stage { position: relative; flex: 1 0 auto; display: flex; justify-content: center; align-items: flex-end; margin-top: 8px; min-height: 260px; }
.stage:has(.stage-hint) { padding-top: 34px; }
.tree-box {
  position: relative; height: min(46dvh, 430px); aspect-ratio: 0.64;
  touch-action: manipulation;
}
.tree-box > .tree { width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 10px 24px rgba(0, 0, 0, .45)); user-select: none; -webkit-user-drag: none; }
.tree-box.pickable { cursor: crosshair; }
.char { position: absolute; bottom: 4%; right: max(-6%, calc(50% - 230px)); height: 30%; pointer-events: none; filter: drop-shadow(0 6px 10px rgba(0,0,0,.4)); }
.char.left { right: auto; left: max(-6%, calc(50% - 230px)); }

.orn {
  position: absolute; width: 14%; aspect-ratio: 1; padding: 0; border: 0; background: none;
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 3px 4px rgba(0, 0, 0, .45));
  transition: transform .15s ease;
}
.orn img { width: 100%; height: 100%; object-fit: contain; pointer-events: none; }
.orn:hover, .orn:focus-visible { transform: translate(-50%, -50%) scale(1.15); z-index: 3; }
.orn:focus-visible { outline: 2px solid var(--gold-text); outline-offset: 2px; border-radius: 50%; }
.orn.mine::after { content: ''; position: absolute; right: -2px; top: -2px; width: 9px; height: 9px; border-radius: 50%; background: #ffd77a; box-shadow: 0 0 6px #ffd77a; }
.orn.new { animation: drop .5s cubic-bezier(.3, 1.5, .6, 1); }
@keyframes drop { from { transform: translate(-50%, -160%) scale(.4); opacity: 0; } }

.target {
  position: absolute; width: 15%; aspect-ratio: 1; border-radius: 50%;
  border: 2px dashed #ffe2a8; background: rgba(255, 226, 168, .14);
  transform: translate(-50%, -50%); pointer-events: none;
  animation: pulse 1.6s ease-in-out infinite;
}
.target img { width: 72%; height: 72%; margin: 14%; object-fit: contain; opacity: .9; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(255, 226, 168, .18); } }
.stage-hint { position: absolute; top: 0; left: 50%; transform: translateX(-50%); white-space: nowrap; font-size: 12px; color: var(--ivory); background: rgba(7, 26, 51, .6); padding: 4px 10px; border-radius: 999px; }

.lock-pill {
  position: relative; z-index: 2;
  display: flex; align-items: center; gap: 10px; width: fit-content; max-width: 100%;
  margin: -18px auto 0; padding: 6px 18px 6px 6px;
  background: #f5e7cb; border: 1px solid var(--gold); border-radius: 999px;
  color: var(--ink); font-size: 13px; box-shadow: 0 6px 16px rgba(0, 0, 0, .35);
}
.lock-pill .ic { width: 30px; height: 30px; border-radius: 50%; background: #c89c47; display: grid; place-items: center; color: #fff8ea; flex: none; }
.lock-pill b { font-family: var(--display); color: var(--red-text); font-size: 17px; font-variant-numeric: tabular-nums; }

/* 크림 패널 */
.panel {
  position: relative; z-index: 2; margin-top: 14px;
  background: var(--paper); border: 1.5px solid var(--gold); border-radius: var(--radius-panel);
  padding: 20px 18px 18px; box-shadow: 0 16px 40px rgba(0, 0, 0, .4);
}
.panel .sprig { position: absolute; top: -18px; right: 10px; width: 64px; pointer-events: none; }
.label { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; font-size: 14px; font-weight: 700; color: var(--ink); }
.label svg { color: var(--red-text); }
.section-title { display: flex; align-items: center; gap: 8px; margin: 0 0 10px; color: var(--red-text); font-family: var(--display); font-weight: 700; font-size: 17px; }
.section-title::after { content: ''; flex: 1; height: 1px; background: linear-gradient(90deg, #ddc08a, transparent); }
.divider { height: 1px; background: #e7d2a8; margin: 16px 0; border: 0; }

.field {
  width: 100%; padding: 12px 14px; border: 1px solid #ccab6e; border-radius: var(--radius-input);
  background: var(--paper-input); color: var(--ink); font-size: 16px;
  box-shadow: inset 0 1px 2px rgba(90, 58, 34, .08);
}
.field::placeholder { color: #9a7f62; }
.field:focus { outline: 2px solid rgba(169, 21, 27, .45); outline-offset: 1px; border-color: var(--red); }
textarea.field { min-height: 108px; resize: none; line-height: 1.55; }
.counter { text-align: right; font-size: 12px; color: var(--ink-soft); margin: 4px 2px 10px; font-variant-numeric: tabular-nums; }
.field-err { color: var(--red); font-size: 13px; margin: 6px 2px 0; min-height: 0; }

/* 트리 스타일 고르기 */
.styles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 0; padding: 0; border: 0; }
.style-opt { position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px; cursor: pointer; }
.style-opt input { position: absolute; opacity: 0; pointer-events: none; }
.style-opt .thumb {
  width: min(68px, 18vw); aspect-ratio: 1; border-radius: 50%;
  background: radial-gradient(circle at 50% 35%, #2c4a74, var(--night-900));
  border: 2px solid var(--gold); display: grid; place-items: center; overflow: hidden;
  transition: transform .15s;
}
.style-opt .thumb img { height: 88%; object-fit: contain; margin-top: 8%; }
.style-opt .name { font-size: 13px; padding: 3px 10px; border-radius: 999px; color: var(--ink); }
.style-opt input:checked + .thumb { border: 3px solid var(--red); transform: scale(1.04); }
.style-opt input:checked ~ .name { background: var(--red); color: var(--ivory); }
.style-opt input:focus-visible + .thumb { outline: 2px solid var(--red); outline-offset: 3px; }
.style-opt .check { position: absolute; top: -2px; right: calc(50% - min(34px, 9vw) - 4px); width: 22px; height: 22px; border-radius: 50%; background: var(--red); color: #fff; display: none; place-items: center; border: 2px solid var(--paper); }
.style-opt input:checked ~ .check { display: grid; }

/* 장식 고르기 */
.kinds { -webkit-mask-image: linear-gradient(90deg, #000 86%, transparent); mask-image: linear-gradient(90deg, #000 86%, transparent); display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 10px; margin: 0 -4px; scroll-snap-type: x proximity; scrollbar-width: thin; }
.kind {
  flex: none; width: 58px; height: 58px; padding: 7px; border-radius: 16px; scroll-snap-align: start;
  background: #fffaf1; border: 1.5px solid #ecdcbc; box-shadow: 0 2px 4px rgba(90, 58, 34, .12);
  transition: transform .12s, border-color .12s;
}
.kind img { width: 100%; height: 100%; object-fit: contain; }
.kind[aria-pressed='true'] { border: 2.5px solid var(--red); background: #fff1e6; transform: translateY(-2px); }
.kind:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

/* 버튼 */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%;
  min-height: 54px; padding: 0 20px; border-radius: var(--radius-btn);
  font-size: 17px; font-weight: 700; text-decoration: none; letter-spacing: .02em;
  transition: transform .1s, filter .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { filter: grayscale(.4) brightness(.9); cursor: progress; }
.btn-red { background: linear-gradient(180deg, #b81c23, var(--red) 55%, var(--red-dark)); color: var(--ivory); border: 1.5px solid #d9a95a; box-shadow: 0 6px 16px rgba(127, 13, 22, .45), inset 0 1px 0 rgba(255, 220, 170, .35); }
.btn-cream { background: var(--paper-alt); color: var(--red-text); border: 1.5px solid var(--gold); box-shadow: 0 6px 16px rgba(0, 0, 0, .3); }
.btn-dark { background: rgba(17, 27, 26, .9); color: var(--gold-text); border: 1.5px solid var(--gold); min-height: 48px; width: auto; padding: 0 36px; }
.btn-text { background: none; border: 0; color: var(--gold-text); font-size: 14px; text-decoration: underline; text-underline-offset: 3px; padding: 10px; }
.btn-text.ink { color: var(--ink-soft); }
.btn:focus-visible, .btn-text:focus-visible, .icon-btn:focus-visible { outline: 3px solid #ffe2a8; outline-offset: 2px; }
.actions { display: grid; gap: 10px; margin-top: 16px; }
.btn .holly-l, .btn .holly-r { position: absolute; width: 30px; opacity: .9; pointer-events: none; }
.btn-red.deco { position: relative; }
.btn .holly-l { left: 10px; } .btn .holly-r { right: 10px; transform: scaleX(-1); }

/* 상단 바 */
.topbar { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 8px; }
.topbar .title { margin: 0; font-size: clamp(20px, 6vw, 26px); }
.icon-btn { width: 44px; height: 44px; border-radius: 50%; border: 0; background: transparent; color: var(--gold-text); display: grid; place-items: center; }
.count-pill { font-size: 12px; color: var(--gold-text); border: 1px solid var(--gold); border-radius: 999px; padding: 6px 12px; white-space: nowrap; background: rgba(7, 26, 51, .5); }

.note { margin: 14px 4px 0; text-align: center; color: #fff2dc; text-shadow: 0 1px 6px rgba(0, 0, 0, .9), 0 0 2px rgba(0, 0, 0, .8); font-size: 13px; line-height: 1.5; word-break: keep-all; }
.note.ink { color: var(--ink-soft); text-shadow: none; }
.my-trees { margin-top: 12px; text-align: center; }
.my-trees a { color: var(--gold-text); font-size: 14px; }

/* 성공 카드 */
.done { text-align: center; }
.done img { width: 72px; margin: 0 auto 8px; }
.done h2 { margin: 0 0 6px; font-family: var(--display); color: var(--red-text); font-size: 21px; }
.done p { margin: 0; color: var(--ink-soft); font-size: 14px; line-height: 1.55; word-break: keep-all; }

/* 모달 */
.modal-back { position: fixed; inset: 0; z-index: 20; background: rgba(4, 14, 30, .62); backdrop-filter: blur(6px); display: flex; align-items: center; justify-content: center; padding: 24px 18px calc(24px + var(--safe-b)); animation: fade .2s ease; }
.modal { width: min(380px, 100%); max-height: 100%; overflow: auto; display: flex; flex-direction: column; align-items: center; gap: 18px; }
@keyframes fade { from { opacity: 0; } }
.envelope {
  position: relative; width: 100%; padding: 30px 22px 0; text-align: center;
  background: var(--paper); border: 1.5px solid var(--gold); border-radius: 26px; overflow: hidden;
  box-shadow: 0 24px 60px rgba(0, 0, 0, .55); animation: rise .35s cubic-bezier(.2, 1.2, .5, 1);
}
@keyframes rise { from { transform: translateY(24px) scale(.96); opacity: 0; } }
.envelope h2 { margin: 6px 0 6px; font-family: var(--display); color: var(--red-text); font-size: 26px; word-break: keep-all; }
.envelope .sub { color: var(--gold-deep); font-size: 14px; }
.envelope .clock { margin-top: 6px; color: #b0292d; font-family: var(--display); font-weight: 700; font-size: 18px; letter-spacing: .04em; font-variant-numeric: tabular-nums; }
.envelope .flap { position: relative; margin: 18px -22px 0; height: 150px; }
.envelope .flap svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.envelope .wax { position: absolute; left: 50%; top: 18px; width: 82px; transform: translateX(-50%); filter: drop-shadow(0 4px 6px rgba(80, 0, 0, .35)); }
.envelope .holly-top { width: 44px; margin: 0 auto; }
.own-preview { margin: 14px 0 0; padding: 12px 14px; border: 1px dashed #ccab6e; border-radius: 14px; text-align: left; font-family: var(--hand); font-size: 21px; line-height: 1.35; color: #3a2a1d; white-space: pre-wrap; word-break: break-word; }
.own-preview small { display: block; font-family: var(--body); font-size: 12px; color: var(--ink-soft); margin-bottom: 4px; }

.letter {
  position: relative; width: 100%; padding: 26px 22px 20px;
  background: var(--paper);
  border: 1.5px solid var(--gold); border-radius: 22px; box-shadow: 0 24px 60px rgba(0, 0, 0, .5);
  animation: rise .35s cubic-bezier(.2, 1.2, .5, 1);
}
.letter .to { font-family: var(--display); color: var(--red-text); font-weight: 700; font-size: 16px; margin-bottom: 8px; }
.letter .body { background: repeating-linear-gradient(180deg, transparent 0 33px, rgba(215, 178, 109, .4) 33px 34px); font-family: var(--hand); font-size: 24px; line-height: 34px; color: #3a2a1d; white-space: pre-wrap; word-break: break-word; min-height: 136px; }
.letter .from { display: flex; align-items: center; justify-content: flex-end; gap: 6px; margin-top: 10px; font-family: var(--hand); font-size: 22px; color: var(--ink); }
.letter .sticker { position: absolute; right: 14px; top: -22px; width: 54px; filter: drop-shadow(0 3px 4px rgba(0,0,0,.3)); }
.modal-actions { display: flex; flex-direction: column; align-items: center; gap: 4px; }

/* 크리스마스 화면 */
.cards { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; padding: 26px 12% 8px; margin: -6px -16px 0; scrollbar-width: none; }
.cards::-webkit-scrollbar { display: none; }
.cards .letter { flex: none; width: 76%; scroll-snap-align: center; animation: none; box-shadow: 0 14px 30px rgba(0, 0, 0, .45); }
.cards .letter .body { min-height: 102px; max-height: 170px; overflow: hidden; }
.dots { display: flex; justify-content: center; gap: 7px; margin: 8px 0 0; }
.dots i { width: 6px; height: 6px; border-radius: 50%; background: #c5a061; opacity: .7; }
.dots i.on { background: #b21c24; opacity: 1; transform: scale(1.3); }
.all-list { display: grid; gap: 14px; width: 100%; }
.all-list .letter { animation: none; }
.modal.wide { width: min(440px, 100%); }
.list-head { display: flex; justify-content: space-between; align-items: center; width: 100%; color: var(--gold-text); font-family: var(--display); font-size: 18px; position: sticky; top: 0; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); z-index: 40;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  max-width: min(420px, calc(100% - 32px)); padding: 12px 18px; border-radius: 16px;
  background: rgba(17, 27, 26, .95); color: var(--ivory); border: 1px solid var(--gold);
  font-size: 14px; text-align: center; line-height: 1.45; transition: .25s ease; word-break: keep-all;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.loading { margin: auto; color: var(--gold-text); font-family: var(--display); }
.error-box { margin: auto; text-align: center; color: var(--ivory); }
.error-box h1 { font-family: var(--display); color: var(--gold-text); }

@media (min-width: 720px) {
  #app { padding-top: 28px; }
  .tree-box { height: min(48dvh, 460px); }
}
@media (max-height: 700px) {
  .tree-box { height: 40dvh; }
  .title { font-size: 26px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
