
:root {
  --bg: #070A12;                          
  --surface: #151925;                     
  --surface-glass: rgba(21, 25, 37, 0.88);
  --text: #F7F7F3;                        
  --muted: #939EB2;
  --accent: #173BFF;                      
  --accent-lift: #6E8BFF;                 
  --accent-dim: rgba(110, 139, 255, 0.18);
  --error: #FFC2CD;                       
  --border: #262D40;
  --toolbar-bg: rgba(7, 10, 18, 0.82);
  --toolbar-h: 72px;
  --safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
  --safe-left: var(--safe-area-inset-left, env(safe-area-inset-left, 0px));
  --safe-right: var(--safe-area-inset-right, env(safe-area-inset-right, 0px));
  --btn-size: 52px;
  --btn-size-mobile: 48px;
  --danger: #C41E3A;                      
  --warning: #E8B004;                     
  --success: #30C86F;                     
  --reaction-emoji-size: 36px;
  --reaction-emoji-size-mobile: 52px;
}
*, *::before, *::after { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  height: 100%;
  overscroll-behavior: none;
}
main.room {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;          
  padding-bottom: calc(var(--toolbar-h) + var(--safe-bottom));
  padding-top: var(--safe-top);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}
header {
  padding: 0.75rem 1rem 0.5rem;
}
h1 { font-size: 1.25rem; font-weight: 600; margin: 0 0 0.25rem; }
h2 { font-size: 1rem; font-weight: 500; margin: 1rem 0 0.5rem; color: var(--muted); }
.muted { color: var(--muted); }
.error { color: var(--error); }
#connection-status { font-size: 0.8rem; color: var(--muted); margin: 0; }
.tagline { font-size: 1.1rem; color: var(--muted); margin: 0 0 1.5rem; }
.splash { text-align: center; padding-top: 4rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 2rem; max-width: 420px; margin: 3rem auto; }
.card form { display: flex; flex-direction: column; gap: 1rem; }
.card label { display: flex; flex-direction: column; gap: 0.5rem; font-size: 0.9rem; color: var(--muted); }
.card input { min-height: 44px; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 0.75rem; border-radius: 8px; font-size: 1rem; }
.card input:focus { outline: none; border-color: var(--accent-lift); }
.card button { min-height: 44px; background: var(--accent); color: var(--text); border: none; padding: 0.85rem; border-radius: 8px; font-weight: 600; font-size: 1rem; cursor: pointer; transition: opacity 0.15s; }
.card button:hover { opacity: 0.9; }
.card button:disabled { opacity: 0.5; cursor: not-allowed; }
#notification-banner { padding: 10px; margin-bottom: 15px; border-radius: 4px; text-align: center; font-weight: 500; }
.video-grid {
  flex: 1;
  display: grid;
  --cols: 1;
  --cols-narrow: 1;
  --strip: 1;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: 0.75rem;
  padding: 0.75rem;
  align-content: start;
}
.video-grid.spotlight {
  grid-template-columns: repeat(var(--strip), minmax(0, 1fr));
}
.video-grid.spotlight .video-tile {
  order: 2;
  max-height: 120px;
}
.video-grid.spotlight .video-tile.spot {
  order: 1;
  grid-column: 1 / -1;
  max-height: none;
}
.waiting-tile[hidden] { display: none; }
.waiting-tile .tile-label { color: var(--muted); }
.video-tile {
  position: relative;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 12px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  transition: border-color 0.2s;
}
.video-tile video {
  width: 100%; height: 100%;
  object-fit: cover;
  background: #000;
  display: block;
}
.video-tile .avatar-canvas {
  position: absolute;
  inset: 0;
  width: 100%; height: 100%;
  background: var(--surface);
}
.video-tile .avatar-canvas[hidden] { display: none; }
.video-tile.speaking {
  border-color: var(--accent-lift);
  box-shadow: 0 0 0 2px var(--accent-dim);
  animation: speaking-pulse 1.2s ease-in-out infinite;
}
@keyframes speaking-pulse {
  0%, 100% { box-shadow: 0 0 0 2px var(--accent-dim); }
  50%       { box-shadow: 0 0 0 6px var(--accent-dim); }
}
.tile-label {
  position: absolute;
  bottom: 0.5rem; left: 0.5rem;
  background: rgba(7,10,18,0.7);
  backdrop-filter: blur(4px);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.82rem;
  max-width: calc(100% - 1rem);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
  pointer-events: none;
}
.seat-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}
.screen-mark {
  flex-shrink: 0;
  font-size: 0.72em;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
}
.screen-tile video { background: var(--bg); }
.guest-mark {
  flex-shrink: 0;
  font-size: 0.72em;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  background: var(--accent-dim);
  color: var(--accent-lift);
}
.tile-overlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.tile-overlays > * { pointer-events: auto; }
.tile-mute-badge {
  position: absolute;
  top: 0.5rem; right: 0.5rem;
  background: rgba(196, 30, 58, 0.85);
  border-radius: 50%;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  pointer-events: none;
}
.tile-mute-badge.hidden { display: none; }
.tile-hand-badge {
  position: absolute;
  top: calc(0.5rem + 9px); left: calc(0.5rem + 48px);
  background: var(--warning);
  border-radius: 50%;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  font-size: 14px;
  pointer-events: none;
}
.tile-hand-badge.hidden { display: none; }
.cam-off-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--surface);
  gap: 0.5rem;
}
.cam-off-placeholder.hidden { display: none; }
.cam-off-initials {
  width: 56px; height: 56px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem; font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.cam-off-name {
  font-size: 0.85rem;
  color: var(--muted);
  max-width: 90%;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.35rem;
  white-space: nowrap;
}
.tile-quality {
  position: absolute;
  bottom: 0.5rem; right: 0.5rem;
  display: flex; align-items: flex-end; gap: 2px;
  pointer-events: none;
}
.tile-quality .bar {
  width: 4px;
  background: var(--muted);
  border-radius: 2px;
  transition: background 0.4s;
}
.tile-quality .bar:nth-child(1) { height: 6px; }
.tile-quality .bar:nth-child(2) { height: 10px; }
.tile-quality .bar:nth-child(3) { height: 14px; }
.tile-quality.good .bar   { background: var(--success); }
.tile-quality.fair .bar:nth-child(1),
.tile-quality.fair .bar:nth-child(2) { background: var(--warning); }
.tile-quality.poor .bar:nth-child(1) { background: var(--danger); }
.tile-pin-btn {
  position: absolute;
  top: 0.5rem; left: 0.5rem;
  min-width: 44px; min-height: 44px;
  background: rgba(21,25,37,0.75);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  padding: 3px 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s;
}
.video-tile:hover .tile-pin-btn,
.video-tile.pinned .tile-pin-btn { opacity: 1; }
@media (pointer: coarse) { .tile-pin-btn { opacity: 1; } }
.video-tile.pinned .tile-pin-btn { background: var(--accent); color: var(--text); }
.tile-reaction-container {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}
.reaction-float {
  position: absolute;
  bottom: 20%;
  left: 50%;
  transform: translateX(-50%);
  font-size: 2rem;
  animation: reaction-rise 2s ease-out forwards;
  pointer-events: none;
}
@keyframes reaction-rise {
  0%   { opacity: 1; transform: translateX(-50%) translateY(0) scale(1); }
  70%  { opacity: 1; transform: translateX(-50%) translateY(-80px) scale(1.2); }
  100% { opacity: 0; transform: translateX(-50%) translateY(-130px) scale(0.9); }
}
.zoom-btn {
  position: absolute;
  top: 0.5rem; left: 50%;
  transform: translateX(-50%);
  white-space: nowrap;
  background: rgba(7,10,18,0.7);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  min-height: 44px;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}
.zoom-btn:hover { background: rgba(21,25,37,0.9); }
.zoom-btn.zoomed { background: var(--accent); color: var(--text); border-color: var(--accent-lift); }
.participants { padding: 0 1rem 1rem; }
.participants ul { list-style: none; padding: 0; margin: 0; }
.participants li { padding: 0.5rem 0; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.participants li:has(.remove-seat) { display: flex; align-items: center; gap: 0.5rem; }
.remove-seat {
  margin-left: auto;
  min-height: 44px;
  min-width: 44px;
  padding: 0 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}
.remove-seat:hover, .remove-seat:focus-visible { color: inherit; border-color: currentColor; }
.call-toolbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--toolbar-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--toolbar-bg);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  z-index: 1000;
  transition: opacity 0.3s, transform 0.3s;
}
.call-toolbar.toolbar-hidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}
.tb-btn {
  width: var(--btn-size);
  height: var(--btn-size);
  min-width: 44px;
  min-height: 44px;       
  border-radius: 50%;
  border: 2px solid transparent;
  background: rgba(255,255,255,0.08);
  color: var(--text);
  font-size: 1.3rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  flex-shrink: 0;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;  
}
.tb-btn:hover  { background: rgba(255,255,255,0.14); }
.tb-btn:active { transform: scale(0.93); }
.tb-btn.btn-muted {
  background: rgba(196, 30, 58, 0.22);
  border-color: var(--error);
  color: var(--error);
}
.tb-btn.btn-active {
  background: var(--accent-dim);
  border-color: var(--accent-lift);
  color: var(--accent-lift);
}
.tb-btn.tb-btn--danger {
  background: rgba(196, 30, 58, 0.2);
  border-color: var(--error);
  color: var(--error);
}
.tb-btn.tb-btn--danger:hover {
  background: rgba(196, 30, 58, 0.36);
}
.tb-btn[data-label]::after {
  content: attr(data-label);
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  color: var(--text);
  font-size: 0.72rem;
  padding: 3px 8px;
  border-radius: 5px;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
  border: 1px solid var(--border);
}
.tb-btn[data-label]:hover::after { opacity: 1; }
#dev-hud-btn {
  position: fixed;
  bottom: calc(var(--toolbar-h) + var(--safe-bottom) + 8px);
  right: 10px;
  z-index: 9998;
  background: rgba(0,0,0,0.5);
  color: white;
  border: none;
  padding: 5px 10px;
  min-height: 44px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}
