:root {
  --ink: #07090d;
  --ink2: #0e121a;
  --panel: #151a24;
  --teal: #00e5c0;
  --teal-dim: #00b89a;
  --coral: #ff4d6d;
  --mist: #9aa3b2;
  --white: #f4f6fa;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --tabbar-h: 68px;
  --radius: 18px;
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  color: var(--white);
  background: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; height: 100%; }
body {
  background:
    radial-gradient(ellipse 90% 55% at 15% -10%, rgba(0,229,192,.2), transparent 55%),
    radial-gradient(ellipse 70% 45% at 100% 20%, rgba(255,77,109,.14), transparent 50%),
    var(--ink);
  overscroll-behavior: none;
}

button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.screen {
  min-height: 100%;
  min-height: 100dvh;
}

/* ---- AUTH ---- */
.auth-screen {
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}
.auth-card {
  width: min(420px, 100%);
  background: rgba(21,26,36,.88);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 28px;
  padding: 28px 22px 24px;
  backdrop-filter: blur(16px);
  box-shadow: 0 30px 80px rgba(0,0,0,.45);
}
.brand {
  font-family: 'Syne', sans-serif;
  font-weight: 800;
  font-size: clamp(42px, 12vw, 56px);
  letter-spacing: -1.5px;
  margin: 10px 0 8px;
  line-height: .95;
}
.tag { color: var(--mist); line-height: 1.45; margin: 0 0 18px; }
.muted { color: var(--mist); }
.small { font-size: 13px; }
.label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--mist);
}
.live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--teal);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 1.3px;
  text-transform: uppercase;
}
.live.compact { font-size: 13px; letter-spacing: 1px; }
.live i {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--teal);
  box-shadow: 0 0 12px var(--teal);
}
.divider {
  display: flex; align-items: center; gap: 12px;
  margin: 18px 0; color: var(--mist); font-size: 12px;
}
.divider::before, .divider::after {
  content: ''; flex: 1; height: 1px; background: rgba(255,255,255,.1);
}
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; align-items: center; }
.row .field { margin: 0; flex: 1; }

.field, select.field {
  width: 100%;
  margin: 0;
  padding: 14px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
  background: var(--ink);
  outline: none;
}
.field:focus { border-color: rgba(0,229,192,.45); }
.otp-input {
  letter-spacing: .4em;
  text-align: center;
  font-size: 22px;
  font-weight: 700;
}
.code-input {
  text-align: center;
  letter-spacing: .25em;
  text-transform: uppercase;
  font-family: 'Syne', sans-serif;
  font-size: 22px;
  font-weight: 800;
}

.btn {
  border: 0;
  border-radius: 14px;
  padding: 13px 18px;
  font-weight: 700;
}
.btn-block { width: 100%; }
.btn-primary {
  background: var(--teal);
  color: var(--ink);
  box-shadow: 0 10px 30px rgba(0,229,192,.28);
}
.btn-primary:active { transform: scale(.98); }
.btn-xl {
  padding: 18px 20px;
  border-radius: 22px;
  font-family: 'Syne', sans-serif;
  font-size: 17px;
  letter-spacing: .4px;
}
.btn-ghost, .btn-soft {
  background: rgba(255,255,255,.06);
  color: var(--white);
  border: 1px solid rgba(255,255,255,.08);
}
.btn-soft { flex: 1; }
.google-wrap { min-height: 44px; display: flex; justify-content: center; }
.banner {
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
}
.banner.ok { background: rgba(0,229,192,.12); color: var(--teal); }
.err { color: var(--coral); font-size: 14px; margin-top: 10px; }

/* ---- APP SHELL ---- */
.app-shell {
  max-width: 560px;
  margin: 0 auto;
  min-height: 100dvh;
  padding:
    calc(12px + var(--safe-top))
    18px
    calc(var(--tabbar-h) + 18px + var(--safe-bottom));
  position: relative;
}
.side-rail { display: none; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 18px;
}
.user-line {
  margin-top: 4px;
  font-size: 13px;
  color: var(--mist);
}
.icon-btn {
  width: 42px; height: 42px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.05);
  font-size: 18px;
}

