:root {
  --bg: #f4efe6;
  --ink: #2f2a24;
  --sub: #7a7166;
  --line: #e2d9cb;
  --accent: #b5562b;
  --accent-ink: #fff;
  --card: rgba(255, 252, 246, 0.94);
  --glass: rgba(255, 252, 246, 0.82);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden;
  background: var(--bg); color: var(--ink);
  font-family: 'Noto Sans KR', system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button { font: inherit; color: inherit; cursor: pointer; }
[hidden] { display: none !important; }

#world { position: fixed; inset: 0; }
#world canvas { display: block; touch-action: none; }

/* ── 입장 화면 ── */
#lobby {
  position: fixed; inset: 0; z-index: 10;
  overflow-y: auto; padding: 24px 16px 40px;
  display: grid; justify-items: center; align-content: start; gap: 16px;
  background:
    radial-gradient(ellipse at 20% 0%, #fde6c8 0%, transparent 55%),
    radial-gradient(ellipse at 100% 100%, #dfe9dc 0%, transparent 55%),
    var(--bg);
}
.card {
  width: 100%; max-width: 440px;
  background: var(--card); border: 1px solid var(--line);
  border-radius: 22px; padding: 28px 22px 22px;
  box-shadow: 0 20px 50px -24px rgba(80, 55, 25, 0.35);
}
.eyebrow { margin: 0; font-size: 13px; letter-spacing: .12em; color: var(--accent); font-weight: 700; }
h1 { margin: 4px 0 6px; font-family: 'Gowun Batang', serif; font-size: 38px; letter-spacing: .04em; }
.lead { margin: 0 0 20px; color: var(--sub); font-size: 14.5px; line-height: 1.6; }

.field { display: block; margin-bottom: 16px; }
.field > span { display: flex; justify-content: space-between; font-size: 14px; font-weight: 700; margin-bottom: 7px; }
.field em { font-style: normal; font-weight: 400; color: var(--sub); font-size: 12.5px; }
.field input {
  width: 100%; padding: 13px 14px; font-size: 16px;
  border: 1px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(181, 86, 43, .15); }

.colors { display: flex; gap: 10px; flex-wrap: wrap; }
.colors button {
  width: 34px; height: 34px; border-radius: 50%; border: 3px solid #fff;
  box-shadow: 0 0 0 1px var(--line); padding: 0;
}
.colors button[aria-pressed="true"] { box-shadow: 0 0 0 2px var(--ink); }

.places { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.places button {
  text-align: left; padding: 12px 12px 11px; border-radius: 14px;
  border: 1px solid var(--line); background: #fff;
  display: grid; grid-template-columns: auto 1fr; column-gap: 10px; align-items: center;
  transition: border-color .15s, background .15s;
}
.places button i { font-style: normal; font-size: 24px; grid-row: span 2; }
.places button b { font-size: 15.5px; }
.places button small { color: var(--sub); font-size: 12px; }
.places button[aria-pressed="true"] { border-color: var(--accent); background: #fff6ef; box-shadow: 0 0 0 1px var(--accent); }

.preview { display: flex; justify-content: center; padding: 6px 0 14px; }
.preview .tag { transform: none; }

.primary {
  width: 100%; padding: 15px; border: 0; border-radius: 14px;
  background: var(--accent); color: var(--accent-ink); font-size: 17px; font-weight: 700;
}
.primary:disabled { opacity: .4; cursor: default; }
.hint { text-align: center; margin: 12px 0 0; font-size: 13.5px; color: var(--sub); }
.hint b { color: var(--accent); }
.fine { text-align: center; margin: 8px 0 0; font-size: 11.5px; color: #a39a8d; }

/* ── 머리 위 이름표·소원 말풍선 ── */
.tag {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  pointer-events: none; user-select: none;
  transform: translateY(-50%);
}
.tag .wish {
  max-width: 170px; padding: 6px 11px; border-radius: 13px;
  background: rgba(255, 253, 248, .95); color: #3b332b;
  font-size: 12.5px; line-height: 1.35; text-align: center; word-break: keep-all; overflow-wrap: anywhere;
  box-shadow: 0 4px 12px -4px rgba(0, 0, 0, .3);
  position: relative;
}
.tag .wish::after {
  content: ''; position: absolute; left: 50%; bottom: -5px; margin-left: -5px;
  border: 5px solid transparent; border-bottom: 0; border-top-color: rgba(255, 253, 248, .95);
}
.tag .name {
  margin-top: 3px; padding: 2px 8px; border-radius: 8px;
  background: rgba(40, 33, 27, .62); color: #fff; font-size: 11.5px; font-weight: 700;
}
.tag.me .name { background: var(--accent); }
.tag.me .wish { box-shadow: 0 0 0 2px rgba(181, 86, 43, .55), 0 4px 12px -4px rgba(0, 0, 0, .3); }
.tag.far .wish { display: none; }

/* ── 들어간 뒤 화면 ── */
#hud { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#hud .top {
  position: absolute; top: max(12px, env(safe-area-inset-top)); left: 12px; right: 12px;
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
}
.pill {
  pointer-events: auto; border: 1px solid var(--line); background: var(--glass);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  border-radius: 999px; padding: 9px 14px; font-size: 13.5px;
}
.pill.info { display: flex; gap: 10px; align-items: center; pointer-events: none; }
.pill.info span { color: var(--sub); }
.guide {
  position: absolute; left: 0; right: 0; top: 64px; margin: 0; text-align: center;
  font-size: 12.5px; color: #fff; text-shadow: 0 1px 4px rgba(0, 0, 0, .55);
  transition: opacity 1s;
}
.actions {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: max(16px, env(safe-area-inset-bottom));
  display: flex; gap: 6px; padding: 7px; border-radius: 22px;
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  pointer-events: auto;
}
.actions button {
  min-width: 66px; padding: 8px 7px 7px; border: 0; border-radius: 16px; background: transparent;
  display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 13px; font-weight: 500;
  white-space: nowrap;
}
.actions button i { font-style: normal; font-size: 22px; line-height: 1.1; }
.actions button:hover { background: rgba(0, 0, 0, .05); }
.actions button:active { transform: scale(.95); }

#toast {
  position: fixed; z-index: 20; left: 50%; top: 22%; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 11px 18px; border-radius: 12px;
  background: rgba(40, 33, 27, .9); color: #fff; font-size: 14px; text-align: center;
}

@media (max-width: 380px) {
  .actions button { min-width: 0; padding: 8px 5px 7px; font-size: 12px; }
  .actions { gap: 2px; padding: 5px; }
  h1 { font-size: 32px; }
}

/* ── 공유 링크로 들어온 소원 ── */
.card.shared { text-align: center; border-color: #ecc9b1; background: linear-gradient(180deg, #fff8f1, var(--card)); }
.card.shared .big { font-family: 'Gowun Batang', serif; font-size: 26px; line-height: 1.45; margin: 10px 0 6px; word-break: keep-all; }
.card.shared .who { margin: 0 0 16px; color: var(--sub); }

/* ── 같이 빌어주기 버튼 공통 ── */
.cheer.done { background: #fdeee4; color: var(--accent); }
.primary.cheer.done { background: #f3d9c8; color: var(--accent); }

/* ── 소원 벽 ── */
.card.wall { padding-bottom: 12px; }
.wallHead { display: flex; justify-content: space-between; align-items: flex-end; gap: 10px; margin-bottom: 10px; }
.wallHead h2 { margin: 0; font-family: 'Gowun Batang', serif; font-size: 24px; }
.sub { margin: 4px 0 0; color: var(--sub); font-size: 13px; }
.tabs { display: flex; background: #efe8dc; border-radius: 10px; padding: 3px; flex-shrink: 0; }
.tabs button { border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; font-size: 13px; color: var(--sub); }
.tabs button[aria-pressed="true"] { background: #fff; color: var(--ink); font-weight: 700; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.wallList { list-style: none; margin: 0; padding: 0; }
.wallList li { display: flex; align-items: center; gap: 8px; padding: 12px 2px; border-top: 1px solid var(--line); }
.wallList li:first-child { border-top: 0; }
.wallList li.mine .wtext p { color: var(--accent); }
.wallList li.empty { justify-content: center; color: var(--sub); font-size: 14px; padding: 22px 0; }
.wtext { flex: 1; min-width: 0; }
.wtext p { margin: 0; font-size: 15px; line-height: 1.45; word-break: keep-all; overflow-wrap: anywhere; }
.wtext small { color: var(--sub); font-size: 12px; }
.wallList .cheer {
  flex-shrink: 0; border: 1px solid var(--line); background: #fff; border-radius: 999px;
  padding: 7px 11px; font-size: 13.5px; font-weight: 700;
}
.wallList .cheer:disabled { opacity: .55; cursor: default; }
.wallList .report { flex-shrink: 0; border: 0; background: none; color: #b7ad9f; font-size: 18px; padding: 4px 2px; }

/* ── 머리 위 말풍선: 응원 수·누르기 ── */
.tag button.wish { pointer-events: auto; border: 0; font-family: inherit; font-size: 12.5px; line-height: 1.35; color: #3b332b; cursor: pointer; }
.tag button.wish:hover { background: #fff; }
.tag button.wish:active { transform: scale(.96); }
.tag .wish .cnt { display: block; margin-top: 2px; font-size: 11px; color: var(--accent); font-weight: 700; }
.tag .wish .cnt i { font-style: normal; font-weight: 500; margin-left: 5px; color: var(--sub); }
.tag button.wish.done .cnt i { display: none; }
.tag { position: relative; }
.tag .float {
  position: absolute; left: 50%; top: -6px; transform: translateX(-50%);
  font-size: 15px; font-weight: 700; color: var(--accent); text-shadow: 0 1px 3px #fff;
  animation: floatUp 1.6s ease-out forwards; white-space: nowrap;
}
@keyframes floatUp { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -44px); } }

/* ── 들어간 뒤: 내 소원·공유 ── */
#hud .top .share { margin-left: auto; display: flex; align-items: center; gap: 8px; padding: 5px 5px 5px 13px; }
#hud .top .share .mine { color: var(--sub); }
#hud .top .share .mine b { color: var(--ink); }
#hud .top .share .go { background: var(--accent); color: #fff; border-radius: 999px; padding: 5px 12px; font-weight: 700; }
@media (max-width: 480px) {
  #hud .top .share .mine { display: none; }
  #hud .top .share { padding: 5px; }
}

/* ── 공유 창 ── */
.modal { position: fixed; inset: 0; z-index: 30; background: rgba(30, 24, 18, .55); display: grid; place-items: center; padding: 16px; }
.sheet { width: 100%; max-width: 420px; max-height: calc(100vh - 32px); overflow-y: auto; background: var(--card); border-radius: 20px; padding: 16px; }
.sheetHead { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; font-size: 16px; }
.sheetHead .x { border: 0; background: none; font-size: 18px; color: var(--sub); padding: 4px 8px; }
.cardBox { position: relative; aspect-ratio: 4 / 5; border-radius: 14px; overflow: hidden; background: #ece4d6; display: grid; place-items: center; }
.cardBox img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cardBox img:not([src]) { display: none; }
#cardWait { color: var(--sub); font-size: 14px; }
.sheet .sub { text-align: center; margin: 12px 0; }
.sheetBtns { display: grid; grid-template-columns: 1.4fr 1fr; gap: 8px; }
.sheetBtns .primary { padding: 13px; font-size: 15.5px; }
.ghost { border: 1px solid var(--line); background: #fff; border-radius: 14px; padding: 13px; font-weight: 700; font-size: 15.5px; }

/* 지금 앉아 있거나 누워 있으면 그 버튼을 눌린 모양으로 */
.actions button.on { background: #fdeee4; color: var(--accent); font-weight: 700; }

/* 머리 모양 고르기 */
.hairs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.hairs button { padding: 9px 4px; border-radius: 10px; border: 1px solid var(--line); background: #fff; font-size: 13px; }
.hairs button[aria-pressed="true"] { border-color: var(--accent); background: #fff6ef; color: var(--accent); font-weight: 700; box-shadow: 0 0 0 1px var(--accent); }

/* ── 소리 버튼 ── */
/* 소리 버튼은 오른쪽 아래 💬 위에 */
#soundBtn {
  position: absolute; right: 14px; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 134px);
  width: 48px; height: 48px; padding: 0; border-radius: 50%; font-size: 20px; line-height: 1;
  box-shadow: 0 4px 14px -6px rgba(0,0,0,.3);
}

/* ── 함께 기도 시간 ── */
.together-hint b { color: var(--accent); }
.togetherBar {
  position: absolute; left: 50%; transform: translateX(-50%); top: 64px;
  width: max-content; max-width: calc(100% - 24px);
  display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 14px; border-radius: 16px;
  background: rgba(255, 246, 228, .94); border: 1px solid #f0d3a6; box-shadow: 0 6px 18px -8px rgba(120, 70, 20, .45);
  font-size: 13.5px; pointer-events: auto;
}
.togetherBar.soon { background: var(--glass); border-color: var(--line); box-shadow: none; padding: 7px 14px; }
.togetherBar b { color: var(--accent); }
.togetherBar button { border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 700; padding: 7px 12px; font-size: 13px; white-space: nowrap; }
.togetherBar.active { animation: glowPulse 2.4s ease-in-out infinite; }
@keyframes glowPulse { 50% { box-shadow: 0 0 0 4px rgba(242, 196, 107, .35), 0 6px 18px -8px rgba(120, 70, 20, .45); } }
#hud .togetherBar:not([hidden]) ~ .guide { opacity: 0 !important; }

/* ── 응원 문구 ── */
.sayBtn {
  position: absolute; right: 14px; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 78px);
  width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--glass); backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  font-size: 22px; pointer-events: auto; box-shadow: 0 4px 14px -6px rgba(0,0,0,.3);
}
.sayMenu {
  position: absolute; right: 70px; bottom: calc(max(16px, env(safe-area-inset-bottom)) + 78px);
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px; padding: 8px; border-radius: 16px;
  background: var(--card); border: 1px solid var(--line); box-shadow: 0 10px 30px -12px rgba(0,0,0,.35);
  pointer-events: auto; width: 248px;
}
.sayMenu button { border: 1px solid var(--line); background: #fff; border-radius: 11px; padding: 9px 6px; font-size: 13.5px; white-space: nowrap; }
.sayMenu button:active { background: #fff6ef; }
/* 머리 위 응원 말풍선 */
.tag .say {
  position: absolute; left: 50%; bottom: 100%; transform: translate(-50%, -6px);
  padding: 6px 12px; border-radius: 14px; white-space: nowrap;
  background: var(--accent); color: #fff; font-size: 13px; font-weight: 700;
  box-shadow: 0 4px 12px -4px rgba(0,0,0,.35);
  animation: sayPop 3.4s ease forwards;
}
@keyframes sayPop {
  0% { opacity: 0; transform: translate(-50%, 4px) scale(.8); }
  10%, 85% { opacity: 1; transform: translate(-50%, -6px) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -14px) scale(1); }
}

/* 소개 글 */
.card.about h2 { margin: 0 0 8px; font-family: 'Gowun Batang', serif; font-size: 20px; }
.card.about p { margin: 0 0 8px; color: var(--sub); font-size: 13.5px; line-height: 1.65; word-break: keep-all; }
.card.about p:last-child { margin-bottom: 0; }
.card.about b { color: var(--ink); font-weight: 700; }
