/* LivCalls — Mobile-first dark theme */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d0d0d;
  --surface:  #1a1a1a;
  --surface2: #252525;
  --border:   #2e2e2e;
  --text:     #f0f0f0;
  --muted:    #777;
  --accent:   #7c3aed;
  --accent-h: #6d28d9;
  --success:  #16a34a;
  --danger:   #dc2626;
  --danger-b: #ef4444;
  --radius:   12px;
  --radius-s: 8px;
}

html, body {
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

/* ── AUTH ─────────────────────────────────────────────────────────────────── */
.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.logo { display: flex; align-items: center; gap: .5rem; }
.logo h1, .logo h2 { font-size: 1.4rem; font-weight: 700; }
.logo-icon { font-size: 1.4rem; }
.logo-sm { font-size: .95rem; font-weight: 700; }
.subtitle { color: var(--muted); font-size: .9rem; }

/* ── FIELDS ──────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: .35rem; }
.field label { font-size: .82rem; color: var(--muted); font-weight: 500; }
.label-text { font-size: .82rem; color: var(--muted); font-weight: 500; }

input[type="text"],
input[type="password"],
input[type="datetime-local"],
textarea,
select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  color: var(--text);
  font-size: 1rem;
  padding: .6rem .8rem;
  width: 100%;
  outline: none;
  transition: border-color .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { font-family: inherit; font-size: .9rem; resize: vertical; }
input[readonly] { color: var(--muted); cursor: default; }

select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23777' stroke-width='2'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
  background-repeat: no-repeat;
  background-position: right .75rem center;
  background-size: .9rem;
  padding-right: 2.25rem;
}

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn {
  border: none; border-radius: var(--radius-s); cursor: pointer;
  font-size: .9rem; font-weight: 600; padding: .6rem 1.1rem;
  transition: opacity .15s, background .15s;
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }

.btn-primary        { background: var(--accent);  color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-h); }
.btn-success        { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { opacity: .85; }
.btn-danger         { background: var(--danger);  color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: .85; }
.btn-danger-outline { background: transparent; border: 1px solid var(--danger-b); color: var(--danger-b); }
.btn-danger-outline:hover:not(:disabled) { background: rgba(239,68,68,.1); }
.btn-ghost          { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); }
.btn-outline        { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover:not(:disabled) { background: var(--surface2); }

.btn-full { width: 100%; }
.btn-sm   { font-size: .78rem; padding: .4rem .8rem; }

/* ── CARDS ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem;
  margin-bottom: .75rem;
}

.knock-panel { background: rgba(124,58,237,.08); border-color: var(--accent); }

/* ── TOP BAR ─────────────────────────────────────────────────────────────── */
.top-bar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: .7rem 1rem; position: sticky; top: 0; z-index: 100;
}
.top-bar-inner {
  display: flex; align-items: center; justify-content: space-between;
  max-width: 700px; margin: 0 auto;
}
.top-bar-right { display: flex; align-items: center; gap: .65rem; }

/* ── DASHBOARD ───────────────────────────────────────────────────────────── */
.dashboard { max-width: 700px; margin: 0 auto; padding: 1.1rem 1rem; }
.dashboard-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1rem;
}
.dashboard-header h2 { font-size: 1.1rem; font-weight: 700; }

.row-btns { display: flex; gap: .5rem; flex-wrap: wrap; }
.copy-row { display: flex; gap: .4rem; }
.copy-row input { flex: 1; }

