/* Aloqa — qorong'i, Discord uslubidagi mavzu. Video (.viewer) ustida filtr/transform ishlatilmaydi. */

:root {
  color-scheme: dark;
  --bg: #1e1f22;
  --panel: #2b2d31;
  --panel-2: #383a40;
  --panel-3: #43454c;
  --line: #3f4147;
  --text: #f2f3f5;
  --muted: #949ba4;
  --accent: #5865f2;
  --accent-2: #7983f5;
  --accent-hover: #4752c4;
  --ok: #23a55a;
  --warn: #f0b232;
  --bad: #f23f42;
  --radius: 16px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, .28);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, .40);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, .50);
  --ease: cubic-bezier(.2, .7, .3, 1);
}

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

html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.2; }
h1 { font-size: clamp(1.5rem, 4.5vw, 2rem); font-weight: 800; letter-spacing: -.01em; }
h2 { font-size: 1.25rem; font-weight: 700; }
h3 { font-size: .75rem; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--muted); margin-top: 1.25rem; }
p { margin: 0 0 .9rem; }
a { color: var(--accent-2); }
a:hover { color: var(--accent); }

.muted { color: var(--muted); }
.small { font-size: .85rem; }
.spacer { flex: 1; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.sr-only { position: absolute; left: -9999px; top: 0; width: 1px; height: 1px; opacity: 0; }

.icon { width: 1.25rem; height: 1.25rem; flex: none; display: block; }

/* Nozik qorong'i skroll (Discord uslubi) */
* { scrollbar-width: thin; scrollbar-color: var(--panel-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--panel-3); border-radius: 999px; border: 2px solid transparent; background-clip: padding-box; }
*::-webkit-scrollbar-thumb:hover { background: #55585f; background-clip: padding-box; }

/* ---------- Tugmalar va maydonlar ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  min-height: 44px; padding: 0 1.1rem;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 12px;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--panel-3); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: default; transform: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.large { min-height: 52px; padding: 0 1.5rem; font-size: 1.05rem; border-radius: 14px; }
.btn.small { min-height: 34px; padding: 0 .8rem; font-size: .9rem; }

input[type="text"], input[type="password"], select {
  width: 100%; min-height: 44px; padding: .6rem .8rem;
  background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px;
  font: inherit;
  transition: border-color .15s var(--ease), background .15s var(--ease);
}
input[type="text"]:hover, input[type="password"]:hover, select:hover { border-color: #55585f; }
input[type="text"]:focus, input[type="password"]:focus, select:focus,
.btn:focus-visible, .icon-btn:focus-visible, .round-btn:focus-visible, .pill-btn:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
select { appearance: auto; }
.range {
  width: 100%; accent-color: var(--accent);
  transition: filter .15s var(--ease);
}
.range:hover { filter: brightness(1.15); }
.field-label { display: block; margin: .9rem 0 .35rem; font-size: .8rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.check { display: flex; gap: .6rem; align-items: center; margin: .9rem 0 0; cursor: pointer; }
.check input { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

.link-btn { background: none; border: 0; padding: 0; color: var(--muted); font: inherit; text-decoration: underline; cursor: pointer; }
.link-btn:hover { color: var(--text); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; padding: 0;
  background: transparent; color: var(--muted);
  border: 0; border-radius: 10px; cursor: pointer;
  transition: background .15s var(--ease), color .15s var(--ease), transform .1s var(--ease);
}
.icon-btn:hover { background: var(--panel-3); color: var(--text); }
.icon-btn:active { transform: scale(.92); }
.icon-btn.small { width: 30px; height: 30px; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.5rem;
  box-shadow: var(--shadow-md);
}

.notice { padding: .7rem .9rem; border-radius: 10px; background: var(--panel-2); border: 1px solid var(--line); font-size: .92rem; }
.notice.ok { border-color: #1a6d42; background: #10291b; color: #9bf0c2; }
.notice.warn { border-color: #8a5b10; background: #2b2110; color: #ffd89c; }
.notice.bad { border-color: #8f2d33; background: #2c1517; color: #ffbcc0; }
.form-error { color: #ff99a0; font-size: .92rem; margin: .5rem 0; }

.copy-row { display: flex; gap: 8px; }
.copy-row input { flex: 1; min-width: 0; }

/* ---------- Bosh sahifa ---------- */

.page-home { background: radial-gradient(ellipse 900px 500px at 50% -10%, rgba(88, 101, 242, .18), transparent 60%), var(--bg); min-height: 100vh; }
.page-home .home { max-width: 560px; margin: 0 auto; padding: 24px 16px 40px; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.3rem; margin-bottom: 1.2rem; letter-spacing: -.01em; }
.brand img { border-radius: 9px; box-shadow: var(--shadow-sm); }
.hero .btn.large { width: 100%; margin-top: .4rem; }
.created { margin-top: 1.2rem; padding-top: 1rem; border-top: 1px solid var(--line); animation: pop-in .25s var(--ease); }
.created .btn.large { width: 100%; margin-top: 1rem; }
.join-by-link { margin-top: 1.4rem; color: var(--muted); }
.join-by-link summary { cursor: pointer; }
.join-by-link summary:hover { color: var(--text); }
.join-by-link form { margin-top: .7rem; }
#footer { margin-top: 1.2rem; text-align: center; }

/* ---------- Parol oynasi ---------- */

.overlay {
  position: fixed; inset: 0; z-index: 100;
  display: grid; place-items: center; padding: 16px;
  background: rgba(5, 6, 8, .85);
  backdrop-filter: blur(3px);
  animation: fade-in .18s var(--ease);
}
.login-card { width: min(100%, 380px); animation: pop-in .22s var(--ease); }
.login-card input { margin: .4rem 0 .6rem; }
.login-card .btn { width: 100%; }

/* ---------- Xonaga kirish / xabar sahifasi ---------- */

.gate { min-height: 100dvh; display: grid; place-items: center; padding: 16px; background: radial-gradient(ellipse 900px 500px at 50% -10%, rgba(88, 101, 242, .16), transparent 60%), var(--bg); }
.gate-card { width: min(100%, 440px); animation: pop-in .22s var(--ease); }
.gate-card .btn.large { width: 100%; margin: 1rem 0; }
.gate-card .brand { margin-bottom: .8rem; }

/* ---------- Qo'ng'iroq sahifasi ---------- */

.page-room { height: 100vh; height: 100dvh; overflow: hidden; }
.app {
  height: 100vh; height: 100dvh;
  display: flex; flex-direction: column;
}

.topbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}
.small-brand { margin: 0; font-size: 1.05rem; font-weight: 800; }
.topbar-actions { margin-left: auto; display: flex; gap: 4px; }

.status {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .3rem .75rem; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line);
  font-size: .88rem; min-width: 0;
  transition: background .2s var(--ease), border-color .2s var(--ease);
}
.status .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; transition: background .2s var(--ease); }
.status.wait .dot { animation: pulse-dot 1.4s ease-in-out infinite; }
.status.ok .dot { background: var(--ok); box-shadow: 0 0 0 3px rgba(35, 165, 90, .22); }
.status.warn .dot { background: var(--warn); animation: pulse-dot 1.1s ease-in-out infinite; }
.status.bad .dot { background: var(--bad); animation: pulse-dot .9s ease-in-out infinite; }
#status-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.banner {
  padding: .55rem 1rem; text-align: center; font-size: .92rem;
  background: #2b2110; color: #ffd89c; border-bottom: 1px solid #8a5b10;
  animation: slide-down .2s var(--ease);
}
.banner.warn { display: flex; gap: 12px; align-items: center; justify-content: center; flex-wrap: wrap; }

