:root {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --primary: #3b82f6;
    --danger: #ef4444;
    --success: #22c55e;
    --radius: 14px;
}

body {
    margin: 0;
    padding: 0;
    font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 24px 12px;
    min-height: 100vh;
}

h2 {
    margin-bottom: 16px;
    font-size: 24px;
    font-weight: 600;
    text-align: center;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 24px;
    justify-content: center;
}

input {
    padding: 10px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--text-muted);
    background: var(--bg-card);
    color: var(--text);
    font-size: 16px;
    outline: none;
}

button {
    padding: 8px 14px;
    border-radius: var(--radius);
    border: none;
    font-size: 14px;
    cursor: pointer;
    font-weight: 500;
    transition: background 0.2s, transform 0.1s;
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

button:active {
    transform: scale(0.96);
}

#join {
    background: var(--primary);
    color: #fff;
}

#leave {
    background: var(--danger);
    color: #fff;
}

#peersList {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
    width: 100%;
    max-width: 820px;
}

.peer {
    position: relative;
    background: var(--bg-card);
    border-radius: var(--radius);
    padding: 16px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    transition: transform 0.2s, box-shadow 0.2s;
}

.peer:hover {
    transform: translateY(-3px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.6);
}

.peer-id {
    font-size: 15px;
    font-weight: 500;
    text-align: center;
}

.mic {
    font-size: 26px;
    cursor: pointer;
    transition: color 0.2s, transform 0.2s;
}

.peer.talking {
    box-shadow:
        0 0 0 2px rgba(34, 197, 94, 1) inset,
        0 0 22px 8px rgba(34, 197, 94, 0.4);
}

.peer.talking::after,
.peer.talking::before {
    content: "";
    position: absolute;
    inset: -4px;
    border-radius: calc(var(--radius) + 4px);
    border: 2px solid rgba(34, 197, 94, 0.9);
    animation: pulse 1.2s infinite;
}

.peer.talking::before {
    inset: -10px;
    border-color: rgba(34, 197, 94, 0.5);
    animation-delay: 0.3s;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.9; }
    100% { transform: scale(1.25); opacity: 0; }
}

.peer.talking .mic {
    color: var(--success);
    animation: mic-bounce 0.6s infinite;
}

@keyframes mic-bounce {
    0%, 100% { transform: translateY(0) scale(1); }
    50% { transform: translateY(-3px) scale(1.15); }
}

.vu {
    width: 100%;
    height: 10px;
    background: rgba(148, 163, 184, 0.25);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 4px;
}

.vu .fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--success), var(--primary));
    transition: width 0.06s linear;
}

.peer audio {
    display: none; /* скрываем элемент, он нужен только для потока */
}

/* Кнопка микрофона внутри карточки */
.peer button.mute {
    padding: 6px 12px;
    font-size: 14px;
    border-radius: var(--radius);
    background: var(--primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    margin-top: 6px;
    transition: background 0.2s, transform 0.1s;
}

.peer button.mute:hover {
    background: #2563eb;
}

@media (max-width: 600px) {
    #peersList {
        grid-template-columns: 1fr;
        gap: 10px;
    }
}
