:root {
  color-scheme: dark;
  --app-height: 100vh;
  --bg: #070707;
  --bg-raised: #111111;
  --panel: #161616;
  --panel-strong: #1f1f1f;
  --text: #f4f7f4;
  --muted: #a7ada8;
  --faint: #6f7670;
  --line: rgba(255, 255, 255, 0.1);
  --accent: #18e08a;
  --accent-strong: #5cffb2;
  --danger: #ff4d6d;
  --warn: #ffd166;
  --shadow: 0 18px 56px rgba(0, 0, 0, 0.5);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --radius: 8px;
  --page-max: 1040px;
  --chat-max: 1120px;
}

@supports (height: 100dvh) {
  :root {
    --app-height: 100dvh;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
}

body {
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  color: var(--text);
  letter-spacing: 0;
  overflow-x: hidden;
}

button,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
}

.app-shell {
  position: relative;
  min-height: var(--app-height);
  overflow: hidden;
  background: linear-gradient(180deg, #070707, #0d0d0d 48%, #070707);
}

.screen {
  display: none;
  min-height: var(--app-height);
  padding: 14px;
  opacity: 0;
  transform: translateY(10px);
  transition:
    opacity 160ms ease,
    transform 160ms ease;
}

.screen.is-active {
  display: flex;
  opacity: 1;
  transform: translateY(0);
}

.screen-home {
  position: relative;
  flex-direction: column;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  padding-bottom: calc(18px + var(--safe-bottom));
  isolation: isolate;
}

.home-media {
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    linear-gradient(180deg, rgba(7, 7, 7, 0.58), rgba(7, 7, 7, 0.68) 42%, rgba(7, 7, 7, 0.96) 100%),
    url("https://images.unsplash.com/photo-1516321318423-f06f85e504b3?auto=format&fit=crop&w=1600&q=80")
      center / cover;
  filter: saturate(0.78) contrast(1.05);
}

.home-media::after {
  position: absolute;
  inset: 0;
  content: "";
  background: rgba(0, 0, 0, 0.18);
}

.topbar,
.app-header,
.chat-header {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-weight: 780;
  text-decoration: none;
}

.app-home-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
}

.app-home-top > * {
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.26);
  border-radius: 8px;
  background: linear-gradient(135deg, var(--accent), #ffffff);
  box-shadow: 0 0 28px rgba(24, 224, 138, 0.34);
}

.top-pill,
.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(17, 17, 17, 0.78);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
  backdrop-filter: blur(18px);
}

.live-pill,
.home-menu-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(9, 9, 9, 0.58);
  color: var(--text);
  font-size: 0.8rem;
  font-weight: 800;
  text-decoration: none;
  backdrop-filter: blur(18px);
}

.live-pill {
  gap: 6px;
  justify-self: end;
  padding: 0 9px;
}

.live-pill strong {
  color: var(--accent-strong);
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 16px rgba(24, 224, 138, 0.62);
}

.home-menu-icon {
  padding: 0 9px;
  cursor: pointer;
}

.status-badge::before {
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 50%;
  background: var(--faint);
  content: "";
}

.status-searching::before,
.status-connecting::before {
  background: var(--warn);
}

.status-connected::before {
  background: var(--accent);
}

.status-disconnected::before,
.status-error::before {
  background: var(--danger);
}

.home-content {
  position: relative;
  z-index: 1;
  width: min(100%, 360px);
  margin: auto auto;
  padding-top: 0;
  text-align: center;
}

.app-home-center {
  display: grid;
  justify-items: center;
  gap: 14px;
  align-content: center;
  transform: none;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  color: var(--text);
  letter-spacing: 0;
  line-height: 1.02;
}

h1 {
  max-width: 11ch;
  margin-inline: auto;
  font-size: clamp(2rem, 7.8vw, 3rem);
}

h2 {
  font-size: clamp(1.58rem, 5.2vw, 2.2rem);
}

.screen-copy p,
.message-panel p,
.modal-panel p,
.empty-state span {
  color: var(--muted);
  line-height: 1.55;
}

.start-mega {
  width: 100%;
  min-height: 64px;
  margin-top: 4px;
  font-size: 1.06rem;
  box-shadow: 0 18px 38px rgba(24, 224, 138, 0.22);
}

.start-mega:hover,
.start-mega:focus-visible {
  transform: translateY(-1px) scale(1.015);
}

.start-mega:active {
  transform: translateY(1px) scale(0.98);
}

.secondary-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: 100%;
  gap: 8px;
}

.link-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 42px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 8px;
  background: rgba(8, 8, 8, 0.48);
  color: #e9eeeb;
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 780;
  backdrop-filter: blur(14px);
  transition:
    transform 130ms ease,
    border-color 130ms ease,
    background 130ms ease;
}

.link-action:active {
  transform: scale(0.97);
}

.bottom-trust {
  position: relative;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px;
  width: min(100%, 360px);
  margin: 0 auto;
}

