/* ================= WELCOME PANEL ================= */

.welcome-backdrop {
    position: fixed;
    inset: 0;
    /* Simpler, lighter overlay with stronger blur */
    background: rgba(40, 40, 40, 0.5);
    backdrop-filter: blur(64px);
    -webkit-backdrop-filter: blur(64px);
    z-index: 10000010;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    /* Respect device safe areas (e.g., iPhone notch and home bar) */
    padding-top: calc(24px + var(--safe-area-top, 0px));
    padding-bottom: calc(24px + var(--safe-area-bottom, 0px));
    opacity: 0;
    visibility: hidden;
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
}

.welcome-backdrop.active {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
}

/* Ensure sidebar and topbar stay below the backdrop blur */
.sidebar {
    z-index: 999 !important;
}

/* Ensure topbar is behind splash screen when splash is active */
body:has(.welcome-backdrop.active) .main-header,
.welcome-backdrop.active ~ .main-header,
.welcome-backdrop.active ~ * .main-header {
    z-index: 999 !important;
}

/* Alternative approach for browsers that don't support :has() */
.welcome-backdrop.active {
    z-index: 10000010 !important;
}

.welcome-backdrop.active ~ * .main-header,
.welcome-backdrop.active ~ .main-header {
    z-index: 999 !important;
}

.welcome-panel {
    background: rgba(12, 12, 12, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 16px;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow: 
        0 20px 50px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.04);
    /* Wider, more landscape-friendly layout */
    max-width: 720px; /* was 800px, reduced by 10% */
    width: 100%;
    /* Limit height to visible viewport minus safe areas; allow internal scroll on overflow */
    max-height: 78vh;
    max-height: min(78vh, calc(100dvh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 48px));
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior: contain;
    position: relative;
    /* Scales adjust below via viewport height queries to avoid overflow */
    --welcome-ui-scale: 1.0;
    transform: scale(calc(var(--welcome-ui-scale) * 0.95)) translateY(20px);
    transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 10000011; /* Ensure modal appears above backdrop */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
}

.welcome-backdrop.active .welcome-panel {
    transform: scale(var(--welcome-ui-scale)) translateY(0);
}

/* Remove plasma glow layers for a lighter look */
.welcome-backdrop::before,
.welcome-backdrop::after {
    content: none !important;
}

/* Remove unused plasma keyframes */

.welcome-close {
    position: absolute;
    top: 16px;
    right: 16px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 10px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: rgba(255, 255, 255, 0.7);
    cursor: pointer;
    transition: all 0.25s ease;
    z-index: 10;
}

.welcome-close:hover {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
    transform: scale(1.05);
}

.welcome-header {
    text-align: center;
    padding: 24px 24px 16px; /* MODIFIED */
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.brand-mark {
    width: 72px; /* MODIFIED */
    height: 72px; /* MODIFIED */
    margin: 0 auto 12px; /* MODIFIED */
    position: relative;
    border-radius: 16px; /* MODIFIED */
    overflow: hidden;
}

.brand-mark img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 16px; /* MODIFIED */
    background: #0a0a0a;
}

.welcome-header h1 {
    font-size: 1.55rem; /* tighter to reduce height */
    font-weight: 700;
    background: linear-gradient(135deg, #F5B700, #FF7043);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 6px; /* MODIFIED */
    letter-spacing: -0.025em;
}

.tagline {
    font-size: 0.9rem; /* tighter */
    color: rgba(255, 255, 255, 0.65);
    font-weight: 400;
    line-height: 1.4;
}

.welcome-body {
    padding: 0 24px 24px;
}

.intro-section {
    text-align: center;
    margin-bottom: 24px;
    padding-top: 12px;
}

.intro-section h2 {
    font-size: 1.125rem; /* MODIFIED */
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 12px;
    font-weight: 600;
}

.intro-section p {
    font-size: 0.875rem; /* MODIFIED */
    color: rgba(255, 255, 255, 0.65);
    line-height: 1.5;
    /* Clamp lines to prevent vertical overflow */
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
    max-width: 520px;
    margin: 0 auto;
}

.capabilities-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

.capability-item {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    padding: 16px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.capability-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(245, 183, 0, 0.4), transparent);
    transform: translateX(-100%);
    transition: transform 0.5s ease;
}

