@font-face {
  font-family: 'Rooyin';
  src: url('/fonts/RooyinFreeFaNum-Regular.ttf') format('truetype');
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'Rooyin';
  src: url('/fonts/RooyinFreeFaNum-Bold.ttf') format('truetype');
  font-weight: 700;
  font-display: swap;
}

:root {
  --bg: #070b15;
  --bg-2: #0b1020;
  --surface: rgba(20, 28, 48, 0.72);
  --surface-solid: #121a2c;
  --border: rgba(255, 255, 255, 0.09);
  --text: #eef3ff;
  --muted: #93a0bd;
  --primary: #4f8cff;
  --primary-2: #7aa7ff;
  --primary-dark: #2f6be0;
  --danger: #ff5c6c;
  --success: #45d483;
  --warn: #ffb547;
  --radius: 18px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.45);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Rooyin', Tahoma, 'Segoe UI', sans-serif;
  overscroll-behavior: none;
}

body {
  background:
    radial-gradient(1200px 600px at 85% -10%, rgba(79, 140, 255, 0.18), transparent 60%),
    radial-gradient(900px 500px at 0% 110%, rgba(122, 167, 255, 0.10), transparent 55%),
    var(--bg);
  height: 100dvh;
  overflow: hidden;
  user-select: none;
}

.app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 780px;
  margin: 0 auto;
  background: var(--bg-2);
  box-shadow: 0 0 80px rgba(0, 0, 0, 0.55);
}

/* ---------- topbar ---------- */
.topbar {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px 10px;
  background: linear-gradient(180deg, rgba(7, 11, 21, 0.92), rgba(7, 11, 21, 0.55) 70%, transparent);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.2px;
}

.brand-mark {
  width: 22px;
  height: 22px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--primary), #9f7bff);
  box-shadow: 0 0 18px rgba(79, 140, 255, 0.6);
  position: relative;
}
.brand-mark::after {
  content: '';
  position: absolute;
  inset: 7px 6px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.9);
  clip-path: polygon(0 20%, 65% 50%, 0 80%, 100% 100%, 100% 0);
}

.conn {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  padding: 6px 11px;
  border-radius: 999px;
}

.conn-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 10px currentColor;
  color: var(--warn);
}
.conn[data-state='on'] .conn-dot { background: var(--success); color: var(--success); }
.conn[data-state='off'] .conn-dot { background: var(--danger); color: var(--danger); }

/* ---------- stage ---------- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(1000px 500px at 50% 35%, rgba(79, 140, 255, 0.10), transparent 65%),
    linear-gradient(180deg, #0a0f1d, #070b15);
}

.remote-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #05070d;
  opacity: 0;
  transition: opacity 0.35s ease;
  z-index: 1;
}
.remote-video.visible { opacity: 1; }

.remote-empty {
  position: absolute;
  inset: 0;
  z-index: 0;
  background:
    radial-gradient(circle at 50% 42%, rgba(122, 167, 255, 0.12), transparent 42%),
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.012) 0 12px, transparent 12px 24px);
}

.peer-chip {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  background: rgba(8, 12, 22, 0.62);
  border: 1px solid var(--border);
  border-radius: 999px;
  backdrop-filter: blur(12px);
  font-size: 13px;
  font-weight: 700;
  max-width: 55%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.peer-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 10px var(--success);
  flex: 0 0 auto;
}

.timer-chip {
  position: absolute;
  top: 14px;
  left: 14px;
  z-index: 10;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(8, 12, 22, 0.62);
  border: 1px solid var(--border);
  backdrop-filter: blur(12px);
  font-size: 13px;
  letter-spacing: 0.5px;
  font-variant-numeric: tabular-nums;
  direction: ltr;
}

.quality {
  position: absolute;
  top: 58px;
  left: 14px;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
  padding: 7px 9px;
  border-radius: 999px;
  background: rgba(8, 12, 22, 0.5);
  border: 1px solid var(--border);
}
.quality span {
  width: 3px;
  border-radius: 2px;
  background: rgba(255, 255, 255, 0.22);
}
.quality span:nth-child(1) { height: 5px; }
.quality span:nth-child(2) { height: 9px; }
.quality span:nth-child(3) { height: 13px; }
.quality[data-q='good'] span:nth-child(-n+2) { background: var(--success); }
.quality[data-q='excellent'] span { background: var(--success); }
.quality[data-q='poor'] span:nth-child(1) { background: var(--warn); }

/* ---------- self view ---------- */
.self-view {
  position: absolute;
  left: 14px;
  bottom: 14px;
  z-index: 9;
  width: 108px;
  height: 150px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5);
  background: #0a0f1a;
  transition: transform 0.25s ease;
}
.self-view video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}
.self-label {
  position: absolute;
  bottom: 6px;
  right: 8px;
  font-size: 10px;
  color: rgba(255, 255, 255, 0.85);
  background: rgba(0, 0, 0, 0.42);
  padding: 2px 6px;
  border-radius: 6px;
}

