
:root {
  --bg:#1c1425;
  --surface:#2a2035;
  --surface2:#342741;
  --line:#44355a;
  --text:#f4efe6;
  --muted:#b7a9c8;
  --accent:#f2c14e;
  --accent-ink:#2a1d05;
  --danger:#ff9b9b;
  font-family:"Bricolage Grotesque",system-ui,-apple-system,"Segoe UI",sans-serif;
}

* {
  box-sizing:border-box;
}

html,
body {
  height:100%;
}

body {
  margin:0;
  background:var(--bg);
  color:var(--text);
  line-height:1.5;
}

[hidden] {
  display:none!important;
}

button,
input {
  font:inherit;
}

.beam {
  position:fixed;
  inset:0;
  pointer-events:none;
  background:linear-gradient(to bottom left,rgba(242,193,78,.18),transparent 70%);
  clip-path:polygon(100% 0,78% 100%,18% 100%);
}

.btn {
  font-weight:600;
  color:var(--text);
  padding:.65em 1.15em;
  border-radius:999px;
  cursor:pointer;
  background:var(--surface);
  border:1px solid var(--line);
  transition:.18s;
}

.btn:hover:not(:disabled) {
  border-color:var(--muted);
  transform:translateY(-1px);
}

.btn:disabled {
  opacity:.45;
  cursor:not-allowed;
}

.btn.primary {
  background:var(--accent);
  border-color:var(--accent);
  color:var(--accent-ink);
}

.btn.danger {
  background:transparent;
  border-color:var(--danger);
  color:var(--danger);
}

.btn.small {
  padding:.48em .85em;
  font-size:.88rem;
}

:focus-visible {
  outline:3px solid var(--accent);
  outline-offset:3px;
}

.home {
  position:relative;
  max-width:650px;
  margin:0 auto;
  padding:12vh 24px 48px;
}

.home-brand {
  font-weight:800;
  font-size:1.2rem;
  margin-bottom:50px;
}

.home-brand span {
  color:var(--accent);
}

.home h1 {
  margin:0 0 16px;
  font-size:clamp(2.6rem,9vw,4.75rem);
  font-weight:800;
  line-height:1.02;
  letter-spacing:-.03em;
}

.lead {
  margin:0 0 28px;
  max-width:46ch;
  font-size:1.1rem;
  color:var(--muted);
}

.join {
  margin-top:48px;
  max-width:440px;
}

.join label {
  display:block;
  margin-bottom:8px;
  color:var(--muted);
}

.join-row {
  display:flex;
  gap:8px;
}

.join-row input,
.youtube-form input,
.chat-form input {
  min-width:0;
  color:var(--text);
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:10px;
  padding:.7em .9em;
}

.join-row input {
  flex:1;
}

.room {
  position:relative;
  max-width:1600px;
  margin:0 auto;
  padding:14px;
  min-height:100dvh;
  display:flex;
  flex-direction:column;
  gap:12px;
}

.bar {
  display:flex;
  align-items:center;
  gap:14px;
  min-height:42px;
}

.brand {
  font-weight:800;
  font-size:1.15rem;
  color:var(--text);
  text-decoration:none;
  margin-right:auto;
}

.presence {
  font-size:.9rem;
  color:var(--muted);
}

.workspace {
  display:grid;
  grid-template-columns:minmax(0,1fr) 285px;
  gap:12px;
  flex:1;
  min-height:0;
}

.watch-area {
  min-width:0;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.stage {
  position:relative;
  min-height:300px;
  flex:1;
  overflow:hidden;
  background:#0e0a14;
  border:1px solid var(--line);
  border-radius:13px;
  isolation:isolate;
}

.stage>video {
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  object-fit:contain;
  background:#000;
  z-index:1;
}

.youtube-player {
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  z-index:3;
  background:#000;
  display:none;
  overflow:hidden;
}

#youtube-frame,
#youtube-frame iframe {
  position:absolute;
  inset:0;
  width:100%!important;
  height:100%!important;
  border:0;
  display:block;
}

.overlay {
  position:absolute;
  inset:0;
  z-index:4;
  display:grid;
  place-items:center;
  padding:24px;
  text-align:center;
  color:var(--muted);
  background:#0e0a14;
}

.overlay p {
  margin:0;
  max-width:34ch;
  font-size:1.05rem;
}