.capability-item:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: rgba(255, 255, 255, 0.12);
    transform: translateY(-1px);
}

.capability-item:hover::before {
    transform: translateX(100%);
}

.capability-icon {
    width: 32px; /* MODIFIED */
    height: 32px; /* MODIFIED */
    margin-bottom: 10px;
    border-radius: 8px;
    background: rgba(245, 183, 0, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
}

.capability-icon img {
    width: 20px; /* MODIFIED */
    height: 20px; /* MODIFIED */
    filter: brightness(1.1);
}

.capability-item h3 {
    font-size: 0.95rem; /* MODIFIED */
    font-weight: 600;
    color: rgba(255, 255, 255, 0.9);
    margin-bottom: 6px;
}

.capability-item p {
    font-size: 0.8rem; /* MODIFIED */
    color: rgba(255, 255, 255, 0.6);
    line-height: 1.4;
    /* Clamp to 2 lines */
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.welcome-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    align-items: center;
    padding-top: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.action-btn {
    padding: 10px 20px;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    position: relative;
    overflow: hidden;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

.action-btn.primary {
    background: linear-gradient(135deg, #F5B700, #FF7043);
    color: #000;
    box-shadow: 0 6px 20px rgba(245, 183, 0, 0.25);
}

.action-btn.primary::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.25), transparent);
    transition: left 0.4s ease;
}

.action-btn.primary:hover::before {
    left: 100%;
}

.action-btn.primary:hover {
    transform: translateY(-1px) scale(1.02);
    box-shadow: 0 12px 30px rgba(245, 183, 0, 0.35);
}

.action-btn.secondary {
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.12);
}

.action-btn.secondary:hover {
    background: rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.95);
    transform: translateY(-1px);
}

.dismiss-option {
    display: flex;
    justify-content: center;
    margin-top: 14px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    color: rgba(255, 255, 255, 0.55);
    cursor: pointer;
    user-select: none;
}

.checkbox-label input[type="checkbox"] {
    display: none;
}

