/* StreamLink UI — dark theme, mobile-first responsive. */

:root {
  --bg: #0f1115;
  --surface: #1a1d24;
  --surface-2: #232733;
  --border: #313747;
  --text: #e8eaf0;
  --muted: #9aa1b2;
  --primary: #3b82f6;
  --primary-hover: #2f6fe0;
  --danger: #ef4444;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.85rem; }
.error { color: var(--danger); font-size: 0.9rem; }

/* ---------- buttons & inputs ---------- */
.btn {
  display: inline-block;
  padding: 0.7rem 1.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-size: 1rem;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.15s;
}
.btn:hover { background: var(--border); }
.btn.primary { background: var(--primary); border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-hover); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost { padding: 0.7rem 0.9rem; }

input[type="text"] {
  width: 100%;
  padding: 0.7rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}
input[type="text"]:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ---------- site header / pages ---------- */
.site-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.7rem 1rem; border-bottom: 1px solid var(--border);
}
.site-header.floating { position: absolute; top: 0; left: 0; right: 0; border: none; }
.site-header .brand { text-decoration: none; color: var(--text); font-size: 1.05rem; }
.site-header nav { display: flex; gap: 0.5rem; align-items: center; }
.brand-link { color: var(--text); text-decoration: none; }
.btn.small { padding: 0.4rem 0.8rem; font-size: 0.85rem; }
.center { text-align: center; }

body.page { min-height: 100dvh; }
.page-main { max-width: 760px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.page-title-row { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 0.6rem; }
.page-title-row h1 { font-size: 1.4rem; margin: 0.4rem 0; }

/* ---------- auth tabs ---------- */
.tabs { display: flex; gap: 0.4rem; margin: 1rem 0; }
.tab {
  flex: 1; padding: 0.6rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: transparent; color: var(--muted);
  font-size: 0.95rem; cursor: pointer;
}
.tab.active { background: var(--surface-2); color: var(--text); border-color: var(--primary); }
form.panel input { margin-bottom: 0.7rem; width: 100%; }
input[type="email"], input[type="password"] {
  width: 100%; padding: 0.7rem 0.9rem; border: 1px solid var(--border);
  border-radius: var(--radius); background: var(--bg); color: var(--text); font-size: 1rem;
  box-sizing: border-box;
}
input[type="email"]:focus, input[type="password"]:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ---------- dashboard ---------- */
.meeting-list { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 1rem; }
.meeting-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem;
}
.meeting-head { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.3rem; }
.status-badge {
  font-size: 0.75rem; padding: 0.1rem 0.55rem; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2);
}
.status-badge.live { color: #34d399; border-color: #34d399; }
.status-badge.off { color: var(--muted); }
.meeting-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.7rem; }
.btn.danger-text { color: var(--danger); }
.history { margin-top: 0.8rem; border-top: 1px solid var(--border); padding-top: 0.6rem; }
.history-row { font-size: 0.85rem; color: var(--muted); padding: 0.15rem 0; }

/* ---------- host controls on tiles ---------- */
.tile .host-actions {
  /* sits left of the bottom-right mic indicator */
  position: absolute; right: 44px; bottom: 8px; display: none; gap: 0.3rem; z-index: 2;
}
.tile:hover .host-actions, .tile:focus-within .host-actions { display: flex; }
@media (hover: none) { .tile .host-actions { display: flex; } }
.host-actions button {
  border: none; border-radius: 999px; width: 30px; height: 30px;
  background: rgba(0,0,0,0.65); color: #fff; cursor: pointer; font-size: 0.8rem;
}
.host-actions button:hover { background: var(--danger); }
.host-chip { font-size: 0.72rem; color: #fbbf24; margin-left: 0.3rem; }

/* ---------- home page ---------- */
body.home {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1rem;
}
.home-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 2rem 1.6rem;
}
.brand { display: flex; align-items: center; gap: 0.6rem; justify-content: center; }
.brand h1 { margin: 0; font-size: 1.7rem; }
.brand-icon { font-size: 1.7rem; }
.tagline { text-align: center; color: var(--muted); margin: 0.5rem 0 1.5rem; }
.panel h2 { font-size: 1.05rem; margin: 0 0 0.8rem; }
.panel input { margin-bottom: 0.7rem; }
.panel .btn { width: 100%; }
.link-row { display: flex; gap: 0.5rem; }
.link-row input { flex: 1; margin-bottom: 0; }
.link-row .btn { width: auto; flex-shrink: 0; }
.create-result { margin-top: 1rem; padding: 1rem; background: var(--surface-2); border-radius: var(--radius); }
.create-result p { margin: 0 0 0.6rem; font-size: 0.9rem; }
.create-result .btn { margin-top: 0.7rem; }
.divider {
  display: flex; align-items: center; gap: 0.8rem;
  margin: 1.4rem 0; color: var(--muted); font-size: 0.85rem;
}
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }

/* ---------- lobby ---------- */
.lobby {
  display: flex; align-items: center; justify-content: center;
  min-height: 100dvh; padding: 1rem;
}
.lobby-card {
  width: 100%; max-width: 420px; text-align: center;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 20px; padding: 1.6rem;
}
.lobby-card h1 { font-size: 1.3rem; margin: 0 0 0.3rem; }
#preview {
  width: 100%; aspect-ratio: 16/9; margin: 1rem 0 0.6rem;
  background: #000; border-radius: var(--radius); object-fit: cover;
  transform: scaleX(-1);
}
.lobby-controls { display: flex; justify-content: center; gap: 0.8rem; margin-bottom: 1rem; }
.lobby-card input { margin-bottom: 0.8rem; }
.lobby-card .btn { width: 100%; }

