:root {
  --paper: #f3efe6;
  --paper-2: #e9e2d3;
  --ink: #2b2620;
  --ink-2: #6b6255;
  --line: #d6ccb9;
  --temple-red: #8e2f22;
  --gold: #a9823f;
  --pine: #2f6a5c;
  --glass: rgba(28, 22, 16, 0.42);
  --glass-line: rgba(255, 244, 225, 0.22);
  --font-head: 'Gowun Batang', 'Nanum Myeongjo', serif;
  --font-body: 'Gowun Dodum', -apple-system, 'Apple SD Gothic Neo', sans-serif;
  --r-s: 8px;
  --r-m: 14px;
  --r-l: 22px;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --gutter: clamp(16px, 4vw, 40px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { overflow: hidden; overscroll-behavior: none; }   /* the page never scrolls; only the chat and sheets do */
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  overscroll-behavior: none;
}
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
body[data-view='select'] #scene { visibility: hidden; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
button { font: inherit; color: inherit; }
a { color: inherit; }

/* ---------- buttons ---------- */
.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; cursor: pointer; background: transparent;
  transition: transform 150ms var(--ease), background-color 150ms, opacity 150ms;
}
.btn:active { transform: scale(0.97); }
.btn:focus-visible, .space-card:focus-visible, .offer-card:focus-visible, .emo:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; }
.btn-primary { background: var(--temple-red); color: #fff7ec; box-shadow: 0 6px 18px rgba(142, 47, 34, 0.28); }
.btn-primary:hover { background: #a3392a; }
.btn-primary:disabled { opacity: 0.55; cursor: default; }
.btn-ghost { border: 1px solid var(--line); }
.btn-ghost:hover { background: var(--paper-2); }
.btn-text { padding: 8px 10px; color: var(--ink-2); }
.btn-text:hover { color: var(--ink); }
.btn-small { padding: 7px 14px; border: 1px solid var(--line); background: #fff; }
.btn-wide { width: 100%; padding: 14px; font-size: 17px; }
.btn-glass {
  background: var(--glass); color: #fff7ec; border: 1px solid var(--glass-line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
.btn-glass:hover { background: rgba(28, 22, 16, 0.58); }
.danger { color: var(--temple-red); }

/* ---------- select screen ---------- */
.select {
  position: absolute; inset: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding: 0 var(--gutter) 24px;
  display: grid; grid-template-rows: auto auto 1fr auto; gap: clamp(20px, 4vh, 44px);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(169, 130, 63, 0.16), transparent 60%),
    radial-gradient(900px 420px at -10% 110%, rgba(47, 106, 92, 0.12), transparent 60%),
    var(--paper);
}
.select-top { display: flex; justify-content: space-between; align-items: center; padding-top: max(14px, env(safe-area-inset-top)); }
.brand { font-family: var(--font-head); font-weight: 700; letter-spacing: 0.08em; }
.top-actions { display: flex; gap: 4px; }
.select-hero { max-width: 760px; }
.mark { margin: 0 0 6px; font-size: 26px; color: var(--gold); }
.select-hero h1 {
  margin: 0; font-family: var(--font-head); font-weight: 700;
  font-size: clamp(44px, 9vw, 96px); letter-spacing: 0.04em; line-height: 1;
}
.tagline { margin: 14px 0 0; color: var(--ink-2); font-size: clamp(15px, 2vw, 19px); line-height: 1.6; }
.spaces-title { margin: 0 0 14px; font-size: 14px; font-weight: 400; color: var(--ink-2); letter-spacing: 0.12em; }
.space-list { display: grid; grid-template-columns: 1.25fr 1fr; gap: clamp(12px, 2vw, 22px); align-items: end; }
.space-card {
  position: relative; display: flex; flex-direction: column; text-align: left; padding: 0; overflow: hidden;
  border: 1px solid var(--line); border-radius: var(--r-l); background: #fffdf8; cursor: pointer;
  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.03), 0 18px 40px -24px rgba(60, 40, 20, 0.35);
  transition: transform 300ms var(--ease), box-shadow 300ms var(--ease);
}
.space-card:hover { transform: translateY(-4px); box-shadow: 0 28px 50px -24px rgba(60, 40, 20, 0.45); }
.card-art { display: block; width: 100%; height: clamp(150px, 26vh, 260px); object-fit: cover; background: var(--paper-2); }
.space-buddha { min-height: 100%; }
.card-body { display: flex; flex-direction: column; gap: 6px; padding: 16px 18px 18px; }
.card-body strong { font-family: var(--font-head); font-size: 22px; }
.card-desc { color: var(--ink-2); font-size: 14px; line-height: 1.55; }
.card-state { font-size: 12px; color: var(--gold); min-height: 1em; }
.select-foot { display: flex; flex-direction: column; gap: 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); }
.pre { max-width: 420px; }
.pre-row { display: flex; justify-content: space-between; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; }
.pre-bar { height: 3px; background: var(--paper-2); border-radius: 3px; overflow: hidden; }
.pre-bar i { display: block; height: 100%; background: var(--gold); transform-origin: left; transform: scaleX(0); transition: transform 300ms var(--ease); }
.legal { margin: 0; font-size: 12px; color: var(--ink-2); }

/* ---------- in-space HUD ---------- */
.hud {
  position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) var(--gutter) 0; pointer-events: none;
}
.hud > * { pointer-events: auto; }
.visitors { color: #fff7ec; font-size: 13px; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); white-space: nowrap; }
body[data-view='buddha'] .visitors { color: var(--ink-2); text-shadow: none; }
body[data-view='buddha'] .back { background: rgba(255, 255, 255, 0.7); color: var(--ink); border-color: var(--line); }
.move-hint {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%); margin: 0; padding: 8px 14px;
  border-radius: 999px; background: var(--glass); color: #fff7ec; font-size: 13px; white-space: nowrap;
  max-width: calc(100% - 32px); overflow: hidden; text-overflow: ellipsis; pointer-events: none; transition: opacity 600ms;
}
.move-hint.fade { opacity: 0; }
.hall-actions {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  padding: 0 var(--gutter) max(16px, env(safe-area-inset-bottom)); pointer-events: none;
}
.hall-actions > * { pointer-events: auto; }
.hall-row { display: flex; gap: 8px; }
.emoji-bar { display: flex; gap: 6px; padding: 6px; border-radius: 999px; background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
.emo { display: grid; place-items: center; width: 44px; height: 44px; border: 1px solid rgba(255, 236, 200, 0.28); border-radius: 50%; background: rgba(255, 248, 232, 0.1); color: #f3dca6; cursor: pointer; transition: transform 150ms var(--ease), background-color 150ms, color 150ms; }
.emo:hover { background: rgba(255, 248, 232, 0.22); color: #fff3d2; transform: translateY(-2px); }
.emo:active { transform: scale(0.94); }
.self-emo { position: absolute; left: 50%; top: 38%; display: grid; place-items: center; width: 76px; height: 64px; border-radius: 32px; background: rgba(255, 251, 242, 0.95); color: #9a7432; box-shadow: 0 8px 24px rgba(0,0,0,0.25); transform: translate(-50%, 0); opacity: 0; pointer-events: none; }
.self-emo.pop { animation: pop 1.8s var(--ease); }
@keyframes pop { 0% { opacity: 0; transform: translate(-50%, 10px) scale(0.6); } 20% { opacity: 1; transform: translate(-50%, 0) scale(1); } 100% { opacity: 0; transform: translate(-50%, -40px) scale(1); } }


/* ---------- chat (부처님 앞) ---------- */
.chat {
  position: absolute; right: var(--gutter); top: 72px; bottom: max(16px, env(safe-area-inset-bottom));
  width: min(420px, calc(100% - 2 * var(--gutter)));
  display: flex; flex-direction: column; border-radius: var(--r-l);
  background: rgba(255, 253, 248, 0.86); border: 1px solid var(--line);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 30px 60px -30px rgba(60, 40, 20, 0.35);
}
.chat-meta { display: flex; flex-wrap: wrap; gap: 8px 14px; align-items: center; padding: 12px 18px 0; font-size: 12px; color: var(--ink-2); }
.chat-free { padding: 3px 10px; border-radius: 999px; background: var(--paper-2); }
.chat-burn { display: inline-flex; align-items: center; gap: 6px; color: var(--gold); }
.chat-burn .offering-art { width: 14px; height: 28px; }
.chat-log { position: relative; flex: 1; overflow-y: auto; padding: 14px 18px; display: flex; flex-direction: column; gap: 12px; }
.msg p { margin: 0; line-height: 1.7; white-space: pre-wrap; }
.msg-buddha { font-family: var(--font-head); font-size: 16px; }
.msg-me { align-self: flex-end; max-width: 85%; padding: 9px 14px; border-radius: 16px 16px 4px 16px; background: var(--ink); color: var(--paper); font-size: 15px; }
.msg-system { font-size: 13px; color: var(--temple-red); }
.msg-wait p { color: var(--ink-2); animation: breathe 1.6s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: 0.45; } }
.src-box { margin-top: 8px; font-family: var(--font-body); font-size: 13px; }
.src-box summary { cursor: pointer; color: var(--gold); }
.src-list { margin: 8px 0 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 10px; }
.src { padding: 10px 12px; border-left: 2px solid var(--gold); background: rgba(169, 130, 63, 0.07); border-radius: 0 var(--r-s) var(--r-s) 0; }
.src-head { display: flex; flex-wrap: wrap; gap: 6px; align-items: baseline; }
.src-n { color: var(--gold); }
.src-title { color: var(--ink-2); }
.src blockquote { margin: 6px 0; white-space: pre-wrap; line-height: 1.6; }
.src-foot { display: flex; gap: 10px; color: var(--ink-2); font-size: 12px; }
.chat-form { display: flex; gap: 8px; padding: 12px; border-top: 1px solid var(--line); }
.chat-input {
  flex: 1; resize: none; border: 1px solid var(--line); border-radius: 14px; padding: 10px 12px; background: #fff;
  font: 16px/1.5 var(--font-body); color: var(--ink); min-height: 44px; max-height: 120px;
}
.chat-input:focus { outline: 2px solid rgba(169, 130, 63, 0.5); border-color: var(--gold); }

/* ---------- sheets ---------- */
.sheet-wrap { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(30, 24, 18, 0.35); z-index: 10; }
.sheet {
  width: min(440px, 100%); max-height: calc(100% - 32px); overflow-y: auto; padding: 24px; border-radius: var(--r-l);
  background: var(--paper); border: 1px solid var(--line); display: flex; flex-direction: column; gap: 12px;
  box-shadow: 0 40px 80px -30px rgba(0, 0, 0, 0.45);
}
.sheet h2 { margin: 0; font-family: var(--font-head); font-size: 24px; }
.sheet h3 { margin: 8px 0 0; font-size: 13px; font-weight: 400; color: var(--ink-2); }
.sheet-lead { margin: 0; line-height: 1.65; color: var(--ink-2); }
.sheet-lead.small { font-size: 13px; }
.sheet-note { margin: 0; min-height: 1.2em; font-size: 13px; color: var(--temple-red); }
.row { display: flex; gap: 8px; align-items: center; }
.field { flex: 1; min-width: 0; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; font: 16px var(--font-body); background: #fff; }
.member-no { font-size: 17px; letter-spacing: 0.04em; }
.linked { margin: 0; color: var(--pine); font-size: 14px; }
.offer-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.offer-card {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 16px 10px; cursor: pointer;
  border: 1px solid var(--line); border-radius: var(--r-m); background: #fffdf8; transition: border-color 150ms, transform 150ms var(--ease);
}
.offer-card[aria-pressed='true'] { border-color: var(--gold); box-shadow: inset 0 0 0 1px var(--gold); background: #fff8ea; }
.offer-card:hover { transform: translateY(-2px); }
.offer-card .offering-art { width: 34px; height: 68px; }
.offer-card strong { font-family: var(--font-head); font-size: 19px; }
.offer-desc { font-size: 12px; color: var(--ink-2); text-align: center; }
.offer-meta { font-size: 13px; color: var(--gold); }
.art-bowl { fill: #8a6a3c; }
.art-stick { fill: #7a4a2a; }
.art-ember { fill: #e0602a; }
.art-smoke { fill: none; stroke: #b9b2a6; stroke-width: 1.2; opacity: 0.7; }
.art-wax { fill: #f1e7d2; stroke: #d9cbb0; }
.art-flame { fill: #f2a640; }

@media (max-width: 720px) {
  .space-list { grid-template-columns: 1fr; }
  .chat { left: 0; right: 0; width: 100%; top: auto; bottom: 0; height: 68%; border-radius: var(--r-l) var(--r-l) 0 0; padding-bottom: env(safe-area-inset-bottom); }
  .hall-actions { align-items: stretch; }
  .emoji-bar { justify-content: space-between; }
  .hall-row { justify-content: space-between; }
  .go-buddha { flex: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ---------- 11/09 additions: resizable chat, light HUD buttons ---------- */
.chat { position: absolute; }
.chat-grip { position: absolute; left: -7px; top: 24px; bottom: 24px; width: 14px; cursor: ew-resize; touch-action: none; z-index: 2; }
.chat-grip::after { content: ''; position: absolute; left: 5px; top: 50%; width: 4px; height: 44px; margin-top: -22px; border-radius: 4px; background: var(--line); transition: background-color 150ms; }
.chat-grip:hover::after { background: var(--gold); }
.hud-gap { flex: 1; }
.btn-light { background: rgba(255, 255, 255, 0.72); color: var(--ink); border-color: var(--line); }
.btn-light:hover { background: #fff; }
@media (max-width: 720px) {
  .chat-grip { left: 50%; right: auto; top: 0; bottom: auto; width: 96px; margin-left: -48px; height: 20px; cursor: ns-resize; }
  .chat-grip::after { left: 26px; top: 8px; width: 44px; height: 4px; margin: 0; }
  .chat-meta { padding-top: 18px; }
  .hall-row { flex-wrap: wrap; }
}
.chat-spacer { flex: none; }
.chat-rice { margin-left: auto; padding: 2px 8px; font-size: 12px; color: var(--gold); }
.burn-time { font-variant-numeric: tabular-nums; font-size: 12px; }
.rice-balance { margin: 0; font-family: var(--font-head); font-size: 18px; color: var(--gold); }
.rice-shop h3 { margin: 6px 0 8px; }
.rice-packs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.rice-pack { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 12px 6px; border: 1px solid var(--line); border-radius: var(--r-m); background: #fffdf8; cursor: pointer; transition: border-color 150ms, transform 150ms var(--ease); }
.rice-pack:hover { border-color: var(--gold); transform: translateY(-2px); }
.rice-pack strong { font-family: var(--font-head); font-size: 16px; }
.rice-pack span { font-size: 13px; color: var(--ink-2); }
.toast { position: absolute; left: 50%; top: 70px; transform: translateX(-50%); padding: 10px 16px; border-radius: 999px; background: var(--ink); color: var(--paper); font-size: 14px; z-index: 20; max-width: calc(100% - 32px); }
/* Mystic mood (owner 11/09): a warm grade and a soft vignette over the 3D view — cheap, so phones keep it too. */
@media (min-width: 720px) and (pointer: fine) { body.mood #scene { filter: saturate(1.06) sepia(0.08) contrast(1.03); } }
body.mood::after { content: ''; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 55%, rgba(40,22,8,0.32) 100%); }
body[data-view='buddha'].mood::after { background: radial-gradient(ellipse at 50% 45%, rgba(0,0,0,0) 62%, rgba(120,90,40,0.16) 100%); }
#ui { z-index: 1; }
.msg-past { opacity: 0.62; }
.msg-past-mark p { color: var(--ink-2); font-size: 12px; text-align: center; }

/* select cards: own progress, open when ready (owner tg 11903) */
.space-card[aria-disabled='true'] { cursor: progress; }
.space-card[aria-disabled='true']:hover { transform: none; }
.card-state { display: flex; flex-direction: column; gap: 6px; margin-top: 4px; }
.card-bar { display: block; height: 3px; border-radius: 3px; background: var(--paper-2); overflow: hidden; }
.card-bar i { display: block; height: 100%; background: var(--gold); transform-origin: left; transform: scaleX(0); transition: transform 300ms var(--ease); }
.space-card.is-ready .card-bar { display: none; }
.space-card.is-ready .card-state-text { color: var(--temple-red); font-weight: 700; }
.space-card.is-ready .card-state-text::after { content: ' ›'; }
/* Phone HUD: one row that fits 320–414 px (owner tg 11908 shots: labels wrapped one letter per line) */
.hud .btn { white-space: nowrap; }
@media (max-width: 720px) {
  .hud { gap: 5px; }
  .hud .btn { padding: 8px 9px; font-size: 13px; flex: none; }
  .hud .back-label { display: none; }
  .hud .hud-gap { display: none; }
  .hud .nav-btn { margin-right: auto; }
}
/* 큰절: the chat sheet / hall buttons step aside; 「일어나기」 and the bow count take their place (owner tg 11944) */
.chat, .hall-actions { transition: translate 450ms var(--ease), opacity 450ms var(--ease); }
body.bowing .chat { translate: calc(100% + 40px) 0; opacity: 0; pointer-events: none; }
body.bowing .hall-actions { opacity: 0; pointer-events: none; }
@media (max-width: 720px) { body.bowing .chat { translate: 0 calc(100% + 12px); } }
.rise-bar { position: absolute; left: 50%; bottom: max(28px, calc(env(safe-area-inset-bottom) + 16px)); translate: -50% 0;
  display: flex; flex-direction: column; align-items: center; gap: 10px; z-index: 6; }
.rise-bar[hidden] { display: none; }
.rise-btn { padding: 14px 34px; font-size: 17px; }
.bow-tally { margin: 0; padding: 5px 12px; border-radius: 999px; background: rgba(255, 253, 248, 0.82); color: var(--ink-2); font-size: 13px;
  font-variant-numeric: tabular-nums; box-shadow: 0 4px 14px -6px rgba(60, 40, 20, 0.35); }
.chat-account { padding: 2px 8px; font-size: 12px; color: var(--ink-2); }
.chat-account:hover { color: var(--ink); }
.rice-pack[hidden] { display: none; }
.verse-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 12px 0 4px; }
.verse-row label { display: flex; flex-direction: column; gap: 2px; }
.verse-row small { color: var(--ink-2); font-size: 12px; }
.verse-row input { width: 22px; height: 22px; accent-color: var(--temple-red); }
.nav-btn:disabled { opacity: 0.8; cursor: default; }
.hall-actions { transition: opacity 300ms var(--ease); }
@media (pointer: coarse) { .key-hint { display: none; } }
.key-hint { opacity: 0.7; font-size: 0.85em; }
.talk-actions { position: absolute; left: var(--gutter); bottom: max(16px, env(safe-area-inset-bottom)); display: flex; gap: 8px; align-items: center; z-index: 4; transition: opacity 300ms var(--ease); }
body.bowing .talk-actions { opacity: 0; pointer-events: none; }
.sound-ctl { display: inline-flex; align-items: center; gap: 4px; }
.sound-btn, .cam-btn { display: inline-flex; align-items: center; gap: 6px; }
.cam-btn svg { flex: none; }
.sound-btn svg { flex: none; }
@media (max-width: 720px) { .hud .nav-btn { margin-right: 0; } .hud .sound-ctl { margin-right: auto; } }
.sound-info { width: 22px; height: 22px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255,255,255,0.7); color: var(--ink-2); font: italic 600 12px/1 var(--font-head); cursor: pointer; }
.chant-credits { margin: 10px 0 6px; display: grid; gap: 2px; font-size: 11px; line-height: 1.45; color: var(--ink-2); }
.chant-credits span { padding: 3px 6px; border-radius: 8px; transition: background-color 200ms, color 200ms; }
.chant-credits span.on { background: #fff1d6; color: #9a3324; font-weight: 700; box-shadow: inset 3px 0 0 var(--gold); }
.chant-credits span.on::before { content: '♪ '; }
/* no dragging with the mouse (owner): no text / image selection or drag, except typing and the answers */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
img, svg, canvas { -webkit-user-drag: none; user-drag: none; }
input, textarea, .chat-log, .chat-log * { -webkit-user-select: text; user-select: text; }
@media (max-width: 720px) { .cam-btn span { display: none; } }
.hall-row .btn[hidden] { display: none; }
.lbl-short { display: none; }
@media (pointer: coarse), (max-width: 720px) { .lbl-long { display: none; } .lbl-short { display: inline; } }
.gift-note { position: fixed; left: 50%; top: 22%; translate: -50% 0; z-index: 20; padding: 10px 16px; border-radius: 999px; background: rgba(43, 38, 32, 0.86); color: #fff7ec; font-size: 14px; pointer-events: none; animation: gift-in 3.6s ease forwards; }
@keyframes gift-in { 0% { opacity: 0; transform: translateY(6px); } 10%, 80% { opacity: 1; transform: none; } 100% { opacity: 0; } }

/* ---------- 11/10 phone layout: top = room button with the counts under it | one sound pill; bottom = one bar of
   five (인사 · 절하기 · 향 · 목탁 · 염주). A PC keeps its rows (same actions). ---------- */
.hud, .hall-actions { z-index: 3; }
.hud-gap { pointer-events: none !important; }   /* an empty spacer: never in the way of a drag */
.hall-actions > [hidden] { display: none !important; }
.hall-situ { display: flex; gap: 8px; }
.bow-prog { display: none; }
.beads-dock { display: flex; flex-direction: column; gap: 10px; pointer-events: none !important; }
.beads-dock > * { pointer-events: auto; }
.hall-row .cell.on, .hall-row .greet-cell[aria-pressed='true'] {
  background: rgba(122, 74, 32, 0.66); color: #ffe7b8; box-shadow: inset 0 0 0 1px rgba(255, 226, 168, 0.55);
}
@media (min-width: 721px) {
  .hud-left, .hud-right { display: contents; }
  .hud .nav-btn { order: 1; }
  .hud .chant-snd { order: 2; }
  .hud .sound-info { order: 3; margin-left: -6px; }
  .hud .moktak-snd { order: 4; }
  .hud .visitors { order: 5; }
  .hud .hud-gap { order: 6; }
  .hud .cam-btn { order: 7; }
  .hall-actions {
    display: grid; grid-template-columns: 1fr auto auto; grid-template-areas: 'dock . emoji' 'dock situ row';
    align-items: end; column-gap: 8px; row-gap: 10px;
  }
  .beads-dock { grid-area: dock; justify-self: start; }
  .hall-situ { grid-area: situ; }
  .emoji-bar { grid-area: emoji; justify-self: end; }
  .hall-row { grid-area: row; }
  .hall-row .greet-cell { display: none; }
  .hall-row .bow-cell { order: 9; }
  .cell-ico { display: none; }
  body.bowing .hall-actions > * { pointer-events: none; }
}
@media (max-width: 720px) {
  .hud { align-items: flex-start; gap: 8px; }
  .hud-left { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; min-width: 0; }
  .hud-left .nav-btn { height: 44px; padding: 0 15px; font-size: 14px; margin: 0; }
  .hud-left .visitors { padding-left: 8px; font-size: 11.5px; }
  .hud-right {
    display: flex; align-items: center; gap: 2px; padding: 3px; flex: none; margin-left: auto; border-radius: 999px; color: #fff7ec;
    background: var(--glass); border: 1px solid var(--glass-line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  }
  body[data-view='buddha'] .hud-right { background: rgba(255, 255, 255, 0.72); border-color: var(--line); color: var(--ink); }
  .hud-right > .btn, .hud-right > .sound-info {
    position: relative; width: 44px; height: 44px; padding: 0; margin: 0; border: 0; border-radius: 50%; flex: none;
    background: transparent; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; color: inherit;
    display: inline-flex; flex-direction: column-reverse; align-items: center; justify-content: center; gap: 2px;
    font-size: 10.5px; line-height: 1;
  }
  .hud-right > .btn:hover, .hud-right > .btn:active, .hud-right > .sound-info:active { background: rgba(255, 248, 232, 0.14); }
  body[data-view='buddha'] .hud-right > .btn:hover { background: rgba(0, 0, 0, 0.05); }
  .hud-right > .sound-info { font: italic 600 14px/1 var(--font-head); }
  .hud-right > .sound-info::before { content: ''; position: absolute; inset: 12px; border: 1.4px solid currentColor; border-radius: 50%; opacity: 0.75; }
  .move-hint { top: 46%; }
  /* the bottom bar */
  .hall-actions { gap: 8px; align-items: stretch; }
  .hall-situ { align-self: flex-start; }
  .hall-situ .btn { height: 42px; padding: 0 16px; font-size: 14px; }
  .hall-row {
    display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 2px; padding: 4px; flex-wrap: nowrap;
    border-radius: 22px; background: var(--glass); border: 1px solid var(--glass-line);
    backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  }
  .hall-row .cell {
    height: 54px; min-width: 0; padding: 0 2px; border: 0; border-radius: 17px; background: transparent; box-shadow: none;
    backdrop-filter: none; -webkit-backdrop-filter: none; white-space: nowrap;
    display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 12px; line-height: 1.1;
  }
  .hall-row .cell:hover { background: rgba(255, 248, 232, 0.12); }
  .hall-row .cell .key-hint { display: none; }
  .hall-row .cell .cell-ico { flex: none; }
  .emoji-bar { display: none; }
  .hall-actions.emo-open .emoji-bar { display: flex; }
  /* bowing: the bar stays, 절하기 reads 일어나기, a thin 108배 bar over it (no big 일어나기 in the hall on a phone) */
  body[data-view='hall'] .rise-bar { display: none; }
  body[data-view='hall'].bowing .hall-actions { opacity: 1; }
  body.bowing .hall-row .cell:not(.bow-cell) { opacity: 0.4; pointer-events: none; }
  body.bowing .hall-actions .emoji-bar { display: none; }
  body.bowing .bow-prog { display: flex; }
  .bow-prog { flex-direction: column; align-items: center; gap: 6px; pointer-events: none !important; }
  .bow-prog-n { font-size: 12px; color: #fff7ec; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6); font-variant-numeric: tabular-nums; }
  .bow-prog i { display: block; width: min(240px, 70%); height: 3px; border-radius: 3px; background: rgba(255, 247, 236, 0.3); overflow: hidden; }
  .bow-prog b { display: block; height: 100%; background: #f2c36b; transform-origin: left; transform: scaleX(0); transition: transform 300ms var(--ease); }
}

/* ---------- 염주 by hand: the hall dims, a big loop in the middle; numbers bottom left, [접기 | 소리] over the bar ---------- */
.beads-wrap {
  position: absolute; inset: 0; z-index: 2; display: grid; place-items: center; touch-action: none; cursor: grab;
  background: rgba(24, 16, 9, 0.34); backdrop-filter: blur(7px); -webkit-backdrop-filter: blur(7px);
  animation: beads-in 260ms var(--ease);
}
.beads-wrap:active { cursor: grabbing; }
@keyframes beads-in { from { opacity: 0; } }
.beads-stage { height: min(54vh, 440px); aspect-ratio: 220 / 360; translate: 0 -5vh; pointer-events: none; filter: drop-shadow(0 18px 28px rgba(0, 0, 0, 0.35)); }
.beads-loop { display: block; width: 100%; height: 100%; }
.beads-hint {
  position: absolute; left: 50%; top: 45%; translate: -50% -50%; margin: 0; padding: 8px 14px; border-radius: 999px;
  background: rgba(255, 251, 242, 0.92); color: var(--ink); font-size: 14px; white-space: nowrap; pointer-events: none;
}
.beads-hint[hidden] { display: none; }
.beads-numbers { align-self: flex-start; color: #fff7ec; text-shadow: 0 2px 8px rgba(0, 0, 0, 0.45); pointer-events: none !important; }
.beads-count { margin: 0; font-family: var(--font-head); font-size: 40px; line-height: 1; font-variant-numeric: tabular-nums; }
.beads-lap { margin: 6px 0 0 2px; font-size: 14px; }
.beads-bar { display: flex; align-self: center; padding: 3px; border-radius: 999px; background: rgba(255, 251, 242, 0.92); box-shadow: 0 8px 22px -10px rgba(0, 0, 0, 0.5); }
.beads-btn { position: relative; display: inline-flex; align-items: center; gap: 6px; height: 40px; padding: 0 18px; border: 0; border-radius: 999px; background: transparent; color: var(--ink); font-size: 14px; cursor: pointer; }
.beads-btn:hover { background: rgba(0, 0, 0, 0.05); }
.beads-btn + .beads-btn::before { content: ''; position: absolute; left: 0; top: 10px; bottom: 10px; width: 1px; background: var(--line); }
@media (min-width: 721px) { .beads-bar { align-self: flex-start; } }
/* the narrowest phones (320 px): the pill a little narrower, the room button smaller, the counts may wrap */
@media (max-width: 359px) {
  .hud-right > .btn, .hud-right > .sound-info { width: 40px; }
  .hud-left .nav-btn { padding: 0 10px; font-size: 13px; }
  .hud-left .visitors { white-space: normal; }
}
/* the left group may be wider than its button: only the button and the counts take clicks, not the space beside them */
.hud .hud-left { pointer-events: none; }
.hud-left > * { pointer-events: auto; }
@media (max-width: 720px) {
  .hud-left { flex: 1 1 auto; }
  .hud-left .nav-btn { max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
}
/* `#ui > *` takes clicks for every layer; these full-width bars and the hint only hold buttons (their own children take
   the clicks), so the rest of their area lets drags and taps through to the hall */
#ui > .hud, #ui > .hall-actions, #ui > .move-hint, #ui > .self-emo { pointer-events: none; }
/* the counts under the room button stay readable over the bright lanterns: a soft dark backing and a light shadow */
@media (max-width: 720px) {
  body[data-view='hall'] .hud-left .visitors {
    padding: 3px 9px; border-radius: 11px; background: rgba(28, 22, 16, 0.42);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
    word-break: keep-all;   /* a narrow phone wraps at the 「·」, not inside 부처님께 */
  }
}
/* the joystick (back by owner 「누가 컨트롤러까지 빼래」): shows where the finger goes down at the lower left */
.joy { position: fixed; left: 0; top: 0; width: 120px; height: 120px; border-radius: 50%; border: 1px solid rgba(255, 255, 255, 0.35); background: rgba(0, 0, 0, 0.18); opacity: 0; pointer-events: none; transition: opacity 150ms; z-index: 2; }
.joy.on { opacity: 1; }
.joy-knob { position: absolute; left: 36px; top: 36px; width: 48px; height: 48px; border-radius: 50%; background: rgba(255, 247, 236, 0.75); }
/* no double-tap zoom anywhere (owner 「두번누르면 확대도빼줘」); quick taps on buttons and the 목탁 still all count.
   :where() keeps it weaker than the places that take no browser gestures at all (the 3D view, the beads, the chat grip). */
:where(html, body, #ui, #ui *) { touch-action: manipulation; }
