*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --pink: #e91e8c;
  --pink-dark: #c4177a;
  --pink-light: #fce4f3;
  --bg: #0f0f12;
  --surface: #1a1a22;
  --surface-2: #252530;
  --text: #f5f5f7;
  --text-muted: #9ca3af;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
  --header-h: 56px;
  --footer-h: 40px;
}

html,
body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  /* Mobile: respeita notches e barras de gestos (iOS) */
  padding-top: env(safe-area-inset-top, 0px);
  padding-right: env(safe-area-inset-right, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  padding-left: env(safe-area-inset-left, 0px);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

#app {
  height: 100%;
}

.screen {
  display: none;
  height: 100%;
  flex-direction: column;
}

.screen--active {
  display: flex;
}

/* Splash */
.splash {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background:
    radial-gradient(ellipse at 20% 80%, rgba(233, 30, 140, 0.15) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 20%, rgba(233, 30, 140, 0.08) 0%, transparent 50%),
    var(--bg);
}

.splash__logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  margin-bottom: 16px;
}

.splash__icon {
  font-size: 48px;
}

.splash h1 {
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #fff 0%, var(--pink) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.splash__tagline {
  color: var(--text-muted);
  font-size: 1.05rem;
  margin-bottom: 24px;
  max-width: 320px;
}

.mode-picker {
  display: flex;
  gap: 10px;
  margin-bottom: 24px;
  flex-wrap: wrap;
  justify-content: center;
  max-width: 420px;
}

.mode-card {
  flex: 1;
  min-width: 100px;
  max-width: 130px;
  padding: 16px 12px;
  border-radius: var(--radius);
  border: 2px solid rgba(255, 255, 255, 0.1);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-family: inherit;
  text-align: center;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}

.mode-card:hover {
  border-color: rgba(233, 30, 140, 0.4);
}

.mode-card--active {
  border-color: var(--pink);
  background: rgba(233, 30, 140, 0.12);
}

.mode-card__icon {
  display: block;
  font-size: 1.75rem;
  margin-bottom: 6px;
}

.mode-card__title {
  display: block;
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 4px;
}

.mode-card__desc {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.splash__note {
  margin-top: 16px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.splash__error {
  margin-top: 16px;
  color: var(--danger);
  font-size: 0.9rem;
  max-width: 360px;
}

.age-gate {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  max-width: 360px;
  margin: 0 0 16px;
  text-align: left;
  font-size: 0.82rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1.4;
}

.age-gate input {
  margin-top: 3px;
  accent-color: var(--pink);
  flex-shrink: 0;
}

.age-gate a {
  color: var(--pink);
  text-decoration: underline;
}

.auth-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
  justify-content: center;
}

.auth-bar__status {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-right: 4px;
}

.btn--sm {
  padding: 6px 14px;
  font-size: 0.8rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.auth-form__field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  text-align: left;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.auth-form__field input {
  padding: 12px 14px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 1rem;
}

.auth-form__field input:focus {
  outline: none;
  border-color: var(--pink);
}

.auth-form__error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: 999px;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s, opacity 0.15s, background 0.15s;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn--primary {
  background: var(--pink);
  color: #fff;
}

.btn--primary:hover:not(:disabled) {
  background: var(--pink-dark);
}

.btn--lg {
  padding: 14px 40px;
  font-size: 1.1rem;
}

.btn--ghost {
  background: var(--surface-2);
  color: var(--text);
}

.btn--ghost:hover:not(:disabled) {
  background: #333340;
}

.btn--danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--danger);
  border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn--danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
}

/* Header */
.header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.header__brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.header__icon {
  font-size: 1.25rem;
}

.header__name {
  font-weight: 700;
  font-size: 1.1rem;
}

.header__actions {
  display: flex;
  gap: 8px;
}

/* Botões do header compactos no telemóvel (base) */
.header__actions .btn {
  padding: 8px 14px;
  font-size: 0.85rem;
}

.badge {
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge--waiting {
  background: rgba(234, 179, 8, 0.15);
  color: #fbbf24;
}

.badge--connected {
  background: rgba(34, 197, 94, 0.15);
  color: var(--success);
}

.badge--idle {
  background: var(--surface-2);
  color: var(--text-muted);
}

.badge--mode {
  background: rgba(233, 30, 140, 0.15);
  color: var(--pink);
}

/* Main layout */
/* Layout base = MOBILE (1 coluna: vídeo em cima, chat em baixo) */
.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: 60vh 1fr;
  min-height: 0;
  overflow: hidden;
}

