* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-color: #06080e;
    --box-bg-top: #0e1322;
    --box-bg-bottom: #090c15;
    --text-primary: #f8fafc;
    --text-muted: #94a3b8;
}

html, body {
    width: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    background-color: var(--bg-color);
    /* Ultra-subtle luxury ambient aura */
    background-image: 
        radial-gradient(circle at 50% 0%, rgba(99, 102, 241, 0.08) 0%, transparent 60%),
        radial-gradient(circle at 85% 85%, rgba(56, 189, 248, 0.04) 0%, transparent 50%);
    font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 32px 16px 20px 16px;
    overflow-x: hidden;
}

/* 
   Adaptive 3-Tier Responsive Box (Premium Luxury Finish):
   1. Desktop Screen: iPad Landscape (Horizontal) - 1180px × 760px
   2. Medium Screen: Rotated iPad Portrait (Vertical) - 768px × 960px
   3. Mobile Screen: iPhone View - 390px × 800px
   - Deep obsidian gradient surface
   - Subtle top specular hairline edge
   - Layered contextual depth shadow
*/

/* --- Tier 1: iPad Landscape (Default Desktop) --- */
.box {
    width: 1180px;
    max-width: calc(100vw - 48px);
    height: 760px;
    max-height: calc(100vh - 84px);
    background: linear-gradient(180deg, var(--box-bg-top) 0%, var(--box-bg-bottom) 100%);
    border-radius: 48px;
    border: none;
    outline: none;
    margin: 0 auto;
    padding: 38px 32px;
    display: flex;
    flex-direction: column;
    align-items: center;

    /* Premium Contextual Shadow + Subtle Top Chamfer Edge */
    box-shadow: 
        0 40px 80px -20px rgba(0, 0, 0, 0.95),
        0 20px 40px -10px rgba(0, 0, 0, 0.75),
        0 0 60px -15px rgba(30, 41, 59, 0.25),
        inset 0 1px 1px 0 rgba(255, 255, 255, 0.09);

    /* Smooth morphing transition when resizing */
    transition: width 0.35s cubic-bezier(0.16, 1, 0.3, 1),
                height 0.35s cubic-bezier(0.16, 1, 0.3, 1),
                max-width 0.35s ease,
                max-height 0.35s ease,
                border-radius 0.35s ease;
}

/* --- Top Center Search Bar (Frosted Glass Finish) --- */
.search-bar {
    position: relative;
    width: 100%;
    max-width: 440px;
    height: 48px;
    background: rgba(255, 255, 255, 0.035);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 999px;
    display: flex;
    align-items: center;
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    box-shadow: 
        0 4px 20px -2px rgba(0, 0, 0, 0.4),
        inset 0 1px 0 rgba(255, 255, 255, 0.06);
    transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}

.search-bar:focus-within {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(99, 102, 241, 0.4);
    box-shadow: 
        0 4px 24px -2px rgba(0, 0, 0, 0.6),
        0 0 25px -4px rgba(99, 102, 241, 0.25),
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
}

.search-icon {
    position: absolute;
    left: 18px;
    width: 18px;
    height: 18px;
    color: rgba(255, 255, 255, 0.4);
    flex-shrink: 0;
    pointer-events: none;
    transition: color 0.2s ease;
}

.search-bar:focus-within .search-icon {
    color: rgba(255, 255, 255, 0.9);
}

.search-input {
    width: 100%;
    height: 100%;
    background: transparent;
    border: none;
    outline: none;
    color: #ffffff;
    font-size: 15px;
    font-family: inherit;
    font-weight: 400;
    letter-spacing: -0.2px;
    text-align: center;
    padding: 0 40px;
}

.search-input::placeholder {
    color: rgba(255, 255, 255, 0.35);
    text-align: center;
}

/* --- Applications Grid (Below Search Bar) --- */
.apps-grid {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 36px 44px;
    margin-top: 56px;
    overflow-y: auto;
    padding: 8px 12px;
}