/* ---------- screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 26px;
  text-align: center;
  background:
    radial-gradient(700px 420px at 50% 20%, rgba(79, 140, 255, 0.10), transparent 60%),
    rgba(7, 11, 21, 0.72);
  backdrop-filter: blur(4px);
  animation: fade-in 0.25s ease;
}
.screen.hidden, .hidden { display: none !important; }

.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 440px;
  animation: rise 0.4s ease;
}
.hero-badge {
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  font-size: 34px;
  border-radius: 26px;
  background: linear-gradient(145deg, rgba(79, 140, 255, 0.22), rgba(159, 123, 255, 0.16));
  border: 1px solid rgba(122, 167, 255, 0.3);
  box-shadow: 0 12px 40px rgba(79, 140, 255, 0.22), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
.hero-badge.warn {
  background: rgba(255, 92, 108, 0.12);
  border-color: rgba(255, 92, 108, 0.3);
  box-shadow: 0 12px 40px rgba(255, 92, 108, 0.14);
}

h1 {
  margin: 6px 0 0;
  font-size: 25px;
  line-height: 1.35;
  letter-spacing: -0.4px;
}
.hero-sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.9;
  max-width: 340px;
}
h2 { margin: 8px 0 0; font-size: 19px; font-weight: 700; }
.muted { color: var(--muted); font-size: 13.5px; margin: 0; line-height: 1.8; }
.hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* ---------- buttons ---------- */
.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 14px;
  padding: 12px 22px;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 700;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease, box-shadow 0.2s ease, opacity 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.btn-primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-color: rgba(255, 255, 255, 0.14);
  box-shadow: 0 12px 30px rgba(47, 107, 224, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.btn-primary:hover { background: linear-gradient(135deg, var(--primary-2), var(--primary)); }
.btn-ghost {
  background: rgba(255, 255, 255, 0.05);
  border-color: var(--border);
  color: var(--muted);
}
.btn-danger {
  background: linear-gradient(135deg, #ff6a79, #e03b4d);
  border-color: rgba(255, 255, 255, 0.14);
}
.btn-xl {
  min-width: 210px;
  padding: 15px 34px;
  font-size: 17px;
  border-radius: 16px;
  margin-top: 10px;
}
.btn-next {
  flex: 1;
  max-width: 210px;
  padding: 13px 20px;
  border-radius: 15px;
  font-size: 15px;
}

/* ---------- spinner / orb ---------- */
.spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.12);
  border-top-color: var(--primary-2);
  animation: spin 0.9s linear infinite;
  margin-bottom: 6px;
}
.orb {
  position: relative;
  width: 110px;
  height: 110px;
  margin-bottom: 8px;
}
.orb::before, .orb::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 1px solid rgba(122, 167, 255, 0.35);
  animation: pulse 2.2s ease-out infinite;
}
.orb::after { animation-delay: 1.1s; }
.orb span {
  position: absolute;
  inset: 34px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #9fc0ff, var(--primary) 55%, #20448f);
  box-shadow: 0 0 40px rgba(79, 140, 255, 0.55);
  animation: breathe 2.2s ease-in-out infinite;
}

/* ---------- call controls ---------- */
.controls {
  position: relative;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px calc(14px + var(--safe-bottom));
  background: linear-gradient(0deg, rgba(7, 11, 21, 0.98), rgba(7, 11, 21, 0.82) 70%, transparent);
}
.controls-side { display: flex; gap: 8px; }

.ctrl {
  width: 46px;
  height: 46px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s, transform 0.12s, border-color 0.2s;
}
.ctrl:active { transform: scale(0.94); }
.ctrl-icon { font-size: 18px; line-height: 1; filter: grayscale(0.15); }
.ctrl.off { background: rgba(255, 92, 108, 0.16); border-color: rgba(255, 92, 108, 0.38); }
.ctrl.off .ctrl-icon { filter: grayscale(0) brightness(0.7); opacity: 0.8; }
.ctrl-danger { background: rgba(255, 92, 108, 0.14); border-color: rgba(255, 92, 108, 0.3); }
.ctrl-danger .ctrl-icon { color: var(--danger); font-weight: 700; }

/* ---------- toast / banner ---------- */
.toast {
  position: absolute;
  z-index: 40;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: calc(100% - 28px);
  padding: 11px 14px;
  border-radius: 13px;
  background: rgba(18, 26, 44, 0.96);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  font-size: 13px;
  line-height: 1.7;
  animation: toast-in 0.25s ease;
}
.toast button {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 2px;
}

.slow-banner {
  position: absolute;
  z-index: 12;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  padding: 9px 15px;
  border-radius: 999px;
  background: rgba(255, 181, 71, 0.14);
  border: 1px solid rgba(255, 181, 71, 0.35);
  color: #ffd58f;
  font-size: 12px;
  white-space: nowrap;
  animation: fade-in 0.3s ease;
}

.tap-play {
  position: absolute;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(5, 8, 15, 0.55);
  backdrop-filter: blur(2px);
}

/* ---------- modal ---------- */
.modal {
  position: fixed;
  z-index: 60;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(3, 6, 12, 0.66);
  backdrop-filter: blur(6px);
  padding: 18px;
  padding-bottom: calc(18px + var(--safe-bottom));
  animation: fade-in 0.2s ease;
}
.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: var(--shadow);
  animation: rise 0.28s ease;
}
.modal-card h3 { margin: 0 0 6px; font-size: 17px; }
.modal-card .muted { margin-bottom: 14px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.045);
  color: var(--text);
  border-radius: 999px;
  padding: 8px 13px;
  font-family: inherit;
  font-size: 12.5px;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s;
}
.chip.selected {
  background: rgba(79, 140, 255, 0.2);
  border-color: rgba(122, 167, 255, 0.65);
  color: #cfe0ff;
}
textarea {
  width: 100%;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 11px 12px;
  outline: none;
  margin-bottom: 14px;
}
textarea:focus { border-color: rgba(122, 167, 255, 0.5); }
.modal-actions { display: flex; gap: 9px; }
.modal-actions .btn { flex: 1; }

/* ---------- animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse {
  0% { transform: scale(0.55); opacity: 0.9; }
  100% { transform: scale(1.25); opacity: 0; }
}
@keyframes breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.08); }
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* ---------- desktop ---------- */
@media (min-width: 780px) {
  .app {
    border-left: 1px solid rgba(255, 255, 255, 0.06);
    border-right: 1px solid rgba(255, 255, 255, 0.06);
  }
  .self-view { width: 132px; height: 184px; }
}
