@font-face{font-family:"Yekan Bakh";src:url("/fonts/YekanBakh-Thin.woff2") format("woff2");font-weight:100;font-style:normal;font-display:swap}
@font-face{font-family:"Yekan Bakh";src:url("/fonts/YekanBakh-Light.woff2") format("woff2");font-weight:300;font-style:normal;font-display:swap}
@font-face{font-family:"Yekan Bakh";src:url("/fonts/YekanBakh-Regular.woff2") format("woff2");font-weight:400;font-style:normal;font-display:swap}
@font-face{font-family:"Yekan Bakh";src:url("/fonts/YekanBakh-SemiBold.woff2") format("woff2");font-weight:500;font-style:normal;font-display:swap}
@font-face{font-family:"Yekan Bakh";src:url("/fonts/YekanBakh-SemiBold.woff2") format("woff2");font-weight:600;font-style:normal;font-display:swap}
@font-face{font-family:"Yekan Bakh";src:url("/fonts/YekanBakh-Bold.woff2") format("woff2");font-weight:700;font-style:normal;font-display:swap}
@font-face{font-family:"Yekan Bakh";src:url("/fonts/YekanBakh-ExtraBold.woff2") format("woff2");font-weight:800;font-style:normal;font-display:swap}
@font-face{font-family:"Yekan Bakh";src:url("/fonts/YekanBakh-Black.woff2") format("woff2");font-weight:900;font-style:normal;font-display:swap}

:root {
  --font: "Yekan Bakh", Tahoma, "Segoe UI", sans-serif;
  --brand: #2F6BFF;
  --brand-ink: #1A4FD6;
  --brand-soft: rgba(47,107,255,.12);
  --brand-line: rgba(47,107,255,.28);
  --bg: #F4F6FA;
  --surface: #FFFFFF;
  --surface-2: #F7F9FC;
  --ink: #0B1220;
  --ink-2: #5B6B82;
  --mute: #7A8799;
  --line: rgba(11,18,32,.08);
  --shadow: 0 8px 24px rgba(15,35,80,.06), 0 1px 2px rgba(15,35,80,.04);
  --radius: 14px;
  --ok: #059669;
  --danger: #DC2626;
  --danger-soft: rgba(220,38,38,.12);
  --topbar-h: 56px;
  --controls-h: 72px;
  --side-w: 300px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden], .is-hidden { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  font-family: var(--font) !important;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
html.room-mode, html.room-mode body {
  overflow: hidden;
  height: 100%;
  overscroll-behavior: none;
}
button, input, textarea, select,
h1, h2, h3, h4, p, span, label, strong, li, a {
  font-family: var(--font) !important;
}
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-ink); }

.shell {
  max-width: 720px;
  margin: 0 auto;
  padding: 28px 16px 48px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
}
.brand-logo {
  width: 48px;
  height: 48px;
  object-fit: contain;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 4px;
  flex-shrink: 0;
}
.brand h1 {
  margin: 0;
  font-size: 1.2rem;
  font-weight: 800;
  color: var(--ink);
  letter-spacing: -.02em;
}
.brand p {
  margin: 2px 0 0;
  color: var(--mute);
  font-size: .8rem;
  font-weight: 500;
}

.hero-card, .lobby, .panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.hero-card { padding: 24px 20px; }
.hero-card h2 {
  margin: 0 0 8px;
  font-size: clamp(1.2rem, 2.5vw, 1.5rem);
  font-weight: 800;
}
.hero-card .lead {
  margin: 0 0 18px;
  color: var(--ink-2);
  line-height: 1.8;
  font-size: .9rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}
