:root {
    /* Premium Color Palette - Studio Dark */
    --primary: #6366f1;
    --primary-glow: rgba(99, 102, 241, 0.4);
    --secondary: #ec4899;
    --accent: #10b981;

    --bg-base: #030712;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;

    --glass-bg: rgba(17, 24, 39, 0.6);
    --glass-border: rgba(255, 255, 255, 0.08);
    --glass-edge: rgba(255, 255, 255, 0.05);

    --card-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    --font-head: 'Outfit', sans-serif;
    --font-body: 'Inter', sans-serif;
}

[data-theme="light"] {
    --bg-base: #f8fafc;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --glass-bg: rgba(255, 255, 255, 0.7);
    --glass-border: rgba(0, 0, 0, 0.05);
    --glass-edge: rgba(0, 0, 0, 0.02);
    --card-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-base);
    color: var(--text-main);
    font-family: var(--font-body);
    min-height: 100vh;
    overflow-x: hidden;
    line-height: 1.5;
}

/* --- Premium Background & Orbs --- */
.app-wrapper {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    z-index: 1;
}

.orb-container {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    z-index: -2;
    pointer-events: none;
}

.orb {
    position: absolute;
    border-radius: 50%;
    filter: blur(80px);
    opacity: 0.4;
    animation: orbFloat 20s infinite alternate ease-in-out;
}

.orb-1 {
    width: 40vw;
    height: 40vw;
    background: radial-gradient(circle, var(--primary), transparent);
    top: -10%;
    left: -10%;
}

.orb-2 {
    width: 35vw;
    height: 35vw;
    background: radial-gradient(circle, var(--secondary), transparent);
    bottom: -5%;
    right: -5%;
    animation-delay: -5s;
}

.orb-3 {
    width: 30vw;
    height: 30vw;
    background: radial-gradient(circle, var(--accent), transparent);
    top: 40%;
    left: 40%;
    opacity: 0.2;
    animation-delay: -10s;
}

@keyframes orbFloat {
    0% {
        transform: translate(0, 0) scale(1);
    }

    100% {
        transform: translate(10%, 15%) scale(1.1);
    }
}

.noise-overlay {
    position: fixed;
    inset: 0;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    opacity: 0.03;
    z-index: -1;
    pointer-events: none;
}

/* --- Navigation --- */
.glass-nav {
    padding: 1.25rem 2rem;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--glass-border);
}

/* --- Scanner UI Overlay --- */
.scanner-wrap {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.95);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    backdrop-filter: blur(25px);
}

#reader {
    width: 100%;
    max-width: 600px;
    aspect-ratio: 1;
    border-radius: 24px;
    overflow: hidden;
    border: 2px solid var(--primary);
    box-shadow: 0 0 50px var(--primary-glow);
    background: #000;
    position: relative;
}

/* Scanner Beam Animation */
#reader::after {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: var(--primary);
    box-shadow: 0 0 15px var(--primary), 0 0 25px var(--primary);
    animation: scannerBeam 2s infinite ease-in-out;
    z-index: 10;
}

@keyframes scannerBeam {
    0% {
        top: 0;
        opacity: 0;
    }

    10% {
        opacity: 1;
    }

    90% {
        opacity: 1;
    }

    100% {
        top: 100%;
        opacity: 0;
    }
}

.close-scanner {
    margin-top: 2.5rem;
    background: rgba(255, 50, 50, 0.1);
    color: #ff4d4d;
    border: 1px solid rgba(255, 80, 80, 0.2);
    padding: 1rem 3rem;
    border-radius: 100px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    cursor: pointer;
    transition: all 0.3s ease;
    backdrop-filter: blur(10px);
}

.close-scanner:hover {
    background: #ff4d4d;
    color: white;
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(255, 77, 77, 0.4);
}

/* Override html5-qrcode standard look */
#reader__dashboard_section_csr button {
    background: var(--primary) !important;
    color: white !important;
    border: none !important;
    padding: 10px 20px !important;
    border-radius: 12px !important;
    font-weight: 600 !important;
    margin: 5px !important;
}