/* Corpo da sala: permite barras de anúncios laterais (desktop) */
.room-body {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* Espaços para anúncios — ocultos até teres o código do fornecedor.
   Remove o atributo hidden e insere o teu código dentro da div. */
.ad-slot--top {
  height: 90px;
  flex-shrink: 0;
}

.ad-slot--left,
.ad-slot--right {
  width: 160px;
  flex-shrink: 0;
}

.main--text-only {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr;
}

.main--text-only .video-panel {
  display: none;
}

.main--text-only .chat-panel {
  border-left: none;
}

#remote-audio {
  display: none;
}

/* Voice UI */
.voice-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: linear-gradient(160deg, #1a1020 0%, #0f0f12 100%);
}

.voice-ui[hidden] {
  display: none !important;
}

.voice-ui__icon {
  font-size: 4rem;
  animation: pulse 2s ease-in-out infinite;
}

.voice-ui__bars {
  display: flex;
  gap: 4px;
  align-items: flex-end;
  height: 32px;
}

.voice-ui__bars span {
  width: 4px;
  background: var(--pink);
  border-radius: 2px;
  animation: voiceBar 0.8s ease-in-out infinite;
}

.voice-ui__bars span:nth-child(1) { animation-delay: 0s; height: 12px; }
.voice-ui__bars span:nth-child(2) { animation-delay: 0.1s; height: 20px; }
.voice-ui__bars span:nth-child(3) { animation-delay: 0.2s; height: 28px; }
.voice-ui__bars span:nth-child(4) { animation-delay: 0.3s; height: 20px; }
.voice-ui__bars span:nth-child(5) { animation-delay: 0.4s; height: 12px; }

@keyframes pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.05); opacity: 0.85; }
}

@keyframes voiceBar {
  0%, 100% { transform: scaleY(0.5); }
  50% { transform: scaleY(1); }
}

.main--voice .video-feed--local {
  display: none;
}

.main--voice .video-feed--remote {
  flex: 1;
}

/* Video panel — MOBILE: chamada estilo WhatsApp (remoto a preencher, tu em PIP) */
.video-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  background: #000;
  min-height: 0;
}

.video-stack {
  flex: 1;
  position: relative;
  min-height: 0;
}

.video-feed {
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  container-type: size;
}

/* Remoto: preenche todo o painel de vídeo */
.video-feed--remote {
  position: absolute;
  inset: 0;
}

.video-feed--remote .video-feed__inner {
  width: 100%;
  height: 100%;
  border-radius: 0;
  border: none;
}

.video-feed--remote .video-feed__video {
  object-fit: cover;
}

/* Local: janela pequena (PIP) no canto, como o WhatsApp */
.video-feed--local {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 28%;
  max-width: 140px;
  aspect-ratio: 3 / 4;
  z-index: 5;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.video-feed--local .video-feed__inner {
  width: 100%;
  height: 100%;
  border-radius: 12px;
}

.video-feed--local .video-feed__video {
  object-fit: cover;
}

.video-feed--local .video-feed__label {
  top: 6px;
  left: 6px;
  font-size: 0.55rem;
  padding: 2px 8px;
}

.video-feed__inner {
  position: relative;
  width: min(100cqw, 100cqh);
  height: min(100cqw, 100cqh);
  aspect-ratio: 1 / 1;
  background: #0a0a0e;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.08);
  flex-shrink: 0;
}

@supports not (width: 1cqw) {
  .video-feed__inner {
    width: 100%;
    max-width: 100%;
    height: auto;
    aspect-ratio: 1 / 1;
    max-height: 100%;
  }
}

.video-feed__label {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.55);
  color: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(6px);
}

.video-feed__video--mirror {
  transform: scaleX(-1);
}

.video-feed__video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
  background: #0a0a0e;
}

.video-feed__placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: linear-gradient(160deg, #1a1020 0%, #0f0f12 100%);
  color: var(--text-muted);
  z-index: 2;
}

.video-feed__placeholder.hidden {
  display: none;
}

/* Controlos sobrepostos ao vídeo (mobile, estilo chamada) */
.video-panel__controls {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 6;
  display: flex;
  justify-content: center;
  gap: 14px;
  padding: 18px 10px 14px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.65), transparent);
}

