* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #1d2230;
  font-family: Pretendard, "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif; color: #1b1b1b; }
#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

button { font: inherit; border: 0; cursor: pointer; }

#hud-top { position: fixed; top: env(safe-area-inset-top, 0); left: 0; right: 0; display: flex;
  justify-content: space-between; align-items: flex-start; padding: 12px; pointer-events: none; }
#hud-top > * { pointer-events: auto; }
.title { background: rgba(255,255,255,.92); border-radius: 14px; padding: 8px 12px; display: flex;
  flex-direction: column; gap: 2px; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.title b { font-size: 15px; letter-spacing: -.02em; }
.title span { font-size: 12px; color: #666; }
.tools { display: flex; gap: 6px; }
.tools button { background: rgba(255,255,255,.92); border-radius: 12px; padding: 9px 12px; font-size: 13px;
  font-weight: 600; box-shadow: 0 2px 10px rgba(0,0,0,.15); }

#hint { position: fixed; left: 50%; top: 70px; transform: translateX(-50%); color: #fff; font-size: 12px;
  background: rgba(0,0,0,.35); padding: 6px 10px; border-radius: 10px; pointer-events: none; transition: opacity 1s; }

#action { position: fixed; left: 50%; bottom: calc(28px + env(safe-area-inset-bottom, 0)); transform: translateX(-50%);
  background: #111; color: #fff; padding: 14px 22px; border-radius: 999px; font-size: 15px; font-weight: 700;
  box-shadow: 0 6px 20px rgba(0,0,0,.35); max-width: 78vw; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#action.build { background: #fff; color: #111; }
#emotes { position: fixed; right: 14px; bottom: calc(28px + env(safe-area-inset-bottom, 0)); display: flex; gap: 6px; z-index: 3; }
#emotes button { background: rgba(255,255,255,.92);
  border-radius: 999px; padding: 12px 14px; font-size: 13px; font-weight: 600; box-shadow: 0 2px 10px rgba(0,0,0,.2); }

#joy { position: fixed; left: 22px; bottom: calc(26px + env(safe-area-inset-bottom, 0)); width: 116px; height: 116px;
  border-radius: 50%; background: rgba(255,255,255,.18); border: 2px solid rgba(255,255,255,.4); display: none; touch-action: none; }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%;
  background: rgba(255,255,255,.85); }
