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

:root {
    --bg: #0b0d11;
    --bg-gradient: linear-gradient(135deg, #0b0d11 0%, #111827 50%, #0f172a 100%);
    --surface: rgba(17, 24, 39, 0.85);
    --surface-solid: #111827;
    --surface-2: rgba(30, 41, 59, 0.7);
    --surface-3: rgba(51, 65, 85, 0.5);
    --border: rgba(71, 85, 105, 0.4);
    --border-focus: rgba(99, 102, 241, 0.6);
    --text: #e2e8f0;
    --text-dim: #94a3b8;
    --text-muted: #64748b;
    --primary: #6366f1;
    --primary-hover: #818cf8;
    --primary-glow: rgba(99, 102, 241, 0.25);
    --danger: #ef4444;
    --danger-hover: #f87171;
    --success: #10b981;
    --warning: #f59e0b;
    --msg-local: linear-gradient(135deg, #4338ca, #6366f1);
    --msg-remote: rgba(30, 41, 59, 0.9);
    --font: 'Inter', 'Segoe UI', system-ui, -apple-system, sans-serif;
    --mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 20px;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --glass-bg: rgba(17, 24, 39, 0.6);
    --glass-border: rgba(148, 163, 184, 0.1);
}

html, body {
    height: 100%;
    font-family: var(--font);
    background: var(--bg);
    background-image: var(--bg-gradient);
    color: var(--text);
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* === Animated Background === */
body::before {
    content: '';
    position: fixed;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background:
        radial-gradient(ellipse at 20% 50%, rgba(99, 102, 241, 0.08) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(139, 92, 246, 0.06) 0%, transparent 50%),
        radial-gradient(ellipse at 40% 80%, rgba(59, 130, 246, 0.05) 0%, transparent 50%);
    animation: bgShift 20s ease-in-out infinite alternate;
    pointer-events: none;
    z-index: 0;
}

@keyframes bgShift {
    0% { transform: translate(0, 0) rotate(0deg); }
    100% { transform: translate(-5%, -3%) rotate(2deg); }
}

/* === Developer Tools Warning === */
.devtools-warning {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: linear-gradient(90deg, #dc2626, #ef4444);
    color: #fff;
    text-align: center;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 600;
    z-index: 10000;
    letter-spacing: 0.5px;
    backdrop-filter: blur(8px);
}

/* === Screens === */
.screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    position: relative;
    z-index: 1;
}

/* === Landing === */
.landing-container {
    text-align: center;
    padding: 48px 40px;
    max-width: 480px;
    width: 90%;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.6s ease-out;
}

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

.landing-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 88px;
    height: 88px;
    border-radius: 50%;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.15), rgba(139, 92, 246, 0.15));
    border: 1px solid rgba(99, 102, 241, 0.2);
    margin-bottom: 24px;
    color: var(--primary);
    animation: iconPulse 3s ease-in-out infinite;
}

@keyframes iconPulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(99, 102, 241, 0.2); }
    50% { box-shadow: 0 0 0 12px rgba(99, 102, 241, 0); }
}

.landing-title {
    font-size: 2rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #e2e8f0, #94a3b8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.landing-subtitle {
    color: var(--text-dim);
    margin-bottom: 20px;
    font-size: 0.9rem;
    line-height: 1.5;
}

.landing-features {
    display: flex;
    gap: 8px;
    justify-content: center;
    flex-wrap: wrap;
    margin-bottom: 32px;
}

.feature-tag {
    padding: 4px 12px;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.2);
    border-radius: 20px;
    font-size: 0.75rem;
    color: var(--primary-hover);
    font-weight: 500;
    letter-spacing: 0.3px;
}

.landing-buttons {
    display: flex;
    gap: 12px;
    justify-content: center;
}

/* === Buttons === */
.btn {
    padding: 12px 28px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    font-family: var(--font);
    position: relative;
    overflow: hidden;
}

.btn:hover {
    transform: translateY(-1px);
}

.btn:active {
    transform: translateY(0);
    scale: 0.98;
}

.btn-primary {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3);
}

.btn-primary:hover {
    background: linear-gradient(135deg, #818cf8, #a78bfa);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.4);
}

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
    backdrop-filter: blur(8px);
}

.btn-secondary:hover {
    background: var(--surface-3);
    border-color: var(--text-muted);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
    border-color: rgba(239, 68, 68, 0.5);
}

.btn-text {
    background: none;
    color: var(--text-dim);
    padding: 8px 16px;
    font-size: 0.85rem;
}

.btn-text:hover {
    color: var(--text);
    background: none;
    transform: none;
}

.btn-small {
    padding: 6px 14px;
    font-size: 0.8rem;
}

/* === Screen Icons === */
.screen-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(99, 102, 241, 0.1);
    border: 1px solid rgba(99, 102, 241, 0.15);
    margin-bottom: 20px;
    color: var(--primary);
}

/* === Create Screen === */
.create-container, .join-container {
    max-width: 520px;
    width: 90%;
    text-align: center;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 40px 36px;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.5s ease-out;
}

.create-container h2, .join-container h2 {
    margin-bottom: 16px;
    font-size: 1.4rem;
    font-weight: 700;
}