#reader__status_span {
    color: var(--text-muted) !important;
}

.nav-content {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.logo-box {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 8px 16px var(--primary-glow);
}

.logo-text {
    font-family: var(--font-head);
    font-weight: 800;
    font-size: 1.25rem;
    letter-spacing: -0.02em;
}

.logo-text .thin {
    font-weight: 300;
    opacity: 0.7;
}

/* --- Hero Section --- */
.content-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 4rem 2rem;
    max-width: 1200px;
    margin: 0 auto;
    width: 100%;
}

.hero-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    gap: 4rem;
}

.hero-text h2 {
    font-family: var(--font-head);
    font-size: clamp(3rem, 8vw, 5rem);
    font-weight: 800;
    line-height: 1.05;
    letter-spacing: -0.04em;
    margin-bottom: 1.5rem;
}

.gradient-text {
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.sub-reveal {
    font-size: 1.25rem;
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto;
}

/* --- Action Cards --- */
.main-actions {
    display: flex;
    gap: 2rem;
    width: 100%;
    max-width: 900px;
}

.prime-card {
    flex: 1;
    position: relative;
    padding: 3rem;
    border-radius: 32px;
    cursor: pointer;
    overflow: hidden;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
}

.prime-card:hover {
    transform: translateY(-12px) scale(1.02);
}

.card-glass {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.05) 0%, transparent 100%);
    z-index: 0;
}

.card-inner {
    position: relative;
    z-index: 1;
}

.icon-wrap {
    font-size: 3.5rem;
    margin-bottom: 1.5rem;
    filter: drop-shadow(0 10px 15px rgba(0, 0, 0, 0.2));
}

.prime-card h3 {
    font-family: var(--font-head);
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.prime-card p {
    color: var(--text-muted);
}

/* --- View Panels --- */
.view-panel {
    width: 100%;
    max-width: 850px;
    margin: 0 auto;
    animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card-container {
    background: var(--glass-bg);
    backdrop-filter: blur(24px);
    border: 1px solid var(--glass-border);
    border-radius: 40px;
    padding: 3rem;
    box-shadow: var(--card-shadow);
}

.panel-header {
    margin-bottom: 2rem;
}

.back-link {
    background: none;
    border: none;
    color: var(--primary);
    font-weight: 600;
    cursor: pointer;
    font-size: 1rem;
    transition: opacity 0.2s;
}

.back-link:hover {
    opacity: 0.7;
}

/* --- Sender Identity --- */
.identity-panel h2 {
    font-family: var(--font-head);
    font-size: 2rem;
    margin-top: 0.5rem;
}

.badge {
    padding: 4px 12px;
    background: rgba(16, 185, 129, 0.1);
    color: var(--accent);
    border-radius: 100px;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.key-grid {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 1.5rem;
    margin: 2rem 0;
}

.key-card,
.qr-card {
    background: rgba(255, 255, 255, 0.03);
    padding: 1.5rem;
    border-radius: 20px;
    border: 1px solid var(--glass-edge);
}

.key-card label {
    font-size: 0.875rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 0.5rem;
}

/* --- Join Panel Refinement --- */
.join-actions-row {
    display: flex;
    gap: 1rem;
    margin: 2rem 0 1rem;
    width: 100%;
}

.key-input-wrap-premium {
    flex: 1;
    position: relative;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 16px;
    display: flex;
    align-items: center;
    padding: 0 1.25rem;
    transition: all 0.3s ease;
}

.key-input-wrap-premium:focus-within {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.08);
    box-shadow: 0 0 20px rgba(99, 102, 241, 0.15);
}

.input-icon {
    font-size: 1.2rem;
    margin-right: 0.75rem;
    opacity: 0.6;
}

.key-input-wrap-premium input {
    background: none;
    border: none;
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 1.1rem;
    font-weight: 500;
    width: 100%;
    outline: none;
    padding: 1rem 0;
}

.key-input-wrap-premium input::placeholder {
    color: var(--text-muted);
    opacity: 0.5;
}

.secondary-glow-btn {
    background: var(--glass-bg);
    color: var(--text-main);
    border: 1px solid var(--glass-border);
    padding: 0 1.5rem;
    border-radius: 16px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
}

.secondary-glow-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--secondary);
    box-shadow: 0 0 15px rgba(236, 72, 153, 0.2);
}