/* ---------- meeting ---------- */
.meeting { display: flex; flex-direction: column; height: 100dvh; }
.topbar {
  display: flex; align-items: center; gap: 0.8rem;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--border);
  font-size: 0.95rem; flex-wrap: wrap;
}
.code-chip {
  background: var(--surface-2); border: 1px solid var(--border);
  padding: 0.15rem 0.6rem; border-radius: 999px;
  font-family: ui-monospace, monospace; font-size: 0.8rem; cursor: pointer;
}

.video-area {
  flex: 1; min-height: 0;
  display: flex; flex-direction: column;
  padding: 8px; gap: 6px;
}

/* Normal mode: equal grid of tiles. */
.video-grid {
  flex: 1; min-height: 0;
  display: grid; gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
  grid-auto-rows: 1fr;
  overflow: hidden;
  align-items: stretch;
}

/* Stage mode: one tile fills the area, the rest become a filmstrip. */
.stage { flex: 1; min-height: 0; display: flex; }
.stage .tile { width: 100%; height: 100%; }
.stage .tile video { object-fit: contain; }   /* never crop a shared screen */

.video-area.stage-mode .video-grid {
  flex: none; height: 116px;
  display: flex; gap: 8px;
  overflow-x: auto; overflow-y: hidden;
  grid-template-columns: none;
}
.video-area.stage-mode .video-grid .tile {
  width: 170px; min-height: 0; flex-shrink: 0;
}
.video-area.stage-mode.strip-hidden .video-grid { display: none; }

.strip-toggle {
  align-self: flex-end;
  border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
  font-size: 0.78rem; padding: 0.25rem 0.8rem; cursor: pointer;
}
.strip-toggle:hover { color: var(--text); }
.tile {
  position: relative; background: var(--surface); border-radius: var(--radius);
  overflow: hidden; min-height: 120px;
}
.tile video { width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.mirror video { transform: scaleX(-1); }
.tile .name-tag {
  position: absolute; left: 8px; bottom: 8px;
  background: rgba(0,0,0,0.55); padding: 0.15rem 0.6rem;
  border-radius: 999px; font-size: 0.8rem;
}
.tile .mic-off {
  position: absolute; right: 8px; top: 8px;
  background: var(--danger); border-radius: 50%;
  width: 26px; height: 26px; display: flex;
  align-items: center; justify-content: center; font-size: 0.75rem;
}
.tile .avatar {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center;
  font-size: 2.2rem; background: var(--surface-2);
  color: var(--muted);
}

/* controls bar */
.controls {
  display: flex; justify-content: center; gap: 0.9rem;
  padding: 0.8rem calc(env(safe-area-inset-left) + 0.8rem)
           calc(env(safe-area-inset-bottom) + 0.8rem);
  border-top: 1px solid var(--border);
}
.ctl {
  position: relative;
  width: 52px; height: 52px; border-radius: 50%;
  border: 1px solid var(--border); background: var(--surface-2);
  color: var(--text); font-size: 1.25rem; cursor: pointer;
}
.ctl.small { width: 30px; height: 30px; font-size: 0.8rem; }
.ctl.on { background: var(--primary); border-color: var(--primary); }
.ctl.off { background: var(--danger); border-color: var(--danger); }
.ctl.danger { background: var(--danger); border-color: var(--danger); transform: rotate(135deg); }
.badge {
  position: absolute; top: -4px; right: -4px;
  background: var(--danger); border-radius: 999px;
  min-width: 18px; height: 18px; font-size: 0.7rem;
  display: flex; align-items: center; justify-content: center; padding: 0 4px;
}

/* chat */
.chat-panel {
  position: fixed; right: 0; top: 0; bottom: 0;
  width: min(340px, 100%); background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 20;
}
.chat-panel header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); font-weight: 600;
}
.chat-messages { flex: 1; overflow-y: auto; padding: 0.8rem 1rem; }
.chat-msg { margin-bottom: 0.7rem; font-size: 0.9rem; overflow-wrap: anywhere; }
.chat-msg .who { color: var(--primary); font-weight: 600; margin-right: 0.4rem; }
.chat-msg.me .who { color: #34d399; }
#chat-form { display: flex; gap: 0.5rem; padding: 0.7rem; border-top: 1px solid var(--border); }
#chat-form input { flex: 1; }

/* per-tile action buttons (enlarge / fullscreen), top-right */
.tile .tile-actions {
  position: absolute; right: 8px; top: 8px;
  display: none; gap: 0.3rem; z-index: 2;
}
.tile:hover .tile-actions, .tile:focus-within .tile-actions { display: flex; }
@media (hover: none) { .tile .tile-actions { display: flex; } } /* touch: always visible */
.tile-actions button {
  border: none; border-radius: 8px; width: 32px; height: 32px;
  background: rgba(0,0,0,0.6); color: #fff; cursor: pointer; font-size: 0.95rem;
}
.tile-actions button:hover { background: var(--primary); }
.tile .mic-off { top: auto; bottom: 8px; right: 8px; } /* moved: actions own the top-right */
.tile .share-label {
  position: absolute; left: 8px; top: 8px;
  background: rgba(59,130,246,0.85); padding: 0.15rem 0.6rem;
  border-radius: 999px; font-size: 0.75rem;
}
/* fullscreen button only makes sense on the enlarged tile */
.tile .fs-btn { display: none; }
.stage .tile .fs-btn { display: block; }

/* mobile tweaks */
@media (max-width: 640px) {
  .desktop-only { display: none; }
  .video-grid { grid-template-columns: repeat(auto-fit, minmax(min(100%, 160px), 1fr)); }
  .video-area.stage-mode .video-grid { height: 88px; }
  .video-area.stage-mode .video-grid .tile { width: 124px; }
  .topbar { font-size: 0.85rem; }
}