.bottom-trust span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 1 1 calc(33.333% - 6px);
  min-height: 34px;
  min-width: 0;
  padding: 0 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.36);
  color: #e8eeea;
  font-size: 0.76rem;
  font-weight: 760;
  text-align: center;
  backdrop-filter: blur(14px);
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 50px;
  min-width: 50px;
  padding: 0 16px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 820;
  color: var(--text);
  transition:
    transform 130ms ease,
    border-color 130ms ease,
    background 130ms ease,
    opacity 130ms ease;
  -webkit-tap-highlight-color: transparent;
}

.button:active {
  transform: translateY(1px) scale(0.99);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.button-primary {
  background: var(--accent);
  color: #04120b;
  box-shadow: 0 16px 36px rgba(24, 224, 138, 0.22);
}

.button-secondary {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
}

.screen-preview,
.screen-chat,
.screen-message {
  flex-direction: column;
  gap: 14px;
  background: var(--bg);
}

.screen-preview {
  padding-bottom: calc(92px + var(--safe-bottom));
}

.screen-chat {
  position: relative;
  gap: 0;
  overflow: hidden;
  padding: 10px 10px calc(92px + var(--safe-bottom));
  background: #000;
}

.icon-button {
  min-height: 38px;
  padding: 0 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.07);
  color: var(--text);
  cursor: pointer;
  font-weight: 760;
}

.preview-layout,
.chat-stage {
  display: grid;
  flex: 1;
  gap: 14px;
  min-height: 0;
  width: min(100%, var(--page-max));
  margin: 0 auto;
}

.screen-chat .chat-stage {
  gap: 0;
  width: min(100%, var(--chat-max));
  min-height: calc(var(--app-height) - 104px);
}

.preview-layout {
  grid-template-rows: minmax(0, 1fr) auto;
  align-items: start;
}

.video-shell {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.06), transparent),
    #050505;
  box-shadow: var(--shadow);
}

.preview-shell {
  width: 100%;
  min-height: 0;
  height: clamp(250px, 46vh, 420px);
  margin-inline: auto;
}

.remote-shell {
  height: 100%;
  min-height: calc(var(--app-height) - 140px);
}

.screen-chat .remote-shell {
  min-height: calc(var(--app-height) - 104px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #050505;
}

#remoteVideo {
  object-position: center top;
}

#localPreview {
  object-fit: contain;
  object-position: center;
  background: #000;
}

#localPreview.is-unmirrored,
.local-pip.is-unmirrored {
  transform: scaleX(-1);
}

.local-pip {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: clamp(74px, 24vw, 108px);
  height: auto;
  aspect-ratio: 9 / 14;
  object-fit: contain;
  object-position: center;
  background: #000;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.46);
}

.screen-chat .local-pip {
  top: 74px;
  right: 10px;
  bottom: auto;
  z-index: 6;
  width: clamp(78px, 23vw, 108px);
  min-width: 78px;
  max-height: 148px;
}

.chat-overlay {
  position: absolute;
  right: 0;
  left: 0;
  z-index: 5;
  display: grid;
  align-items: center;
  gap: 8px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 12px 12px;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.66), transparent);
  pointer-events: none;
}

.chat-overlay.top {
  top: 0;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.chat-overlay > div {
  min-width: 0;
}

#chatStatus {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
}

.chat-overlay h2 {
  max-width: 18ch;
  font-size: 0.98rem;
  line-height: 1.1;
}

.chat-overlay .eyebrow {
  margin-bottom: 5px;
  font-size: 0.68rem;
}

.report-chip {
  grid-column: 2;
  grid-row: 2;
  justify-self: end;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(12, 12, 12, 0.56);
  color: #ffd8df;
  cursor: pointer;
  font-size: 0.78rem;
  font-weight: 820;
  pointer-events: auto;
  backdrop-filter: blur(14px);
}

.report-chip:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 8px;
  padding: 18px;
  text-align: center;
  background: #080808;
}

.empty-state strong {
  font-size: 1.1rem;
}

.empty-state.is-hidden {
  display: none;
}

.screen-copy {
  display: grid;
  align-content: start;
  max-width: 100%;
  gap: 0;
  padding-bottom: 0;
}

.screen-copy p {
  margin: 10px 0 0;
}

.mini-note {
  display: inline-flex;
  align-items: center;
  width: max-content;
  max-width: 100%;
  min-height: 32px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 720;
}

.bottom-panel,
.action-bar {
  position: fixed;
  right: 12px;
  bottom: calc(12px + var(--safe-bottom));
  left: 12px;
  z-index: 10;
  display: grid;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(7, 7, 7, 0.88);
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(22px);
}

.bottom-panel {
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.9fr);
}

.action-bar {
  grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.12fr);
}

.screen-chat .action-bar {
  grid-template-columns: minmax(0, 0.88fr) minmax(0, 1.12fr);
  background: rgba(7, 7, 7, 0.72);
}

.screen-chat .action-bar .button {
  min-height: 50px;
  font-size: 0.94rem;
}

.action-bar .button,
.bottom-panel .button {
  width: 100%;
  min-height: 50px;
  padding-inline: 10px;
}

.screen-message {
  align-items: center;
  justify-content: center;
}

