:root {
  --glass: rgba(28, 26, 24, 0.55);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f6f1e7;
  --dim: rgba(246, 241, 231, 0.62);
  --gold: #e9c46a;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #14110f; color: var(--text); touch-action: none; overscroll-behavior: none;
  font-family: Pretendard, -apple-system, 'Apple SD Gothic Neo', 'Noto Sans KR', sans-serif; user-select: none; -webkit-user-select: none; }
input, textarea { font-size: 16px; touch-action: manipulation; } /* <16px makes iOS Safari zoom the page on focus */
.scroll { touch-action: pan-y; -webkit-overflow-scrolling: touch; }
canvas#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; -webkit-touch-callout: none; outline: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; touch-action: manipulation; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
svg.gold { color: var(--gold); }
[hidden] { display: none !important; }

.pill { background: var(--glass); border: 1px solid var(--line); border-radius: 999px; backdrop-filter: blur(14px) saturate(1.2); -webkit-backdrop-filter: blur(14px) saturate(1.2);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); }
.round { width: 52px; height: 52px; display: grid; place-items: center; }

.tl { position: fixed; top: 16px; left: calc(16px + var(--safe-l)); display: flex; gap: 10px; z-index: 5; }
#btnChannel { display: flex; align-items: center; gap: 10px; height: 52px; padding: 0 18px; }
#btnChannel b { font-size: 19px; letter-spacing: 0.02em; }
#btnChannel .sep { width: 1px; height: 16px; background: var(--line); }
#btnChannel #chLabel { color: var(--dim); font-size: 14px; }
.chev { width: 16px; height: 16px; opacity: 0.6; }

.tr { position: fixed; top: 16px; right: calc(16px + var(--safe-r)); z-index: 5; display: flex; flex-direction: column; align-items: flex-end; gap: 10px; }
.bar { display: flex; align-items: center; gap: 2px; height: 52px; padding: 0 8px; }
.bar > * { height: 40px; min-width: 44px; display: grid; place-items: center; border-radius: 999px; }
.bar button:hover { background: rgba(255, 255, 255, 0.08); }
.online { display: flex !important; gap: 6px; padding: 0 10px; font-weight: 700; }
#btnSound .wave { display: none; }
#btnSound.on .wave { display: inline; }
#btnSound.on .x { display: none; }
.swatch-now { width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.85); }

.pop { background: rgba(28, 26, 24, 0.82); border: 1px solid var(--line); border-radius: 18px; padding: 14px; backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); min-width: 220px; }
.pop-title { font-size: 13px; color: var(--dim); margin: 2px 2px 10px; display: flex; justify-content: space-between; gap: 12px; }
.pop-title + .seg { margin-bottom: 12px; }
.seg { display: flex; gap: 4px; background: rgba(255, 255, 255, 0.06); border-radius: 12px; padding: 4px; }
.seg button { flex: 1; padding: 7px 10px; border-radius: 9px; font-size: 13px; white-space: nowrap; }
.seg button.on { background: rgba(233, 196, 106, 0.22); color: var(--gold); }
/* sound settings */
.sndpop { width: 264px; max-height: calc(100vh - 90px); overflow-y: auto; }
.snd-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 14px; min-height: 36px; cursor: pointer; }
.snd-row small { display: block; font-size: 11.5px; color: var(--dim); margin-top: 1px; }
.snd-row.head { font-size: 13px; color: var(--dim); border-bottom: 1px solid var(--line); padding-bottom: 8px; margin-bottom: 6px; }
.sndpop.muted .snd-row:not(.head), .sndpop input:disabled, .sndpop select:disabled { opacity: 0.45; }
input.sw { appearance: none; -webkit-appearance: none; width: 42px; height: 24px; border-radius: 12px; background: rgba(255, 255, 255, 0.18); position: relative; flex: none; margin: 0; cursor: pointer; transition: background 0.2s; }
input.sw::after { content: ''; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #f6f1e7; transition: transform 0.2s; }
input.sw:checked { background: rgba(233, 196, 106, 0.85); }
input.sw:checked::after { transform: translateX(18px); }
.sndpop input[type='range'] { width: 100%; margin: 2px 0 10px; accent-color: var(--gold); height: 28px; touch-action: none; }
.sndpop select { width: 100%; font: inherit; font-size: 16px; color: var(--text); background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; margin-top: 2px; }
.sndpop select option { color: #14110f; }
.snd-note { font-size: 11.5px; color: var(--dim); margin: 8px 2px 0; line-height: 1.45; }
.swatches { display: grid; grid-template-columns: repeat(5, 36px); gap: 10px; }
.swatches button { width: 36px; height: 36px; border-radius: 50%; border: 2px solid transparent; box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.2); position: relative; }
.swatches button.on { border-color: #fff; transform: scale(1.06); }
.swatches button span { position: absolute; top: 40px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--dim); white-space: nowrap; }
.chpop { position: fixed; top: 78px; left: 78px; z-index: 6; width: 280px; max-height: 60vh; overflow: auto; }
#chList { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
#chList button { width: 100%; display: flex; justify-content: space-between; padding: 9px 12px; border-radius: 10px; font-size: 14px; }
#chList button:hover { background: rgba(255, 255, 255, 0.07); }
#chList button.on { color: var(--gold); background: rgba(233, 196, 106, 0.12); }
#chList .full { color: #e98a7a; text-align: right; }
#chList .full small { display: block; font-size: 11px; opacity: 0.85; }

.drawer { position: fixed; top: 0; bottom: 0; left: 0; width: 290px; z-index: 8; background: rgba(22, 20, 18, 0.9); border-right: 1px solid var(--line);
  backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px); padding: 20px 16px; animation: slide 0.25s ease; }