.desktop-secondary { display: flex; }
.mobile-only       { display: none; }
@media (max-width: 480px) {
  .desktop-secondary { display: none; }   
  .mobile-only       { display: flex; }   
  .call-toolbar {
    gap: 0.5rem;
    justify-content: space-evenly;
  }
  .tb-btn {
    width: var(--btn-size-mobile);
    height: var(--btn-size-mobile);
  }
}
@media (min-width: 480px) and (max-width: 1024px) {
  .mobile-only { display: none; }
}
@media (pointer: coarse) {
  .call-toolbar.toolbar-hidden {
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
  }
}
.reaction-popover {
  position: fixed;
  bottom: calc(var(--toolbar-h) + var(--safe-bottom) + 12px);
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 10px 14px;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  max-width: min(92vw, 520px);
  gap: 10px;
  z-index: 1100;
  opacity: 0;
  transform: translateY(8px) scale(0.95);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
}
.reaction-popover.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.reaction-popover button {
  background: none; border: none; cursor: pointer;
  font-size: var(--reaction-emoji-size);
  width: 52px; height: 52px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}
.reaction-popover button:hover { background: var(--accent-dim); transform: scale(1.15); }
.reaction-sheet {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--border);
  border-radius: 20px 20px 0 0;
  padding: 12px 20px calc(16px + var(--safe-bottom));
  z-index: 1200;
  transform: translateY(100%);
  transition: transform 0.28s cubic-bezier(0.32, 0.72, 0, 1);
  touch-action: pan-y;
}
.reaction-sheet.open {
  transform: translateY(0);
}
.reaction-sheet-handle {
  width: 40px; height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 0 auto 14px;
}
.reaction-sheet-label {
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 12px;
}
.reaction-sheet-emojis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  justify-items: center;
  gap: 8px;
}
.reaction-sheet button {
  background: none; border: none; cursor: pointer;
  font-size: var(--reaction-emoji-size-mobile);
  min-width: 60px; min-height: 60px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.reaction-sheet button:active { background: var(--accent-dim); }
.overflow-menu {
  position: fixed;
  bottom: calc(var(--toolbar-h) + var(--safe-bottom) + 8px);
  right: 16px;
  background: var(--surface-glass);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 1100;
  opacity: 0;
  transform: translateY(8px) scale(0.96);
  pointer-events: none;
  transition: opacity 0.18s, transform 0.18s;
  min-width: 180px;
}
.overflow-menu.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
.overflow-menu button {
  background: none; border: none; cursor: pointer;
  color: var(--text);
  padding: 10px 14px;
  min-height: 44px;
  border-radius: 9px;
  text-align: left;
  font-size: 0.9rem;
  display: flex; align-items: center; gap: 10px;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}
.overflow-menu button:hover { background: rgba(255,255,255,0.07); }
.overflow-menu button.active { color: var(--accent-lift); }
.overflow-menu button[hidden], .overflow-menu input[hidden] { display: none; }
.invite-link {
  margin: 2px 6px 6px;
  padding: 8px 10px;
  min-height: 44px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--text);
  font-size: 0.8rem;
  width: calc(100% - 12px);
  box-sizing: border-box;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-backdrop.open {
  opacity: 1;
  pointer-events: auto;
}
.leave-modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 1.75rem 2rem;
  max-width: 340px;
  width: calc(100vw - 40px);
  text-align: center;
  transform: scale(0.94);
  transition: transform 0.2s;
}
.modal-backdrop.open .leave-modal { transform: scale(1); }
.leave-modal h2 { font-size: 1.1rem; font-weight: 600; margin: 0 0 0.5rem; }
.leave-modal p  { font-size: 0.9rem; color: var(--muted); margin: 0 0 1.5rem; }
.leave-modal-actions {
  display: flex; gap: 0.75rem; justify-content: center;
}
.leave-modal-actions button {
  flex: 1;
  border: none;
  border-radius: 10px;
  padding: 0.75rem;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.15s;
  min-height: 44px;
}
.leave-modal-actions button:hover { opacity: 0.87; }
.leave-modal-actions .btn-cancel {
  min-height: 44px;
  background: rgba(255,255,255,0.08);
  color: var(--text);
}
.leave-modal-actions .btn-leave {
  min-height: 44px;
  background: var(--danger);
  color: #fff;
}
#dev-hud {
  position: fixed;
  top: 10px; right: 10px;
  background: rgba(0,0,0,0.85);
  color: #0f0;
  font-family: monospace;
  padding: 10px;
  z-index: 9999;
  display: none;
  max-width: 400px;
  font-size: 12px;
  border: 1px solid #0f0;
  line-height: 1.4;
  border-radius: 6px;
  max-height: 80vh;
  overflow-y: auto;
}
@media (max-width: 480px) {
  main.room > header { padding: 0.5rem 0.75rem 0.25rem; }
  h1 { font-size: 1rem; }
  .video-grid { grid-template-columns: repeat(var(--cols-narrow), minmax(0, 1fr)); gap: 0.5rem; padding: 0.5rem; }
  .cam-off-initials { width: 44px; height: 44px; font-size: 1.1rem; }
}
@media (min-width: 1025px) {
  .video-grid { max-width: 1200px; margin: 0 auto; }
}