/* ============================================
   MeritIT — P2P Video Call · Design System
   ============================================ */

/* --- CSS Variables / Design Tokens --- */
:root {
    --font-primary: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

    /* Dark theme palette */
    --bg-primary: #0a0a12;
    --bg-secondary: #12121e;
    --bg-card: rgba(20, 20, 35, 0.65);
    --bg-card-hover: rgba(30, 30, 50, 0.75);

    --text-primary: #f0f0f5;
    --text-secondary: #8888a8;
    --text-muted: #55556a;

    --accent-primary: #6C5CE7;
    --accent-secondary: #00D2FF;
    --accent-gradient: linear-gradient(135deg, #6C5CE7, #00D2FF);
    --accent-gradient-hover: linear-gradient(135deg, #7d6ef0, #1adcff);

    --danger: #FF6B6B;
    --danger-glow: rgba(255, 107, 107, 0.35);
    --success: #00E676;
    --success-glow: rgba(0, 230, 118, 0.3);
    --warning: #FFD93D;

    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-accent: rgba(108, 92, 231, 0.4);

    --glass-bg: rgba(16, 16, 30, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;
    --radius-full: 50%;

    --transition-fast: 0.15s ease;
    --transition-base: 0.25s ease;
    --transition-slow: 0.4s cubic-bezier(0.4, 0, 0.2, 1);
}

/* --- Reset & Base --- */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-primary);
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Animated Background --- */
.bg-animation {
    position: fixed;
    inset: 0;
    z-index: 0;
    overflow: hidden;
    pointer-events: none;
}

.bg-orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.25;
    animation: orbFloat 20s ease-in-out infinite;
}

.bg-orb-1 {
    width: 500px;
    height: 500px;
    background: var(--accent-primary);
    top: -10%;
    left: -10%;
    animation-delay: 0s;
}

.bg-orb-2 {
    width: 400px;
    height: 400px;
    background: var(--accent-secondary);
    bottom: -10%;
    right: -10%;
    animation-delay: -7s;
}

.bg-orb-3 {
    width: 300px;
    height: 300px;
    background: #a855f7;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    animation-delay: -14s;
    opacity: 0.12;
}

@keyframes orbFloat {
    0%, 100% { transform: translate(0, 0) scale(1); }
    25% { transform: translate(30px, -40px) scale(1.05); }
    50% { transform: translate(-20px, 20px) scale(0.95); }
    75% { transform: translate(40px, 30px) scale(1.02); }
}

/* --- Screen Transitions --- */
.screen {
    position: fixed;
    inset: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

.screen.active {
    opacity: 1;
    visibility: visible;
}

/* --- Glass Card --- */
.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--glass-shadow);
}

/* ============================================
   LOBBY SCREEN
   ============================================ */
.lobby-container {
    width: 100%;
    max-width: 480px;
    padding: 24px;
    animation: fadeUp 0.6s ease-out;
}

@keyframes fadeUp {
    from { opacity: 0; transform: translateY(24px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Logo */
.lobby-header {
    text-align: center;
    margin-bottom: 32px;
}

.logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 14px;
    margin-bottom: 12px;
}

.logo-icon {
    width: 44px;
    height: 44px;
    animation: logoPulse 3s ease-in-out infinite;
}

@keyframes logoPulse {
    0%, 100% { filter: drop-shadow(0 0 6px rgba(108, 92, 231, 0.4)); }
    50% { filter: drop-shadow(0 0 16px rgba(108, 92, 231, 0.7)); }
}

.logo h1 {
    font-size: 28px;
    font-weight: 800;
    letter-spacing: -0.5px;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-size: 13px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
}

/* Lobby Card */
.lobby-card {
    padding: 32px;
}

.section-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1.2px;
    color: var(--text-secondary);
    margin-bottom: 10px;
}

/* ID Display */
.id-section {
    margin-bottom: 8px;
}

.id-display {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(108, 92, 231, 0.08);
    border: 1px solid var(--border-accent);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    transition: var(--transition-base);
}

.id-display:hover {
    border-color: rgba(108, 92, 231, 0.6);
    background: rgba(108, 92, 231, 0.12);
}

.peer-id-text {
    flex: 1;
    font-size: 18px;
    font-weight: 600;
    letter-spacing: 2px;
    color: var(--accent-secondary);
    font-variant-numeric: tabular-nums;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-icon {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--radius-sm);
    transition: var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    color: var(--text-primary);
    background: rgba(255, 255, 255, 0.08);
}

.btn-icon:disabled {
    opacity: 0.3;
    cursor: not-allowed;
}

.id-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Divider */
.divider {
    display: flex;
    align-items: center;
    gap: 16px;
    margin: 24px 0;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-subtle);
}