.ctrl-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  transition: background 0.15s;
}

.ctrl-btn:hover {
  background: rgba(0, 0, 0, 0.8);
}

.ctrl-btn.off {
  background: rgba(239, 68, 68, 0.8);
}

.ctrl-btn--active {
  background: rgba(233, 30, 140, 0.35);
  color: #fff;
  box-shadow: 0 0 0 2px rgba(233, 30, 140, 0.5);
}

/* Chat panel */
.chat-panel {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  min-height: 0;
}

.chat-panel__header {
  padding: 12px 16px;
  font-weight: 600;
  font-size: 0.9rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.typing {
  font-size: 0.75rem;
  color: var(--pink);
  font-weight: 500;
}

.chat-panel__messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
}

.chat-system {
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-muted);
  padding: 8px;
}

.chat-msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  line-height: 1.4;
  word-break: break-word;
}

.chat-msg--mine {
  align-self: flex-end;
  background: var(--pink);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.chat-msg--theirs {
  align-self: flex-start;
  background: var(--surface-2);
  color: var(--text);
  border-bottom-left-radius: 4px;
}

.chat-panel__input-row {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.chat-panel__input-row input {
  flex: 1;
  padding: 10px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
}

.chat-panel__input-row input:focus {
  border-color: var(--pink);
}

.chat-panel__input-row input:disabled {
  opacity: 0.5;
}

/* Footer */
.footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--surface);
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.footer__link {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-family: inherit;
  font-size: inherit;
  text-decoration: none;
}

.footer__link:hover {
  color: var(--pink);
}

.footer__free {
  color: var(--success);
  font-weight: 500;
}

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid rgba(233, 30, 140, 0.2);
  border-top-color: var(--pink);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal[hidden] {
  display: none;
}

.modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
}

.modal__box {
  position: relative;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 360px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.modal__box h3 {
  margin-bottom: 8px;
}

.modal__box p {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 16px;
}

.modal__reasons {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 16px;
}

.reason-btn {
  padding: 12px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
  transition: border-color 0.15s, background 0.15s;
}

.reason-btn:hover {
  border-color: var(--pink);
  background: rgba(233, 30, 140, 0.1);
}

/* Desktop (>=769px): vídeo + chat lado a lado */
@media (min-width: 769px) {
  .main {
    grid-template-columns: 1fr 380px;
    grid-template-rows: none;
  }

  .chat-panel {
    border-top: none;
    border-left: 1px solid rgba(255, 255, 255, 0.06);
  }

  .header__actions .btn {
    padding: 10px 20px;
    font-size: 0.95rem;
  }

  .splash h1 {
    font-size: 2.5rem;
  }

  /* Vídeos lado a lado: remoto | tu */
  .video-stack {
    display: flex;
    flex-direction: row;
    gap: 8px;
    padding: 8px;
  }

  .video-feed {
    flex: 1;
  }

  .video-feed--remote,
  .video-feed--local {
    position: relative;
    inset: auto;
    top: auto;
    right: auto;
    width: auto;
    max-width: none;
    aspect-ratio: auto;
    z-index: auto;
    border-radius: 0;
    overflow: visible;
    box-shadow: none;
  }

  .video-feed--remote .video-feed__inner,
  .video-feed--local .video-feed__inner {
    width: min(100cqw, 100cqh);
    height: min(100cqw, 100cqh);
    aspect-ratio: 1 / 1;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.08);
  }

  .video-feed--remote .video-feed__video,
  .video-feed--local .video-feed__video {
    object-fit: contain;
  }

  .video-feed--local .video-feed__label {
    top: 10px;
    left: 10px;
    font-size: 0.7rem;
    padding: 4px 10px;
  }

  .video-panel__controls {
    position: relative;
    left: auto;
    right: auto;
    bottom: auto;
    z-index: auto;
    padding: 10px;
    background: var(--surface);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
  }
}

/* Ecrãs largos: seletor de modo mais confortável */
@media (min-width: 1024px) {
  .mode-picker {
    max-width: 560px;
  }
}

/* Toque (telemóveis/tablets): alvos maiores, sem zoom automático ao focar */
@media (pointer: coarse) {
  .ctrl-btn {
    width: 48px;
    height: 48px;
  }

  .chat-panel__input-row input {
    font-size: 16px;
  }

  .mode-card {
    min-height: 92px;
  }
}
