:root,
html[data-theme='midnight'] {
  --bg: #0f1420;
  --bg-glow: #182238;
  --bg-elevated: #171d2e;
  --card: #1b2333;
  --border: #2a3348;
  --text: #e8ebf3;
  --text-muted: #9aa4bd;
  --primary: #5b8cff;
  --primary-hover: #4576f0;
  --danger: #ef5a5a;
  --danger-hover: #d94848;
  --success: #3ecf8e;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html[data-theme='forest'] {
  --bg: #0e1612;
  --bg-glow: #1a2a20;
  --bg-elevated: #152019;
  --card: #1a2620;
  --border: #2a3d32;
  --text: #e6efe9;
  --text-muted: #9bb5a6;
  --primary: #3ecf8e;
  --primary-hover: #2fb876;
  --danger: #ef5a5a;
  --danger-hover: #d94848;
  --success: #3ecf8e;
}

html[data-theme='ember'] {
  --bg: #16120f;
  --bg-glow: #2a1e16;
  --bg-elevated: #1e1914;
  --card: #241e18;
  --border: #3d3228;
  --text: #f2ebe3;
  --text-muted: #b5a798;
  --primary: #e8884a;
  --primary-hover: #d47438;
  --danger: #ef5a5a;
  --danger-hover: #d94848;
  --success: #3ecf8e;
}

html[data-theme='ocean'] {
  --bg: #0c1518;
  --bg-glow: #143038;
  --bg-elevated: #122024;
  --card: #162830;
  --border: #274048;
  --text: #e4eef1;
  --text-muted: #93aeb6;
  --primary: #2ec4b6;
  --primary-hover: #25a99d;
  --danger: #ef5a5a;
  --danger-hover: #d94848;
  --success: #3ecf8e;
}

html[data-theme='daylight'] {
  --bg: #f0f3f8;
  --bg-glow: #dde6f5;
  --bg-elevated: #ffffff;
  --card: #ffffff;
  --border: #d0d7e5;
  --text: #1a2233;
  --text-muted: #5c6b85;
  --primary: #3b6fd8;
  --primary-hover: #2f5bc0;
  --danger: #d94848;
  --danger-hover: #c23a3a;
  --success: #1f9d63;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at top, var(--bg-glow) 0%, var(--bg) 60%);
  color: var(--text);
}

a {
  color: var(--primary);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.65rem 1.2rem;
  border-radius: 8px;
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s ease, transform 0.05s ease;
}

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

/* The [hidden] attribute is only display:none via the UA stylesheet, which
   author rules like .btn's display:inline-flex silently override - so any
   hidden button/link needs this reinforced explicitly. */
.btn[hidden] {
  display: none;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-small {
  padding: 0.4rem 0.8rem;
  font-size: 0.85rem;
}

.btn-control {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--border);
  min-width: 120px;
}

.btn-control:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-control.active {
  background: var(--danger);
  color: #fff;
  border-color: var(--danger);
}

/* ---------- Auth pages (login/register) ---------- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.25rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.auth-card h1 {
  margin: 0 0 0.4rem;
  font-size: 1.6rem;
}

.auth-subtitle {
  margin: 0 0 1.5rem;
  color: var(--text-muted);
  font-size: 0.95rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.auth-form label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-top: 0.6rem;
}

.auth-form input {
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.95rem;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--primary);
}

.auth-form .btn {
  margin-top: 1.3rem;
}

.auth-footer {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.9rem;
  color: var(--text-muted);
}

.form-message {
  margin: 0.6rem 0 0;
  padding: 0.6rem 0.8rem;
  border-radius: 8px;
  font-size: 0.85rem;
}

.form-message.error {
  background: rgba(239, 90, 90, 0.15);
  color: #ff9a9a;
  border: 1px solid rgba(239, 90, 90, 0.3);
}

.form-message.success {
  background: rgba(62, 207, 142, 0.15);
  color: var(--success);
  border: 1px solid rgba(62, 207, 142, 0.3);
}

/* ---------- Lobby page ---------- */

.top-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
}

.brand {
  font-weight: 700;
  font-size: 1.1rem;
  letter-spacing: 0.02em;
}

.top-bar-right {
  display: flex;
  align-items: center;
  gap: 1rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.lobby-main {
  max-width: 720px;
  margin: 3rem auto;
  padding: 0 1.5rem;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
}

.lobby-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.75rem;
}

.lobby-card h2 {
  margin: 0 0 0.4rem;
  font-size: 1.2rem;
}

.lobby-card p {
  margin: 0 0 1.2rem;
  color: var(--text-muted);
  font-size: 0.9rem;
}

