/* ============================================================
   Century Meet — Room Stylesheet
   UTF-8, clean rewrite (previous file had UTF-16LE corruption)

   Breakpoints:
     mobile portrait  : < 480px
     tablet/landscape : 480px – 1024px
     desktop          : > 1024px

   Safe-area insets used throughout for iOS home indicator / notch.
   ============================================================ */

/* ── Design Tokens ─────────────────────────────────────────── */
:root {
  --bg: #0b0f1a;
  --surface: #151b2b;
  --surface-glass: rgba(21, 27, 43, 0.88);
  --text: #e8ecf4;
  --muted: #8a93a8;
  --accent: #4da3ff;
  --accent-dim: rgba(77, 163, 255, 0.18);
  --error: #ff6b6b;
  --border: #252d42;
  --toolbar-bg: rgba(10, 13, 24, 0.82);
  --toolbar-h: 72px;
  --btn-size: 52px;
  --btn-size-mobile: 48px;
  --danger: #e53e3e;
  --warning: #f6ad55;
  --success: #48bb78;
  --reaction-emoji-size: 36px;
  --reaction-emoji-size-mobile: 52px;
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::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%;
  /* Prevent rubber-band scroll behind the fixed toolbar on iOS */
  overscroll-behavior: none;
}

/* ── Room layout ────────────────────────────────────────────── */
main.room {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;          /* dvh: respects address bar on mobile */
  /* Bottom padding = toolbar height + iOS safe area */
  padding-bottom: calc(var(--toolbar-h) + env(safe-area-inset-bottom));
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-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; }

/* ── Cards (invite / claim pages) ──────────────────────────── */
.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 { 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); }
.card button { background: var(--accent); color: #0b0f1a; 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 — Gallery layout (default) ──────────────────── */
.video-grid {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  padding: 0.75rem;
  align-content: start;
}

/* ── Video grid — Spotlight layout ─────────────────────────── */
.video-grid.spotlight {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr auto;
}
.video-grid.spotlight .video-tile:first-child {
  /* Local tile moves to the strip below the spotlight */
  order: 2;
  max-height: 120px;
}
/* Pinned tile occupies the large slot */
.video-grid.spotlight .video-tile.pinned,
.video-grid.spotlight .video-tile.remote:not(.pinned) {
  order: 1;
}
.video-grid.spotlight .video-tile.pinned {
  grid-row: 1;
}

/* Horizontal strip below spotlight on mobile */
@media (max-width: 480px) {
  .video-grid.spotlight {
    grid-template-columns: 1fr;
  }
  /* Strip tiles wrap horizontally */
  .video-grid.spotlight .video-tile:not(.pinned):not(.remote) {
    max-width: 100px;
    min-height: 60px;
  }
}

/* ── Video tile ─────────────────────────────────────────────── */
.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;
}
/* Speaking ring — pulsing accent border */
.video-tile.speaking {
  border-color: var(--accent);
  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 labels & overlays ─────────────────────────────────── */
.tile-label {
  position: absolute;
  bottom: 0.5rem; left: 0.5rem;
  background: rgba(11,15,26,0.7);
  backdrop-filter: blur(4px);
  padding: 0.2rem 0.5rem;
  border-radius: 6px;
  font-size: 0.82rem;
  max-width: calc(100% - 1rem);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  pointer-events: none;
}

.tile-overlays {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.tile-overlays > * { pointer-events: auto; }

/* Mute badge — top-right corner of tile */
.tile-mute-badge {
  position: absolute;
  top: 0.5rem; right: 0.5rem;
  background: rgba(229, 62, 62, 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; }

/* Hand-raise badge — top-left corner of tile */
.tile-hand-badge {
  position: absolute;
  top: 0.5rem; left: 0.5rem;
  background: rgba(246, 173, 85, 0.9);
  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; }

/* Camera-off placeholder */
.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%;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Quality bars */
.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(--error); }

/* Pin button — shows on hover (desktop), always visible when pinned */
.tile-pin-btn {
  position: absolute;
  top: 0.5rem; left: 0.5rem;
  background: rgba(21,27,43,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; }
.video-tile.pinned .tile-pin-btn { background: var(--accent); color: #0b0f1a; }

/* Reaction float — ephemeral animated emoji over a tile */
.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); }
}

/* ── Vitals panel ───────────────────────────────────────────── */
.vitals-panel {
  position: absolute;
  top: 0.5rem; right: 0.5rem;
  background: rgba(11,15,26,0.85);
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  backdrop-filter: blur(4px);
  min-width: 80px;
}
.vital-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 0.25rem;
}
.vital-row:last-child { margin-bottom: 0; }
.vital-label { color: var(--muted); font-weight: 500; margin-right: 0.75rem; }
.vital-value { font-family: monospace; font-weight: 600; font-size: 0.95rem; }
#vitals-hr  { color: #ff6b6b; }
#vitals-spo2 { color: var(--accent); }
#vitals-rr  { color: #f5d76e; }