@media (pointer: coarse) { #joy { display: block; } #hint { display: none; } #action { bottom: calc(160px + env(safe-area-inset-bottom, 0)); } }

#modal { position: fixed; inset: 0; background: rgba(10,12,20,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
#modal[hidden] { display: none; }
.sheet { background: #fff; width: min(440px, 100%); max-height: 86vh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 20px 18px calc(20px + env(safe-area-inset-bottom, 0)); }
@media (min-width: 600px) { #modal { align-items: center; } .sheet { border-radius: 20px; } }
.sheet h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.02em; }
.sheet .sub { color: #777; font-size: 13px; margin: 0 0 14px; word-break: break-all; }
.sheet label { display: block; font-size: 12px; font-weight: 700; color: #555; margin: 12px 0 6px; }
.sheet input[type=text], .sheet input[type=url], .sheet input[type=search] { width: 100%; padding: 12px; border: 1px solid #ddd;
  border-radius: 12px; font: inherit; font-size: 15px; }
.row { display: flex; gap: 8px; margin-top: 16px; }
.row button { flex: 1; padding: 13px; border-radius: 12px; font-weight: 700; font-size: 15px; background: #eee; }
.row button.primary { background: #111; color: #fff; }
.row button.danger { background: #fbe9e7; color: #b3261e; }
.styles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.styles button { padding: 10px 4px; border-radius: 10px; background: #f3f3f3; font-size: 13px; font-weight: 600; }
.styles button.on { background: #111; color: #fff; }
.colors { display: flex; flex-wrap: wrap; gap: 8px; }
.colors button { width: 32px; height: 32px; border-radius: 50%; border: 3px solid transparent; }
.colors button.on { border-color: #111; }
.small { font-size: 12px; color: #888; margin-top: 12px; line-height: 1.5; }
.linkbtn { background: none; color: #888; text-decoration: underline; font-size: 12px; padding: 8px 0 0; }
.list { margin-top: 10px; display: flex; flex-direction: column; }
.list button { text-align: left; background: none; padding: 11px 4px; border-bottom: 1px solid #f0f0f0; display: flex;
  justify-content: space-between; gap: 8px; font-size: 14px; }
.list button span { color: #999; font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }
.err { color: #b3261e; font-size: 13px; margin-top: 10px; min-height: 1em; }

#toast { position: fixed; left: 50%; top: 84px; transform: translateX(-50%); background: #111; color: #fff; padding: 10px 16px;
  border-radius: 12px; font-size: 14px; z-index: 20; }

/* 채팅 */
#chat { position: fixed; left: 12px; bottom: calc(14px + env(safe-area-inset-bottom, 0)); width: min(360px, 42vw);
  display: none; flex-direction: column; gap: 6px; z-index: 5; }
#chat.open { display: flex; }
#chat-log { max-height: 34vh; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; padding: 8px 10px;
  background: rgba(15,17,25,.42); border-radius: 14px; color: #fff; font-size: 13.5px; line-height: 1.45;
  scrollbar-width: none; -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 18px); mask-image: linear-gradient(to bottom, transparent 0, #000 18px); }
#chat-log::-webkit-scrollbar { display: none; }
#chat-log:empty { display: none; }
#chat-log .msg { word-break: break-all; text-shadow: 0 1px 2px rgba(0,0,0,.4); }
#chat-log .msg b { cursor: pointer; margin-right: 2px; }
#chat-log .msg.sys { color: #ffe3a3; font-size: 12.5px; }
#chat-bar { display: flex; gap: 6px; }
#chat-input { flex: 1; min-width: 0; padding: 11px 12px; border-radius: 12px; border: 0; font: inherit; font-size: 15px;
  background: rgba(255,255,255,.94); box-shadow: 0 2px 10px rgba(0,0,0,.18); }
#chat-send { padding: 0 14px; border-radius: 12px; background: #111; color: #fff; font-weight: 700; font-size: 14px; }
#chat-toggle { position: fixed; right: 14px; bottom: calc(84px + env(safe-area-inset-bottom, 0)); background: #111; color: #fff;
  border-radius: 999px; padding: 12px 16px; font-size: 13px; font-weight: 700; box-shadow: 0 2px 10px rgba(0,0,0,.25); z-index: 5; }
#chat-toggle.hidden { display: none; }
.title { cursor: pointer; }
@media (pointer: fine) { #chat-toggle { display: none; } }
@media (pointer: coarse) {
  #chat { left: 8px; right: 8px; width: auto; bottom: calc(8px + env(safe-area-inset-bottom, 0)); z-index: 8; }
  #chat-log { max-height: 30vh; }
  #chat.open ~ #chat-toggle { display: none; }
}
body:has(#chat.open) #joy { display: none; }
@media (pointer: coarse) { body:has(#chat.open) #action, body:has(#chat.open) #emotes { display: none; } }
#chat-close { display: none; padding: 0 12px; border-radius: 12px; background: rgba(255,255,255,.94); font-weight: 700; font-size: 14px; }
@media (pointer: coarse) { #chat-close { display: block; } }
/* 데스크톱: 행동 버튼을 오른쪽으로 빼서 채팅창과 겹치지 않게 */
@media (pointer: fine) { #action { left: auto; right: 14px; transform: none; bottom: calc(84px + env(safe-area-inset-bottom, 0)); } }
.notice { margin: 0; padding: 0; font-size: 14px; line-height: 1.6; color: #333; }
.notice p { margin: 0 0 6px; }
.notice b { color: #111; }
.notice.rules { padding-left: 18px; }
.notice.rules li { margin-bottom: 3px; }
.sheet textarea { width: 100%; padding: 12px; border: 1px solid #ddd; border-radius: 12px; font: inherit; font-size: 15px; resize: none; }
.sheet .count { text-align: right; font-size: 11px; color: #999; margin-top: 3px; }
.sheet .promo { background: #fff8e6; border-radius: 12px; padding: 12px 14px; font-size: 15px; line-height: 1.5; margin: 0 0 6px; color: #3a2a12; }

/* 문 앞 간판 카드 */
#plate { position: fixed; left: 50%; top: calc(70px + env(safe-area-inset-top, 0)); transform: translateX(-50%); width: min(420px, 92vw);
  background: rgba(255,255,255,.96); border-radius: 16px; padding: 12px 16px; box-shadow: 0 6px 24px rgba(0,0,0,.22); z-index: 4; pointer-events: none; }
#plate[hidden] { display: none; }
#plate .plate-top { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
#plate b { font-size: 18px; letter-spacing: -.02em; }
#plate .who { font-size: 12px; color: #888; }
#plate p { margin: 6px 0 4px; font-size: 14.5px; line-height: 1.45; color: #3a2a12; background: #fff8e6; padding: 8px 10px; border-radius: 10px; }
#plate .meta { font-size: 12px; color: #999; }
#plate .rank { font-size: 12px; font-weight: 800; padding: 2px 8px; border-radius: 999px; background: #eee; }
#plate .rank.r1 { background: #d4af37; color: #fff; } #plate .rank.r2 { background: #b8c2cc; color: #fff; } #plate .rank.r3 { background: #c98a4b; color: #fff; }
/* 캐릭터 고르기 */
.look-preview { display: flex; justify-content: center; background: linear-gradient(#f6efe2, #efe4cf); border-radius: 16px; margin: 4px 0 6px; }
.styles button.swatch { height: 34px; border: 3px solid transparent; }
.styles button.swatch.on { border-color: #111; }
@media (max-width: 520px) {
  .tools { flex-wrap: wrap; justify-content: flex-end; max-width: 56vw; gap: 4px; }
  .tools button { padding: 7px 9px; font-size: 12px; }
  .title { max-width: 40vw; } .title b { font-size: 14px; } .title span { font-size: 11px; }
}
.threads-login { display: block; text-align: center; background: #111; color: #fff; text-decoration: none; padding: 13px; border-radius: 12px; font-weight: 700; margin: 6px 0; }
.or { text-align: center; font-size: 12px; color: #999; margin: 8px 0 -4px; }
.small-link { display: inline-block; font-size: 12px; color: #3a6ad1; margin-top: 6px; }
.verified { display: inline-block; font-size: 11px; font-weight: 700; color: #fff; background: #3a6ad1; padding: 2px 8px; border-radius: 999px; margin: 0 0 8px; }
#plate .verified { margin: 0; }
.build-preview { margin: 6px 0 8px; }
#wx { font-size: 11px; color: #888; }
.admin-row { display: flex; align-items: center; gap: 6px; padding: 8px 0; border-bottom: 1px solid #f0f0f0; font-size: 13px; }
.admin-row b { flex: 1; } .admin-row span { color: #999; font-size: 11px; }
.admin-row button { padding: 6px 10px; border-radius: 8px; background: #eee; font-size: 12px; font-weight: 700; }
.admin-row button.danger { background: #fbe9e7; color: #b3261e; }
.worldmap { width: 100%; display: block; border-radius: 14px; margin-top: 8px; cursor: pointer; touch-action: manipulation; }
.row.tabs { margin-top: 6px; } .row.tabs button { padding: 9px; font-size: 13px; }
@media (pointer: coarse) { #emotes { gap: 4px; } #emotes button { padding: 10px 10px; font-size: 12px; } }
#emotes button#run.on { background: #111; color: #fff; }
