:root {
  --bg: #202124;
  --tile: #3c4043;
  --text: #e8eaed;
  --muted: #9aa0a6;
  --red: #ea4335;
  --blue: #8ab4f8;
  --btn: #3c4043;
  --btn-hover: #4a4e51;
  --primary: #1a73e8;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; margin: 0; overscroll-behavior: none; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: "Google Sans", Roboto, -apple-system, "Segoe UI", Arial, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;   /* sem "Salvar vídeo" no toque longo do iPhone */
  touch-action: manipulation;    /* sem zoom por toque duplo */
  overflow: hidden;
}
[hidden] { display: none !important; }
.view { height: 100vh; height: 100dvh; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; }
svg { width: 24px; height: 24px; fill: currentColor; display: block; }
video { -webkit-touch-callout: none; }

.round {
  width: 48px; height: 48px; border-radius: 50%;
  background: var(--btn);
  display: inline-grid; place-items: center;
  transition: background .15s;
}
.round.off { background: var(--red); }
.round .i-off, .round.off .i-on { display: none; }
.round.off .i-off { display: block; }
@media (hover: hover) {
  .round:hover { background: var(--btn-hover); }
  .round.off:hover { background: #d93025; }
}

.primary {
  background: var(--primary); color: #fff;
  border-radius: 24px; padding: 12px 28px;
  font-weight: 500; font-size: 15px;
}
.primary:disabled { opacity: .6; cursor: default; }
.primary.big { padding: 14px 32px; font-size: 16px; }
.btn-outline {
  border: 1px solid #dadce0; background: #fff; color: var(--primary);
  border-radius: 24px; padding: 12px 24px; font-weight: 500;
}

.spinner {
  width: 36px; height: 36px; border-radius: 50%;
  border: 3px solid #5f6368; border-top-color: var(--blue);
  animation: spin 1s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Lobby ---------- */
#lobby {
  background: #fff; color: #202124;
  display: flex; align-items: center; justify-content: center;
  gap: 48px; padding: 24px; flex-wrap: wrap; overflow: auto;
}
.preview-box {
  position: relative; width: min(740px, calc(100vw - 32px)); aspect-ratio: 16 / 9;
  background: #202124; border-radius: 12px; overflow: hidden;
}
.preview-box video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.cam-off-msg { position: absolute; inset: 0; display: grid; place-items: center; color: #fff; font-size: 18px; }
.preview-controls {
  position: absolute; bottom: 16px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 24px;
}
.preview-controls .round { width: 56px; height: 56px; background: rgba(0,0,0,.25); border: 1px solid #fff; color: #fff; }
.preview-controls .round.off { background: var(--red); border-color: var(--red); }
.perm-note { color: #5f6368; font-size: 14px; max-width: 740px; margin: 12px 0 0; }
.lobby-side { text-align: center; width: 320px; }
.lobby-side h1 { font-weight: 400; font-size: 28px; margin: 0 0 12px; }
.lobby-who { display: flex; align-items: center; justify-content: center; gap: 8px; color: #5f6368; margin-bottom: 24px; }
.mini-avatar {
  width: 24px; height: 24px; border-radius: 50%; background: #7b1fa2; color: #fff;
  display: grid; place-items: center; font-size: 12px; flex-shrink: 0;
}
.err { color: #d93025; min-height: 1.2em; font-size: 14px; }

/* ---------- Chamada (desktop) ---------- */
#call { position: relative; display: flex; flex-direction: column; background: var(--bg); overflow: hidden; }
.stage { position: relative; flex: 1; min-height: 0; padding: 16px 16px 0; }
.tile { position: relative; background: var(--tile); border-radius: 12px; overflow: hidden; }
.remote { width: 100%; height: 100%; background: #000; }
.remote video {
  position: relative; width: 100%; height: 100%;
  object-fit: contain; pointer-events: none;
}
.remote.fit-cover video { object-fit: cover; }
/* fundo desfocado quando o formato do vídeo não bate com a tela (ex.: horizontal no celular em pé) */
.bg {
  position: absolute; inset: -10%; width: 120%; height: 120%;
  filter: blur(28px) brightness(.55); opacity: 0; transition: opacity .6s;
}
.remote.blurred .bg { opacity: 1; }
.shield { position: absolute; inset: 0; } /* bloqueia "Salvar vídeo como" do menu do vídeo */
.name {
  position: absolute; left: 12px; bottom: 10px; z-index: 2;
  font-size: 14px; font-weight: 500; text-shadow: 0 1px 3px rgba(0,0,0,.8);
  display: flex; align-items: center; gap: 4px;
}
.muted-ico svg { width: 18px; height: 18px; }
.connecting {
  position: absolute; inset: 0; z-index: 1;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px;
  background: var(--tile); color: var(--muted);
}
.watermark {
  position: absolute; z-index: 1; pointer-events: none;
  color: rgba(255,255,255,.14); font-size: 13px; letter-spacing: 1px;
  transition: top 3s ease, left 3s ease;
}

.self {
  position: absolute; z-index: 3;
  width: clamp(160px, 22vw, 300px); aspect-ratio: 16 / 9;
  box-shadow: 0 2px 12px rgba(0,0,0,.5);
  outline: 3px solid transparent;
  transition: outline-color .12s, top .25s, bottom .25s, left .25s, right .25s;
  touch-action: none; cursor: grab;
}
.self.dragging { transition: none; cursor: grabbing; }
.self.cam-portrait { width: clamp(120px, 12vw, 200px); }
.self.speaking { outline-color: var(--blue); }
.self video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); pointer-events: none; }
.self.rear video { transform: none; }
.self .name { font-size: 12px; left: 8px; bottom: 6px; }
.corner-br { right: 32px; bottom: 16px; }
.corner-bl { left: 32px; bottom: 16px; }
.corner-tr { right: 32px; top: 32px; }
.corner-tl { left: 32px; top: 32px; }
.avatar { position: absolute; inset: 0; display: grid; place-items: center; background: var(--tile); }
.avatar span {
  width: 56px; height: 56px; border-radius: 50%; background: #5f6368;
  display: grid; place-items: center; font-size: 24px;
}

.topbar { display: none; }
.bar {
  height: 80px; flex-shrink: 0;
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  padding: 0 24px;
}
.bar-left { display: flex; gap: 12px; font-size: 16px; white-space: nowrap; overflow: hidden; }
.bar-left .sep { color: var(--muted); }
.bar-center { display: flex; gap: 12px; }
.hangup { width: 72px; border-radius: 24px; background: var(--red); }
.bar-right { justify-self: end; display: flex; gap: 4px; }
.icon-btn {
  width: 48px; height: 48px; border-radius: 50%; background: transparent;
  display: grid; place-items: center;
}
.icon-btn.active { color: var(--blue); }
.icon-btn.dark { color: #5f6368; }
@media (hover: hover) { .icon-btn:hover { background: rgba(255,255,255,.08); } .icon-btn.dark:hover { background: #f1f3f4; } }

.panel {
  position: absolute; right: 16px; top: 16px; bottom: 0; z-index: 5;
  width: 360px; background: #fff; color: #202124;
  border-radius: 12px; padding: 12px 12px 20px 24px; overflow: auto;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel h2 { font-size: 18px; font-weight: 400; margin: 0; }
.panel h3 { font-size: 14px; font-weight: 500; margin: 20px 0 8px; }
.panel p { color: #3c4043; font-size: 14px; margin: 4px 0; }
.person { display: flex; align-items: center; gap: 12px; padding: 8px 0; font-size: 14px; }
.person .mini-avatar { width: 36px; height: 36px; font-size: 15px; }
.person small { color: #5f6368; display: block; }

.unmute {
  position: absolute; inset: 0; z-index: 10;
  display: grid; place-items: center; background: rgba(0,0,0,.55); padding: 24px;
}

/* ---------- Mensagens ---------- */
.msg {
  background: #fff; color: #202124;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 24px calc(24px + var(--safe-r)) calc(24px + var(--safe-b)) calc(24px + var(--safe-l));
}
.msg h1 { font-weight: 400; font-size: 30px; margin: 0 0 12px; }
.msg p { color: #5f6368; margin: 0 0 28px; max-width: 480px; line-height: 1.5; }
.msg-actions { display: flex; gap: 12px; flex-wrap: wrap; justify-content: center; }
.msg.dark { background: var(--bg); }

/* =====================================================================
   Celular / tablet: vídeo de ponta a ponta, barras por cima do vídeo
   ===================================================================== */
@media (max-width: 820px), (max-height: 520px) {
  /* Lobby */
  #lobby {
    flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; gap: 20px;
    padding: calc(16px + var(--safe-t)) 16px calc(24px + var(--safe-b));
  }
  .lobby-preview, .lobby-side { width: 100%; }
  .preview-box { width: 100%; aspect-ratio: 3 / 4; max-height: 62dvh; margin: 0 auto; }
  .lobby-side h1 { font-size: 24px; }
  .lobby-side .primary.big { width: 100%; max-width: 420px; }

  /* Chamada */
  #call { display: block; }
  .stage { position: absolute; inset: 0; padding: 0; }
  .remote { border-radius: 0; }
  .remote .name { left: calc(16px + var(--safe-l)); bottom: calc(104px + var(--safe-b)); transition: bottom .25s; }

  .self { width: 30vw; max-width: 150px; border-radius: 10px; }
  .self:not(.cam-portrait) { width: 40vw; max-width: 200px; }
  .corner-br { right: calc(12px + var(--safe-r)); bottom: calc(104px + var(--safe-b)); }
  .corner-bl { left: calc(12px + var(--safe-l)); bottom: calc(104px + var(--safe-b)); }
  .corner-tr { right: calc(12px + var(--safe-r)); top: calc(64px + var(--safe-t)); }
  .corner-tl { left: calc(12px + var(--safe-l)); top: calc(64px + var(--safe-t)); }

  .topbar {
    display: flex; align-items: center; justify-content: space-between;
    position: absolute; left: 0; right: 0; top: 0; z-index: 4;
    padding: calc(8px + var(--safe-t)) calc(8px + var(--safe-r)) 16px calc(16px + var(--safe-l));
    background: linear-gradient(rgba(0,0,0,.55), transparent);
    transition: opacity .25s, transform .25s;
  }
  .top-code { font-size: 15px; font-weight: 500; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
  .top-actions { display: flex; gap: 4px; }

  .bar {
    position: absolute; left: 0; right: 0; bottom: 0; z-index: 4;
    height: auto; display: flex; justify-content: center;
    padding: 24px 12px calc(16px + var(--safe-b));
    background: linear-gradient(transparent, rgba(0,0,0,.6));
    transition: opacity .25s, transform .25s;
  }
  .bar-left, .bar-right { display: none; }
  .bar-center { gap: 20px; }
  .bar .round { width: 56px; height: 56px; background: rgba(60,64,67,.85); }
  .bar .round.off { background: var(--red); }
  .bar .hangup { width: 80px; border-radius: 28px; background: var(--red); }

  /* Toque no vídeo esconde/mostra as barras */
  #call.hide-ui .topbar { opacity: 0; transform: translateY(-100%); pointer-events: none; }
  #call.hide-ui .bar { opacity: 0; transform: translateY(100%); pointer-events: none; }
  #call.hide-ui .remote .name { bottom: calc(16px + var(--safe-b)); }
  #call.hide-ui .corner-br, #call.hide-ui .corner-bl { bottom: calc(16px + var(--safe-b)); }
  #call.hide-ui .corner-tr, #call.hide-ui .corner-tl { top: calc(16px + var(--safe-t)); }

  .panel {
    left: 0; right: 0; bottom: 0; top: auto; width: auto; max-height: 70dvh;
    border-radius: 16px 16px 0 0; padding-bottom: calc(20px + var(--safe-b)); z-index: 6;
  }
}

/* Celular deitado: barra mais baixa, quadro menor */
@media (max-height: 520px) and (orientation: landscape) {
  .bar { padding-top: 12px; padding-bottom: calc(8px + var(--safe-b)); }
  .bar .round { width: 48px; height: 48px; }
  .remote .name, .corner-br, .corner-bl { bottom: calc(76px + var(--safe-b)); }
  .self { width: 22vw; max-width: 180px; }
  .self.cam-portrait { width: 14vw; max-width: 110px; }
  .preview-box { aspect-ratio: 16 / 9; max-height: 70dvh; }
}

/* Avaliação na tela final */
.rating { margin-top: 36px; padding: 20px 28px; border: 1px solid #e8eaed; border-radius: 16px; }
.rating-q { margin: 0 0 10px !important; color: #3c4043 !important; font-size: 15px; }
.stars { display: flex; justify-content: center; gap: 6px; }
.stars button {
  background: none; font-size: 36px; line-height: 1; padding: 4px; color: #dadce0;
  transition: color .12s, transform .12s;
}
.stars button.on { color: #fbbc04; }
.stars button:active { transform: scale(.88); }
.stars.done button { pointer-events: none; }

/* ---------- Lobby: pedido de permissão explicado ---------- */
.preview-name { position: absolute; left: 16px; top: 14px; color: #fff; font-size: 14px; font-weight: 500; text-shadow: 0 1px 3px rgba(0,0,0,.6); }
.perm-ask {
  position: absolute; inset: 0; z-index: 2;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  padding: 24px; text-align: center; color: #e8eaed;
  background: radial-gradient(120% 90% at 50% 0%, #3c4043 0%, #202124 70%);
}
.perm-ask h2 { font-size: 20px; font-weight: 400; margin: 4px 0 0; max-width: 420px; line-height: 1.35; }
.perm-ask p { font-size: 14px; color: #bdc1c6; margin: 0 0 8px; max-width: 380px; line-height: 1.5; }
.perm-icons { display: flex; gap: 12px; }
.perm-icons span {
  width: 56px; height: 56px; border-radius: 50%; display: grid; place-items: center;
  background: rgba(138,180,248,.15); color: var(--blue);
}
.perm-icons svg { width: 28px; height: 28px; }
.text-btn { background: none; color: var(--blue); font-weight: 500; font-size: 14px; padding: 8px 12px; border-radius: 20px; }
.mini-avatar.online { position: relative; }
.mini-avatar.online::after {
  content: ''; position: absolute; right: -2px; bottom: -2px; width: 9px; height: 9px;
  border-radius: 50%; background: #1e8e3e; border: 2px solid #fff;
}

/* Botão com "carregando" */
.primary.loading { color: transparent; position: relative; pointer-events: none; }
.primary.loading::after {
  content: ''; position: absolute; inset: 0; margin: auto; width: 20px; height: 20px;
  border: 2.5px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%;
  animation: spin .8s linear infinite;
}

/* ---------- Indicador de volume (Meet) ---------- */
[data-toggle="mic"] { position: relative; }
.lvl {
  --lvl: 0;
  position: absolute; top: -3px; right: -3px; width: 20px; height: 20px; border-radius: 50%;
  background: #1a73e8; display: flex; align-items: center; justify-content: center; gap: 2px;
  opacity: 0; transform: scale(.6); transition: opacity .15s, transform .15s; pointer-events: none;
}
.lvl i { width: 3px; border-radius: 2px; background: #fff; height: calc(3px + var(--lvl) * 6px); transition: height .09s; }
.lvl i:nth-child(2) { height: calc(3px + var(--lvl) * 10px); }
[data-toggle="mic"]:not(.off) .lvl, .self.speaking .tile-lvl { opacity: 1; transform: scale(1); }
.tile-lvl { top: 8px; right: 8px; left: auto; z-index: 2; }

/* ---------- Entrada animada ---------- */
.remote video { opacity: 0; transition: opacity .7s ease; }
.remote.ready video { opacity: 1; }
.connecting { transition: opacity .6s ease; gap: 10px; }
.connecting.gone { opacity: 0; pointer-events: none; }
.connecting strong { color: #e8eaed; font-size: 20px; font-weight: 400; margin-top: 14px; }
.conn-text { font-size: 14px; }
.pulse { position: relative; width: 96px; height: 96px; }
.big-avatar {
  position: absolute; inset: 0; border-radius: 50%; background: #7b1fa2; color: #fff;
  display: grid; place-items: center; font-size: 40px;
}
.ring { position: absolute; inset: 0; border-radius: 50%; border: 2px solid rgba(138,180,248,.7); animation: ring 2s ease-out infinite; }
.ring.r2 { animation-delay: 1s; }
@keyframes ring { from { transform: scale(1); opacity: .9; } to { transform: scale(1.9); opacity: 0; } }

/* ---------- Aviso no rodapé ---------- */
.snack {
  position: absolute; left: 24px; bottom: 96px; z-index: 8;
  background: #323232; color: #fff; font-size: 14px; padding: 12px 18px; border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,.35); max-width: calc(100vw - 32px);
  opacity: 0; transform: translateY(12px); transition: opacity .2s, transform .2s; pointer-events: none;
}
.snack.show { opacity: 1; transform: none; }

/* ---------- Confirmação de saída (celular) ---------- */
.sheet-wrap {
  position: absolute; inset: 0; z-index: 12; background: rgba(0,0,0,.5);
  display: flex; align-items: flex-end; animation: fade .2s ease;
}
.sheet {
  width: 100%; background: #2d2e31; border-radius: 20px 20px 0 0;
  padding: 24px 20px calc(16px + var(--safe-b)); text-align: center; animation: up .25s ease;
}
.sheet h2 { margin: 0 0 8px; font-size: 20px; font-weight: 400; }
.sheet p { margin: 0 0 20px; color: #bdc1c6; font-size: 14px; line-height: 1.5; }
.sheet-btn { display: block; width: 100%; padding: 15px; border-radius: 28px; font-size: 16px; font-weight: 500; background: #3c4043; margin-top: 10px; }
.sheet-btn.danger { background: var(--red); }
@keyframes fade { from { opacity: 0; } }
@keyframes up { from { transform: translateY(100%); } }

@media (max-width: 820px), (max-height: 520px) {
  .snack { left: 50%; bottom: calc(112px + var(--safe-b)); transform: translate(-50%, 12px); white-space: nowrap; }
  .snack.show { transform: translate(-50%, 0); }
  #call.hide-ui .snack { bottom: calc(24px + var(--safe-b)); }
  .perm-ask h2 { font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) { .ring { animation: none; } }