.brand-serif,
.hero-brand,
.hero-meet {
  font-family: 'Libre Baskerville', Georgia, serif;
}
.btn-google {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(255,255,255,.06);
  color: var(--white);
  border: 1px solid rgba(255,255,255,.14);
  margin-bottom: 4px;
}
.btn-google .g-icon {
  width: 22px; height: 22px;
  border-radius: 50%;
  background: #fff;
  color: #4285f4;
  font-weight: 800;
  font-size: 13px;
  display: grid;
  place-items: center;
}
.hero.hero-flash {
  position: relative;
  min-height: calc(100dvh - var(--tabbar-h) - 80px);
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  padding: 24px 4px 12px;
  background:
    linear-gradient(135deg, rgba(11,74,66,.85) 0%, transparent 55%),
    radial-gradient(ellipse 80% 60% at 10% 20%, rgba(0,229,192,.18), transparent 60%);
}
.hero-flash .hero-copy { margin-bottom: auto; padding-top: 12vh; }
.hero-flash .hero-brand {
  display: block;
  font-size: clamp(48px, 14vw, 72px);
  font-weight: 700;
  margin: 0;
  letter-spacing: -1px;
  line-height: .95;
  color: #fff;
}
.hero-flash .hero-meet {
  font-size: clamp(22px, 6vw, 32px);
  font-weight: 400;
  margin: 10px 0 0;
  color: #fff;
}
.btn-start {
  align-self: stretch;
  padding: 18px 22px;
  border-radius: 16px;
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .4px;
}
.app-shell.on-home .topbar { display: none; }

.hero { padding-top: 18px; }
.hero-links { display: none; }
.hero-actions { display: none; }
.page-title {
  font-family: 'Libre Baskerville', Georgia, serif;
  font-size: 28px;
  margin: 0 0 8px;
}
.card {
  background: rgba(21,26,36,.9);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 22px;
  padding: 18px;
  margin-top: 14px;
}
.friends-layout { display: block; }
.chat-layout { display: block; }
.chat-friend-list { display: none; }
.list { display: flex; flex-direction: column; gap: 4px; }
.friend-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(255,255,255,.06);
  font-size: 14px;
  width: 100%;
  text-align: left;
  background: transparent;
  border-left: 0;
  border-right: 0;
  border-top: 0;
  color: inherit;
  cursor: pointer;
}
.friend-item.active {
  background: rgba(0,229,192,.1);
  border-radius: 12px;
  padding-left: 10px;
  padding-right: 10px;
  border-bottom-color: transparent;
}
.section-label {
  margin-top: 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--mist);
}

.tabbar {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: min(560px, 100%);
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  padding: 8px 10px calc(8px + var(--safe-bottom));
  background: rgba(7,9,13,.92);
  border-top: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(18px);
  z-index: 40;
}
.tab {
  border: 0;
  background: transparent;
  color: var(--mist);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 14px;
}
.tab span { font-size: 16px; line-height: 1; }
.tab.active {
  color: var(--teal);
  background: rgba(0,229,192,.1);
}

.chat-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 220px;
  overflow: auto;
}
.chat-box.tall { min-height: 240px; max-height: 45vh; }
.chat-msg {
  align-self: flex-start;
  max-width: 85%;
  background: rgba(255,255,255,.07);
  padding: 8px 12px;
  border-radius: 14px 14px 14px 4px;
  font-size: 14px;
}
.chat-msg.me {
  align-self: flex-end;
  background: rgba(0,229,192,.18);
  border-radius: 14px 14px 4px 14px;
}

/* ---- CALL ---- */
.call-screen {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: #000;
}
.call-stage {
  position: relative;
  width: 100%;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  background: #000;
}
#remote-video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
  transition: filter .25s ease;
}
#local-video.pip {
  position: absolute;
  top: calc(14px + var(--safe-top));
  right: 14px;
  width: clamp(96px, 26vw, 140px);
  height: clamp(132px, 36vw, 190px);
  object-fit: contain;
  border-radius: 16px;
  border: 1.5px solid rgba(255,255,255,.22);
  background: #111;
  z-index: 5;
  box-shadow: 0 12px 30px rgba(0,0,0,.45);
}

