:root {
  --bg: #0b0716;
  --panel: rgba(16, 10, 34, .82);
  --panel-solid: #140c2a;
  --ink: #ece8f7;
  --muted: #b7aed3;
  --violet: #9b5cff;
  --cyan: #3fe0f0;
  --gold: #f2c35b;
  --danger: #ff6b8a;
  --focus: #ffe08a;
  --tile-h: clamp(84px, 16vh, 150px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
[hidden] { display: none !important; }

.skip-link { position: absolute; left: 1rem; top: -4rem; background: var(--gold); color: #1a1030; padding: .5rem 1rem; border-radius: 6px; z-index: 50; }
.skip-link:focus { top: 1rem; }

button {
  cursor: pointer;
  border: 1px solid rgba(255, 255, 255, .18);
  background: rgba(255, 255, 255, .06);
  color: var(--ink);
  padding: .55rem 1rem;
  border-radius: 999px;
  min-height: 44px;
}
button:hover { background: rgba(255, 255, 255, .12); }
button.primary { background: linear-gradient(135deg, var(--violet), #6b3fd6); border-color: transparent; font-weight: 600; }
button.danger { border-color: rgba(255, 107, 138, .5); color: #ffd2dc; }
button[aria-pressed="false"].toggle-off, button.off { background: rgba(255, 107, 138, .16); border-color: rgba(255, 107, 138, .45); }
button:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Lobby ---------- */
.lobby {
  min-height: 100vh;
  min-height: 100svh;
  display: grid;
  place-items: center;
  padding: 1.5rem 1rem;
  background:
    radial-gradient(ellipse 80% 60% at 50% 20%, rgba(155, 92, 255, .35), transparent 70%),
    radial-gradient(ellipse 60% 40% at 50% 100%, rgba(63, 224, 240, .2), transparent 70%),
    var(--bg);
}
.lobby-card { width: min(34rem, 100%); background: var(--panel); border: 1px solid rgba(255, 255, 255, .1); border-radius: 18px; padding: 1.75rem; }
.lobby-card h1 { margin: .25rem 0 .5rem; font-size: clamp(1.6rem, 4vw, 2.2rem); }
.eyebrow { margin: 0; color: var(--cyan); letter-spacing: .12em; text-transform: uppercase; font-size: .75rem; }
.lobby-card label { display: block; margin-top: 1rem; color: var(--muted); font-size: .9rem; }
.lobby-card input { width: 100%; margin-top: .35rem; padding: .7rem .9rem; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .2); background: rgba(0, 0, 0, .3); color: var(--ink); }
.enter-options { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: 1.25rem; }
.fine-print { color: var(--muted); font-size: .82rem; margin-top: 1.25rem; }
.lobby-error { color: var(--danger); min-height: 1.5em; margin: .5rem 0 0; }

/* ---------- World ---------- */
.world { display: flex; flex-direction: column; height: 100vh; height: 100svh; overflow: hidden; }
.room-header { position: relative; z-index: 3; display: flex; align-items: baseline; gap: 1rem; flex-wrap: wrap; padding: .6rem 1rem .4rem; }
.room-header h1 { margin: 0; font-size: clamp(1.1rem, 3vw, 1.5rem); }
.room-meta { margin: 0; color: var(--muted); font-size: .9rem; }
.room-actions { display: flex; flex-wrap: wrap; gap: .4rem; margin-left: auto; }
button.small { min-height: 36px; padding: .3rem .8rem; font-size: .85rem; }
button[aria-pressed="true"].small { background: rgba(242, 195, 91, .2); border-color: rgba(242, 195, 91, .6); }

/* Text list of doors: keyboard/screen-reader friendly and usable on small screens. */
.door-list { display: flex; flex-wrap: wrap; justify-content: center; gap: .4rem; margin: .45rem 1rem 0; }
.door-list button { min-height: 36px; padding: .25rem .75rem; font-size: .82rem; }
.door-list .door-occ { color: var(--cyan); margin-left: .35rem; }
.status { margin: 0 1rem .4rem; padding: .35rem .8rem; border-radius: 999px; background: rgba(242, 195, 91, .15); color: var(--gold); font-size: .85rem; align-self: flex-start; }

.stage-wrap { flex: 1 1 auto; min-height: 0; display: grid; place-items: center; padding: 0 .5rem; container-type: size; overflow: hidden; }
/*
 * 16:9 box sized from the space actually left for it (container query units), so header, door
 * list, tiles and controls can grow without the stage overflowing over them. Door hotspots use
 * percentages of this box so they line up with the art.
 */
.stage {
  position: relative;
  width: min(100cqw, 100cqh * 16 / 9);
  aspect-ratio: 16 / 9;
  border-radius: 14px;
  overflow: hidden;
  background: #120a24;
  box-shadow: 0 10px 40px rgba(0, 0, 0, .5);
}
.bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity .6s ease; }
.bg.visible { opacity: 1; }
.stage.moving .bg.visible { filter: brightness(.6) saturate(.8); transition: opacity .6s ease, filter .3s ease; }
.doors { position: absolute; inset: 0; }
.door {
  position: absolute;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  border: 2px solid transparent;
  background: transparent;
  border-radius: 12px 12px 4px 4px;
  padding: .25rem;
  min-height: 0;
  color: var(--ink);
  transition: border-color .15s ease, background .15s ease;
}
.door:hover, .door:focus-visible { border-color: rgba(63, 224, 240, .8); background: rgba(63, 224, 240, .1); }
.door .door-label {
  background: rgba(10, 6, 22, .85);
  border-radius: 8px;
  padding: .15rem .5rem;
  font-size: clamp(.65rem, 1.4vw, .85rem);
  line-height: 1.3;
  text-align: center;
}
.door .door-occ { display: block; color: var(--cyan); font-size: .9em; }
.door.locked .door-occ { color: var(--gold); }
.door.target { border-color: var(--gold); background: rgba(242, 195, 91, .15); }
.room-desc { position: absolute; left: .75rem; top: .6rem; margin: 0; max-width: 60%; font-size: clamp(.7rem, 1.4vw, .9rem); color: rgba(236, 232, 247, .85); text-shadow: 0 1px 6px #000; }

/* ---------- Structured rooms (M5D audio domains): tables, stage, reactions ---------- */
.seats { position: absolute; inset: 0; pointer-events: none; }
.seat {
  position: absolute; transform: translate(-50%, -50%); pointer-events: auto;
  min-height: 0; padding: .2rem .55rem; border-radius: 999px; font-size: clamp(.6rem, 1.3vw, .8rem);
  background: rgba(10, 6, 22, .82); border: 2px solid rgba(63, 224, 240, .35); color: var(--ink);
}
.seat .seat-occ { display: block; color: var(--cyan); font-size: .9em; }
.seat:hover, .seat:focus-visible { border-color: rgba(63, 224, 240, .9); }
.seat.here { border-color: var(--gold); background: rgba(242, 195, 91, .2); }
.seat.full:not(.here) { opacity: .6; }
.seat[data-kind="stage"] { border-color: rgba(255, 107, 138, .6); }
.domain-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: .4rem; margin: .45rem 1rem 0; font-size: .85rem; }
.domain-where { color: var(--cyan); }
.reactions { display: inline-flex; gap: .25rem; }
.reactions button { min-height: 32px; padding: .1rem .5rem; font-size: 1rem; }
.ambience-meter { color: var(--gold); min-width: 4ch; }
.hands-wrap { margin: .4rem 1rem 0; padding: .4rem .8rem; border-radius: 10px; background: rgba(242, 195, 91, .08); }
.hands-wrap h3 { margin: 0 0 .3rem; font-size: .85rem; }
.hands { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .25rem; font-size: .85rem; }
.hands li { display: flex; align-items: center; gap: .5rem; }
.tile.speaker::after { content: 'on stage'; position: absolute; left: .4rem; top: .3rem; font-size: .65rem; background: rgba(255, 107, 138, .85); color: #fff; padding: 0 .3rem; border-radius: 4px; }

/* ---------- Venue stage (live broadcast, visible in every room) ---------- */
.stage-panel { position: absolute; right: .6rem; top: .6rem; width: min(38%, 26rem); background: rgba(10, 6, 22, .88); border: 1px solid rgba(255, 107, 138, .45); border-radius: 12px; padding: .4rem; z-index: 2; box-shadow: 0 8px 30px rgba(0, 0, 0, .5); }
.stage-head { display: flex; align-items: center; gap: .4rem; font-size: .8rem; }
.live-dot { background: #e0244a; color: #fff; font-weight: 700; font-size: .65rem; padding: .05rem .35rem; border-radius: 4px; letter-spacing: .05em; }
.stage-title { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-video { display: block; width: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #000; border-radius: 8px; margin-top: .35rem; }
.stage-state { margin: .3rem 0 0; font-size: .75rem; color: var(--gold); min-height: 1em; }
.stage-volume { display: flex; align-items: center; gap: .4rem; font-size: .72rem; color: var(--muted); margin-top: .2rem; }
.stage-volume input { flex: 1; }
.stage-panel.collapsed .stage-video, .stage-panel.collapsed .stage-volume { display: none; }
.device-panel .check { display: flex; gap: .5rem; align-items: flex-start; font-size: .8rem; }

.banner { margin: .4rem 1rem 0; padding: .4rem .8rem; border-radius: 10px; background: rgba(63, 224, 240, .1); color: var(--cyan); font-size: .85rem; }

/* ---------- Tiles along the bottom ---------- */
.tiles { list-style: none; display: flex; gap: .5rem; margin: .5rem 0 0; padding: 0 1rem; overflow-x: auto; min-height: var(--tile-h); scrollbar-width: thin; }
.tile {
  position: relative;
  flex: 0 0 auto;
  height: var(--tile-h);
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  background: linear-gradient(160deg, #2a1a52, #120a24);
  border: 2px solid rgba(255, 255, 255, .08);
}
.tile.self { border-color: rgba(155, 92, 255, .6); }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; background: #000; }
.tile.self video { transform: scaleX(-1); }
.tile .avatar { position: absolute; inset: 0; display: grid; place-items: center; font-size: calc(var(--tile-h) * .35); font-weight: 700; color: rgba(255, 255, 255, .8); }
.tile .name { position: absolute; left: .35rem; bottom: .3rem; max-width: calc(100% - .7rem); padding: .05rem .45rem; border-radius: 6px; background: rgba(0, 0, 0, .6); font-size: .75rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .badge { position: absolute; right: .3rem; top: .3rem; padding: .05rem .4rem; border-radius: 6px; background: rgba(0, 0, 0, .65); font-size: .68rem; color: var(--gold); }
.tile .badge.ok { color: var(--cyan); }
.tile.speaking { border-color: var(--cyan); box-shadow: 0 0 0 2px rgba(63, 224, 240, .55), 0 0 18px rgba(63, 224, 240, .35); }
.tile .host-mark { position: absolute; left: .35rem; bottom: 1.7rem; padding: 0 .4rem; border-radius: 6px; background: rgba(242, 195, 91, .9); color: #1a1030; font-size: .65rem; font-weight: 700; }
.tile .remove { position: absolute; right: .3rem; bottom: .3rem; min-height: 28px; padding: .1rem .5rem; font-size: .7rem; background: rgba(0, 0, 0, .7); border-color: rgba(255, 107, 138, .6); opacity: 0; }
.tile:hover .remove, .tile:focus-within .remove { opacity: 1; }
.tile .muted-mark { position: absolute; left: .35rem; top: .3rem; padding: .05rem .35rem; border-radius: 6px; background: rgba(255, 107, 138, .85); font-size: .65rem; }

/* ---------- Controls ---------- */
.controls { position: relative; display: flex; flex-wrap: wrap; justify-content: center; gap: .5rem; padding: .6rem 1rem calc(.6rem + env(safe-area-inset-bottom)); }
.device-panel { position: absolute; bottom: calc(100% + .25rem); left: 50%; transform: translateX(-50%); display: grid; gap: .5rem; background: var(--panel-solid); border: 1px solid rgba(255, 255, 255, .15); border-radius: 12px; padding: .75rem; width: min(22rem, calc(100vw - 2rem)); z-index: 10; }
.device-panel label { display: grid; gap: .25rem; font-size: .85rem; color: var(--muted); }
.device-panel select { padding: .4rem; border-radius: 8px; background: #1d1238; color: var(--ink); border: 1px solid rgba(255, 255, 255, .2); }

.toasts { position: fixed; bottom: calc(var(--tile-h) + 5.5rem); left: 50%; transform: translateX(-50%); display: grid; gap: .5rem; width: min(22rem, calc(100vw - 1.5rem)); z-index: 20; pointer-events: none; } /* text only: never block the controls underneath */
.toast { background: var(--panel-solid); border: 1px solid rgba(255, 255, 255, .15); border-left: 4px solid var(--gold); border-radius: 10px; padding: .6rem .8rem; font-size: .88rem; box-shadow: 0 6px 20px rgba(0, 0, 0, .4); }
.toast.error { border-left-color: var(--danger); }

.diag { position: fixed; left: .5rem; bottom: .5rem; max-width: min(40rem, calc(100vw - 1rem)); max-height: 45vh; overflow: auto; margin: 0; padding: .5rem; background: rgba(0, 0, 0, .85); color: #b9f5d0; font-size: .7rem; border-radius: 8px; z-index: 30; }

@media (max-width: 640px) {
  :root { --tile-h: 76px; }
  .stage { width: 100%; }
  .room-desc { display: none; }
  /* Natural top-to-bottom flow on phones: room, doors, people, controls. No dead space. */
  .world { height: auto; min-height: 100svh; overflow: visible; }
  .stage-wrap { flex: none; display: block; padding: 0 .5rem; container-type: normal; overflow: visible; }
  .toasts { top: auto; bottom: 5.5rem; }
  /* Hotspots get small on phones: the door list below the stage is the primary navigation. */
  .door .door-label { display: none; }
  .room-actions { margin-left: 0; }
  .tile .remove { opacity: 1; }
  .stage-panel { width: 56%; right: .3rem; top: .3rem; }
  .controls button { padding: .45rem .8rem; }
}

@media (prefers-reduced-motion: reduce) {
  .bg { transition: none; }
}

/* ---------- Community (M3): account, directory, spaces, reports, moderation ---------- */
.lobby-cards { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; align-items: flex-start; width: min(70rem, 100%); }
.lobby-cards > .lobby-card { flex: 1 1 24rem; max-width: 34rem; }
.lobby-error.ok { color: var(--cyan); }
.lobby-card h2 { margin: 1.25rem 0 .4rem; font-size: 1rem; color: var(--gold); }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.lobby-card .row input { flex: 1 1 12rem; width: auto; margin-top: 0; }
.account-state { margin: 0; }
.signin-form label { margin-top: .9rem; }
.signin-intro { margin: 0 0 .75rem; }
/* Google sign-in button per Google's branding guidelines (dark theme, pill shape):
   fill #131314, 1px #8E918F stroke, #E3E3E3 text, Roboto Medium 14/20, 20px logo, 12px/10px spacing. */
.gsi-button {
  display: inline-flex; align-items: center; gap: 10px; height: 40px; padding: 0 12px;
  background: #131314; border: 1px solid #8E918F; border-radius: 20px; color: #E3E3E3;
  font-family: Roboto, arial, sans-serif; font-weight: 500; font-size: 14px; line-height: 20px; letter-spacing: .25px;
  text-decoration: none; white-space: nowrap; transition: background-color .218s, border-color .218s;
}
.gsi-button:hover { background: #1d1d1f; box-shadow: 0 1px 2px rgba(60, 64, 67, .3), 0 1px 3px 1px rgba(60, 64, 67, .15); }
.gsi-button:active { background: #2a2a2c; }
.gsi-icon { display: inline-flex; width: 20px; height: 20px; }
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: .4rem; }
.list > li { background: rgba(255, 255, 255, .04); border: 1px solid rgba(255, 255, 255, .08); border-radius: 10px; padding: .5rem .7rem; }
.list .item-title { font-weight: 600; }
.list .item-sub { color: var(--muted); font-size: .82rem; }
.list .row { margin-top: .3rem; }
.list .empty { background: none; border: none; color: var(--muted); font-size: .85rem; padding: 0; }
.destination { color: var(--cyan); margin: .75rem 0 0; }
.space-form label, .dialog label { display: block; margin-top: .6rem; color: var(--muted); font-size: .88rem; }
.space-form input, .space-form select, .dialog select, .dialog textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .7rem; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .2); background: rgba(0, 0, 0, .3); color: var(--ink); font: inherit;
}
.space-form button { margin-top: .9rem; }
details summary { cursor: pointer; margin-top: .9rem; color: var(--cyan); }
.check { display: flex !important; gap: .5rem; align-items: flex-start; }
.check input { width: auto !important; margin-top: .3rem !important; }
.button-link { display: inline-flex; align-items: center; min-height: 36px; padding: .3rem .9rem; border-radius: 999px; border: 1px solid rgba(255, 255, 255, .18); color: var(--ink); text-decoration: none; font-size: .88rem; }
.button-link:hover { background: rgba(255, 255, 255, .12); }
a { color: var(--cyan); }
.dialog { width: min(30rem, calc(100vw - 2rem)); max-height: min(80vh, 40rem); overflow: auto; background: var(--panel-solid); color: var(--ink); border: 1px solid rgba(255, 255, 255, .15); border-radius: 14px; padding: 1.1rem 1.25rem; }
.dialog::backdrop { background: rgba(5, 2, 12, .65); }
.dialog h2 { margin: 0 0 .4rem; font-size: 1.1rem; }
.dialog h3 { margin: 1rem 0 .4rem; font-size: .95rem; color: var(--gold); }
.dialog .row { margin-top: 1rem; justify-content: flex-end; }
.dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.tile .verified { margin-left: .25rem; color: var(--cyan); }
.tile .tile-actions { position: absolute; right: .3rem; top: 1.6rem; display: flex; flex-direction: column; gap: .2rem; opacity: 0; }
.tile:hover .tile-actions, .tile:focus-within .tile-actions { opacity: 1; }
.tile .tile-actions button { min-height: 26px; padding: 0 .5rem; font-size: .68rem; background: rgba(0, 0, 0, .72); }
.tile[data-blocked="true"] { opacity: .55; }
/* Moderator console */
.admin-main { width: min(60rem, 100%); margin: 0 auto; padding: 1.5rem 1rem 4rem; }
.admin-head h1 { margin: .2rem 0; }
.admin-main h2 { color: var(--gold); font-size: 1.05rem; margin-top: 1.75rem; }
.mod-item .mod-title { margin: 0; font-weight: 600; }
.mod-item blockquote { margin: .4rem 0; padding: .4rem .7rem; border-left: 3px solid var(--violet); background: rgba(0, 0, 0, .25); white-space: pre-wrap; }
.mod-people { list-style: none; padding: 0; margin: .5rem 0 0; display: grid; gap: .3rem; }
.mod-people li { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.mod-people li span { flex: 1 1 10rem; }
.status-line { min-height: 1.5em; color: var(--cyan); }
@media (max-width: 640px) {
  .tile .tile-actions { opacity: 1; }
}

/* ---------- Discovery, onboarding, events, usage (M4) ---------- */
.first-time { margin: .9rem 0 0; padding-left: 1.2rem; color: var(--muted); font-size: .9rem; display: grid; gap: .3rem; }
.first-time strong { color: var(--ink); }
.chips { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: .4rem; }
.count { color: var(--muted); font-weight: 400; font-size: .85rem; }
.link-button { min-height: 0; padding: 0; border: 0; background: none; color: var(--cyan); text-decoration: underline; font-size: inherit; border-radius: 0; }
.link-button:hover { background: none; }
.button-link.small { min-height: 36px; padding: .3rem .8rem; font-size: .85rem; }
.button-link.primary-link { background: linear-gradient(135deg, var(--violet), #6b3fd6); border-color: transparent; font-weight: 600; min-height: 44px; padding: .55rem 1.2rem; }
.entrance-card { overflow: hidden; }
.entrance-art { display: block; width: calc(100% + 3.5rem); margin: -1.75rem -1.75rem 1.25rem; aspect-ratio: 16 / 7; object-fit: cover; }
.badge-chip { display: inline-block; margin: 0 0 .5rem; padding: .15rem .7rem; border-radius: 999px; background: rgba(242, 195, 91, .18); border: 1px solid rgba(242, 195, 91, .55); color: var(--gold); font-size: .85rem; }
.entrance-event { color: var(--gold); }
.entrance-card[data-state="closed"] h1, .entrance-card[data-state="private"] h1, .entrance-card[data-state="missing"] h1 { color: var(--muted); }
.qr { margin: .5rem 0 0; display: grid; gap: .6rem; justify-items: center; }
.qr-art { width: min(18rem, 70vw); background: #fff; border-radius: 8px; padding: .25rem; }
.qr-art svg { display: block; width: 100%; height: auto; }
.qr figcaption { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85rem; color: var(--muted); word-break: break-all; text-align: center; }
.dialog-body { margin-top: .5rem; }
.event-form .row label { flex: 1 1 8rem; }
.dialog input[type="date"], .dialog input[type="time"], .dialog input:not([type]), .dialog input[type="text"], .dialog input[type="email"] {
  display: block; width: 100%; margin-top: .3rem; padding: .55rem .7rem; border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, .2); background: rgba(0, 0, 0, .3); color: var(--ink); font: inherit;
}
.admin-main h3 { font-size: .95rem; color: var(--muted); margin: 1rem 0 .4rem; }
.admin-main select { padding: .45rem .6rem; border-radius: 10px; border: 1px solid rgba(255, 255, 255, .2); background: rgba(0, 0, 0, .3); color: var(--ink); font: inherit; }
.table-wrap { overflow-x: auto; }
.usage { border-collapse: collapse; font-size: .85rem; min-width: 100%; }
.usage th, .usage td { padding: .35rem .6rem; border-bottom: 1px solid rgba(255, 255, 255, .08); text-align: right; white-space: nowrap; }
.usage th:first-child, .usage td:first-child { text-align: left; }
.usage thead th { color: var(--muted); font-weight: 500; }
.usage tfoot th { color: var(--gold); }
.places h2 { margin-top: 0; }
#recent-wrap:not([hidden]) + #discoveries-wrap { margin-top: 1.25rem; }
