/* ── Reset & Base ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0f0f13;
  --surface:  #1a1a24;
  --border:   #2e2e42;
  --accent:   #5b6af0;
  --accent-h: #7b88ff;
  --danger:   #e05555;
  --text:     #e8e8f0;
  --muted:    #8888aa;
  --green:    #4caf50;
  --yellow:   #ffc107;
  --radius:   12px;
  --ctrl-h:   68px;
}

html { touch-action: manipulation; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #fff;
  color: #111;
}

/* Applied via JS when the call screen is active */
body.in-call {
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

/* ── Blog / Join Screen ──────────────────────────────────────────────── */
#join-screen {
  min-height: 100dvh;
  background: #fff;
  color: #1a1a2e;
}

.blog-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .75rem 1.5rem;
  background: rgba(255,255,255,.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid #e5e7eb;
}

.blog-brand {
  font-size: 1.15rem;
  font-weight: 800;
  color: #111827;
  letter-spacing: -.5px;
  text-decoration: none;
  flex-shrink: 0;
}

.blog-search {
  display: flex;
  align-items: center;
  gap: .3rem;
  border: 1.5px solid #d1d5db;
  border-radius: 999px;
  padding: .28rem .35rem .28rem .85rem;
  background: #f9fafb;
  transition: border-color .2s, box-shadow .2s;
}

.blog-search:focus-within {
  border-color: #6366f1;
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
}

.blog-search input {
  border: none;
  background: transparent;
  font-size: .88rem;
  color: #111827;
  outline: none;
  width: clamp(110px, 22vw, 210px);
  /* prevent iOS zoom */
  font-size: 16px;
}

.blog-search input::placeholder { color: #9ca3af; }

.blog-search button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: #111827;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
  transition: background .2s;
  -webkit-tap-highlight-color: transparent;
}

.blog-search button:hover { background: #374151; }
.blog-search button svg   { width: 14px; height: 14px; }

.blog-main {
  max-width: 700px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
}

.blog-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: .45rem;
  font-size: .8rem;
  color: #6b7280;
  margin-bottom: 1rem;
}

.blog-tag {
  background: #ede9fe;
  color: #5b21b6;
  padding: .18rem .5rem;
  border-radius: 4px;
  font-weight: 600;
  font-size: .72rem;
}

.blog-dot { color: #d1d5db; }

.blog-title {
  font-size: clamp(1.55rem, 5vw, 2.1rem);
  font-weight: 800;
  line-height: 1.22;
  color: #111827;
  letter-spacing: -.5px;
  margin-bottom: 1rem;
}

.blog-lead {
  font-size: clamp(.97rem, 3vw, 1.12rem);
  color: #374151;
  line-height: 1.75;
  margin-bottom: 1.4rem;
}

.blog-article p {
  font-size: .95rem;
  color: #374151;
  line-height: 1.8;
  margin-bottom: 1.15rem;
}

.blog-article h2 {
  font-size: 1.2rem;
  font-weight: 700;
  color: #111827;
  margin: 1.8rem 0 .7rem;
}

.blog-search-result {
  margin-top: 1.25rem;
  padding: .7rem .9rem;
  border-radius: 8px;
  font-size: .88rem;
  background: #fef2f2;
  color: #b91c1c;
  border: 1px solid #fecaca;
}

/* ── Call Screen ─────────────────────────────────────────────────────── */
#call-screen {
  position: relative;
  height: 100dvh;
}

/* ── Video grid — always full screen, controls overlay on top ────────── */
#video-grid {
  position: absolute;
  inset: 0;
  background: #000;
  overflow: hidden;
}

.video-box {
  position: absolute;
  overflow: hidden;
  border-radius: var(--radius);
}

#remote-container {
  inset: 0;
  border-radius: 0;
  background: #111;
}

#remote-video {
  width: 100%; height: 100%;
  object-fit: contain;
  display: block;
  background: #000;
}

/* View modes */
#remote-container.mode-fill  #remote-video { object-fit: cover; }
#remote-container.mode-fit   #remote-video { object-fit: contain; }
#remote-container.mode-width #remote-video {
  object-fit: fill;
  width: 100%; height: auto;
  max-height: 100%;
  position: absolute;
  top: 50%; left: 0;
  transform: translateY(-50%);
}

/* Local PiP — default sits above the controls bar; JS adjusts on hide/show */
#local-container {
  bottom: calc(var(--ctrl-h) + 12px);
  right: 12px;
  transition: bottom .3s ease;
  width: 28vw;
  max-width: 180px;
  min-width: 90px;
  aspect-ratio: 4 / 3;
  border: 2px solid var(--border);
  box-shadow: 0 4px 20px rgba(0,0,0,.6);
  z-index: 10;
  background: #0a0a0a;
  cursor: move;
  touch-action: none;
  border-radius: 10px;
}