.call-top {
  position: absolute;
  top: calc(14px + var(--safe-top));
  left: 12px;
  right: calc(clamp(96px, 26vw, 140px) + 28px);
  display: flex;
  gap: 8px;
  align-items: center;
  z-index: 6;
  flex-wrap: wrap;
}
.pill {
  border: 0;
  border-radius: 999px;
  padding: 8px 12px;
  background: rgba(0,0,0,.5);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255,255,255,.12);
}
.peer-pill {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
}

.call-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 12px;
  background: rgba(7,9,13,.55);
  text-align: center;
  z-index: 4;
  padding: 24px;
}
.call-overlay p { margin: 0; font-family: 'Syne', sans-serif; font-size: 22px; }
.radar {
  width: 72px; height: 72px; margin: 0 auto 8px;
  border-radius: 50%;
  border: 2px solid rgba(0,229,192,.35);
  box-shadow: 0 0 0 12px rgba(0,229,192,.08);
  animation: pulse 1.6s ease-out infinite;
}
@keyframes pulse {
  0% { transform: scale(.85); opacity: .9; }
  100% { transform: scale(1.25); opacity: 0; }
}

.filters-sheet {
  position: absolute;
  top: calc(64px + var(--safe-top));
  left: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  overflow-x: auto;
  z-index: 7;
  padding-bottom: 4px;
}
.filter-chip {
  flex: 0 0 auto;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.55);
  color: #fff;
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 700;
}
.filter-chip.active {
  background: var(--teal);
  color: var(--ink);
  border-color: transparent;
}

/* Video filters */
.filter-warm { filter: sepia(.25) saturate(1.2) contrast(1.05); }
.filter-cool { filter: hue-rotate(190deg) saturate(1.1) brightness(1.05); }
.filter-mono { filter: grayscale(1) contrast(1.1); }
.filter-vivid { filter: saturate(1.55) contrast(1.12); }
.filter-soft { filter: brightness(1.08) contrast(.92) blur(.2px); }

.call-chat {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(96px + var(--safe-bottom));
  z-index: 6;
  pointer-events: none;
}
.call-chat-msgs {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 28vh;
  overflow: auto;
  margin-bottom: 8px;
  pointer-events: none;
}
.call-chat-msgs .chat-msg {
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(8px);
  pointer-events: none;
}
.call-chat-input {
  display: flex;
  gap: 8px;
  pointer-events: auto;
}
.call-chat-input input {
  flex: 1;
  border: 1px solid rgba(255,255,255,.14);
  background: rgba(0,0,0,.55);
  border-radius: 999px;
  padding: 12px 16px;
  outline: none;
  backdrop-filter: blur(10px);
}
.call-chat-input button {
  width: 46px; height: 46px;
  border-radius: 50%;
  border: 0;
  background: var(--teal);
  color: var(--ink);
  font-weight: 800;
}

.call-controls {
  position: absolute;
  left: 0; right: 0;
  bottom: calc(18px + var(--safe-bottom));
  display: flex;
  justify-content: center;
  gap: 12px;
  z-index: 7;
  flex-wrap: wrap;
  padding: 0 12px;
}
.ctrl {
  width: 54px; height: 54px;
  border-radius: 50%;
  border: 0;
  background: rgba(255,255,255,.14);
  color: #fff;
  font-size: 18px;
  backdrop-filter: blur(8px);
}
.ctrl.teal { background: var(--teal); color: var(--ink); }
.ctrl.red { background: var(--coral); }
.ctrl:disabled { opacity: .4; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + var(--safe-bottom));
  transform: translateX(-50%);
  z-index: 100;
  background: rgba(21,26,36,.96);
  border: 1px solid rgba(255,255,255,.12);
  color: #fff;
  padding: 12px 16px;
  border-radius: 14px;
  font-size: 14px;
  max-width: min(90vw, 360px);
  text-align: center;
  box-shadow: 0 16px 40px rgba(0,0,0,.4);
}