.message-panel,
.modal-panel {
  width: min(100%, 460px);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.message-panel {
  padding: 20px;
}

.message-panel p {
  margin: 14px 0 0;
}

.message-actions,
.modal-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  margin-top: 22px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: calc(82px + var(--safe-bottom));
  left: 18px;
  z-index: 30;
  display: none;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(20, 20, 20, 0.94);
  color: var(--text);
  box-shadow: var(--shadow);
}

.toast.is-visible {
  display: block;
}

.debug-panel {
  position: absolute;
  right: 10px;
  bottom: 10px;
  left: 10px;
  z-index: 7;
  max-height: 32vh;
  overflow: auto;
  padding: 10px 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.76);
  color: #d9fff0;
  font-family:
    ui-monospace,
    "SFMono-Regular",
    Consolas,
    "Liberation Mono",
    monospace;
  font-size: 0.72rem;
  line-height: 1.45;
  white-space: pre-wrap;
  pointer-events: none;
}

.debug-panel[hidden] {
  display: none;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: end center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.66);
  backdrop-filter: blur(10px);
}

.modal[hidden] {
  display: none;
}

.modal-panel {
  padding: 20px;
}

.modal-panel h2 {
  font-size: 1.55rem;
}

.modal-panel p {
  margin: 10px 0 0;
}

.modal-form {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.modal-form label {
  display: grid;
  gap: 8px;
  color: var(--text);
  font-weight: 760;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d0d0d;
  color: var(--text);
  outline: none;
}

input {
  min-height: 48px;
  padding: 0 12px;
}

select {
  min-height: 48px;
  padding: 0 12px;
}

textarea {
  resize: vertical;
  min-height: 90px;
  padding: 12px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(24, 224, 138, 0.62);
}

.form-error {
  min-height: 18px;
  margin: -2px 0 0;
  color: #ff9aaa;
  font-size: 0.82rem;
}

.modal-actions-single {
  grid-template-columns: 1fr;
}

@media (min-width: 720px) {
  .screen {
    padding: 18px;
  }

  .screen-home {
    padding: 18px 18px calc(22px + var(--safe-bottom));
  }

  .app-home-top,
  .app-header,
  .preview-layout {
    width: min(100%, var(--page-max));
    margin-inline: auto;
  }

  h1 {
    max-width: 12ch;
    font-size: clamp(3.1rem, 4.6vw, 3.9rem);
  }

  h2 {
    font-size: clamp(1.95rem, 2.8vw, 2.35rem);
  }

  .home-content {
    width: min(100%, 420px);
    padding-top: 0;
  }

  .app-home-center {
    gap: 16px;
    transform: none;
  }

  .bottom-trust {
    width: min(100%, 420px);
  }

  .preview-layout {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 320px);
    grid-template-rows: 1fr;
    align-items: center;
    gap: 20px;
  }

  .screen-copy {
    align-content: center;
    max-width: 320px;
  }

  .preview-shell {
    width: 100%;
    height: min(68vh, 600px);
  }

  .bottom-panel,
  .action-bar {
    right: auto;
    left: 50%;
    width: min(calc(100% - 36px), 960px);
    transform: translateX(-50%);
    padding: 10px;
  }

  .chat-stage {
    min-height: calc(var(--app-height) - 128px);
  }

  .remote-shell {
    min-height: min(72vh, 760px);
  }

  .screen-chat .remote-shell,
  .screen-chat .chat-stage {
    min-height: min(78vh, 760px);
  }

  .screen-chat .action-bar {
    width: min(calc(100% - 36px), 520px);
  }

  .chat-overlay.top {
    grid-template-columns: minmax(0, 1fr) auto auto;
    align-items: center;
  }

  #chatStatus,
  .report-chip {
    grid-column: auto;
    grid-row: auto;
  }

  .chat-overlay h2 {
    max-width: none;
    font-size: 1.08rem;
  }

  .screen-chat .local-pip {
    top: 88px;
    right: 14px;
    width: clamp(96px, 14vw, 132px);
    max-height: 188px;
  }

  .debug-panel {
    right: 14px;
    bottom: 14px;
    left: auto;
    width: min(320px, calc(100% - 28px));
    max-height: 240px;
  }

  .modal {
    place-items: center;
  }

  .message-actions,
  .modal-actions {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 390px) {
  .screen-home {
    padding-inline: 12px;
  }

  h1 {
    font-size: 1.92rem;
  }

  .start-mega {
    min-height: 58px;
  }

  h2 {
    font-size: 1.42rem;
  }

  .secondary-actions {
    grid-template-columns: 1fr;
  }

  .remote-shell {
    min-height: calc(var(--app-height) - 148px);
  }

  .screen-chat .local-pip {
    top: 70px;
    width: 74px;
    min-width: 74px;
    max-height: 126px;
  }
}

@media (max-width: 719px) {
  .preview-shell {
    height: min(44vh, 380px);
  }

  .home-menu-icon {
    min-width: 0;
    font-size: 0.74rem;
  }

  .screen-chat .action-bar {
    width: auto;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