#local-video {
  width: 100%; height: 100%;
  object-fit: cover;
  display: block;
  transform: scaleX(-1);
  border-radius: 8px;
}

/* ── Connection status pill ──────────────────────────────────────────── */
#status-pill {
  position: absolute;
  bottom: 12px;
  left: 12px;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 5px;
  background: rgba(0,0,0,.45);
  padding: 3px 9px 3px 7px;
  border-radius: 999px;
  font-size: .6rem;
  color: rgba(255,255,255,.75);
  backdrop-filter: blur(4px);
  pointer-events: none;
  user-select: none;
  transition: bottom .3s ease, opacity .3s ease;
}

#status-dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--yellow);
  flex-shrink: 0;
  transition: background .35s;
}

#status-dot.connected    { background: var(--green); }
#status-dot.disconnected { background: var(--danger); }

/* ── Video labels (signal bars only, no text) ────────────────────────── */
.video-label {
  position: absolute;
  bottom: 6px; left: 7px;
  display: flex;
  align-items: center;
  background: rgba(0,0,0,.45);
  padding: 3px 5px;
  border-radius: 4px;
  pointer-events: none;
  user-select: none;
  backdrop-filter: blur(4px);
}

/* Mini signal bars inside video labels */
.label-sig {
  display: flex;
  align-items: flex-end;
  gap: 1px;
  height: 7px;
  flex-shrink: 0;
}

.label-sig .bar {
  width: 2px;
  border-radius: 1px;
  background: rgba(255,255,255,.2);
  transition: background .3s;
}

.label-sig .bar:nth-child(1) { height: 25%; }
.label-sig .bar:nth-child(2) { height: 50%; }
.label-sig .bar:nth-child(3) { height: 75%; }
.label-sig .bar:nth-child(4) { height: 100%; }

.label-sig[data-bars="4"] .bar.active { background: var(--green); }
.label-sig[data-bars="3"] .bar.active { background: var(--green); }
.label-sig[data-bars="2"] .bar.active { background: var(--yellow); }
.label-sig[data-bars="1"] .bar.active { background: var(--danger); }
.label-sig[data-bars="0"] .bar.active { background: rgba(255,255,255,.2); }

/* ── Remote peer badges ──────────────────────────────────────────────── */
#remote-mute-badge,
#remote-share-badge {
  position: absolute;
  display: flex;
  align-items: center;
  gap: .35rem;
  padding: .3rem .7rem;
  border-radius: 999px;
  background: rgba(0,0,0,.6);
  color: #fff;
  font-size: .75rem;
  font-weight: 500;
  pointer-events: none;
  z-index: 6;
  backdrop-filter: blur(4px);
}

/* Bug 3 fix: badges were both at top:12px left:12px and would overlap */
#remote-mute-badge  { top: 12px; left: 12px; color: var(--danger); }
#remote-share-badge { top: 12px; right: 12px; left: auto; color: var(--accent-h); }
#remote-mute-badge  svg,
#remote-share-badge svg { width: 14px; height: 14px; flex-shrink: 0; }

/* ── Waiting overlay ─────────────────────────────────────────────────── */
#waiting-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,.78);
  gap: 1rem;
  z-index: 5;
  transition: opacity .4s;
}

/* Use a custom class so display:flex is preserved for the fade transition */
#waiting-overlay.overlay-hidden {
  opacity: 0;
  pointer-events: none;
}

#waiting-text {
  font-size: clamp(.85rem, 3.5vw, 1rem);
  color: var(--muted);
  text-align: center;
  padding: 0 1.5rem;
}

.spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Controls bar — overlays bottom of video ─────────────────────────── */
#controls {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: clamp(1rem, 5vw, 2rem);
  padding: .9rem 1.5rem;
  padding-bottom: calc(.9rem + env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  min-height: var(--ctrl-h);
  transition: transform .3s ease, opacity .3s ease;
}

/* Auto-hide on mobile (JS adds/removes this class) */
#controls.ctrl-hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

.call-btn-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .3rem;
}

.btn-label {
  font-size: clamp(.6rem, 2.5vw, .68rem);
  color: var(--muted);
  user-select: none;
  letter-spacing: .01em;
}

/* ── Circular call button ────────────────────────────────────────────── */
.call-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,.1);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background .18s, transform .12s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  position: relative;
}

.call-btn:hover  { background: rgba(255,255,255,.18); }
.call-btn:active { transform: scale(.91); }

