:root {
    /* ── Nebula palette ── */
    --void: #050310;
    --bg-dark: #0a0718;
    --bg-darker: #030209;
    --nebula-violet: #8b5cf6;
    --nebula-magenta: #d946ef;
    --nebula-cyan: #22d3ee;

    --primary: var(--nebula-violet);
    --primary-glow: rgba(139, 92, 246, 0.55);
    --success: var(--nebula-cyan);
    --danger: #fb7185;

    --glass-bg: rgba(150, 120, 255, 0.055);
    --glass-border: rgba(180, 150, 255, 0.16);
    --text-main: #f3f0ff;
    --text-muted: #a99fd6;
    --nav-bg: rgba(8, 6, 20, 0.75);

    --font-display: 'Space Grotesk', sans-serif;
    --font-body: 'Manrope', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
}

body.light-mode {
    /* ── Nebula Dawn (soft daylight variant, still cosmic) ── */
    --bg-dark: #f3effc;
    --bg-darker: #e9e1f7;
    --nebula-violet: #7c3aed;
    --nebula-magenta: #c026d3;
    --nebula-cyan: #0891b2;
    --primary: var(--nebula-violet);
    --primary-glow: rgba(124, 58, 237, 0.25);
    --success: #0e7490;
    --danger: #dc2626;
    --glass-bg: rgba(255, 255, 255, 0.55);
    --glass-border: rgba(124, 58, 237, 0.16);
    --text-main: #201533;
    --text-muted: #6c6089;
    --nav-bg: rgba(243, 239, 252, 0.9);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: var(--font-body);
}

h1, h2, h3, .logo h2 {
    font-family: var(--font-display);
    letter-spacing: -0.01em;
}

::selection {
    background: var(--nebula-violet);
    color: white;
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
    background: linear-gradient(var(--nebula-violet), var(--nebula-magenta));
    border-radius: 8px;
}

body {
    background-color: var(--void);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    overflow-x: hidden;
}

.app-container {
    width: 100%;
    min-height: 100vh;
    position: relative;
    background: var(--void);
    box-shadow: 0 0 80px rgba(139, 92, 246, 0.12);
    overflow: hidden;
    isolation: isolate;
}

/* On tablet/desktop, present the app as a floating device frame instead
   of stretching edge-to-edge — much easier to read and scan. */
@media (min-width: 640px) {
    body {
        align-items: center;
        padding: 32px 20px;
    }

    .app-container {
        width: 420px;
        min-height: 780px;
        max-height: 900px;
        border-radius: 32px;
        border: 1px solid var(--glass-border);
        box-shadow:
            0 40px 100px rgba(0, 0, 0, 0.45),
            0 0 0 1px rgba(255, 255, 255, 0.04),
            0 0 90px rgba(139, 92, 246, 0.18);
    }
}

/* Nebula cloud wash */
.app-container::before {
    content: "";
    position: absolute;
    inset: -15%;
    background:
        radial-gradient(ellipse 55% 40% at 12% -5%, rgba(139, 92, 246, 0.38), transparent 60%),
        radial-gradient(ellipse 50% 45% at 108% 18%, rgba(217, 70, 239, 0.30), transparent 60%),
        radial-gradient(ellipse 45% 38% at 25% 115%, rgba(34, 211, 238, 0.20), transparent 60%),
        radial-gradient(ellipse 40% 35% at 90% 100%, rgba(139, 92, 246, 0.16), transparent 60%);
    filter: blur(50px);
    animation: nebula-drift 60s ease-in-out infinite alternate;
    z-index: 0;
    pointer-events: none;
}

