:root {
  --green: #1f3d33;
  --green-2: #2a5244;
  --beige: #f3dcb4;
  --ink: #1f2327;
  --ink-2: #6b7076;
  --line: rgba(40, 46, 52, .12);
  --card: rgba(255, 255, 255, .86);
  --shadow: 0 10px 30px rgba(20, 24, 28, .16), 0 2px 6px rgba(20, 24, 28, .08);
  --font: "Pretendard Variable", Pretendard, "Malgun Gothic", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #c9ccd0; font-family: var(--font); color: var(--ink); -webkit-font-smoothing: antialiased; }
button { font: inherit; color: inherit; cursor: pointer; }
#app { position: fixed; inset: 0; }
#app canvas { display: block; }
.css2d { position: absolute; inset: 0; }
.css2d > div { pointer-events: none; }
#app .css2d { touch-action: none; }

/* ---------------- 상단 로고 */
.brand { position: fixed; left: 16px; top: 16px; z-index: 10; display: flex; align-items: center; gap: 12px; padding: 10px 16px 10px 10px; background: var(--card); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); }
.logo { width: 42px; height: 42px; border-radius: 12px; background: linear-gradient(145deg, var(--green-2), #163028); color: var(--beige); display: grid; place-items: center; font-weight: 900; font-size: 14px; letter-spacing: .02em; }
a.logo { text-decoration: none; }
.logo.big { width: 64px; height: 64px; font-size: 21px; border-radius: 18px; }
.brand h1 { margin: 0; font-size: 17px; font-weight: 800; letter-spacing: -.02em; }
.brand p { margin: 2px 0 0; font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.live-dot { width: 7px; height: 7px; border-radius: 50%; background: #2fb36d; box-shadow: 0 0 0 0 rgba(47, 179, 109, .5); animation: pulse 2s infinite; }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px rgba(47, 179, 109, 0); } 100% { box-shadow: 0 0 0 0 rgba(47, 179, 109, 0); } }

/* ---------------- 왼쪽 방 목록 */
.panel { position: fixed; left: 16px; top: 92px; bottom: 74px; z-index: 10; width: 268px; display: flex; flex-direction: column; background: var(--card); backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: 16px; box-shadow: var(--shadow); overflow: hidden; transition: transform .3s, opacity .3s; }
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 16px; font-size: 13px; color: var(--ink-2); }
.panel-head b { color: var(--ink); font-size: 14px; }
.icon-btn { width: 30px; height: 30px; border-radius: 9px; border: 1px solid var(--line); background: #fff; }
.room-list { overflow-y: auto; padding: 0 8px 10px; display: flex; flex-direction: column; gap: 4px; }
.room-btn { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; padding: 8px 10px; border: 1px solid transparent; border-radius: 12px; background: transparent; transition: background .15s, border-color .15s; }
.room-btn:hover { background: rgba(255, 255, 255, .9); border-color: var(--line); }
.room-btn.active { background: #fff; border-color: color-mix(in srgb, var(--c) 45%, #fff); box-shadow: 0 0 0 3px color-mix(in srgb, var(--c) 18%, transparent); }
.room-btn .ic { width: 34px; height: 34px; flex: none; border-radius: 10px; display: grid; place-items: center; font-size: 17px; background: color-mix(in srgb, var(--c) 16%, #fff); }
.room-btn .tx { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.room-btn b { font-size: 13.5px; font-weight: 750; letter-spacing: -.02em; }
.room-btn small { font-size: 11.5px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-btn .cnt { font-size: 11.5px; font-weight: 700; color: var(--c); background: color-mix(in srgb, var(--c) 12%, #fff); padding: 3px 8px; border-radius: 999px; }
body.panel-closed .panel { bottom: auto; height: 50px; }
body.panel-closed .room-list { display: none; }

/* ---------------- 오른쪽 위 버튼 */
.toolbar { position: fixed; right: 16px; top: 16px; z-index: 10; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; max-width: calc(100vw - 340px); }
.tb { display: flex; align-items: center; gap: 6px; height: 38px; padding: 0 13px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); backdrop-filter: blur(14px); box-shadow: 0 4px 14px rgba(20, 24, 28, .1); font-size: 13px; font-weight: 650; white-space: nowrap; }
.tb:hover { background: #fff; }
.tb.on { background: var(--green); color: var(--beige); border-color: var(--green); }
.tb span { font-size: 14px; }

/* ---------------- 아래 조작 안내 */
.hint { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 10; display: flex; gap: 14px; padding: 9px 16px; border-radius: 999px; background: rgba(31, 35, 39, .78); color: #fff; font-size: 12.5px; backdrop-filter: blur(10px); white-space: nowrap; }
.hint kbd { font-family: inherit; font-size: 11.5px; font-weight: 700; padding: 2px 7px; margin-right: 4px; border-radius: 6px; background: rgba(255, 255, 255, .16); color: var(--beige); }

/* ---------------- 방 이름표 (3D 위에 떠 있음) */
.room-tag { pointer-events: auto !important; display: flex; align-items: center; gap: 6px; padding: 5px 11px 5px 5px; border-radius: 999px; border: 1px solid rgba(40, 46, 52, .14); background: rgba(255, 255, 255, .94); box-shadow: 0 6px 18px rgba(20, 24, 28, .16); font-size: 13px; white-space: nowrap; transition: transform .15s, opacity .3s; }
.room-tag:hover { transform: translateY(-3px) scale(1.04); }
.room-tag .ic { width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: color-mix(in srgb, var(--c) 18%, #fff); }
.room-tag b { font-weight: 800; letter-spacing: -.02em; }
.room-tag .n { font-size: 11px; font-weight: 800; color: #fff; background: var(--c); min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; display: grid; place-items: center; }
body.close-up .room-tag { opacity: 0; pointer-events: none !important; }

/* ---------------- 사람 이름표 + 말풍선 */
.npc-label { position: relative; width: 1px; height: 1px; pointer-events: none; }
.npc-label .st { display: none; }
.npc-label .name { position: absolute; left: 50%; bottom: 4px; transform: translate(-50%, 4px); display: flex; align-items: center; gap: 5px; padding: 3px 9px 3px 6px; border-radius: 999px; background: #fff; border: 1px solid rgba(40, 46, 52, .14); box-shadow: 0 4px 12px rgba(20, 24, 28, .16); font-size: 12px; font-weight: 800; white-space: nowrap; opacity: 0; transition: opacity .2s, transform .2s; }
.npc-label .name i { width: 8px; height: 8px; border-radius: 50%; }
.npc-label .name small { font-size: 10.5px; font-weight: 600; color: var(--ink-2); }
.npc-label.hover .name, .npc-label.selected .name { opacity: 1; transform: translate(-50%, 0); }
.npc-label.selected .name { border-color: var(--green); box-shadow: 0 0 0 3px rgba(31, 61, 51, .2), 0 4px 12px rgba(20, 24, 28, .16); }
.bubble { position: absolute; left: 50%; bottom: 34px; width: max-content; max-width: 220px; padding: 7px 11px; border-radius: 13px; background: rgba(33, 30, 27, .92); color: #fff; font-size: 12px; font-weight: 500; line-height: 1.4; text-align: center; opacity: 0; transform: translate(-50%, 6px) scale(.92); transition: opacity .25s, transform .25s; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -5px; margin-left: -5px; border: 5px solid transparent; border-bottom: 0; border-top-color: rgba(33, 30, 27, .92); }
.bubble.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* ---------------- 회원 카드 */
.card { position: fixed; right: 16px; bottom: 72px; z-index: 11; width: 250px; padding: 16px; border-radius: 16px; background: rgba(255, 255, 255, .95); border: 1px solid var(--line); box-shadow: var(--shadow); backdrop-filter: blur(14px); }
.card[hidden] { display: none; }
.card-x { position: absolute; right: 10px; top: 8px; width: 28px; height: 28px; border: 0; background: transparent; font-size: 20px; color: var(--ink-2); }
.card-top { display: flex; align-items: center; gap: 8px; font-size: 18px; font-weight: 800; }
.card-top i { width: 12px; height: 12px; border-radius: 50%; }
.card-home { margin: 4px 0 12px; font-size: 12.5px; color: var(--ink-2); }
.card-row { display: flex; justify-content: space-between; gap: 8px; padding: 7px 0; border-top: 1px solid var(--line); font-size: 13px; }
.card-row span { color: var(--ink-2); }
.card-btn { width: 100%; margin-top: 10px; height: 36px; border-radius: 10px; border: 1px solid var(--green); background: #fff; color: var(--green); font-weight: 750; }
.card-btn.on, .card-btn:hover { background: var(--green); color: var(--beige); }

/* ---------------- 알림 */
.toast { position: fixed; left: 50%; top: 18px; transform: translate(-50%, -20px); z-index: 30; padding: 10px 16px; border-radius: 12px; background: rgba(31, 35, 39, .92); color: #fff; font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .3s, transform .3s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------------- 로딩 */
.loading { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; background: radial-gradient(circle at 50% 40%, #f3f4f6, #c9ccd0); transition: opacity .6s, visibility .6s; }
.loading.done { opacity: 0; visibility: hidden; }
.load-box { display: flex; flex-direction: column; align-items: center; gap: 12px; text-align: center; }
.load-box b { font-size: 16px; }
.load-box small { font-size: 12.5px; color: var(--ink-2); }
.bar { width: 240px; height: 6px; border-radius: 99px; background: rgba(31, 61, 51, .12); overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--green-2), #3b7a63); border-radius: 99px; transition: width .3s; }

/* ---------------- 좁은 화면 */
@media (max-width: 760px) {
  .brand { left: 10px; top: 10px; padding: 8px 12px 8px 8px; }
  .brand p { display: none; }
  .logo { width: 34px; height: 34px; font-size: 12px; }
  .panel { left: 10px; top: 70px; width: calc(100vw - 20px); max-height: 46vh; bottom: auto; }
  .toolbar { left: 10px; right: 10px; top: auto; bottom: 10px; max-width: none; justify-content: center; }
  .tb { height: 34px; padding: 0 10px; font-size: 12px; }
  .hint { display: none; }
  .card { right: 10px; left: 10px; width: auto; bottom: 100px; }
}

/* ---------------- 사진 모드 표시 */
.photo-badge { position: fixed; left: 50%; top: 18px; transform: translateX(-50%); z-index: 12; display: flex; align-items: center; gap: 8px; padding: 8px 14px; border-radius: 999px; background: rgba(31, 35, 39, .82); color: #fff; font-size: 13px; font-weight: 600; backdrop-filter: blur(8px); }
.photo-badge[hidden] { display: none; }
.photo-badge i { width: 8px; height: 8px; border-radius: 50%; background: #f6c56b; box-shadow: 0 0 0 0 rgba(246,197,107,.6); animation: pulse 1.6s infinite; }

/* 개설 준비중 · 메인(AI) 스터디 */
.room-btn .cnt.soon { color: #6b7076; background: #eceef0; font-weight: 600; }
.room-tag .n { white-space: nowrap; }
.room-tag.soon .n { background: #8d9298; font-size: 10px; }
.room-tag.soon { opacity: .82; }
.room-tag.main { font-size: 15px; padding: 7px 14px 7px 7px; border: 2px solid var(--c); box-shadow: 0 8px 26px color-mix(in srgb, var(--c) 45%, transparent); }
.room-tag.main .ic { width: 30px; height: 30px; font-size: 16px; }

/* ---------------- 실시간 채팅 (js/chat.js) */
.chat-launch { position: fixed; left: 16px; bottom: 16px; z-index: 12; display: flex; align-items: center; gap: 10px; padding: 7px 16px 7px 7px; border-radius: 16px; border: 1px solid var(--line); background: var(--card); backdrop-filter: blur(14px); box-shadow: var(--shadow); text-align: left; transition: transform .15s, background .15s; }
.chat-launch:hover { background: #fff; transform: translateY(-2px); }
.chat-launch[hidden] { display: none; }
.chat-launch .ic { width: 36px; height: 36px; flex: none; border-radius: 11px; display: grid; place-items: center; font-size: 18px; background: color-mix(in srgb, var(--c) 16%, #fff); }
.chat-launch .tx { display: flex; flex-direction: column; gap: 2px; }
.chat-launch b { font-size: 13.5px; font-weight: 800; letter-spacing: -.02em; }
.chat-launch small { display: flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--ink-2); }
.chat-launch .badge { position: absolute; top: -6px; right: -6px; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: #e5484d; color: #fff; font-size: 11px; font-weight: 800; display: grid; place-items: center; box-shadow: 0 2px 6px rgba(229, 72, 77, .4); }
.chat-launch .badge[hidden] { display: none; }

.chat { position: fixed; right: 16px; bottom: 72px; z-index: 25; width: 340px; height: min(560px, calc(100% - 180px)); min-height: 300px; display: flex; flex-direction: column; border-radius: 18px; background: rgba(255, 255, 255, .96); border: 1px solid var(--line); box-shadow: 0 18px 50px rgba(20, 24, 28, .22), 0 2px 8px rgba(20, 24, 28, .08); backdrop-filter: blur(16px); overflow: hidden; }
.chat[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 12px 10px 10px 12px; border-bottom: 1px solid var(--line); background: linear-gradient(180deg, color-mix(in srgb, var(--c) 9%, #fff), #fff); }
.chat-head .ic { width: 36px; height: 36px; flex: none; border-radius: 11px; display: grid; place-items: center; font-size: 18px; background: color-mix(in srgb, var(--c) 18%, #fff); }
.chat-head .tt { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.chat-head b { font-size: 15px; font-weight: 800; letter-spacing: -.02em; }
.chat-head small { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--ink-2); }
.chat-head .dot { width: 7px; height: 7px; border-radius: 50%; background: #b4b8bd; }
.chat[data-state="on"] .chat-head .dot { background: #2fb36d; }
.chat[data-state="off"] .chat-head .dot { background: #e5a23a; }
.chat-x { width: 32px; height: 32px; flex: none; border: 0; border-radius: 9px; background: transparent; font-size: 22px; line-height: 1; color: var(--ink-2); }
.chat-x:hover { background: rgba(31, 35, 39, .06); color: var(--ink); }
.chat-who { display: flex; gap: 5px; padding: 8px 12px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.chat-who[hidden] { display: none; }
.chat-who span { flex: none; font-size: 11.5px; font-weight: 650; padding: 3px 9px; border-radius: 999px; background: #f1f3f4; color: #3c4146; }
.chat-who span.me { background: color-mix(in srgb, var(--c) 16%, #fff); color: var(--ink); }
.chat-log { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 12px 6px; display: flex; flex-direction: column; gap: 3px; overscroll-behavior: contain; }
.chat-log .m { max-width: 86%; align-self: flex-start; margin-top: 7px; }
.chat-log .m.cont { margin-top: 0; }
.chat-log .m.me { align-self: flex-end; }
.chat-log .who { display: flex; align-items: baseline; gap: 6px; margin: 0 4px 3px; }
.chat-log .m.me .who { justify-content: flex-end; }
.chat-log .who b { font-size: 12px; font-weight: 750; }
.chat-log .who time { font-size: 10.5px; color: var(--ink-2); }
.chat-log .txt { padding: 8px 12px; border-radius: 4px 14px 14px 14px; background: #f1f3f4; font-size: 13.5px; line-height: 1.45; white-space: pre-wrap; word-break: break-word; }
.chat-log .m.me .txt { border-radius: 14px 4px 14px 14px; background: var(--green); color: #fff; }
.chat-log .m.old .txt { opacity: .82; }
.chat-log .sys { align-self: center; margin: 8px 0 2px; padding: 3px 10px; border-radius: 999px; background: rgba(31, 35, 39, .05); font-size: 11.5px; color: var(--ink-2); text-align: center; }
.chat-join, .chat-form { padding: 10px 12px 12px; border-top: 1px solid var(--line); background: #fff; }
.chat-join[hidden], .chat-form[hidden] { display: none; }
.chat-join { display: flex; flex-direction: column; gap: 7px; }
.chat-join b { font-size: 13px; }
.chat-join .row { display: flex; gap: 6px; }
.chat-join small { font-size: 11.5px; color: var(--ink-2); }
.chat-join small.bad { color: #c2353a; }
.chat input { flex: 1; min-width: 0; height: 40px; padding: 0 12px; border-radius: 11px; border: 1px solid rgba(40, 46, 52, .18); background: #fff; font: inherit; font-size: 14px; color: var(--ink); outline: none; }
.chat input:focus { border-color: var(--green-2); box-shadow: 0 0 0 3px rgba(42, 82, 68, .15); }
.chat-join button { height: 40px; padding: 0 16px; border: 0; border-radius: 11px; background: var(--green); color: var(--beige); font-weight: 800; }
.chat-form { display: flex; align-items: center; gap: 6px; }
.chat-form .me { flex: none; max-width: 92px; height: 40px; padding: 0 10px; border-radius: 11px; border: 1px solid var(--line); background: #f6f7f8; font-size: 12px; font-weight: 750; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-form .send { flex: none; width: 40px; height: 40px; border: 0; border-radius: 11px; background: var(--green); color: var(--beige); font-size: 15px; }
.chat-form .send:hover, .chat-join button:hover { background: var(--green-2); }
body.chat-open .card { right: 372px; }

/* 방 목록 💬 단추 · 3D 이름표 💬 · 이름표 위 말풍선 */
.room-btn .chat-chip { flex: none; display: flex; align-items: center; gap: 3px; height: 26px; padding: 0 8px; border-radius: 999px; font-size: 13px; background: color-mix(in srgb, var(--c) 14%, #fff); border: 1px solid color-mix(in srgb, var(--c) 35%, #fff); }
.room-btn .chat-chip:hover { background: color-mix(in srgb, var(--c) 26%, #fff); }
.room-btn .chat-chip i { font-style: normal; font-size: 11px; font-weight: 800; color: var(--c); }
.room-btn .chat-chip i:empty { display: none; }
.room-tag .talk { display: grid; place-items: center; width: 26px; height: 26px; margin-left: 2px; border-radius: 50%; background: var(--c); font-size: 13px; box-shadow: 0 2px 6px color-mix(in srgb, var(--c) 45%, transparent); }
.room-tag .talk:hover { transform: scale(1.12); }
.room-tag .tag-say { position: absolute; left: 50%; bottom: calc(100% + 10px); transform: translateX(-50%); width: max-content; max-width: 260px; padding: 7px 12px; border-radius: 13px; background: rgba(33, 30, 27, .92); color: #fff; font-size: 12.5px; font-weight: 600; line-height: 1.4; white-space: normal; text-align: center; pointer-events: none; animation: tagSay 6s ease forwards; }
.room-tag .tag-say::after { content: ""; position: absolute; left: 50%; bottom: -5px; margin-left: -5px; border: 5px solid transparent; border-bottom: 0; border-top-color: rgba(33, 30, 27, .92); }
@keyframes tagSay { 0% { opacity: 0; transform: translate(-50%, 6px); } 6%, 85% { opacity: 1; transform: translate(-50%, 0); } 100% { opacity: 0; } }

/* 조작 안내 줄이 왼쪽 아래 채팅 단추와 겹치지 않게 (가운데 정렬은 폭 1100px 이상에서만) */
@media (max-width: 1100px) and (min-width: 761px) {
  .hint { left: auto; right: 16px; transform: none; }
  body.chat-open .hint, body.embedded .hint { display: none; }   /* 워드프레스 안에선 오른쪽 아래가 '크게 보기' 자리 */
}
@media (max-width: 760px) {
  .chat-launch { left: auto; right: 10px; bottom: auto; top: 10px; padding: 5px 12px 5px 5px; gap: 8px; border-radius: 14px; }
  .chat-launch .ic { width: 30px; height: 30px; font-size: 15px; border-radius: 9px; }
  .chat-launch b { font-size: 12.5px; }
  .chat-launch small { font-size: 11px; }
  body.embedded .chat-launch { right: 118px; }   /* 워드프레스 안에 끼워졌을 때 오른쪽 위 '크게 보기' 자리 비움 */
  .chat { left: 10px; right: 10px; bottom: 10px; width: auto; height: min(72%, 520px); min-height: 0; }
  body.chat-open .card { right: 10px; }
}

/* 실제 접속 인원이 0명인 방은 숫자를 흐리게 */
.room-tag.empty .n { background: #a3a8ae; }