.room-id-display {
    margin-bottom: 16px;
    font-family: var(--mono);
    font-size: 1rem;
    color: var(--primary-hover);
    background: rgba(99, 102, 241, 0.08);
    padding: 8px 16px;
    border-radius: var(--radius-sm);
    display: inline-block;
}

.security-warning {
    background: rgba(245, 158, 11, 0.08);
    border: 1px solid rgba(245, 158, 11, 0.2);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 20px;
    font-size: 0.85rem;
    color: var(--warning);
    line-height: 1.5;
}

.mnemonic-display {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 12px;
    font-family: var(--mono);
    font-size: 0.85rem;
    line-height: 2;
    word-spacing: 4px;
    user-select: text;
    position: relative;
    overflow: hidden;
    text-align: left;
}

.mnemonic-display::after {
    content: 'CONFIDENTIAL';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-25deg);
    font-size: 3rem;
    color: rgba(255, 255, 255, 0.025);
    font-weight: 800;
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 8px;
}

.mnemonic-timer {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 20px;
}

.create-actions {
    display: flex;
    gap: 12px;
    justify-content: center;
    align-items: center;
}

/* === Join Screen === */
.input-group {
    margin-bottom: 16px;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.8rem;
    color: var(--text-dim);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.input-group input,
.input-group textarea {
    width: 100%;
    padding: 12px 16px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--mono);
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s ease;
}

.input-group input:focus,
.input-group textarea:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-group textarea {
    resize: vertical;
    min-height: 80px;
}

.join-container .btn-primary {
    width: 100%;
    margin-top: 8px;
    margin-bottom: 8px;
}

/* === Connecting Screen === */
.connecting-container {
    text-align: center;
    background: var(--glass-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: 48px 40px;
    box-shadow: var(--shadow-lg);
    animation: fadeInUp 0.5s ease-out;
}

.connecting-title {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.spinner {
    width: 44px;
    height: 44px;
    border: 3px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 24px;
}

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

.connection-status {
    color: var(--text-dim);
    font-size: 0.85rem;
}

/* === Chat Screen === */
#chat-screen {
    flex-direction: column;
    align-items: stretch;
    justify-content: stretch;
    background: var(--bg);
}

.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--glass-border);
    z-index: 10;
}

.chat-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.chat-lock-icon {
    color: var(--success);
    flex-shrink: 0;
}

.chat-title {
    font-weight: 600;
    font-size: 1rem;
    letter-spacing: -0.3px;
}

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.message {
    max-width: 72%;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.55;
    position: relative;
    overflow: hidden;
    word-break: break-word;
    animation: msgFadeIn 0.3s ease-out;
}

@keyframes msgFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.97);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message::after {
    content: 'CONFIDENTIAL';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-20deg);
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.02);
    font-weight: 800;
    pointer-events: none;
    white-space: nowrap;
    letter-spacing: 4px;
}

.message.local {
    align-self: flex-end;
    background: var(--msg-local);
    color: #fff;
    border-bottom-right-radius: 4px;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.2);
}

.message.remote {
    align-self: flex-start;
    background: var(--msg-remote);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.message .msg-text {
    user-select: text;
}

.message .msg-time {
    font-size: 0.65rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 6px;
    text-align: right;
}

.message.remote .msg-time {
    color: var(--text-muted);
}

.message.system {
    align-self: center;
    background: none;
    color: var(--text-muted);
    font-size: 0.78rem;
    font-style: italic;
    max-width: 90%;
    padding: 8px 0;
    text-align: center;
}

.message.system::after {
    display: none;
}

/* === Input Area === */
.input-area {
    display: flex;
    padding: 16px 24px;
    gap: 12px;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-top: 1px solid var(--glass-border);
    align-items: center;
}

.input-area input {
    flex: 1;
    padding: 12px 18px;
    background: rgba(15, 23, 42, 0.5);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    font-family: var(--font);
    transition: all 0.2s ease;
}

.input-area input:focus {
    border-color: var(--border-focus);
    box-shadow: 0 0 0 3px var(--primary-glow);
}

.input-area input::placeholder {
    color: var(--text-muted);
}

.btn-send {
    width: 46px;
    height: 46px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
    box-shadow: 0 2px 12px rgba(99, 102, 241, 0.3);
}

.btn-send:hover {
    background: linear-gradient(135deg, #818cf8, #a78bfa);
    box-shadow: 0 4px 20px rgba(99, 102, 241, 0.5);
    transform: scale(1.05);
}

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

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

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* === Responsive === */
@media (max-width: 600px) {
    .landing-container,
    .create-container,
    .join-container,
    .connecting-container {
        padding: 32px 24px;
        border-radius: var(--radius);
    }

    .landing-title {
        font-size: 1.6rem;
    }

    .landing-buttons {
        flex-direction: column;
    }

    .landing-features {
        gap: 6px;
    }

    .feature-tag {
        font-size: 0.7rem;
        padding: 3px 10px;
    }

    .message {
        max-width: 88%;
    }

    .messages {
        padding: 16px;
    }

    .input-area {
        padding: 12px 16px;
    }

    .chat-header {
        padding: 12px 16px;
    }

    .create-actions {
        flex-direction: column;
    }

    .create-actions .btn {
        width: 100%;
    }
}

/* === Selection === */
::selection {
    background: rgba(99, 102, 241, 0.3);
    color: #fff;
}
