:root {
  color-scheme: dark;
  --bg: #000000;
  --surface: rgba(0, 0, 0, 0.15);
  --surface-strong: rgba(255, 255, 255, 0.06);
  --text: #f7f1e8;
  --muted: #b9b1a5;
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.28);
  --accent: #f2c14e;
  --accent-2: #4cc9b0;
  --accent-3: #e36a5b;
  --radius: 8px;
  --dock-h: 72px;
  --top-h: 56px;
  --sidebar-w: 320px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

@supports (font-variation-settings: normal) {
  :root { font-family: InterVariable, Inter, ui-sans-serif, system-ui, sans-serif; }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { -webkit-tap-highlight-color: transparent; cursor: pointer; }
kbd {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.05);
  font: inherit;
  font-size: 0.85em;
}

.muted { color: var(--muted); }

/* ------------------------------------------------------------ background */
.background {
  position: fixed;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(60% 50% at 20% 15%, rgba(242, 193, 78, 0.10), transparent 70%),
    radial-gradient(50% 45% at 85% 85%, rgba(76, 201, 176, 0.10), transparent 70%),
    radial-gradient(40% 40% at 70% 20%, rgba(227, 106, 91, 0.07), transparent 70%),
    #000;
  animation: bg-drift 24s ease-in-out infinite alternate;
}
.background::after {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(ellipse at center, black 30%, transparent 80%);
}

/* ------------------------------------------------------------ gate */
.gate {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 12px;
  padding: 32px 18px;
  background: rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(0.5px);
  transition: opacity 360ms ease, visibility 360ms ease;
}
body:not(.is-locked) .gate {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.gate__card {
  width: min(100%, 390px);
  padding: 26px 18px;
  display: grid;
  justify-items: center;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-align: center;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(1.5px);
  animation: profile-pulse 3.2s ease-in-out infinite;
}

.gate__logo {
  width: clamp(68px, 18vw, 88px);
  height: clamp(68px, 18vw, 88px);
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #161920;
}

.gate h1 {
  margin: 18px 0 0;
  font-size: clamp(1.9rem, 5vw, 2.8rem);
  line-height: 0.95;
  font-weight: 800;
  animation: nickname-pulse 2.8s ease-in-out infinite;
}

.gate__intro {
  max-width: 42rem;
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.65;
}

.field {
  width: min(100%, 340px);
  margin-top: 12px;
  display: grid;
  gap: 6px;
  text-align: left;
}
.field:first-of-type { margin-top: 20px; }
.field span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.field input {
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.3);
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.field input:focus {
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.14);
}

.gate__error {
  width: min(100%, 340px);
  margin: 10px 0 0;
  padding: 8px 10px;
  border: 1px solid rgba(227, 106, 91, 0.5);
  border-radius: var(--radius);
  background: rgba(227, 106, 91, 0.12);
  color: #ffb3a9;
  font-size: 0.82rem;
  font-weight: 600;
  text-align: left;
}

.gate__submit {
  width: min(100%, 340px);
  margin-top: 14px;
  justify-content: center;
}
.gate__hint {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 600;
  min-height: 1em;
}

.footer-note {
  margin: 0;
  color: rgba(255, 255, 255, 0.62);
  font-size: 0.72rem;
  font-weight: 600;
  text-align: center;
}