/* Connect Section */
.connect-input-group {
    display: flex;
    gap: 10px;
}

.connect-input-group input {
    flex: 1;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    font-size: 15px;
    font-family: var(--font-primary);
    color: var(--text-primary);
    outline: none;
    transition: var(--transition-base);
    letter-spacing: 1px;
}

.connect-input-group input::placeholder {
    color: var(--text-muted);
    letter-spacing: 0;
}

.connect-input-group input:focus {
    border-color: var(--accent-primary);
    background: rgba(108, 92, 231, 0.06);
    box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.15);
}

.btn-primary {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 24px;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font-primary);
    cursor: pointer;
    transition: var(--transition-base);
    white-space: nowrap;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-gradient-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.4);
}

.btn-primary:active:not(:disabled) {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Quality Selector */
.settings-section {
    margin-top: 28px;
}

.quality-selector {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
}

.quality-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 14px 8px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-base);
    color: var(--text-secondary);
    font-family: var(--font-primary);
}

.quality-btn:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(255, 255, 255, 0.12);
}

.quality-btn.active {
    background: rgba(108, 92, 231, 0.12);
    border-color: var(--accent-primary);
    color: var(--text-primary);
}

.quality-icon {
    font-size: 20px;
}

.quality-name {
    font-size: 13px;
    font-weight: 600;
}

.quality-desc {
    font-size: 10px;
    color: var(--text-muted);
}

.quality-btn.active .quality-desc {
    color: var(--text-secondary);
}

/* Footer */
.lobby-footer {
    text-align: center;
    margin-top: 24px;
}

.lobby-footer p {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================
   CALL SCREEN
   ============================================ */
.call-container {
    position: fixed;
    inset: 0;
    background: #000;
}

/* Remote Video */
.remote-video-wrapper {
    position: absolute;
    inset: 0;
}

.remote-video-wrapper video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.video-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    background: linear-gradient(135deg, #0d0d1a, #1a1a2e);
}

.placeholder-avatar {
    width: 80px;
    height: 80px;
    color: var(--text-muted);
    animation: breathe 3s ease-in-out infinite;
}

@keyframes breathe {
    0%, 100% { opacity: 0.4; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.05); }
}

.video-placeholder p {
    font-size: 14px;
    color: var(--text-secondary);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* Local Video (PiP) */
.local-video-wrapper {
    position: absolute;
    bottom: 110px;
    right: 24px;
    width: 200px;
    height: 150px;
    border-radius: var(--radius-md);
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, 0.15);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 10;
    transition: var(--transition-base);
    cursor: grab;
}

.local-video-wrapper:hover {
    border-color: rgba(108, 92, 231, 0.5);
    box-shadow: 0 8px 32px rgba(108, 92, 231, 0.2);
}

.local-video-wrapper video {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

/* Network Stats Overlay */
.network-stats {
    position: absolute;
    top: 16px;
    left: 16px;
    display: flex;
    gap: 16px;
    padding: 10px 16px;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-sm);
    border: 1px solid rgba(255, 255, 255, 0.08);
    z-index: 10;
    transition: var(--transition-base);
}

.network-stats.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
}

.stat-label {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    font-weight: 500;
}

.stat-value {
    font-size: 13px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
}

/* Connection Quality */
.connection-quality {
    position: absolute;
    top: 16px;
    right: 16px;
    display: flex;
    align-items: flex-end;
    gap: 3px;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(12px);
    border-radius: var(--radius-sm);
    z-index: 10;
    height: 40px;
}

.quality-bar {
    width: 5px;
    border-radius: 2px;
    background: var(--text-muted);
    transition: var(--transition-base);
}

.quality-bar:nth-child(1) { height: 6px; }
.quality-bar:nth-child(2) { height: 10px; }
.quality-bar:nth-child(3) { height: 14px; }
.quality-bar:nth-child(4) { height: 18px; }

/* Quality states */
.connection-quality.excellent .quality-bar { background: var(--success); }
.connection-quality.good .quality-bar:nth-child(-n+3) { background: var(--success); }
.connection-quality.fair .quality-bar:nth-child(-n+2) { background: var(--warning); }
.connection-quality.poor .quality-bar:nth-child(1) { background: var(--danger); }

/* Call Timer */
.call-timer {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 18px;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(12px);
    border-radius: 20px;
    z-index: 10;
    font-size: 14px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: 0.5px;
}

