:root {
  --ink: #1c1c1e;
  --ink2: #55555b;
  --muted: #8e8e93;
  --line: #e6e4df;
  --bg: #f4f2ee;
  --surface: #ffffff;
  --point: #c8372d;
  --point-soft: #fdf0ee;
  --radius: 14px;
  --ui: 'Noto Sans KR', 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--ui);
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }

/* ── 공통 버튼 ── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 20px;
  font-size: 14px; font-weight: 700; white-space: nowrap;
  background: #efede8; color: var(--ink);
}
.btn.primary { background: var(--point); color: #fff; }
.btn.dark { background: var(--ink); color: #fff; }
.btn.block { width: 100%; height: 48px; border-radius: 12px; font-size: 15px; }
.btn:active { transform: scale(.98); }
.icon-btn {
  width: 40px; height: 40px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 22px;
}
.icon-btn:hover { background: #efede8; }

/* ── 상단 바 ── */
.bar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  height: 56px; padding: 0 12px;
  background: rgba(244, 242, 238, .92);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.bar .bar-title { flex: 1; font-size: 16px; font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── 홈 ── */
.home { max-width: 1120px; margin: 0 auto; padding: 0 16px 48px; }
.home-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 0 14px; }
.home-head h1 { font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.home-head .org { font-size: 12px; color: var(--muted); font-weight: 700; letter-spacing: 1px; }
.hero {
  border-radius: 18px; padding: 20px 22px; color: #fff;
  background: linear-gradient(120deg, #b52c23, #e8784a);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.hero small { font-size: 12px; opacity: .85; font-weight: 600; }
.hero strong { display: block; font-size: 19px; font-weight: 800; margin-top: 4px; letter-spacing: -.3px; }
.hero p { font-size: 13px; opacity: .9; margin-top: 6px; line-height: 1.5; }
.hero .seal {
  flex: 0 0 auto; width: 64px; height: 64px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Noto Serif KR', serif; font-size: 20px; font-weight: 700;
}
.tabs { display: flex; gap: 8px; margin: 20px 0 10px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; height: 36px; padding: 0 16px; border-radius: 18px;
  background: var(--surface); color: var(--ink2); font-size: 14px; font-weight: 700;
  border: 1px solid var(--line);
}
.tab.on { background: var(--ink); color: #fff; border-color: var(--ink); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip {
  height: 30px; padding: 0 12px; border-radius: 8px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink2);
}
.chip.on { border-color: var(--point); color: var(--point); background: var(--point-soft); }
.grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 16px 12px; margin-top: 6px; }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 900px) { .grid { grid-template-columns: repeat(4, 1fr); gap: 24px 18px; } }
.tpl { text-align: left; display: block; }
.tpl .thumb { position: relative; border-radius: 12px; overflow: hidden; box-shadow: 0 6px 16px rgba(0,0,0,.10); transition: transform .15s; }
.tpl:hover .thumb { transform: translateY(-3px); }
.tpl .badge {
  position: absolute; top: 8px; left: 8px; z-index: 3;
  font-size: 10px; font-weight: 800; padding: 3px 7px; border-radius: 5px;
  background: #fff; color: var(--point); box-shadow: 0 1px 3px rgba(0,0,0,.15);
}
.tpl .name { font-size: 14px; font-weight: 700; margin-top: 8px; }
.tpl .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.empty { padding: 60px 0; text-align: center; color: var(--muted); }
.home-foot { margin-top: 36px; font-size: 12px; color: var(--muted); line-height: 1.6; text-align: center; }

/* ── 카드 (360x540 고정, 바깥에서 축소) ── */
.card-fit { position: relative; width: 100%; aspect-ratio: 2 / 3; overflow: hidden; border-radius: inherit; }
.card-fit > .card { position: absolute; top: 0; left: 0; transform-origin: 0 0; }
.card {
  width: 360px; height: 540px; overflow: hidden; position: relative;
  color: var(--fg);
  background: linear-gradient(170deg, var(--bg1), var(--bg2));
  font-family: var(--font);
}
.card .deco { position: absolute; inset: 0; width: 100%; height: 100%; }
.card-text {
  position: absolute; left: 36px; right: 36px;
  display: flex; flex-direction: column; align-items: center; text-align: center;
}
.al-left .card-text { align-items: flex-start; text-align: left; }
.lay-center .card-text { top: 0; bottom: 0; justify-content: center; }
.lay-top .card-text { top: 52px; }
.lay-bottom .card-text { bottom: 46px; }
.c-brand { font-family: var(--ui); font-size: 10px; font-weight: 700; letter-spacing: 3px; color: var(--ac); margin-bottom: 14px; }
.c-title { color: var(--ac); font-weight: 700; line-height: 1.25; letter-spacing: 1px; word-break: keep-all; }
.c-year { font-size: calc(11px * var(--fs)); opacity: .75; margin-top: 10px; letter-spacing: 1px; }
.c-to { font-size: calc(14px * var(--s) * var(--fs)); font-weight: 700; margin-top: 22px; }
.c-msg {
  font-size: calc(12.5px * var(--s) * var(--fs)); line-height: 1.85; margin-top: 12px;
  white-space: pre-line; word-break: keep-all; opacity: .92;
}
.c-from { font-size: calc(12px * var(--s) * var(--fs)); margin-top: 20px; color: var(--ac); font-weight: 600; }