/* Starfield */
.app-container::after {
    content: "";
    position: absolute;
    inset: 0;
    background-image:
        radial-gradient(1.2px 1.2px at 20px 30px, rgba(255,255,255,0.9), transparent),
        radial-gradient(1px 1px at 90px 80px, rgba(255,255,255,0.7), transparent),
        radial-gradient(1.6px 1.6px at 150px 20px, rgba(255,255,255,0.85), transparent),
        radial-gradient(1px 1px at 190px 140px, rgba(255,255,255,0.6), transparent),
        radial-gradient(1px 1px at 55px 160px, rgba(255,255,255,0.5), transparent),
        radial-gradient(1.6px 1.6px at 235px 95px, rgba(255,255,255,0.75), transparent),
        radial-gradient(1px 1px at 270px 40px, rgba(255,255,255,0.55), transparent);
    background-repeat: repeat;
    background-size: 300px 220px;
    opacity: 0.55;
    z-index: 0;
    pointer-events: none;
}

body.light-mode .app-container::after { opacity: 0.12; }

@keyframes nebula-drift {
    from { transform: translate(0, 0) scale(1); }
    to   { transform: translate(-3%, 3%) scale(1.06); }
}

.screen {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    pointer-events: none;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(20px);
    display: flex;
    flex-direction: column;
    z-index: 1;
}

.screen.active {
    opacity: 1;
    pointer-events: all;
    transform: translateX(0);
}

/* Glassmorphism utility */
.glass-card {
    position: relative;
    background: var(--glass-bg);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border: 1px solid var(--glass-border);
    border-radius: 20px;
    padding: 24px;
    overflow: hidden;
}

/* Nebula edge: a soft gradient hairline along the top of every card */
.glass-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--nebula-violet), var(--nebula-magenta), var(--nebula-cyan), transparent);
    opacity: 0.55;
}

/* Auth Screen */
#auth-screen {
    justify-content: center;
    align-items: center;
    padding: 20px;
}
.auth-card {
    width: 100%;
    max-width: 450px;
}

.logo {
    text-align: center;
    margin-bottom: 30px;
}

.logo i {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 84px;
    height: 84px;
    border-radius: 50%;
    font-size: 2.1rem;
    color: white;
    background: linear-gradient(135deg, var(--nebula-violet), var(--nebula-magenta));
    box-shadow: 0 0 40px var(--primary-glow), 0 0 90px rgba(217, 70, 239, 0.22);
    margin-bottom: 14px;
}

.logo h2 {
    font-weight: 600;
    background: linear-gradient(90deg, var(--text-main), var(--nebula-violet) 130%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.25);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 24px;
    border: 1px solid var(--glass-border);
}

.tab {
    flex: 1;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-weight: 600;
    font-family: var(--font-display);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.3s ease;
}

.tab.active {
    background: linear-gradient(135deg, var(--nebula-violet), var(--nebula-magenta));
    color: white;
    box-shadow: 0 4px 16px var(--primary-glow);
}

.input-group {
    position: relative;
    margin-bottom: 16px;
}

.input-group i {
    position: absolute;
    left: 16px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
}

.input-group input {
    width: 100%;
    padding: 14px 16px 14px 45px;
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    color: var(--text-main);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.input-group input:focus {
    border-color: var(--nebula-violet);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}

.btn-primary {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--nebula-violet), var(--nebula-magenta));
    color: white;
    border: none;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    font-family: var(--font-display);
    cursor: pointer;
    box-shadow: 0 6px 20px var(--primary-glow), 0 2px 10px rgba(217, 70, 239, 0.25);
    transition: transform 0.2s, box-shadow 0.2s;
    margin-top: 10px;
}

.btn-primary:active {
    transform: scale(0.98);
}

.error-msg {
    color: var(--danger);
    text-align: center;
    margin-top: 15px;
    font-size: 0.9rem;
    min-height: 20px;
}

/* Dashboard */
.topbar {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--glass-border);
    background: var(--nav-bg);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--nebula-violet), var(--nebula-magenta));
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    box-shadow: 0 0 18px var(--primary-glow);
}

#display-username {
    font-family: var(--font-display);
    font-weight: 600;
}

.btn-icon {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    transition: background 0.3s, color 0.3s;
}

.btn-icon:hover {
    background: var(--glass-bg);
    color: var(--nebula-cyan);
}

.dashboard-content {
    padding: 20px;
    flex: 1;
    overflow-y: auto;
    padding-bottom: 100px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.status-card {
    margin-bottom: 20px;
}

.status-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
}

