:root {
  --bg: #121620;
  --glass: rgba(20, 22, 32, 0.72);
  --glass-strong: rgba(22, 24, 36, 0.92);
  --line: rgba(255, 255, 255, 0.1);
  --text: #f4efe6;
  --muted: rgba(244, 239, 230, 0.62);
  --accent: #ff8a4c;
  --accent-2: #ff4f9a;
  --good: #3ccf91;
  --danger: #ff5a5a;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text); font-family: Nunito, system-ui, sans-serif; -webkit-tap-highlight-color: transparent; }
#stage, #stage canvas { position: fixed; inset: 0; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
kbd { font-family: Fredoka, sans-serif; }
.glass { background: var(--glass); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border: 1px solid var(--line); border-radius: var(--radius); }

/* ---------- top bar */
#topbar { position: fixed; top: 0; left: 0; right: 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: linear-gradient(rgba(10, 12, 18, 0.85), rgba(10, 12, 18, 0)); z-index: 10; pointer-events: none; }
#topbar > * { pointer-events: auto; }
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: linear-gradient(135deg, var(--accent), var(--accent-2)); font-size: 18px; flex: none; box-shadow: 0 4px 14px rgba(255, 79, 154, 0.35); }
#siteName { font-family: Fredoka, sans-serif; font-weight: 700; font-size: 21px; white-space: nowrap; }
.room-chip { font-size: 13px; font-weight: 700; color: var(--muted); padding: 3px 10px; border: 1px solid var(--line); border-radius: 99px; white-space: nowrap; }
.edit-badge { display: none; white-space: nowrap; font-size: 12px; font-weight: 800; background: var(--accent); color: #1a1006; padding: 3px 9px; border-radius: 99px; }
body.edit .edit-badge { display: inline-block; }
nav { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; }
nav::-webkit-scrollbar { display: none; }
.pill { background: var(--glass); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border: 1px solid var(--line); border-radius: 99px; padding: 8px 16px; font-weight: 700; font-size: 15px; white-space: nowrap; transition: transform 0.12s, background 0.2s; }
.pill:hover { background: rgba(50, 54, 72, 0.85); }
.pill:active { transform: scale(0.96); }
.pill.on { background: linear-gradient(135deg, #7a3df0, var(--accent-2)); border-color: transparent; }
.pill.accent { background: linear-gradient(135deg, var(--accent), var(--accent-2)); border-color: transparent; color: #fff; }
.pill.small { padding: 6px 12px; font-size: 13px; }
.pill.big { padding: 13px 26px; font-size: 18px; }
.pill.ghost { background: transparent; }
.pill.danger { color: #fff; background: rgba(255, 90, 90, 0.25); border-color: rgba(255, 90, 90, 0.5); }
.icon { background: rgba(255, 255, 255, 0.08); border: 1px solid var(--line); border-radius: 50%; width: 36px; height: 36px; display: grid; place-items: center; font-size: 14px; flex: none; }
.icon.big { width: 52px; height: 52px; font-size: 18px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); border: none; }
.icon.danger { width: 30px; height: 30px; font-size: 13px; }

/* ---------- now playing */
#nowPlaying { position: fixed; top: 64px; right: 16px; display: flex; align-items: center; gap: 12px; padding: 8px 8px 8px 10px; z-index: 9; cursor: pointer; max-width: 300px; }
.np-art { width: 38px; height: 38px; border-radius: 10px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: flex; align-items: flex-end; justify-content: center; gap: 3px; padding: 8px; flex: none; }
.np-art i { width: 5px; height: 30%; background: #fff; border-radius: 2px; }
#nowPlaying.playing .np-art i { animation: eq 0.9s ease-in-out infinite; }
#nowPlaying.playing .np-art i:nth-child(2) { animation-delay: -0.3s; }
#nowPlaying.playing .np-art i:nth-child(3) { animation-delay: -0.6s; }
@keyframes eq { 0%, 100% { height: 25%; } 50% { height: 100%; } }
.np-text { min-width: 0; }
.np-title { font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.np-artist { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- voice / people */
#btnVoice.on { background: linear-gradient(135deg, #1f9d6a, #3ccf91); border-color: transparent; color: #fff; }
#btnVoice.off { background: rgba(255, 90, 90, 0.25); border-color: rgba(255, 90, 90, 0.5); }
#people { position: fixed; top: 128px; right: 16px; padding: 10px 14px; z-index: 9; font-size: 14px; min-width: 160px; max-width: 240px; }
#people .ph { font-weight: 800; margin-bottom: 4px; }
#people .pp { display: flex; align-items: center; gap: 6px; padding: 2px 0; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#people .pp.speaking { color: #3ccf91; font-weight: 800; }
@media (max-width: 720px) { #people { top: auto; bottom: 150px; left: 16px; right: auto; font-size: 12px; } }

/* ---------- prompt */
#prompt { position: fixed; left: 50%; bottom: 120px; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; padding: 9px 18px 9px 9px; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 99px; font-weight: 800; font-size: 15px; z-index: 8; animation: pop 0.18s ease-out; }
#prompt kbd { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; background: #fff; color: #1a1a22; font-weight: 700; font-size: 15px; }
@keyframes pop { from { transform: translateX(-50%) scale(0.9); opacity: 0; } }

/* ---------- chat / emotes / hints */
#chat { position: fixed; left: 16px; bottom: 44px; width: min(380px, calc(100vw - 180px)); z-index: 8; }
#chatLog p { margin: 0 0 4px; font-size: 14px; text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9); transition: opacity 1.5s; }
#chatLog p.fade { opacity: 0; }
#chatInput { width: 100%; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--glass); color: var(--text); font: inherit; font-size: 15px; outline: none; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
#chatInput:focus { border-color: var(--accent); }
#emotes { position: fixed; right: 16px; bottom: 44px; display: flex; gap: 8px; z-index: 8; }
#emotes button { width: 48px; height: 48px; border-radius: 14px; border: 1px solid var(--line); background: var(--glass); font-size: 22px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); transition: transform 0.12s; }
#btnJump { display: none; font-weight: 800; }
body.touch #btnJump { display: block; }
#emotes button:hover { transform: translateY(-2px); }
#hints { position: fixed; left: 0; right: 0; bottom: 0; padding: 8px 16px; font-size: 13px; color: var(--muted); background: linear-gradient(rgba(10, 12, 18, 0), rgba(10, 12, 18, 0.8)); z-index: 7; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#hints b { color: var(--text); }

/* ---------- joystick (touch) */
#joystick { display: none; position: fixed; left: 24px; bottom: 120px; width: 110px; height: 110px; border-radius: 50%; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.18); z-index: 9; touch-action: none; }
#joystick .knob { position: absolute; left: 50%; top: 50%; width: 48px; height: 48px; margin: -24px 0 0 -24px; border-radius: 50%; background: rgba(255, 255, 255, 0.35); }
body.touch #joystick { display: block; }
body.touch #hints { display: none; }
body.touch #chat { bottom: 16px; }
body.touch #prompt { bottom: 250px; }
body.touch #emotes { bottom: 16px; }
body.building #joystick, body.building #emotes, body.building #chat { display: none; }

/* ---------- drone HUD */
#droneHud { position: fixed; top: 66px; left: 50%; transform: translateX(-50%); display: flex; gap: 14px; align-items: center; padding: 8px 16px; border-radius: 99px; background: rgba(10, 12, 18, 0.72); border: 1px solid var(--line); font: 700 13px/1 ui-monospace, Menlo, monospace; color: #e8f4ff; z-index: 9; white-space: nowrap; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); }
#droneHud b { color: #fff; font-size: 15px; }
#droneHud .rec { color: #ff4d4d; animation: blink 1s steps(2) infinite; }
#droneHud .mode { color: #3dff7a; }
#droneHud .keys { color: var(--muted); font-weight: 600; }
@keyframes blink { 50% { opacity: 0.25; } }
#droneLift { display: none; position: fixed; right: 16px; bottom: 90px; flex-direction: column; gap: 10px; z-index: 9; }
#droneLift button { width: 58px; height: 58px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); font-size: 20px; backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); touch-action: none; }
body.touch.flying #droneLift { display: flex; }
body.flying #emotes { display: none; }
@media (max-width: 720px) { #droneHud { top: auto; bottom: 150px; gap: 10px; font-size: 11px; } #droneHud .keys { display: none; } }

/* ---------- build panel */
#buildPanel { position: fixed; top: 64px; left: 16px; bottom: 44px; width: 300px; padding: 14px; z-index: 9; overflow-y: auto; display: flex; flex-direction: column; gap: 12px; }
.bp-head { display: flex; align-items: center; justify-content: space-between; }
.bp-head h3 { margin: 0; font-family: Fredoka, sans-serif; font-size: 20px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tabs button { border: 1px solid var(--line); background: transparent; border-radius: 99px; padding: 5px 11px; font-size: 13px; font-weight: 700; }
.tabs button.on { background: var(--text); color: #1a1a22; }
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cat-item { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.04); font-size: 12px; font-weight: 700; text-align: center; line-height: 1.15; }
.cat-item:hover { background: rgba(255, 255, 255, 0.1); }
.cat-item.on { border-color: var(--accent); background: rgba(255, 138, 76, 0.18); }
.cat-item .ci { font-size: 26px; }
details summary { cursor: pointer; font-weight: 800; margin-bottom: 8px; }
.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 700; color: var(--muted); margin-bottom: 10px; flex: 1; }
.field input, .field select { padding: 9px 11px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3); color: var(--text); font: inherit; font-size: 15px; outline: none; }
.field input:focus { border-color: var(--accent); }
.row { display: flex; gap: 10px; align-items: flex-end; }
.colors { flex-wrap: wrap; gap: 12px; margin-bottom: 14px; }
.colors label { display: flex; flex-direction: column; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; color: var(--muted); }
input[type=color] { width: 40px; height: 40px; border: 2px solid var(--line); border-radius: 50%; padding: 0; background: none; cursor: pointer; overflow: hidden; }
input[type=color]::-webkit-color-swatch-wrapper { padding: 0; }
input[type=color]::-webkit-color-swatch { border: none; border-radius: 50%; }
.fine { font-size: 12px; color: var(--muted); margin: 0; }
code { background: rgba(255, 255, 255, 0.08); padding: 1px 5px; border-radius: 5px; }

#selPanel { position: fixed; left: 50%; bottom: 44px; transform: translateX(-50%); display: flex; align-items: center; gap: 8px; padding: 8px 10px; z-index: 9; flex-wrap: wrap; justify-content: center; max-width: calc(100vw - 340px); }
#selName { font-weight: 800; padding: 0 6px; }
#selPanel input[type=color] { width: 32px; height: 32px; }
#selPanel input:not([type]) { padding: 7px 10px; border-radius: 9px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.3); color: var(--text); font: inherit; font-size: 14px; width: 150px; }

/* ---------- modals */
.modal { position: fixed; inset: 0; display: none; place-items: center; background: rgba(6, 8, 14, 0.55); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); z-index: 20; padding: 16px; }
.modal.open { display: grid; animation: fade 0.18s ease-out; }
@keyframes fade { from { opacity: 0; } }
.card { position: relative; background: var(--glass-strong); border: 1px solid var(--line); border-radius: 22px; padding: 24px; width: min(420px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.5); }
.card h2 { margin: 0 0 16px; font-family: Fredoka, sans-serif; font-size: 24px; }
.card .close { position: absolute; top: 14px; right: 14px; width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.08); }

.welcome { text-align: center; padding: 34px 28px 26px; }
.welcome h1 { font-family: Fredoka, sans-serif; font-size: 38px; margin: 14px 0 6px; }
.welcome p { color: var(--muted); margin: 0 0 20px; line-height: 1.45; }
.welcome .field { text-align: left; }
.welcome .pill.big { width: 100%; margin: 6px 0 14px; }
.disc { width: 84px; height: 84px; margin: 0 auto; border-radius: 50%; background: radial-gradient(circle, #ffcf4a 0 12%, #111 13% 16%, #1c1c22 17% 100%); box-shadow: inset 0 0 0 6px #26262e, inset 0 0 0 12px #1c1c22, inset 0 0 0 13px #2e2e38, inset 0 0 0 20px #1c1c22, inset 0 0 0 21px #2e2e38, 0 10px 30px rgba(255, 79, 154, 0.35); animation: spin 3s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.jukebox { width: min(620px, 100%); }
#viz { width: 100%; height: 90px; display: block; margin-bottom: 12px; }
.np-big { margin-bottom: 10px; }
#jbTitle { font-family: Fredoka, sans-serif; font-size: 22px; font-weight: 600; }
#jbArtist { color: var(--muted); font-size: 14px; }
.progress { height: 6px; background: rgba(255, 255, 255, 0.1); border-radius: 99px; overflow: hidden; cursor: pointer; margin-bottom: 14px; }
.progress div { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 99px; }
.progress.indef div { opacity: 0.35; }
.transport { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.vol { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 14px; }
.vol input { width: 110px; accent-color: var(--accent); }
#trackList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
#trackList li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; cursor: pointer; }
#trackList li:hover { background: rgba(255, 255, 255, 0.06); }
#trackList li.active { background: rgba(255, 138, 76, 0.14); }
.tn { font-family: Fredoka, sans-serif; color: var(--muted); width: 22px; }
.tt { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.tt small { color: var(--muted); }
.eq { display: none; gap: 2px; align-items: flex-end; height: 16px; }
.eq i { width: 3px; background: var(--accent); border-radius: 1px; animation: eq 0.8s ease-in-out infinite; }
.eq i:nth-child(2) { animation-delay: -0.25s; } .eq i:nth-child(3) { animation-delay: -0.5s; }
#trackList li.playing .eq { display: flex; }

#roomList { list-style: none; margin: 0 0 16px; padding: 0; display: flex; flex-direction: column; gap: 6px; }
#roomList li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; }
#roomList li:hover { background: rgba(255, 255, 255, 0.06); }
#roomList li.active { border-color: var(--accent); }
.sw { width: 34px; height: 34px; border-radius: 9px; flex: none; }
.rn { flex: 1; font-weight: 800; }
.rc { color: var(--muted); font-size: 13px; }

.arcade { width: auto; padding: 16px; text-align: center; }
#arcadeCanvas { display: block; width: min(560px, calc(100vw - 64px)); border-radius: 12px; margin-bottom: 10px; background: #07041a; }

/* ---------- TV channel guide */
.channels { width: min(560px, 100%); }
.channels .fine { margin: -8px 0 14px; }
#channelList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#channelList li { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
#channelList li.on { border-color: #ff0033; }
.ch-tile { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-size: 22px; flex: none; }
.ch-text { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.ch-text small { color: var(--muted); }
#channelList a { text-decoration: none; flex: none; }
.pill.yt { background: #ff0033; border-color: transparent; color: #fff; display: inline-flex; align-items: center; gap: 6px; }
.yt-ic { width: 14px; height: 10px; border-radius: 3px; background: #fff; position: relative; }
.yt-ic::after { content: ''; position: absolute; left: 5px; top: 2px; border-left: 5px solid #ff0033; border-top: 3px solid transparent; border-bottom: 3px solid transparent; }
@media (max-width: 520px) { #channelList li { flex-wrap: wrap; } .ch-text { flex-basis: calc(100% - 60px); } }

/* ---------- favorite books */
.books { width: min(520px, 100%); }
#bookList { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
#bookList li { display: flex; align-items: center; gap: 14px; padding: 10px 12px; border-radius: 12px; background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); }
.bk-spine { width: 14px; height: 48px; border-radius: 3px; flex: none; box-shadow: inset -3px 0 0 rgba(0, 0, 0, 0.25), inset 0 6px 0 rgba(255, 255, 255, 0.18); }
.bk-text { display: flex; flex-direction: column; flex: 1; min-width: 0; gap: 2px; }
.bk-text b { font-size: 15px; }
.bk-text small { color: var(--muted); }
.bk-text em { color: var(--muted); font-size: 13px; }
#bookList a { text-decoration: none; flex: none; }

/* ---------- portal doorway */
.portal { text-align: center; }
.portal h2 { margin: 18px 0 6px; }
.pm-url { color: var(--muted); margin: 0 0 18px; font-weight: 700; }
.portal .pill.big { width: 100%; margin-bottom: 8px; color: #fff; border: none; }
.portal .pill.ghost { width: 100%; }
.pm-ring { --pc: #2f8fe0; width: 96px; height: 96px; margin: 0 auto; border-radius: 50%; background: conic-gradient(from 0deg, var(--pc), #fff, var(--pc), #111, var(--pc)); animation: spin 1.6s linear infinite; box-shadow: 0 0 40px var(--pc); position: relative; }
.pm-ring::after { content: ''; position: absolute; inset: 14px; border-radius: 50%; background: radial-gradient(circle, #fff 0 10%, var(--pc) 40%, #0b0d14 100%); }
#portalFlash { --pc: #2f8fe0; position: fixed; inset: 0; pointer-events: none; z-index: 40; opacity: 0; background: radial-gradient(circle at 50% 55%, #fff 0, var(--pc) 35%, rgba(0, 0, 0, 0.9) 100%); }
#portalFlash.go { animation: portal 0.9s ease-out; }
@keyframes portal { 0% { opacity: 0; transform: scale(0.2); } 25% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(1.6); } }

#toast { position: fixed; top: 74px; left: 50%; transform: translate(-50%, -10px); background: var(--glass-strong); border: 1px solid var(--line); padding: 10px 18px; border-radius: 99px; font-weight: 700; font-size: 14px; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 30; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small screens */
@media (max-width: 720px) {
  #topbar { flex-direction: column; align-items: stretch; gap: 8px; padding: 10px 16px; }
  #siteName { font-size: 18px; }
  .pill { padding: 7px 13px; font-size: 14px; }
  #nowPlaying { top: auto; bottom: 76px; right: 16px; max-width: 220px; }
  body.touch #nowPlaying { bottom: 80px; }
  #chat { width: calc(100vw - 210px); }
  #prompt { bottom: 140px; }
  #buildPanel { top: auto; left: 0; right: 0; bottom: 0; width: auto; max-height: 45vh; border-radius: 18px 18px 0 0; }
  #selPanel { max-width: calc(100vw - 32px); bottom: calc(45vh + 10px); }
  .grid { grid-template-columns: repeat(4, 1fr); }
}
