:root {
  color-scheme: dark;
  --bg: #151816;
  --surface: #20251f;
  --surface-2: #2b302a;
  --text: #f4f5f0;
  --muted: #b9c0b3;
  --line: #3b4238;
  --accent: #4fd18b;
  --accent-2: #8dc9ff;
  --danger: #ff8a8a;
  --shadow: 0 18px 55px rgba(0, 0, 0, .32);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

a {
  color: inherit;
}

button,
input {
  font: inherit;
}

.home-page {
  display: grid;
  place-items: center;
  padding: 24px;
}

.home {
  width: min(980px, 100%);
}

.home__intro h1,
.topbar h1,
.studio-header h1 {
  margin: 4px 0 0;
  font-size: clamp(1.8rem, 4vw, 3.4rem);
  line-height: 1.05;
}

.home__intro p {
  max-width: 760px;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.55;
}

.home__privacy {
  width: fit-content;
  max-width: 760px;
  margin-top: 16px;
  padding: 10px 12px;
  border: 1px solid rgba(79, 209, 139, .36);
  border-radius: 8px;
  background: rgba(79, 209, 139, .1);
  color: var(--text);
  font-weight: 700;
}

.home__steps {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 28px;
}

.home__steps article {
  min-height: 108px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.home__steps strong,
.home__steps span {
  display: block;
}

.home__steps strong {
  margin-bottom: 8px;
}

.home__steps span {
  color: var(--muted);
  line-height: 1.45;
}

.home__features {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 18px;
}

.home__features span {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: .9rem;
  font-weight: 700;
}

.eyebrow {
  margin: 0;
  color: var(--accent);
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.launcher {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 28px;
}

.launcher__item {
  display: flex;
  gap: 16px;
  min-height: 132px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.launcher__item strong {
  display: block;
  margin-bottom: 6px;
  font-size: 1.2rem;
}

.launcher__item small {
  color: var(--muted);
}

.launcher__icon {
  display: grid;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #07130c;
  font-weight: 900;
}

.home__credits {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 22px;
  color: var(--muted);
  font-size: .72rem;
}

.home__credits img {
  width: 40px;
  height: 40px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  object-fit: contain;
}

.home__credits a {
  text-underline-offset: 2px;
}

.home__credits a:hover {
  color: var(--accent);
}

.regie-page .studio {
  min-height: calc(100vh - 44px);
}

.license-banner {
  display: flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: .72rem;
}

.license-banner img {
  width: 26px;
  height: 26px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  object-fit: contain;
}

.license-banner a {
  text-underline-offset: 2px;
}

.license-banner a:hover {
  color: var(--accent);
}

.phone-shell {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 18px;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.phone-panel {
  width: min(520px, 100%);
  padding: 16px;
}

.topbar,
.studio-header {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 16px;
}

.back-link,
.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  text-decoration: none;
}

.icon-button {
  color: var(--text);
  cursor: pointer;
}

.status-pill {
  max-width: 150px;
  padding: 8px 10px;
  border-radius: 999px;
  background: rgba(79, 209, 139, .14);
  color: var(--accent);
  font-size: .78rem;
  font-weight: 800;
  text-align: center;
}

.phone-preview {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 64vh;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #050605;
  object-fit: cover;
}

.controls-grid {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 14px;
}

.field span,
.range-field span,
.peer-id span,
.fps-meter span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.field input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10130f;
  color: var(--text);
  padding: 0 12px;
}

.primary-button,
.secondary-button,
.file-button {
  display: inline-grid;
  min-height: 44px;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #07130c;
  padding: 0 16px;
  font-weight: 900;
  cursor: pointer;
}

.secondary-button,
.file-button {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--text);
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.info-strip {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 12px;
  padding: 12px;
  border-radius: 8px;
  background: #10130f;
  color: var(--muted);
}

.info-strip strong,
.peer-id strong {
  color: var(--text);
  word-break: break-all;
}

.studio {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) 300px 280px;
  gap: 18px;
  min-height: 100vh;
  padding: 18px;
}

.stage-wrap {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 14px;
  align-self: start;
}

.studio-header {
  justify-content: space-between;
}

.studio-header h1 {
  font-size: clamp(1.35rem, 3vw, 2.2rem);
}

.stage {
  position: relative;
  display: grid;
  width: min(100%, 1120px);
  aspect-ratio: 16 / 9;
  min-height: 300px;
  max-height: calc(100vh - 132px);
  justify-self: center;
  overflow: hidden;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #060806;
}

.stage canvas {
  width: 100%;
  height: 100%;
  background-color: #141714;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, .08) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(255, 255, 255, .08) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(255, 255, 255, .08) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(255, 255, 255, .08) 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  object-fit: contain;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
  pointer-events: none;
}

.empty-state[hidden],
.stage.has-video .empty-state {
  display: none;
}

.empty-state strong {
  color: var(--text);
  font-size: 1.25rem;
}

.ai-busy-overlay {
  position: absolute;
  top: 16px;
  left: 50%;
  z-index: 2;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 32px);
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid rgba(255, 214, 102, .75);
  border-radius: 8px;
  background: rgba(21, 18, 8, .9);
  color: #ffe08a;
  box-shadow: 0 12px 30px rgba(0, 0, 0, .38);
  transform: translateX(-50%);
  pointer-events: none;
}

.ai-busy-overlay[hidden] {
  display: none;
}

.busy-spinner {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  border: 2px solid rgba(255, 224, 138, .35);
  border-top-color: #ffe08a;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

.tools-panel,
.qr-panel {
  display: grid;
  align-content: start;
  gap: 14px;
}

.tools-panel .panel,
.qr-panel .panel {
  padding: 16px;
}

.panel.has-collapse-control {
  position: relative;
}

.panel.has-collapse-control>.eyebrow {
  min-height: 30px;
  padding-right: 82px;
}

.panel-collapse-button {
  position: absolute;
  top: 10px;
  right: 10px;
  min-width: 70px;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  font-size: .75rem;
  font-weight: 800;
  cursor: pointer;
}

.panel.has-collapse-control.is-tool-collapsed {
  min-height: 52px;
  padding-top: 16px;
  padding-bottom: 6px;
  box-shadow: none;
}

.panel.has-collapse-control.is-tool-collapsed> :not(.eyebrow):not(.panel-collapse-button) {
  display: none;
}

.presentation-panel {
  order: 1;
}

.background-panel {
  order: 2;
}

.recording-panel {
  order: 3;
}

.broadcast-panel {
  order: 4;
}

.broadcast-panel .primary-button {
  width: 100%;
  margin-top: 10px;
}

.broadcast-quality-field {
  display: block;
  margin-top: 10px;
}

.broadcast-quality-field select {
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10130f;
  color: var(--text);
}

.broadcast-panel .primary-button.is-broadcasting {
  background: var(--danger);
  color: #240707;
}

.broadcast-link-box {
  margin-top: 12px;
}

.broadcast-link-box>label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.copy-row input {
  width: 100%;
  min-width: 0;
  height: 38px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10130f;
  color: var(--text);
  font-size: .76rem;
}

.copy-row .compact-button {
  width: auto;
}

.viewer-count {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: .82rem;
}

.viewer-count strong {
  color: var(--text);
}

.recording-panel .secondary-button.is-recording {
  border-color: var(--danger);
  color: var(--danger);
}

.connection-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}

.connection-head>div {
  display: contents;
}

.compact-button {
  width: auto;
  min-height: 30px;
  margin-top: 0;
  padding: 0 10px;
  font-size: .78rem;
  line-height: 1;
  white-space: nowrap;
}

.compact-peer-id {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 8px 0 0;
  padding: 8px 10px;
  min-width: 0;
}

.compact-peer-id span {
  display: inline;
  flex: 0 0 auto;
  margin: 0;
}

.compact-peer-id strong {
  flex: 1 1 auto;
  min-width: 0;
  font-size: .95rem;
  line-height: 1.2;
  white-space: nowrap;
  word-break: normal;
}

.connection-panel.is-collapsed .compact-peer-id {
  margin-bottom: 0;
}

.qr-content[hidden] {
  display: none;
}

.peer-id {
  margin: 12px 0;
  padding: 12px;
  border-radius: 8px;
  background: #10130f;
}

.qr-code {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  border-radius: 8px;
  background: #fff;
}

.text-link {
  display: block;
  margin-top: 10px;
  color: var(--accent-2);
  word-break: break-all;
}

.muted {
  color: var(--muted);
}

.range-field,
.toggle-field {
  display: block;
  margin-top: 14px;
}

.segmented-control {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.segmented-control label {
  cursor: pointer;
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.segmented-control span {
  display: grid;
  min-height: 40px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 800;
}

.segmented-control input:checked+span {
  border-color: rgba(79, 209, 139, .72);
  background: rgba(79, 209, 139, .16);
  color: var(--accent);
}

.color-tools {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  margin-top: 12px;
}

.color-field {
  display: grid;
  grid-template-columns: 1fr 52px;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10130f;
}

.color-field span {
  color: var(--muted);
  font-size: .78rem;
  font-weight: 700;
}

.color-field input {
  width: 44px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
}

.primary-button:disabled,
.secondary-button:disabled,
input:disabled,
select:disabled {
  cursor: wait;
  opacity: .55;
}

.color-tools .secondary-button {
  width: auto;
  margin-top: 0;
}

.ai-button {
  margin-top: 14px;
}

.ai-button.is-active {
  border-color: rgba(141, 201, 255, .7);
  background: rgba(141, 201, 255, .14);
  color: var(--accent-2);
}

.ai-button.is-working {
  position: relative;
  overflow: hidden;
}

.ai-button.is-working::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .22), transparent);
  transform: translateX(-100%);
  animation: loading-sweep 1.1s linear infinite;
}

