:root {
  --bg: #0d0b1e;
  --panel: rgba(28, 22, 58, .55);
  --line: rgba(255, 255, 255, .12);
  --text: #eeeaff;
  --muted: #a49cc9;
  --accent: #8b5cff;
  --accent2: #22d3ee;
  --grad: linear-gradient(135deg, #8b5cff, #22d3ee);
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body { font-family: 'Outfit', sans-serif; background: var(--bg); color: var(--text); }
[hidden] { display: none !important; }

.glass { background: var(--panel); backdrop-filter: blur(16px); border: 1px solid var(--line); border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,.4); }

/* Lobby */
#lobby { position: fixed; inset: 0; display: grid; place-items: center; overflow: auto; padding: 20px;
  background: radial-gradient(circle at 20% 20%, #2a1b6b 0, transparent 50%), radial-gradient(circle at 80% 80%, #0e4a5c 0, transparent 50%), var(--bg); }
.bg-shapes i { position: absolute; width: 180px; height: 180px; background: var(--grad); opacity: .15; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); animation: float 12s ease-in-out infinite; }
.bg-shapes i:nth-child(1) { top: 8%; left: 8%; }
.bg-shapes i:nth-child(2) { bottom: 10%; right: 6%; width: 260px; height: 260px; animation-delay: -3s; }
.bg-shapes i:nth-child(3) { top: 60%; left: 15%; width: 90px; height: 90px; animation-delay: -6s; }
.bg-shapes i:nth-child(4) { top: 12%; right: 20%; width: 120px; height: 120px; animation-delay: -9s; }
@keyframes float { 50% { transform: translateY(-30px) rotate(30deg); } }

.card { position: relative; width: min(760px, 100%); padding: 32px; animation: rise .6s ease; }
@keyframes rise { from { opacity: 0; transform: translateY(20px); } }
h1 { font-size: 46px; font-weight: 900; letter-spacing: -1px; }
h1 span, .brand span { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.sub { color: var(--muted); margin: 4px 0 20px; }
.lobby-grid { display: grid; grid-template-columns: 220px 1fr; gap: 24px; margin-bottom: 18px; }
.preview-wrap { background: radial-gradient(circle, rgba(139,92,255,.25), transparent 70%); border-radius: 16px; border: 1px solid var(--line); }
label { display: block; font-size: 12px; text-transform: uppercase; letter-spacing: 2px; color: var(--muted); margin: 10px 0 6px; }
input { width: 100%; margin-top: 6px; padding: 12px 14px; background: rgba(0,0,0,.3); border: 1px solid var(--line); border-radius: 12px; color: var(--text); font: inherit; font-size: 15px; outline: none; transition: border .2s; text-transform: none; letter-spacing: 0; }
input:focus { border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255,255,255,.04); color: var(--text); cursor: pointer; font: inherit; font-size: 14px; transition: .2s; }
.chip:hover { transform: translateY(-2px); border-color: var(--accent); }
.chip.on { background: var(--grad); border-color: transparent; }
.swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.sw { width: 30px; height: 30px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; transition: .2s; clip-path: polygon(50% 0, 100% 25%, 100% 75%, 50% 100%, 0 75%, 0 25%); }
.sw:hover { transform: scale(1.15); }
.sw.on { transform: scale(1.25); filter: drop-shadow(0 0 6px #fff) brightness(1.2); }
.rooms { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 20px; }
.room-card { padding: 14px 10px; border-radius: 14px; border: 1px solid var(--line); cursor: pointer; text-align: center; transition: .25s; position: relative; overflow: hidden; }
.room-card:hover { transform: translateY(-4px); }
.room-card.on { border-color: #fff; box-shadow: 0 0 0 2px var(--accent), 0 10px 30px rgba(139,92,255,.4); }
.room-card b { display: block; font-size: 22px; }
.room-card span { font-size: 13px; }
.room-card small { display: block; color: rgba(255,255,255,.7); font-size: 11px; margin-top: 2px; }
.btn { width: 100%; padding: 15px; border: 0; border-radius: 14px; background: var(--grad); color: #fff; font: 700 17px 'Outfit'; cursor: pointer; transition: .2s; box-shadow: 0 10px 30px rgba(139,92,255,.35); }
.btn:hover { transform: translateY(-2px); filter: brightness(1.1); }
.btn:disabled { opacity: .5; cursor: wait; }
.btn.sm { width: auto; padding: 10px 16px; font-size: 14px; }
.status { text-align: center; color: var(--muted); font-size: 13px; margin-top: 10px; }

/* Game */
#game { position: fixed; inset: 0; }
#world { position: absolute; inset: 0; width: 100%; height: 100%; cursor: pointer; touch-action: none; }
.topbar { position: absolute; top: 14px; left: 14px; right: 14px; display: flex; align-items: center; gap: 16px; padding: 10px 18px; z-index: 10; }
.brand { font-weight: 900; font-size: 22px; }
.menu-panel { display: flex; align-items: center; gap: 16px; flex: 1; }
#room-tabs { display: flex; gap: 6px; flex: 1; justify-content: center; flex-wrap: wrap; }
.cur-room { display: none; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.menu-toggle { display: none; width: 44px; height: 44px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255,255,255,.06); cursor: pointer; position: relative; flex-shrink: 0; }
.menu-toggle i { position: absolute; left: 12px; right: 12px; height: 2px; border-radius: 2px; background: var(--text); transition: transform .3s, opacity .2s, top .3s; }
.menu-toggle i:nth-child(1) { top: 14px; } .menu-toggle i:nth-child(2) { top: 21px; } .menu-toggle i:nth-child(3) { top: 28px; }
.topbar.open .menu-toggle { background: var(--grad); border-color: transparent; }
.topbar.open .menu-toggle i:nth-child(1) { top: 21px; transform: rotate(45deg); }
.topbar.open .menu-toggle i:nth-child(2) { opacity: 0; }
.topbar.open .menu-toggle i:nth-child(3) { top: 21px; transform: rotate(-45deg); }
.voice-ctl { display: flex; gap: 6px; }
.chip.voice.live { background: linear-gradient(135deg, #10b981, #22d3ee); border-color: transparent; animation: pulse 2s infinite; }
.chip.muted { background: #e11d48; border-color: transparent; }
@keyframes pulse { 50% { box-shadow: 0 0 0 6px rgba(16,185,129,.25); } }
.online { font-size: 13px; color: var(--muted); white-space: nowrap; }
.online::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: #34d399; margin-right: 6px; box-shadow: 0 0 8px #34d399; }
.chat { position: absolute; left: 14px; bottom: 14px; width: min(360px, calc(100% - 28px)); padding: 12px; display: flex; flex-direction: column; gap: 8px; }
#chat-log { height: 200px; overflow-y: auto; font-size: 14px; display: flex; flex-direction: column; gap: 4px; padding-right: 4px; }
#chat-log::-webkit-scrollbar { width: 4px; } #chat-log::-webkit-scrollbar-thumb { background: var(--line); border-radius: 4px; }
.msg { animation: rise .25s ease; line-height: 1.35; word-wrap: break-word; }
.msg b { margin-right: 4px; }
.msg.sys { color: var(--muted); font-style: italic; font-size: 13px; }
#chat-form { display: flex; gap: 6px; }
#chat-form input { margin: 0; }
.emotes { display: flex; gap: 4px; }
.emotes button { flex: 1; background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 10px; padding: 6px; font-size: 18px; cursor: pointer; transition: .15s; }
.emotes button:hover { transform: scale(1.15); background: rgba(255,255,255,.12); }
.hint { position: absolute; right: 14px; bottom: 14px; padding: 10px 16px; font-size: 13px; color: var(--muted); }

@media (max-width: 820px) {
  .topbar { top: 10px; left: 10px; right: 10px; padding: 8px 10px 8px 16px; gap: 10px; flex-wrap: wrap; }
  .brand { font-size: 18px; }
  .cur-room { display: block; font-size: 14px; color: var(--muted); }
  .menu-toggle { display: block; }
  .menu-panel { flex-basis: 100%; flex-direction: column; align-items: stretch; gap: 12px;
    max-height: 0; opacity: 0; overflow: hidden; pointer-events: none; transform: translateY(-8px);
    transition: max-height .35s ease, opacity .25s ease, transform .3s ease, padding .3s; }
  .topbar.open .menu-panel { max-height: 80vh; opacity: 1; pointer-events: auto; transform: none; padding: 6px 0 8px; overflow-y: auto; }
  #room-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  #room-tabs .chip, .voice-ctl .chip { padding: 12px; font-size: 15px; border-radius: 14px; text-align: center; }
  .voice-ctl { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
  .voice-ctl .chip:only-child, .voice-ctl .chip[hidden] + * , .voice-ctl #voice-btn:has(+ [hidden]) { grid-column: 1 / -1; }
  .online { text-align: center; }
  .hint { display: none; }
}
@media (max-width: 640px) {
  .lobby-grid { grid-template-columns: 1fr; } .preview-wrap { display: flex; justify-content: center; }
  .rooms { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 22px; } h1 { font-size: 36px; }
  .chat { left: 10px; bottom: 10px; width: calc(100% - 20px); padding: 10px; }
  #chat-log { height: 110px; }
  #chat-form input { font-size: 16px; } /* prevents iOS zoom */
}
