/* ========================================
   P2P Connect - Serverless Video Chat
   CSS Styles
   ======================================== */

:root {
    --primary: #6366F1;
    --primary-hover: #4F46E5;
    --secondary: #1E1E2E;
    --accent: #22C55E;
    --background: #0F0F1A;
    --surface: #1A1A2E;
    --surface-elevated: #252540;
    --text-primary: #FFFFFF;
    --text-secondary: #A1A1AA;
    --text-muted: #71717A;
    --error: #EF4444;
    --warning: #F59E0B;
    --border-radius-sm: 8px;
    --border-radius-md: 12px;
    --border-radius-lg: 24px;
    --shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    --transition: all 0.2s ease;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

/* Background Pattern */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background:
        radial-gradient(circle at 20% 80%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(34, 197, 94, 0.1) 0%, transparent 50%),
        linear-gradient(180deg, var(--background) 0%, #0a0a12 100%);
    z-index: -1;
}

.app {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========================================
   Screens
   ======================================== */

.screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    min-height: 100vh;
    animation: fadeIn 0.3s ease;
}

.screen.hidden {
    display: none;
}

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

/* ========================================
   Home Screen
   ======================================== */

.logo {
    text-align: center;
    margin-bottom: 2rem;
}

.logo-icon {
    font-size: 4rem;
    margin-bottom: 0.5rem;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}

.logo h1 {
    font-size: 2rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--primary), var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.logo p {
    color: var(--text-secondary);
    margin-top: 0.25rem;
}

.connection-panel {
    background: var(--surface);
    border-radius: var(--border-radius-md);
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.my-code-section, .join-section {
    text-align: center;
}

.my-code-section h3, .join-section h3 {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 1rem;
}

.code-display {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

#my-code {
    font-size: 2rem;
    font-weight: 700;
    letter-spacing: 0.3em;
    color: var(--primary);
    font-family: 'Courier New', monospace;
}

#qr-code {
    margin: 1rem auto;
    padding: 1rem;
    background: white;
    border-radius: var(--border-radius-sm);
    display: inline-block;
}

#qr-code canvas {
    display: block;
}

.divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    color: var(--text-muted);
}

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

.divider span {
    padding: 0 1rem;
    font-size: 0.875rem;
}

input[type="text"] {
    width: 100%;
    padding: 1rem;
    border: 2px solid var(--surface-elevated);
    border-radius: var(--border-radius-md);
    background: var(--background);
    color: var(--text-primary);
    font-size: 1.25rem;
    text-align: center;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    transition: var(--transition);
    margin-bottom: 1rem;
}

input[type="text"]:focus {
    outline: none;
    border-color: var(--primary);
}

input[type="text"]::placeholder {
    letter-spacing: 0.1em;
    color: var(--text-muted);
}

.info-text {
    margin-top: 2rem;
    text-align: center;
}

.info-text p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* ========================================
   Buttons
   ======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.875rem 1.5rem;
    border-radius: var(--border-radius-lg);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    width: 100%;
    margin-bottom: 0.5rem;
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--surface-elevated);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #2f2f4a;
}

.btn-outline {
    background: transparent;
    border: 2px solid var(--surface-elevated);
    color: var(--text-secondary);
}

.btn-outline:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--border-radius-sm);
    background: var(--surface-elevated);
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    font-size: 1.25rem;
}

.icon-btn:hover {
    background: var(--primary);
    color: white;
}

/* ========================================
   Pre-Call Screen
   ======================================== */

.preview-container {
    width: 100%;
    max-width: 600px;
    aspect-ratio: 16/9;
    background: var(--surface);
    border-radius: var(--border-radius-md);
    overflow: hidden;
    position: relative;
}

#local-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    transform: scaleX(-1);
}

.preview-controls {
    position: absolute;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 0.5rem;
}

.control-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: rgba(0, 0, 0, 0.6);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.25rem;
    transition: var(--transition);
    backdrop-filter: blur(10px);
}

.control-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    transform: scale(1.1);
}

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

.control-btn.inactive {
    background: var(--error);
}

.precall-actions {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
}

.precall-actions .btn {
    width: auto;
    min-width: 150px;
}

/* ========================================
   Call Screen
   ======================================== */

.video-container {
    position: relative;
    width: 100%;
    height: calc(100vh - 100px);
    background: var(--surface);
    border-radius: var(--border-radius-md);
    overflow: hidden;
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
}

/* Both videos equal size - side by side like Omegle */
#remote-video {
    flex: 1;
    width: 50%;
    height: 100%;
    object-fit: cover;
    background: #000;
    border-radius: var(--border-radius-sm);
}

.local-video-wrapper {
    width: 50%;
    height: 100%;
    border-radius: var(--border-radius-sm);
    overflow: hidden;
    box-shadow: var(--shadow);
    cursor: move;
    transition: transform 0.2s ease;
    flex-shrink: 0;
}

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

.pip-controls {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    opacity: 0;
    transition: var(--transition);
}

.local-video-wrapper:hover .pip-controls {
    opacity: 1;
}

.call-info {
    position: absolute;
    top: 1rem;
    left: 1rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    background: rgba(0, 0, 0, 0.6);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-lg);
    backdrop-filter: blur(10px);
}

#call-timer {
    font-family: 'Courier New', monospace;
    font-size: 1rem;
}

.status {
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.status.connected {
    color: var(--accent);
}

.status.connecting {
    color: var(--warning);
}

.status.failed {
    color: var(--error);
}

.screen-share-indicator {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: var(--primary);
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius-lg);
    font-size: 0.875rem;
    animation: pulse 2s infinite;
}

