/* Self-hosted variable font (Vazirmatn v33.0.3, OFL); Google Fonts is unreliable from Iran. */
@font-face {
  font-family: Vazirmatn;
  src: url('/static/fonts/Vazirmatn-wght.woff2') format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #222631;
  --border: #2c3140;
  --text: #e8eaf0;
  --muted: #9aa1b2;
  --accent: #3b82f6;
  --accent-2: #2563eb;
  --danger: #ef4444;
  --danger-2: #dc2626;
  --ok: #22c55e;
  --radius: 14px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: Vazirmatn, Tahoma, 'Segoe UI', system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

/* ---------- setup / message cards ---------- */
.center {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}
.card {
  width: 100%;
  max-width: 420px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, .35);
}
.card h1 { margin: 0 0 4px; font-size: 1.35rem; }
.card p.sub { margin: 0 0 20px; color: var(--muted); font-size: .95rem; }
.card.message { text-align: center; }
.card.message .icon { font-size: 2.4rem; line-height: 1; margin-bottom: 8px; color: var(--muted); }

label { display: block; font-size: .9rem; color: var(--muted); margin: 14px 0 6px; }
input[type=text], input[type=password] {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font: inherit;
  outline: none;
}
input:focus { border-color: var(--accent); }
input.ltr { direction: ltr; text-align: left; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 18px;
  border: 0;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  transition: background .15s, opacity .15s;
}
.btn:hover { background: #2b303d; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--accent); }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { background: var(--danger-2); }
.btn.block { width: 100%; margin-top: 18px; }
.btn + .btn.block { margin-top: 10px; }

.error { color: #fca5a5; font-size: .92rem; margin-top: 12px; min-height: 1em; }
.hint { color: var(--muted); font-size: .85rem; margin-top: 10px; }

/* ---------- call view ---------- */
.call {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background: #000;
}
.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}
.invite {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1 1 320px;
  min-width: 0;
}
.invite input { padding: 7px 10px; font-size: .85rem; min-width: 0; }
.invite .btn { padding: 7px 12px; font-size: .85rem; white-space: nowrap; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  padding: 5px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font: inherit;
  font-size: .82rem;
  cursor: pointer;
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chip.active { background: var(--accent); border-color: var(--accent); }

.banner {
  background: #78350f;
  color: #fde68a;
  text-align: center;
  padding: 6px 12px;
  font-size: .9rem;
}

.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  padding: 8px;
  overflow: hidden;
}
.stage.grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(var(--cols, 1), minmax(0, 1fr));
  grid-auto-rows: minmax(0, 1fr);
}

.tile {
  position: relative;
  background: #11141a;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  min-width: 0;
  min-height: 0;
}
.tile video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #000;
}
.tile.self video { transform: scaleX(-1); }
.tile .avatar {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  background: #11141a;
}
.tile .avatar span {
  width: 84px;
  height: 84px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  font-size: 2.2rem;
  font-weight: 600;
}
.tile.no-video .avatar { display: grid; }
.tile .label {
  position: absolute;
  bottom: 8px;
  right: 8px;
  max-width: calc(100% - 16px);
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .55);
  font-size: .85rem;
  white-space: nowrap;
  overflow: hidden;
}
.tile .label .name { overflow: hidden; text-overflow: ellipsis; }
.tile .label .badge { color: #93c5fd; font-size: .75rem; }
.tile .label svg { width: 15px; height: 15px; flex: none; color: #fca5a5; display: none; }
.tile.muted .label svg { display: block; }
.tile .status {
  position: absolute;
  top: 8px;
  right: 8px;
  padding: 2px 10px;
  border-radius: 8px;
  background: rgba(0, 0, 0, .6);
  font-size: .8rem;
  color: #fde68a;
}

/* focus (one participant fullscreen, others as thumbnails) */
.stage.focus .tile.focused {
  position: absolute;
  inset: 8px;
  border-radius: 12px;
}
.stage.focus .tile.focused video { object-fit: contain; }
.stage.focus .tile:not(.focused) {
  position: absolute;
  z-index: 2;
  bottom: 16px;
  left: calc(16px + var(--i, 0) * (min(22vw, 200px) + 8px));
  width: min(22vw, 200px);
  aspect-ratio: 16 / 10;
  border: 2px solid rgba(255, 255, 255, .2);
  box-shadow: 0 6px 20px rgba(0, 0, 0, .5);
}
.stage.focus .tile:not(.focused) .avatar span { width: 40px; height: 40px; font-size: 1.1rem; }
.stage.focus .tile:not(.focused) .label { font-size: .72rem; padding: 1px 6px; bottom: 4px; right: 4px; }
.stage.focus .tile:not(.focused) .status { display: none; }

.controls {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel);
  border-top: 1px solid var(--border);
}
.ctrl {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: 0;
  display: grid;
  place-items: center;
  background: var(--panel-2);
  color: var(--text);
  cursor: pointer;
  transition: background .15s;
}
.ctrl:hover { background: #2f3542; }
.ctrl svg { width: 24px; height: 24px; }
.ctrl.off { background: #fff; color: #111; }
.ctrl.danger { background: var(--danger); }
.ctrl.danger:hover { background: var(--danger-2); }
.ctrl:disabled { opacity: .4; cursor: not-allowed; }
.ctrl.wide {
  width: auto;
  border-radius: 26px;
  padding: 0 18px;
  display: inline-flex;
  gap: 6px;
  font: inherit;
  font-size: .9rem;
}

.toast {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--panel-2);
  border: 1px solid var(--border);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: .9rem;
  z-index: 10;
}

@media (max-width: 600px) {
  .ctrl { width: 46px; height: 46px; }
  .ctrl.wide { padding: 0 12px; font-size: .82rem; }
  .ctrl .txt { display: none; }
  .stage.focus .tile:not(.focused) {
    width: 28vw;
    aspect-ratio: 3 / 4;
    left: calc(10px + var(--i, 0) * (28vw + 6px));
    bottom: 10px;
  }
}
