* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: 'Segoe UI', sans-serif; background: #121212; color: white; overflow: hidden; height: 100vh; }

/* Экран авторизации */
#welcome-screen {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: radial-gradient(circle, #252528 0%, #0a0a0b 100%);
    display: flex; flex-direction: column; align-items: center; justify-content: center; z-index: 1000;
}
.card { background: #1e1e20; padding: 40px; border-radius: 12px; box-shadow: 0 8px 24px rgba(0,0,0,0.5); text-align: center; max-width: 400px; width: 90%; position: relative; }
.card h1 { margin-bottom: 25px; font-size: 24px; color: #e5e5e5; }
.card button { width: 100%; padding: 12px; margin: 10px 0; border: none; border-radius: 6px; font-size: 16px; font-weight: bold; cursor: pointer; transition: 0.2s; }
.btn-prime { background: #0078d4; color: white; }
.btn-prime:hover { background: #106ebe; }
.btn-sec { background: #333; color: #ccc; }
.btn-sec:hover { background: #444; }

.card input { width: 100%; padding: 12px; border: 1px solid #444; background: #2d2d30; color: white; border-radius: 6px; margin-bottom: 12px; font-size: 16px; text-align: center; }
.card input#join-code-input { text-transform: uppercase; }

.btn-about-trigger { background: none; border: none; color: #555; cursor: pointer; font-size: 13px; text-decoration: underline; margin-top: 15px; transition: 0.2s; }
.btn-about-trigger:hover { color: #0078d4; }

/* Рабочее пространство */
#app-screen { display: none; height: 100vh; width: 100vw; position: relative; }

/* Тег комнаты — кликабельный */
#room-tag {
    position: absolute; top: 20px; left: 20px;
    background: rgba(30,30,30,0.85); padding: 8px 15px; border-radius: 20px;
    border: 1px solid #444; font-size: 14px; z-index: 10;
    display: flex; align-items: center; gap: 8px;
    cursor: pointer; user-select: none; transition: 0.2s;
}
#room-tag:hover { border-color: #0078d4; background: rgba(30,30,30,0.95); }
#room-tag i.fa-copy { color: #888; font-size: 12px; transition: 0.2s; }
#room-tag:hover i.fa-copy { color: #0078d4; }
#display-room-code { color: #0078d4; }

/* Сетка видео */
#video-grid {
    display: grid; 
    gap: 15px; 
    padding: 20px; 
    box-sizing: border-box;
    width: 100vw; 
    height: 100vh;
    background: #141416;
    align-content: center;
    justify-content: center;
}

.video-container { 
    position: relative; 
    background: #000; 
    border-radius: 10px; 
    overflow: hidden; 
    width: 100%;
    aspect-ratio: 16 / 9; 
    display: none;
    cursor: pointer;
    transition: box-shadow 0.2s;
}
.video-container:hover { box-shadow: 0 0 0 2px #0078d4; }

/* Настройки сетки в зависимости от людей */
#video-grid.show-1 { 
    grid-template-columns: min(100%, calc((100vh - 40px) * 16 / 9)); 
}
#video-grid.show-2 { 
    grid-template-columns: repeat(2, min(calc(50vw - 25px), calc((100vh - 40px) * 16 / 9))); 
}
#video-grid.show-3, #video-grid.show-4 { 
    grid-template-columns: repeat(2, min(calc(50vw - 25px), calc((50vh - 30px) * 16 / 9)));
}

video { width: 100%; height: 100%; object-fit: contain; background: #000; }
.mirror { transform: scaleX(-1); }
.user-label { position: absolute; bottom: 15px; left: 15px; background: rgba(0,0,0,0.7); padding: 5px 12px; border-radius: 5px; font-size: 13px; font-weight: bold; border: 1px solid #444; pointer-events: none; }

/* Панель управления */
#panel-trigger { position: fixed; bottom: 0; left: 0; width: 100%; height: 20px; z-index: 998; }
#control-panel {
    position: fixed; bottom: -100px; left: 50%; transform: translateX(-50%);
    background: rgba(28, 28, 30, 0.95); backdrop-filter: blur(10px);
    padding: 15px 30px; border-radius: 20px 20px 0 0; border: 1px solid #3a3a3c;
    display: flex; align-items: center; gap: 15px; transition: bottom 0.2s ease; z-index: 999;
}
body:hover #control-panel, #control-panel:hover { bottom: 0; }

.circle-btn {
    width: 50px; height: 50px; border-radius: 50%; border: none;
    background: #2c2c2e; color: white; font-size: 18px;
    display: flex; align-items: center; justify-content: center; cursor: pointer; transition: 0.2s;
    flex-shrink: 0;
}
.circle-btn:hover { background: #3a3a3c; }
.circle-btn.off { background: #e81123 !important; }
.circle-btn.on { background: #107c41 !important; }
.btn-leave { background: #e81123; }
.btn-leave:hover { background: #c40e1b; }

.crop-box { display: flex; gap: 8px; align-items: center; background: #2c2c2e; padding: 8px 12px; border-radius: 8px; font-size: 13px; border: 1px solid #444; white-space: nowrap; }
.crop-box input[type="number"] { width: 50px; background: #1e1e1f; border: 1px solid #555; color: white; text-align: center; border-radius: 4px; padding: 2px; }
.crop-box input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; }

/* Модальное окно "О программе" */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    background: rgba(0,0,0,0.75); backdrop-filter: blur(5px); z-index: 2000;
    align-items: center; justify-content: center;
}
.modal-content {
    background: #1e1e20; border: 1px solid #3a3a3c; padding: 30px; border-radius: 12px;
    max-width: 450px; width: 90%; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.6);
}
.modal-content h2 { margin-bottom: 15px; font-size: 20px; color: #0078d4; }
.modal-content p { font-size: 14px; color: #ccc; line-height: 1.6; margin-bottom: 10px; text-align: left; }
.modal-content .close-modal-btn { background: #0078d4; color: white; border: none; padding: 10px 25px; border-radius: 6px; cursor: pointer; font-weight: bold; margin-top: 15px; width: auto; }
.modal-content .close-modal-btn:hover { background: #106ebe; }

/* ===================== АДАПТИВ ===================== */
@media (max-width: 768px) {
    body { overflow-y: auto; }
    #app-screen { height: auto; min-height: 100vh; }

    #room-tag {
        top: 10px; left: 10px; font-size: 12px; padding: 6px 10px;
    }

    #video-grid {
        height: auto;
        min-height: calc(100vh - 70px);
        padding: 10px;
        padding-bottom: 80px;
        gap: 8px;
        align-content: start;
        overflow-y: auto;
    }

    .video-container {
        aspect-ratio: 16 / 9;
        min-height: 140px;
    }

    /* 1–4 участника: 2 колонки, если много — скролл */
    #video-grid.show-1 { grid-template-columns: 1fr; }
    #video-grid.show-2 { grid-template-columns: repeat(2, 1fr); }
    #video-grid.show-3, #video-grid.show-4 { grid-template-columns: repeat(2, 1fr); }

    /* Панель — всегда видна, компактнее */
    #panel-trigger { display: none; }
    #control-panel {
        bottom: 0;
        padding: 10px 15px;
        gap: 8px;
        flex-wrap: wrap;
        justify-content: center;
        border-radius: 12px 12px 0 0;
        max-width: 100vw;
    }
    .circle-btn { width: 44px; height: 44px; font-size: 16px; }
    .crop-box { display: none; } /* на мобильном скрываем — некуда */
}

@media (max-width: 380px) {
    .circle-btn { width: 40px; height: 40px; font-size: 14px; }
    #control-panel { padding: 8px 10px; gap: 6px; }
}

/* Модальное окно лицензии */
#license-modal .modal-content {
    max-width: 420px;
}
#license-modal code {
    font-family: 'Consolas', 'Courier New', monospace;
    color: #00ff88;
}
#license-modal .close-modal-btn {
    width: auto;
    padding: 10px 18px;
    font-size: 14px;
}
