/* ═══════════════════════════════════════════════════════
   CkChat — Cinematic Dark Communication UI
   ═══════════════════════════════════════════════════════ */

:root {
    --bg-deep: #08090c;
    --bg: #0d0f14;
    --bg-surface: #14171f;
    --bg-elevated: #1a1e28;
    --bg-hover: #1f2430;
    --bg-glass: rgba(20, 23, 31, 0.75);

    --border: rgba(255, 255, 255, 0.06);
    --border-subtle: rgba(255, 255, 255, 0.03);
    --border-focus: rgba(232, 178, 80, 0.4);

    --text: #e8e6e1;
    --text-secondary: #9a978f;
    --text-muted: #5c5a55;

    --gold: #e8b250;
    --gold-dim: #c49338;
    --gold-glow: rgba(232, 178, 80, 0.15);
    --gold-bright: #f0c866;

    --green: #4ade80;
    --green-dim: rgba(74, 222, 128, 0.15);
    --red: #f87171;
    --red-dim: rgba(248, 113, 113, 0.15);
    --blue: #60a5fa;

    --radius: 10px;
    --radius-lg: 14px;
    --radius-xl: 20px;

    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow: 0 4px 16px rgba(0,0,0,.4);
    --shadow-lg: 0 8px 32px rgba(0,0,0,.5);
}

body {
    background: var(--bg-deep);
    color: var(--text);
}

/* ── Utility ─────────────────────────────────────────── */

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes slideIn {
    from { opacity: 0; transform: translateX(16px); }
    to { opacity: 1; transform: translateX(0); }
}

/* ── Header ──────────────────────────────────────────── */

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.5rem;
    height: 56px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    position: relative;
    z-index: 20;
}

header::after {
    content: "";
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--gold-glow), transparent);
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    text-decoration: none;
    font-weight: 700;
    font-size: var(--text-lg);
    color: var(--text);
    letter-spacing: var(--tracking-tight);
}

.logo-mark {
    width: 28px;
    height: 28px;
    background: linear-gradient(135deg, var(--gold), var(--gold-dim));
    border-radius: 7px;
    display: grid;
    place-items: center;
    color: var(--bg-deep);
    font-weight: 700;
    font-size: var(--text-sm);
    box-shadow: 0 2px 8px rgba(232, 178, 80, 0.25);
}

.header-user {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    animation: fadeIn 0.4s ease;
}

.user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 1.5px solid var(--border);
    display: grid;
    place-items: center;
    font-weight: 600;
    font-size: var(--text-sm);
    color: var(--gold);
    text-transform: uppercase;
    flex-shrink: 0;
}

.user-name {
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
}

/* ── Landing ─────────────────────────────────────────── */

.landing {
    max-width: 540px;
    margin: 0 auto;
    padding: 3rem 1.5rem 4rem;
}

.landing-hero {
    text-align: center;
    margin-bottom: 2.5rem;
    animation: fadeUp 0.5s ease;
}

.landing-hero h1 {
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--text), var(--text-secondary));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.landing-hero p {
    color: var(--text-muted);
    font-size: var(--text-base);
}

/* ── Identity section ──────────────────────────────── */

.identity-section {
    animation: fadeUp 0.5s ease 0.1s both;
    margin-bottom: 2rem;
}

.identity-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    align-items: center;
    gap: 1rem;
    transition: border-color 0.2s;
}

.identity-card:focus-within {
    border-color: var(--border-focus);
}

.identity-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--bg-elevated);
    border: 2px solid var(--border);
    display: grid;
    place-items: center;
    font-weight: 700;
    font-size: var(--text-xl);
    color: var(--gold);
    text-transform: uppercase;
    flex-shrink: 0;
    transition: all 0.3s;
}

.identity-avatar.has-name {
    background: linear-gradient(135deg, var(--gold-glow), transparent);
    border-color: var(--gold-dim);
}