@keyframes slide { from { transform: translateX(-100%); } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; font-size: 18px; margin-bottom: 14px; }
.x-btn { width: 36px; height: 36px; border-radius: 50%; }
#templeList { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
#templeList button { width: 100%; text-align: left; padding: 14px; border-radius: 14px; border: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
#templeList button.on { border-color: rgba(233, 196, 106, 0.6); background: rgba(233, 196, 106, 0.1); }
#templeList button:disabled { opacity: 0.45; cursor: default; }
#templeList small { display: block; color: var(--dim); margin-top: 3px; font-size: 12px; }
#templeList em { font-style: normal; font-size: 12px; color: var(--dim); }
.drawer-foot { color: var(--dim); font-size: 13px; margin-top: 18px; }

#toasts { position: fixed; top: 84px; left: 50%; transform: translateX(-50%); z-index: 4; display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { background: var(--glass); border: 1px solid var(--line); padding: 11px 22px; border-radius: 999px; font-size: 15px; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  animation: toast 4s ease forwards; white-space: nowrap; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 8%, 85% { opacity: 1; transform: none; } 100% { opacity: 0; } }
.hint { position: fixed; bottom: calc(190px + var(--safe-b)); left: 50%; transform: translateX(-50%); font-size: 14px; color: var(--text); text-shadow: 0 1px 6px #000; pointer-events: none; z-index: 3; opacity: 0; transition: opacity 0.3s; }
.hint.show { opacity: 1; }

.bottom { position: fixed; left: 50%; bottom: calc(18px + var(--safe-b)); transform: translateX(-50%); z-index: 5; display: flex; flex-direction: column; align-items: center; gap: 10px; width: min(560px, calc(100vw - 24px)); pointer-events: none; }
.bottom > * { pointer-events: auto; } /* the gap around the bars lets touches through to the canvas */
.chat { display: flex; width: 100%; height: 46px; padding: 4px 4px 4px 18px; }
.chat input { flex: 1; min-width: 0; background: none; border: 0; outline: 0; color: var(--text); font: inherit; font-size: 16px; user-select: text; -webkit-user-select: text; }
.chat input::placeholder { color: var(--dim); }
.chat button { padding: 0 18px; border-radius: 999px; background: rgba(233, 196, 106, 0.18); color: var(--gold); font-weight: 600; white-space: nowrap; }
.chat button:disabled { color: var(--dim); background: rgba(255, 255, 255, 0.06); }
/* 대화 끄기 toggle: a speech-bubble icon at the left of the chat bar; off -> bubbles hidden and the bar shrinks to the icon */
.chat { padding-left: 4px; }
.chat .chat-toggle { flex: none; width: 38px; padding: 0; display: grid; place-items: center; background: none; color: var(--dim); }
.chat .chat-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linejoin: round; stroke-linecap: round; }
.chat .chat-toggle .x { display: none; }
.chat .chat-toggle:hover { color: var(--text); }
body.chat-off .chat { width: auto; padding: 4px; }
body.chat-off .chat input, body.chat-off #chatSend { display: none; }
body.chat-off .chat .chat-toggle .x { display: inline; }
.actions { display: flex; padding: 8px 14px; gap: 2px; }
.actions button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 6px 12px; border-radius: 14px; font-size: 13px; min-width: 64px; }
.actions button:hover, .actions button.on { background: rgba(255, 255, 255, 0.08); }
.actions button.on { color: var(--gold); }
/* the chat bar stays hidden until 채팅 (or Enter) opens it above the action buttons; it closes after sending */
.bottom .chat { display: none; }
.chat-open .bottom .chat { display: flex; }
.touch.chat-open .joy { display: none; } /* typing: the open chat bar sits where the joystick rests */

