:root {
  --page-bg: linear-gradient(90deg, #eaf0f9 0%, #d9e7f6 100%);
  --brand-fg: #0f2440;
  --switch-fg: #51637a;
  --switch-line: rgba(15, 36, 64, .12);

  --bar-bg: #ffffff;
  --bar-fg: #1b2233;
  --bar-muted: #6b7486;
  --bar-sep: #e3e7ef;
  --tab-active-bg: #1c2336;
  --tab-active-fg: #ffffff;

  --stage-bg: radial-gradient(ellipse at 50% 45%, #141b2a 0%, #080b12 62%, #020306 100%);
  --start-bg: linear-gradient(135deg, #f6f8fc 0%, #eef0fb 100%);
  --start-fg: #1b2233;
  --start-muted: #7d8699;

  --msg-bg: #f3f5fa;
  --msg-fg: #1b2233;
  --msg-muted: #7d8699;
  --bubble-theirs: #ffffff;
  --bubble-line: #e3e7ef;
  --field-bg: #ffffff;
  --field-line: #d5dbe6;
  --modal-bg: #ffffff;

  --primary: #0a5cff;
  --primary-hover: #004ad8;
  --danger: #ff3b4e;
  --ok: #19b35c;
  --online: #22c55e;
  --badge: #e5141f;

  --radius: 8px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --page-bg: linear-gradient(90deg, #03172a 0%, #0c3b5e 100%);
    --brand-fg: #ffffff;
    --switch-fg: #8fa6c0;
    --switch-line: rgba(255, 255, 255, .1);
    --msg-bg: #0d1320;
    --msg-fg: #e8ecf4;
    --msg-muted: #8a93a6;
    --bubble-theirs: #1b2334;
    --bubble-line: #232d42;
    --field-bg: #151c2b;
    --field-line: #2a3449;
    --modal-bg: #151c2b;
    --start-bg: linear-gradient(135deg, #f6f8fc 0%, #eef0fb 100%);
  }
}
:root[data-theme="dark"] {
  --page-bg: linear-gradient(90deg, #03172a 0%, #0c3b5e 100%);
  --brand-fg: #ffffff;
  --switch-fg: #8fa6c0;
  --switch-line: rgba(255, 255, 255, .1);
  --msg-bg: #0d1320;
  --msg-fg: #e8ecf4;
  --msg-muted: #8a93a6;
  --bubble-theirs: #1b2334;
  --bubble-line: #232d42;
  --field-bg: #151c2b;
  --field-line: #2a3449;
  --modal-bg: #151c2b;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--page-bg);
  background-attachment: fixed;
  color: var(--bar-fg);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
svg { width: 20px; height: 20px; flex: none; }
.sprite { position: absolute; width: 0; height: 0; }

.page {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0 16px;
}

.brand {
  height: 91px;
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  user-select: none;
}
.brand-word { font-size: 26px; font-weight: 700; letter-spacing: -.02em; color: var(--brand-fg); }

.card {
  width: min(920px, 100%);
  height: min(680px, calc(100% - 130px));
  min-height: 460px;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: 0 30px 80px rgba(0, 0, 0, .25);
  position: relative;
}
.card:fullscreen { width: 100%; height: 100%; border-radius: 0; }

/* ---------- Вход ---------- */
.start {
  height: 100%;
  background: var(--start-bg);
  color: var(--start-fg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.start-inner { width: min(340px, 100%); display: flex; flex-direction: column; align-items: center; text-align: center; }
.start-title { margin: 0 0 28px; font-size: 28px; font-weight: 500; letter-spacing: -.01em; }
.start-avatar {
  width: 120px; height: 120px; border-radius: 50%;
  background: #fff;
  box-shadow: 0 6px 18px rgba(20, 40, 90, .12), inset 0 -3px 0 rgba(20, 40, 90, .05);
  display: grid; place-items: center;
  overflow: hidden;
  position: relative;
}
.start-avatar video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.start-avatar-icon { width: 44px; height: 44px; color: var(--primary); }
.start-sub { margin: 18px 0 20px; color: var(--start-muted); font-size: 15px; line-height: 1.45; }
.start-form { width: 100%; display: flex; flex-direction: column; gap: 12px; }
.start-hint { margin: 14px 0 0; font-size: 14px; color: var(--start-muted); }

.field {
  width: 100%;
  height: 46px;
  padding: 0 14px;
  border: 1px solid var(--field-line);
  border-radius: 6px;
  background: var(--field-bg);
  color: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.start .field { background: #fff; border-color: #d5dbe6; color: #1b2233; }
.field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(10, 92, 255, .15); }

.btn-primary {
  height: 46px;
  padding: 0 24px;
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #fff;
  font-size: 16px;
  font-weight: 500;
  box-shadow: 0 6px 20px rgba(10, 92, 255, .35);
  transition: background .15s, transform .05s;
}
.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { cursor: default; background: var(--primary); opacity: 1; }
.btn-primary.wide { width: 280px; max-width: calc(100% - 32px); }
.btn-primary.is-cancel { background: var(--danger); box-shadow: 0 6px 20px rgba(255, 59, 78, .3); }

.link-btn {
  display: inline-flex; align-items: center; gap: 6px;
  margin-top: 12px;
  padding: 6px 10px;
  border: 0; background: none;
  color: var(--primary);
  font-size: 14px; font-weight: 500;
}
.link-btn svg { width: 16px; height: 16px; }
.link-btn.light { color: #8fb4ff; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Приложение ---------- */
.app { height: 100%; display: flex; flex-direction: column; }

.topbar {
  height: 52px;
  flex: none;
  display: flex;
  align-items: center;
  background: var(--bar-bg);
  color: var(--bar-fg);
  padding-right: 12px;
}
.tab {
  height: 100%;
  display: flex; align-items: center; gap: 8px;
  padding: 0 20px;
  border: 0;
  background: none;
  color: inherit;
  font-size: 14px;
  position: relative;
}
.tab-icon { display: none; width: 22px; height: 22px; }
.tab.is-active { background: var(--tab-active-bg); color: var(--tab-active-fg); }
.tab:not(.is-active):hover { color: var(--primary); }
.badge {
  min-width: 18px; height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--badge);
  color: #fff;
  font-size: 11px; font-weight: 700;
  display: inline-grid; place-items: center;
}
.sep { width: 1px; height: 22px; background: var(--bar-sep); margin: 0 8px; }
.icon-btn {
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 0; background: none; color: var(--bar-fg);
  border-radius: 6px;
}
.icon-btn:hover { color: var(--primary); }
.me { margin-left: auto; border: 0; background: none; padding: 0; }

.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: inline-grid; place-items: center;
  background: linear-gradient(135deg, #5b8cff, #0a5cff);
  color: #fff;
  font-weight: 600; font-size: 15px;
  flex: none;
  text-transform: uppercase;
}
.avatar.xl { width: 96px; height: 96px; font-size: 38px; }
.avatar.alt { background: linear-gradient(135deg, #ff7aa2, #e63d78); }

.body { flex: 1; min-height: 0; position: relative; }
.pane { position: absolute; inset: 0; }

.toast {
  position: absolute; z-index: 20;
  top: 4px; left: 50%; transform: translateX(-50%);
  max-width: calc(100% - 24px);
  min-height: 44px;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 24px 10px 16px;
  border-radius: 6px;
  background: #e1ecfc;
  color: #1b2233;
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .25);
}
.spinner {
  width: 22px; height: 22px; flex: none;
  border-radius: 50%;
  border: 2px solid rgba(27, 34, 51, .15);
  border-top-color: #1b2233;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Видео ---------- */
.pane-video { background: var(--stage-bg); overflow: hidden; }
.remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.remote-off {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  color: #b7c0d1; font-size: 14px;
  background: var(--stage-bg);
}
.pip {
  position: absolute; z-index: 5;
  right: 16px; bottom: 16px;
  width: 200px; aspect-ratio: 4 / 3;
  object-fit: cover;
  border-radius: 8px;
  background: #111;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45);
  transform: scaleX(-1);
}
.pip.is-env { transform: none; }

.stage {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px;
  text-align: center;
}
.stage-peer { position: relative; margin-bottom: 26px; }
.stage-peer .dot {
  position: absolute; right: 6px; bottom: 6px;
  width: 18px; height: 18px; border-radius: 50%;
  background: #56627a; border: 3px solid #0b0f18;
}
.stage-peer .dot.on { background: var(--online); }
.stage-sub { margin: 12px 0 0; color: #fff; font-size: 14px; line-height: 1.5; max-width: 360px; }
.stage-sub .hl { color: #ffd23f; font-weight: 700; }
.stage-sub .muted { color: #9aa4b8; }

.live {
  position: absolute; z-index: 6;
  left: 16px; bottom: 16px;
  width: min(360px, calc(100% - 250px));
  display: flex; flex-direction: column; gap: 8px;
}
.live-feed {
  max-height: 220px;
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 28px);
          mask-image: linear-gradient(to bottom, transparent 0, #000 28px);
  padding-top: 28px;
  scrollbar-width: none;
}
.live-feed::-webkit-scrollbar { display: none; }
.live-msg {
  align-self: flex-start;
  max-width: 100%;
  padding: 7px 12px;
  border-radius: 14px;
  background: rgba(10, 14, 24, .62);
  backdrop-filter: blur(8px);
  color: #fff;
  font-size: 14px; line-height: 1.35;
  overflow-wrap: anywhere;
}
.live-msg b { font-weight: 600; margin-right: 6px; color: #8fb4ff; }
.live-msg.mine b { color: #ffd23f; }
.live-form {
  display: flex; align-items: center;
  height: 44px;
  border-radius: 22px;
  background: rgba(10, 14, 24, .62);
  backdrop-filter: blur(8px);
  padding: 0 4px 0 16px;
}
.live-form input { flex: 1; min-width: 0; height: 100%; border: 0; background: none; color: #fff; outline: none; font-size: 14px; }
.live-form input::placeholder { color: #a9b2c4; }
.live-form button { width: 36px; height: 36px; border: 0; border-radius: 50%; background: var(--primary); color: #fff; display: grid; place-items: center; }
.live-form button svg { width: 18px; height: 18px; }

.controls {
  position: absolute; z-index: 7;
  left: 50%; transform: translateX(-50%);
  top: 16px;
  display: flex; gap: 10px;
  padding: 6px;
  border-radius: 30px;
  background: rgba(10, 14, 24, .5);
  backdrop-filter: blur(8px);
}
.ctl {
  width: 46px; height: 46px;
  border: 0; border-radius: 50%;
  display: grid; place-items: center;
  background: rgba(255, 255, 255, .14);
  color: #fff;
  transition: background .15s;
}
.ctl:hover { background: rgba(255, 255, 255, .24); }
.ctl.is-off { background: #fff; color: #1b2233; }
.ctl.danger { background: var(--danger); }
.ctl.danger:hover { background: #e4283b; }

/* ---------- Сообщения ---------- */
.pane-msg { background: var(--msg-bg); color: var(--msg-fg); display: flex; flex-direction: column; }
.dm-head {
  flex: none;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--bubble-line);
}
.dm-who { display: flex; flex-direction: column; min-width: 0; }
.dm-who b { font-weight: 600; font-size: 15px; }
.dm-who small { color: var(--msg-muted); font-size: 12px; }
.dm-who small.on { color: var(--online); }
.dm-call {
  margin-left: auto;
  width: 40px; height: 40px;
  border: 0; border-radius: 50%;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
}
.dm-call:disabled { background: var(--field-line); color: var(--msg-muted); cursor: default; }
.dm-list {
  flex: 1; min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex; flex-direction: column; gap: 4px;
}
.dm-empty { margin: auto; text-align: center; color: var(--msg-muted); font-size: 14px; line-height: 1.5; }
.dm-day { align-self: center; margin: 10px 0 6px; font-size: 12px; color: var(--msg-muted); }
.dm-msg { display: flex; }
.dm-msg.mine { justify-content: flex-end; }
.bubble {
  max-width: min(75%, 520px);
  padding: 8px 12px 6px;
  border-radius: 16px 16px 16px 4px;
  background: var(--bubble-theirs);
  border: 1px solid var(--bubble-line);
  font-size: 15px; line-height: 1.4;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}
.dm-msg.mine .bubble { background: var(--primary); border-color: var(--primary); color: #fff; border-radius: 16px 16px 4px 16px; }
.meta { display: block; margin-top: 2px; font-size: 11px; text-align: right; opacity: .6; }
.meta .tag { margin-right: 6px; font-weight: 600; }
.dm-form {
  flex: none;
  display: flex; gap: 8px;
  padding: 12px 16px;
  border-top: 1px solid var(--bubble-line);
}
.send-btn {
  width: 46px; height: 46px; flex: none;
  border: 0; border-radius: 6px;
  background: var(--primary); color: #fff;
  display: grid; place-items: center;
}

.blocker {
  position: absolute; inset: 0; z-index: 30;
  background: var(--start-bg);
  color: var(--start-fg);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 24px; text-align: center;
}
.blocker h2 { margin: 0 0 10px; font-size: 24px; font-weight: 500; }
.blocker p { margin: 0 0 22px; color: var(--start-muted); max-width: 360px; line-height: 1.45; }

/* ---------- Тема ---------- */
.theme-switch {
  position: fixed; right: 24px; bottom: 22px;
  display: flex; gap: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--switch-line);
}
.theme-switch button {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: 0; background: none;
  color: var(--switch-fg);
  font-size: 11px;
}
.sw { display: block; width: 54px; height: 22px; border-radius: 4px; border: 1px solid transparent; position: relative; }
.sw::before { content: ""; position: absolute; left: 7px; top: 7px; width: 8px; height: 8px; border-radius: 50%; }
.sw::after { content: ""; position: absolute; left: 21px; right: 8px; top: 7px; height: 2px; border-radius: 1px; box-shadow: 0 4px 0 currentColor; }
.sw-light { background: #f1f4fa; color: #1b2233; }
.sw-light::before, .sw-light::after { background: #1b2233; }
.sw-dark { background: #0d2744; color: #2e8cff; }
.sw-dark::before, .sw-dark::after { background: #2e8cff; }
.sw-system { background: #1a1f2b; color: #aab3c5; }
.sw-system::before, .sw-system::after { background: #aab3c5; }
.theme-switch button.is-active { color: #2e8cff; }
.theme-switch button.is-active .sw { border-color: #2e8cff; }

/* ---------- Модалки ---------- */
.modal {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(3, 10, 22, .6);
  backdrop-filter: blur(4px);
  display: grid; place-items: center;
  padding: 16px;
}
.modal-card {
  width: min(360px, 100%);
  border-radius: 12px;
  background: var(--modal-bg);
  color: var(--msg-fg);
  box-shadow: 0 30px 80px rgba(0, 0, 0, .4);
}
.ring { padding: 32px 24px 24px; display: flex; flex-direction: column; align-items: center; text-align: center; }
.ring-label { margin: 18px 0 4px; color: var(--msg-muted); font-size: 14px; }
.ring h2 { margin: 0 0 26px; font-size: 22px; font-weight: 600; overflow-wrap: anywhere; }
.ring-actions { display: flex; gap: 64px; }
.ring-captions { display: flex; gap: 64px; margin-top: 8px; font-size: 12px; color: var(--msg-muted); }
.ring-captions span { width: 60px; }
.round { width: 60px; height: 60px; border: 0; border-radius: 50%; color: #fff; display: grid; place-items: center; }
.round svg { width: 26px; height: 26px; }
.round.danger { background: var(--danger); }
.round.ok { background: var(--ok); }
.pulse { animation: pulse 1.4s ease-out infinite; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(10, 92, 255, .5); } 100% { box-shadow: 0 0 0 22px rgba(10, 92, 255, 0); } }

.settings { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 14px; }
.settings header { display: flex; align-items: center; justify-content: space-between; }
.settings h2 { margin: 0; font-size: 18px; font-weight: 600; }
.settings label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--msg-muted); }
.settings .field { color: var(--msg-fg); }
.settings .link-btn { align-self: flex-start; margin: 0; padding-left: 0; }
.x { width: 34px; height: 34px; border: 0; background: none; color: var(--msg-muted); display: grid; place-items: center; }
.settings .link-btn.danger { color: var(--danger); text-align: left; }
.reset-confirm {
  display: flex; flex-direction: column; gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--field-line);
  border-radius: 8px;
}
.reset-confirm p { margin: 0; font-size: 13px; line-height: 1.45; color: var(--msg-fg); }
.settings label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--msg-fg); cursor: pointer; }
.check input { width: 16px; height: 16px; margin: 0; accent-color: var(--danger); }
.reset-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn-ghost, .btn-danger { height: 38px; padding: 0 16px; border-radius: 6px; font-size: 14px; font-weight: 500; }
.btn-ghost { border: 1px solid var(--field-line); background: none; color: var(--msg-fg); }
.btn-danger { border: 0; background: var(--danger); color: #fff; }
.btn-danger:hover { background: #e4283b; }
.dm-msg.gone .bubble { opacity: .7; }

/* ---------- Мобилка ---------- */
@media (max-width: 700px), (max-height: 560px) {
  .page { padding: 0; }
  .brand, .theme-switch { display: none; }
  .card { position: fixed; inset: 0; width: 100%; height: 100%; height: 100dvh; min-height: 0; border-radius: 0; box-shadow: none; }
  .tab { padding: 0 14px; }
  .tab-label { display: none; }
  .tab-icon { display: block; }
  .tab .badge { position: absolute; top: 7px; right: 5px; }
  .sep { margin: 0 4px; }
  .pip { width: 96px; aspect-ratio: 3 / 4; right: 12px; top: 12px; bottom: auto; }
  .live { left: 12px; right: 12px; width: auto; bottom: 84px; }
  .live-feed { max-height: 32vh; }
  .controls { top: auto; bottom: calc(16px + env(safe-area-inset-bottom)); }
  .dm-form { padding-bottom: calc(12px + env(safe-area-inset-bottom)); }
  .bubble { max-width: 85%; }
}