.glow-btn.wide {
    width: 100%;
    padding: 1.25rem;
    font-size: 1.1rem;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: white;
    border: none;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 10px 25px var(--primary-glow);
    transition: all 0.3s ease;
}

.glow-btn.wide:hover {
    transform: translateY(-2px);
    box-shadow: 0 15px 30px var(--primary-glow);
}

/* --- Device Naming --- */
.name-setup-premium {
    margin: 1.5rem 0;
}

.name-setup-premium label {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    display: block;
    margin-bottom: 0.5rem;
}

.premium-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    padding: 1rem 1.25rem;
    border-radius: 12px;
    color: var(--text-main);
    font-family: var(--font-body);
    font-weight: 500;
    outline: none;
    transition: all 0.3s ease;
}

.premium-input:focus {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
    box-shadow: 0 0 15px var(--primary-glow);
}

.bottom-gap {
    margin-bottom: 2rem;
}

/* --- Receiver UI Improvements --- */
.stream-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.stream-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.25rem;
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.02);
    gap: 1rem;
    width: 100%;
}

.stream-info {
    flex: 1;
    min-width: 0;
    /* Critical for truncation inside flexbox */
}

.stream-info strong {
    display: block;
    word-break: break-all;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.4;
    white-space: normal;
    font-size: 1rem;
}

.stream-info small {
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    opacity: 0.7;
}

.stream-actions {
    display: flex;
    gap: 0.75rem;
}

.action-btn {
    padding: 0.6rem 1.2rem;
    border-radius: 10px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid var(--glass-border);
    transition: all 0.2s ease;
}

.action-btn.accept {
    background: var(--accent);
    color: white;
    border: none;
}

.action-btn.decline {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border-color: rgba(239, 68, 68, 0.2);
}

.action-btn:hover {
    transform: scale(1.05);
    filter: brightness(1.1);
}

/* --- Multi-Receiver Card --- */
.receivers-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}

.receiver-card {
    background: rgba(255, 255, 255, 0.03);
    padding: 1.25rem;
    border-radius: 16px;
    border: 1px solid var(--glass-border);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    text-align: center;
}

.receiver-status-tag {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 8px;
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.05);
}

.receiver-status-tag.waiting {
    color: #f59e0b;
}

.receiver-status-tag.done {
    color: var(--accent);
}

/* Disconnect Button & Hub */
.disconnect-btn {
    background: rgba(239, 68, 68, 0.1);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.2);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.2s ease;
}

.disconnect-btn:hover {
    background: #ef4444;
    color: white;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.connection-hub-card {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    padding: 1.5rem;
    border-radius: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    animation: fadeIn 0.4s ease;
}

.hub-info {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.hub-dot {
    width: 12px;
    height: 12px;
    background: var(--accent);
    border-radius: 50%;
    box-shadow: 0 0 10px var(--accent);
}

.hub-text strong {
    display: block;
    font-size: 1.1rem;
    font-family: var(--font-head);
}

.hub-text span {
    font-size: 0.85rem;
    color: var(--text-muted);
}

.qr-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
}

#qrcode canvas,
#qrcode img {
    border-radius: 12px;
    padding: 12px;
    background: white;
    width: 100% !important;
    height: auto !important;
    max-width: 200px;
}

/* --- Drop Zone --- */
.drop-zone-prime {
    border: 2px dashed var(--glass-border);
    border-radius: 24px;
    padding: 4rem 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-top: 2rem;
}