.stage {
  position: relative; flex: 1 1 0; min-height: 0;
  display: flex; flex-direction: column; justify-content: center; align-items: center;
  gap: 12px; padding: 12px; overflow: auto;
}
.stage.has-screen { justify-content: flex-start; align-items: stretch; overflow: hidden; }

/* Do'st ekrani */
.viewer {
  position: relative; flex: 1 1 0; min-height: 0;
  background: #000; border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow-lg);
  animation: pop-in .22s var(--ease);
}
.viewer video {
  display: block; width: 100%; height: 100%;
  object-fit: contain; background: #000;
}
.viewer:fullscreen { border-radius: 0; }
.viewer:-webkit-full-screen { border-radius: 0; }
.viewer-label {
  position: absolute; left: 10px; top: 10px;
  padding: .25rem .65rem; border-radius: 8px;
  background: rgba(0, 0, 0, .55); backdrop-filter: blur(6px);
  font-size: .8rem; font-weight: 600; pointer-events: none;
  transition: opacity .25s var(--ease);
}
.viewer-stall {
  position: absolute; left: 50%; top: 12px; margin-left: -110px; width: 220px; text-align: center;
  padding: .35rem .6rem; border-radius: 8px;
  background: rgba(0, 0, 0, .6); backdrop-filter: blur(6px);
  color: var(--warn); font-size: .85rem; font-weight: 600; pointer-events: none;
  animation: fade-in .2s var(--ease), pulse-text 1.6s ease-in-out infinite;
}
.viewer-bar {
  position: absolute; left: 0; right: 0; bottom: 0;
  display: flex; align-items: center; gap: 8px; padding: 8px 12px;
  background: linear-gradient(to top, rgba(0, 0, 0, .65), transparent);
  transition: opacity .25s var(--ease);
}
.viewer-bar .range { width: 120px; }
.viewer.idle .viewer-bar, .viewer.idle .viewer-label { opacity: 0; pointer-events: none; }
.viewer.fs.idle { cursor: none; }