.identity-input {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.identity-input label {
    color: var(--text-muted);
    font-size: var(--text-xs);
}

.identity-input input {
    background: transparent;
    border: none;
    color: var(--text);
    font-size: var(--text-lg);
    font-weight: 500;
    outline: none;
    padding: 0;
}

.identity-input input::placeholder {
    color: var(--text-muted);
    font-weight: 400;
}

/* ── Sections ──────────────────────────────────────── */

.section-label {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    margin-bottom: 0.75rem;
    color: var(--text-muted);
    font-size: var(--text-xs);
    font-weight: 600;
    letter-spacing: var(--tracking-wide);
    text-transform: uppercase;
}

.section-label::after {
    content: "";
    flex: 1;
    height: 1px;
    background: var(--border);
}

/* ── Create room ─────────────────────────────────────── */

.create-section {
    animation: fadeUp 0.5s ease 0.2s both;
    margin-bottom: 2rem;
}

.create-form {
    display: flex;
    gap: 0.5rem;
}

.create-form input {
    flex: 1;
    padding: 0.6875rem 0.875rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: var(--text-base);
    transition: border-color 0.2s;
    outline: none;
}

.create-form input:focus {
    border-color: var(--border-focus);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.6875rem 1.125rem;
    font-size: var(--text-sm);
    font-weight: 600;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
    text-decoration: none;
}

.btn-gold {
    background: linear-gradient(135deg, var(--gold), var(--gold-dim));
    color: var(--bg-deep);
    box-shadow: 0 2px 8px rgba(232, 178, 80, 0.2);
}

.btn-gold:hover {
    box-shadow: 0 4px 16px rgba(232, 178, 80, 0.3);
    transform: translateY(-1px);
}

.btn-gold:active {
    transform: translateY(0);
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

/* ── Room list ───────────────────────────────────────── */

.rooms-section {
    animation: fadeUp 0.5s ease 0.3s both;
}

.room-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.room-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.125rem;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    cursor: pointer;
    transition: all 0.2s;
    animation: fadeUp 0.3s ease both;
}

.room-card:hover {
    background: var(--bg-elevated);
    border-color: rgba(255, 255, 255, 0.1);
    transform: translateY(-1px);
    box-shadow: var(--shadow);
}

.room-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--bg-elevated);
    display: grid;
    place-items: center;
    flex-shrink: 0;
}

.room-icon svg {
    width: 18px;
    height: 18px;
    color: var(--text-secondary);
}

.room-info {
    flex: 1;
    min-width: 0;
}

.room-name {
    font-weight: 600;
    font-size: var(--text-base);
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.room-meta {
    font-size: var(--text-xs);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 0.375rem;
    margin-top: 0.125rem;
}

.online-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--green);
    animation: pulse 2s ease infinite;
}

.room-join {
    padding: 0.4375rem 0.875rem;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.room-card:hover .room-join {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--bg-deep);
}

.empty-state {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-muted);
    font-size: var(--text-sm);
}

.empty-state svg {
    width: 40px;
    height: 40px;
    margin: 0 auto 0.75rem;
    color: var(--text-muted);
    opacity: 0.4;
}

/* ── Name required toast ─────────────────────────────── */

.name-required {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 0.625rem 1rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: var(--text-sm);
    color: var(--gold);
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
    z-index: 50;
}

.name-required.show {
    transform: translateX(-50%) translateY(0);
}

/* ═══════════════════════════════════════════════════════
   Room View
   ═══════════════════════════════════════════════════════ */

.room-view {
    display: flex;
    flex-direction: column;
    height: calc(100svh - 56px);
    background: var(--bg-deep);
}

/* ── Room toolbar ────────────────────────────────────── */

.room-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    height: 52px;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.room-title {
    display: flex;
    align-items: center;
    gap: 0.625rem;
}

.room-title h1 {
    font-size: var(--text-lg);
    font-weight: 600;
}

.room-title .peer-count {
    padding: 0.125rem 0.5rem;
    background: var(--bg-elevated);
    border-radius: 999px;
    font-size: var(--text-xs);
    color: var(--text-muted);
    font-weight: 500;
}