/* ── Zoom (detail tier) button ──────────────────────────────── */
.zoom-btn {
  position: absolute;
  top: 0.5rem; left: 0.5rem;
  background: rgba(11,15,26,0.7);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 0.35rem 0.65rem;
  border-radius: 6px;
  font-size: 0.8rem;
  cursor: pointer;
}
.zoom-btn:hover { background: rgba(21,27,43,0.9); }
.zoom-btn.zoomed { background: var(--accent); color: #0b0f1a; border-color: var(--accent); }

/* ── Participants list ──────────────────────────────────────── */
.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; }

/* ── Call Toolbar ───────────────────────────────────────────── */
.call-toolbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--toolbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-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;
}

/* Desktop auto-hide: JS adds .toolbar-hidden on inactivity */
.call-toolbar.toolbar-hidden {
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
}

/* ── Toolbar buttons ────────────────────────────────────────── */
.tb-btn {
  width: var(--btn-size);
  height: var(--btn-size);
  min-width: 44px;
  min-height: 44px;       /* Apple HIG / Material minimum tap target */
  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;  /* Prevent 300ms tap delay */
}
.tb-btn:hover  { background: rgba(255,255,255,0.14); }
.tb-btn:active { transform: scale(0.93); }

/* Muted state */
.tb-btn.btn-muted {
  background: rgba(229, 62, 62, 0.22);
  border-color: var(--error);
  color: var(--error);
}

/* Active (on) state — hand raised, detail tier, etc. */
.tb-btn.btn-active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: var(--accent);
}

/* Danger (leave) button */
.tb-btn.tb-btn--danger {
  background: rgba(229, 62, 62, 0.2);
  border-color: var(--error);
  color: var(--error);
}
.tb-btn.tb-btn--danger:hover {
  background: rgba(229, 62, 62, 0.36);
}

/* Tooltip on hover (desktop) */
.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 toggle button (legacy — keep for compatibility) */
#dev-hud-btn {
  position: fixed;
  bottom: calc(var(--toolbar-h) + env(safe-area-inset-bottom) + 8px);
  right: 10px;
  z-index: 9998;
  background: rgba(0,0,0,0.5);
  color: white;
  border: none;
  padding: 5px 10px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
}

/* ── Narrow viewport: hide secondary controls into overflow ── */
.desktop-secondary { display: flex; }
.mobile-only       { display: none; }

@media (max-width: 480px) {
  .desktop-secondary { display: none; }   /* Hand raise, view toggle */
  .mobile-only       { display: flex; }   /* Flip camera */
  .call-toolbar {
    gap: 0.5rem;
    justify-content: space-evenly;
  }
  .tb-btn {
    width: var(--btn-size-mobile);
    height: var(--btn-size-mobile);
  }
}

/* Tablet/landscape: all controls visible */
@media (min-width: 480px) and (max-width: 1024px) {
  .mobile-only { display: none; }
}

/* On touch-primary devices (mobile/tablet), NEVER auto-hide toolbar */
@media (pointer: coarse) {
  .call-toolbar.toolbar-hidden {
    opacity: 1 !important;
    transform: none !important;
    pointer-events: auto !important;
  }
}

/* ── Reaction popover (desktop, above btn-react) ─────────────── */
.reaction-popover {
  position: fixed;
  bottom: calc(var(--toolbar-h) + env(safe-area-inset-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;
  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 bottom sheet (mobile) ─────────────────────────── */
.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 + env(safe-area-inset-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: flex;
  justify-content: space-around;
  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 ───────────────────────────────────────────── */
.overflow-menu {
  position: fixed;
  bottom: calc(var(--toolbar-h) + env(safe-area-inset-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;
  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); }

/* ── Leave confirmation modal ─────────────────────────────────── */
.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 {
  background: rgba(255,255,255,0.08);
  color: var(--text);
}
.leave-modal-actions .btn-leave {
  background: var(--danger);
  color: #fff;
}

/* ── Dev HUD overlay ─────────────────────────────────────────── */
#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 queries ───────────────────────────────────────────── */
@media (max-width: 480px) {
  main.room > header { padding: 0.5rem 0.75rem 0.25rem; }
  h1 { font-size: 1rem; }
  .video-grid { grid-template-columns: 1fr; gap: 0.5rem; padding: 0.5rem; }
  .vitals-panel { font-size: 0.75rem; padding: 0.35rem 0.5rem; }
  .cam-off-initials { width: 44px; height: 44px; font-size: 1.1rem; }
}

@media (min-width: 481px) and (max-width: 1024px) {
  .video-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 1025px) {
  .video-grid { grid-template-columns: 1fr 1fr; max-width: 1200px; margin: 0 auto; }
}