:root {
  --panel: rgba(24, 26, 40, 0.92);
  --panel-solid: #1c1e2e;
  --line: rgba(255, 255, 255, 0.09);
  --text: #eceef8;
  --muted: #9aa0bd;
  --accent: #6c63ff;
  --accent-2: #8f88ff;
  --green: #2ecc71;
  --red: #ef476f;
  --yellow: #ffd166;
  --radius: 14px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, sans-serif;
  color: var(--text);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #151724; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#world { position: fixed; inset: 0; width: 100%; height: 100%; display: block; cursor: default; }

/* ------------------------------------------------ HUD */
#hud { position: fixed; top: 14px; left: 14px; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
#zone-pill {
  pointer-events: auto; align-self: flex-start;
  display: flex; align-items: center; gap: 8px;
  padding: 8px 14px; border-radius: 999px; background: var(--panel);
  border: 1px solid var(--line); font-size: 13px; font-weight: 600;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
#zone-pill .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); }
#zone-pill.private .dot { background: var(--yellow); }
#zone-pill.private::after { content: "🔒 private"; font-weight: 400; color: var(--muted); margin-left: 2px; }
#minimap {
  pointer-events: auto; width: 192px; height: 120px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--panel); cursor: pointer;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}

/* ------------------------------------------------ video */
#video-strip {
  position: fixed; top: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 10px; max-width: calc(100vw - 480px); overflow-x: auto; padding: 2px;
}
.vtile {
  position: relative; flex: 0 0 auto; width: 168px; height: 112px; border-radius: 12px; overflow: hidden;
  background: #262a40; border: 2px solid transparent; cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,.35); transition: border-color .15s;
}
.vtile.speaking { border-color: var(--green); }
.vtile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.vtile.self video { transform: scaleX(-1); }
.vtile.no-video video { visibility: hidden; position: absolute; }
.vtile .ph { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; }
.vtile.no-video .ph { display: flex; }
.vtile .ph span {
  width: 52px; height: 52px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; font-size: 20px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.3);
}
.vlabel {
  position: absolute; left: 6px; bottom: 6px; right: 6px; display: flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 600; pointer-events: none;
}
.vlabel .nm { background: rgba(0,0,0,.55); padding: 2px 7px; border-radius: 6px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.vlabel .muted { background: var(--red); border-radius: 6px; padding: 1px 5px; font-size: 10px; }
.vlabel .tag { background: var(--accent); border-radius: 6px; padding: 1px 5px; font-size: 10px; }

#spotlight {
  position: fixed; inset: 0; background: rgba(8, 9, 16, .88); display: flex; align-items: center; justify-content: center; z-index: 40;
}
#spotlight video { max-width: 92vw; max-height: 84vh; border-radius: 12px; background: #000; box-shadow: 0 20px 60px rgba(0,0,0,.6); }
#spotlight .spot-label { position: absolute; bottom: 32px; left: 50%; transform: translateX(-50%); background: var(--panel); padding: 8px 14px; border-radius: 999px; font-weight: 600; }
#spotlight .spot-close { position: absolute; top: 20px; right: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: 50%; width: 40px; height: 40px; cursor: pointer; }