.controls {
    display: flex;
    align-items: center;
    gap: 0.375rem;
}

.ctrl-btn {
    width: 38px;
    height: 38px;
    display: grid;
    place-items: center;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    color: var(--text-secondary);
    padding: 0;
}

.ctrl-btn svg {
    width: 18px;
    height: 18px;
}

.ctrl-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}

.ctrl-btn.active {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--bg-deep);
    box-shadow: 0 2px 8px rgba(232, 178, 80, 0.2);
}

.ctrl-btn.leave {
    background: transparent;
    border-color: var(--red);
    color: var(--red);
}

.ctrl-btn.leave:hover {
    background: var(--red-dim);
}

.ctrl-divider {
    width: 1px;
    height: 24px;
    background: var(--border);
    margin: 0 0.25rem;
}

/* ── Room body ───────────────────────────────────────── */

.room-body {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ── Video grid ──────────────────────────────────────── */

.video-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 0.625rem;
    padding: 0.625rem;
    align-content: start;
    overflow-y: auto;
}

.video-tile {
    position: relative;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    aspect-ratio: 16 / 9;
    border: 1px solid var(--border);
    animation: fadeUp 0.3s ease;
}

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

.video-tile.local {
    border-color: rgba(232, 178, 80, 0.15);
}

.video-label {
    position: absolute;
    bottom: 0.625rem;
    left: 0.625rem;
    padding: 0.25rem 0.625rem;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    border-radius: 6px;
    font-size: var(--text-xs);
    font-weight: 500;
    color: #fff;
}

/* ── Chat panel ──────────────────────────────────────── */

.chat-panel {
    width: 320px;
    border-left: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    background: var(--bg);
    animation: slideIn 0.25s ease;
}

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

.chat-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.chat-header svg {
    width: 14px;
    height: 14px;
    color: var(--text-muted);
}

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

.chat-messages::-webkit-scrollbar {
    width: 4px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 2px;
}

.chat-msg {
    padding: 0.5rem 0.75rem;
    border-radius: 8px;
    font-size: var(--text-sm);
    line-height: 1.45;
    animation: fadeUp 0.2s ease;
}

.chat-msg .chat-author {
    font-weight: 600;
    color: var(--gold);
    margin-right: 0.375rem;
}

.chat-msg .chat-time {
    font-size: var(--text-xs);
    color: var(--text-muted);
    float: right;
    font-family: var(--font-mono);
    margin-top: 0.125rem;
}

.chat-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid var(--border);
    background: var(--bg-surface);
}

.chat-form input {
    flex: 1;
    padding: 0.5625rem 0.75rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: var(--text-sm);
    outline: none;
    transition: border-color 0.2s;
}

.chat-form input:focus {
    border-color: var(--border-focus);
}

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

.chat-form button {
    padding: 0.5625rem 0.875rem;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.chat-form button:hover {
    background: var(--gold);
    border-color: var(--gold);
    color: var(--bg-deep);
}

/* ═══════════════════════════════════════════════════════
   Responsive
   ═══════════════════════════════════════════════════════ */

@media (max-width: 768px) {
    .landing {
        padding: 2rem 1rem 3rem;
    }

    .landing-hero h1 {
        font-size: var(--text-2xl);
    }

    .room-toolbar {
        padding: 0 0.75rem;
        height: 48px;
    }

    .room-title h1 {
        font-size: var(--text-base);
    }

    .controls {
        gap: 0.25rem;
    }

    .ctrl-btn {
        width: 34px;
        height: 34px;
    }

    .ctrl-btn svg {
        width: 16px;
        height: 16px;
    }

    .video-grid {
        grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
        gap: 0.375rem;
        padding: 0.375rem;
    }

    .chat-panel {
        position: fixed;
        top: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        z-index: 30;
        background: var(--bg);
    }

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

@media (max-width: 480px) {
    .create-form {
        flex-direction: column;
    }

    .room-card {
        padding: 0.875rem;
    }

    .room-icon {
        width: 36px;
        height: 36px;
    }
}