/* ------------------------------------------------------------ buttons */
.btn {
  position: relative;
  overflow: hidden;
  min-height: 40px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  font-size: 0.92rem;
  font-weight: 700;
  text-decoration: none;
  transition: border-color 180ms ease, box-shadow 180ms ease, color 180ms ease, background 180ms ease;
}
.btn__icon { width: 18px; flex: 0 0 auto; text-align: center; }
.btn::before {
  position: absolute;
  inset: -45% auto -45% -35%;
  width: 34px;
  content: "";
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.82), transparent);
  opacity: 0;
  transform: rotate(18deg);
  pointer-events: none;
}
.btn:hover:not(:disabled) {
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.2);
  animation: button-glow 1.4s ease-in-out infinite;
}
.btn:hover:not(:disabled)::before { animation: button-shine 1.35s ease-in-out infinite; }
.btn:focus-visible, .iconbtn:focus-visible, input:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 3px;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn--primary { border-color: rgba(255, 255, 255, 0.3); background: rgba(255, 255, 255, 0.06); }
.btn--danger:hover:not(:disabled) { border-color: rgba(227, 106, 91, 0.8); color: #ffb3a9; }
.btn.is-live {
  border-color: rgba(76, 201, 176, 0.7);
  color: var(--accent-2);
  background: rgba(76, 201, 176, 0.08);
}
.btn.is-on {
  border-color: rgba(242, 193, 78, 0.7);
  color: var(--accent);
  background: rgba(242, 193, 78, 0.08);
}

.iconbtn {
  position: relative;
  width: 32px;
  height: 32px;
  display: inline-grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  transition: border-color 180ms ease, box-shadow 180ms ease, color 180ms ease;
}
.iconbtn:hover { border-color: rgba(255, 255, 255, 0.72); box-shadow: 0 0 14px rgba(255, 255, 255, 0.18); }
.iconbtn--solid { background: rgba(255, 255, 255, 0.08); }
.iconbtn[aria-pressed="true"].person__mute { border-color: rgba(227, 106, 91, 0.7); color: #ffb3a9; }

.ico-mic-off { display: none; }
[aria-pressed="true"] > .ico-mic-on, .is-muted > .ico-mic-on { display: none; }
[aria-pressed="true"] > .ico-mic-off, .is-muted > .ico-mic-off { display: block; }

.badge {
  position: absolute;
  top: -6px;
  right: -6px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: #000;
  font-size: 0.68rem;
  font-weight: 800;
}

/* ------------------------------------------------------------ room layout */
.room {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: var(--top-h) 1fr var(--dock-h);
  grid-template-columns: 1fr var(--sidebar-w);
  grid-template-areas:
    "top top"
    "stage side"
    "dock side";
  transition: filter 420ms ease, opacity 420ms ease, transform 420ms ease;
}
.is-locked .room {
  filter: blur(8px);
  opacity: 0.34;
  transform: scale(0.98);
  pointer-events: none;
}
.room.sidebar-hidden {
  grid-template-columns: 1fr 0;
}
.room.sidebar-hidden .sidebar { display: none; }

.topbar {
  grid-area: top;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
}
.topbar__brand { display: flex; align-items: center; gap: 10px; font-size: 1rem; }
.topbar__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 10px var(--accent-2);
  animation: dot-pulse 2s ease-in-out infinite;
}
.topbar__sub { color: var(--muted); font-size: 0.8rem; font-weight: 600; }
.topbar__actions { display: flex; gap: 8px; }

/* stage + tiles */
.stage {
  grid-area: stage;
  position: relative;
  overflow: auto;
  padding: 16px;
}
.stage__empty {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 4px;
  text-align: center;
  font-weight: 600;
  color: var(--text);
  opacity: 0.85;
}
.stage__empty p { margin: 0; }
.stage.has-tiles .stage__empty { display: none; }

.grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  align-content: start;
  min-height: 100%;
}
.grid[data-count="1"] { grid-template-columns: 1fr; }
.grid[data-count="1"] .tile { max-height: calc(100vh - var(--top-h) - var(--dock-h) - 32px); }

