:root {
  color-scheme: dark;
  --bg: #0f1411;
  --panel: rgba(253, 247, 229, 0.08);
  --panel-strong: rgba(253, 247, 229, 0.13);
  --panel-border: rgba(244, 213, 162, 0.2);
  --text: #fff6dc;
  --muted: #b9aa8e;
  --accent: #f4b860;
  --accent-strong: #62d39c;
  --danger: #f97316;
  --shadow: 0 26px 80px rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 18% 12%, rgba(244, 184, 96, 0.26), transparent 24%),
    radial-gradient(circle at 88% 6%, rgba(98, 211, 156, 0.18), transparent 22%),
    linear-gradient(145deg, #111812 0%, #101316 46%, #070908 100%);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.18;
  background-image:
    linear-gradient(rgba(255, 246, 220, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 246, 220, 0.08) 1px, transparent 1px);
  background-size: 42px 42px;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 999px;
  padding: 0.85rem 1.2rem;
  cursor: pointer;
  background: linear-gradient(135deg, var(--accent), #ffd98a);
  color: #171006;
  font-weight: 800;
  box-shadow: 0 12px 30px rgba(244, 184, 96, 0.22);
  transition:
    transform 140ms ease,
    opacity 140ms ease,
    border-color 140ms ease;
}

button:hover:not(:disabled) {
  transform: translateY(-1px);
}

button.ghost {
  background: rgba(110, 142, 194, 0.12);
  color: var(--text);
  border: 1px solid rgba(151, 176, 219, 0.22);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

input,
select {
  width: 100%;
  margin-top: 0.45rem;
  border-radius: 16px;
  border: 1px solid rgba(244, 213, 162, 0.22);
  background: rgba(5, 8, 7, 0.6);
  color: var(--text);
  padding: 0.85rem 1rem;
}

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--accent) 50%),
    linear-gradient(135deg, var(--accent) 50%, transparent 50%);
  background-position:
    calc(100% - 20px) 52%,
    calc(100% - 14px) 52%;
  background-size:
    6px 6px,
    6px 6px;
  background-repeat: no-repeat;
}