.inline-form {
  display: flex;
  gap: 0.6rem;
}

.inline-form input {
  flex: 1;
  padding: 0.65rem 0.8rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text);
  font-size: 0.95rem;
  text-transform: uppercase;
}

.inline-form input:focus {
  outline: none;
  border-color: var(--primary);
}

/* ---------- Admin panel ---------- */

.admin-main {
  max-width: 960px;
  margin: 2.5rem auto;
  padding: 0 1.5rem;
}

.admin-panels {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.5rem;
  margin-bottom: 1.5rem;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.9rem;
  color: var(--text);
  cursor: pointer;
  margin: 0.6rem 0 1.1rem;
}

.toggle-row input[type='checkbox'] {
  width: 18px;
  height: 18px;
  accent-color: var(--primary);
  cursor: pointer;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

.admin-table th,
.admin-table td {
  padding: 0.8rem 1rem;
  text-align: left;
  font-size: 0.9rem;
  border-bottom: 1px solid var(--border);
}

.admin-table th {
  color: var(--text-muted);
  font-weight: 600;
  background: var(--bg-elevated);
}

.admin-table tbody tr:last-child td {
  border-bottom: none;
}

.admin-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--bg-elevated);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.badge-success {
  background: rgba(62, 207, 142, 0.15);
  color: var(--success);
  border-color: rgba(62, 207, 142, 0.3);
}

.badge-pending {
  background: rgba(255, 200, 87, 0.15);
  color: #ffc857;
  border-color: rgba(255, 200, 87, 0.3);
}

.badge-admin {
  background: rgba(91, 140, 255, 0.15);
  color: var(--primary);
  border-color: rgba(91, 140, 255, 0.3);
}

/* ---------- Room page ---------- */

.room-body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

.room-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 0.6rem;
  padding: 0.9rem 1.5rem;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}

.room-code-area {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.7rem;
  font-size: 0.95rem;
  color: var(--text-muted);
}

.room-code-area strong {
  color: var(--text);
  letter-spacing: 0.08em;
  font-size: 1.05rem;
}

.error-banner {
  margin: 0.75rem 1.5rem 0;
  padding: 0.6rem 0.9rem;
  border-radius: 8px;
  background: rgba(239, 90, 90, 0.15);
  color: #ff9a9a;
  border: 1px solid rgba(239, 90, 90, 0.3);
  font-size: 0.9rem;
}

.video-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  grid-auto-rows: minmax(180px, 1fr);
  gap: 1rem;
  padding: 1.25rem;
  overflow: auto;
}

.video-tile {
  position: relative;
  background: #000;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  /* Fixed to the camera's requested aspect ratio (see the getUserMedia
     constraints in room.js) so object-fit below never has to crop a
     mismatched box - that mismatch is what made the picture look
     "zoomed in" before. */
  aspect-ratio: 16 / 9;
}

.video-tile video {
  width: 100%;
  height: 100%;
  /* contain, not cover: always shows the full camera frame - never
     crops/zooms in to fill the tile, at the cost of thin letterboxing
     if a peer's camera doesn't exactly match the 16:9 aspect ratio. */
  object-fit: contain;
}

.video-name-tag {
  position: absolute;
  bottom: 0.6rem;
  left: 0.6rem;
  padding: 0.25rem 0.6rem;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.55);
  font-size: 0.8rem;
}

.controls-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 1rem;
  padding: 1rem;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
}

.theme-options {
  display: grid;
  gap: 0.55rem;
  margin: 0.7rem 0 0;
}

.theme-option {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  cursor: pointer;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.theme-option:hover {
  border-color: var(--primary);
}

.theme-option:has(input:checked) {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 12%, var(--bg-elevated));
}

.theme-option input {
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.theme-swatch {
  width: 2.2rem;
  height: 1.35rem;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: linear-gradient(90deg, var(--swatch-bg) 50%, var(--swatch-accent) 50%);
  flex-shrink: 0;
}

.theme-option-label {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  font-size: 0.9rem;
  color: var(--text);
}

.theme-option-label small {
  color: var(--text-muted);
  font-size: 0.75rem;
}

/* ---------- Guest name gate (invite-link join without account) ---------- */

.guest-gate {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: color-mix(in srgb, var(--bg) 72%, transparent);
  backdrop-filter: blur(8px);
}

.guest-gate[hidden] {
  display: none;
}

.guest-gate-card {
  width: 100%;
  max-width: 380px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 2.25rem;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.guest-gate-card h1 {
  margin: 0 0 0.4rem;
  font-size: 1.6rem;
}