/* virtual joystick: always visible bottom-left on touch devices, clear of the bottom bars and the safe area */
.joy { display: none; position: fixed; left: calc(26px + var(--safe-l)); bottom: calc(100px + var(--safe-b)); width: 140px; height: 140px; border-radius: 50%; background: rgba(28, 26, 24, 0.35); border: 1.5px solid rgba(255, 255, 255, 0.35); z-index: 4;
  touch-action: none; -webkit-touch-callout: none; opacity: 0.75; transition: opacity 0.15s, background 0.15s; box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25); }
.joy::before { content: ''; position: absolute; inset: 14px; border-radius: 50%; border: 1px dashed rgba(255, 255, 255, 0.22); }
.joy-knob { position: absolute; left: 40px; top: 40px; width: 60px; height: 60px; border-radius: 50%; background: rgba(255, 255, 255, 0.55); box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3), inset 0 0 0 2px rgba(255, 255, 255, 0.5); pointer-events: none; }
.touch .joy { display: block; }
.joy.on { opacity: 1; background: rgba(28, 26, 24, 0.5); }
.joy.on .joy-knob { background: rgba(233, 196, 106, 0.85); }
.touch-hint { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 7; width: min(320px, calc(100vw - 48px)); padding: 18px 20px 16px; border-radius: 18px; text-align: center;
  background: rgba(28, 26, 24, 0.86); border: 1px solid var(--line); box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45); animation: hintin 0.4s ease; }