.shell {
  width: min(1280px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
  position: relative;
}

.hero {
  display: flex;
  justify-content: center;
}

.shell[data-app-state="prejoin"] {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.shell[data-app-state="prejoin"] .hero {
  min-height: calc(100vh - 76px);
  align-items: center;
}

.shell[data-app-state="prejoin"] .join-card {
  width: min(560px, 100%);
  min-height: 640px;
}

.shell[data-app-state="prejoin"] .in-room-only {
  display: none;
}

.shell[data-app-state="in-room"] .hero {
  display: none;
}

.shell[data-app-state="in-room"] {
  padding-bottom: 120px;
}

h2 {
  margin: 0;
  font-size: 1.3rem;
  letter-spacing: -0.02em;
}

.panel {
  background: var(--panel);
  backdrop-filter: blur(12px);
  border: 1px solid var(--panel-border);
  border-radius: 28px;
  box-shadow: var(--shadow);
}

.form-grid {
  padding: 24px;
  display: grid;
  gap: 15px;
}

.join-card {
  align-content: start;
}

.helper {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.build-version {
  margin: 0.2rem 0 0;
  color: rgba(255, 246, 220, 0.52);
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.section-kicker {
  margin: 0 0 6px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  font-weight: 900;
}

.advanced {
  border-radius: 18px;
  border: 1px solid rgba(244, 213, 162, 0.14);
  padding: 12px 14px;
  background: rgba(5, 8, 7, 0.28);
}

.advanced summary {
  cursor: pointer;
  color: var(--muted);
  font-weight: 800;
}

.advanced label {
  display: block;
  margin-top: 12px;
}

.prejoin-media {
  display: grid;
  gap: 10px;
}

.prejoin-toggle {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  border: 1px solid rgba(244, 213, 162, 0.14);
  background: rgba(5, 8, 7, 0.28);
  color: var(--text);
  cursor: pointer;
}

.prejoin-toggle input {
  width: 18px;
  height: 18px;
  margin: 0;
  accent-color: var(--accent);
  flex: 0 0 auto;
}

.prejoin-toggle span {
  font-weight: 700;
}

.actions,
.toggles,
.participant-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.participant-actions [hidden],
.video-frame [hidden] {
  display: none !important;
}

.icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  box-shadow: none;
}

.icon-button svg {
  width: 18px;
  height: 18px;
}

.heading-action {
  flex: 0 0 auto;
}

.toggles {
  align-items: center;
}

.round-control {
  width: 50px;
  height: 50px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: none;
}

.round-control svg {
  width: 22px;
  height: 22px;
}

.round-control.is-active {
  background: linear-gradient(135deg, var(--accent), #ffd98a);
  color: #171006;
  border-color: transparent;
}

.round-control.is-active[data-control="mic"] {
  background: linear-gradient(135deg, var(--accent-strong), #d7f88f);
}

.round-control.is-active[data-control="priority"] {
  background: linear-gradient(135deg, #d92d3a, #ff6b73);
  color: #fff7f7;
  border-color: transparent;
  box-shadow: 0 10px 28px rgba(217, 45, 58, 0.3);
}

.status-row {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin: 20px 0;
  padding: 14px;
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(920px, calc(100% - 32px));
  z-index: 10;
}

.shell[data-app-state="in-room"] .status-row {
  margin-top: 0;
}

.diagnostics {
  padding: 14px 18px;
  margin: 0 0 20px;
}

.media-controls {
  position: fixed;
  inset: 50% auto auto 50%;
  transform: translate(-50%, -50%);
  width: min(980px, calc(100% - 32px));
  max-height: calc(100vh - 96px);
  overflow: auto;
  padding: 16px 18px;
  margin: 0;
  z-index: 30;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.settings-header h3 {
  margin: 0;
  font-size: 1rem;
}

.media-controls[hidden] {
  display: none;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(2, 5, 7, 0.58);
  backdrop-filter: blur(4px);
  z-index: 24;
}

.settings-backdrop[hidden] {
  display: none !important;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 12px;
}

.section-heading .helper {
  max-width: 46ch;
  text-align: right;
}

.participants-heading {
  margin-top: 24px;
}

.device-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
  align-items: end;
}

.audio-health {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.diagnostics-panel {
  margin-top: 14px;
  border-radius: 18px;
  border: 1px solid rgba(244, 213, 162, 0.14);
  background: rgba(5, 8, 7, 0.28);
  padding: 12px 14px;
}

.diagnostics-panel summary {
  cursor: pointer;
  color: var(--text);
  font-weight: 800;
}

.diagnostics-log {
  margin: 10px 0 0;
  padding: 12px;
  max-height: 220px;
  overflow: auto;
  border-radius: 14px;
  background: rgba(5, 8, 7, 0.72);
  border: 1px solid rgba(244, 213, 162, 0.12);
  color: #d7f7e4;
  font: 12px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace;
  white-space: pre-wrap;
}

.media-controls label span,
.media-controls strong {
  font-size: 0.9rem;
}

.media-controls input,
.media-controls select {
  padding: 0.72rem 0.9rem;
  border-radius: 14px;
}

.media-controls button {
  padding: 0.72rem 1rem;
  box-shadow: none;
}

.media-controls .icon-button {
  width: 42px;
  height: 42px;
  padding: 0;
}

.settings-close {
  flex: 0 0 auto;
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
}

.meter {
  height: 14px;
  margin: 8px 0 6px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(5, 8, 7, 0.74);
  border: 1px solid rgba(244, 213, 162, 0.18);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent-strong), #d7f88f, var(--accent));
  transition: width 90ms linear;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.6rem 0.9rem;
  border-radius: 999px;
  background: rgba(98, 211, 156, 0.12);
  color: #a7f5c7;
  border: 1px solid rgba(98, 211, 156, 0.26);
  font-weight: 800;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(330px, 1fr));
  gap: 20px;
}

.participant-card {
  padding: 14px;
  background: var(--panel-strong);
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-self: start;
  content-visibility: auto;
  contain-intrinsic-size: 560px;
}

.participant-header {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.participant-name {
  margin: 0;
  font-size: 1.18rem;
  letter-spacing: -0.02em;
}

.participant-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.participant-mic-state {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  background: rgba(217, 45, 58, 0.14);
  border: 1px solid rgba(255, 107, 115, 0.28);
  color: #ffb9be;
  flex: 0 0 auto;
}

.participant-mic-state[hidden] {
  display: none !important;
}

.participant-mic-state svg {
  width: 14px;
  height: 14px;
}

.participant-meta {
  margin: 4px 0 0;
  color: var(--muted);
}

.participant-card.is-speaking {
  border-color: rgba(98, 211, 156, 0.6);
  box-shadow:
    0 0 0 1px rgba(98, 211, 156, 0.3),
    0 22px 44px rgba(0, 0, 0, 0.28),
    0 0 26px rgba(98, 211, 156, 0.18);
}

.participant-card.is-priority {
  border-color: var(--panel-border);
  box-shadow: var(--shadow);
}

.participant-card.is-priority.is-speaking {
  border-color: rgba(244, 184, 96, 0.78);
  box-shadow:
    0 0 0 1px rgba(244, 184, 96, 0.45),
    0 22px 44px rgba(0, 0, 0, 0.28),
    0 0 36px rgba(244, 184, 96, 0.28);
}

.priority-speaker-btn.is-priority {
  background: rgba(244, 184, 96, 0.18);
  border-color: rgba(244, 184, 96, 0.45);
  color: #ffe4b9;
}

.remote-camera-toggle-btn.is-disabled {
  background: rgba(249, 115, 22, 0.12);
  border-color: rgba(249, 115, 22, 0.34);
  color: #ffd4b8;
}

.remote-screen-toggle-btn.is-disabled {
  background: rgba(249, 115, 22, 0.12);
  border-color: rgba(249, 115, 22, 0.34);
  color: #ffd4b8;
}

.video-frame,
.popout-video {
  position: relative;
  min-height: 240px;
  border-radius: 22px;
  background:
    radial-gradient(circle at 50% 35%, rgba(244, 184, 96, 0.16), transparent 30%),
    linear-gradient(135deg, rgba(5, 8, 7, 0.95), rgba(17, 24, 18, 0.92));
  border: 1px solid rgba(244, 213, 162, 0.18);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.video-frame[hidden] {
  display: none !important;
}

.screen-frame {
  min-height: 200px;
}

.video-frame video,
.popout-video video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.clean-popout video {
  object-fit: contain !important;
  background: #000;
}

.video-frame video.force-normal-x,
.clean-popout video.force-normal-x {
  transform: scaleX(1) !important;
}

.video-frame video.force-flip-x,
.clean-popout video.force-flip-x {
  transform: scaleX(-1) !important;
}

.source-badge {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 1;
  padding: 0.4rem 0.7rem;
  border-radius: 999px;
  background: rgba(5, 8, 7, 0.72);
  border: 1px solid rgba(244, 213, 162, 0.18);
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
}

.screen-popout-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 1;
  box-shadow: none;
}

.empty-state {
  color: var(--muted);
  font-weight: 800;
}

.popout-body {
  background: #000;
}

.clean-popout {
  min-height: 100vh;
  border: 0;
  border-radius: 0;
  background: #000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.popout-ui {
  position: fixed;
  top: 14px;
  right: 14px;
  z-index: 5;
}

.popout-quality-toggle {
  padding: 0.55rem 0.95rem;
  border-radius: 999px;
  font-weight: 800;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.32);
}

.popout-quality-toggle.is-hq {
  background: linear-gradient(135deg, #f4b860, #ffd98a);
  color: #1f1607;
  border-color: transparent;
}

.remote-audio {
  display: none;
}

.priority-toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  width: min(560px, calc(100vw - 32px));
  padding: 18px 20px;
  border-radius: 20px;
  background: rgba(120, 11, 24, 0.95);
  border: 1px solid rgba(255, 154, 154, 0.34);
  color: #fff4f4;
  text-align: center;
  font-weight: 900;
  font-size: 1.05rem;
  box-shadow: 0 28px 64px rgba(0, 0, 0, 0.42);
}

.priority-toast.is-release {
  background: rgba(18, 97, 48, 0.94);
  border-color: rgba(140, 255, 182, 0.34);
  color: #f1fff5;
}

.priority-toast[hidden] {
  display: none !important;
}

@media (max-width: 900px) {
  .hero {
    display: block;
  }

  .status-row {
    flex-direction: column;
    align-items: stretch;
    width: calc(100% - 24px);
    bottom: 12px;
  }

  .section-heading {
    display: block;
  }

  .section-heading .helper {
    text-align: left;
  }

  .device-grid,
  .audio-health {
    grid-template-columns: 1fr;
  }

  .toggles {
    justify-content: space-between;
  }

  .shell[data-app-state="prejoin"] .join-card {
    min-height: auto;
  }
}