/* ── STATUS BADGES ───────────────────────────────────────────────────────── */
.status-badge {
  font-size: .7rem; font-weight: 700; padding: .2rem .55rem;
  border-radius: 999px; text-transform: uppercase; letter-spacing: .05em;
}
.status-connecting  { background: #222; color: var(--muted); }
.status-connected   { background: rgba(22,163,74,.15); color: #4ade80; }
.status-disconnected{ background: rgba(220,38,38,.15);  color: #f87171; }

/* ── ROOM PAGES ──────────────────────────────────────────────────────────── */
.room-page { display: flex; flex-direction: column; min-height: 100vh; }

.room-header {
  background: var(--surface); border-bottom: 1px solid var(--border);
  padding: .7rem 1rem; display: flex; align-items: center;
  justify-content: space-between; position: sticky; top: 0; z-index: 100;
}

.room-main {
  flex: 1; max-width: 700px; width: 100%; margin: 0 auto; padding: 1rem;
  display: flex; flex-direction: column;
}

/* ── VIDEO GRID ──────────────────────────────────────────────────────────── */
.video-grid {
  display: grid; grid-template-columns: 1fr 1fr;
  gap: .65rem; margin-bottom: .75rem;
}
.video-tile {
  position: relative; background: var(--surface2);
  border: 1px solid var(--border); border-radius: var(--radius);
  aspect-ratio: 3/4; overflow: hidden;
}
.video-placeholder {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; height: 100%; gap: .4rem;
  color: var(--muted); font-size: .8rem; text-align: center;
}
.video-placeholder span { font-size: 2.2rem; }
.video-label {
  position: absolute; bottom: .45rem; left: .45rem;
  background: rgba(0,0,0,.65); color: #fff;
  font-size: .7rem; font-weight: 600; padding: .2rem .45rem; border-radius: 6px;
}

/* ── CHAT ────────────────────────────────────────────────────────────────── */
.chat-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-top: auto;
}
.chat-header {
  padding: .65rem 1rem; font-weight: 600; font-size: .85rem;
  border-bottom: 1px solid var(--border);
}
.chat-body { min-height: 60px; }

/* ── STATUS PANEL ────────────────────────────────────────────────────────── */
.status-panel { text-align: center; padding: 2rem 1rem; }

/* ── SCREENS (fan flow) ──────────────────────────────────────────────────── */
.screen { flex: 1; display: flex; flex-direction: column; }

/* ── UTILITIES ───────────────────────────────────────────────────────────── */
.hidden   { display: none !important; }
.center-text { text-align: center; }
.muted    { color: var(--muted); }
.hint-text{ font-size: .78rem; }

.pulse-icon {
  font-size: 2.2rem; margin-bottom: .5rem;
  animation: pulse 2s ease-in-out infinite;
}
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:.4} }

.error-msg {
  color: #f87171; font-size: .82rem;
  background: rgba(220,38,38,.08); border-radius: 6px; padding: .45rem .65rem;
}

.badge {
  background: var(--accent); color: #fff;
  font-size: .7rem; font-weight: 700; padding: .1rem .4rem;
  border-radius: 999px; min-width: 1.2rem; text-align: center;
}

hr { border: none; border-top: 1px solid var(--border); margin: .85rem 0; }
h3 { font-size: .95rem; font-weight: 700; margin-bottom: .25rem; }
h4 { font-size: .88rem; font-weight: 600; margin-bottom: .4rem; }

/* ── VIDEO ELEMENTS ──────────────────────────────────────────────────────── */
.video-tile video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: var(--radius);
  background: #000;
  display: none;
}
.video-tile.active video          { display: block; }
.video-tile.active .video-placeholder { display: none; }

