:root {
  --bg: #12141c;
  --panel: #1b1e2a;
  --panel-raised: #232739;
  --border: rgba(255, 255, 255, 0.09);
  --text: #edeef2;
  --text-muted: #8a8fa3;
  --accent: #4cd3c2;
  --accent-dim: rgba(76, 211, 194, 0.14);
  --danger: #e8604c;
  --radius: 10px;
  --font-display: "Space Grotesk", "Inter", sans-serif;
  --font-body: "Inter", sans-serif;
  --gold: #f0b429;
  --gold-dim: rgba(240,180,41,0.15);
  --gold-border: rgba(240,180,41,0.3);
}

* { box-sizing: border-box; }

/* .view sets its own `display` (flex/block), which — being an author
   style — otherwise overrides the browser's built-in `[hidden]` rule.
   This makes sure hidden views actually stay hidden. */
.view[hidden] {
  display: none !important;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  line-height: 1.5;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------- wordmark ---------- */

.mark {
  position: fixed;
  top: 22px;
  left: 24px;
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
  z-index: 5;
}

.mark__dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-dim);
}

/* ---------- auth area (Cloudflare Access) ---------- */

.auth-area {
  position: fixed;
  top: 16px;
  right: 20px;
  z-index: 6;
}

.login-btn[hidden],
.user-menu[hidden] {
  display: none !important;
}

