/* 한 땀 편지 — 수예점 도안책: 남색 인쇄 + 파란 모눈 + 홍실. 장면(천)이 주인공. */
@font-face {
  font-family: "Galmuri UI";
  src: url("../vendor/galmuri/galmuri11-ui.woff2") format("woff2");
  font-display: swap;
}
:root {
  --ink: #22336a;
  --ink-2: rgba(34, 51, 106, .66);
  --paper: #fbfbf7;
  --chart: rgba(52, 92, 160, .13);
  --red: #c4262f;
  --red-d: #9e1c25;
  --fabric: #eeeee9;
  --pix: "Galmuri UI", "Gowun Dodum", system-ui, sans-serif;
  --body: "Gowun Dodum", system-ui, sans-serif;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
body[data-fabric="natural"] { --fabric: #d4c4a4; }
body[data-fabric="black"] { --fabric: #26252a; }
body[data-fabric="check"] { --fabric: #efeee8; }

* { box-sizing: border-box; }
html { scrollbar-width: none; -webkit-text-size-adjust: 100%; }
html::-webkit-scrollbar { display: none; }
body {
  margin: 0; min-height: 100svh; height: auto; overflow-x: hidden; overflow-y: visible;
  background: var(--fabric); color: var(--ink); font-family: var(--body);
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

#stage { position: fixed; left: 0; top: 0; display: block; touch-action: pan-y; cursor: text; }
body.playing #stage, body.recv-intro #stage { cursor: default; }
#ta {
  position: fixed; left: 0; top: 0; width: 2px; height: 2px; padding: 0; border: 0; margin: 0;
  opacity: 0; resize: none; font-size: 16px; color: transparent; background: transparent; caret-color: transparent; overflow: hidden;
}

/* ── 위 막대 ───────────────────────────────────────── */
.bar {
  position: fixed; left: 0; right: 0; top: 0; z-index: 20;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: calc(10px + var(--safe-t)) 14px 8px;
  pointer-events: none;
}
.bar > * { pointer-events: auto; }
.logo {
  font: 400 15px/1 var(--pix); color: var(--paper); background: var(--ink); text-decoration: none;
  padding: 7px 8px 6px; border-radius: 3px; letter-spacing: .02em; white-space: nowrap; flex-shrink: 0;
}
.title { margin: 0; font: 400 15px/1 var(--pix); color: var(--ink); letter-spacing: .04em; padding: 0 2px; white-space: nowrap; }
body[data-fabric="black"] .title, body[data-fabric="black"] .count { color: #e9e7f2; }
.opts { display: flex; gap: 6px; flex-wrap: nowrap; }
.tally { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; }
.count { font: 400 12px/1 var(--pix); color: var(--ink-2); font-variant-numeric: tabular-nums; }
.clear {
  height: 26px; padding: 0 8px; font: 400 12px/1 var(--pix); color: var(--red); background: var(--paper);
  border: 1px dashed var(--red); border-radius: 3px; cursor: pointer;
}
.clear.armed { background: var(--red); color: #fff; border-style: solid; }
.clear[hidden] { display: none; }
body.empty .count { visibility: hidden; }
body[data-fabric="black"] .clear:not(.armed) { background: transparent; color: #ff8a8f; border-color: #ff8a8f; }

.chip, .btn {
  position: relative; display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 11px;
  font: 400 13px/1 var(--pix); color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--ink); border-radius: 4px; cursor: pointer; white-space: nowrap;
  box-shadow: 0 2px 0 rgba(34, 51, 106, .22);
}
/* 꿰맨 라벨처럼 안쪽 홈질 */
.chip::after, .btn::after {
  content: ""; position: absolute; inset: 3px; border: 1px dashed currentColor; border-radius: 2px; opacity: .35; pointer-events: none;
}
.chip b, .btn b { font-weight: 400; }
.chip b { color: var(--ink-2); margin-left: 3px; }
.chip b:empty { display: none; }
.fsw { width: 16px; height: 16px; border-radius: 2px; border: 1px solid rgba(34, 51, 106, .5); background: var(--fabric) center / cover; }
.chip[aria-expanded="true"] { background: var(--ink); color: var(--paper); }
.chip[aria-expanded="true"] b { color: rgba(251, 251, 247, .75); }
.chip:active, .btn:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(34, 51, 106, .22); }
.sw { width: 14px; height: 14px; border-radius: 50%; border: 1px solid rgba(34, 51, 106, .5); background: var(--red); }
.btn.red { background: var(--red); border-color: var(--red-d); color: #fff; box-shadow: 0 2px 0 var(--red-d); }
.btn.red::after { opacity: .6; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.chip.quiet, .btn.quiet { box-shadow: none; }
#sound svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
#sound svg path:first-child { fill: currentColor; stroke: none; }
#sound[aria-pressed="false"] .on, #sound[aria-pressed="true"] .off { display: none; }

/* 옵션 시트: 모눈 도안지 */
.sheet {
  position: absolute; top: calc(100% - 2px); left: 14px; width: min(440px, calc(100vw - 28px));
  max-height: min(62vh, 520px); overflow: auto; padding: 12px 12px 14px;
  background-color: var(--paper);
  background-image: linear-gradient(var(--chart) 1px, transparent 1px), linear-gradient(90deg, var(--chart) 1px, transparent 1px);
  background-size: 10px 10px; background-position: -1px -1px;
  border: 1.5px solid var(--ink); border-radius: 4px; box-shadow: 0 14px 34px rgba(20, 30, 60, .2);
}
.sh-t { margin: 2px 2px 10px; font: 400 14px/1.3 var(--pix); }
.sh-t small { display: block; margin-top: 3px; font: 400 12.5px/1.4 var(--body); color: var(--ink-2); }
.sh-t + .pills + .sh-t { margin-top: 16px; }
.grid { display: grid; gap: 8px 6px; }
.skeins { grid-template-columns: repeat(5, 1fr); }
.swatches { grid-template-columns: repeat(4, 1fr); }
.skein, .swatch {
  display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 6px 2px 5px; min-height: 44px;
  background: rgba(251, 251, 247, .88); border: 1.5px solid transparent; border-radius: 4px; cursor: pointer;
  font: 400 11.5px/1.15 var(--pix); color: var(--ink); text-align: center; word-break: keep-all;
}
.skein[aria-checked="true"], .swatch[aria-checked="true"], .pill[aria-checked="true"] { border-color: var(--ink); background: var(--paper); box-shadow: 0 2px 0 rgba(34, 51, 106, .25); }
/* 실타래: 꼬인 실 + 가운데 종이 띠 */
.sk {
  position: relative; width: 46px; height: 22px; border-radius: 11px; background: var(--sk);
  box-shadow: inset 0 -3px 4px rgba(0, 0, 0, .22), inset 0 2px 3px rgba(255, 255, 255, .35);
}
.sk::before {
  content: ""; position: absolute; inset: 0; border-radius: 11px;
  background: repeating-linear-gradient(115deg, rgba(0, 0, 0, .16) 0 1.5px, transparent 1.5px 4px);
}
.sk::after {
  content: ""; position: absolute; left: 50%; top: -2px; bottom: -2px; width: 12px; transform: translateX(-50%);
  background: var(--paper); border-left: 1.5px solid var(--ink); border-right: 1.5px solid var(--ink);
}
.skein.dim { opacity: .45; }
.skein.dim span:last-child::after { content: " · 흐림"; color: var(--red); }
.dim-note { color: var(--red); }
.swatch img, .swatch .none { width: 54px; height: 54px; border-radius: 3px; border: 1px solid rgba(34, 51, 106, .3); display: block; }
.swatch .none { background: repeating-linear-gradient(45deg, transparent 0 6px, rgba(34, 51, 106, .12) 6px 7px), var(--paper); }
.pills { display: flex; flex-wrap: wrap; gap: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px;
  background: rgba(251, 251, 247, .88); border: 1.5px solid rgba(34, 51, 106, .3); border-radius: 4px; cursor: pointer;
  font: 400 13px/1 var(--pix); color: var(--ink);
}
.dots { display: inline-block; width: 18px; height: 18px; background-image: radial-gradient(var(--ink) 38%, transparent 40%); }
.d-l { background-size: 9px 9px; } .d-m { background-size: 6px 6px; } .d-s { background-size: 4.5px 4.5px; }

/* 힌트 */
.hint {
  position: fixed; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%); z-index: 10; margin: 0;
  font: 400 13px/1 var(--pix); color: var(--ink); background: var(--paper); border: 1.5px solid var(--ink); border-radius: 3px;
  padding: 9px 12px; white-space: nowrap; transition: opacity .4s; pointer-events: none;
}
.hint .fine { display: none; }
@media (pointer: fine) { .hint .fine { display: inline; } .hint .coarse { display: none; } }
body:not(.empty) .hint, body.typing .hint, body.stitching .hint, body.playing .hint, body.recv-intro .hint { opacity: 0; }

/* 받은 편지 재생 중 */
.playui { position: fixed; left: 0; right: 0; bottom: calc(18px + var(--safe-b)); z-index: 12; display: none; align-items: center; gap: 12px; padding: 0 16px; }
body.playing .playui { display: flex; }
body.playing .opts, body.playing #finish, body.playing .tally,
body.recv-intro .opts, body.recv-intro #finish, body.recv-intro .tally { visibility: hidden; }
.playbar { --p: 0; flex: 1; height: 6px; border-radius: 3px; background: rgba(34, 51, 106, .14); overflow: hidden; }
.playbar::before { content: ""; display: block; height: 100%; width: calc(var(--p) * 100%); background: var(--red); }

/* 도착: 실로 묶은 봉투(선물) — 아무 데나 누르면 풀린다 */
.intro {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; padding: 20px; cursor: pointer;
  background: radial-gradient(ellipse at 50% 42%, rgba(251, 251, 247, .55), rgba(30, 38, 70, .38) 75%);
}
.intro[hidden] { display: none; }
.gift { display: flex; flex-direction: column; align-items: center; text-align: center; width: min(380px, 100%); }
.parcel {
  position: relative; display: block; width: min(400px, 82vw, 52svh); padding: 0; border: 0; background: none; cursor: pointer;
}
/* 흔들림은 안쪽에만(버튼 자리는 가만히 — 누르기 쉽게) */
.bobber { position: relative; display: block; filter: drop-shadow(0 18px 22px rgba(20, 30, 60, .28)); animation: bob 3.2s ease-in-out infinite; }
.parcel:focus-visible { outline-offset: 6px; }
.parcel-svg { display: block; width: 100%; height: auto; overflow: visible; }
.tie path, .tie circle { fill: none; stroke: #c4262f; stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.tie .tw { stroke: #8f1a24; stroke-width: 4; stroke-dasharray: 1.4 3.2; opacity: .7; }
.tie .bow path { stroke-width: 3.6; }
.tie .bow path:not(.tail) { fill: rgba(196, 38, 47, .14); }
.tie .bow circle { fill: #c4262f; stroke: #8f1a24; stroke-width: 1.4; }
.tie-v path { stroke-dasharray: 140; stroke-dashoffset: 0; }
.tie-h path { stroke-dasharray: 220; stroke-dashoffset: 0; }
.tie-v .tw, .tie-h .tw { stroke-dasharray: 1.4 3.2; }
.env-flap { transform-origin: 120px 41px; transform-box: view-box; }
.bow { transform-origin: 150px 124px; transform-box: view-box; }
.tag {
  position: absolute; right: -4%; bottom: 2%; transform: rotate(-7deg); display: flex; flex-direction: column; gap: 3px;
  min-width: 92px; max-width: 58%; padding: 8px 12px 8px 18px; text-align: left; color: var(--ink); background: var(--paper);
  border: 1.5px solid var(--ink); border-radius: 3px 12px 12px 3px; box-shadow: 0 3px 0 rgba(34, 51, 106, .18);
}
.tag::before { content: ""; position: absolute; left: 6px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; border: 1.5px solid var(--ink); }
.tag small { font: 400 10.5px/1 var(--pix); color: var(--ink-2); }
.tag b { font: 400 15px/1.15 var(--pix); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.g-h { margin: 22px 0 6px; font: 400 19px/1.4 var(--pix); color: var(--ink); background: var(--paper); padding: 6px 10px; border-radius: 3px; word-break: keep-all; }
.g-s { margin: 0 0 16px; font: 400 13px/1 var(--pix); color: var(--ink); opacity: .8; }
.intro .btn { height: 36px; }
.intro.opening { pointer-events: none; transition: opacity .45s .5s; opacity: 0; }
.intro.opening .bobber { animation: none; }
.intro.opening .tie-v path { transition: stroke-dashoffset .45s ease-in; stroke-dashoffset: 140; }
.intro.opening .tie-h path { transition: stroke-dashoffset .45s ease-in; stroke-dashoffset: -220; }
.intro.opening .tie-v .tw, .intro.opening .tie-h .tw { opacity: 0; transition: opacity .2s; }
.intro.opening .bow { transition: transform .35s ease-in, opacity .35s; transform: scale(.2) rotate(40deg); opacity: 0; }
.intro.opening .pin { transition: transform .4s ease-in, opacity .4s; transform: translate(30px, -30px); opacity: 0; }
.intro.opening .env-flap { transition: transform .4s .3s ease-out; transform: scaleY(-1); }
.intro.opening .tag { transition: transform .5s ease-in, opacity .5s; transform: rotate(14deg) translate(30px, 40px); opacity: 0; }
@keyframes bob { 0%, 100% { transform: translateY(0) rotate(-1.2deg); } 50% { transform: translateY(-6px) rotate(1deg); } }

/* 보내는 사람 이름 */
.from { flex: 1 1 100%; min-width: 0; display: flex; align-items: center; gap: 10px; padding: 0 2px; }
.from span { font: 400 13px/1 var(--pix); white-space: nowrap; }
.from input {
  flex: 1; width: 0; min-width: 0; height: 40px; padding: 0 10px; font: 400 16px var(--body); color: var(--ink); background: #fff;
  border: 1.5px solid rgba(34, 51, 106, .45); border-bottom: 1.5px dashed var(--ink); border-radius: 3px;
}
.from input:focus { outline: none; border-color: var(--ink); }

/* 완성: 수틀 */
.finale {
  position: fixed; inset: 0; z-index: 45; display: grid; place-items: center; padding: 12px;
  background: rgba(24, 30, 56, .55); opacity: 0; transition: opacity .3s;
}
.finale[hidden] { display: none; }
.finale.on { opacity: 1; }
.fin-card {
  width: min(560px, 100%); max-height: calc(100svh - 24px); overflow: auto; padding: 12px 12px 14px;
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 4px;
  transform: translateY(18px) scale(.97); transition: transform .45s cubic-bezier(.2, .9, .3, 1.2);
}
.finale.on .fin-card { transform: none; }
.fin-head { display: flex; align-items: center; justify-content: space-between; padding: 2px 2px 8px; }
.fin-head h2 { margin: 0; font: 400 16px/1 var(--pix); }
.x { width: 36px; height: 36px; display: grid; place-items: center; background: none; border: 0; cursor: pointer; color: var(--ink); }
.x svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; stroke-linecap: round; fill: none; }
.hoop-view canvas { display: block; width: 100%; height: auto; max-height: min(62svh, 640px); object-fit: contain; border-radius: 3px; }
.fin-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.fin-actions .btn { height: 42px; padding: 0 14px; font-size: 14px; }
.fin-actions .fin-primary, .fin-actions #mine { flex: 1 1 100%; justify-content: center; }
.fin-note { margin: 10px 2px 0; font-size: 13px; line-height: 1.5; color: var(--ink-2); word-break: keep-all; }
body:not(.recv) .only-recv, body.recv .only-send { display: none !important; }
#saveVid[hidden] { display: none; }

.toast {
  position: fixed; left: 50%; top: calc(100px + var(--safe-t)); z-index: 60; transform: translate(-50%, -8px);
  max-width: calc(100vw - 32px); padding: 10px 14px; background: var(--ink); color: var(--paper);
  font: 400 13px/1.4 var(--pix); border-radius: 3px; opacity: 0; pointer-events: none; transition: opacity .25s, transform .25s; text-align: center; word-break: keep-all;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
/* 시트가 열려 있으면 시트를 덮지 않게 아래로 */
body.sheet-open .toast { top: auto; bottom: calc(28px + var(--safe-b)); }

/* ── 아래 안내(첫 화면 밖) ──────────────────────────── */
.guide {
  position: relative; z-index: 30; margin-top: 100svh;
  background-color: var(--paper);
  background-image: linear-gradient(var(--chart) 1px, transparent 1px), linear-gradient(90deg, var(--chart) 1px, transparent 1px);
  background-size: 12px 12px;
  border-top: 1.5px solid var(--ink);
  content-visibility: auto; contain-intrinsic-size: auto 1700px;
}
.guide-in { max-width: 680px; margin: 0 auto; padding: 44px 20px 64px; }
.guide h2 { font: 400 19px/1.35 var(--pix); margin: 38px 0 12px; }
.guide h2:first-child { margin-top: 0; }
.guide p, .guide li, .guide dd { font-size: 16px; line-height: 1.75; word-break: keep-all; }
.guide p { margin: 0 0 12px; }
.steps { margin: 0; padding-left: 1.4em; }
.steps li { margin-bottom: 10px; }
.steps b, .faq dt { font-family: var(--pix); font-weight: 400; }
.steps b { display: block; font-size: 15px; }
.faq { margin: 0; }
.faq dt { font-size: 15px; margin-top: 18px; }
.faq dd { margin: 4px 0 0; color: #3a4670; }
.others { margin: 0; padding: 0; list-style: none; }
.others li { margin-bottom: 8px; }
.guide a { color: var(--red); text-underline-offset: 3px; }
.others a { font-family: var(--pix); margin-right: 6px; }
.credit { margin-top: 30px !important; font-size: 13px !important; color: var(--ink-2); }
.fallback { position: fixed; top: 40%; left: 0; right: 0; text-align: center; font: 400 15px var(--pix); }

.narrow-only { display: none; }
/* 좁은 화면: 한 줄 막대(실·천·땀·테두리 칩 + 수틀 버튼), 이름과 소리는 시트로 */
@media (max-width: 900px) {
  .bar { gap: 6px; padding: calc(8px + var(--safe-t)) 12px 6px; flex-wrap: nowrap; }
  .title { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
  .opts { gap: 5px; }
  .chip, .btn { height: 34px; padding: 0 9px; font-size: 13px; }
  .chip b { display: none; }
  #sound { display: none; }
  .narrow-only { display: block; }
  .pills.narrow-only { display: flex; }
  /* 글자 수·다 풀기는 막대 아래 오른쪽에 작게, 쓰는 동안만 */
  .tally { position: absolute; right: 12px; top: calc(100% + 2px); margin: 0; }
  body.empty .tally { display: none; }
  .count { font-size: 11.5px; }
  #finish { margin-left: auto; }
  .sheet { left: 12px; width: calc(100vw - 24px); }
  .skeins { grid-template-columns: repeat(4, 1fr); }
}
@media (max-width: 380px) {
  .bar { gap: 5px; padding-left: 10px; padding-right: 10px; }
  .opts { gap: 4px; }
  .chip, .btn { padding: 0 7px; font-size: 12.5px; gap: 5px; }
}
@media (max-width: 340px) {
  .chip, .btn { padding: 0 5px; font-size: 12px; }
}
@media (prefers-reduced-motion: reduce) {
  .fin-card, .finale, .toast, .hint { transition: none; }
  .bobber { animation: none; }
}