.call-btn.muted       { background: var(--danger); }
.call-btn.muted:hover { background: #c0392b; }

.ic-mic-off { display: none; }
.call-btn.muted .ic-mic     { display: none; }
.call-btn.muted .ic-mic-off { display: block; }

.call-btn.ns-on       { background: var(--accent); }
.call-btn.ns-on:hover { background: var(--accent-h); }

.call-btn.sharing       { background: var(--accent); }
.call-btn.sharing:hover { background: var(--accent-h); }
.call-btn.sharing::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  animation: pulse-ring 1.4s ease-out infinite;
  pointer-events: none;
}

@keyframes pulse-ring {
  0%   { opacity: .8; transform: scale(1); }
  100% { opacity: 0;  transform: scale(1.4); }
}

.ic-share-on { display: none; }
.call-btn.sharing .ic-share-off { display: none; }
.call-btn.sharing .ic-share-on  { display: block; }

.call-btn.end-call {
  background: #e53935;
  width: 56px;
  height: 56px;
}
.call-btn.end-call .ic { transform: rotate(135deg); }
.call-btn.end-call:hover { background: #c62828; }

.ic {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  pointer-events: none;
}

/* ── Single cycling view button ──────────────────────────────────────── */
.view-ic { display: none; }
#view-btn[data-mode="fit"]   .view-ic-fit   { display: block; }
#view-btn[data-mode="fill"]  .view-ic-fill  { display: block; }
#view-btn[data-mode="width"] .view-ic-width { display: block; }

/* ── Portrait phones (≤ 480px) ───────────────────────────────────────── */
@media (max-width: 480px) {
  #local-container   { width: 30vw; min-width: 80px; right: 10px; }
  .call-btn          { width: 44px; height: 44px; }
  .call-btn.end-call { width: 48px; height: 48px; }
  .ic                { width: 17px; height: 17px; }
  #controls          { gap: clamp(.6rem, 4vw, 1.25rem); padding: .65rem 1rem; padding-bottom: calc(.65rem + env(safe-area-inset-bottom)); }
}

/* ── Very small phones (≤ 360px) ─────────────────────────────────────── */
@media (max-width: 360px) {
  .call-btn          { width: 40px; height: 40px; }
  .call-btn.end-call { width: 44px; height: 44px; }
  .ic                { width: 15px; height: 15px; }
  #controls          { gap: .5rem; padding: .5rem .75rem; padding-bottom: calc(.5rem + env(safe-area-inset-bottom)); }
  .btn-label         { display: none; }
}

/* ── Landscape phones ────────────────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
  .call-btn          { width: 40px; height: 40px; }
  .call-btn.end-call { width: 44px; height: 44px; }
  .ic                { width: 16px; height: 16px; }
  .btn-label         { display: none; }
  #controls          { min-height: 52px; padding: .3rem 1rem; padding-bottom: calc(.3rem + env(safe-area-inset-bottom)); gap: 1.25rem; align-items: center; }
  #local-container   { width: 22vw; max-width: 130px; bottom: 8px; right: 8px; }
}

/* ── Tablets (≥ 768px) ───────────────────────────────────────────────── */
@media (min-width: 768px) {
  #local-container   { width: 200px; max-width: 200px; bottom: 16px; right: 16px; }
  .call-btn          { width: 56px; height: 56px; }
  .call-btn.end-call { width: 60px; height: 60px; }
  .ic                { width: 22px; height: 22px; }
}

/* ── Enhancement 3: screen-share audio-choice popover ────────────────── */
.share-wrap { position: relative; }

.share-options {
  position: absolute;
  bottom: calc(100% + 10px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 152px;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,.55);
}

/* Small arrow pointing down toward the share button */
.share-options::after {
  content: "";
  position: absolute;
  bottom: -6px;
  left: 50%;
  transform: translateX(-50%);
  border-left: 6px solid transparent;
  border-right: 6px solid transparent;
  border-top: 6px solid var(--border);
}

.share-opt-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 11px;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text);
  font-size: .82rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s;
  -webkit-tap-highlight-color: transparent;
}
.share-opt-btn:hover { background: rgba(255,255,255,.08); }
.share-opt-btn svg   { width: 15px; height: 15px; flex-shrink: 0; }

/* ── Enhancement 2: PiP resize handle (top-left corner) ─────────────── */
.pip-resize-handle {
  position: absolute;
  top: 0;
  left: 0;
  width: 20px;
  height: 20px;
  cursor: nw-resize;
  z-index: 11;
  touch-action: none;
}

/* L-shaped corner grip indicator */
.pip-resize-handle::after {
  content: "";
  position: absolute;
  top: 4px;
  left: 4px;
  width: 8px;
  height: 8px;
  border-top: 2px solid rgba(255,255,255,.45);
  border-left: 2px solid rgba(255,255,255,.45);
  border-radius: 1px;
  pointer-events: none;
}