label.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 160px;
  min-width: 0;
}
label.field span {
  font-size: .78rem;
  color: var(--mute);
  font-weight: 700;
}
input {
  width: 100%;
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
  outline: none;
  font-size: 16px; /* avoid iOS zoom */
  transition: border-color .15s, box-shadow .15s;
}
input:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-soft);
  background: var(--surface);
}
button {
  cursor: pointer;
  padding: 12px 18px;
  font-weight: 700;
  font-size: .9rem;
  border-radius: 12px;
  border: 0;
  background: var(--brand);
  color: #fff;
  transition: filter .15s, background .15s;
}
button:hover { filter: brightness(1.05); }
button.ghost {
  background: var(--surface-2);
  color: var(--ink);
  border: 1px solid var(--line);
}
button.ghost:hover { background: #eef2f7; filter: none; }
button:disabled { opacity: .55; cursor: wait; }

.err {
  color: var(--danger);
  font-size: .8rem;
  margin-top: 10px;
  min-height: 1.2em;
  font-weight: 600;
}

/* —— Lobby —— */
.lobby-wrap {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background:
    radial-gradient(600px 280px at 100% 0%, rgba(47,107,255,.10), transparent 60%),
    radial-gradient(500px 240px at 0% 100%, rgba(47,107,255,.06), transparent 55%),
    var(--bg);
}
.lobby {
  width: min(420px, 100%);
  padding: 22px 18px;
  margin: auto;
}
.lobby .brand { margin-bottom: 16px; }
.lobby h2 { margin: 0 0 6px; font-size: 1.1rem; font-weight: 800; }
.lobby #lobbyMeta,
.lobby > p {
  margin: 0 0 14px;
  color: var(--ink-2);
  font-size: .84rem;
  line-height: 1.7;
}
.lobby .form-row {
  flex-direction: column;
}
.lobby .form-row button {
  width: 100%;
}
.lobby label.field {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}
.lobby label.field span {
  flex: 0 0 auto;
  white-space: nowrap;
  margin: 0;
}
.lobby label.field input {
  flex: 1 1 auto;
  min-width: 0;
}

/* —— Room app: locked to viewport —— */
.room-app {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-rows: var(--topbar-h) minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: #0B1520;
}
.room-app[hidden] { display: none !important; }

.topbar {
  height: var(--topbar-h);
  min-height: var(--topbar-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: #111C28;
  overflow: hidden;
  color: #E8EEF5;
}
.topbar .brand-mini {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  flex: 1;
}
.topbar .brand-mini img {
  width: 32px;
  height: 32px;
  object-fit: contain;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,.1);
  background: #0B1520;
  padding: 2px;
  flex-shrink: 0;
}
.topbar .meta {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
}
.topbar .meta strong {
  font-size: .9rem;
  font-weight: 800;
  color: #F3F7FB;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .meta span {
  font-size: .7rem;
  color: #8FA0B3;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar .actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}
.topbar .actions button {
  padding: 7px 10px;
  font-size: .75rem;
  white-space: nowrap;
  background: rgba(255,255,255,.06);
  color: #E8EEF5;
  border: 1px solid rgba(255,255,255,.1);
}
.topbar .actions button:hover { background: rgba(255,255,255,.1); filter: none; }

.stage {
  min-height: 0;
  min-width: 0;
  display: grid;
  direction: ltr; /* ویدیو چپ، سایدبار راست — مستقل از RTL صفحه */
  grid-template-columns: minmax(0, 1fr) var(--side-w);
  grid-template-areas: "videos side";
  overflow: hidden;
  background: #0B1520;
}
.stage > .videos {
  grid-area: videos;
  direction: rtl;
  min-height: 0;
  min-width: 0;
}
.stage > .side {
  grid-area: side;
  direction: rtl;
  min-height: 0;
  min-width: 0;
}
.stage > .side-backdrop {
  grid-area: videos;
  display: none;
}

.videos {
  min-height: 0;
  min-width: 0;
  display: grid;
  gap: 12px;
  padding: 12px;
  overflow: hidden;
  align-content: stretch;
  justify-content: stretch;
  grid-template-columns: 1fr;
  grid-auto-rows: minmax(0, 1fr);
}
.videos[data-count="2"],
.videos[data-count="3"],
.videos[data-count="4"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.videos[data-count="5"],
.videos[data-count="6"],
.videos[data-count="7"],
.videos[data-count="8"],
.videos[data-count="9"] {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}
.videos[data-count="10"],
.videos[data-count="11"],
.videos[data-count="12"],
.videos[data-count="13"],
.videos[data-count="14"],
.videos[data-count="15"],
.videos[data-count="16"] {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}
.videos[data-count="1"] {
  grid-template-columns: 1fr;
  max-width: 720px;
  margin: 0 auto;
  width: 100%;
}

/* Participant tile — avatar card style */
.tile {
  --tile-accent: #4FC3F7;
  position: relative;
  min-height: 0;
  min-width: 0;
  border-radius: 22px;
  overflow: hidden;
  border: 2px solid var(--tile-accent);
  background:
    radial-gradient(ellipse 70% 60% at 50% 42%, #1a3c48 0%, #122833 45%, #0d1b2a 100%);
  box-shadow: 0 10px 28px rgba(0,0,0,.28);
  display: grid;
  place-items: center;
}
.tile audio {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}
.tile video {
  position: absolute;
  inset: 0;
  z-index: 2;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  background: #0d1b2a;
  display: block;
  opacity: 0;
  pointer-events: none;
}
.tile:not(.has-video) video {
  opacity: 0 !important;
  visibility: hidden !important;
}
.tile.has-video video {
  opacity: 1 !important;
  visibility: visible !important;
}
.tile.local.has-video:not(.screen-share) video { transform: scaleX(-1); }
.tile.screen-share video {
  object-fit: contain !important;
  background: #0b1220;
  transform: none !important;
}

.tile .avatar-wrap {
  position: relative;
  z-index: 1;
  width: min(42%, 168px);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  transition: opacity .2s ease, transform .2s ease;
}
.tile.has-video .avatar-wrap {
  opacity: 0;
  visibility: hidden;
  transform: scale(.92);
  pointer-events: none;
}
.tile .avatar-ring,
.tile .avatar-ring-2 {
  position: absolute;
  inset: -14%;
  border-radius: 50%;
  border: 2px solid rgba(79,195,247,.22);
  opacity: 0;
  transform: scale(.92);
  transition: opacity .2s ease, transform .2s ease, border-color .2s ease;
}
.tile .avatar-ring-2 {
  inset: -28%;
  border-color: rgba(79,195,247,.12);
}
.tile.speaking .avatar-ring,
.tile.speaking .avatar-ring-2 {
  opacity: 1;
  transform: scale(1);
  animation: speakPulse 1.4s ease-out infinite;
}
.tile.speaking .avatar-ring-2 { animation-delay: .18s; }
.tile.speaking { border-color: #7DD3FC; box-shadow: 0 0 0 1px rgba(79,195,247,.25), 0 12px 32px rgba(0,0,0,.35); }

@keyframes speakPulse {
  0% { opacity: .55; transform: scale(.94); }
  70% { opacity: 0; transform: scale(1.08); }
  100% { opacity: 0; transform: scale(1.08); }
}

.tile .avatar {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  border: 2px solid var(--tile-accent);
  background: #243447;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: clamp(1.8rem, 6vw, 3.2rem);
  font-weight: 800;
  letter-spacing: .02em;
  user-select: none;
}

.tile .tag {
  position: absolute;
  right: 14px;
  bottom: 14px;
  left: auto;
  z-index: 3;
  max-width: calc(100% - 28px);
  background: transparent;
  color: #fff;
  padding: 0;
  border-radius: 0;
  font-size: clamp(.85rem, 1.6vw, 1rem);
  font-weight: 600;
  text-shadow: 0 1px 3px rgba(0,0,0,.55);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tile.has-video .tag {
  background: rgba(11,18,32,.72);
  padding: 5px 10px;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 700;
  right: 10px;
  left: auto;
  bottom: 10px;
}

.side {
  border-left: 1px solid rgba(255,255,255,.08);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) minmax(120px, .9fr);
  background: #111C28;
  color: #E8EEF5;
  overflow: hidden;
}
.side h3 {
  margin: 0;
  padding: 10px 12px;
  font-size: .8rem;
  font-weight: 800;
  border-bottom: 1px solid rgba(255,255,255,.08);
  color: #9BB0C4;
  background: #0E1824;
}
.peers {
  list-style: none;
  margin: 0;
  padding: 6px;
  overflow: auto;
  min-height: 0;
  -webkit-overflow-scrolling: touch;
}
.peers li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: .8rem;
  font-weight: 600;
  color: #E8EEF5;
}
.peers li:hover { background: rgba(255,255,255,.05); }
.peers li button {
  padding: 4px 8px !important;
  font-size: .68rem !important;
}

.chat {
  min-height: 0;
  border-top: 1px solid rgba(255,255,255,.08);
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  overflow: hidden;
}
.chat-log {
  min-height: 0;
  overflow: auto;
  padding: 8px 10px;
  font-size: .76rem;
  color: #A8B8C9;
  -webkit-overflow-scrolling: touch;
}
.chat-log .row { margin-bottom: 6px; line-height: 1.5; word-break: break-word; }
.chat-log b { color: #7DD3FC; font-weight: 800; }
.chat-form {
  display: flex;
  gap: 6px;
  padding: 8px;
  border-top: 1px solid rgba(255,255,255,.08);
  background: #0E1824;
}
.chat-form input {
  flex: 1;
  min-width: 0;
  padding: 8px 10px;
  font-size: 16px;
  background: #162232;
  color: #E8EEF5;
  border-color: rgba(255,255,255,.1);
}
.chat-form button { padding: 8px 12px; flex-shrink: 0; }

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  flex-wrap: nowrap;
  gap: 8px;
  padding: 10px 12px calc(10px + var(--safe-b));
  border-top: 1px solid rgba(255,255,255,.08);
  background: #111C28;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.controls button.ctrl {
  flex: 0 0 auto;
  position: relative;
  width: 48px;
  height: 48px;
  min-width: 48px;
  padding: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,.06);
  color: #E8EEF5;
  border: 1px solid rgba(255,255,255,.12);
  font-size: 0;
  line-height: 0;
}
.controls button.ctrl svg {
  width: 22px;
  height: 22px;
  display: block;
  pointer-events: none;
}
.controls button.ctrl:hover { filter: none; background: rgba(255,255,255,.12); }
.controls button.ctrl.on {
  background: rgba(5,150,105,.2);
  color: #34D399;
  border-color: rgba(52,211,153,.32);
}
.controls button.ctrl.off {
  background: rgba(239,68,68,.16);
  color: #F87171;
  border-color: rgba(248,113,113,.28);
}
.controls button.ctrl.off::after {
  content: "";
  position: absolute;
  width: 26px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  transform: rotate(-32deg);
  box-shadow: 0 0 0 1px rgba(17,28,40,.35);
}
.controls button.ctrl.leave {
  background: #DC2626;
  color: #fff;
  border-color: transparent;
  width: 52px;
  height: 52px;
}
.controls button.ctrl.leave:hover { background: #EF4444; }
.controls button.ctrl.leave svg { width: 24px; height: 24px; }
.controls button.ctrl.on.screen-on,
.controls button#btnScreen.on {
  background: rgba(37,99,235,.2);
  color: #93C5FD;
  border-color: rgba(147,197,253,.35);
}

.side-backdrop {
  display: none;
}

.toast {
  position: fixed;
  bottom: calc(88px + var(--safe-b));
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100% - 24px);
  background: var(--ink);
  color: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  display: none;
  z-index: 50;
  font-size: .82rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  text-align: center;
}
.toast.show { display: block; }

/* —— Tablet / mobile —— */
@media (max-width: 900px) {
  :root { --side-w: min(86vw, 320px); }

  .stage {
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "videos";
  }

  .stage > .side {
    position: fixed;
    top: var(--topbar-h);
    bottom: calc(var(--controls-h) + var(--safe-b));
    right: 0;
    left: auto;
    width: var(--side-w);
    z-index: 30;
    border-left: 1px solid rgba(255,255,255,.08);
    box-shadow: 0 8px 24px rgba(0,0,0,.35);
    transform: translateX(105%);
    transition: transform .2s ease;
  }
  .room-app.side-open .stage > .side {
    transform: translateX(0);
  }

  .stage > .side-backdrop {
    display: block;
    position: fixed;
    inset: var(--topbar-h) 0 calc(var(--controls-h) + var(--safe-b));
    background: rgba(11,18,32,.35);
    z-index: 25;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s ease;
  }
  .room-app.side-open .stage > .side-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  .videos[data-count="2"],
  .videos[data-count="3"],
  .videos[data-count="4"],
  .videos[data-count="5"],
  .videos[data-count="6"],
  .videos[data-count="7"],
  .videos[data-count="8"],
  .videos[data-count="9"],
  .videos[data-count="10"],
  .videos[data-count="11"],
  .videos[data-count="12"],
  .videos[data-count="13"],
  .videos[data-count="14"],
  .videos[data-count="15"],
  .videos[data-count="16"] {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 480px) {
  .shell { padding: 20px 14px 36px; }
  .topbar .meta span { display: none; }
  .controls button.ctrl { width: 44px; height: 44px; min-width: 44px; }
  .controls button.ctrl.leave { width: 48px; height: 48px; }
  .videos { gap: 6px; padding: 6px; }
}

.tile.screen-share {
  outline: 2px solid rgba(59, 130, 246, 0.55);
}
