:root{
      --bg:#0f1115;
      --panel:#151922;
      --tile:#3a3a3a;
      --tile2:#2f2f2f;
      --text:#e8eaed;
      --muted:#a7adb5;
      --border:rgba(255,255,255,.08);
      --shadow: 0 8px 24px rgba(0,0,0,.35);
      --radius:16px;
      --gap:10px;
      --ctrl-h:84px;
    }
    *{ box-sizing:border-box; }
    html,body{ height:100%; }
    body{
      margin:0;
      font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Arial, "Noto Sans", "Liberation Sans", sans-serif;
      background:var(--bg);
      color:var(--text);
      overflow:hidden;
    }

    /* ===== Layout ===== */
    .app{
      height:100%;
      display:flex;
      flex-direction:column;
    }

    .stage{
      position:relative;
      flex:1 1 auto;
      min-height:0;
      padding: var(--gap);
      padding-bottom: calc(var(--ctrl-h) + var(--gap) + env(safe-area-inset-bottom));
    }

    #grid{
      height:100%;
      width:100%;
      display:grid;
      gap: var(--gap);
      grid-template-columns: repeat(var(--cols, 1), 1fr);
      grid-template-rows: repeat(var(--rows, 1), 1fr);
      align-content:stretch;
      justify-content:stretch;
    }

    /* allow #remotes children to behave like grid items */
    #remotes{ display: contents; }

    /* ===== Tile layout modes (dblclick / double-tap) ===== */
    /* Desktop: equal -> focus (main left + strip right) -> full -> equal
       Mobile:  equal <-> full */
    /* These modes only affect the in-call area inside .stage, so tiles never go under the control bar. */
    #grid.layout-focus,
    #grid.layout-full{
      display:flex;
      flex-direction:row;
      align-items:stretch;
      justify-content:stretch;
      gap: var(--gap);
    }

    #grid.layout-focus .focus-main,
    #grid.layout-full .focus-main{
      flex: 1 1 auto;
      min-width:0;
      min-height:0;
      display:flex;
    }
    #grid.layout-focus .focus-main > .video-box,
    #grid.layout-full .focus-main > .video-box{
      flex: 1 1 auto;
      min-width:0;
      min-height:0;
    }

    /* Desktop focus: right column with remaining tiles */
    #grid.layout-focus .focus-side{
      flex: 0 0 20%;
      min-width: 220px;
      max-width: 360px;
      min-height:0;
      display:flex;
      flex-direction:column;
      gap: var(--gap);
      overflow:auto;
      padding-right: 2px;
    }

    /* In focus/full mode, remotes container becomes a normal column */
    #grid.layout-focus #remotes,
    #grid.layout-full #remotes{
      display:flex;
      flex-direction:column;
      gap: var(--gap);
    }

    /* Tile size inside the side strip */
    #grid.layout-focus .focus-side .video-box,
    #grid.layout-full .focus-side .video-box{
      height: clamp(90px, 18vh, 180px);
      flex: 0 0 auto;
    }

    /* Desktop full: only the focused tile */
    #grid.layout-full .focus-side{ display:none; }

    @media (max-width: 700px){
      #grid.layout-focus,
      #grid.layout-full{ flex-direction:column; }
      #grid.layout-focus .focus-side,
      #grid.layout-full .focus-side{ display:none; }
    }


    /* ===== Tiles ===== */
    .video-box{
      position:relative;
      background: var(--tile);
      border-radius: var(--radius);
      overflow:hidden;
      box-shadow: var(--shadow), 0 0 0 2px transparent;
      transition: box-shadow .18s ease;
      min-width: 0;
      min-height: 0;
      user-select:none;
      touch-action: manipulation;
    }

    .video-box video{
      width:100%;
      height:100%;
      display:block;
      object-fit: cover;
      background:#000;
    }

    /* Screen-share must fit into the tile without cropping (different aspect ratios). */
    .video-box.is-screen video{
      object-fit: contain;
      object-position: center;
      background:#000;
    }

    /* Connection status ring */
    .video-box.conn-connecting { box-shadow: var(--shadow), 0 0 0 3px orange; }
    .video-box.conn-connected  { box-shadow: var(--shadow), 0 0 0 3px #2196f3; }
    .video-box.conn-restarting { box-shadow: var(--shadow), 0 0 0 3px #9c27b0; }
    .video-box.conn-failed     { box-shadow: var(--shadow), 0 0 0 3px #f44336; }

    /* Voice activity (speaking) ring overrides connection ring while active */
    .video-box.speaking { box-shadow: var(--shadow), 0 0 0 3px #4caf50; }

    .name-badge{
      position:absolute;
      left:10px;
      top:10px;
      padding:6px 10px;
      border-radius: 999px;
      background: rgba(0,0,0,.55);
      color:#fff;
      font-size: 12px;
      line-height: 1;
      max-width: calc(100% - 20px);
      white-space:nowrap;
      overflow:hidden;
      text-overflow:ellipsis;
      pointer-events:none;
      z-index:4;
      backdrop-filter: blur(8px);
    }

    /* Heartbeat (DataChannel) indicator: pulse dot + RTT text */
    .hb-indicator{
      position:absolute;
      right:10px;
      top:10px;
      display:flex;
      align-items:center;
      gap:6px;
      padding:5px 8px;
      border-radius: 999px;
      background: rgba(0,0,0,.45);
      color:#fff;
      font-size: 11px;
      line-height: 1;
      pointer-events:none;
      z-index:4;
      backdrop-filter: blur(8px);
      opacity: .92;
    }
    #localVideoBox #localHb{ display:none; }
    .hb-indicator .hb-dot{
      width:8px;
      height:8px;
      border-radius:999px;
      display:inline-block;
      background: #9e9e9e;
    }
    .hb-indicator.hb-ok .hb-dot{ background:#4caf50; animation: hbPulse 1s infinite; }
    .hb-indicator.hb-warn .hb-dot{ background:#ff9800; }
    .hb-indicator.hb-dead .hb-dot{ background:#f44336; }
    .hb-indicator.hb-unknown .hb-dot{ background:#9e9e9e; }

    @keyframes hbPulse{
      0% { transform: scale(1); opacity: .85; }
      50% { transform: scale(1.25); opacity: 1; }
      100% { transform: scale(1); opacity: .85; }
    }

    .avatar-circle{
      position:absolute;
      inset:0;
      display:flex;
      align-items:center;
      justify-content:center;
      z-index:3;
      pointer-events:none;
    }
    .avatar-circle > .inner{
      width: 104px;
      height: 104px;
      border-radius: 999px;
      display:flex;
      align-items:center;
      justify-content:center;
      font-weight: 700;
      letter-spacing: .5px;
      color: rgba(255,255,255,.92);
      box-shadow: 0 10px 30px rgba(0,0,0,.35);
      border: 2px solid rgba(255,255,255,.14);
      text-transform: uppercase;
      padding: 10px;
      text-align:center;
      line-height:1.05;
      font-size: 34px;
    }
    .avatar-circle .inner.small-text{
      font-size: 22px;
      letter-spacing: .2px;
      text-transform:none;
    }

    /* ===== Join overlay ===== */
    .join-overlay{
      position:absolute;
      inset:0;
      display:flex;
      align-items:center;
      justify-content:center;
      padding: 18px;
      z-index: 20;
      background: radial-gradient(1200px 600px at 50% -10%, rgba(255,255,255,.10), transparent 55%),
                  radial-gradient(700px 500px at 90% 10%, rgba(33,150,243,.10), transparent 60%),
                  rgba(15,17,21,.72);
      backdrop-filter: blur(10px);
    }
    .join-card{
      width: min(520px, 100%);
      background: rgba(21,25,34,.92);
      border: 1px solid var(--border);
      border-radius: 20px;
      box-shadow: var(--shadow);
      padding: 18px;
    }
    .join-head{
      display:flex;
      align-items:center;
      justify-content:space-between;
      gap: 12px;
      margin: 0 0 12px 0;
    }
    .join-title{
      font-size: 18px;
      font-weight: 700;
      margin: 0;
      letter-spacing:.2px;
    }
    .lang-switch{
      display:inline-flex;
      align-items:center;
      border: 1px solid var(--border);
      background: rgba(0,0,0,.18);
      border-radius: 999px;
      padding: 2px;
      gap: 2px;
      flex-shrink: 0;
    }
    .lang-btn{
      appearance:none;
      border: none;
      background: transparent;
      color: var(--muted);
      font-size: 12px;
      padding: 6px 10px;
      border-radius: 999px;
      cursor:pointer;
      line-height:1;
      user-select:none;
    }
    .lang-btn.active{
      background: rgba(33,150,243,.22);
      color: var(--text);
    }
    .join-grid{
      display:grid;
      grid-template-columns: 1fr 1fr;
      gap: 10px;
    }
    .field label{
      display:block;
      font-size: 12px;
      color: var(--muted);
      margin-bottom: 6px;
    }
    .field input{
      width:100%;
      padding: 12px 12px;
      border-radius: 12px;
      border: 1px solid var(--border);
      background: rgba(0,0,0,.18);
      color: var(--text);
      outline: none;
    }
    .field input:focus{
      border-color: rgba(33,150,243,.55);
      box-shadow: 0 0 0 3px rgba(33,150,243,.15);
    }
    .join-actions{
      margin-top: 12px;
      display:flex;
      gap: 10px;
      justify-content:flex-end;
      flex-wrap:wrap;
    }

    /* ===== Buttons ===== */
    .btn{
      border: 1px solid transparent;
      border-radius: 14px;
      padding: 12px 14px;
      font-size: 14px;
      cursor:pointer;
      background:#1f6feb;
      color:#fff;
      display:inline-flex;
      align-items:center;
      justify-content:center;
      gap: 8px;
      transition: transform .08s ease, filter .15s ease, opacity .15s ease;
      user-select:none;
    }
    .btn:hover:not(:disabled){ filter: brightness(1.05); transform: translateY(-1px); }
    .btn:active:not(:disabled){ transform: translateY(0); filter: brightness(.98); }
    .btn:disabled{ opacity:.55; cursor: default; }

    .btn-secondary{ background: rgba(255,255,255,.10); border-color: var(--border); color: var(--text); }
    .btn-off{ background: rgba(244,67,54,.92); }
    .btn-ghost{ background: transparent; border-color: var(--border); color: var(--text); }
    .btn-small{ padding: 10px 12px; border-radius: 12px; font-size: 13px; }

    /* ===== Bottom control bar ===== */
    .control-bar{
      position:fixed;
      left:0; right:0;
      bottom:0;
      height: var(--ctrl-h);
      padding: 10px calc(10px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
      background: rgba(21,25,34,.92);
      border-top: 1px solid var(--border);
      backdrop-filter: blur(10px);
      z-index: 30;
      display:flex;
      align-items:center;
      justify-content:center;
    }
    .control-inner{
      width: min(1100px, 100%);
      display:flex;
      gap: 10px;
      align-items:center;
      justify-content:space-between;
    }
    .ctrl-group{
      display:flex;
      gap: 10px;
      align-items:center;
      flex-wrap:nowrap;
      min-width:0;
    }
    .ctrl-group.right{ justify-content:flex-end; }
    .ctrl-btn{
      min-width: 120px;
      height: 48px;
      border-radius: 14px;
      padding: 0 14px;
      font-size: 14px;
      white-space:nowrap;
    }
    .ctrl-btn.icon{
      min-width: 48px;
      width: 48px;
      padding: 0;
    }

    /* ===== In-room chat overlay ===== */
    .chat-panel{
      position:absolute;
      top: var(--gap);
      right: var(--gap);
      bottom: calc(var(--ctrl-h) + var(--gap) + env(safe-area-inset-bottom));
      width: clamp(260px, 26vw, 440px);
      z-index: 25;
      display:none;
      pointer-events:none; /* enabled when open */
    }
    .chat-panel.open{ display:flex; pointer-events:auto; }

    .chat-card{
      width:100%;
      height:100%;
      display:flex;
      flex-direction:column;
      border-radius: 18px;
      overflow:hidden;
      border: 1px solid var(--border);
      background: rgba(21,25,34,.70); /* ~30% transparent */
      backdrop-filter: blur(10px);
      box-shadow: var(--shadow);
    }

    .chat-head{
      display:flex;
      align-items:center;
      justify-content:space-between;
      gap: 10px;
      padding: 12px 12px;
      border-bottom: 1px solid var(--border);
    }
    .chat-title{ font-weight: 800; letter-spacing:.2px; }

    .chat-messages{
      flex:1 1 auto;
      min-height:0;
      overflow:auto;
      padding: 12px;
      display:flex;
      flex-direction:column;
      gap: 10px;
    }

    .chat-msg{
      display:flex;
      flex-direction:column;
      gap: 4px;
      padding: 8px 10px;
      border-radius: 14px;
      background: rgba(0,0,0,.20);
      border: 1px solid rgba(255,255,255,.08);
    }
    .chat-msg.me{
      background: rgba(33,150,243,.16);
      border-color: rgba(33,150,243,.22);
    }
    .chat-meta{
      display:flex;
      align-items:baseline;
      justify-content:space-between;
      gap: 10px;
      font-size: 12px;
      color: var(--muted);
      line-height: 1.2;
    }
    .chat-name{ font-weight: 700; color: var(--text); opacity: .9; }
    .chat-time{ font-variant-numeric: tabular-nums; white-space:nowrap; }
    .chat-text{
      font-size: 13px;
      line-height: 1.3;
      white-space: pre-wrap;
      word-break: break-word;
    }

    .chat-compose{
      display:flex;
      gap: 10px;
      padding: 12px;
      border-top: 1px solid var(--border);
      background: rgba(0,0,0,.10);
    }
    .chat-input{
      flex:1 1 auto;
      min-width:0;
      height: 40px;
      border-radius: 14px;
      border: 1px solid var(--border);
      background: rgba(0,0,0,.20);
      color: var(--text);
      padding: 0 12px;
      outline:none;
    }
    .chat-input:focus{ border-color: rgba(33,150,243,.55); }

    html.is-mobile .chat-panel{
      left: 0;
      right: 0;
      top: 0;
      width:auto;
      bottom: calc(var(--ctrl-h) + env(safe-area-inset-bottom));
    }
    html.is-mobile .chat-card{
      border-radius: 0;
      background: rgba(21,25,34,.96);
    }

    
/* ===== TURN speed (join screen) ===== */
.turn-speed{
  width: 100%;
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.18);
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 10px;
}
.turn-speed__label{
  font-size: 12px;
  color: var(--muted);
  line-height: 1.2;
  white-space:nowrap;
  overflow:hidden;
  text-overflow: ellipsis;
}
.turn-speed__value{
  display:inline-flex;
  align-items:baseline;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.10);
  font-variant-numeric: tabular-nums;
}
#turnSpeedValue{
  font-weight: 800;
  color: var(--text);
  letter-spacing: .2px;
}
.turn-speed__unit{
  font-size: 12px;
  color: var(--muted);
}

/* ===== Settings modal ===== */
    .modal{
      position: fixed;
      inset: 0;
      display:none;
      align-items:center;
      justify-content:center;
      padding: 18px;
      z-index: 50;
      background: rgba(0,0,0,.55);
      backdrop-filter: blur(6px);
    }
    .modal.open{ display:flex; }
    .modal-card{
      width: min(620px, 100%);
      background: rgba(21,25,34,.96);
      border: 1px solid var(--border);
      border-radius: 20px;
      box-shadow: var(--shadow);
      overflow:hidden;
    }
    .modal-head{
      display:flex;
      align-items:center;
      justify-content:space-between;
      padding: 14px 16px;
      border-bottom: 1px solid var(--border);
    }
    .modal-head h2{
      margin:0;
      font-size: 16px;
      font-weight: 700;
    }
    .modal-body{
      padding: 16px;
      display:grid;
      gap: 12px;
    }
    .row{
      display:flex;
      gap: 10px;
      align-items:center;
      flex-wrap: wrap;
    }
    .row .bg-control{
      display:flex;
      align-items:center;
      gap: 8px;
      color: var(--muted);
      font-size: 13px;
    }
    .row select, .row input[type="file"]{
      padding: 10px 12px;
      border-radius: 12px;
      border: 1px solid var(--border);
      background: rgba(0,0,0,.18);
      color: var(--text);
      outline:none;
    }

    /* ===== Log drawer ===== */
    #logWrapper{
      position: fixed;
      right: 10px;
      bottom: calc(var(--ctrl-h) + 10px + env(safe-area-inset-bottom));
      width: min(520px, calc(100vw - 20px));
      max-height: min(48vh, 520px);
      background: rgba(21,25,34,.94);
      border: 1px solid var(--border);
      border-radius: 16px;
      box-shadow: var(--shadow);
      overflow:hidden;
      z-index: 40;
    }
    #logHeader{
      padding: 10px 12px;
      border-bottom: 1px solid var(--border);
      font-size: 13px;
      color: var(--muted);
      display:flex;
      align-items:center;
      justify-content:space-between;
      gap: 10px;
    }
    #log{
      height: 100%;
      max-height: min(40vh, 420px);
      overflow:auto;
      padding: 10px 12px;
      font-size: 11px;
      color: rgba(255,255,255,.86);
      white-space: pre-wrap;
      background: rgba(0,0,0,.10);
    }

    /* ===== in-call toggles ===== */
    body.in-call .join-overlay{ display:none; }
    body:not(.in-call) .control-bar{ display:none; }
    body:not(.in-call) .stage{ padding-bottom: var(--gap); }

    /* ===== Responsive ===== */
    
    /* ---------- Mobile: удобные размеры + две строки контролов ---------- */


@media (max-width: 700px){
      :root{ --gap: 8px; --ctrl-h: 76px; }
      .avatar-circle > .inner{
        width: 84px; height: 84px; font-size: 28px;
      }
      .avatar-circle .inner.small-text{ font-size: 18px; }
      .control-inner{ gap: 8px; }
      .ctrl-btn{
        min-width: 48px;
        width: 48px;
        padding: 0;
      }
      .ctrl-btn .label{ display:none; }
      .join-grid{ grid-template-columns: 1fr; }
    }
    @media (max-width: 420px){
      .name-badge{ font-size: 11px; padding: 5px 8px; }
      .btn{ border-radius: 14px; }
    }

  
/* --- Mobile/desktop conditional controls --- */
html.is-mobile #screenShareBtn{ display:none !important; }  /* Экран убираем на телефоне */
html.is-mobile #recordBtn{ display:none !important; }       /* Запись не нужна на телефоне */
.control-bar #toggleLogBtn{ display:none !important; }      /* Лог прячем в настройки */


/* --- Invite modal (acts like bottom-sheet on mobile) --- */
#inviteModal .modal-card{ max-width: 560px; }
html.is-mobile #inviteModal .modal-card{
  width: calc(100vw - 16px);
  max-width: 720px;
  border-radius: 18px;
}
.invite-link{
  width:100%;
  padding: 12px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.22);
  color: var(--text);
  font-size: 14px;
}
html.is-mobile .invite-link{ font-size: 16px; padding: 14px 12px; }
.invite-actions{ display:flex; gap:10px; flex-wrap:wrap; justify-content:flex-end; }
html.is-mobile .invite-actions .btn{ flex: 1 1 140px; }


/* ===== GDPR cookie consent banner ===== */
.cookie-banner{
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 9999;
  display: none;
}
.cookie-banner.show{ display:block; }
.cookie-banner__inner{
  display:flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(0,0,0,0.72);
  backdrop-filter: blur(10px);
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}
.cookie-banner__text{ min-width: 0; }
.cookie-banner__title{ font-weight: 700; font-size: 14px; margin-bottom: 4px; }
.cookie-banner__msg{ color: var(--muted); font-size: 12px; line-height: 1.35; }
.cookie-banner__actions{ display:flex; gap: 10px; flex-shrink: 0; }

.cookie-warn{
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 9998;
  display: none;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(255, 190, 50, 0.14);
  color: var(--text);
  font-size: 12px;
  line-height: 1.35;
}
.cookie-warn.show{ display:block; }

body.in-call .cookie-banner{ bottom: calc(12px + var(--ctrl-h)); }
body.in-call .cookie-warn{ bottom: calc(12px + var(--ctrl-h)); }

@media (max-width: 700px){
  .cookie-banner__inner{ flex-direction: column; align-items: stretch; }
  .cookie-banner__actions{ justify-content: flex-end; }
}