@keyframes hintin { from { opacity: 0; transform: translate(-50%, -46%); } }
.touch-hint p { margin: 0 0 14px; font-size: 16px; line-height: 1.6; }
.touch-hint button { height: 42px; padding: 0 22px; border-radius: 12px; background: linear-gradient(180deg, #edc979, #c99a45); color: #2a1d0b; font-weight: 700; }
.touch .pill, .touch .pop, .touch .toast, .touch .drawer { backdrop-filter: none; -webkit-backdrop-filter: none; } /* blur over WebGL is a frame-rate killer on phones */
.touch .pill, .touch .toast { background: rgba(28, 26, 24, 0.74); }

.overlay { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; overflow: auto; padding: 16px 0; background: rgba(10, 8, 6, 0.45); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.card { margin: auto; flex: none; width: min(420px, calc(100vw - 32px)); background: rgba(30, 27, 24, 0.9); border: 1px solid var(--line); border-radius: 24px; padding: 28px; box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5); }
.card h1 { margin: 6px 0 4px; font-size: 28px; text-align: center; letter-spacing: 0.04em; }
.card h2 { margin: 0 0 6px; font-size: 22px; }
.logo { text-align: center; font-size: 30px; color: var(--gold); }
.sub { color: var(--dim); font-size: 14px; line-height: 1.6; text-align: center; margin: 0 0 18px; }
.card h2 + .sub { text-align: left; }
.card label { display: block; font-size: 13px; color: var(--dim); margin: 14px 0 8px; }
.card input { width: 100%; height: 46px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06); color: var(--text); padding: 0 14px; font: inherit; font-size: 16px; outline: 0; user-select: text; -webkit-user-select: text; }
.card input:focus { border-color: rgba(233, 196, 106, 0.6); }
.card .swatches { margin: 4px 0 26px; grid-template-columns: repeat(5, 1fr); justify-items: center; }
#lanternSwatches { margin-top: 14px; grid-template-columns: repeat(8, 1fr); }
.row { display: flex; gap: 8px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 8px; }
.primary, .ghost { height: 46px; padding: 0 20px; border-radius: 12px; font-weight: 600; display: inline-grid; place-items: center; text-decoration: none; }
.primary { background: linear-gradient(180deg, #edc979, #c99a45); color: #2a1d0b; }
.primary:disabled { opacity: 0.5; }
#enter { width: 100%; margin-top: 4px; font-size: 17px; }
.ghost { border: 1px solid var(--line); color: var(--text); }
.keys { color: var(--dim); font-size: 12px; text-align: center; margin: 14px 0 0; line-height: 1.6; }
.touch .keys { display: none; }
.card.photo { width: min(860px, calc(100vw - 24px)); padding: 14px; }
.card.photo img { width: 100%; border-radius: 14px; display: block; }
.flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 19; }
.flash.go { animation: flash 0.45s ease; }
@keyframes flash { 0% { opacity: 0.85; } 100% { opacity: 0; } }
.wishpop { position: fixed; z-index: 6; padding: 10px 16px; font-size: 14px; transform: translate(-50%, -120%); pointer-events: none; max-width: 280px; text-align: center; }
.loading { position: fixed; inset: 0; display: grid; place-items: center; background: #14110f; z-index: 30; color: var(--dim); font-size: 15px; letter-spacing: 0.05em; transition: opacity 0.6s; text-align: center; line-height: 1.7; padding: 24px; }
.loading small { font-size: 12px; opacity: 0.8; }
.loading button { margin-top: 6px; padding: 10px 18px; border-radius: 10px; background: rgba(233, 196, 106, 0.2); color: var(--gold); font-weight: 600; }
.loading.done { opacity: 0; pointer-events: none; }

@media (max-width: 640px) {
  .tl { top: 10px; left: 10px; gap: 6px; }
  .tr { top: 10px; right: 10px; }
  .round, #btnChannel, .bar { height: 44px; }
  .round { width: 44px; }
  #btnChannel { padding: 0 12px; gap: 6px; }
  #btnChannel b { font-size: 16px; }
  #btnChannel .sep, #btnChannel #chLabel { display: none; }
  .bar { padding: 0 4px; }
  .bar > * { min-width: 36px; height: 36px; }
  .online { padding: 0 6px; }
  .actions { padding: 6px 6px; }
  .actions button { min-width: 48px; padding: 6px 6px; font-size: 11px; }
  .actions svg { width: 20px; height: 20px; }
  .chpop { left: 10px; top: 62px; }
  #toasts { top: 64px; }
  .toast { font-size: 13px; padding: 9px 16px; }
}

@media (max-width: 480px) {
  /* one row: [☰][서해사찰 ▾] ... [👥 🔊 🌙 ● 📷] */
  #btnChannel { padding: 0 10px; }
  #btnChannel .gold { display: none; }
  .bar { padding: 0 2px; }
  .bar > * { min-width: 34px; }
  .online { padding: 0 4px; }
}
@media (max-width: 380px) {
  #btnChannel .chev { display: none; }
  .bar > * { min-width: 31px; }
}
@media (max-width: 340px) { /* very narrow (320px) phones: the bar goes back under the temple button */
  .tr { top: 62px; }
  #toasts { top: 116px; }
}

/* phones in landscape: compact bars so the scene and joystick keep room */
@media (max-height: 480px) {
  .tl, .tr { top: 8px; }
  .round, #btnChannel, .bar { height: 42px; }
  .round { width: 42px; }
  .bar > * { min-width: 36px; height: 34px; }
  .bottom { bottom: calc(6px + var(--safe-b)); gap: 6px; width: min(480px, calc(100vw - 260px)); }
  .chat { height: 40px; }
  .actions { padding: 4px 8px; }
  .actions button { padding: 4px 8px; font-size: 11px; gap: 2px; }
  .actions svg { width: 20px; height: 20px; }
  .hint { bottom: calc(128px + var(--safe-b)); }
  #toasts { top: 56px; }
  .joy { bottom: calc(110px + var(--safe-b)); left: calc(20px + var(--safe-l)); }
}
@media (max-height: 560px) {
  .card { padding: 16px 20px; }
  .logo { display: none; }
  .card h1 { font-size: 22px; margin: 0; }
  .sub { margin-bottom: 8px; }
  .card label { margin: 8px 0 6px; }
  .card .swatches { margin: 2px 0 14px; }
}

/* 돌탑 쌓기 (js/stones.js) */
.stonepop { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(150px + var(--safe-b)); z-index: 6; width: min(340px, calc(100vw - 24px)); }
.stonepop .pop-title { align-items: center; font-size: 14px; color: var(--text); }
.stonepop .pop-title b { color: var(--gold); font-weight: 600; }
.stonepop .x-btn { width: 30px; height: 30px; border-radius: 50%; color: var(--dim); }
.stone-sizes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.stone-sizes button { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px; height: 86px; padding: 10px 4px; border-radius: 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-size: 13px; }
.stone-sizes button:hover:not(:disabled) { border-color: rgba(233, 196, 106, 0.6); background: rgba(233, 196, 106, 0.1); }
.stone-sizes button:disabled { opacity: 0.4; cursor: default; }
.st { display: block; border-radius: 50% 46% 52% 48% / 58% 54% 46% 42%; background: radial-gradient(circle at 35% 30%, #b9b4aa, #6f6a62 70%); box-shadow: 0 3px 4px rgba(0, 0, 0, 0.35); }
.st0 { width: 46px; height: 21px; } .st1 { width: 34px; height: 16px; } .st2 { width: 24px; height: 12px; }
.stone-note { margin: 10px 2px 0; font-size: 12.5px; color: var(--dim); line-height: 1.5; }
@media (max-width: 640px) { .stonepop { bottom: calc(176px + var(--safe-b)); } }
.nick-edit { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.nick-edit .row { display: flex; gap: 8px; }
.nick-edit input { flex: 1; min-width: 0; width: 9em; font-size: 16px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3); color: inherit; }
.nick-edit button { min-height: 44px; padding: 0 14px; }
.nick-msg { margin: 8px 2px 0; font-size: 12px; color: var(--dim); min-height: 1em; }
.drawer-nick { width: 100%; margin-top: 12px; padding: 14px; min-height: 48px; border-radius: 14px; border: 1px solid var(--line); text-align: left; color: var(--gold); }