.status-header h3 { font-family: var(--font-display); }

.status-badge {
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    font-family: var(--font-mono);
    letter-spacing: 0.02em;
}

.status-badge.offline { background: rgba(169, 159, 214, 0.14); color: var(--text-muted); }
.status-badge.online { background: rgba(34, 211, 238, 0.18); color: var(--nebula-cyan); }

/* ── The Singularity Core ── */
.device-mockup {
    background:
        radial-gradient(circle at center, rgba(139, 92, 246, 0.08), transparent 70%),
        rgba(0, 0, 0, 0.35);
    border-radius: 16px;
    height: 130px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--glass-border);
    transition: border-color 0.5s, box-shadow 0.5s;
}

.device-mockup.online {
    border-color: rgba(34, 211, 238, 0.4);
    box-shadow: inset 0 0 50px rgba(34, 211, 238, 0.12);
}

.screen-content {
    text-align: center;
    color: var(--text-muted);
}

.screen-content i {
    margin-bottom: 10px;
    transition: color 0.3s;
}

#bot-icon {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: var(--bg-darker);
    z-index: 1;
}

#bot-icon::after {
    content: "";
    position: absolute;
    inset: -9px;
    border-radius: 50%;
    background: conic-gradient(from 0deg, var(--nebula-violet), var(--nebula-magenta), var(--nebula-cyan), var(--nebula-violet));
    z-index: -1;
    opacity: 0.32;
    filter: blur(2px);
    animation: spin-slow 14s linear infinite;
    transition: opacity 0.5s;
}

.device-mockup.online #bot-icon {
    background: radial-gradient(circle, rgba(34, 211, 238, 0.25), var(--bg-darker) 72%);
}

.device-mockup.online #bot-icon::after {
    opacity: 0.95;
    filter: blur(3px);
    animation-duration: 4s;
    box-shadow: 0 0 24px rgba(34, 211, 238, 0.5);
}

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

.action-card {
    text-align: center;
    margin-bottom: 20px;
}

.action-card h3, .pairing-card h3, .active-session-card h3 { font-family: var(--font-display); }

.subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 8px 0 20px;
}

.phone-input {
    display: flex;
    gap: 10px;
}

.phone-input .country-code {
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--glass-border);
    border-radius: 12px;
    padding: 0 15px;
    display: flex;
    align-items: center;
    font-weight: 600;
    font-family: var(--font-mono);
}

.phone-input input {
    padding-left: 16px;
    font-family: var(--font-mono);
}

.pairing-card {
    text-align: center;
    background: linear-gradient(145deg, rgba(139, 92, 246, 0.12), rgba(217, 70, 239, 0.10), rgba(34, 211, 238, 0.08));
    border: 1px solid rgba(139, 92, 246, 0.35);
}

.pairing-code {
    font-family: var(--font-mono);
    font-size: 2.3rem;
    font-weight: 600;
    letter-spacing: 6px;
    margin: 20px 0;
    background: linear-gradient(90deg, var(--nebula-violet), var(--nebula-magenta), var(--nebula-cyan));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 0 18px rgba(139, 92, 246, 0.35));
}

.instruction {
    font-size: 0.85rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.loader {
    width: 30px;
    height: 30px;
    border: 3px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--nebula-violet);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin: 20px auto 0;
}

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

.hidden { display: none !important; }

/* Active Session Card */
.active-session-card {
    border-color: rgba(34, 211, 238, 0.35);
    margin-top: 20px;
}

.session-info {
    margin: 15px 0;
}

.session-row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--glass-border);
    font-family: var(--font-mono);
    font-size: 0.9rem;
}

.session-row:last-child {
    border-bottom: none;
}

.status-online { color: var(--nebula-cyan); }

.btn-danger {
    background: rgba(251, 113, 133, 0.15);
    color: var(--danger);
    border: 1px solid rgba(251, 113, 133, 0.35);
    padding: 12px;
    border-radius: 12px;
    font-weight: 600;
    font-family: var(--font-display);
    cursor: pointer;
    transition: background 0.3s, opacity 0.3s;
}