.tile {
  position: relative;
  overflow: hidden;
  display: grid;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #0a0a0c;
  box-shadow: 0 0 14px rgba(255, 255, 255, 0.06);
  transition: border-color 180ms ease, box-shadow 180ms ease;
  animation: tile-in 300ms ease;
}
.tile:hover { border-color: var(--line-strong); box-shadow: 0 0 22px rgba(255, 255, 255, 0.12); }
.tile.is-self { border-color: rgba(76, 201, 176, 0.5); }
.tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}
.tile__bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 180ms ease, transform 180ms ease;
}
.tile:hover .tile__bar, .tile:focus-within .tile__bar { opacity: 1; transform: none; }
.tile__name {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.82rem;
  font-weight: 800;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
}
.tile.is-self .tile__name::after { content: " · you"; color: var(--accent-2); }
.tile__vol { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.tile.is-self .tile__vol { display: none; }
.tile__vol input[type="range"] { width: 110px; accent-color: var(--text); }

/* ------------------------------------------------------------ sidebar */
.sidebar {
  grid-area: side;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
  border-left: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
}
.panel { display: grid; min-height: 0; padding: 12px 14px; }
.panel--people { border-bottom: 1px solid var(--line); grid-template-rows: auto auto; }
.panel--chat { grid-template-rows: auto 1fr auto; }
.panel__title {
  margin: 0 0 8px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}
.panel__count {
  padding: 0 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.68rem;
  color: var(--text);
}

.people { list-style: none; margin: 0; padding: 0; max-height: 30vh; overflow: auto; display: grid; gap: 4px; align-content: start; scrollbar-width: thin; }
.person {
  display: grid;
  grid-template-columns: 26px 1fr auto 32px;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 4px;
  border-radius: var(--radius);
  transition: background 150ms ease;
}
.person:hover { background: rgba(255, 255, 255, 0.04); }
.person__avatar {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: #161920;
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}
.person__name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 0.88rem; font-weight: 700; }
.person.is-self .person__name::after { content: " (you)"; color: var(--muted); font-weight: 600; }
.person__tags { display: flex; gap: 4px; }
.tag {
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-radius: 999px;
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.tag--live { color: var(--accent-2); border-color: rgba(76, 201, 176, 0.5); }
.tag--mic { color: var(--accent); border-color: rgba(242, 193, 78, 0.5); }
.person.is-self .person__mute { visibility: hidden; }
.person__mute { width: 28px; height: 28px; }

.chat {
  list-style: none;
  margin: 0;
  padding: 0 2px 0 0;
  overflow-y: auto;
  display: grid;
  gap: 6px;
  align-content: end;
  font-size: 0.86rem;
  line-height: 1.45;
  scrollbar-width: thin;
}
.chat__msg { display: grid; gap: 1px; animation: tile-in 180ms ease; }
.chat__meta { display: flex; gap: 6px; align-items: baseline; }
.chat__name { font-weight: 800; }
.chat__time { color: var(--muted); font-size: 0.7rem; }
.chat__text { overflow-wrap: anywhere; white-space: pre-wrap; }
.chat__sys {
  padding: 2px 0;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 600;
  text-align: center;
}
.chat__sys::before, .chat__sys::after { content: " · "; opacity: 0.5; }

.chat__form {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr 32px;
  gap: 6px;
}
.chat__form input {
  min-height: 32px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.3);
  outline: none;
  transition: border-color 180ms ease, box-shadow 180ms ease;
}
.chat__form input:focus { border-color: rgba(255, 255, 255, 0.72); box-shadow: 0 0 14px rgba(255, 255, 255, 0.14); }

/* ------------------------------------------------------------ dock */
.dock {
  grid-area: dock;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 16px;
  border-top: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
}

/* ------------------------------------------------------------ toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h) + 14px);
  z-index: 30;
  transform: translateX(-50%);
  padding: 8px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.8);
  font-size: 0.84rem;
  font-weight: 700;
  box-shadow: 0 0 18px rgba(255, 255, 255, 0.12);
  animation: tile-in 200ms ease;
}

/* ------------------------------------------------------------ responsive */
@media (max-width: 860px) {
  :root { --sidebar-w: 0px; }
  .room {
    grid-template-columns: 1fr;
    grid-template-areas:
      "top"
      "stage"
      "dock";
  }
  .sidebar {
    position: fixed;
    top: var(--top-h);
    right: 0;
    bottom: var(--dock-h);
    width: min(100%, 340px);
    border-left: 1px solid var(--line);
    background: rgba(0, 0, 0, 0.92);
    z-index: 15;
  }
  .btn span:not(.btn__icon) { display: none; }
  .btn { min-width: 44px; justify-content: center; padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}

/* ------------------------------------------------------------ keyframes */
@keyframes button-glow {
  0%, 100% { box-shadow: 0 0 10px rgba(255, 255, 255, 0.16); }
  50% { box-shadow: 0 0 24px rgba(255, 255, 255, 0.34); }
}
@keyframes button-shine {
  0% { left: -35%; opacity: 0; }
  28% { opacity: 0.5; }
  62% { opacity: 0; }
  100% { left: 112%; opacity: 0; }
}
@keyframes nickname-pulse {
  0%, 100% { text-shadow: 0 0 8px rgba(255, 255, 255, 0.12); }
  50% { text-shadow: 0 0 18px rgba(255, 255, 255, 0.36); }
}
@keyframes profile-pulse {
  0%, 100% { box-shadow: 0 0 14px rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.14); }
  50% { box-shadow: 0 0 28px rgba(255, 255, 255, 0.18); border-color: rgba(255, 255, 255, 0.28); }
}
@keyframes dot-pulse {
  0%, 100% { box-shadow: 0 0 6px var(--accent-2); }
  50% { box-shadow: 0 0 14px var(--accent-2); }
}
@keyframes tile-in {
  from { opacity: 0; transform: translateY(6px) scale(0.985); }
  to { opacity: 1; transform: none; }
}
@keyframes bg-drift {
  from { background-position: 0 0, 0 0, 0 0, 0 0; }
  to { background-position: 4% 6%, -5% -4%, 3% -6%, 0 0; }
}