.login-btn {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 14px;
  padding: 11px 20px 11px 15px;
  border-radius: 100px;
  text-decoration: none;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.login-btn:hover {
  border-color: rgba(76, 211, 194, 0.35);
  background: var(--panel);
}

.login-btn__icon {
  width: 17px;
  height: 17px;
  color: var(--accent);
  flex-shrink: 0;
}

.user-menu {
  position: relative;
}

.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 100px;
  padding: 6px 16px 6px 6px;
  cursor: pointer;
  color: var(--text);
  font: inherit;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.user-menu-trigger:hover {
  border-color: rgba(76, 211, 194, 0.35);
  background: var(--panel);
}

.user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid rgba(76, 211, 194, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.user-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.user-menu-name {
  font-size: 14px;
  font-weight: 600;
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-trigger .chevron {
  width: 14px;
  height: 14px;
  color: var(--text-muted);
  transition: transform 0.2s ease;
  flex-shrink: 0;
}

.user-menu.open .user-menu-trigger .chevron {
  transform: rotate(180deg);
}

.user-menu-panel {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 250px;
  background: var(--panel-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
  padding: 16px;
  opacity: 0;
  transform: translateY(-8px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
  z-index: 10;
}

.user-menu.open .user-menu-panel {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.user-menu-panel-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

.user-avatar-lg {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent-dim);
  border: 1px solid rgba(76, 211, 194, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  flex-shrink: 0;
}

.user-avatar-lg img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.user-menu-info {
  min-width: 0;
}

.user-menu-fullname {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-menu-email {
  font-size: 11.5px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.user-menu-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 10.5px;
  color: var(--gold);
  background: var(--gold-dim);
  border: 1px solid var(--gold-border);
  padding: 3px 9px;
  border-radius: 100px;
  margin-top: 8px;
}

.user-menu-logout {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: rgba(232, 96, 76, 0.12);
  border: 1px solid rgba(232, 96, 76, 0.3);
  color: var(--danger);
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  padding: 10px;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease;
}

.user-menu-logout:hover {
  background: rgba(232, 96, 76, 0.2);
}

.user-menu-logout svg,
.user-menu-badge svg {
  width: 14px;
  height: 14px;
  flex-shrink: 0;
}

@media (max-width: 640px) {
  .auth-area { top: 14px; right: 14px; }
  .login-btn { font-size: 13px; padding: 10px 16px 10px 12px; }
  .user-menu-name { display: none; }
  .user-menu-trigger { padding: 5px; }
  .user-avatar { width: 30px; height: 30px; }
  .user-menu-panel { width: 230px; }
}

/* ---------- landing / lobby ---------- */

.view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.panel {
  width: 100%;
}

.panel--entry {
  max-width: 420px;
}

.panel--entry h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(28px, 4vw, 34px);
  line-height: 1.15;
  letter-spacing: -0.015em;
  margin: 0 0 12px;
}

.lede {
  color: var(--text-muted);
  font-size: 15px;
  margin: 0 0 28px;
  max-width: 38ch;
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field__label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="text"] {
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  padding: 12px 14px;
}

input[type="text"]::placeholder {
  color: #565b70;
}

input[type="text"]:focus {
  border-color: var(--accent);
}

.fineprint {
  font-size: 13px;
  color: var(--text-muted);
  margin: 14px 0 0;
  min-height: 18px;
}

/* ---------- buttons ---------- */

.btn {
  font: inherit;
  font-weight: 600;
  font-size: 14.5px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 12px 18px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:active { transform: scale(0.98); }

.btn--primary {
  width: 100%;
  background: var(--text);
  color: #12141c;
}

.btn--primary:hover { background: #d7d9e0; }

.btn--accent {
  background: var(--accent);
  color: #0b1614;
}

.btn--accent:hover { background: #63dccd; }

.btn--accent.is-active {
  background: var(--danger);
  color: #1a0e0b;
}

.btn--ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}

.btn--ghost:hover { border-color: var(--text-muted); }

.btn--danger {
  background: transparent;
  border-color: var(--danger);
  color: var(--danger);
}

.btn--danger:hover { background: rgba(232, 96, 76, 0.1); }

.btn--icon {
  min-width: 40px;
  padding: 10px 14px;
  font-variant-numeric: tabular-nums;
}

/* ---------- room / stage ---------- */

#view-room.view {
  display: block;
  padding: 0;
  min-height: 100vh;
}

.stage {
  min-height: 100vh;
  padding: 84px 24px 110px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-grid {
  width: 100%;
  max-width: 1400px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
}

.tile {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 16 / 10;
}

.tile video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  display: block;
}

.tile__label {
  position: absolute;
  left: 10px;
  bottom: 10px;
  background: rgba(10, 11, 16, 0.72);
  backdrop-filter: blur(4px);
  padding: 5px 10px;
  border-radius: 100px;
  font-size: 12.5px;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 6px;
}

.tile__label::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-muted);
}

.tile__fullscreen {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(10, 11, 16, 0.72);
  backdrop-filter: blur(4px);
  color: var(--text);
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease,
    border-color 0.15s ease;
}

.tile__fullscreen svg {
  width: 15px;
  height: 15px;
}

.tile__fullscreen:hover,
.tile__fullscreen:focus-visible {
  opacity: 1;
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.tile__flip {
  position: absolute;
  top: 10px;
  right: 52px;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: rgba(10, 11, 16, 0.72);
  backdrop-filter: blur(4px);
  color: var(--text);
  cursor: pointer;
  opacity: 0.8;
  transition: opacity 0.15s ease, background 0.15s ease, color 0.15s ease,
    border-color 0.15s ease;
}

.tile__flip svg {
  width: 15px;
  height: 15px;
}

.tile__flip:hover,
.tile__flip:focus-visible {
  opacity: 1;
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

.tile.is-connected .tile__label::before { background: var(--accent); }

.tile.is-local .tile__label { color: var(--accent); }

.empty-state {
  color: var(--text-muted);
  font-size: 14.5px;
  text-align: center;
  max-width: 32ch;
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.video-grid:not(:empty) + .empty-state { display: none; }

/* ---------- roster drawer ---------- */

.roster {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: 260px;
  background: var(--panel);
  border-left: 1px solid var(--border);
  padding: 84px 20px 20px;
  overflow-y: auto;
  z-index: 4;
}

.roster h2 {
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-muted);
  margin: 0 0 14px;
}

.roster ul {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.roster li {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

.roster li::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex-shrink: 0;
}

/* ---------- bottom console ---------- */

.console {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 24px;
  background: linear-gradient(to top, rgba(18, 20, 28, 0.96), rgba(18, 20, 28, 0.7));
  border-top: 1px solid var(--border);
  z-index: 5;
}

.console__group {
  display: flex;
  gap: 10px;
}

/* ---------- toast ---------- */

.toast {
  position: fixed;
  bottom: 92px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-raised);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13.5px;
  padding: 10px 16px;
  border-radius: 100px;
  z-index: 10;
}

@media (max-width: 640px) {
  .roster { width: 100%; border-left: none; border-top: 1px solid var(--border); }
  .console { flex-wrap: wrap; }
  .console__group { flex-wrap: wrap; }
  .console .btn { padding: 10px 14px; font-size: 13.5px; }
}
