:root {
  --night: #0E1B2C;
  --night-2: #132740;
  --night-3: #17304D;
  --line: #2F4A6B;
  --ink-on-dark: #F4EEE2;
  --muted-on-dark: #C9D3E0;
  --dim-on-dark: #A9B6C8;
  --gold: #E8B04B;
  --berry: #B8293F;
  --berry-dark: #9C2135;
  --ink: #2B2118;
  --ink-2: #5A4A3B;
  --ink-3: #6B5A49;
  --paper: #FBF5E9;
  --paper-line: #D9CBB4;
  --cream: #FBF5E9;
  --rose: #F7DEDC;
  --mint: #DDEBDF;
  --sky: #DEE6F2;
  --serif: 'Gowun Batang', serif;
  --sans: 'Noto Sans KR', system-ui, sans-serif;
  --pen: 'Nanum Pen Script', cursive;
  --script: 'Cormorant Garamond', 'Gowun Batang', serif;
  --gold-line: #D9B26A;
  --gold-ink: #A9802F;
  --ivory: #FBF6EA;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--night); color: var(--ink-on-dark); font-family: var(--sans); }
button { font-family: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }
textarea:focus, input:focus { outline: 3px solid var(--gold); outline-offset: 1px; }
[hidden] { display: none !important; }

.page { position: relative; min-height: 100vh; overflow: hidden; }
.container { position: relative; max-width: 1200px; margin: 0 auto; padding-left: 32px; padding-right: 32px; }

/* ---------- 배경 / 눈 ---------- */
.sky { position: absolute; left: 0; right: 0; top: 0; height: 1500px; pointer-events: none;
  background: radial-gradient(900px 760px at 50% 52%, #13233A 0%, rgba(10,20,34,.6) 55%, rgba(14,27,44,0) 100%); }
.snow { position: absolute; inset: 0; }
.flake { position: absolute; top: 0; border-radius: 50%; background: #fff;
  animation: fall linear infinite; }
@keyframes fall { 0% { transform: translateY(-20px); opacity: 0 } 10% { opacity: .9 } 100% { transform: translateY(1500px); opacity: 0 } }
@keyframes twinkle { 0%,100% { opacity: 1 } 50% { opacity: .35 } }
.bulb { animation: twinkle 2.4s ease-in-out infinite; }

/* ---------- 헤더 / 히어로 ---------- */
.header { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; padding-top: 28px; padding-bottom: 28px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-weight: 700; font-size: 22px; }
.pill { font-size: 14px; color: var(--muted-on-dark); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; }
.pill.closed { color: #F3CB7E; border-color: #6B5523; }

.hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 16px; padding-top: 32px; padding-bottom: 8px; }
.eyebrow { font-family: var(--script); font-style: italic; font-weight: 500; font-size: 22px; letter-spacing: 2px; color: var(--gold-line); }
.divider { display: flex; align-items: center; gap: 12px; }
.divider span { width: 64px; height: 1px; background: linear-gradient(90deg, rgba(217,178,106,0), var(--gold-line)); }
.divider span:last-child { background: linear-gradient(90deg, var(--gold-line), rgba(217,178,106,0)); }
.divider i { width: 6px; height: 6px; transform: rotate(45deg); border: 1px solid var(--gold-line); }
.hero h1 { margin: 0; font-family: var(--serif); font-weight: 700; font-size: 48px; line-height: 1.25; letter-spacing: -1px; }
.br-mobile { display: none; }
.lead { margin: 0; font-size: 17px; line-height: 1.6; color: var(--muted-on-dark); }
.hero-actions { display: flex; align-items: center; justify-content: center; gap: 20px; flex-wrap: wrap; margin-top: 8px; }
.count { font-size: 16px; color: var(--muted-on-dark); }
.count strong { color: var(--ink-on-dark); font-size: 20px; }

/* ---------- 버튼 ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; height: 52px; padding: 0 24px;
  border-radius: 999px; border: 0; font-size: 16px; font-weight: 700; cursor: pointer; transition: background .15s ease, transform .1s ease; }
.btn:active { transform: translateY(1px); }
.btn-lg { height: 56px; padding: 0 28px; font-size: 18px; }
.btn-primary { background: var(--berry); color: #fff; }
.btn-primary:hover { background: var(--berry-dark); }
.btn-primary:disabled { background: #B9A99A; cursor: not-allowed; }
.btn-ghost { height: 48px; border: 1px solid var(--line); background: transparent; color: var(--ink-on-dark); font-weight: 400; }
.btn-ghost:hover { background: var(--night-3); }
.btn-outline { border: 1.5px solid var(--paper-line); background: transparent; color: var(--ink); font-weight: 500; }
.icon-btn { width: 44px; height: 44px; border: 0; background: transparent; color: var(--ink-2); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.icon-btn:hover { background: rgba(43,33,24,.06); }

/* ---------- 트리 ---------- */
.tree-section { padding-top: 24px; }
.tree-note { margin: 0 0 8px; text-align: center; font-size: 15px; font-weight: 400; color: var(--gold); }
.tree-stage { position: relative; width: 1100px; max-width: 100%; aspect-ratio: 1100 / 1000; margin: 0 auto; }
.tree-svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.tree-mobile { display: none; }
.ornaments { position: absolute; inset: 0; }
.tree-empty { position: absolute; left: 50%; top: 40%; transform: translate(-50%, -50%); margin: 0; text-align: center;
  font-family: var(--serif); font-size: 20px; line-height: 1.6; color: var(--ink-on-dark);
  background: rgba(14,27,44,.75); padding: 20px 28px; border-radius: 16px; }

/* ---------- 편지 카드 ---------- */
.letter { position: relative; color: var(--ink); border-radius: 14px; display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 12px 26px rgba(0,0,0,.35); }
.letter.theme-cream, .swatch.theme-cream { background: var(--cream); }
.letter.theme-rose, .swatch.theme-rose { background: var(--rose); }
.letter.theme-mint, .swatch.theme-mint { background: var(--mint); }
.letter.theme-sky, .swatch.theme-sky { background: var(--sky); }
.letter-text { margin: 0; font-family: var(--pen); line-height: 1.28; word-break: keep-all; overflow-wrap: anywhere; }
.letter-foot { display: flex; align-items: center; justify-content: space-between; gap: 6px; border-top: 1px dashed rgba(43,33,24,.25); }
.letter-from { font-size: 13px; color: var(--ink-2); min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.letter-from strong { color: var(--ink); }
.letter-actions { display: flex; align-items: center; margin-right: -10px; flex: none; }
.like-btn { min-width: 44px; height: 44px; padding: 0 6px; border: 0; background: transparent; color: var(--ink-3);
  font-size: 14px; font-weight: 700; cursor: pointer; display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; }
.like-btn svg { fill: none; transition: transform .15s ease; }
.like-btn[aria-pressed="true"] { color: var(--berry); }
.like-btn[aria-pressed="true"] svg { fill: var(--berry); }
.like-btn.pop svg { transform: scale(1.3); }
.report-btn { width: 44px; height: 44px; border: 0; background: transparent; color: var(--ink-3); cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; border-radius: 50%; }
.like-btn:hover, .report-btn:hover { background: rgba(43,33,24,.06); }

/* 트리에 걸린 카드: 아이보리 종이 + 금박 이중 테두리 */
.ornament { position: absolute; width: clamp(140px, 16vw, 178px); padding: 20px 16px 4px; transform: translateX(-50%) rotate(var(--rot, 0deg));
  transform-origin: 50% -24px; transition: transform .2s ease, left .4s ease, top .4s ease;
  background: var(--ivory); color: #2A2016; border-radius: 4px; gap: 6px;
  outline: 1px solid var(--gold-line); outline-offset: -6px; box-shadow: 0 18px 30px rgba(0,0,0,.45); }
.letter.ornament { background: var(--ivory); } /* 테마색보다 우선 */
.ornament .letter-foot { border-top: 1px solid rgba(169,128,47,.35); }
.ornament .like-btn { color: #8A7350; }
.ornament .like-btn[aria-pressed="true"] { color: #9E2B3B; }
.ornament .like-btn[aria-pressed="true"] svg { fill: #9E2B3B; }
.ornament:hover, .ornament:focus-within { transform: translateX(-50%) rotate(0deg) scale(1.06); z-index: 5; }
.ornament .letter-text { font-size: 21px; }
.ornament .letter-from { font-size: 12px; }
.ornament .letter-actions { margin-right: -8px; }
.ornament::before { content: ''; position: absolute; top: -26px; left: 50%; width: 1.5px; height: 22px;
  background: linear-gradient(180deg, rgba(217,178,106,.15), var(--gold-line)); }
.ornament::after { content: ''; position: absolute; top: -8px; left: calc(50% - 6px); width: 12px; height: 12px; border-radius: 50%;
  border: 1.5px solid var(--gold-line); background: var(--night); }
/* 1~3위: 이탤릭 No.1 */
.rank { display: block; margin: -4px 0 -2px; font-family: var(--script); font-style: italic; font-weight: 500; font-size: 17px; line-height: 1; color: var(--gold-ink); }

/* ---------- 목록 ---------- */
.list-section { padding-top: 72px; padding-bottom: 80px; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 32px; }
.list-head h2 { margin: 0; font-family: var(--serif); font-size: 26px; font-weight: 700; }
.segmented { display: flex; padding: 4px; border-radius: 999px; background: var(--night-3); }
.segmented button { height: 44px; padding: 0 18px; border: 0; border-radius: 999px; background: transparent; color: var(--muted-on-dark);
  font-size: 15px; font-weight: 500; cursor: pointer; }
.segmented button[aria-pressed="true"] { background: var(--ink-on-dark); color: var(--night); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 24px; }
.grid .letter { padding: 22px 20px 0; min-height: 160px; justify-content: space-between; }
.grid .letter-text { font-size: 26px; }
.grid .letter.is-new { box-shadow: 0 0 0 3px var(--gold), 0 12px 26px rgba(0,0,0,.35); }
.list-empty { text-align: center; color: var(--dim-on-dark); }
.more-wrap { display: flex; justify-content: center; margin-top: 48px; }

.footer { position: relative; border-top: 1px solid #1F3756; padding: 28px 32px 32px; text-align: center; font-size: 14px; line-height: 1.7; color: var(--dim-on-dark); }
.fab-wrap { display: none; }

/* ---------- 토스트 ---------- */
.toast { position: fixed; left: 50%; bottom: 32px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; z-index: 40;
  background: var(--ink-on-dark); color: #1C2A3A; border-radius: 999px; padding: 14px 22px; font-size: 16px; font-weight: 500;
  box-shadow: 0 10px 30px rgba(0,0,0,.4); max-width: calc(100% - 32px); }

/* ---------- 모달 ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(6,12,22,.72); }
.dialog { position: relative; width: 100%; max-width: 520px; max-height: calc(100vh - 40px); overflow-y: auto; background: var(--paper); color: var(--ink);
  border-radius: 22px; padding: 28px; display: flex; flex-direction: column; gap: 20px; box-shadow: 0 30px 60px rgba(0,0,0,.45); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; }
.dialog-head h2 { margin: 0; font-family: var(--serif); font-size: 24px; font-weight: 700; }
.dialog-head .icon-btn { margin-right: -10px; }
#write-form { display: flex; flex-direction: column; gap: 20px; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field-head { display: flex; justify-content: space-between; align-items: baseline; }
.field label, .field-label { font-size: 15px; font-weight: 700; }
.muted { font-weight: 400; color: var(--ink-3); }
.counter { font-size: 14px; font-weight: 500; color: var(--ink-3); }
.counter.warn { color: #9A5B12; }
.counter.over { color: #A3253A; }
textarea, input[type="text"] { width: 100%; border: 1.5px solid var(--paper-line); border-radius: 12px; background: #FFFDF8; color: var(--ink); }
textarea { resize: none; padding: 14px 16px; font-family: var(--pen); font-size: 26px; line-height: 1.3; }
input[type="text"] { height: 48px; padding: 0 16px; font-family: var(--sans); font-size: 16px; }
textarea.invalid { border-color: #C24A5C; }
.swatches { display: flex; gap: 12px; }
.swatch { width: 44px; height: 44px; border-radius: 50%; cursor: pointer; border: 3px solid #fff; box-shadow: 0 0 0 1px var(--paper-line); }
.swatch[aria-checked="true"] { border-color: var(--ink); }
.turnstile:empty { display: none; }
.captcha-msg { margin: -8px 0 0; font-size: 14px; color: var(--ink-3); }
.dialog-actions { display: flex; gap: 12px; justify-content: flex-end; }
.alert { display: flex; gap: 12px; align-items: flex-start; background: #FBE3E3; border: 1px solid #E7A9AE; border-radius: 12px; padding: 14px 16px; }
.alert svg { flex: none; margin-top: 2px; }
.alert div { display: flex; flex-direction: column; gap: 2px; }
.alert strong { font-size: 15px; color: #8A1F31; }
.alert span { font-size: 14px; color: #6E2A33; }

/* ---------- 반응형 ---------- */
@media (max-width: 860px) {
  .container { padding-left: 20px; padding-right: 20px; }
  .header { padding-top: 18px; padding-bottom: 18px; }
  .brand { font-size: 18px; }
  .brand svg { width: 22px; height: 22px; }
  .pill { font-size: 12px; padding: 6px 10px; }
  .hero { padding-top: 16px; gap: 8px; }
  .eyebrow { font-size: 11px; letter-spacing: 2.5px; }
  .hero h1 { font-size: 28px; letter-spacing: -0.5px; line-height: 1.3; }
  .br-mobile { display: inline; }
  .lead { font-size: 14px; }
  .hero-actions .btn { display: none; }
  .count { font-size: 14px; }
  .count strong { font-size: 16px; }
  .tree-section { padding-left: 0; padding-right: 0; padding-top: 12px; }
  .tree-note { font-size: 13px; }
  .tree-stage { width: 100%; max-width: 430px; aspect-ratio: 390 / 640; }
  .tree-desktop { display: none; }
  .tree-mobile { display: block; }
  .ornament { width: 40%; max-width: 168px; padding: 16px 13px 2px; transform-origin: 50% -20px; outline-offset: -5px; }
  .ornament::before { top: -20px; height: 16px; }
  .ornament::after { width: 10px; height: 10px; top: -7px; left: calc(50% - 5px); }
  .ornament .letter-text { font-size: 18px; line-height: 1.2; }
  .ornament .letter-from { font-size: 11px; }
  .rank { font-size: 15px; }
  .list-section { padding-top: 36px; padding-bottom: 120px; }
  .list-head { margin-bottom: 16px; }
  .list-head h2 { font-size: 21px; }
  .segmented button { padding: 0 14px; font-size: 14px; }
  .grid { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .grid .letter { padding: 18px 16px 0; min-height: 0; }
  .grid .letter-text { font-size: 24px; }
  .footer { padding-bottom: 110px; }
  .fab-wrap { display: block; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 40px 20px 24px;
    background: linear-gradient(180deg, rgba(14,27,44,0) 0%, var(--night) 45%); pointer-events: none; }
  .fab { width: 100%; pointer-events: auto; box-shadow: 0 10px 24px rgba(0,0,0,.4); }
  .toast { bottom: 100px; font-size: 15px; }
  .dialog { padding: 22px; border-radius: 20px; }
  .dialog-actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  .flake, .bulb { animation: none; }
  .flake { opacity: .5; }
  .ornament, .like-btn svg, .btn { transition: none; }
}