/* ── 효과 레이어 ── */
.fx { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 2; }
.fx i { position: absolute; top: -20px; font-style: normal; animation: fall linear infinite; opacity: .85; }
.fx.snow i { color: #fff; text-shadow: 0 0 3px rgba(0,0,0,.25); }
.fx.sparkle i { top: auto; animation-name: twinkle; animation-timing-function: ease-in-out; color: #ffe9a8; text-shadow: 0 0 6px rgba(255,220,120,.9); }
.fx.petal i { width: 9px; height: 6px; border-radius: 60% 0 60% 0; background: #f6a3b0; }
@keyframes fall {
  0% { transform: translate(0, 0) rotate(0); }
  100% { transform: translate(30px, 620px) rotate(300deg); }
}
@keyframes twinkle { 0%, 100% { opacity: 0; transform: scale(.4); } 50% { opacity: 1; transform: scale(1); } }
@media (prefers-reduced-motion: reduce) { .fx { display: none; } }

/* ── 편집 화면 ── */
.editor { max-width: 1120px; margin: 0 auto; }
.stage { padding: 18px 16px; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.stage .preview { width: min(300px, 78vw, 30vh);border-radius: 10px; box-shadow: 0 14px 30px rgba(0,0,0,.18); }
.stage .hint { font-size: 12px; color: var(--muted); }
.controls { background: var(--surface); border-top: 1px solid var(--line); min-height: 50vh; }
.seg { display: flex; position: sticky; top: 56px; background: var(--surface); z-index: 5; border-bottom: 1px solid var(--line); }
.seg button { flex: 1; height: 48px; font-size: 14px; font-weight: 700; color: var(--muted); border-bottom: 2px solid transparent; }
.seg button.on { color: var(--ink); border-bottom-color: var(--ink); }
.pane { padding: 18px 16px 120px; display: flex; flex-direction: column; gap: 18px; }
.field > label, .field > .label { display: flex; justify-content: space-between; align-items: center; font-size: 12px; font-weight: 700; color: var(--ink2); margin-bottom: 7px; }
.field input[type=text], .field textarea {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; background: #fafaf8;
  padding: 11px 12px; font-size: 15px; outline: none;
}
.field textarea { min-height: 112px; line-height: 1.6; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--ink); background: #fff; }
.field input:disabled { color: var(--muted); background: #f1f0ec; }
.count { font-weight: 500; color: var(--muted); }
.presets { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.presets button { height: 30px; padding: 0 11px; border-radius: 15px; font-size: 12px; font-weight: 700; background: var(--point-soft); color: var(--point); }
.lock-note { font-size: 12px; color: var(--point); font-weight: 700; }
.swatches { display: flex; flex-wrap: wrap; gap: 10px; }
.swatch {
  width: 52px; height: 52px; border-radius: 12px; position: relative; overflow: hidden;
  border: 2px solid transparent; box-shadow: 0 0 0 1px var(--line);
}
.swatch.on { border-color: var(--ink); box-shadow: none; }
.swatch span { position: absolute; right: 6px; bottom: 6px; width: 14px; height: 14px; border-radius: 50%; }
.opts { display: flex; flex-wrap: wrap; gap: 8px; }
.opt {
  min-width: 64px; height: 42px; padding: 0 14px; border-radius: 10px;
  border: 1px solid var(--line); background: #fafaf8; font-size: 14px; font-weight: 600;
}
.opt.on { border-color: var(--ink); background: var(--ink); color: #fff; }
.opt:disabled { opacity: .45; cursor: not-allowed; }
.toggle { display: flex; align-items: center; justify-content: space-between; font-size: 14px; font-weight: 600; }
.toggle input { width: 20px; height: 20px; accent-color: var(--point); }
.note { font-size: 12px; color: var(--muted); line-height: 1.6; }
.mobile-cta {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  background: rgba(255,255,255,.95); border-top: 1px solid var(--line);
  display: flex; gap: 8px;
}
.mobile-cta .btn { flex: 1; height: 48px; border-radius: 12px; }

@media (min-width: 900px) {
  .editor { display: grid; grid-template-columns: 1fr 440px; gap: 0; padding: 24px 24px 0; align-items: start; }
  .stage { position: sticky; top: 80px; padding: 20px; }
  .stage .preview { width: 360px; }
  .controls { border: 1px solid var(--line); border-radius: 16px; min-height: 0; overflow: hidden; margin-bottom: 24px; }
  .seg { top: 0; }
  .pane { padding-bottom: 24px; }
  .mobile-cta { display: none; }
}
@media (max-width: 899px) { .desktop-only { display: none !important; } }

/* ── 여러 명 보내기 ── */
.mini-seg { display: inline-flex; background: #efede8; border-radius: 8px; padding: 2px; }
.mini-seg button { height: 26px; padding: 0 11px; border-radius: 6px; font-size: 12px; font-weight: 700; color: var(--muted); }
.mini-seg button.on { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0,0,0,.12); }
.bulk-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; font-size: 13px; color: var(--ink2); }
.bulk-meta label { display: inline-flex; align-items: center; gap: 6px; }
.bulk-meta input { width: 18px; height: 18px; accent-color: var(--point); }
.bulk-meta b { color: var(--point); }
.field .note { margin-top: 6px; }
.bulk-tools { display: flex; gap: 8px; margin: 16px 0 10px; }
.bulk-tools .btn { flex: 1; border-radius: 10px; }
.bulk-list { list-style: none; max-height: 42vh; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.bulk-list li { display: flex; align-items: center; gap: 6px; padding: 9px 10px 9px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
.bulk-list li:last-child { border-bottom: 0; }
.bulk-list .nm { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
.bulk-list .acts { display: flex; gap: 5px; flex: 0 0 auto; }
@media (max-width: 480px) {
  .bulk-list li { flex-wrap: wrap; }
  .bulk-list .nm { flex-basis: 100%; }
  .bulk-list .acts { flex: 1; }
  .bulk-list .acts .mini { flex: 1; }
}
.bulk-list li.done .nm { color: var(--muted); }
.bulk-list li.done .nm::before { content: '✓ '; color: #16a34a; font-weight: 800; }
.mini { flex: 0 0 auto; height: 30px; padding: 0 10px; border-radius: 8px; background: #efede8; font-size: 12px; font-weight: 700; }
.mini.dark { background: var(--ink); color: #fff; }

/* ── 모달 ── */
.modal-bg {
  position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.45);
  display: flex; align-items: flex-end; justify-content: center;
  animation: fade .2s;
}
.modal {
  width: 100%; max-width: 480px; max-height: 92vh; overflow: auto; background: #fff; border-radius: 20px 20px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  animation: up .25s ease-out;
}
@media (min-width: 640px) { .modal-bg { align-items: center; } .modal { border-radius: 20px; } }
.modal h2 { font-size: 18px; font-weight: 800; }
.modal .desc { font-size: 13px; color: var(--ink2); margin-top: 6px; line-height: 1.6; }
.share-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px; margin: 20px 0 16px; }
.share-row button { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 600; color: var(--ink2); white-space: nowrap; }
.share-row .ico { width: 48px; height: 48px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 22px; }
.link-box { display: flex; gap: 6px; }
.link-box input { flex: 1; min-width: 0; height: 44px; border: 1px solid var(--line); border-radius: 10px; padding: 0 12px; font-size: 13px; background: #fafaf8; color: var(--ink2); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }

/* ── 받는 화면 ── */
.viewer {
  min-height: 100vh; min-height: 100dvh; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 32px 16px calc(32px + env(safe-area-inset-bottom));
  background: radial-gradient(circle at 50% 30%, var(--vb1, #26304f), var(--vb2, #0b0f1c));
}
.viewer .from-line { font-size: 14px; opacity: .85; margin-bottom: 18px; text-align: center; }
.viewer .preview { width: min(340px, 86vw); border-radius: 12px; box-shadow: 0 24px 60px rgba(0,0,0,.45); }
.viewer .actions { width: min(340px, 86vw); display: flex; flex-direction: column; gap: 8px; margin-top: 22px; }
.viewer .actions .btn.ghost { background: rgba(127,127,127,.2); color: inherit; }
.viewer .made { margin-top: 18px; font-size: 12px; opacity: .55; }
.envelope {
  width: min(320px, 82vw); aspect-ratio: 3 / 2; position: relative; cursor: pointer;
  border-radius: 10px; background: var(--env, #c8372d); box-shadow: 0 20px 50px rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  animation: bob 2.4s ease-in-out infinite;
}
.envelope::before {
  content: ''; position: absolute; inset: 0; border-radius: 10px 10px 0 0;
  background: rgba(0,0,0,.14);
  clip-path: polygon(0 0, 100% 0, 50% 58%);
}
.envelope .wax {
  position: relative; width: 64px; height: 64px; border-radius: 50%;
  background: #f3dfb4; color: #7a2a20; font-family: 'Noto Serif KR', serif; font-weight: 700; font-size: 18px;
  display: flex; align-items: center; justify-content: center; box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.envelope-hint { margin-top: 22px; font-size: 14px; opacity: .8; }
.opened { animation: pop .6s cubic-bezier(.2,.9,.3,1.2); }
@keyframes bob { 50% { transform: translateY(-8px); } }
@keyframes pop { from { transform: scale(.7) translateY(30px); opacity: 0; } }

/* ── 토스트 ── */
.toast {
  position: fixed; left: 50%; bottom: 96px; transform: translate(-50%, 20px);
  background: rgba(28,28,30,.92); color: #fff; font-size: 14px; font-weight: 600;
  padding: 11px 18px; border-radius: 22px; opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s; z-index: 100; max-width: calc(100vw - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