.drop-zone-prime:hover,
.drop-zone-prime.active {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.drop-plus {
    width: 60px;
    height: 60px;
    background: var(--primary);
    margin: 0 auto 1.5rem;
    border-radius: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    box-shadow: 0 10px 20px var(--primary-glow);
}

.drop-content p span {
    color: var(--primary);
    font-weight: 600;
}

/* --- Progress Card --- */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    backdrop-filter: blur(8px);
    transition: all 0.3s ease;
}

.progress-card {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: calc(100% - 2rem);
    max-width: 450px;
    background: var(--bg-base);
    border: 1px solid var(--glass-border);
    border-radius: 32px;
    padding: 2.5rem;
    box-shadow: 0 50px 100px rgba(0, 0, 0, 0.5);
}

.progress-header {
    display: flex;
    gap: 1.25rem;
    margin-bottom: 2rem;
}

.file-icon-mini {
    width: 50px;
    height: 50px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.file-name-wrap h4 {
    font-family: var(--font-head);
    font-size: 1.1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 70vw;
    /* Better for mobile */
}

.file-name-wrap span {
    font-size: 0.875rem;
    color: var(--text-muted);
}

.progress-details {
    margin-top: 1rem;
}

.progress-actions {
    margin: 1.5rem 0;
    display: flex;
    justify-content: center;
}

.progress-footer {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.25rem;
    margin-top: 2rem;
}

.status-group {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

#progress-status-label {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

#progress-percent {
    font-size: 2.5rem;
    font-family: var(--font-head);
    font-weight: 800;
    background: linear-gradient(135deg, #fff, var(--text-muted));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.cancel-link {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 0.85rem;
    font-weight: 600;
    text-decoration: underline;
    cursor: pointer;
    transition: color 0.2s ease;
}

.cancel-link:hover {
    color: #ef4444;
}

body.active-transfer .main-footer {
    opacity: 0;
    pointer-events: none;
    transform: translateY(20px);
}

.main-footer {
    transition: all 0.4s ease;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1.5rem;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--glass-border);
}

.metric-item {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.m-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.m-value {
    font-family: var(--font-head);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-main);
}

.progress-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
}

#progress-percent {
    font-size: 2rem;
    font-weight: 800;
    font-family: var(--font-head);
    background: linear-gradient(to right, var(--primary), var(--secondary));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.text-link {
    background: none;
    border: none;
    color: var(--text-muted);
    font-weight: 600;
    cursor: pointer;
    font-size: 0.9rem;
    transition: color 0.2s;
}

.text-link:hover {
    color: var(--danger);
}

/* --- Theme Switch --- */
.theme-switch {
    width: 64px;
    height: 32px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 100px;
    cursor: pointer;
    position: relative;
    padding: 4px;
}

.switch-ball {
    width: 24px;
    height: 24px;
    background: var(--text-main);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

[data-theme="light"] .switch-ball {
    transform: translateX(32px);
}

[data-theme="dark"] .sun {
    display: none;
}

[data-theme="light"] .moon {
    display: none;
}

/* Status Indicators */
.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.badge {
    background: rgba(99, 102, 241, 0.1);
    color: var(--primary);
    padding: 0.4rem 0.8rem;
    border-radius: 8px;
    font-size: 0.75rem;
    font-weight: 700;
    white-space: nowrap;
}

.badge.success {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.badge.cancelled {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.pulse-dot {
    width: 10px;
    height: 10px;
    background: var(--accent);
    border-radius: 50%;
    animation: hubPulse 2s infinite;
}

@keyframes hubPulse {
    0% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(16, 185, 129, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(16, 185, 129, 0);
    }
}

.hidden {
    display: none !important;
}

/* Mobile Optimization */
@media (max-width: 768px) {
    .main-actions {
        flex-direction: column;
    }

    .hero-text h2 {
        font-size: 3rem;
    }

    .key-grid {
        grid-template-columns: 1fr;
    }

    .card-container {
        padding: 1.5rem;
        border-radius: 24px;
        width: 100%;
        overflow: hidden;
        /* Prevent child extension */
    }

    .stream-item {
        padding: 1rem;
    }

    .stream-actions {
        flex-shrink: 0;
    }

    .action-btn {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }
}