:root {
  --bg: #fbf4ea;
  --panel: #ffffff;
  --text: #2d2320;
  --muted: #7a6a62;
  --line: #ead9c4;
  --accent: #cf3a43;
  --accent-ink: #ffffff;
  --gold: #f2c14e;
  --chip: #f4e7d6;
  --tag-bg: rgba(255, 255, 255, .92);
  --tag-ink: #2d2320;
  --host-bg: #fff3c4;
  --bubble-bg: #ffffff;
  --bubble-ink: #2d2320;
  --shadow: 0 6px 24px rgba(60, 30, 20, .14);
  --font-title: 'Jua', 'Noto Sans KR', sans-serif;
  --font: 'Noto Sans KR', system-ui, -apple-system, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1d1714; --panel: #2a221e; --text: #f4ebe2; --muted: #b9a89c; --line: #3d322c;
    --chip: #3a2f29; --shadow: 0 6px 24px rgba(0, 0, 0, .45); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1d1714; --panel: #2a221e; --text: #f4ebe2; --muted: #b9a89c; --line: #3d322c;
  --chip: #3a2f29; --shadow: 0 6px 24px rgba(0, 0, 0, .45); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--font); -webkit-text-size-adjust: 100%; }
button, input, textarea { font: inherit; color: inherit; }
[hidden], dialog:not([open]) { display: none !important; }

.locked { min-height: 100dvh; display: grid; place-items: center; padding: 16px; }
.locked-card { background: var(--panel); border-radius: 20px; padding: 28px 24px; text-align: center; box-shadow: var(--shadow); max-width: 360px; }
.locked-card h1 { white-space: nowrap; }
.locked-card p { word-break: keep-all; }
.locked-card p { margin: 0; color: var(--muted); }
.locked-card h1 { font-family: var(--font-title); font-weight: 400; color: var(--accent); margin: 0 0 8px; }

/* 레이아웃: 폰은 세로, 넓은 화면은 좌 맵 / 우 피드 */
.app { display: grid; grid-template-columns: 1fr; padding-bottom: calc(76px + env(safe-area-inset-bottom)); }
.stage-wrap { display: flex; justify-content: center; }
.side { padding: 12px 16px; }
@media (min-width: 900px) {
  .app { grid-template-columns: auto 340px; gap: 20px; padding: 16px 20px; justify-content: center; align-items: start; }
  .side { position: sticky; top: 16px; max-height: calc(100dvh - 32px); display: flex; flex-direction: column; background: var(--panel); border-radius: 18px; box-shadow: var(--shadow); padding: 16px; }
  .stage { border-radius: 14px; box-shadow: var(--shadow); }
}

/* 스테이지: isolation 으로 캐릭터 z-index 가 팝업 위로 못 올라오게 */
.stage { position: relative; isolation: isolate; overflow: hidden; background: #d7a46c; touch-action: manipulation; }
.map { display: block; image-rendering: pixelated; image-rendering: crisp-edges; }
.banner {
  position: absolute; left: 0; right: 0; text-align: center; color: #fff8e6; font-family: var(--font-title);
  text-shadow: 0 2px 0 #7a1d24; pointer-events: none; z-index: 1; letter-spacing: .02em; white-space: nowrap;
}
.actors { position: absolute; inset: 0; z-index: 2; }
.actor { position: absolute; left: 0; top: 0; will-change: transform; transition: transform 1.8s linear; }
.actor img { display: block; image-rendering: pixelated; image-rendering: crisp-edges; pointer-events: none; }
.actor .body { position: absolute; left: 0; bottom: 0; animation: bob 1.4s steps(2, jump-none) infinite; }
.actor.walk .body { animation-duration: .5s; }
.actor.flip img { transform: scaleX(-1); }
.actor.me .body::after { content: ''; position: absolute; left: 50%; top: -10px; width: 8px; height: 8px; margin-left: -4px; background: var(--gold); border: 2px solid #3a2a28; transform: rotate(45deg); }
.actor button.hit { position: absolute; inset: 0; background: none; border: 0; padding: 0; cursor: grab; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.actor.drag { cursor: grabbing; }
.actor.drag .body { animation: none; transform: translateY(-6px) scale(1.08); filter: drop-shadow(0 6px 3px rgba(40, 20, 10, .35)); }
@keyframes bob { from { transform: translateY(0); } to { transform: translateY(var(--bob, -2px)); } }

.tag {
  position: absolute; left: 50%; transform: translateX(-50%); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  background: var(--tag-bg); color: var(--tag-ink); border: 1.5px solid #3a2a28; border-radius: 7px;
  font-weight: 700; line-height: 1.25; padding: 0 5px; pointer-events: none;
}
.tag.host { background: var(--host-bg); border-color: #8a5a1a; }
.tag.me { background: #fff0c2; }

.bubble {
  position: absolute; z-index: 50; background: var(--bubble-bg); color: var(--bubble-ink); border: 2px solid #3a2a28;
  border-radius: 10px; padding: 3px 8px; line-height: 1.3; font-weight: 700; text-align: center; word-break: keep-all; overflow-wrap: anywhere;
  box-shadow: 0 2px 0 rgba(58, 42, 40, .25); pointer-events: none; animation: pop .25s ease-out;
}
.bubble::after { content: ''; position: absolute; left: var(--tail, 50%); bottom: -7px; width: 10px; height: 10px; margin-left: -5px; background: var(--bubble-bg); border-right: 2px solid #3a2a28; border-bottom: 2px solid #3a2a28; transform: rotate(45deg); }
.bubble.out { animation: fade .4s ease-in forwards; }
@keyframes pop { from { transform: scale(.6); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes fade { to { opacity: 0; transform: translateY(-4px); } }

/* 피드 */
.side-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.side-head h2 { font-family: var(--font-title); font-weight: 400; font-size: 22px; margin: 0; }
.count { color: var(--muted); font-size: 16px; }
.chip { border: 1px solid var(--line); background: var(--chip); border-radius: 999px; padding: 6px 12px; font-size: 14px; cursor: pointer; }
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; overflow: auto; }
.card { display: grid; grid-template-columns: 56px 1fr; gap: 10px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 10px; }
.card .ava { width: 56px; height: 56px; border-radius: 12px; background: #f1dcc0; overflow: hidden; display: flex; justify-content: center; align-items: flex-start; }
.card .ava img { width: 64px; height: 56px; image-rendering: pixelated; margin-top: 2px; }
.card .who { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 6px; }
.card .grp { font-weight: 400; color: var(--muted); font-size: 13px; }
.card ul { margin: 4px 0 0; padding: 0; list-style: none; }
.card li { font-size: 15px; line-height: 1.45; display: flex; gap: 6px; align-items: flex-start; }
.card li + li { margin-top: 2px; }
.del { margin-left: auto; border: 0; background: none; color: var(--accent); font-size: 13px; cursor: pointer; padding: 2px 4px; flex: none; }
.empty { color: var(--muted); text-align: center; padding: 24px 8px; }

/* 폰 하단 바: 한 손 조작 */
.bar { position: fixed; left: 0; right: 0; bottom: 0; z-index: 20; display: flex; gap: 10px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); background: color-mix(in srgb, var(--bg) 92%, transparent); border-top: 1px solid var(--line); backdrop-filter: blur(6px); }
.bar .btn { flex: 1; white-space: nowrap; font-size: 15px; padding: 0 10px; }
.bar .btn.primary { flex: 2; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 52px; padding: 0 18px; border-radius: 14px; border: 0; font-weight: 700; font-size: 17px; cursor: pointer; background: var(--chip); color: var(--text); text-align: center; }
.btn.primary { background: var(--accent); color: var(--accent-ink); font-family: var(--font-title); font-weight: 400; font-size: 20px; }
.btn.ghost { background: transparent; border: 1.5px solid var(--line); }
.btn.big { min-height: 60px; font-size: 18px; width: 100%; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn:focus-visible, .chip:focus-visible, .opt:focus-visible { outline: 3px solid var(--gold); outline-offset: 2px; }

/* 시트(팝업) */
.sheet { border: 0; padding: 0; width: 100%; max-width: 480px; max-height: 100dvh; background: var(--panel); color: var(--text); border-radius: 22px 22px 0 0; margin: auto auto 0; box-shadow: var(--shadow); }
.sheet::backdrop { background: rgba(30, 15, 10, .45); }
@media (min-width: 600px) { .sheet { border-radius: 22px; margin: auto; } }
.sheet form, .sheet.small { display: flex; flex-direction: column; }
.sheet form { max-height: 100dvh; }
.sheet.small { padding: 0 16px 16px; }
.sheet-head { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px; position: relative; flex-wrap: wrap; }
.sheet.small .sheet-head { padding: 14px 0 6px; }
.sheet-head h2 { font-family: var(--font-title); font-weight: 400; font-size: 24px; margin: 0; flex: 1; }
.x { width: 44px; height: 44px; border: 0; background: none; font-size: 28px; cursor: pointer; color: var(--muted); }
.steps { display: flex; gap: 6px; width: 100%; }
.steps i { flex: 1; height: 5px; border-radius: 3px; background: var(--line); }
.steps i.on { background: var(--accent); }
.step { padding: 4px 16px 8px; overflow: auto; }
.sheet-foot { display: flex; gap: 10px; padding: 10px 16px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
.sheet.small .sheet-foot { padding: 10px 0 0; border: 0; }
.sheet-foot .btn { flex: 1; }
.sheet-foot .btn.primary { flex: 2; }
.field { display: flex; flex-direction: column; gap: 6px; margin: 10px 0; border: 0; padding: 0; }
.field > span, .field legend { font-weight: 700; font-size: 16px; padding: 0; margin-bottom: 6px; }
.field small, .hint { color: var(--muted); font-size: 14px; margin: 6px 0; }
input:not([type]), textarea { width: 100%; border: 1.5px solid var(--line); border-radius: 12px; padding: 12px; font-size: 18px; background: var(--bg); resize: none; }
input:focus, textarea:focus { outline: 2px solid var(--accent); border-color: transparent; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.opt { border: 2px solid var(--line); background: var(--bg); border-radius: 14px; padding: 10px 8px; min-height: 56px; cursor: pointer; text-align: center; line-height: 1.3; }
.opt b { display: block; font-size: 16px; }
.opt small { color: var(--muted); font-size: 12px; }
.opt[aria-pressed="true"] { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, var(--bg)); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.photo-box { margin-top: 12px; display: flex; gap: 12px; align-items: center; }
.photo-box img { width: 84px; height: 84px; object-fit: cover; border-radius: 14px; flex: none; }
.consent { display: flex; gap: 8px; align-items: flex-start; font-size: 15px; }
.consent input { width: 22px; height: 22px; flex: none; margin-top: 2px; }
.err { color: var(--accent); margin: 0 16px; min-height: 0; font-size: 14px; }
.err:empty { display: none; }

.dress { display: flex; flex-direction: column; gap: 10px; }
.preview-box { position: relative; align-self: center; background: #d7a46c; border-radius: 16px; padding: 10px 26px; }
#preview { width: 96px; height: 144px; image-rendering: pixelated; display: block; }
.convert-state { position: absolute; left: 0; right: 0; bottom: -4px; text-align: center; font-size: 12px; background: var(--panel); border-radius: 8px; padding: 2px; }
.options { display: flex; flex-direction: column; gap: 10px; }
.orow { display: flex; flex-direction: column; gap: 4px; }
.orow > span { font-size: 14px; font-weight: 700; color: var(--muted); }
.ochoices { display: flex; gap: 6px; overflow-x: auto; padding: 2px 2px 4px; scrollbar-width: none; }
.ochoices .opt { flex: none; min-height: 44px; min-width: 44px; padding: 6px 10px; font-size: 15px; }
.ochoices .sw { width: 44px; padding: 0; border-width: 3px; }
.examples { display: flex; flex-wrap: wrap; gap: 6px; }
.examples button { border: 1px solid var(--line); background: var(--chip); border-radius: 999px; padding: 8px 12px; font-size: 15px; cursor: pointer; }
.mine-msgs { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.mine-msgs li { display: flex; gap: 6px; background: var(--bg); border-radius: 10px; padding: 8px 10px; font-size: 15px; }

@media (prefers-reduced-motion: reduce) {
  .actor { transition: none; }
  .actor .body { animation: none; }
  .bubble, .bubble.out { animation: none; }
}

.qr-card { display: none; }
.bar .btn.qr-btn { flex: 0 0 52px; padding: 0; font-family: var(--font-title); }
.qr-big { padding: 8px 0 4px; }
.qr-big svg, .qr-img svg { display: block; width: 100%; height: auto; background: #fff; border-radius: 10px; }
.qr-big svg { max-width: 300px; margin: 0 auto; }

@media (min-width: 900px) {
  .qr-card { display: flex; align-items: center; gap: 12px; margin-top: 12px; padding: 10px; border: 1px solid var(--line); border-radius: 14px; background: none; color: var(--text); font: inherit; text-align: left; cursor: zoom-in; }
  .qr-card .qr-img { flex: 0 0 120px; }
  .qr-card .qr-text { display: flex; flex-direction: column; gap: 4px; }
  .qr-card b { font-family: var(--font-title); font-weight: 400; font-size: 20px; }
  .qr-card small { color: var(--muted); font-size: 13px; line-height: 1.4; }
  .bar .btn.qr-btn { display: none; }
  .bar { position: static; padding: 12px 0 0; background: none; border: 0; backdrop-filter: none; }
  .app { padding-bottom: 16px; }
}