.checkmark {
    width: 14px;
    height: 14px;
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 3px;
    position: relative;
    transition: all 0.2s ease;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark {
    background: #F5B700;
    border-color: #F5B700;
}

.checkbox-label input[type="checkbox"]:checked + .checkmark::after {
    content: '';
    position: absolute;
    left: 4px;
    top: 1px;
    width: 4px;
    height: 8px;
    border: solid #000;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
}

/* ================= RESPONSIVE DESIGN ================= */

@media (max-width: 768px) {
    .welcome-backdrop {
        padding: 8px;
        align-items: flex-start;
        padding-top: calc(8px + var(--safe-area-top, 0px));
        padding-bottom: calc(16px + var(--safe-area-bottom, 0px)); /* extra bottom space for navbar/home bar */
    }

    .welcome-panel {
        /* Account for safe areas on smaller screens - maximize screen usage */
        max-height: calc(100vh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 24px);
        max-height: calc(100dvh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 24px);
        border-radius: 12px;
        width: calc(100vw - 16px);
        max-width: none;
    }

    /* On mobile, ensure sidebar stays below backdrop */
    .sidebar {
        z-index: 998 !important;
    }
    
    .sidebar-overlay {
        z-index: 997 !important;
    }

    .welcome-header {
        padding: 12px 12px 8px;
    }

    .welcome-body {
        padding: 0 12px 12px;
    }

    .welcome-header h1 {
        font-size: 1.625rem;
    }

    .brand-mark {
        width: 68px;
        height: 68px;
        margin-bottom: 10px;
    }

    .capabilities-grid {
        grid-template-columns: 1fr;
        gap: 12px;
        margin-bottom: 14px;
    }

    .capability-item {
        padding: 14px;
    }

    .welcome-actions {
        flex-direction: column;
        gap: 10px;
    }

    .action-btn {
        width: 100%;
        justify-content: center;
        padding: 12px 18px;
    }

    .intro-section {
        margin-bottom: 14px;
    }

    .intro-section h2 {
        font-size: 1.125rem;
    }
}

@media (max-width: 480px) {
    .welcome-backdrop {
        padding: 6px;
        padding-top: calc(6px + var(--safe-area-top, 0px));
        padding-bottom: calc(14px + var(--safe-area-bottom, 0px)); /* extra bottom space for navbar/home bar */
    }

    .welcome-panel {
        border-radius: 10px;
        max-height: calc(100vh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 20px);
        max-height: calc(100dvh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 20px);
        width: calc(100vw - 12px);
    }

    .welcome-header {
        padding: 10px 10px 8px;
    }

    .welcome-body {
        padding: 0 10px 10px;
    }

    .welcome-header h1 {
        font-size: 1.375rem;
        margin-bottom: 6px;
    }

    .tagline {
        font-size: 0.9rem;
    }

    .brand-mark {
        width: 58px;
        height: 58px;
        margin-bottom: 8px;
    }

    .capability-item {
        padding: 12px;
    }

    .capability-icon {
        width: 32px;
        height: 32px;
        margin-bottom: 10px;
    }

    .capability-icon img {
        width: 20px;
        height: 20px;
    }

    .capability-item h3 {
        font-size: 0.9rem;
        margin-bottom: 4px;
    }

    .capability-item p {
        font-size: 0.8rem;
    }

    .welcome-close {
        top: 10px;
        right: 10px;
        width: 30px;
        height: 30px;
    }

    .welcome-close svg {
        width: 14px;
        height: 14px;
    }

    .intro-section h2 {
        font-size: 1rem;
        margin-bottom: 8px;
    }

    .intro-section p {
        font-size: 0.85rem;
    }

    .action-btn {
        padding: 9px 14px;
        font-size: 0.8rem;
    }
}

/* ================= LANDSCAPE MOBILE ================= */
@media (max-width: 768px) and (orientation: landscape) {
    .welcome-backdrop {
        padding: 4px;
        padding-top: calc(4px + var(--safe-area-top, 0px));
        padding-bottom: calc(10px + var(--safe-area-bottom, 0px)); /* extra bottom space */
        align-items: center;
    }

    .welcome-panel {
        max-height: calc(100vh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 16px);
        max-height: calc(100dvh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 16px);
        max-width: 96vw;
        width: calc(100vw - 8px);
    }

    .welcome-header {
        padding: 14px 20px 10px;
    }

    .welcome-body {
        padding: 0 20px 14px;
    }

    .brand-mark {
        width: 56px;
        height: 56px;
        margin-bottom: 6px;
    }

    .welcome-header h1 {
        font-size: 1.25rem;
        margin-bottom: 4px;
    }

    .tagline {
        font-size: 0.85rem;
    }

    .intro-section {
        margin-bottom: 14px;
    }

    .intro-section h2 {
        font-size: 0.95rem;
        margin-bottom: 6px;
    }

    .intro-section p {
        font-size: 0.8rem;
    }

    .capabilities-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 12px;
    }

    .capability-item {
        padding: 10px;
    }

    .capability-icon {
        width: 28px;
        height: 28px;
        margin-bottom: 6px;
    }

    .capability-icon img {
        width: 16px;
        height: 16px;
    }

    .capability-item h3 {
        font-size: 0.8rem;
        margin-bottom: 2px;
    }

    .capability-item p {
        font-size: 0.75rem;
        line-height: 1.4;
    }

    .welcome-actions {
        flex-direction: row;
        gap: 8px;
    }

    .action-btn {
        padding: 7px 12px;
        font-size: 0.75rem;
        flex: 1;
    }
}