.badge {
  position:absolute;
  top:12px;
  left:12px;
  z-index:7;
  padding:.3em .8em;
  border-radius:999px;
  font-size:.85rem;
  background:rgba(28,20,37,.86);
  border:1px solid var(--line);
}

.camera-layer {
  position:absolute;
  inset:0;
  z-index:5;
  pointer-events:none;
}

.camera-tile {
  position:absolute;
  left:var(--x,16px);
  top:var(--y,16px);
  width:var(--w,150px);
  aspect-ratio:4/3;
  min-width:76px;
  min-height:57px;
  max-width:55%;
  overflow:visible;
  pointer-events:auto;
  touch-action:none;
  user-select:none;
  -webkit-user-select:none;
}

.camera-tile .camera-video-wrap {
  position:absolute;
  inset:0;
  overflow:hidden;
  border:2px solid rgba(244,239,230,.75);
  border-radius:12px;
  background:#17101f;
  box-shadow:0 5px 22px #0008;
}

.camera-tile.round .camera-video-wrap {
  border-radius:50%;
  aspect-ratio:1;
}

.camera-tile video {
  width:100%;
  height:100%;
  object-fit:cover;
  display:block;
}

.camera-name {
  position:absolute;
  left:5px;
  right:5px;
  bottom:5px;
  z-index:2;
  padding:2px 5px;
  border-radius:6px;
  background:#1c1425c9;
  color:var(--text);
  font-size:11px;
  text-align:center;
  overflow:hidden;
  text-overflow:ellipsis;
  white-space:nowrap;
  pointer-events:none;
}

.camera-tile.selected {
  outline:2px solid var(--accent);
  outline-offset:4px;
}

.camera-tile .resize-handle {
  position:absolute;
  right:-7px;
  bottom:-7px;
  width:20px;
  height:20px;
  border-radius:50%;
  background:var(--accent);
  border:2px solid var(--bg);
  z-index:4;
  cursor:nwse-resize;
  touch-action:none;
  padding:0;
}

.camera-tile .move-hint {
  display:none;
  position:absolute;
  top:-25px;
  left:0;
  background:#1c1425e8;
  padding:2px 7px;
  border-radius:5px;
  color:var(--text);
  font-size:10px;
  white-space:nowrap;
}

.camera-tile.selected .move-hint {
  display:block;
}

.camera-tools {
  display:flex;
  justify-content:flex-end;
  gap:6px;
  margin-top:5px;
}

.camera-tools button {
  font-size:11px;
  padding:3px 7px;
  border-radius:6px;
  background:var(--surface);
  color:var(--text);
  border:1px solid var(--line);
}

.youtube-tools {
  padding:10px;
  background:var(--surface);
  border:1px solid var(--line);
  border-radius:12px;
}

.youtube-form {
  display:flex;
  gap:8px;
}

.youtube-form input {
  flex:1;
}

.player-controls {
  display:flex;
  align-items:center;
  gap:8px;
  margin-top:9px;
}

.yt-time {
  font-size:12px;
  color:var(--muted);
  font-variant-numeric:tabular-nums;
  min-width:42px;
}

#yt-seek {
  flex:1;
  min-width:40px;
  accent-color:var(--accent);
}

.controls {
  display:flex;
  flex-wrap:wrap;
  gap:8px;
  align-items:center;
}

/* Microfone e controles de câmera */

#microphone-toggle,
#camera-toggle,
#camera-audio {
  white-space:nowrap;
}

/* Botão de tela cheia */

#fullscreen {
  white-space:nowrap;
}

/* Conversa */

.chat {
  display:flex;
  flex-direction:column;
  min-height:300px;
  max-height:calc(100dvh - 82px);
  background:rgba(42,32,53,.92);
  border:1px solid var(--line);
  border-radius:13px;
  overflow:hidden;
}

.chat-header {
  display:flex;
  justify-content:space-between;
  align-items:center;
  padding:13px 14px;
  border-bottom:1px solid var(--line);
}

.chat-header strong {
  display:block;
}

.chat-header span {
  display:block;
  font-size:11px;
  color:var(--muted);
}

.icon-btn {
  border:0;
  background:transparent;
  color:var(--muted);
  font-size:24px;
  cursor:pointer;
}