/* ── CALL CONTROLS ───────────────────────────────────────────────────────── */
.call-controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: .75rem;
  padding: .65rem 0;
  margin-bottom: .5rem;
}
.ctrl-btn {
  width: 52px; height: 52px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface2);
  color: var(--text);
  font-size: 1.25rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
}
.ctrl-btn:hover     { background: var(--surface); }
.ctrl-btn.muted     { background: rgba(220,38,38,.18); border-color: var(--danger); color: #f87171; }
.ctrl-btn.cam-off   { background: rgba(220,38,38,.18); border-color: var(--danger); color: #f87171; }
.ctrl-btn.flip      { font-size: 1rem; }

/* ── CHAT PANEL (Phase 2) ────────────────────────────────────────────────── */
.chat-messages {
  height: 130px;
  overflow-y: auto;
  padding: .5rem .75rem;
  display: flex;
  flex-direction: column;
  gap: .3rem;
  scroll-behavior: smooth;
}
.chat-msg          { font-size: .8rem; display: flex; flex-direction: column; gap: .05rem; }
.chat-msg-header   { display: flex; gap: .35rem; align-items: baseline; }
.chat-sender       { font-weight: 700; color: #a78bfa; font-size: .75rem; }
.chat-sender.fan-sender { color: #4ade80; }
.chat-text         { color: var(--text); word-break: break-word; line-height: 1.4; }
.chat-msg.system-msg { color: var(--muted); font-style: italic; font-size: .75rem; }

.chat-input-row {
  display: flex;
  gap: .4rem;
  padding: .5rem .65rem;
  border-top: 1px solid var(--border);
}
.chat-input-row input  { flex: 1; font-size: .82rem; padding: .38rem .55rem; border-radius: 6px; }
.chat-input-row button { padding: .38rem .7rem; font-size: .78rem; border-radius: 6px; }

/* ── TOAST ───────────────────────────────────────────────────────────────── */
#toast-area {
  position: fixed;
  top: 4.5rem; right: .75rem;
  display: flex; flex-direction: column; gap: .4rem;
  z-index: 9999;
  pointer-events: none;
  max-width: 280px;
}
.toast {
  background: rgba(220,38,38,.92);
  color: #fff;
  padding: .55rem .9rem;
  border-radius: var(--radius-s);
  font-size: .82rem;
  font-weight: 600;
  line-height: 1.4;
  animation: toastIn .2s ease;
  pointer-events: auto;
}
@keyframes toastIn { from { transform: translateX(120%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── ICE STATUS BADGE ────────────────────────────────────────────────────── */
.ice-badge {
  font-size: .65rem; font-weight: 700;
  padding: .15rem .4rem; border-radius: 999px;
  text-transform: uppercase; letter-spacing: .04em;
}
.ice-checking     { background: #292900; color: #facc15; }
.ice-connected    { background: rgba(22,163,74,.18);  color: #4ade80; }
.ice-disconnected { background: rgba(220,38,38,.18);  color: #f87171; }
.ice-failed       { background: rgba(220,38,38,.28);  color: #f87171; }

/* ── RESPONSIVE ──────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  .video-grid { grid-template-columns: 1fr; }
  .auth-card  { padding: 1.4rem; }
  .dashboard  { padding: .9rem .75rem; }
}

/* ── TIMER PANEL ─────────────────────────────────────────────────────────── */
.timer-panel {
  text-align: center;
  padding: 1rem .9rem;
}
.timer-panel-fan {
  padding: .7rem .9rem;
}
.timer-display {
  font-size: 2.6rem;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: .04em;
  color: #a78bfa;
  line-height: 1;
  margin-bottom: .25rem;
}
.timer-display.paused  { color: var(--muted); }
.timer-display.expired { color: #f87171; }
.timer-status-label {
  font-size: .75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: .75rem;
}
.timer-controls { display: flex; flex-direction: column; gap: .5rem; align-items: center; }
.timer-controls.hidden { display: none; }
.timer-input-row {
  display: flex; align-items: center; gap: .5rem;
  font-size: .82rem;
}
.timer-preset-row {
  display: flex; flex-wrap: wrap; gap: .35rem; justify-content: center; margin-bottom: .5rem;
}
.timer-preset-btn {
  font-size: .78rem; padding: .25rem .55rem; min-width: 52px;
}
.timer-preset-btn.active {
  border-color: var(--accent); color: #a78bfa; background: rgba(139,92,246,.12);
}
.timer-input {
  width: 64px;
  text-align: center;
  font-size: .9rem;
  padding: .3rem .4rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.timer-expired-label {
  font-size: 1rem; font-weight: 700; color: #f87171; margin: 0 0 .4rem;
}
.timer-expired-notice {
  display: flex; align-items: center; gap: .5rem;
  padding: .6rem .9rem; font-size: .85rem; font-weight: 600;
  color: #f87171;
  border: 1px solid rgba(248,113,113,.3);
}

/* ── PHASE 4: VIDEO GRID WRAP + WATERMARK + DISCONNECT OVERLAY ────────────── */

.video-grid-wrap {
  position: relative;
}

/* Moving watermark — visible in screenshots/recordings.
   Cannot reliably detect or prevent recording; this is a tracing ref only. */
.video-watermark {
  position: absolute;
  top: 10%;
  left: 8%;
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.28);
  pointer-events: none;
  user-select: none;
  white-space: nowrap;
  z-index: 10;
  letter-spacing: 0.05em;
  font-weight: 500;
  animation: wm-drift 32s ease-in-out infinite;
}

@keyframes wm-drift {
  0%   { top: 10%; left:  8%; opacity: 0.28; }
  14%  { top: 58%; left: 62%; opacity: 0.22; }
  28%  { top: 78%; left: 12%; opacity: 0.30; }
  42%  { top: 18%; left: 74%; opacity: 0.20; }
  57%  { top: 68%; left: 38%; opacity: 0.28; }
  71%  { top: 32%; left: 55%; opacity: 0.22; }
  85%  { top: 82%; left: 70%; opacity: 0.26; }
  100% { top: 10%; left:  8%; opacity: 0.28; }
}

/* Creator/peer disconnect overlay */
.disconnect-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.74);
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.disconnect-overlay-inner {
  text-align: center;
  padding: 1.5rem 2rem;
}

.disconnect-overlay-inner p {
  margin-top: 0.4rem;
  font-size: 1rem;
}

/* ── MOBILE VIDEO LAYOUT (portrait ≤ 600px) ───────────────────────────────── */
/* Placed at the end of the file so these rules win over the desktop
   .video-grid / .timer-panel / .chat-panel declarations above. */
@media (max-width: 600px) {
  /* Fill the safe-area viewport */
  body {
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }

  .room-main {
    padding: .5rem env(safe-area-inset-right, .5rem) 0 env(safe-area-inset-left, .5rem);
  }

  /* Stack panels compactly */
  .room-header { padding: .4rem .6rem; }
  .status-panel, .knock-panel, .timer-panel { padding: .6rem .7rem; }

  /* Video grid: relative container, remote fills it, local overlays */
  .video-grid-wrap {
    position: relative;
    width: 100%;
    aspect-ratio: 9/16;      /* portrait phone ratio */
    max-height: 56vh;
    overflow: hidden;
    border-radius: var(--radius);
    background: #000;
  }

  .video-grid {
    display: block;          /* override desktop grid */
    width: 100%;
    height: 100%;
    position: relative;
    margin-bottom: 0;
  }

  /* Remote video: fills the entire grid-wrap */
  #remote-tile {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border-radius: 0;
  }
  #remote-tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* Local video: small overlay — bottom-right corner */
  #local-tile {
    position: absolute;
    bottom: .6rem;
    right: .6rem;
    width: 28%;
    aspect-ratio: 3/4;
    border-radius: 8px;
    overflow: hidden;
    border: 1.5px solid rgba(255,255,255,.25);
    z-index: 5;
    background: #111;
  }
  #local-tile video {
    width: 100%;
    height: 100%;
    object-fit: cover;
  }

  /* Watermark stays inside the grid wrap */
  .video-watermark { font-size: .55rem; }

  /* Controls bar: compact horizontal row */
  .call-controls {
    display: flex; justify-content: center; gap: .9rem; padding: .5rem .4rem;
  }
  .ctrl-btn { font-size: 1.3rem; padding: .35rem; }

  /* Chat: collapsible — collapsed by default on mobile */
  .chat-panel {
    max-height: 0;
    overflow: hidden;
    transition: max-height .3s ease;
  }
  .chat-panel.chat-open { max-height: 40vh; }

  /* Chat toggle button — show only on mobile.
     !important is required to beat the inline style="display:none" that
     keeps the button hidden on desktop. */
  #chat-toggle-btn { display: flex !important; }
}

/* ── MOBILE LANDSCAPE (≤ 900px wide, ≤ 500px tall) ───────────────────────── */
@media (max-width: 900px) and (max-height: 500px) {
  .video-grid-wrap {
    aspect-ratio: unset;
    max-height: 70vw;
    width: 55%;
    float: left;
    margin-right: .75rem;
  }
  .video-grid { display: block; width: 100%; height: 100%; position: relative; }
  #remote-tile { position: absolute; inset: 0; }
  #remote-tile video { width: 100%; height: 100%; object-fit: cover; }
  #local-tile {
    position: absolute; bottom: .5rem; right: .5rem;
    width: 30%; aspect-ratio: 3/4; border-radius: 6px; overflow: hidden;
    border: 1.5px solid rgba(255,255,255,.2); z-index: 5; background: #111;
  }
  #local-tile video { width: 100%; height: 100%; object-fit: cover; }
}

/* ── FANS / ACCESS HISTORY ───────────────────────────────────────────────── */

/* Security notices — deliberately plain and always visible above the fan list.
   IP data is observational, not identity; the wording must not be dismissible. */
.notice-card { background: rgba(217,119,6,.07); border-color: #78350f; }
.notice-item {
  color: #d1c4a8; font-size: .76rem; line-height: 1.45;
}
.notice-item + .notice-item { margin-top: .4rem; }

/* Horizontal scroll rather than a squashed table on narrow phones */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.data-table { width: 100%; border-collapse: collapse; font-size: .78rem; }
.data-table th {
  text-align: left; font-weight: 600; color: var(--muted);
  padding: .4rem .45rem; border-bottom: 1px solid var(--border);
  white-space: nowrap; font-size: .72rem; text-transform: uppercase;
  letter-spacing: .04em;
}
.data-table td {
  padding: .45rem .45rem; border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table .cell-nowrap { white-space: nowrap; }
.data-table .cell-mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.data-table .cell-actions { white-space: nowrap; text-align: right; }
.data-table .cell-actions .btn { padding: .25rem .5rem; font-size: .72rem; }

.pill {
  display: inline-block; border-radius: 999px; padding: .1rem .45rem;
  font-size: .68rem; font-weight: 700; white-space: nowrap;
}
.pill-ok      { background: rgba(22,163,74,.16);  color: #4ade80; }
.pill-blocked { background: rgba(220,38,38,.18);  color: #f87171; }
.pill-preview { background: #292900;              color: #facc15; }

/* ── MODAL ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(0,0,0,.72);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.1rem;
  width: 100%; max-width: 380px;
  max-height: 90vh; overflow-y: auto;
}

/* ── BEAUTY FILTER (DeepAR) ──────────────────────────────────────────────── */
.ctrl-btn.beauty { font-size: 1.2rem; }

/* Still loading, or the SDK/license never came up. Kept clickable so the tap
   can explain itself via a toast — see room-creator.js. */
.ctrl-btn.beauty.beauty-loading {
  opacity: .4;
  cursor: default;
}
.ctrl-btn.beauty.beauty-loading:hover { background: var(--surface2); }

.ctrl-btn.beauty.beauty-on {
  background: rgba(139,92,246,.18);
  border-color: var(--accent);
  color: #c4b5fd;
  box-shadow: 0 0 12px rgba(139,92,246,.5);
}

.beauty-controls { display: flex; justify-content: center; }

.beauty-slider-row {
  display: none;                /* .visible is added while the filter is on */
  align-items: center;
  gap: .6rem;
  width: 100%;
  max-width: 320px;
  margin: 0 auto .5rem;
  padding: .45rem .8rem;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: .8rem;
}
.beauty-slider-row.visible { display: flex; }
.beauty-slider-row label   { color: var(--muted); white-space: nowrap; }
.beauty-slider-row input[type="range"] {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
  cursor: pointer;
}
.beauty-intensity-val {
  min-width: 2.6rem;
  text-align: right;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