/* ================= VERY SMALL SCREENS ================= */
@media (max-width: 360px) {
    .welcome-backdrop {
        padding: 4px;
        padding-top: calc(4px + var(--safe-area-top, 0px));
        padding-bottom: calc(4px + var(--safe-area-bottom, 0px));
    }

    .welcome-panel {
        max-height: calc(100vh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 8px);
        max-height: calc(100dvh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 8px);
        width: calc(100vw - 8px);
        border-radius: 8px;
    }

    .welcome-header {
        padding: 8px 8px 6px;
    }

    .welcome-body {
        padding: 0 8px 8px;
    }

    .welcome-header h1 {
        font-size: 1.25rem;
        margin-bottom: 4px;
    }

    .tagline {
        font-size: 0.8rem;
    }

    .brand-mark {
        width: 48px;
        height: 48px;
        margin-bottom: 6px;
    }

    .capability-item {
        padding: 10px;
    }

    .capability-icon {
        width: 28px;
        height: 28px;
        margin-bottom: 8px;
    }

    .capability-icon img {
        width: 16px;
        height: 16px;
    }

    .capability-item h3 {
        font-size: 0.85rem;
        margin-bottom: 3px;
    }

    .capability-item p {
        font-size: 0.75rem;
    }

    .intro-section h2 {
        font-size: 0.95rem;
        margin-bottom: 6px;
    }

    .intro-section p {
        font-size: 0.8rem;
    }

    .action-btn {
        padding: 8px 12px;
        font-size: 0.75rem;
    }
}

/* ================= VIEWPORT HEIGHT SAFETY ================= */
/* Scale down gently as viewport height decreases to avoid overflow */
@media (max-height: 900px) {
    .welcome-panel { --welcome-ui-scale: 1.0; }
}
@media (max-height: 780px) {
    .welcome-panel { --welcome-ui-scale: 0.98; }
    .welcome-header { padding: 18px 20px 12px; }
}
@media (max-height: 700px) {
    .welcome-panel { --welcome-ui-scale: 0.95; max-height: 74vh; }
    .brand-mark { width: 56px; height: 56px; margin-bottom: 6px; }
    .welcome-header h1 { font-size: 1.4rem; }
    .tagline { display: none; }
    .intro-section h2 { font-size: 1.05rem; }
}
@media (max-height: 620px) {
    .welcome-panel { --welcome-ui-scale: 0.92; max-height: 72vh; }
    .intro-section p { -webkit-line-clamp: 2; }
    .capabilities-grid { gap: 10px; }
}
@media (max-height: 560px) {
    .welcome-panel { --welcome-ui-scale: 0.9; max-height: 70vh; }
    .dismiss-option { display: none; }
}

/* Mobile-specific height optimizations */
@media (max-width: 768px) and (max-height: 600px) {
    .welcome-panel { 
        --welcome-ui-scale: 0.88; 
        max-height: calc(100vh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 8px);
        max-height: calc(100dvh - var(--safe-area-top, 0px) - var(--safe-area-bottom, 0px) - 8px);
    }
    .welcome-header { padding: 8px 12px 6px; }
    .welcome-body { padding: 0 12px 8px; }
    .brand-mark { width: 48px; height: 48px; margin-bottom: 4px; }
    .welcome-header h1 { font-size: 1.2rem; margin-bottom: 4px; }
    .tagline { display: none; }
    .intro-section { margin-bottom: 8px; }
    .intro-section h2 { font-size: 0.95rem; margin-bottom: 4px; }
    .intro-section p { font-size: 0.8rem; -webkit-line-clamp: 2; }
    .capabilities-grid { gap: 8px; margin-bottom: 8px; }
    .capability-item { padding: 10px; }
    .capability-icon { width: 28px; height: 28px; margin-bottom: 6px; }
    .capability-icon img { width: 16px; height: 16px; }
    .capability-item h3 { font-size: 0.85rem; margin-bottom: 3px; }
    .capability-item p { font-size: 0.75rem; -webkit-line-clamp: 1; }
    .welcome-actions { padding-top: 8px; }
    .action-btn { padding: 8px 12px; font-size: 0.75rem; }
    .dismiss-option { display: none; }
}