/* Ishtirokchilar */
.tiles { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; width: 100%; }
.tile {
  position: relative; display: flex; align-items: center; gap: 14px;
  flex: 1 1 260px; max-width: 340px; min-width: 0;
  padding: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: opacity .2s var(--ease), border-color .2s var(--ease), box-shadow .2s var(--ease);
}
.tile.offline { opacity: .55; }
.tile.speaking { border-color: var(--ok); box-shadow: 0 0 0 2px rgba(35, 165, 90, .35), 0 0 18px rgba(35, 165, 90, .25); }
.tile.speaking .avatar { background: #0f3d26; color: var(--ok); box-shadow: 0 0 0 3px rgba(35, 165, 90, .3); }
.avatar {
  flex: none; width: 64px; height: 64px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(145deg, var(--panel-3), var(--panel-2));
  color: var(--accent-2);
  font-size: 1.6rem; font-weight: 700;
  transition: background .2s var(--ease), box-shadow .2s var(--ease);
}
.tile-info { min-width: 0; flex: 1; }
.tile-name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tag { font-size: .68rem; font-weight: 600; color: var(--muted); border: 1px solid var(--line); border-radius: 6px; padding: 0 .35rem; margin-left: .25rem; vertical-align: middle; }
.tile-meta { color: var(--muted); font-size: .85rem; min-height: 1.2em; }
.tile-mic { color: var(--ok); transition: color .15s var(--ease); }
.tile.muted .tile-mic { color: var(--bad); }
.tile.offline .tile-mic { visibility: hidden; }
.self-preview {
  position: absolute; right: 8px; bottom: 8px; width: 120px; aspect-ratio: 16 / 9;
  object-fit: contain; background: #000; border-radius: 8px; border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}
.stage.has-screen .tiles { flex: 0 0 auto; flex-wrap: nowrap; justify-content: center; }
.stage.has-screen .tile { flex: 0 1 260px; padding: 8px 12px; gap: 10px; }
.stage.has-screen .avatar { width: 36px; height: 36px; font-size: 1rem; }
.stage.has-screen .tile-meta, .stage.has-screen .tag { display: none; }
.stage.has-screen .waiting { display: none; }

.waiting { max-width: 440px; text-align: center; }
#mobile-note { max-width: 440px; text-align: center; }

/* Statistika paneli */
.stats {
  position: absolute; left: 12px; top: 12px; z-index: 10;
  width: 320px; max-height: calc(100% - 24px); overflow: auto;
  padding: 12px 14px;
  background: rgba(30, 31, 34, .96); backdrop-filter: blur(8px);
  border: 1px solid var(--line); border-radius: 12px;
  font-size: .85rem;
  box-shadow: var(--shadow-lg);
  animation: pop-in .18s var(--ease);
}
.stats-head { display: flex; justify-content: space-between; align-items: center; }
.stats h3 { margin: .9rem 0 .3rem; font-size: .7rem; }
.stats h3 small { text-transform: none; letter-spacing: 0; font-weight: 400; }
.stats-grid { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0; }
.stats-grid dt { color: var(--muted); }
.stats-grid dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.v.ok { color: var(--ok); }
.v.warn { color: var(--warn); }
.v.bad { color: var(--bad); }

/* Pastki boshqaruv */
.controls {
  display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 10px;
  padding: 12px; padding-bottom: calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--panel);
}
.round-btn, .pill-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  height: 48px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
  font: inherit; font-weight: 600; cursor: pointer;
  transition: background .15s var(--ease), border-color .15s var(--ease), color .15s var(--ease), transform .1s var(--ease);
}
.round-btn { width: 48px; border-radius: 50%; padding: 0; }
.pill-btn { padding: 0 1.1rem; border-radius: 24px; }
.round-btn:hover, .pill-btn:hover { background: var(--panel-3); }
.round-btn:active, .pill-btn:active { transform: scale(.94); }
.round-btn.off { background: rgba(242, 63, 66, .16); border-color: rgba(242, 63, 66, .5); color: #ff9499; }
.round-btn.off:hover { background: rgba(242, 63, 66, .24); }
.pill-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.pill-btn.active:hover { background: var(--accent-hover); }
.pill-btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.pill-btn.danger:hover { background: #d8343a; }

/* Sozlamalar */
.sheet {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 30;
  width: min(100%, 380px);
  display: flex; flex-direction: column;
  background: var(--panel); border-left: 1px solid var(--line);
  box-shadow: var(--shadow-lg);
  animation: slide-in-right .22s var(--ease);
}
.sheet-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; padding-top: calc(10px + env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
}
.sheet-body { padding: 4px 16px 24px; overflow: auto; }
.sheet-body h3:first-child { margin-top: .6rem; }

/* Xabarlar (toast) */
#toasts {
  position: fixed; left: 50%; bottom: calc(132px + env(safe-area-inset-bottom)); z-index: 60;
  width: min(92vw, 460px); margin-left: calc(min(92vw, 460px) / -2);
  display: flex; flex-direction: column; gap: 8px; pointer-events: none;
}
.toast {
  pointer-events: auto; cursor: pointer;
  padding: .7rem .9rem; border-radius: 10px;
  background: var(--panel-2); border: 1px solid var(--line); border-left: 4px solid var(--accent);
  box-shadow: var(--shadow-md); font-size: .92rem;
  animation: toast-in .22s var(--ease);
}
.toast.ok { border-left-color: var(--ok); }
.toast.bad { border-left-color: var(--bad); }

/* ---------- Animatsiyalar ---------- */

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(6px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes slide-down { from { opacity: 0; transform: translateY(-100%); } to { opacity: 1; transform: none; } }
@keyframes slide-in-right { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
@keyframes pulse-dot { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
@keyframes pulse-text { 0%, 100% { opacity: 1; } 50% { opacity: .55; } }

/* Tugma bosilganda chiqadigan radiial "ping" (mikrofon/ulashish) */
@keyframes ring-pulse {
  0% { box-shadow: 0 0 0 0 rgba(88, 101, 242, .5); }
  100% { box-shadow: 0 0 0 16px rgba(88, 101, 242, 0); }
}
.pulse-ring { animation: ring-pulse .55s var(--ease); }

/* Do'st xonaga kirganda ishtirokchi kartasi uchun */
@keyframes pop-join {
  0% { transform: scale(1); }
  35% { transform: scale(1.04); border-color: var(--ok); box-shadow: 0 0 0 3px rgba(35, 165, 90, .35), 0 0 20px rgba(35, 165, 90, .25); }
  100% { transform: scale(1); }
}
.pop-join { animation: pop-join .6s var(--ease); }

/* Do'st chiqib ketganda ishtirokchi kartasi uchun */
@keyframes pop-leave {
  0% { transform: scale(1); opacity: 1; }
  40% { transform: scale(.97); opacity: .55; border-color: var(--bad); }
  100% { transform: scale(1); opacity: 1; }
}
.pop-leave { animation: pop-leave .5s var(--ease); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; }
}

/* ---------- Telefon ---------- */

@media (max-width: 640px) {
  .topbar { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .small-brand span { display: none; }
  .status { font-size: .8rem; padding: .25rem .6rem; }
  .stage { padding: 8px; }
  .tile { flex-basis: 100%; max-width: none; }
  .stage.has-screen .tile { flex: 1 1 0; min-width: 0; }
  .controls { gap: 8px; padding-left: 8px; padding-right: 8px; }
  .pill-btn { padding: 0 .9rem; font-size: .9rem; }
  .sheet {
    top: auto; width: 100%; max-height: 82vh; max-height: 82dvh;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 20px 20px 0 0;
    animation: slide-up .22s var(--ease);
  }
  .stats { left: 8px; right: 8px; top: 8px; width: auto; max-height: 70%; }
  .viewer-bar .range { width: 90px; }
  #toasts { bottom: calc(190px + env(safe-area-inset-bottom)); }
  .page-home .home { padding-top: 16px; }
  .card { padding: 1.1rem; }
}

@keyframes slide-up { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: none; } }

@media (max-height: 480px) and (orientation: landscape) {
  .topbar { padding-top: 4px; padding-bottom: 4px; }
  .controls { padding-top: 6px; padding-bottom: 6px; }
  .round-btn, .pill-btn { height: 40px; }
  .round-btn { width: 40px; }
}