/* Tablet */
@media (min-width: 700px) {
  .app-shell {
    max-width: 92%;
    padding-left: 28px;
    padding-right: 28px;
  }
  .tabbar { width: min(720px, 92%); }
  .hero-title { font-size: 48px; }
}

@media (min-width: 768px) {
  #local-video.pip {
    width: 160px;
    height: 220px;
  }
  .call-chat {
    left: 24px;
    right: auto;
    width: min(380px, 40vw);
  }
}

/* Desktop — side rail + wide layouts */
@media (min-width: 900px) {
  .auth-card { padding: 36px 32px; }
  .app-shell {
    max-width: none;
    margin: 0;
    display: flex;
    min-height: 100dvh;
    padding: 0;
  }
  .side-rail {
    display: flex;
    flex-direction: column;
    width: 112px;
    flex-shrink: 0;
    padding: 24px 10px 20px;
    background: rgba(18,22,31,.65);
    border-right: 1px solid rgba(255,255,255,.08);
    min-height: 100dvh;
    position: sticky;
    top: 0;
  }
  .rail-brand {
    text-align: center;
    margin-bottom: 28px;
  }
  .rail-brand .live {
    justify-content: center;
    font-family: 'Libre Baskerville', Georgia, serif;
    color: var(--teal);
    font-size: 16px;
  }
  .rail-brand .live i { display: none; }
  .rail-brand .user-line { display: none; }
  .rail-nav {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
  }
  .rail-tab {
    border: 0;
    background: transparent;
    color: var(--mist);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 12px 6px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 14px;
  }
  .rail-tab span { font-size: 18px; }
  .rail-tab.active {
    color: var(--ink);
    background: var(--teal);
  }
  .rail-logout { margin: 0 auto; }

  .app-main {
    flex: 1;
    min-width: 0;
    padding: 28px 40px 40px;
  }
  .topbar { display: none; }
  .tabbar { display: none; }

  .hero.hero-flash {
    display: block;
    position: relative;
    min-height: calc(100dvh - 40px);
    padding: 0;
    background:
      linear-gradient(115deg, #0b4a42 0%, #071512 42%, #050608 100%);
  }
  .hero-flash .hero-copy {
    position: absolute;
    left: 8%;
    top: 50%;
    transform: translateY(-50%);
    margin: 0;
    padding: 0;
  }
  .hero-flash .hero-brand {
    font-size: clamp(64px, 8vw, 96px);
  }
  .hero-flash .hero-meet {
    font-size: clamp(28px, 3.5vw, 40px);
  }
  .btn-start {
    position: absolute;
    right: 48px;
    bottom: 48px;
    align-self: auto;
    width: auto;
    min-width: 220px;
    padding: 20px 36px;
    font-size: 18px;
  }
  .hero-actions { display: none; }
  .hero-links { display: none; }

  .room-wrap {
    max-width: 420px;
    margin: 48px auto 0;
  }

  .friends-layout {
    display: grid;
    grid-template-columns: 0.9fr 1.1fr;
    gap: 24px;
    align-items: start;
  }
  .friends-pane { margin-top: 0; min-height: 320px; }

  .chat-page-title { margin-bottom: 16px; }
  .chat-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 0;
    min-height: calc(100dvh - 120px);
    border: 1px solid rgba(255,255,255,.08);
    border-radius: 22px;
    overflow: hidden;
    background: rgba(21,26,36,.55);
  }
  .chat-sidebar {
    border-right: 1px solid rgba(255,255,255,.08);
    padding: 12px;
    overflow: auto;
  }
  .chat-select-mobile { display: none; }
  .chat-friend-list { display: flex; flex-direction: column; gap: 2px; }
  .chat-thread {
    margin: 0;
    border: 0;
    border-radius: 0;
    background: transparent;
    display: flex;
    flex-direction: column;
    height: 100%;
  }
  .chat-box.tall {
    flex: 1;
    max-height: none;
    min-height: 0;
  }
}

@media (orientation: landscape) and (max-height: 500px) {
  .call-chat { max-width: 42vw; bottom: calc(78px + var(--safe-bottom)); }
  .call-chat-msgs { max-height: 34vh; }
  #local-video.pip { width: 110px; height: 78px; }
}