.screen-share-indicator.hidden {
    display: none;
}

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

.call-controls {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 0.75rem;
    padding: 1rem;
    background: linear-gradient(to top, rgba(0, 0, 0, 0.8), transparent);
}

.call-controls .control-btn {
    width: 56px;
    height: 56px;
}

.call-controls .end-call {
    background: var(--error);
}

.call-controls .end-call:hover {
    background: #dc2626;
}

/* ========================================
   Modals
   ======================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--surface);
    border-radius: var(--border-radius-md);
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--surface-elevated);
}

.modal-header h2 {
    font-size: 1.25rem;
}

.modal-body {
    padding: 1.5rem;
}

.setting-group {
    margin-bottom: 1.5rem;
}

.setting-group label {
    display: block;
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin-bottom: 0.5rem;
}

.setting-group select {
    width: 100%;
    padding: 0.75rem;
    background: var(--background);
    border: 1px solid var(--surface-elevated);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-size: 1rem;
}

.setting-group input[type="checkbox"] {
    margin-right: 0.5rem;
}

.background-options {
    display: flex;
    gap: 0.5rem;
}

.bg-option {
    flex: 1;
    padding: 0.75rem;
    background: var(--background);
    border: 2px solid var(--surface-elevated);
    border-radius: var(--border-radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.bg-option.active {
    border-color: var(--primary);
    color: var(--primary);
}

.bg-option:hover {
    border-color: var(--primary);
}

textarea {
    width: 100%;
    height: 100px;
    padding: 0.75rem;
    background: var(--background);
    border: 1px solid var(--surface-elevated);
    border-radius: var(--border-radius-sm);
    color: var(--text-primary);
    font-family: monospace;
    font-size: 0.875rem;
    resize: vertical;
}

textarea:focus {
    outline: none;
    border-color: var(--primary);
}

/* ========================================
   Toast Notifications
   ======================================== */

.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: var(--surface-elevated);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow);
    z-index: 2000;
    animation: slideUp 0.3s ease;
}

.toast.hidden {
    display: none;
}

.toast.success {
    border-left: 4px solid var(--accent);
}

.toast.error {
    border-left: 4px solid var(--error);
}

.toast.info {
    border-left: 4px solid var(--primary);
}

@keyframes slideUp {
    from { transform: translateX(-50%) translateY(100%); opacity: 0; }
    to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ========================================
   QR Reader
   ======================================== */

#qr-reader {
    width: 100%;
    aspect-ratio: 1;
    background: var(--background);
    border-radius: var(--border-radius-sm);
    overflow: hidden;
}

#qr-reader video {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

#scanner-status {
    text-align: center;
    color: var(--text-secondary);
    margin-top: 1rem;
}

/* ========================================
   Recording Indicator
   ======================================== */

.recording .control-btn#record-btn {
    background: var(--error);
    animation: recordPulse 1s infinite;
}

@keyframes recordPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 10px rgba(239, 68, 68, 0); }
}

/* ========================================
   Responsive
   ======================================== */

@media (max-width: 640px) {
    .screen {
        padding: 1rem;
    }

    .connection-panel {
        padding: 1.5rem;
    }

    .logo h1 {
        font-size: 1.5rem;
    }

    #my-code {
        font-size: 1.5rem;
    }

    .call-controls {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .call-controls .control-btn {
        width: 48px;
        height: 48px;
        font-size: 1rem;
    }

    /* On mobile: stack videos vertically */
    .video-container {
        flex-direction: column;
    }

    .local-video-wrapper {
        width: 100%;
        height: 50%;
    }

    .modal-content {
        width: 95%;
        margin: 0.5rem;
    }
}

/* Fullscreen mode */
:fullscreen .video-container {
    border-radius: 0;
}

:fullscreen .call-controls {
    background: rgba(0, 0, 0, 0.5);
}

/* PiP mode - picture-in-picture */
@media (picture-in-picture: active) {
    .call-controls {
        display: none;
    }
}

/* Loading states */
.loading {
    position: relative;
    pointer-events: none;
}

.loading::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 20px;
    height: 20px;
    margin: -10px 0 0 -10px;
    border: 2px solid transparent;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========================================
   Chat Panel
   ======================================== */

.chat-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 80px;
    width: 300px;
    background: var(--surface);
    border-left: 1px solid var(--surface-elevated);
    display: flex;
    flex-direction: column;
    z-index: 100;
    animation: slideIn 0.3s ease;
}

.chat-panel.hidden {
    display: none;
}

@keyframes slideIn {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

.chat-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem;
    border-bottom: 1px solid var(--surface-elevated);
}

.chat-header h3 {
    font-size: 1rem;
    margin: 0;
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.chat-message {
    max-width: 80%;
    padding: 0.5rem 0.75rem;
    border-radius: var(--border-radius-md);
    font-size: 0.875rem;
    word-wrap: break-word;
}

.chat-message.sent {
    align-self: flex-end;
    background: var(--primary);
    color: white;
}

.chat-message.received {
    align-self: flex-start;
    background: var(--surface-elevated);
    color: var(--text-primary);
}

.chat-input {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    border-top: 1px solid var(--surface-elevated);
}

.chat-input input {
    flex: 1;
    padding: 0.5rem;
    border: 1px solid var(--surface-elevated);
    border-radius: var(--border-radius-sm);
    background: var(--background);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.chat-input input:focus {
    outline: none;
    border-color: var(--primary);
}

.chat-input .btn {
    width: auto;
    padding: 0.5rem 1rem;
    margin: 0;
}

/* Hidden utility */
.hidden {
    display: none !important;
}