.ai-status {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #10130f;
  color: var(--muted);
}

.ai-status.is-working {
  border-color: rgba(255, 214, 102, .75);
  background: rgba(255, 214, 102, .12);
  color: #ffe08a;
  font-weight: 800;
}

.compact-text {
  margin: 10px 0 0;
  font-size: .82rem;
}

.stage.is-picking canvas {
  cursor: crosshair;
}

@keyframes loading-sweep {
  to {
    transform: translateX(100%);
  }
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.range-field input {
  width: 100%;
  accent-color: var(--accent);
}

.toggle-field {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
}

.tools-panel .file-button,
.tools-panel .secondary-button,
.qr-panel .file-button,
.qr-panel .secondary-button {
  margin-top: 10px;
}

.qr-panel .compact-button {
  margin-top: 0;
}

.fps-meter {
  display: flex;
  justify-content: space-between;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.fps-meter span {
  margin: 0;
}

.viewer-page {
  overflow: hidden;
  background: #050605;
}

.viewer-shell {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  min-height: 100dvh;
}

.viewer-stage {
  position: relative;
  display: grid;
  min-height: 0;
  overflow: hidden;
  place-items: center;
  background: #050605;
}

.viewer-stage video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.viewer-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

.viewer-empty-state[hidden],
.viewer-empty-state .busy-spinner[hidden] {
  display: none;
}

.viewer-empty-state strong {
  color: var(--text);
  font-size: clamp(1.3rem, 4vw, 2rem);
}

.viewer-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.viewer-controls strong {
  display: block;
  margin-top: 3px;
}

.viewer-controls .primary-button {
  flex: 0 0 auto;
}

@media (max-width: 1180px) {
  .studio {
    grid-template-columns: minmax(0, 1fr) 320px;
  }

  .qr-panel {
    grid-column: 1 / -1;
  }

  .qr-panel .panel {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 220px minmax(180px, 1fr);
    align-items: start;
    gap: 14px;
  }

  .qr-code {
    width: 220px;
  }
}

@media (max-width: 900px) {

  .studio,
  .launcher,
  .home__steps {
    grid-template-columns: 1fr;
  }

  .studio {
    padding: 12px;
  }

  .stage {
    width: 100%;
    max-height: none;
  }

  .tools-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .qr-panel .panel {
    display: block;
  }

  .qr-code {
    width: 100%;
  }
}

@media (max-width: 620px) {

  .controls-grid,
  .tools-panel {
    grid-template-columns: 1fr;
  }

  .home-page {
    place-items: start;
    padding: 16px;
  }

  .home__intro h1 {
    font-size: 2rem;
  }

  .topbar,
  .studio-header {
    align-items: flex-start;
  }
}