/* Prefer a slightly larger scale on tall viewports */
@media (min-height: 1000px) {
    .welcome-panel { --welcome-ui-scale: 1.1; }
}

/* ================= ANIMATIONS ================= */

.capability-item {
    animation: slideInUp 0.5s cubic-bezier(0.4, 0, 0.2, 1) forwards;
    opacity: 0;
    transform: translateY(16px);
}

.capability-item:nth-child(1) { animation-delay: 0.1s; }
.capability-item:nth-child(2) { animation-delay: 0.15s; }
.capability-item:nth-child(3) { animation-delay: 0.2s; }
.capability-item:nth-child(4) { animation-delay: 0.25s; }
.capability-item:nth-child(5) { animation-delay: 0.3s; }
.capability-item:nth-child(6) { animation-delay: 0.35s; }

@keyframes slideInUp {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.welcome-actions {
    animation: fadeIn 0.5s cubic-bezier(0.4, 0, 0.2, 1) 0.4s forwards;
    opacity: 0;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

/* ================= TOUR TOOLTIP ================= */

.tour-tooltip {
    background: rgba(8, 8, 8, 0.95);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 16px;
    color: white;
    max-width: 280px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    animation: tooltipFadeIn 0.3s ease forwards;
    opacity: 0;
    transform: translateY(8px);
}

.tour-tooltip h4 {
    font-size: 0.95rem;
    font-weight: 600;
    color: rgba(255, 255, 255, 0.95);
    margin-bottom: 8px;
}

.tour-tooltip p {
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
    line-height: 1.4;
    margin-bottom: 12px;
}

.tour-next {
    background: linear-gradient(135deg, #F5B700, #FF7043);
    color: #000;
    border: none;
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.tour-next:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(245, 183, 0, 0.3);
}

@keyframes tooltipFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ================= ACCESSIBILITY ================= */

.welcome-close:focus-visible,
.action-btn:focus-visible,
.tour-next:focus-visible {
    outline: 2px solid #F5B700;
    outline-offset: 2px;
}

.checkbox-label:focus-within .checkmark {
    outline: 2px solid #F5B700;
    outline-offset: 2px;
}

/* ================= REDUCED MOTION ================= */

@media (prefers-reduced-motion: reduce) {
    .welcome-panel,
    .capability-item,
    .welcome-actions,
    .tour-tooltip {
        animation: none;
        transition: none;
    }
    .welcome-backdrop::before,
    .welcome-backdrop::after {
        animation: none;
        opacity: 0.25;
    }
    
    .welcome-backdrop.active .welcome-panel {
        transform: none;
    }
    
    .capability-item {
        opacity: 1;
        transform: none;
    }
    
    .welcome-actions {
        opacity: 1;
    }

    .capability-item::before {
        display: none;
    }

    .action-btn.primary::before {
        display: none;
    }
}

/* ================= HIGH CONTRAST ================= */

@media (prefers-contrast: high) {
    .welcome-panel {
        background: rgba(0, 0, 0, 0.98);
        border-color: rgba(255, 255, 255, 0.3);
    }

    .capability-item {
        background: rgba(255, 255, 255, 0.05);
        border-color: rgba(255, 255, 255, 0.2);
    }

    .welcome-close {
        background: rgba(255, 255, 255, 0.15);
        border-color: rgba(255, 255, 255, 0.3);
    }

    .action-btn.secondary {
        background: rgba(255, 255, 255, 0.15);
        border-color: rgba(255, 255, 255, 0.3);
    }
}