.timer-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    animation: timerBlink 1.5s ease-in-out infinite;
}

@keyframes timerBlink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

/* Controls Bar */
.controls-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    padding: 20px 24px 32px;
    background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
    z-index: 10;
}

.controls-group {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: rgba(20, 20, 35, 0.7);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-xl);
}

.control-btn {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-full);
    border: none;
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-base);
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.15);
    transform: scale(1.08);
}

.control-btn:active {
    transform: scale(0.95);
}

.control-btn.active {
    background: var(--accent-primary);
    color: white;
}

.control-btn.muted {
    background: rgba(255, 107, 107, 0.2);
    color: var(--danger);
}

.control-btn.hang-up {
    width: 60px;
    height: 52px;
    border-radius: 26px;
    background: var(--danger);
    color: white;
    margin-left: 8px;
}

.control-btn.hang-up:hover {
    background: #ff5252;
    box-shadow: 0 4px 20px var(--danger-glow);
}

/* ============================================
   INCOMING CALL MODAL
   ============================================ */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-slow);
}

.modal.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    z-index: 1;
    padding: 40px;
    text-align: center;
    min-width: 340px;
    animation: modalPop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes modalPop {
    from { opacity: 0; transform: scale(0.85) translateY(20px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* Incoming call animation */
.incoming-call-animation {
    position: relative;
    width: 100px;
    height: 100px;
    margin: 0 auto 24px;
}

.ring-pulse {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    border: 2px solid var(--accent-primary);
    animation: ringExpand 2s ease-out infinite;
}

.ring-pulse-2 {
    animation-delay: 0.6s;
}

@keyframes ringExpand {
    0% { transform: scale(0.8); opacity: 0.8; }
    100% { transform: scale(1.6); opacity: 0; }
}

.caller-avatar {
    position: absolute;
    inset: 15px;
    border-radius: 50%;
    background: rgba(108, 92, 231, 0.15);
    border: 2px solid var(--accent-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-secondary);
}

.modal-content h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 8px;
}

.modal-content p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 28px;
}

.modal-actions {
    display: flex;
    gap: 16px;
    justify-content: center;
}

.btn-decline,
.btn-accept {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 14px 28px;
    border: none;
    border-radius: var(--radius-xl);
    font-size: 15px;
    font-weight: 600;
    font-family: var(--font-primary);
    cursor: pointer;
    transition: var(--transition-base);
}

.btn-decline {
    background: rgba(255, 107, 107, 0.15);
    color: var(--danger);
    border: 1px solid rgba(255, 107, 107, 0.3);
}

.btn-decline:hover {
    background: var(--danger);
    color: white;
    box-shadow: 0 4px 20px var(--danger-glow);
}

.btn-accept {
    background: var(--accent-gradient);
    color: white;
}

.btn-accept:hover {
    box-shadow: 0 4px 20px rgba(108, 92, 231, 0.4);
    transform: translateY(-1px);
}

/* ============================================
   TOAST
   ============================================ */
.toast {
    position: fixed;
    bottom: 32px;
    left: 50%;
    transform: translateX(-50%) translateY(0);
    padding: 12px 24px;
    background: rgba(20, 20, 35, 0.9);
    backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    z-index: 200;
    transition: var(--transition-base);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.toast.hidden {
    opacity: 0;
    visibility: hidden;
    transform: translateX(-50%) translateY(16px);
}

/* ============================================
   UTILITY CLASSES
   ============================================ */
.hidden {
    display: none !important;
}

/* For the stats toggle, override display:none with visibility-based hiding */
.network-stats.hidden {
    display: flex !important;
    opacity: 0;
    visibility: hidden;
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 520px) {
    .lobby-container {
        padding: 16px;
    }

    .lobby-card {
        padding: 24px 20px;
    }

    .logo h1 {
        font-size: 24px;
    }

    .peer-id-text {
        font-size: 15px;
    }

    .connect-input-group {
        flex-direction: column;
    }

    .btn-primary {
        justify-content: center;
    }

    .quality-selector {
        gap: 6px;
    }

    .quality-btn {
        padding: 10px 6px;
    }

    .local-video-wrapper {
        width: 130px;
        height: 100px;
        bottom: 100px;
        right: 12px;
    }

    .controls-group {
        gap: 6px;
        padding: 8px 12px;
    }

    .control-btn {
        width: 44px;
        height: 44px;
    }

    .control-btn.hang-up {
        width: 52px;
        height: 44px;
    }

    .network-stats {
        gap: 10px;
        padding: 8px 12px;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}
