:root { --bg: #05080f; --panel: rgba(8, 14, 28, 0.78); --line: rgba(160, 185, 230, 0.18); --gold: #ffd25a; --up: #ff4040; --down: #1fd17a; --text: #e8eefc; --dim: #8a9cc2; }
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: "Noto Sans TC", "Microsoft JhengHei", sans-serif; -webkit-user-select: none; user-select: none; }
#c { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }
[hidden] { display: none !important; }

#labels { position: fixed; inset: 0; pointer-events: none; overflow: hidden; }
.tag { position: absolute; left: 0; top: 0; transform: translate(-50%, -100%); display: flex; flex-direction: column; align-items: center; gap: 4px; will-change: transform; }
.tag .nm { font-weight: 700; font-size: 14px; padding: 2px 9px; border-radius: 999px; background: rgba(5, 10, 22, 0.72); border: 1px solid var(--line); white-space: nowrap; text-shadow: 0 1px 2px #000; }
.tag.me .nm { border-color: var(--gold); color: var(--gold); }
.tag .bb { max-width: 220px; font-size: 14px; line-height: 1.35; padding: 6px 10px; border-radius: 12px; background: #fff; color: #111; box-shadow: 0 4px 14px rgba(0,0,0,0.4); word-break: break-all; position: relative; }
.tag .bb::after { content: ""; position: absolute; left: 50%; bottom: -6px; margin-left: -6px; border: 6px solid transparent; border-bottom: 0; border-top-color: #fff; }
.tag .em { font-size: 26px; animation: pop 0.4s ease-out; }
.tag .em img { width: 40px; height: 40px; display: block; filter: drop-shadow(0 2px 4px rgba(0,0,0,0.5)); }
@keyframes pop { from { transform: scale(0.3); opacity: 0; } to { transform: scale(1); opacity: 1; } }

#hud { position: fixed; left: 14px; top: calc(12px + env(safe-area-inset-top)); padding: 10px 14px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; backdrop-filter: blur(6px); }
.hud-row { display: flex; align-items: center; gap: 10px; font-size: 15px; }
.hud-row + .hud-row { margin-top: 6px; }
.dim { color: var(--dim); font-size: 13px; }
.pill { font-size: 12px; font-weight: 700; padding: 2px 9px; border-radius: 999px; background: #33415f; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #666; display: inline-block; }
.dot.ok { background: var(--down); box-shadow: 0 0 8px var(--down); }

#roster { position: fixed; right: 14px; top: calc(12px + env(safe-area-inset-top)); width: 170px; max-height: 40vh; overflow: auto; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; font-size: 13px; }
.r-title { color: var(--dim); margin-bottom: 6px; }
#roster ul { list-style: none; margin: 0; padding: 0; }
#roster li { padding: 2px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#roster li.me { color: var(--gold); }

#chat { position: fixed; left: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); width: min(380px, calc(100vw - 28px)); }
#chat-log { list-style: none; margin: 0 0 8px; padding: 0; max-height: 28vh; overflow: hidden; display: flex; flex-direction: column; justify-content: flex-end; font-size: 14px; }
#chat-log li { padding: 3px 9px; margin-top: 3px; background: rgba(5, 10, 22, 0.6); border-radius: 8px; width: fit-content; max-width: 100%; word-break: break-all; animation: pop 0.2s; }
#chat-log li b { color: var(--gold); font-weight: 700; margin-right: 6px; }
#chat-log li.sys { color: var(--dim); }
#chat-form { display: flex; gap: 6px; }
#chat-input { flex: 1; min-width: 0; font: inherit; font-size: 15px; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px; outline: none; -webkit-user-select: text; user-select: text; }
#chat-input:focus { border-color: var(--gold); }
#chat-form button { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0 14px; cursor: pointer; }

#emotes { position: fixed; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; gap: 8px; }
#emotes button { height: 56px; width: 60px; padding: 0; font-size: 22px; display: flex; flex-direction: column; align-items: center; justify-content: center; line-height: 1.1; }
#emotes button span { font-size: 11px; color: var(--dim); }
#emotes button:active { border-color: var(--gold); }

#help { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(14px + env(safe-area-inset-bottom)); font-size: 12px; color: var(--dim); background: rgba(5,10,22,0.55); padding: 5px 12px; border-radius: 999px; white-space: nowrap; pointer-events: none; }

#joy { position: fixed; left: 26px; bottom: calc(150px + env(safe-area-inset-bottom)); width: 120px; height: 120px; border-radius: 50%; background: rgba(255,255,255,0.06); border: 1px solid var(--line); touch-action: none; }
#joy-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%; background: rgba(255,210,90,0.35); border: 1px solid var(--gold); }

#join { position: fixed; inset: 0; display: flex; align-items: center; justify-content: flex-start; padding: 16px 5vw; background: linear-gradient(90deg, rgba(3,6,14,0.92) 0%, rgba(3,6,14,0.6) 45%, rgba(3,6,14,0) 70%); }
#join .card { width: min(420px, 100%); }
#join h1 { margin: 0; font-size: 44px; font-weight: 900; letter-spacing: 0.08em; color: var(--gold); }
#join .sub { color: var(--dim); line-height: 1.6; margin: 8px 0 22px; }
#join label, #join .lbl { display: block; font-size: 14px; color: var(--dim); margin-bottom: 8px; }
#j-name { display: block; width: 100%; margin: 6px 0 14px; font: inherit; font-size: 18px; padding: 12px 14px; color: var(--text); background: rgba(255,255,255,0.06); border: 1px solid var(--line); border-radius: 12px; outline: none; -webkit-user-select: text; user-select: text; }
#j-name:focus { border-color: var(--gold); }
#j-hall { display: block; width: 100%; margin: 6px 0 14px; font: inherit; font-size: 16px; padding: 10px 12px; color: var(--text); background: #0d1424; border: 1px solid var(--line); border-radius: 12px; outline: none; }
.j-online { float: right; color: var(--down); }
#hud-invite { font: inherit; font-size: 12px; color: var(--gold); background: transparent; border: 1px solid rgba(255,210,90,0.4); border-radius: 999px; padding: 2px 9px; cursor: pointer; }
#j-avatars { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 20px; }
#j-avatars button { font: inherit; font-size: 14px; padding: 12px 0; color: var(--text); background: rgba(255,255,255,0.05); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
#j-avatars button.on { border-color: var(--gold); color: var(--gold); background: rgba(255,210,90,0.1); }
#j-go { width: 100%; font: inherit; font-size: 20px; font-weight: 900; padding: 14px; border: 0; border-radius: 12px; background: var(--gold); color: #1a1200; cursor: pointer; }
#j-go:disabled { opacity: 0.5; cursor: wait; }
#j-donate { display: block; margin-top: 10px; text-align: center; padding: 11px; border-radius: 12px; border: 1px solid var(--gold); color: var(--gold); text-decoration: none; font-weight: 700; }
#join .fine { font-size: 12px; color: #5e6f93; margin-top: 16px; line-height: 1.5; }

#toast { position: fixed; left: 50%; top: 18%; transform: translateX(-50%); padding: 10px 18px; border-radius: 12px; background: var(--panel); border: 1px solid var(--gold); color: var(--gold); font-weight: 700; opacity: 0; transition: opacity 0.3s; pointer-events: none; }
#toast.show { opacity: 1; }

@media (max-width: 760px) {
  #join { align-items: flex-end; background: linear-gradient(0deg, rgba(3,6,14,0.95) 0%, rgba(3,6,14,0.75) 60%, rgba(3,6,14,0) 100%); padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  #join h1 { font-size: 34px; }
  #join .sub { margin-bottom: 14px; font-size: 14px; }
  #roster { display: none; }
  #help { display: none; }
  #chat { width: calc(100vw - 28px); }
  #chat-log { max-height: 84px; font-size: 13px; }
  #emotes { flex-direction: column; bottom: calc(68px + env(safe-area-inset-bottom)); }
  #emotes button { height: 50px; width: 54px; }
  #joy { bottom: calc(170px + env(safe-area-inset-bottom)); }
}

/* action bar (bottom right) */
#actions { position: fixed; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#actions .row { display: flex; gap: 6px; }
#actions button { position: relative; width: 56px; height: 58px; padding: 0; font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
#actions button:active, #actions button:hover { border-color: var(--gold); }
#actions button span { font-size: 11px; color: var(--dim); line-height: 1; }
#actions kbd { position: absolute; top: 3px; right: 5px; font: 600 9px "IBM Plex Mono", monospace; color: #6a7ba0; }
.ic { font-style: normal; font-size: 22px; line-height: 1; display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; }
.ic img { width: 100%; height: 100%; object-fit: contain; }
#actions .moves { display: none; }
#actions .sit { opacity: 0.4; }
#actions.can-sit .sit { opacity: 1; border-color: var(--gold); }
#menu-btn { position: fixed; right: 196px; top: calc(12px + env(safe-area-inset-top)); width: 44px; height: 44px; padding: 0; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; color: var(--text); cursor: pointer; }
#seat-hint { position: fixed; left: 50%; top: 62%; transform: translateX(-50%); padding: 6px 14px; border-radius: 999px; background: rgba(5,10,22,0.75); border: 1px solid var(--gold); color: var(--gold); font-size: 14px; pointer-events: none; }
#labels.no-names .tag:not(.me) .nm { display: none; }
#labels.no-bubbles .bb { display: none !important; }

/* Esc menu + kicked */
#menu, #kicked { position: fixed; inset: 0; background: rgba(2,5,12,0.6); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 50; }
#menu .card, #kicked .card { width: min(440px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: #0a1222; border: 1px solid var(--line); border-radius: 16px; padding: 22px; }
#menu h2, #kicked h2 { margin: 0 0 4px; color: var(--gold); }
#menu button, #kicked button { display: block; width: 100%; margin-top: 10px; font: inherit; font-size: 16px; padding: 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,0.05); color: var(--text); cursor: pointer; }
#menu button.primary { background: var(--gold); color: #1a1200; border: 0; font-weight: 900; }
#menu .sets { margin: 16px 0 6px; display: grid; gap: 10px; font-size: 15px; }
#menu .sets label { display: flex; align-items: center; gap: 8px; }
#menu .sets select { margin-left: auto; font: inherit; padding: 6px 8px; background: #0d1424; color: var(--text); border: 1px solid var(--line); border-radius: 8px; }
#menu details { margin-top: 10px; font-size: 14px; color: var(--dim); line-height: 1.6; }
#menu summary { cursor: pointer; color: var(--text); }
#menu .donate { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 16px; padding: 12px; border-radius: 12px; border: 1px solid var(--gold); color: var(--gold); text-decoration: none; font-weight: 700; }

@media (pointer: coarse) {
  #actions .moves { display: flex; }
  #actions button { width: 50px; height: 52px; }
  #help { display: none !important; }
  #menu-btn { right: 14px; }
}
@media (max-width: 760px) {
  #actions .acts { flex-wrap: wrap; justify-content: flex-end; width: 226px; }
  #actions button { width: 50px; height: 50px; }
  #actions kbd { display: none; }
  /* phones: input across the bottom, log under the HUD, buttons + joystick above the input */
  #chat { left: 10px; right: 10px; width: auto; }
  #chat-log { position: fixed; left: 10px; top: calc(86px + env(safe-area-inset-top)); width: 62vw; max-height: 22vh; margin: 0; }
  #actions { bottom: calc(66px + env(safe-area-inset-bottom)); }
  #joy { bottom: calc(80px + env(safe-area-inset-bottom)); left: 18px; }
}

#hud-invite img { width: 14px; height: 14px; vertical-align: -2px; }
#chat-form button img { width: 24px; height: 24px; display: block; }
img.si { width: 20px; height: 20px; vertical-align: -4px; }
img.si.big { width: 30px; height: 30px; vertical-align: -6px; }