.btn-danger:hover {
    background: rgba(251, 113, 133, 0.25);
}

.full-width { width: 100%; }

/* Bottom Nav */
.bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    background: var(--nav-bg);
    backdrop-filter: blur(15px);
    border-top: 1px solid var(--glass-border);
    display: flex;
    justify-content: space-around;
    padding: 12px 0;
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
    z-index: 10;
}

.nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.75rem;
    font-family: var(--font-mono);
    transition: color 0.3s, text-shadow 0.3s;
}

.nav-item i { font-size: 1.2rem; }
.nav-item.active {
    color: var(--nebula-violet);
    text-shadow: 0 0 14px var(--primary-glow);
}

/* Config Editor */
.form-row {
    display: grid;
    grid-template-columns: 1fr 96px;
    gap: 12px;
}

.form-group-narrow input {
    text-align: center;
    font-family: var(--font-mono);
}

.form-group {
    margin-bottom: 14px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.cfg-input {
    width: 100%;
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.2);
    color: var(--text-main);
    font-family: var(--font-body);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.3s, box-shadow 0.3s;
}

.cfg-input:focus {
    border-color: var(--nebula-violet);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}

select.cfg-input {
    appearance: none;
}

.toggle-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--glass-border);
    font-size: 0.9rem;
}

.toggle-row:last-child {
    border-bottom: none;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.12);
    transition: 0.3s;
    border-radius: 24px;
}

.switch .slider::before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: 0.3s;
    border-radius: 50%;
}

.switch input:checked + .slider {
    background: linear-gradient(135deg, var(--nebula-violet), var(--nebula-magenta));
}

.switch input:checked + .slider::before {
    transform: translateX(20px);
}

.config-advanced-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.cfg-json-editor {
    width: 100%;
    min-height: 320px;
    margin-top: 10px;
    padding: 14px;
    border-radius: 10px;
    border: 1px solid var(--glass-border);
    background: rgba(0, 0, 0, 0.35);
    color: #c9c2f0;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.5;
    resize: vertical;
    outline: none;
    white-space: pre;
}

.cfg-json-editor:focus {
    border-color: var(--nebula-violet);
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.18);
}

.config-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 0 5px;
}

.cfg-status {
    text-align: center;
    font-size: 0.85rem;
    font-family: var(--font-mono);
    padding: 10px 5px 20px;
}

.cfg-status.success { color: var(--nebula-cyan); }
.cfg-status.error { color: var(--danger); }

/* Respect reduced motion */
@media (prefers-reduced-motion: reduce) {
    .app-container::before,
    #bot-icon::after,
    .loader {
        animation: none !important;
    }
}

/* About screen */
.about-hero h3 { margin-bottom: 2px; }

.about-desc {
    margin-top: 15px;
    color: var(--text-muted);
    font-size: 0.9rem;
    line-height: 1.6;
}

.version-badge {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 22px;
    padding: 10px;
    border-radius: 12px;
    background: rgba(139, 92, 246, 0.08);
    border: 1px solid var(--glass-border);
    font-family: var(--font-mono);
    font-weight: 600;
    color: var(--nebula-violet);
}

.stats-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
    margin-top: 20px;
}

.stat-card {
    text-align: center;
    padding: 20px 14px;
    border-radius: 16px;
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    backdrop-filter: blur(16px);
}

.stat-card i {
    font-size: 1.5rem;
    color: var(--nebula-cyan);
    margin-bottom: 10px;
}

.stat-card h4 {
    font-family: var(--font-display);
    font-size: 1.6rem;
    margin-bottom: 2px;
}

.stat-card span {
    font-size: 0.78rem;
    color: var(--text-muted);
}

/* Settings screen */
.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    margin-top: 20px;
}

.setting-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.theme-toggle-btn {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--glass-border);
    color: var(--text-main);
    width: auto;
    padding: 8px 16px;
    border-radius: 20px;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.3s, color 0.3s;
}

.theme-toggle-btn:hover {
    border-color: var(--nebula-violet);
    color: var(--nebula-violet);
}