.messages {
  flex:1;
  overflow-y:auto;
  padding:12px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

.message {
  max-width:95%;
  overflow-wrap:anywhere;
}

.message.mine {
  align-self:flex-end;
  text-align:right;
}

.message-meta {
  display:flex;
  gap:7px;
  align-items:baseline;
  color:var(--muted);
  font-size:11px;
  margin:0 3px 3px;
}

.message.mine .message-meta {
  justify-content:flex-end;
}

.message-bubble {
  display:inline-block;
  padding:8px 11px;
  border-radius:12px;
  background:#3a2c48;
  color:var(--text);
  text-align:left;
  font-size:13px;
  white-space:pre-wrap;
}

.message.mine .message-bubble {
  background:#59452b;
  color:#fff4d8;
}

.chat-form {
  display:flex;
  gap:7px;
  padding:10px;
  border-top:1px solid var(--line);
}

.chat-form input {
  flex:1;
  width:0;
  font-size:13px;
}

.send-btn {
  width:40px;
  border:0;
  border-radius:10px;
  background:var(--accent);
  color:var(--accent-ink);
  font-weight:800;
  cursor:pointer;
}

.chat-open {
  display:none;
  position:fixed;
  right:15px;
  bottom:15px;
  z-index:12;
  border:1px solid var(--line);
  border-radius:999px;
  padding:11px 17px;
  background:var(--accent);
  color:var(--accent-ink);
  font-weight:700;
}

.toast {
  position:fixed;
  left:50%;
  bottom:24px;
  z-index:30;
  transform:translate(-50%,16px);
  max-width:min(90vw,440px);
  padding:.7em 1.2em;
  border-radius:10px;
  background:var(--surface);
  border:1px solid var(--line);
  opacity:0;
  pointer-events:none;
  transition:opacity .2s,transform .2s;
}

.toast.show {
  opacity:1;
  transform:translate(-50%,0);
}

/* Tela cheia */

#stage:fullscreen,
#stage:-webkit-full-screen {
  position:fixed!important;
  inset:0!important;
  z-index:9999!important;
  width:100vw!important;
  height:100vh!important;
  height:100dvh!important;
  min-width:100vw!important;
  min-height:100vh!important;
  min-height:100dvh!important;
  max-width:none!important;
  max-height:none!important;
  flex:none!important;
  aspect-ratio:auto!important;
  margin:0!important;
  padding:0!important;
  border:0!important;
  border-radius:0!important;
  background:#000!important;
  overflow:hidden!important;
}

#stage:fullscreen>video,
#stage:-webkit-full-screen>video {
  position:absolute;
  inset:0;
  width:100%!important;
  height:100%!important;
  object-fit:contain;
}

#stage:fullscreen .youtube-player,
#stage:-webkit-full-screen .youtube-player {
  position:absolute;
  inset:0;
  width:100%!important;
  height:100%!important;
}

#stage:fullscreen #youtube-frame,
#stage:-webkit-full-screen #youtube-frame,
#stage:fullscreen #youtube-frame iframe,
#stage:-webkit-full-screen #youtube-frame iframe {
  width:100%!important;
  height:100%!important;
}

#stage:fullscreen .camera-layer,
#stage:-webkit-full-screen .camera-layer {
  position:absolute;
  inset:0;
  width:100%;
  height:100%;
  pointer-events:none;
}

#stage:fullscreen .camera-tile,
#stage:-webkit-full-screen .camera-tile {
  pointer-events:auto;
}

#stage:fullscreen .overlay,
#stage:-webkit-full-screen .overlay {
  position:absolute;
  inset:0;
}


/* Balões de mensagem (celular na horizontal ou tela cheia) */

.chat-notices {
  position:fixed;
  right:12px;
  bottom:68px;
  z-index:10000;
  display:flex;
  flex-direction:column;
  justify-content:flex-end;
  align-items:flex-end;
  gap:6px;
  width:min(300px,70vw);
  pointer-events:none;
}

.chat-notice {
  max-width:100%;
  padding:8px 11px;
  border-radius:12px;
  background:#3a2c48;
  color:var(--text);
  font-size:13px;
  overflow-wrap:anywhere;
  box-shadow:0 4px 18px #0008;
  animation:notice-in .25s ease-out;
  transition:opacity .4s,transform .4s;
}

.chat-notice strong {
  display:block;
  font-size:11px;
  color:var(--muted);
  margin-bottom:2px;
}

.chat-notice.fade-out {
  opacity:0;
  transform:translateY(-6px);
}

@keyframes notice-in {
  from { opacity:0; transform:translateY(10px); }
  to { opacity:1; transform:none; }
}

/* Tela cheia simulada (iPhone/Safari) */

