:root {
  --bg: #FBEDE7;
  --bg-soft: #F6DAD1;
  --ink: #3A1E16;
  --ink-2: #6E4A40;
  --ink-3: #8A6459;
  --line: #E7C3B8;
  --red: #C92F55;
  --red-dark: #A8243F;
  --red-deep: #8E1E3B;
  --biscuit: #E8B86D;
  --night: #24130E;
  --night-2: #3E2219;
  --cream: #FBEDE7;
  --cream-2: #D9BFB6;
  --display: 'Jua', system-ui, sans-serif;
  --body: 'Gowun Dodum', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  word-break: keep-all;
  overflow-wrap: anywhere;
}
body.dark { background: var(--night); color: var(--cream); }

a { color: var(--red); }
a:hover { color: var(--red-dark); }
button { font: inherit; color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible {
  outline: 3px solid var(--red);
  outline-offset: 2px;
}
.dark button:focus-visible, .dark a:focus-visible { outline-color: var(--biscuit); }

.screen {
  max-width: 430px;
  margin: 0 auto;
  min-height: 100dvh;
  padding: 28px 24px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.center { align-items: center; justify-content: center; text-align: center; }
.spacer { flex: 1 1 auto; }

.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.stack-s { display: flex; flex-direction: column; gap: 4px; }

.eyebrow { font-size: 13px; color: var(--ink-2); }
.dark .eyebrow { color: var(--cream-2); }
.h1 { margin: 0; font-family: var(--display); font-weight: 400; font-size: 30px; line-height: 1.22; }
.h1.big { font-size: 34px; }
.lead { margin: 0; font-size: 15px; line-height: 1.6; color: var(--ink-2); }
.dark .lead { color: var(--cream-2); }
.small { font-size: 13px; color: var(--ink-3); line-height: 1.5; }

.pill {
  display: inline-flex; align-items: center; height: 32px; padding: 0 14px;
  border-radius: 16px; background: var(--ink); color: var(--cream);
  font-family: var(--display); font-size: 14px;
}
.pill.biscuit { background: var(--biscuit); color: var(--night); height: 30px; }
.dday { font-family: var(--display); font-size: 18px; color: var(--red); }

/* 버튼 */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 56px; border-radius: 16px; border: 0; cursor: pointer;
  font-family: var(--display); font-size: 18px; text-decoration: none;
  transition: transform .08s ease, opacity .2s ease;
}
.btn:active { transform: scale(.98); }
.btn[disabled] { opacity: .5; cursor: default; }
.btn-primary { background: var(--red); color: #fff; }
.btn-primary:hover { color: #fff; background: var(--red-dark); }
.btn-dark { background: var(--ink); color: var(--cream); }
.btn-dark:hover { color: var(--cream); }
.btn-outline { background: transparent; border: 1.5px solid var(--ink); color: var(--ink); height: 52px; font-size: 17px; }
.dark .btn-outline { border-color: #6B4134; color: var(--cream); }
.btn-link {
  align-self: center; min-height: 44px; padding: 0 12px; border: 0; background: transparent;
  color: var(--red); font-family: var(--body); font-size: 15px; cursor: pointer; text-decoration: underline;
}
.dark .btn-link { color: var(--biscuit); }

/* 입력 */
.field { display: flex; flex-direction: column; gap: 8px; }
.field label, .field .label { font-size: 13px; color: var(--ink-2); }
.input, .textarea {
  width: 100%; border-radius: 16px; border: 1.5px solid var(--line); background: #fff;
  font-family: var(--body); font-size: 16px; color: var(--ink); padding: 0 16px;
}
.input { height: 52px; }
.textarea { height: 84px; padding: 12px 16px; line-height: 1.5; resize: none; }
.input:focus, .textarea:focus { border-color: var(--red); outline: none; }
.notice { display: flex; gap: 8px; align-items: flex-start; font-size: 13px; line-height: 1.5; color: var(--ink-2); }
.notice svg { flex: 0 0 auto; margin-top: 2px; }
.error { color: var(--red-dark); font-size: 14px; min-height: 1em; }

/* 첫 화면 그림 */
.hero { position: relative; width: 100%; max-width: 342px; height: 290px; margin: 0 auto; flex: 0 0 auto; }
.hero-circle { position: absolute; left: 50%; top: 10px; width: 260px; height: 260px; margin-left: -130px; border-radius: 50%; background: var(--bg-soft); }
.hero-stick {
  position: absolute; bottom: 64px; width: 26px; border-radius: 13px; overflow: hidden;
  display: flex; flex-direction: column; transform-origin: bottom center;
  box-shadow: inset -6px 0 0 rgba(0,0,0,.13), inset 4px 0 0 rgba(255,255,255,.10);
}
.hero-box {
  position: absolute; left: 50%; bottom: 0; width: 240px; height: 140px; margin-left: -120px;
  border-radius: 18px; background: var(--red); overflow: hidden;
  box-shadow: 0 18px 30px -18px rgba(90,20,40,.6);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
}
.hero-box::before { content: ''; position: absolute; left: 0; right: 0; top: 0; height: 16px; background: var(--red-dark); }
.hero-box::after { content: ''; position: absolute; left: 16px; top: 28px; width: 6px; height: 70px; border-radius: 3px; background: rgba(255,255,255,.18); }
.hero-box .num { font-family: var(--display); font-size: 46px; color: #fff; line-height: 1; margin-top: 10px; }
.hero-box .cap { font-size: 13px; color: #FFE3EA; letter-spacing: .04em; }

/* 카운트다운 카드 */
.countdown {
  border-radius: 22px; padding: 18px 20px; background-color: var(--ink);
  background-image: linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px), linear-gradient(90deg, rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 34px 34px; display: flex; flex-direction: column; gap: 4px;
}
.countdown .k { font-size: 13px; color: var(--biscuit); }
.countdown .v { font-family: var(--display); font-size: 38px; line-height: 1.1; color: var(--cream); font-variant-numeric: tabular-nums; }
.countdown .s { font-size: 13px; color: var(--cream-2); }

/* 상자 */
.box { border-radius: 24px; padding: 14px; background: var(--red); display: flex; flex-direction: column; gap: 12px; box-shadow: 0 18px 30px -20px rgba(90,20,40,.7); }
.tray {
  position: relative; height: 236px; border-radius: 14px; padding: 18px 10px 0; background: var(--red-deep);
  display: flex; align-items: flex-end; justify-content: center; gap: 4px; overflow: hidden;
}
.slot { flex: 0 0 22px; border-radius: 11px 11px 4px 4px; }
.slot.empty { border: 1.5px dashed rgba(255,255,255,.45); }
.slot.full { box-shadow: 0 2px 4px rgba(60,10,25,.35), inset 0 0 0 1px rgba(58,30,22,.12); }
.lip {
  position: absolute; left: 0; right: 0; bottom: 0; height: 46px; background: var(--red);
  box-shadow: 0 -6px 12px -6px rgba(60,10,25,.55);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--display); font-size: 18px; color: #FFE3EA; letter-spacing: .08em;
}
.box-foot { display: flex; align-items: baseline; justify-content: space-between; padding: 0 4px; color: #fff; }
.box-foot .n { font-family: var(--display); font-size: 22px; }
.box-foot .t { font-size: 13px; color: #FFE9EE; }

.owner-link {
  border-radius: 16px; background: #fff; padding: 14px 16px; display: flex; flex-direction: column; gap: 8px;
  box-shadow: 0 1px 0 #EED3CA;
}

/* 넣기 화면 */
.preview {
  position: relative; height: 140px; flex: 0 0 auto; border-radius: 22px; background: var(--bg-soft);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.stick-h { position: relative; width: 266px; height: 32px; transform: rotate(-6deg); }
.stick-h.pop { animation: pop .35s ease-out; }
.stick-h .body {
  position: absolute; inset: 0; border-radius: 16px; overflow: hidden; display: flex;
  box-shadow: 0 14px 20px -12px rgba(58,30,22,.55), inset 0 -5px 0 rgba(0,0,0,.1);
}
.biscuit-h {
  flex: 0 0 32%;
  background: linear-gradient(180deg, rgba(255,255,255,.25) 0 6px, transparent 6px),
    repeating-linear-gradient(90deg, rgba(150,90,30,.20) 0 2px, transparent 2px 8px), var(--biscuit);
}
.coat-h { flex: 1; }
.sleeve {
  position: absolute; left: -12px; top: -10px; width: 120px; height: 52px; border-radius: 10px 4px 4px 10px;
  box-shadow: 0 8px 14px -8px rgba(58,30,22,.5), inset -6px 0 0 rgba(0,0,0,.08), inset 0 0 0 1px rgba(58,30,22,.10);
  animation: wrapin .4s ease-out both;
}
.ribbon { position: absolute; left: 92px; top: -13px; width: 10px; height: 58px; border-radius: 3px; box-shadow: 0 0 0 1px rgba(58,30,22,.12); animation: wrapin .4s ease-out both; }
.knot { position: absolute; left: 86px; top: 8px; width: 22px; height: 16px; border-radius: 8px; box-shadow: 0 0 0 1px rgba(58,30,22,.12); animation: wrapin .4s ease-out both; }
.preview .tag {
  position: absolute; right: 12px; bottom: 10px; max-width: calc(100% - 24px); height: 26px; padding: 0 10px; border-radius: 13px;
  background: #fff; display: flex; align-items: center; font-size: 13px; color: var(--ink-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
@keyframes pop { 0% { transform: rotate(-6deg) scale(1); } 40% { transform: rotate(-6deg) scale(1.06); } 100% { transform: rotate(-6deg) scale(1); } }
@keyframes wrapin { 0% { opacity: 0; transform: translateX(-26px); } 100% { opacity: 1; transform: none; } }

.tabs { display: flex; gap: 4px; padding: 4px; border-radius: 16px; background: rgba(255,255,255,.55); }
.tab { flex: 1; height: 40px; border: 0; border-radius: 12px; cursor: pointer; font-family: var(--display); font-size: 16px; background: transparent; color: var(--ink-2); }
.tab[aria-selected="true"] { background: var(--ink); color: var(--cream); }

.options { min-height: 100px; display: flex; flex-direction: column; gap: 8px; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.wrapflex { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: flex; align-items: center; gap: 8px; cursor: pointer; font-family: var(--body); font-size: 14px;
  color: var(--ink); background: rgba(255,255,255,.5); border: 1.5px solid var(--line);
  height: 46px; padding: 0 12px; border-radius: 14px; text-align: left;
}
.chip[aria-pressed="true"] { background: #fff; border: 2px solid var(--red); }
.chip.round { height: 44px; border-radius: 22px; padding: 0 12px 0 8px; }
.chip.tile { flex-direction: column; justify-content: center; gap: 6px; height: 72px; padding: 8px; font-size: 13px; text-align: center; }
.sw { width: 22px; height: 22px; border-radius: 50%; flex: 0 0 auto; box-shadow: inset 0 0 0 1px rgba(58,30,22,.15); }
.sw-wrap { width: 100%; height: 26px; border-radius: 8px; box-shadow: inset 0 0 0 1px rgba(58,30,22,.12); }

/* 덮개 화면 */
.overlay {
  position: fixed; inset: 0; z-index: 20; background: var(--bg); overflow-y: auto;
  display: flex; align-items: center; justify-content: center;
}
.overlay.dim { background: rgba(36,19,14,.9); color: var(--cream); }
.overlay > .screen { min-height: auto; width: 100%; }
.drop { position: relative; width: 200px; height: 180px; margin: 0 auto; }
.drop .stick-v { position: absolute; left: 89px; top: 0; width: 22px; height: 124px; animation: drop .8s ease-out both; }
.stick-v .body { position: absolute; inset: 0; border-radius: 11px; overflow: hidden; display: flex; flex-direction: column; }
.stick-v .sleeve-v { position: absolute; left: -7px; bottom: -6px; width: 36px; height: 58px; border-radius: 4px 4px 8px 8px; box-shadow: 0 8px 14px -8px rgba(58,30,22,.5), inset 0 0 0 1px rgba(58,30,22,.10); }
.stick-v .ribbon-v { position: absolute; left: -9px; bottom: 40px; width: 40px; height: 7px; border-radius: 3px; }
.drop .mini-box { position: absolute; left: 30px; bottom: 0; width: 140px; height: 78px; border-radius: 14px; background: var(--red); overflow: hidden; }
.drop .mini-box::before { content: ''; display: block; height: 10px; background: var(--red-dark); }
.drop .mini-box span { display: block; font-family: var(--display); font-size: 28px; color: #fff; text-align: center; margin-top: 12px; }
@keyframes drop { 0% { transform: translateY(-60px) rotate(-20deg); opacity: 0; } 60% { transform: translateY(6px) rotate(4deg); opacity: 1; } 100% { transform: none; } }

/* 녹이기 */
.melt { position: relative; width: 100%; aspect-ratio: 342 / 330; flex: 0 0 auto; }
.melt .letter {
  position: absolute; inset: 0; border-radius: 22px; background: var(--cream); color: var(--ink);
  padding: 28px 26px; display: flex; flex-direction: column; justify-content: center; gap: 16px;
}
.melt .letter .msg { font-family: var(--display); font-size: 25px; line-height: 1.4; word-break: keep-all; overflow-wrap: anywhere; }
.melt .letter .meta { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--ink-2); }
.melt-grid {
  position: absolute; inset: 0; border-radius: 22px; overflow: hidden; display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr)); grid-template-rows: repeat(5, minmax(0, 1fr));
  touch-action: none; cursor: grab; user-select: none; -webkit-user-select: none;
}
.melt-grid.done { pointer-events: none; }
.piece {
  background: #5A2E21;
  transition: opacity .45s ease, transform .45s ease, filter .2s ease, border-radius .2s ease;
}
.progress { height: 8px; border-radius: 4px; background: var(--night-2); overflow: hidden; }
.progress > div { height: 100%; border-radius: 4px; background: var(--biscuit); transition: width .3s ease; }

/* 모아보기 */
.shelf { height: 104px; flex: 0 0 auto; border-radius: 22px; background: var(--ink); display: flex; align-items: flex-end; justify-content: center; gap: 10px; padding: 0 16px 16px; overflow: hidden; }
.shelf .stick-v { position: relative; width: 14px; flex: 0 0 auto; }
.shelf .stick-v.open { outline: 2px solid var(--biscuit); outline-offset: 2px; border-radius: 7px; }
.credit { border-radius: 18px; background: #fff; padding: 12px 14px; display: flex; align-items: center; gap: 12px; box-shadow: 0 1px 0 #EED3CA; }
.credit .t { font-family: var(--display); font-size: 16px; }
.keys { display: flex; gap: 4px; }
.keys span { width: 10px; height: 10px; border-radius: 50%; background: #EED3CA; }
.keys span.on { background: var(--red); }
.cards { display: flex; flex-direction: column; gap: 10px; }
.card { border-radius: 18px; background: #fff; padding: 14px 16px; display: flex; gap: 14px; align-items: flex-start; box-shadow: 0 1px 0 #EED3CA; }
.card .txt { font-size: 16px; line-height: 1.45; word-break: keep-all; overflow-wrap: anywhere; }
.card .foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 36px; }
.mini-h { margin-top: 6px; width: 40px; height: 11px; border-radius: 6px; overflow: hidden; display: flex; flex: 0 0 auto; }
.mini-h .b { flex: 0 0 28%; background: var(--biscuit); }
.mini-h .c { flex: 1; }
.name-badge {
  display: inline-flex; align-items: center; height: 28px; padding: 0 12px; border-radius: 14px;
  background: var(--red); color: #fff; font-family: var(--display); font-size: 15px; animation: reveal .5s ease-out both;
}
@keyframes reveal { 0% { transform: scale(.6); opacity: 0; } 60% { transform: scale(1.12); opacity: 1; } 100% { transform: none; } }
.reveal-btn {
  flex: 0 0 auto; min-height: 36px; padding: 0 12px; border-radius: 18px; border: 1.5px solid var(--ink);
  background: transparent; color: var(--ink); font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 6px;
}
.badge { display: inline-flex; align-items: center; height: 18px; padding: 0 6px; border-radius: 5px; background: var(--biscuit); color: var(--ink); font-family: var(--display); font-size: 11px; letter-spacing: .04em; }

.footer { text-align: center; font-size: 12px; color: var(--ink-3); padding-top: 8px; }
.dark .footer { color: var(--cream-2); }
.footer a { color: inherit; }

#toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px);
  max-width: calc(100% - 48px); padding: 12px 18px; border-radius: 14px; background: var(--ink); color: var(--cream);
  font-size: 14px; opacity: 0; pointer-events: none; transition: opacity .2s ease, transform .2s ease; z-index: 50;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

.spinner { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--red); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

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