* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #000; color: #fff;
             font: 16px -apple-system, system-ui, sans-serif;
             -webkit-tap-highlight-color: transparent; -webkit-text-size-adjust: 100%; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }

/* --- Вход, роль, название --- */
.page { min-height: 100%; display: flex; align-items: center; justify-content: center;
        padding: calc(env(safe-area-inset-top) + 20px) 20px calc(env(safe-area-inset-bottom) + 20px); }
.card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 12px; }
.card h1 { margin: 0 0 8px; font-size: 28px; }
.card input { background: #1c1c1e; border: 1px solid #333; color: #fff; border-radius: 12px;
              padding: 14px 16px; font-size: 17px; outline: none; }
.card input:focus { border-color: #888; }
.primary { background: #fff; color: #000; border: 0; border-radius: 12px; padding: 14px; font-weight: 600; font-size: 17px; }
.error { color: #ff6b6b; min-height: 1.2em; margin: 0; font-size: 15px; }
.hint { color: #999; margin: -4px 0 4px; font-size: 15px; }
.choice { display: flex; flex-direction: column; gap: 4px; text-align: left; background: #1c1c1e;
          border: 1px solid #333; border-radius: 16px; padding: 18px; }
.choice b { font-size: 20px; }
.choice span { color: #999; font-size: 15px; }
.choice:active { background: #2c2c2e; }
.link { background: none; border: 0; color: #888; padding: 10px; font-size: 15px; }

/* --- Камера --- */
#client { position: fixed; inset: 0; overflow: hidden; touch-action: none;
          -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; pointer-events: none; }
#cmsg { position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
        text-align: center; padding: 30px; }
#cmsg button { margin-top: 16px; background: rgba(0,0,0,.55); border: 1px solid rgba(255,255,255,.3);
               border-radius: 18px; padding: 8px 14px; }

/* «Облачка» камеры: каждое — отдельное плавающее стеклянное окошко */
#cui { position: absolute; inset: 0; pointer-events: none; transition: opacity .25s; }
#cui.hidden { opacity: 0; }
#cui.hidden .pill { pointer-events: none; }
.ctop { position: absolute; top: calc(env(safe-area-inset-top) + 10px); left: calc(env(safe-area-inset-left) + 10px);
        right: calc(env(safe-area-inset-right) + 10px); display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
#cViewers { display: flex; flex-direction: column; align-items: flex-start; gap: 5px; }
.cbottom { position: absolute; left: 0; right: 0; bottom: calc(env(safe-area-inset-bottom) + 14px);
           display: flex; flex-direction: column; align-items: center; gap: 8px; padding: 0 10px; }
.prow { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.pill { pointer-events: auto; display: inline-flex; align-items: center; gap: 7px;
        background: rgba(0,0,0,.5); border: 1px solid rgba(255,255,255,.22); border-radius: 18px;
        padding: 7px 13px; font-size: 14px; color: #fff; max-width: 100%;
        -webkit-backdrop-filter: blur(12px); backdrop-filter: blur(12px); }
.pill.small { font-size: 12px; padding: 5px 10px; color: #ddd; }
.pill.round { min-width: 44px; justify-content: center; font-weight: 600; }
.pill.on { background: #fff; color: #000; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: #888; flex: none; }
.dot.on { background: #6ee7a0; }
.dot.warn { background: #fbbf24; }
.dot.off { background: #ff6b6b; }

/* QR-код ссылки */
#cqr { position: fixed; inset: 0; z-index: 30; display: flex; align-items: center; justify-content: center;
       background: rgba(0,0,0,.6); padding: 20px; }
.qr-card { background: rgba(28,28,30,.92); border: 1px solid rgba(255,255,255,.15); border-radius: 20px;
           padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 10px;
           max-width: 340px; max-height: 100%; overflow: auto; -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px); }
.qr-card img { width: min(220px, 50vh); height: auto; aspect-ratio: 1; background: #fff; border-radius: 12px; }
.qr-card .hint { margin: 0; text-align: center; font-size: 13px; }
.qr-card code { font-size: 11px; color: #aaa; word-break: break-all; text-align: center;
                user-select: all; -webkit-user-select: all; }
.qr-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.qr-actions button { background: rgba(255,255,255,.12); border: 0; border-radius: 12px; padding: 9px 14px; font-size: 14px; }

/* --- Пульт --- */
#control { min-height: 100%; padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left); }
#control header { display: flex; align-items: center; gap: 12px; padding: 12px 14px; }
#control header b { font-size: 20px; }
#kstatus { color: #888; font-size: 14px; flex: 1; }
#control header button { background: #1c1c1e; border: 1px solid #333; border-radius: 10px; padding: 7px 12px; font-size: 14px; }
#grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(420px, 100%), 1fr)); gap: 10px; padding: 0 10px 10px; }
#empty { color: #888; text-align: center; padding: 60px 20px; line-height: 1.5; }

.tile { position: relative; background: #161618; border-radius: 14px; overflow: hidden; display: flex; flex-direction: column;
        -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
.tile .screen { position: relative; aspect-ratio: 16 / 9; background: #000; overflow: hidden; }
/* размер и поворот видео задаёт layoutVideo(): при 90°/270° ширина и высота меняются местами */
.tile video { position: absolute; top: 50%; left: 50%; width: 100%; height: 100%; transform: translate(-50%, -50%);
              object-fit: contain; background: #000; pointer-events: none; }
.tile .wait { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #888; font-size: 14px; }
.tile .top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 6px; padding: 8px 10px;
             background: linear-gradient(rgba(0,0,0,.6), transparent); transition: opacity .3s; }
.tile .name { font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .badge { font-size: 12px; color: #ccc; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile .badge.lan { color: #6ee7a0; }
.tile .badge.wan { color: #fbbf24; }
.tile .bottom { display: flex; flex-direction: column; gap: 8px; padding: 10px; transition: opacity .3s; }
.tile .row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.tile .grow { flex: 1; }
.tile .lbl { font-size: 12px; color: #888; margin-left: 4px; }
.tile .lbl:first-child { margin-left: 0; }
.tile .stops { display: flex; gap: 4px; }
.tile button { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); border-radius: 14px;
               min-width: 36px; padding: 5px 9px; font-size: 13px; font-weight: 600; }
.tile button.on { background: #fff; color: #000; }
.tile .seg { display: flex; background: rgba(255,255,255,.08); border-radius: 12px; padding: 2px; }
.tile .seg button { background: none; border: 0; border-radius: 10px; min-width: 0; padding: 4px 9px; font-weight: 500; color: #ddd; }
.tile .seg button.on { background: #fff; color: #000; font-weight: 600; }
.tile .zslider { flex: 1; min-width: 100px; accent-color: #fff; height: 24px; }
.tile .zlabel { font-size: 13px; font-weight: 600; min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; }

/* Развёрнутая камера: видео на весь экран, управление поверх и прячется через 3 секунды */
.tile.expanded { position: fixed; inset: 0; z-index: 10; border-radius: 0; background: #000; }
.tile.expanded .screen { position: absolute; inset: 0; aspect-ratio: auto; }
.tile.expanded .top { padding: calc(env(safe-area-inset-top) + 8px) calc(env(safe-area-inset-right) + 12px) 8px calc(env(safe-area-inset-left) + 12px); }
.tile.expanded .bottom { position: absolute; left: 0; right: 0; bottom: 0;
                         padding: 30px calc(env(safe-area-inset-right) + 12px) calc(env(safe-area-inset-bottom) + 12px) calc(env(safe-area-inset-left) + 12px);
                         background: linear-gradient(transparent, rgba(0,0,0,.75)); }
.tile.expanded .bottom button, .tile.expanded .seg { background-color: rgba(0,0,0,.45); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); }
.tile.expanded .bottom button.on, .tile.expanded .seg button.on { background: #fff; }
.tile.expanded .seg button { background: none; -webkit-backdrop-filter: none; backdrop-filter: none; }
.tile.expanded.clean .top, .tile.expanded.clean .bottom { opacity: 0; pointer-events: none; }
.tile.expanded.clean { cursor: none; }
.tile.expanded.cover video { object-fit: cover; }
body.locked { overflow: hidden; }

/* --- Окно ссылок --- */
.sheet { position: fixed; inset: 0; z-index: 20; background: rgba(0,0,0,.6); display: flex;
         align-items: flex-end; justify-content: center; }
.sheet-card { width: 100%; max-width: 520px; max-height: 85%; overflow: auto; background: #1c1c1e;
              border-radius: 18px 18px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
              display: flex; flex-direction: column; gap: 12px; }
@media (min-width: 600px) { .sheet { align-items: center; } .sheet-card { border-radius: 18px; } }
.sheet-head { display: flex; align-items: center; justify-content: space-between; font-size: 18px; }
.sheet-head button { background: #2c2c2e; border: 0; border-radius: 50%; width: 32px; height: 32px; }
.sheet .hint { margin: 0; font-size: 13px; }
.link-item { background: #2c2c2e; border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; }
.link-item .row { display: flex; gap: 8px; align-items: center; }
.link-item .lname { font-weight: 600; flex: 1; }
.link-item .lstate { font-size: 12px; color: #888; }
.link-item .lstate.on { color: #6ee7a0; }
.link-item code { font-size: 12px; color: #aaa; word-break: break-all; user-select: all; -webkit-user-select: all; }
.link-item button { background: #3a3a3c; border: 0; border-radius: 9px; padding: 7px 12px; font-size: 14px; }
.link-item button.danger { color: #ff6b6b; }
#linksList:empty::before { content: 'Ссылок пока нет'; color: #888; font-size: 14px; }

/* --- Просмотр по ссылке: только одна камера, без управления --- */
body.viewer #control header, body.viewer .tile .ctl-only, body.viewer #studio, body.viewer #camsHead { display: none !important; }
body.viewer #empty { padding-top: 40vh; }

/* --- Студия: виртуальные камеры --- */
.hostsw { display: flex; align-items: center; gap: 6px; font-size: 13px; color: #bbb; }
.sec-head { display: flex; align-items: center; gap: 10px; padding: 14px 14px 8px; }
.sec-head b { font-size: 16px; }
.sec-head .grow { flex: 1; }
#hostInfo { font-size: 12px; color: #888; }
#hostInfo.warn { color: #fbbf24; }
.sec-head button { background: #1c1c1e; border: 1px solid #333; border-radius: 10px; padding: 6px 12px; font-size: 13px; }
#outs { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(360px, 100%), 1fr)); gap: 10px; padding: 0 10px; }
.out { background: #161618; border-radius: 14px; overflow: hidden; border: 2px solid transparent; }
.out.live { border-color: #ef4444; }
.out-screen { position: relative; aspect-ratio: 16 / 9; background: #000; }
.out-screen canvas { width: 100%; height: 100%; display: block; }
.out-live { position: absolute; top: 8px; left: 8px; background: #ef4444; color: #fff; font-size: 11px; font-weight: 700;
            letter-spacing: .05em; border-radius: 6px; padding: 3px 7px; }
.out:not(.live) .out-live { background: rgba(0,0,0,.6); color: #aaa; }
.out-body { padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.out .row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.out .grow { flex: 1; }
.out-id { background: #fff; color: #000; font-weight: 800; border-radius: 7px; min-width: 24px; text-align: center; padding: 1px 6px; }
.out-name { cursor: text; }
.out-viewers { font-size: 12px; color: #888; }
.out .lbl { font-size: 12px; color: #888; }
.out button { background: rgba(255,255,255,.08); border: 1px solid rgba(255,255,255,.14); border-radius: 12px;
              padding: 5px 10px; font-size: 13px; font-weight: 600; }
.out button.onair { background: #ef4444; border-color: #ef4444; }
.out .seg { display: flex; background: rgba(255,255,255,.08); border-radius: 12px; padding: 2px; gap: 2px; }
.out .seg button { background: none; border: 0; border-radius: 10px; padding: 4px 10px; font-weight: 600; color: #ddd; }
.out .seg button.on { background: #fff; color: #000; }
.out .seg button.offline { color: #666; }
.out .seg button:disabled { color: #444; cursor: default; }
.out .out-src button { min-width: 34px; font-size: 15px; }

/* номер камеры на плитке */
.tile .slotsel { background: #fff; color: #000; font-weight: 800; border: 0; border-radius: 7px; padding: 2px 4px;
                 font-size: 14px; -webkit-appearance: none; appearance: none; text-align: center; min-width: 30px; cursor: pointer; }
.tile .slotsel.none { background: rgba(255,255,255,.2); color: #fff; }

#kDirect { border-color: #fbbf24 !important; color: #fbbf24; }

/* шапка пульта на узком экране (пульт с телефона) переносится на несколько строк */
#control header { flex-wrap: wrap; }
.sec-head { flex-wrap: wrap; }
.sec-head button.allon { border-color: #ef4444; color: #fca5a5; }