/* ------------------------------------------------ toolbar */
#toolbar {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35); z-index: 20;
}
.me { display: flex; align-items: center; gap: 8px; padding-right: 4px; }
#me-avatar { width: 40px; height: 40px; border-radius: 10px; background: #2a2e48; }
#me-name { font-weight: 700; font-size: 13px; max-width: 120px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#status-select {
  background: transparent; border: none; font-size: 12px; padding: 0; cursor: pointer; color: var(--green); outline: none;
}
#status-select.busy { color: var(--red); }
#status-select.away { color: var(--yellow); }
#status-select option { background: var(--panel-solid); color: var(--text); }
.sep { width: 1px; height: 28px; background: var(--line); }
.tool {
  position: relative; width: 44px; height: 44px; border-radius: 12px; border: none; cursor: pointer;
  background: rgba(255,255,255,.06); display: grid; place-items: center; transition: background .15s;
}
.tool:hover { background: rgba(255,255,255,.12); }
.tool svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tool svg .fill { fill: currentColor; stroke: none; }
.tool .slash { display: none; stroke: var(--red); stroke-width: 2.2; }
.tool.off { background: rgba(239, 71, 111, .16); color: #ff9db3; }
.tool.off .slash { display: inline; }
.tool.active { background: var(--accent); color: #fff; }
.badge { position: absolute; top: 4px; right: 4px; min-width: 16px; height: 16px; border-radius: 8px; background: var(--red); font-size: 10px; font-weight: 700; display: grid; place-items: center; padding: 0 4px; }

.emote-wrap { position: relative; }
#emote-menu {
  position: absolute; bottom: 54px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 4px; padding: 6px; background: var(--panel-solid); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
#emote-menu button { width: 40px; height: 40px; border: none; border-radius: 10px; background: transparent; font-size: 22px; cursor: pointer; position: relative; }
#emote-menu button:hover { background: rgba(255,255,255,.1); }
#emote-menu button small { position: absolute; bottom: 1px; right: 4px; font-size: 9px; color: var(--muted); }

/* ------------------------------------------------ sidebar */
#sidebar {
  position: fixed; top: 14px; right: 14px; bottom: 90px; width: 320px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden; z-index: 15;
  box-shadow: 0 10px 30px rgba(0,0,0,.35);
}
#sidebar header { display: flex; align-items: center; gap: 4px; padding: 8px; border-bottom: 1px solid var(--line); }
.tab { flex: 1; border: none; background: transparent; padding: 8px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.tab.active { background: rgba(255,255,255,.08); color: var(--text); }
.count { color: var(--muted); font-weight: 400; }
.icon-btn { border: none; background: transparent; width: 32px; height: 32px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: rgba(255,255,255,.08); }
.tab-body { flex: 1; overflow-y: auto; display: none; }
.tab-body.active { display: flex; flex-direction: column; }

#people-list { list-style: none; margin: 0; padding: 6px; }
#people-list li { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; }
#people-list li:hover { background: rgba(255,255,255,.05); }
#people-list .av { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; position: relative; flex: none; }
#people-list .av::after { content: ""; position: absolute; right: -1px; bottom: -1px; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--panel-solid); background: var(--green); }
#people-list .av.busy::after { background: var(--red); }
#people-list .av.away::after { background: var(--yellow); }
#people-list .info { flex: 1; min-width: 0; }
#people-list .nm { font-weight: 600; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#people-list .where { font-size: 11px; color: var(--muted); }
#people-list .near { color: var(--green); }
#people-list button { border: 1px solid var(--line); background: transparent; border-radius: 8px; padding: 4px 10px; font-size: 12px; cursor: pointer; }
#people-list button:hover { background: rgba(255,255,255,.08); }

#people-list .desk-link { border: none; background: none; padding: 0; font-size: 11px; color: var(--muted); cursor: pointer; }
#people-list .desk-link:hover { color: var(--text); background: none; text-decoration: underline; }
#people-list li > button + button { margin-left: -4px; }

#chat-log, #dm-log { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 10px; }
#tab-chat.active { min-height: 0; }
#convos { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.convo {
  display: inline-flex; align-items: center; gap: 6px; max-width: 100%;
  border: 1px solid var(--line); background: transparent; border-radius: 999px;
  padding: 4px 10px; font-size: 12px; font-weight: 600; color: var(--muted); cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.convo:hover { background: rgba(255,255,255,.06); color: var(--text); }
.convo.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.convo.dm { padding-left: 4px; }
.convo.offline { opacity: .6; }
.mini-av { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; font-size: 9px; font-weight: 800; color: #fff; flex: none; }
.mini-av.offline { filter: grayscale(1); }
.count-badge { min-width: 16px; height: 16px; border-radius: 8px; background: var(--red); color: #fff; font-size: 10px; display: grid; place-items: center; padding: 0 4px; }
#dm-status { font-size: 12px; color: var(--yellow); }
#chat-input:disabled { opacity: .5; }
.msg .meta .scope.slack { background: rgba(224, 30, 90, .16); color: #ff7aa8; }
.msg .meta { font-size: 11px; color: var(--muted); display: flex; gap: 6px; align-items: baseline; }
.msg .meta b { color: var(--text); font-size: 12px; }
.msg .meta .scope { font-size: 10px; padding: 0 5px; border-radius: 4px; background: rgba(46, 204, 113, .15); color: var(--green); }
.msg .body { font-size: 13px; line-height: 1.4; word-wrap: break-word; white-space: pre-wrap; }
.msg.system .body { color: var(--muted); font-style: italic; font-size: 12px; }
#chat-form { border-top: 1px solid var(--line); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
#chat-form .scope { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
#chat-form .scope input { accent-color: var(--accent); }
#chat-input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.25); outline: none; }
#chat-input:focus { border-color: var(--accent); }

/* ------------------------------------------------ toasts & banner */
#toasts { position: fixed; bottom: 92px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; pointer-events: none; z-index: 30; }
.toast { background: var(--panel-solid); border: 1px solid var(--line); padding: 8px 14px; border-radius: 10px; font-size: 13px; animation: toast-in .2s ease-out; box-shadow: 0 8px 20px rgba(0,0,0,.3); }
.toast.out { opacity: 0; transition: opacity .3s; }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } }
#banner { position: fixed; top: 0; left: 0; right: 0; text-align: center; padding: 8px; background: var(--red); font-weight: 600; z-index: 50; }

/* ------------------------------------------------ join */
/* Scrolls when the card is taller than the screen (phones); margin:auto centres it otherwise
   without cutting off the top, which grid centring would do. */
#join {
  position: fixed; inset: 0; display: flex; flex-direction: column; padding: 16px 0;
  overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch;
  background: rgba(12, 13, 24, .55); backdrop-filter: blur(3px); z-index: 60;
}
#join-card {
  margin: auto; flex-shrink: 0;
  width: min(560px, calc(100vw - 32px)); background: var(--panel-solid); border: 1px solid var(--line);
  border-radius: 20px; padding: 26px 28px; box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.brand { display: flex; align-items: center; gap: 10px; font-size: 22px; font-weight: 800; letter-spacing: -.3px; }
.logo { width: 28px; height: 28px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), #f15bb5); }
.sub { color: var(--muted); margin: 6px 0 18px; font-size: 14px; }
.join-grid { display: grid; grid-template-columns: 170px 1fr; gap: 20px; }
.preview-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
#preview { width: 170px; height: 170px; border-radius: 16px; background: radial-gradient(circle at 50% 60%, #3a3f63, #22253a); }
.hint { font-size: 11px; color: var(--muted); }
.fields { display: flex; flex-direction: column; gap: 10px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; font-weight: 600; color: var(--muted); }
.field input { padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(0,0,0,.25); outline: none; font-size: 14px; color: var(--text); font-weight: 500; }
.field input:focus { border-color: var(--accent); }
.field .error { color: var(--red); font-weight: 500; }
.swatches, .styles { display: flex; flex-wrap: wrap; gap: 6px; }
.swatches button { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0; box-shadow: inset 0 0 0 1px rgba(0,0,0,.2); }
.swatches button.sel { border-color: #fff; transform: scale(1.12); }
.styles button { border: 1px solid var(--line); background: transparent; padding: 4px 10px; border-radius: 8px; font-size: 12px; cursor: pointer; text-transform: capitalize; }
.styles button.sel { background: var(--accent); border-color: var(--accent); }
.join-media { display: flex; gap: 22px; margin: 20px 0 16px; font-size: 14px; }
.switch { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.switch input { display: none; }
.switch span { width: 34px; height: 20px; border-radius: 10px; background: #3a3e5a; position: relative; transition: background .15s; }
.switch span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(14px); }
.primary { width: 100%; padding: 13px; border: none; border-radius: 12px; background: var(--accent); font-weight: 700; font-size: 15px; cursor: pointer; transition: background .15s; }
.primary:hover { background: var(--accent-2); }
.primary:disabled { opacity: .6; cursor: wait; }

@media (max-width: 900px) {
  #video-strip { max-width: calc(100vw - 28px); top: 150px; }
  #sidebar { width: calc(100vw - 28px); }
  .join-grid { grid-template-columns: 1fr; }
}

/* Phones: a compact join card with bigger tap targets */
@media (max-width: 600px) {
  #join { padding: 10px 0; }
  #join-card { width: calc(100vw - 20px); padding: 18px 16px; border-radius: 16px; }
  .sub { margin: 4px 0 12px; font-size: 13px; }
  .join-grid { gap: 12px; }
  #preview { width: 120px; height: 120px; }
  .field input { font-size: 16px; } /* 16px stops iOS zooming in on focus */
  .swatches, .styles { gap: 8px; }
  .swatches button { width: 30px; height: 30px; }
  .styles button { padding: 7px 12px; font-size: 13px; }
  .join-media { margin: 16px 0 12px; }
}

/* ------------------------------------------------ context hint, toasts */
#hint {
  position: fixed; bottom: 88px; left: 50%; transform: translateX(-50%); z-index: 19; pointer-events: none;
  background: rgba(255, 214, 102, .95); color: #1d1f2e; font-weight: 700; font-size: 13px;
  padding: 7px 14px; border-radius: 999px; box-shadow: 0 8px 20px rgba(0,0,0,.3); white-space: nowrap;
}
#hint:not([hidden]) ~ #toasts { bottom: 128px; }
.toast.clickable { pointer-events: auto; cursor: pointer; }
.toast.clickable:hover { border-color: var(--accent); }

/* ------------------------------------------------ dialogs, games, desks, help */
#modal { position: fixed; inset: 0; z-index: 45; display: grid; place-items: center; background: rgba(8, 9, 16, .6); backdrop-filter: blur(2px); }
.modal-card {
  width: min(440px, calc(100vw - 32px)); max-height: calc(100vh - 40px); display: flex; flex-direction: column;
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 30px 80px rgba(0,0,0,.5);
}
.modal-card.wide { width: min(980px, calc(100vw - 32px)); }
.modal-card > header { display: flex; align-items: center; gap: 8px; padding: 14px 14px 10px 20px; }
.modal-card h2 { flex: 1; margin: 0; font-size: 17px; }
#modal-body { padding: 0 20px 20px; overflow: auto; }
.muted { color: var(--muted); font-size: 13px; line-height: 1.45; }
.note-text { white-space: pre-wrap; line-height: 1.55; font-size: 14px; }

.game-wrap { display: flex; gap: 16px; align-items: flex-start; }
.game-host { flex: 1; min-width: 0; min-height: 360px; border-radius: 12px; background: #11131f; overflow: hidden; position: relative; }
.leaderboard { width: 220px; flex: none; }
.leaderboard h3 { margin: 4px 0 8px; font-size: 14px; }
.leaderboard p { margin: 0 0 10px; }
.leaderboard ol { margin: 0; padding: 0 0 0 22px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.leaderboard li { padding: 3px 6px; border-radius: 6px; }
.leaderboard li > span { display: inline-flex; }
.leaderboard li .nm { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.leaderboard li .sc { float: right; font-variant-numeric: tabular-nums; color: var(--yellow); font-weight: 700; }
.leaderboard li.mine { background: rgba(108, 99, 255, .25); }
.leaderboard li.empty { list-style: none; margin-left: -22px; color: var(--muted); }

.decor-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin: 12px 0 16px; }
.decor-grid button, .modal-actions button {
  border: 1px solid var(--line); background: rgba(255,255,255,.04); border-radius: 10px; padding: 9px 10px; font-size: 13px; cursor: pointer; text-align: left;
}
.decor-grid button:hover:not(:disabled) { background: rgba(255,255,255,.1); }
.decor-grid button.sel { background: var(--accent); border-color: var(--accent); color: #fff; }
.decor-grid button:disabled { opacity: .4; cursor: default; }
.modal-actions { display: flex; justify-content: flex-end; }
.modal-actions .danger { color: #ff9db3; border-color: rgba(239, 71, 111, .4); }
.modal-actions .danger:hover { background: rgba(239, 71, 111, .16); }

dl.keys { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 4px 0 14px; font-size: 13px; align-items: center; }
dl.keys dt { display: flex; gap: 4px; flex-wrap: wrap; white-space: nowrap; }
dl.keys dd { margin: 0; }
kbd { display: inline-block; padding: 2px 7px; border-radius: 6px; background: rgba(255,255,255,.08); border: 1px solid var(--line); border-bottom-width: 2px; font-family: inherit; font-size: 11px; font-weight: 600; line-height: 1.4; color: var(--text); }

@media (max-width: 700px) {
  .game-wrap { flex-direction: column; }
  .leaderboard { width: 100%; }
}