body.pseudo-fs {
  overflow:hidden;
}

body.pseudo-fs .room {
  padding:0;
}

body.pseudo-fs #stage {
  position:fixed!important;
  inset:0!important;
  z-index:9000!important;
  width:100vw!important;
  height:100vh!important;
  height:100dvh!important;
  min-height:0!important;
  max-width:none!important;
  aspect-ratio:auto!important;
  margin:0!important;
  border:0!important;
  border-radius:0!important;
  background:#000!important;
}

body.pseudo-fs .chat {
  position:fixed;
  z-index:10002;
  right:12px;
  bottom:68px;
  width:min(340px,calc(100vw - 24px));
  height:min(62dvh,520px);
  min-height:0;
  max-height:calc(100dvh - 80px);
  box-shadow:0 12px 45px #0009;
  display:none;
}

body.pseudo-fs .chat.open {
  display:flex;
}

body.pseudo-fs .chat-open {
  display:block;
  z-index:10001;
}

body.pseudo-fs .toast {
  z-index:10010;
}

.fs-bar {
  position:absolute;
  top:10px;
  left:10px;
  z-index:20;
  display:flex;
  gap:6px;
  flex-wrap:wrap;
  padding-top:env(safe-area-inset-top,0px);
}

.fs-bar {
  transition:opacity .3s;
}

.fs-bar.idle {
  opacity:0;
  pointer-events:none;
}

.fs-bar[hidden] {
  display:none;
}

.fs-bar button {
  border:1px solid var(--line);
  border-radius:999px;
  padding:.5em .9em;
  background:rgba(42,32,53,.85);
  color:var(--text);
  font-size:12px;
  font-weight:600;
}

/* Responsividade */

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

  .chat {
    position:fixed;
    z-index:15;
    right:12px;
    bottom:68px;
    width:min(340px,calc(100vw - 24px));
    height:min(62dvh,520px);
    min-height:260px;
    box-shadow:0 12px 45px #0009;
    display:none;
  }

  .chat.open {
    display:flex;
  }

  .chat-open {
    display:block;
  }

  .stage {
    min-height:260px;
    flex:initial;
    aspect-ratio:16/9;
  }

  .room {
    /* espaço para o botão flutuante da conversa não cobrir os controles */
    padding:10px 10px 72px;
  }
}

@media(max-width:520px) {
  .bar {
    gap:8px;
  }

  .presence {
    font-size:12px;
  }

  .controls {
    gap:7px;
  }

  .controls .btn {
    flex:1 1 auto;
    min-width:0;
    font-size:12px;
    padding:.65em .7em;
  }

  .youtube-form {
    flex-wrap:wrap;
  }

  .youtube-form input {
    flex-basis:100%;
  }

  .player-controls {
    gap:5px;
  }

  .player-controls .btn {
    padding:.4em .6em;
  }

  /* Mantém a largura controlada pelo JavaScript. */

  .camera-tile {
    width:var(--w,145px);
    max-width:55%;
  }

  .camera-tile .resize-handle {
    width:26px;
    height:26px;
    right:-10px;
    bottom:-10px;
  }

  .camera-tile .move-hint {
    font-size:9px;
  }

  .toast {
    bottom:18px;
    font-size:13px;
  }
}

@media(prefers-reduced-motion:reduce) {
  * {
    transition:none!important;
  }
}

/* App instalado (PWA) e telas com notch */

.install-hint {
  max-width:320px;
  margin:10px auto 0;
  font-size:13px;
  line-height:1.4;
  color:var(--muted);
  text-align:center;
}

.home #install {
  margin-top:14px;
}

@media(max-width:850px) {
  .room {
    padding-top:calc(10px + env(safe-area-inset-top,0px));
    padding-bottom:calc(72px + env(safe-area-inset-bottom,0px));
    padding-left:calc(10px + env(safe-area-inset-left,0px));
    padding-right:calc(10px + env(safe-area-inset-right,0px));
  }

  .chat-open {
    bottom:calc(15px + env(safe-area-inset-bottom,0px));
    right:calc(15px + env(safe-area-inset-right,0px));
  }
}

.home {
  padding-top:calc(12vh + env(safe-area-inset-top,0px));
  padding-bottom:calc(48px + env(safe-area-inset-bottom,0px));
}

.build-room {
  position:fixed;
  left:8px;
  bottom:4px;
  font-size:10px;
  color:var(--muted);
  opacity:.45;
  pointer-events:none;
}