.app-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.22s cubic-bezier(0.16, 1, 0.3, 1);
    width: 82px;
}

.app-item:hover {
    transform: translateY(-5px);
}

.app-item:active {
    transform: scale(0.92);
}

.app-icon {
    width: 68px;
    height: 68px;
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.app-icon svg {
    width: 32px;
    height: 32px;
    color: #ffffff;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.25));
}

/* Premium Luminous App Gradients */
.icon-notes {
    background: linear-gradient(145deg, #fbbf24 0%, #d97706 50%, #92400e 100%);
    box-shadow: 
        0 14px 28px -6px rgba(217, 119, 6, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.35);
}

.icon-timer {
    background: linear-gradient(145deg, #fb7185 0%, #e11d48 50%, #881337 100%);
    box-shadow: 
        0 14px 28px -6px rgba(225, 29, 72, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.35);
}

.icon-calculator {
    background: linear-gradient(145deg, #38bdf8 0%, #2563eb 50%, #1e3a8a 100%);
    box-shadow: 
        0 14px 28px -6px rgba(37, 99, 235, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.35);
}

.icon-scientific-calculator {
    background: linear-gradient(145deg, #a855f7 0%, #6366f1 50%, #312e81 100%);
    box-shadow: 
        0 14px 28px -6px rgba(99, 102, 241, 0.4),
        inset 0 1px 1px rgba(255, 255, 255, 0.35);
}

.app-item:hover .app-icon {
    filter: brightness(1.08);
}

.app-label {
    margin-top: 10px;
    font-size: 13px;
    font-weight: 500;
    color: #cbd5e1;
    letter-spacing: -0.2px;
    text-align: center;
    transition: color 0.2s ease;
}

.app-item:hover .app-label {
    color: #ffffff;
}

/* --- Below Box Footer --- */
.page-footer {
    margin-top: 20px;
    font-size: 12px;
    color: #475569;
    letter-spacing: 0.2px;
    text-align: center;
    user-select: none;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    flex-wrap: wrap;
}

.footer-divider {
    color: #334155;
    font-size: 10px;
}

.footer-terms-btn {
    background: none;
    border: none;
    color: #64748b;
    font-size: 12px;
    font-family: inherit;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color 0.2s ease;
}

.footer-terms-btn:hover {
    color: #f59e0b;
}

/* --- Disclaimer Modal Dialog --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

/* In Installed Standalone PWA mode, suppress auto-disclaimer unless clicked by user */
@media all and (display-mode: standalone) {
    .modal-overlay:not(.user-opened) {
        display: none !important;
    }
}

.modal-card {
    width: 100%;
    max-width: 560px;
    max-height: 85vh;
    background: #0f1422;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 28px;
    box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.9);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transform: scale(0.95);
    transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.modal-overlay.active .modal-card {
    transform: scale(1);
}

.modal-header {
    padding: 20px 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(15, 20, 34, 0.8);
}

.modal-header-title {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #ffffff;
    font-size: 15px;
}

.modal-close-btn {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 16px;
    cursor: pointer;
    transition: color 0.2s;
}

.modal-close-btn:hover {
    color: #ffffff;
}

.modal-body {
    padding: 20px 24px;
    overflow-y: auto;
    font-size: 13px;
    color: #cbd5e1;
    line-height: 1.6;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-item h4 {
    font-size: 13px;
    font-weight: 600;
    color: #ffffff;
    margin-bottom: 4px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.modal-item p {
    color: #94a3b8;
    font-size: 12px;
}

.modal-footer {
    padding: 16px 24px;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.07);
    background: rgba(15, 20, 34, 0.9);
}

.btn-decline {
    padding: 8px 18px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #94a3b8;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-decline:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.1);
}

.btn-accept {
    padding: 8px 22px;
    border-radius: 999px;
    background: #2563eb;
    border: none;
    color: #ffffff;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(37, 99, 235, 0.35);
    transition: all 0.2s;
}

.btn-accept:hover {
    background: #1d4ed8;
}

/* Modal Footer Mode Toggling: Entry Gatekeeper vs Manual Terms View */
.modal-overlay.user-opened .footer-entry-actions {
    display: none !important;
}
.modal-overlay.user-opened .footer-terms-actions {
    display: flex !important;
    width: 100%;
}
.modal-overlay:not(.user-opened) .footer-entry-actions {
    display: flex !important;
}
.modal-overlay:not(.user-opened) .footer-terms-actions {
    display: none !important;
}

/* --- Tier 2: iPad Portrait (Medium Screens / Rotated iPad) --- */
@media (max-width: 1200px) and (min-width: 769px) {
    .box {
        width: 768px;
        max-width: calc(100vw - 36px);
        height: 960px;
        max-height: calc(100vh - 76px);
        border-radius: 42px;
        padding: 34px 24px;
    }

    .search-bar {
        max-width: 400px;
        height: 46px;
    }

    .apps-grid {
        gap: 32px 34px;
        margin-top: 48px;
    }

    .app-icon {
        width: 64px;
        height: 64px;
        border-radius: 18px;
    }

    .app-icon svg {
        width: 30px;
        height: 30px;
    }
}

/* --- Tier 3: iPhone / Mobile Phone Screen (Fullscreen Native App) --- */
@media (max-width: 768px) {
    html, body {
        padding: 0 !important;
        margin: 0 !important;
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
        min-height: 100dvh !important;
        max-height: 100dvh !important;
        overflow: hidden !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: space-between !important;
    }

    .box {
        width: 100% !important;
        max-width: 100% !important;
        flex: 1 !important;
        height: auto !important;
        max-height: none !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        border: none !important;
        padding: max(20px, env(safe-area-inset-top)) 20px 10px 20px !important;
        display: flex !important;
        flex-direction: column !important;
        justify-content: flex-start !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
    }

    .search-container {
        margin-bottom: 24px !important;
        width: 100% !important;
    }

    .search-bar {
        max-width: 100% !important;
        width: 100% !important;
        height: 48px !important;
    }

    .search-input {
        font-size: 15px !important;
        padding: 0 40px !important;
    }

    .apps-grid {
        gap: 24px 16px !important;
        margin-top: 10px !important;
        display: grid !important;
        grid-template-columns: repeat(3, 1fr) !important;
        width: 100% !important;
        max-width: 360px !important;
        margin-left: auto !important;
        margin-right: auto !important;
    }

    .app-item {
        width: 100% !important;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
    }

    .app-icon {
        width: 68px !important;
        height: 68px !important;
        border-radius: 20px !important;
        margin: 0 auto !important;
    }

    .app-icon svg {
        width: 30px !important;
        height: 30px !important;
    }

    .app-label {
        font-size: 13px !important;
        margin-top: 8px !important;
    }

    /* Pinned inside the screen at the bottom */
    .page-footer {
        position: relative !important;
        bottom: 0 !important;
        left: 0 !important;
        right: 0 !important;
        width: 100% !important;
        flex-shrink: 0 !important;
        margin-top: auto !important;
        padding: 12px 16px max(14px, env(safe-area-inset-bottom)) 16px !important;
        background: rgba(9, 12, 21, 0.98) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.08) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        gap: 8px !important;
        font-size: 11px !important;
        color: #64748b !important;
        z-index: 20 !important;
        user-select: none !important;
    }

    .page-footer span, .page-footer button {
        font-size: 11px !important;
    }

    /* Mobile Disclaimer Modal - Clears Safari Bottom Widgets & Toolbars */
    .modal-overlay {
        position: fixed !important;
        top: 0 !important;
        left: 0 !important;
        right: 0 !important;
        bottom: 0 !important;
        width: 100% !important;
        height: 100% !important;
        height: 100dvh !important;
        height: 100svh !important;
        padding: max(16px, env(safe-area-inset-top, 16px)) 16px max(80px, calc(env(safe-area-inset-bottom, 0px) + 70px)) 16px !important;
        box-sizing: border-box !important;
        display: flex !important;
        align-items: center !important;
        justify-content: center !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        z-index: 99999 !important;
    }

    .modal-card {
        width: 100% !important;
        max-width: 500px !important;
        max-height: calc(100dvh - max(110px, calc(env(safe-area-inset-top, 0px) + env(safe-area-inset-bottom, 0px) + 95px))) !important;
        border-radius: 24px !important;
        display: flex !important;
        flex-direction: column !important;
        overflow: hidden !important;
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.95), 0 0 0 1px rgba(255, 255, 255, 0.12) !important;
        margin: auto 0 !important;
        flex-shrink: 0 !important;
    }

    .modal-header {
        padding: 14px 18px !important;
        flex-shrink: 0 !important;
    }

    .modal-body {
        padding: 14px 18px !important;
        flex: 1 1 auto !important;
        overflow-y: auto !important;
        -webkit-overflow-scrolling: touch !important;
        gap: 12px !important;
    }

    .modal-item h4 {
        font-size: 12px !important;
        margin-bottom: 3px !important;
    }

    .modal-item p {
        font-size: 11.5px !important;
        line-height: 1.5 !important;
    }

    .modal-footer {
        padding: 12px 18px !important;
        flex-shrink: 0 !important;
        background: rgba(13, 18, 30, 0.98) !important;
        border-top: 1px solid rgba(255, 255, 255, 0.1) !important;
        display: flex !important;
        align-items: center !important;
        justify-content: flex-end !important;
        gap: 10px !important;
        z-index: 10 !important;
    }

    .btn-accept, .btn-decline {
        padding: 9px 18px !important;
        font-size: 12px !important;
        min-height: 40px !important;
        display: inline-flex !important;
        align-items: center !important;
        justify-content: center !important;
        touch-action: manipulation !important;
    }
}

/* Standalone PWA Mode (Installed on Home Screen) */
@media all and (display-mode: standalone) {
    html, body {
        padding: 0 !important;
        margin: 0 !important;
    }
    .box {
        border-radius: 0 !important;
        box-shadow: none !important;
        width: 100% !important;
        max-width: 100% !important;
        padding-top: max(24px, env(safe-area-inset-top)) !important;
    }
}

/* --- PWA Install Guidance Toasts (Android, iOS & Success) --- */
.install-toast,
.ios-install-toast {
    position: fixed;
    bottom: max(20px, calc(env(safe-area-inset-bottom, 0px) + 16px));
    left: 50%;
    transform: translateX(-50%) translateY(140px);
    background: #0f172a;
    border: 1px solid rgba(56, 189, 248, 0.3);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.75);
    border-radius: 18px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    z-index: 999;
    max-width: 92vw;
    width: 390px;
    color: #f1f5f9;
    font-size: 13px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

.install-toast.show,
.ios-install-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
    pointer-events: auto;
}

.install-toast .toast-icon,
.ios-install-toast .toast-icon {
    font-size: 16px;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.ios-toast-icon,
.ios-install-toast .toast-icon {
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.15);
}

.android-toast-icon {
    color: #4ade80;
    background: rgba(74, 222, 128, 0.15);
}

.success-toast-icon {
    color: #38bdf8;
    background: rgba(56, 189, 248, 0.15);
}

.install-toast .toast-text-wrap {
    flex: 1;
    min-width: 0;
}

.install-toast .toast-title {
    font-weight: 600;
    font-size: 13px;
    color: #ffffff;
}

.install-toast .toast-subtext {
    font-size: 11px;
    color: #94a3b8;
    margin-top: 2px;
    line-height: 1.35;
}

.install-toast .toast-action-btn {
    background: #2563eb;
    border: none;
    color: #ffffff;
    padding: 7px 14px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
    transition: background 0.15s ease;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.install-toast .toast-action-btn:hover {
    background: #1d4ed8;
}

.install-toast .toast-close,
.ios-install-toast .toast-close {
    background: none;
    border: none;
    color: #64748b;
    font-size: 14px;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
}
