:root {
  --glass: rgba(22, 18, 14, 0.62);
  --glass-strong: rgba(22, 18, 14, 0.82);
  --line: rgba(255, 240, 210, 0.14);
  --text: #f3ead8;
  --muted: rgba(243, 234, 216, 0.6);
  --accent: #e8b75a;
  --hanji: #f4efe3;
  --ink: #2b2620;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%;
  overflow: hidden; background: #0d0a08; color: var(--text);
  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; }

#canvasContainer { position: fixed; inset: 0; touch-action: none; }
#canvasContainer canvas { display: block; width: 100%; height: 100%; }

/* ---------- 이름표 / 말풍선 ---------- */
#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.label {
  position: absolute; left: 0; top: 0;
  display: flex; flex-direction: column; align-items: center;
  transform: translate(-50%, -100%);
  will-change: transform;
}
.label .name {
  font-size: 11px; padding: 1px 7px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.45); color: var(--text); white-space: nowrap;
}
.label.me .name { background: rgba(232, 183, 90, 0.9); color: #2a1d08; font-weight: 700; }
.label .bubble {
  max-width: 200px; margin-bottom: 4px; padding: 6px 10px;
  border-radius: 12px; background: rgba(255, 250, 240, 0.95); color: var(--ink);
  font-size: 12.5px; line-height: 1.4; word-break: break-all;
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35);
  display: none; position: relative;
  animation: bubble-in 0.25s ease-out;
}
@keyframes bubble-in { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
.label .bubble::after {
  content: ''; position: absolute; left: 50%; bottom: -5px; transform: translateX(-50%);
  border: 5px solid transparent; border-top-color: rgba(255, 250, 240, 0.95); border-bottom: 0;
}
.label .bubble.show { display: block; }

/* ---------- HUD 공통 ---------- */
.hud { position: fixed; z-index: 10; }
.pill {
  background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 14px;
}
.top-left { top: 14px; left: 14px; }
.top-right { top: 14px; right: 14px; }
.brand { display: flex; align-items: center; gap: 8px; padding: 8px 14px; font-size: 14px; }
.brand-mark { color: var(--accent); }
.brand-sub { font-size: 11px; color: var(--muted); }

.tools { display: flex; align-items: center; gap: 4px; padding: 4px 6px; }
.tool-stat { font-size: 12.5px; padding: 0 8px; color: var(--muted); white-space: nowrap; }
.tool-stat b { color: var(--text); font-weight: 500; }
.icon-btn {
  width: 34px; height: 34px; border: 0; border-radius: 10px; background: transparent;
  color: var(--text); font-size: 14px;
}
.icon-btn:hover { background: rgba(255, 255, 255, 0.08); }

/* ---------- 하단 액션바 ---------- */
.bottom {
  left: 50%; bottom: 16px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.my-bows {
  font-size: 13px; color: var(--muted); padding: 4px 12px; border-radius: 999px;
  background: rgba(0, 0, 0, 0.35);
}
.my-bows b { color: var(--accent); font-size: 15px; }
.actions { display: flex; gap: 4px; padding: 5px; }
.action {
  display: flex; align-items: center; gap: 6px;
  border: 0; background: transparent; padding: 9px 16px; border-radius: 10px; font-size: 14px;
  transition: background 0.15s, transform 0.1s;
}
.action:hover { background: rgba(255, 255, 255, 0.07); }
.action:active { transform: scale(0.96); }
.action.active { background: rgba(255, 255, 255, 0.12); }
.action.busy { opacity: 0.5; }
.action .ico { font-size: 15px; }
.action kbd {
  font-family: inherit; font-size: 10px; color: var(--muted);
  border: 1px solid var(--line); border-radius: 4px; padding: 0 4px;
}
.hint { margin: 0; font-size: 11px; color: var(--muted); text-shadow: 0 1px 2px #000; }

/* ---------- 채팅 ---------- */
.chat {
  left: 14px; bottom: 16px; width: 320px;
  background: var(--glass); border: 1px solid var(--line); border-radius: 14px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  overflow: hidden;
}
.chat-toggle {
  width: 100%; display: flex; align-items: center; gap: 6px; padding: 8px 12px;
  background: transparent; border: 0; border-bottom: 1px solid var(--line); font-size: 13px; text-align: left;
}
.chat-toggle .chev { margin-left: auto; font-size: 11px; transition: transform 0.2s; }
.chat.collapsed .chat-body { display: none; }
.chat.collapsed .chat-toggle { border-bottom: 0; }
.chat.collapsed .chev { transform: rotate(180deg); }
#chatLog {
  list-style: none; margin: 0; padding: 8px 12px; height: 220px; overflow-y: auto;
  font-size: 13px; line-height: 1.5;
}
#chatLog li { margin: 2px 0; word-break: break-all; }
#chatLog .nick { color: var(--accent); font-weight: 500; margin-right: 6px; }
#chatLog .me .nick { color: #ffd892; }
#chatLog .system { color: var(--muted); font-size: 12px; }
#chatLog::-webkit-scrollbar { width: 6px; }
#chatLog::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 3px; }
#chatForm { display: flex; border-top: 1px solid var(--line); }
#chatInput {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text);
  padding: 10px 12px; font: inherit; font-size: 13px; outline: none;
}
#chatInput::placeholder { color: var(--muted); }
#chatForm button { border: 0; background: transparent; padding: 0 14px; color: var(--accent); }

/* ---------- 모달 ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: rgba(10, 8, 6, 0.55);
  backdrop-filter: blur(3px); -webkit-backdrop-filter: blur(3px);
}
.join-card, .scripture-card {
  position: relative; width: 100%; max-width: 420px;
  background: var(--hanji); color: var(--ink);
  border-radius: 18px; padding: 32px 28px 22px;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.55);
  font-family: 'Gowun Batang', serif;
}
.join-eyebrow { margin: 0 0 10px; font-size: 13px; color: #8a7f6c; }
.join-card h1 { margin: 0; font-size: 34px; line-height: 1.2; letter-spacing: -0.5px; }
.join-sub { margin: 14px 0 22px; font-size: 16px; }
#joinForm { display: flex; flex-direction: column; gap: 10px; }
#nickInput {
  width: 100%; padding: 13px 14px; border-radius: 10px; border: 1px solid #d9cfbb;
  background: #fffdf7; font: inherit; font-size: 15px; color: var(--ink); outline: none;
}
#nickInput:focus { border-color: #a88a52; }
#joinBtn {
  padding: 13px; border: 0; border-radius: 10px; background: #2f2a23; color: #f4efe3;
  font-size: 15px; font-weight: 700;
}
#joinBtn:disabled { opacity: 0.5; cursor: default; }
.join-error { min-height: 18px; margin: 8px 0 0; color: #b33a2a; font-size: 13px; }
.join-foot { margin: 8px 0 0; font-size: 12px; color: #8a7f6c; font-family: 'Noto Sans KR', sans-serif; }

.scripture-card { max-width: 520px; max-height: 86vh; display: flex; flex-direction: column; }
.scripture-card h2 { margin: 0 0 14px; font-size: 24px; }
.scripture-text { overflow-y: auto; font-size: 15.5px; line-height: 1.9; padding-right: 6px; }
.scripture-text p { margin: 0 0 10px; }
.scripture-text .mantra { margin-top: 16px; padding: 12px 14px; border-left: 3px solid #a88a52; background: rgba(168, 138, 82, 0.1); font-weight: 700; }
.close-btn {
  position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border-radius: 50%;
  border: 0; background: #2f2a23; color: #f4efe3;
}

/* ---------- 토스트 ---------- */
.toast {
  position: fixed; top: 70px; left: 50%; transform: translate(-50%, -10px);
  z-index: 60; padding: 9px 16px; border-radius: 999px;
  background: var(--glass-strong); border: 1px solid var(--line);
  font-size: 13px; opacity: 0; pointer-events: none; transition: opacity 0.25s, transform 0.25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 모바일 ---------- */
@media (max-width: 720px) {
  .tool-stat { padding: 0 5px; font-size: 12px; }
  .icon-btn { width: 30px; height: 30px; }
  .brand-sub { display: none; }
  .chat {
    left: 10px; right: 10px; width: auto; bottom: auto; top: 62px;
  }
  #chatLog { height: 140px; }
  .bottom { bottom: 12px; width: calc(100% - 20px); }
  .action kbd { display: none; }
  .hint { display: none; }
  .join-card h1 { font-size: 28px; }
}
