/* ========================================
   APPS PAGE - App Selection Styles
   Unique styling with copper/amber accents
   ======================================== */

/* Disable double-tap zoom on mobile */
html, body {
    touch-action: manipulation;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
}

/* Allow text selection for input fields */
input, textarea, select {
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
    user-select: text;
}

/* Apps selection container - Default to dark theme colors */
.apps-selection-container {
    position: relative;
    width: 100%;
    min-height: 100vh;
    min-height: 100svh;
    background: linear-gradient(180deg, #000000 0%, #0a0a12 50%, #000000 100%);
    z-index: 1;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    text-align: center;
    font-family: 'JetBrains Mono', 'Courier New', Courier, monospace;
    color: #FFFFFF;
    flex-direction: column;
    overflow: visible;
}

/* Hide apps selection page by default */
.apps-selection-container:not(.active) {
    display: none;
}

/* Apps content container - normal document flow */
.apps-content-container {
    margin: 0 auto;
    padding: 20px 1rem;
    max-width: 90rem;
    width: 100%;
    line-height: 1.6;
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    min-height: 100vh;
    min-height: 100svh;
    position: relative;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* PWA and mobile browser specific heights */
body.pwa-standalone .apps-content-container {
    min-height: 100vh;
    min-height: 100svh;
}

body.mobile-browser .apps-content-container {
    min-height: 100vh;
    min-height: 100svh;
}

/* Mobile: Force full height for proper mobile experience */
@media (max-width: 768px) {
    .apps-selection-container {
        min-height: 100vh;
        min-height: 100svh;
    }
    
    .apps-content-container {
        min-height: 100vh;
        min-height: 100svh;
    }
}

/* Apps content text (header) - Default to dark theme white */
.apps-content-text {
    font-family: 'Orbitron', 'Rajdhani', 'Bebas Neue', 'JetBrains Mono', 'Courier New', Courier, monospace;
    font-size: clamp(3rem, 10vw, 6rem);
    font-weight: 900;
    margin-top: 0px;
    margin-bottom: 80px;
    color: #FFFFFF;
    text-align: center;
    padding-top: 12px;
    transition: opacity 0.3s ease;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    text-shadow: 0 0 8px rgba(212, 165, 116, 0.3);
    line-height: 1.2;
}

/* Fade out content text when scrolling */
.apps-content-text.fade-out {
    opacity: 0;
}

/* Light theme text - Clean black with subtle blue glow */
html.theme-light .apps-content-text { 
    color: #000000;
    background: none;
    -webkit-background-clip: unset;
    -webkit-text-fill-color: unset;
    background-clip: unset;
    text-shadow: 0 0 6px rgba(31, 117, 254, 0.25);
    filter: none;
    font-weight: 900;
}

/* Mobile responsive header text */
@media (max-width: 768px) {
    .apps-content-text {
        font-size: clamp(2rem, 9vw, 3.5rem);
        margin-top: 0px;
        margin-bottom: 60px;
        padding-top: 8px;
        letter-spacing: 0.15em;
    }
}

/* Mobile and PWA positioning */
@media (max-width: 480px) {
    .apps-content-text {
        margin-top: 0px;
        margin-bottom: 48px;
        padding-top: 4px;
        font-size: clamp(1.8rem, 8vw, 2.8rem);
        letter-spacing: 0.12em;
    }
    
    .apps-content-container {
        padding-top: 0px;
    }
    
    /* PWA-specific minimal padding */
    @media (display-mode: standalone) {
        .apps-content-container {
            padding-top: 0px;
        }
        
        .apps-content-text {
            padding-top: 1px;
        }
    }
}

/* Apps tiles container - Professional responsive grid */
.apps-tiles-container {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 320px));
    gap: 24px;
    max-width: 900px;
    width: 100%;
    margin-top: 12px;
    padding: 0 10px;
    justify-content: center;
}

/* Desktop: Constrain tile size for professional appearance */
@media (min-width: 769px) {
    .apps-tiles-container {
        grid-template-columns: repeat(auto-fit, minmax(280px, 320px));
        gap: 32px;
        max-width: 1200px;
    }
}

/* Large desktop: Keep tiles at optimal size */
@media (min-width: 1200px) {
    .apps-tiles-container {
        grid-template-columns: repeat(auto-fit, 320px);
        gap: 40px;
    }
}

/* Tablet landscape: Moderate sizing */
@media (min-width: 769px) and (max-width: 1024px) {
    .apps-tiles-container {
        grid-template-columns: repeat(auto-fit, minmax(260px, 300px));
        gap: 28px;
    }
}

/* Apps tile wrapper - Contains tile and label */
.apps-tile-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0;
    width: 100%;
}

/* Apps tile label container */
.apps-tile-label {
    width: 100%;
    text-align: center;
    margin-top: 20px;
    padding: 0 8px;
    opacity: 0;
    transform: translateY(-8px);
    animation: labelFadeIn 0.6s ease-out 0.3s forwards;
}

@keyframes labelFadeIn {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Apps tile label text - Default to dark theme white */
.apps-tile-label-text {
    font-family: 'Rajdhani', 'JetBrains Mono', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    font-size: clamp(15px, 2.5vw, 18px);
    font-weight: 600;
    letter-spacing: 0.5px;
    line-height: 1.3;
    color: #FFFFFF;
    text-shadow: 0 0 6px rgba(232, 196, 160, 0.3);
    transition: all 0.3s ease;
    display: inline-block;
    position: relative;
}

/* Hover effect for dark theme default */
.apps-tile-wrapper:hover .apps-tile-label-text {
    text-shadow: 0 0 8px rgba(232, 196, 160, 0.4);
}

/* Light theme - Clean black with subtle blue glow */
html.theme-light .apps-tile-label-text {
    color: #000000;
    background: none;
    -webkit-background-clip: unset;
    -webkit-text-fill-color: unset;
    background-clip: unset;
    text-shadow: 0 0 5px rgba(31, 117, 254, 0.25);
    filter: none;
}

html.theme-light .apps-tile-wrapper:hover .apps-tile-label-text {
    text-shadow: 0 0 7px rgba(31, 117, 254, 0.35);
}

/* Desktop: Enhanced typography */
@media (min-width: 769px) {
    .apps-tile-label {
        margin-top: 24px;
    }
    
    .apps-tile-label-text {
        font-size: clamp(16px, 1.8vw, 20px);
        font-weight: 600;
        letter-spacing: 0.8px;
    }
}

/* Large desktop: Optimal spacing */
@media (min-width: 1200px) {
    .apps-tile-label {
        margin-top: 28px;
    }
    
    .apps-tile-label-text {
        font-size: 20px;
        letter-spacing: 1px;
    }
}

/* Hover effect - Subtle enhancement on parent wrapper hover */
.apps-tile-wrapper:hover .apps-tile-label-text {
    transform: translateY(-1px);
}

/* Mobile optimizations - Match PWA text sizes */
@media (max-width: 768px) {
    .apps-tile-label {
        margin-top: 14px;
        padding: 0 4px;
    }
    
    .apps-tile-label-text {
        font-size: clamp(16px, 4vw, 19px);
        font-weight: 600;
        letter-spacing: 0.7px;
    }
}

/* Extra small screens - Match PWA text sizes */
@media (max-width: 480px) {
    .apps-tile-label {
        margin-top: 12px;
    }
    
    .apps-tile-label-text {
        font-size: clamp(15px, 4.2vw, 18px);
        letter-spacing: 0.6px;
    }
}

/* PWA optimizations - Enhanced for standalone mode */
@media (display-mode: standalone) {
    .apps-tile-label {
        margin-top: 26px;
    }
    
    .apps-tile-label-text {
        font-size: clamp(17px, 2vw, 21px);
        letter-spacing: 0.9px;
    }
}

/* Individual apps tile - Default to dark theme white border */
.apps-tile {
    position: relative;
    background: linear-gradient(135deg, #0a0a12 0%, #12121a 100%);
    border: 2px solid #FFFFFF;
    border-radius: 54px;
    cursor: pointer;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
    aspect-ratio: 1/1;
    min-height: 180px;
    max-height: 320px;
    box-shadow: 0 0 8px rgba(212, 165, 116, 0.15);
}

/* Desktop: Professional tile sizing */
@media (min-width: 769px) {
    .apps-tile {
        min-height: 280px;
        max-height: 320px;
        border-radius: 64px;
    }
    
    .apps-tile-image {
        border-radius: 60px;
    }
}

/* Default hover - dark theme white border */
.apps-tile:hover {
    transform: translateY(-4px) scale(1.02);
    box-shadow: 
        0 0 12px rgba(232, 196, 160, 0.25),
        0 4px 16px rgba(212, 165, 116, 0.2);
    border-color: #FFFFFF;
}

/* Desktop: More subtle and professional hover */
@media (min-width: 769px) {
    .apps-tile:hover {
        transform: translateY(-6px) scale(1.01);
        box-shadow: 
            0 0 15px rgba(232, 196, 160, 0.3),
            0 6px 20px rgba(212, 165, 116, 0.2);
    }
}

/* Light theme tiles - Black border with subtle blue glow */
html.theme-light .apps-tile {
    background: #ffffff;
    border: 2px solid #000000;
    box-shadow: 0 0 6px rgba(31, 117, 254, 0.12);
}

html.theme-light .apps-tile:hover {
    border-color: #000000;
    box-shadow: 
        0 0 10px rgba(31, 117, 254, 0.2),
        0 4px 14px rgba(21, 87, 199, 0.15);
}

/* Default selected state - dark theme white border */
.apps-tile.selected {
    border-color: #FFFFFF;
    border-width: 3px;
    box-shadow: 
        0 0 15px rgba(232, 196, 160, 0.35),
        0 0 28px rgba(232, 196, 160, 0.25);
    transform: translateY(-4px);
}

/* Light theme selected state - Black border with subtle blue glow */
html.theme-light .apps-tile.selected {
    border-color: #000000;
    border-width: 3px;
    box-shadow: 
        0 0 14px rgba(31, 117, 254, 0.3),
        0 0 24px rgba(21, 87, 199, 0.2);
    transform: translateY(-4px);
}

/* Sophisticated photo animation for selected state */
.apps-tile.selected .apps-tile-image {
    overflow: hidden;
    position: relative;
}

.apps-tile.selected .apps-tile-image::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        135deg,
        rgba(212, 165, 116, 0.08) 0%,
        rgba(212, 165, 116, 0.04) 30%,
        rgba(212, 165, 116, 0.12) 60%,
        rgba(212, 165, 116, 0.06) 100%
    );
    opacity: 0;
    z-index: 5;
    animation: elegantShimmer 3s ease-in-out infinite;
}

.apps-tile.selected .apps-tile-image img {
    transform: scale(1.03);
    filter: brightness(1.1) contrast(1.05) saturate(1.15);
    transition: all 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94);
}

/* Elegant shimmer animation */
@keyframes elegantShimmer {
    0%, 100% {
        opacity: 0;
        transform: translateX(-100%) skewX(-15deg);
    }
    50% {
        opacity: 1;
        transform: translateX(100%) skewX(-15deg);
    }
}

/* Light theme photo enhancement */
html.theme-light .apps-tile.selected .apps-tile-image::before {
    background: linear-gradient(
        135deg,
        rgba(31, 117, 254, 0.06) 0%,
        rgba(31, 117, 254, 0.03) 30%,
        rgba(31, 117, 254, 0.10) 60%,
        rgba(31, 117, 254, 0.04) 100%
    );
}

html.theme-light .apps-tile.selected .apps-tile-image img {
    filter: brightness(1.08) contrast(1.03) saturate(1.12);
}

/* Mobile optimizations for photo animation */
@media (max-width: 768px) {
    .apps-tile.selected .apps-tile-image img {
        transform: scale(1.02);
        filter: brightness(1.08) contrast(1.03) saturate(1.12);
    }

    html.theme-light .apps-tile.selected .apps-tile-image img {
        filter: brightness(1.06) contrast(1.02) saturate(1.08);
    }

    .apps-tile.selected .apps-tile-image::before {
        animation: elegantShimmer 2.5s ease-in-out infinite;
    }
}

/* Tiny screen optimizations */
@media (max-width: 480px) {
    .apps-tile.selected .apps-tile-image img {
        transform: scale(1.015);
        filter: brightness(1.06) contrast(1.02) saturate(1.08);
    }

    html.theme-light .apps-tile.selected .apps-tile-image img {
        filter: brightness(1.04) contrast(1.01) saturate(1.05);
    }

    .apps-tile.selected .apps-tile-image::before {
        animation: elegantShimmer 2s ease-in-out infinite;
    }
}

/* PWA optimizations */
@media (display-mode: standalone) {
    .apps-tile.selected .apps-tile-image img {
        transform: scale(1.04);
        filter: brightness(1.12) contrast(1.06) saturate(1.18);
    }

    html.theme-light .apps-tile.selected .apps-tile-image img {
        filter: brightness(1.10) contrast(1.04) saturate(1.15);
    }

    .apps-tile.selected .apps-tile-image::before {
        animation: elegantShimmer 3.5s ease-in-out infinite;
    }
}

/* Apps tile image container */
.apps-tile-image {
    position: relative;
    width: 100%;
    height: 100%;
    overflow: hidden;
    border-bottom: none;
    border-radius: 50px;
}

.apps-tile-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    min-opacity: 0.3 !important;
    background-color: #1a1a2e;
    transition: transform 0.5s ease, filter 0.5s ease;
    border-radius: inherit;
}

/* Hover effect on images */
.apps-tile:hover .apps-tile-image img {
    transform: scale(1.05);
    filter: brightness(1.1);
}

/* Image loading states */
.apps-tile-image img.image-loading {
    opacity: 0.7;
    background: linear-gradient(45deg, #1a1a2e 25%, #2a2a4e 25%, #2a2a4e 50%, #1a1a2e 50%, #1a1a2e 75%, #2a2a4e 75%);
    background-size: 20px 20px;
    animation: loading-shimmer 1.5s ease-in-out infinite;
}

.apps-tile-image img.image-error {
    opacity: 0.6 !important;
    filter: grayscale(20%) brightness(0.9);
    border: 1px solid rgba(212, 165, 116, 0.2);
}

.apps-tile-image img.image-intervention {
    opacity: 0.8 !important;
    filter: brightness(0.95);
}

.apps-tile-image img.image-loaded {
    opacity: 1 !important;
    filter: none;
}

/* Dark theme adjustments for image states */
html.theme-dark .apps-tile-image img {
    background-color: #1a1a2e;
}

html.theme-dark .apps-tile-image img.image-loading {
    background: linear-gradient(45deg, #1a1a2e 25%, #2a2a4e 25%, #2a2a4e 50%, #1a1a2e 50%, #1a1a2e 75%, #2a2a4e 75%);
    background-size: 20px 20px;
}

html.theme-dark .apps-tile-image img.image-error {
    border: 1px solid rgba(212, 165, 116, 0.2);
}

@keyframes loading-shimmer {
    0% { background-position: 0 0; }
    100% { background-position: 40px 40px; }
}

/* No overlay needed */
.apps-tile-overlay {
    display: none;
}

/* Lock icon styling - Centered at bottom */
.apps-tile-lock {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    font-size: clamp(20px, 5vw, 32px);
    color: #FFFFFF;
    z-index: 15;
    
    filter: drop-shadow(0 4px 8px rgba(0, 0, 0, 0.5));
    
    text-shadow: 
        0 0 12px rgba(212, 165, 116, 0.8),
        0 0 24px rgba(212, 165, 116, 0.5),
        0 0 36px rgba(212, 165, 116, 0.3);
    
    transition: all 0.3s ease;
    animation: lockPulse 2s ease-in-out infinite;
}

/* Dark theme lock - White with subtle copper glow */
html.theme-dark .apps-tile-lock {
    color: #FFFFFF;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.3));
    text-shadow: 0 0 8px rgba(232, 196, 160, 0.4);
    animation: lockPulseDark 2s ease-in-out infinite;
}

@keyframes lockPulseDark {
    0%, 100% {
        text-shadow: 0 0 8px rgba(232, 196, 160, 0.4);
    }
    50% {
        text-shadow: 0 0 12px rgba(232, 225, 255, 0.5);
    }
}

html.theme-dark .apps-tile:hover .apps-tile-lock {
    transform: translateX(-50%) scale(1.15);
    text-shadow: 0 0 12px rgba(232, 225, 255, 0.5);
}

/* Light theme lock - Black with subtle blue glow */
html.theme-light .apps-tile-lock {
    color: #000000;
    filter: drop-shadow(0 2px 4px rgba(31, 117, 254, 0.2));
    text-shadow: 0 0 6px rgba(31, 117, 254, 0.35);
    animation: lockPulseLight 2s ease-in-out infinite;
}

@keyframes lockPulseLight {
    0%, 100% {
        text-shadow: 0 0 6px rgba(31, 117, 254, 0.35);
    }
    50% {
        text-shadow: 0 0 10px rgba(31, 117, 254, 0.45);
    }
}

html.theme-light .apps-tile:hover .apps-tile-lock {
    transform: translateX(-50%) scale(1.15);
    text-shadow: 0 0 10px rgba(31, 117, 254, 0.45);
}

@keyframes lockPulse {
    0%, 100% {
        text-shadow: 
            0 0 12px rgba(212, 165, 116, 0.8),
            0 0 24px rgba(212, 165, 116, 0.5),
            0 0 36px rgba(212, 165, 116, 0.3);
    }
    50% {
        text-shadow: 
            0 0 16px rgba(212, 165, 116, 1),
            0 0 32px rgba(212, 165, 116, 0.7),
            0 0 48px rgba(212, 165, 116, 0.4);
    }
}

/* Hover effect for lock */
.apps-tile:hover .apps-tile-lock {
    transform: translateX(-50%) scale(1.15);
    text-shadow: 
        0 0 16px rgba(212, 165, 116, 1),
        0 0 32px rgba(212, 165, 116, 0.8),
        0 0 48px rgba(212, 165, 116, 0.5);
}

/* Coming soon tile styling */
.apps-tile.coming-soon {
    opacity: 1;
    cursor: pointer;
}

.apps-tile.coming-soon:hover {
    opacity: 1;
}

/* Subtle vignette overlay for locked tiles */
.apps-tile.coming-soon .apps-tile-image::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle at center, transparent 30%, rgba(0, 0, 0, 0.3) 100%);
    pointer-events: none;
    border-radius: inherit;
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .apps-tiles-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 18px;
        max-width: 100%;
        margin-top: 0px;
    }

    .apps-tile {
        min-height: 160px;
        border-radius: 54px;
    }

    .apps-tile-image {
        border-radius: 50px;
    }

    .apps-tile-lock {
        font-size: clamp(18px, 4.5vw, 28px);
        bottom: 16px;
    }

    .apps-tile.selected {
        border-width: 2px;
    }
    
    html.theme-dark .apps-tile.selected {
        box-shadow: 
            0 0 12px rgba(232, 196, 160, 0.3),
            0 0 20px rgba(232, 196, 160, 0.2);
    }
    
    html.theme-light .apps-tile.selected {
        box-shadow: 
            0 0 10px rgba(31, 117, 254, 0.25),
            0 0 18px rgba(21, 87, 199, 0.18);
    }

    .apps-content-text {
        margin-top: 8px;
        margin-bottom: 65px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .apps-tiles-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .apps-tile {
        min-height: 140px;
        border-radius: 54px;
    }

    .apps-tile-image {
        border-radius: 50px;
    }

    .apps-tile-lock {
        font-size: clamp(16px, 4vw, 24px);
        bottom: 14px;
    }

    .apps-tile.selected {
        border-width: 2px;
    }
    
    html.theme-dark .apps-tile.selected {
        box-shadow: 
            0 0 10px rgba(232, 196, 160, 0.28),
            0 0 18px rgba(232, 196, 160, 0.18);
    }
    
    html.theme-light .apps-tile.selected {
        box-shadow: 
            0 0 9px rgba(31, 117, 254, 0.23),
            0 0 16px rgba(21, 87, 199, 0.15);
    }
}

/* PWA adjustments */
@media (display-mode: standalone) {
    .apps-selection-container {
        padding-top: max(8vh, env(safe-area-inset-top, 60px));
    }
    
    .apps-tile-lock {
        text-shadow: 
            0 0 14px rgba(212, 165, 116, 0.9),
            0 0 28px rgba(212, 165, 116, 0.6),
            0 0 42px rgba(212, 165, 116, 0.4);
        filter: drop-shadow(0 3px 6px rgba(0, 0, 0, 0.5));
    }
}

/* Light theme overrides */
html.theme-light .apps-selection-container {
    background: linear-gradient(180deg, #f8f8f8 0%, #f0f4ff 50%, #f8f8f8 100%);
    color: #1F75FE;
}

html.theme-light .apps-tile-image img {
    background-color: #f0f0f0;
}

html.theme-light .apps-tile-image img.image-loading {
    background: linear-gradient(45deg, #f0f0f0 25%, #e0e0e0 25%, #e0e0e0 50%, #f0f0f0 50%, #f0f0f0 75%, #e0e0e0 75%);
    background-size: 20px 20px;
}

html.theme-light .apps-tile.coming-soon .apps-tile-image::after {
    background: radial-gradient(circle at center, transparent 30%, rgba(255, 255, 255, 0.2) 100%);
}

/* ========================================
   BACK BUTTON - Bottom Navigation
   ======================================== */

.back-button-container {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 20px;
    padding-bottom: max(20px, env(safe-area-inset-bottom, 20px));
    pointer-events: none;
    z-index: 100;
}

/* Default to dark theme white */
.back-button {
    /* Reset button styles */
    background: none;
    border: none;
    outline: none;
    
    /* Text styling - default dark theme white */
    font-family: 'JetBrains Mono', 'Courier New', Courier, monospace;
    font-size: clamp(14px, 3vw, 18px);
    font-weight: 600;
    letter-spacing: 2px;
    color: #FFFFFF;
    
    /* Layout */
    padding: 12px 32px;
    cursor: pointer;
    pointer-events: auto;
    
    /* Professional subtle effects */
    position: relative;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    
    /* Subtle shadow for depth */
    text-shadow: 0 0 6px rgba(232, 196, 160, 0.25);
    
    /* Invisible background that appears on hover */
    border-radius: 8px;
}

/* Pseudo-element for the hover/active background */
.back-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(212, 165, 116, 0.08);
    border-radius: 8px;
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: -1;
    transform: scale(0.9);
}

/* Hover state - elegant elevation */
.back-button:hover {
    transform: translateY(-2px);
    text-shadow: 0 0 8px rgba(232, 196, 160, 0.35);
    color: #FFFFFF;
}

.back-button:hover::before {
    opacity: 1;
    transform: scale(1);
}

/* Active/Click state - subtle press */
.back-button:active {
    transform: translateY(1px);
    text-shadow: 0 0 6px rgba(232, 196, 160, 0.25);
}

.back-button:active::before {
    opacity: 1;
    transform: scale(0.95);
    background: rgba(212, 165, 116, 0.12);
}

/* Unique ripple effect on click */
@keyframes ripple {
    0% {
        transform: scale(0);
        opacity: 0.6;
    }
    100% {
        transform: scale(2.5);
        opacity: 0;
    }
}

.back-button::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, rgba(232, 196, 160, 0.2) 0%, transparent 70%);
    border-radius: 50%;
    transform: translate(-50%, -50%) scale(0);
    opacity: 0;
    pointer-events: none;
}

.back-button:active::after {
    animation: ripple 0.6s ease-out;
}

html.theme-dark .back-button:active {
    text-shadow: 0 0 6px rgba(232, 196, 160, 0.25);
}

html.theme-dark .back-button:active::before {
    background: rgba(212, 165, 116, 0.12);
}

html.theme-dark .back-button::after {
    background: radial-gradient(circle, rgba(232, 196, 160, 0.2) 0%, transparent 70%);
}

/* Light theme enhanced styles - Clean black with subtle blue glow */
html.theme-light .back-button {
    color: #000000;
    text-shadow: 0 0 5px rgba(31, 117, 254, 0.2);
}

html.theme-light .back-button::before {
    background: rgba(31, 117, 254, 0.06);
}

html.theme-light .back-button:hover {
    text-shadow: 0 0 7px rgba(31, 117, 254, 0.3);
    color: #000000;
}

html.theme-light .back-button:active::before {
    background: rgba(31, 117, 254, 0.1);
}

html.theme-light .back-button::after {
    background: radial-gradient(circle, rgba(31, 117, 254, 0.18) 0%, transparent 70%);
}

/* Mobile optimizations */
@media (max-width: 768px) {
    .back-button-container {
        padding: 16px;
        padding-bottom: max(16px, env(safe-area-inset-bottom, 16px));
    }
    
    .back-button {
        font-size: clamp(13px, 3.5vw, 16px);
        padding: 10px 28px;
        letter-spacing: 1.5px;
    }
}

/* Tiny screens */
@media (max-width: 480px) {
    .back-button-container {
        padding: 14px;
        padding-bottom: max(14px, env(safe-area-inset-bottom, 14px));
    }
    
    .back-button {
        font-size: clamp(12px, 3.2vw, 14px);
        padding: 9px 24px;
        letter-spacing: 1.2px;
    }
}

/* PWA optimizations */
@media (display-mode: standalone) {
    .back-button-container {
        padding-bottom: max(24px, env(safe-area-inset-bottom, 24px));
    }
    
    .back-button {
        font-size: clamp(15px, 3vw, 19px);
        padding: 13px 36px;
    }
}

/* ========================================
   FIRSTLOOK PORTAL REVEAL ANIMATION
   Premium game-like reveal for non-logged-in users
   ======================================== */

/* Tile expansion for mobile portal - smooth height transition */
#firstlook-tile {
    transition: 
        transform 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        box-shadow 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        border-color 0.4s cubic-bezier(0.4, 0, 0.2, 1),
        aspect-ratio 0.5s cubic-bezier(0.34, 1.56, 0.64, 1),
        min-height 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* Mobile expansion when portal is active */
@media (max-width: 768px) {
    #firstlook-tile.portal-expanded {
        aspect-ratio: 1 / 1.35;
        min-height: 220px;
    }
    
    /* Shift portal content down to add space below X button */
    #firstlook-tile.portal-expanded .portal-content {
        transform: translate(-50%, -46%);
    }
    
    /* Slightly larger gap for expanded view */
    #firstlook-tile.portal-expanded .portal-actions {
        gap: 10px;
    }
}

@media (max-width: 480px) {
    #firstlook-tile.portal-expanded {
        aspect-ratio: 1 / 1.45;
        min-height: 195px;
    }
    
    /* Shift content down more on smaller screens */
    #firstlook-tile.portal-expanded .portal-content {
        transform: translate(-50%, -44%);
    }
    
    #firstlook-tile.portal-expanded .portal-actions {
        gap: 9px;
    }
    
    #firstlook-tile.portal-expanded .portal-btn {
        padding: 11px 22px;
    }
    
    #firstlook-tile.portal-expanded .portal-btn.portal-about {
        padding: 11px 22px;
    }
}

/* PWA mobile expansion - slightly more room */
@media (max-width: 768px) and (display-mode: standalone) {
    #firstlook-tile.portal-expanded {
        aspect-ratio: 1 / 1.38;
        min-height: 250px;
    }
    
    /* Shift content down for PWA */
    #firstlook-tile.portal-expanded .portal-content {
        transform: translate(-50%, -46%);
    }
    
    #firstlook-tile.portal-expanded .portal-actions {
        gap: 12px;
    }
    
    #firstlook-tile.portal-expanded .portal-btn {
        padding: 14px 28px;
    }
    
    #firstlook-tile.portal-expanded .portal-btn.portal-about {
        padding: 14px 28px;
    }
}

/* Portal overlay container */
.firstlook-portal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border-radius: inherit;
    z-index: 50;
    pointer-events: none;
    opacity: 0;
    overflow: hidden;
    transition: opacity 0.4s ease;
}

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

/* Portal background with radial reveal */
.portal-backdrop {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.95);
    border-radius: inherit;
    transform: scale(0);
    transform-origin: center center;
    transition: transform 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.firstlook-portal-overlay.active .portal-backdrop {
    transform: scale(1);
}

/* Light theme backdrop */
html.theme-light .portal-backdrop {
    background: rgba(248, 248, 248, 0.97);
}

/* Portal energy ring effect */
.portal-ring {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    pointer-events: none;
}

.portal-ring::before,
.portal-ring::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    border-radius: 50%;
    transform: translate(-50%, -50%);
    animation: none;
}

.firstlook-portal-overlay.active .portal-ring::before {
    width: 200%;
    height: 200%;
    border: 2px solid rgba(212, 165, 116, 0.6);
    box-shadow: 
        0 0 20px rgba(212, 165, 116, 0.4),
        inset 0 0 20px rgba(212, 165, 116, 0.2);
    animation: portalRingExpand 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) forwards;
}

.firstlook-portal-overlay.active .portal-ring::after {
    width: 150%;
    height: 150%;
    border: 1px solid rgba(212, 165, 116, 0.3);
    animation: portalRingExpand 0.8s cubic-bezier(0.25, 0.46, 0.45, 0.94) 0.1s forwards;
}

/* Light theme ring colors */
html.theme-light .firstlook-portal-overlay.active .portal-ring::before {
    border-color: rgba(31, 117, 254, 0.5);
    box-shadow: 
        0 0 20px rgba(31, 117, 254, 0.3),
        inset 0 0 20px rgba(31, 117, 254, 0.15);
}

html.theme-light .firstlook-portal-overlay.active .portal-ring::after {
    border-color: rgba(31, 117, 254, 0.25);
}

@keyframes portalRingExpand {
    0% {
        width: 0;
        height: 0;
        opacity: 1;
    }
    70% {
        opacity: 1;
    }
    100% {
        width: 300%;
        height: 300%;
        opacity: 0;
    }
}

/* Particle container */
.portal-particles {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    overflow: hidden;
    border-radius: inherit;
}

/* Individual particle - Default to dark theme gold/white */
.portal-particle {
    position: absolute;
    width: 4px;
    height: 4px;
    background: #D4A574;
    border-radius: 50%;
    opacity: 0;
    box-shadow: 0 0 6px rgba(212, 165, 116, 0.8);
}

html.theme-light .portal-particle {
    background: #1F75FE;
    box-shadow: 0 0 6px rgba(31, 117, 254, 0.6);
}

/* Particle animation variants */
.firstlook-portal-overlay.active .portal-particle:nth-child(1) { animation: particleFloat 2s ease-in-out infinite 0.1s; top: 20%; left: 10%; }
.firstlook-portal-overlay.active .portal-particle:nth-child(2) { animation: particleFloat 2.2s ease-in-out infinite 0.3s; top: 30%; right: 15%; }
.firstlook-portal-overlay.active .portal-particle:nth-child(3) { animation: particleFloat 1.8s ease-in-out infinite 0.2s; bottom: 25%; left: 20%; }
.firstlook-portal-overlay.active .portal-particle:nth-child(4) { animation: particleFloat 2.4s ease-in-out infinite 0.4s; bottom: 35%; right: 10%; }
.firstlook-portal-overlay.active .portal-particle:nth-child(5) { animation: particleFloat 2s ease-in-out infinite 0.5s; top: 50%; left: 5%; }
.firstlook-portal-overlay.active .portal-particle:nth-child(6) { animation: particleFloat 2.3s ease-in-out infinite 0.15s; top: 15%; right: 25%; }
.firstlook-portal-overlay.active .portal-particle:nth-child(7) { animation: particleFloat 1.9s ease-in-out infinite 0.35s; bottom: 15%; left: 30%; }
.firstlook-portal-overlay.active .portal-particle:nth-child(8) { animation: particleFloat 2.1s ease-in-out infinite 0.25s; bottom: 45%; right: 20%; }

@keyframes particleFloat {
    0%, 100% {
        opacity: 0;
        transform: translateY(0) scale(0.5);
    }
    20% {
        opacity: 0.8;
        transform: translateY(-5px) scale(1);
    }
    50% {
        opacity: 0.6;
        transform: translateY(-15px) scale(0.8);
    }
    80% {
        opacity: 0.4;
        transform: translateY(-25px) scale(0.6);
    }
}

/* Portal content container */
.portal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    width: 85%;
    max-width: 220px;
    z-index: 10;
    pointer-events: none; /* Block all clicks until ready */
}

/* Enable content interaction only when buttons are ready */
.firstlook-portal-overlay.active.buttons-ready .portal-content {
    pointer-events: auto;
}

/* Portal title - Default to dark theme white */
.portal-title {
    font-family: 'Rajdhani', 'Orbitron', 'JetBrains Mono', sans-serif;
    font-size: clamp(11px, 2.5vw, 14px);
    font-weight: 600;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: rgba(255, 255, 255, 0.85);
    text-shadow: 0 0 8px rgba(212, 165, 116, 0.4);
    text-align: center;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
    margin-bottom: 4px;
}

.firstlook-portal-overlay.active .portal-title {
    opacity: 1;
    transform: translateY(0);
    transition-delay: 0.3s;
}

html.theme-light .portal-title {
    color: #1F75FE;
    text-shadow: none;
}

/* Portal action buttons container */
.portal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    width: 100%;
}

/* Individual portal button */
.portal-btn {
    position: relative;
    width: 100%;
    padding: 14px 24px;
    font-family: 'Rajdhani', 'Orbitron', 'JetBrains Mono', sans-serif;
    font-size: clamp(13px, 2.8vw, 16px);
    font-weight: 700;
    letter-spacing: 3px;
    text-transform: uppercase;
    text-decoration: none;
    text-align: center;
    border: none;
    border-radius: 50px; /* Pill shape - matches mobile/PWA */
    cursor: pointer;
    overflow: hidden;
    opacity: 0;
    transform: translateY(30px) scale(0.9);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    -webkit-tap-highlight-color: transparent;
    pointer-events: none; /* Disabled until animation completes */
}

/* Enable button clicks only when portal is active AND animation is complete */
.firstlook-portal-overlay.active.buttons-ready .portal-btn {
    pointer-events: auto;
}

/* Staggered entrance for buttons */
.firstlook-portal-overlay.active .portal-btn:nth-child(1) {
    opacity: 1;
    transform: translateY(0) scale(1);
    transition-delay: 0.4s;
}

.firstlook-portal-overlay.active .portal-btn:nth-child(2) {
    opacity: 1;
    transform: translateY(0) scale(1);
    transition-delay: 0.5s;
}

.firstlook-portal-overlay.active .portal-btn:nth-child(3) {
    opacity: 1;
    transform: translateY(0) scale(1);
    transition-delay: 0.6s;
}

/* SIGN UP button - Default to dark theme yellow */
.portal-btn.portal-signup {
    background: linear-gradient(135deg, #D4A574 0%, #A67B5B 100%);
    color: #000000;
    box-shadow: 
        0 4px 15px rgba(212, 165, 116, 0.35),
        0 2px 6px rgba(0, 0, 0, 0.3),
        inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

.portal-btn.portal-signup::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(
        90deg,
        transparent,
        rgba(255, 255, 255, 0.2),
        transparent
    );
    transition: left 0.5s ease;
}

.portal-btn.portal-signup:hover::before {
    left: 100%;
}

.portal-btn.portal-signup:hover {
    transform: translateY(-3px) scale(1.02);
    box-shadow: 
        0 8px 25px rgba(212, 165, 116, 0.5),
        0 4px 10px rgba(0, 0, 0, 0.25);
}

.portal-btn.portal-signup:active {
    transform: translateY(0) scale(0.98);
    box-shadow: 
        0 2px 10px rgba(212, 165, 116, 0.4),
        inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

/* Light theme SIGN UP - Use blue accent */
html.theme-light .portal-btn.portal-signup {
    background: linear-gradient(135deg, #1F75FE 0%, #1557c7 100%);
    color: #FFFFFF;
    box-shadow: 
        0 4px 15px rgba(31, 117, 254, 0.35),
        0 2px 6px rgba(0, 0, 0, 0.15);
}

html.theme-light .portal-btn.portal-signup:hover {
    box-shadow: 
        0 8px 25px rgba(31, 117, 254, 0.45),
        0 4px 10px rgba(0, 0, 0, 0.15);
}

/* LOG IN button - Default to dark theme white */
.portal-btn.portal-login {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.6);
    color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 8px rgba(255, 255, 255, 0.1);
}

.portal-btn.portal-login:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: #FFFFFF;
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.15);
}

.portal-btn.portal-login:active {
    transform: translateY(0) scale(0.98);
    background: rgba(255, 255, 255, 0.12);
}

/* Light theme LOG IN */
html.theme-light .portal-btn.portal-login {
    border-color: #000000;
    color: #000000;
}

html.theme-light .portal-btn.portal-login:hover {
    background: rgba(0, 0, 0, 0.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

/* ABOUT button - Default to dark theme white */
.portal-btn.portal-about {
    background: transparent;
    border: 2px solid rgba(255, 255, 255, 0.6);
    color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 8px rgba(255, 255, 255, 0.1);
}

.portal-btn.portal-about:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: #FFFFFF;
    transform: translateY(-2px) scale(1.01);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.15);
}

.portal-btn.portal-about:active {
    transform: translateY(0) scale(0.98);
    background: rgba(255, 255, 255, 0.12);
}

/* Light theme ABOUT */
html.theme-light .portal-btn.portal-about {
    border-color: #000000;
    color: #000000;
}

html.theme-light .portal-btn.portal-about:hover {
    background: rgba(0, 0, 0, 0.05);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.12);
}

/* Close button */
.portal-close {
    position: absolute;
    top: 4%;
    left: 50%;
    width: 32px;
    height: 32px;
    border: none;
    background: transparent;
    cursor: pointer;
    z-index: 20;
    opacity: 0;
    transform: translateX(-50%) rotate(-90deg) scale(0.5);
    transition: all 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    -webkit-tap-highlight-color: transparent;
    pointer-events: none; /* Disabled until visible */
}

.firstlook-portal-overlay.active .portal-close {
    opacity: 1;
    transform: translateX(-50%) rotate(0) scale(1);
    transition-delay: 0.7s;
    pointer-events: auto; /* Enable once visible */
}

/* Default to dark theme white */
.portal-close::before,
.portal-close::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 18px;
    height: 2px;
    background: rgba(255, 255, 255, 0.5);
    border-radius: 2px;
    transition: all 0.3s ease;
}

.portal-close::before {
    transform: translate(-50%, -50%) rotate(45deg);
}

.portal-close::after {
    transform: translate(-50%, -50%) rotate(-45deg);
}

.portal-close:hover::before,
.portal-close:hover::after {
    background: #FFFFFF;
}

html.theme-light .portal-close::before,
html.theme-light .portal-close::after {
    background: rgba(0, 0, 0, 0.35);
}

html.theme-light .portal-close:hover::before,
html.theme-light .portal-close:hover::after {
    background: #000000;
}

/* Ambient glow effect - Default to dark theme gold */
.portal-glow {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 120%;
    height: 120%;
    transform: translate(-50%, -50%);
    background: radial-gradient(
        ellipse at center,
        rgba(212, 165, 116, 0.08) 0%,
        rgba(212, 165, 116, 0.04) 40%,
        transparent 70%
    );
    opacity: 0;
    animation: none;
    pointer-events: none;
}

.firstlook-portal-overlay.active .portal-glow {
    opacity: 1;
    animation: portalGlowPulse 3s ease-in-out infinite;
}

html.theme-light .portal-glow {
    background: radial-gradient(
        ellipse at center,
        rgba(31, 117, 254, 0.1) 0%,
        rgba(31, 117, 254, 0.03) 40%,
        transparent 70%
    );
}

html.theme-dark .portal-glow {
    background: radial-gradient(
        ellipse at center,
        rgba(212, 165, 116, 0.08) 0%,
        rgba(212, 165, 116, 0.04) 40%,
        transparent 70%
    );
}

@keyframes portalGlowPulse {
    0%, 100% {
        opacity: 0.6;
        transform: translate(-50%, -50%) scale(1);
    }
    50% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1.05);
    }
}

/* Mobile responsive adjustments */
@media (max-width: 768px) {
    .portal-content {
        gap: 10px;
        max-width: 200px;
    }
    
    .portal-btn {
        padding: 12px 24px;
        font-size: clamp(12px, 3vw, 14px);
        letter-spacing: 2px;
        border-radius: 50px; /* Pill shape */
        width: auto;
        min-width: 120px;
    }
    
    .portal-btn.portal-about {
        padding: 12px 24px;
        font-size: clamp(12px, 2.8vw, 14px);
        min-width: 120px;
    }
    
    .portal-actions {
        gap: 8px;
        align-items: center;
    }
    
    .portal-title {
        font-size: clamp(10px, 2.8vw, 12px);
        letter-spacing: 1.5px;
    }
    
    .portal-close {
        top: 3%;
        left: 50%;
        width: 28px;
        height: 28px;
    }
    
    .portal-close::before,
    .portal-close::after {
        width: 14px;
    }
}

/* Extra small screens */
@media (max-width: 480px) {
    .portal-content {
        gap: 8px;
        max-width: 180px;
    }
    
    .portal-btn {
        padding: 11px 22px;
        font-size: clamp(11px, 3.2vw, 13px);
        letter-spacing: 1.5px;
        border-radius: 50px; /* Pill shape */
        min-width: 110px;
    }
    
    .portal-btn.portal-about {
        padding: 8px 18px;
        font-size: clamp(9px, 2.8vw, 11px);
        min-width: 90px;
    }
    
    .portal-title {
        font-size: clamp(9px, 3vw, 11px);
        margin-bottom: 2px;
    }
    
    .portal-particle {
        width: 3px;
        height: 3px;
    }
}

/* PWA optimizations */
@media (display-mode: standalone) {
    .portal-content {
        gap: 14px;
        max-width: 220px;
    }
    
    .portal-btn {
        padding: 14px 28px;
        font-size: clamp(13px, 2.5vw, 15px);
        border-radius: 50px; /* Pill shape */
        min-width: 130px;
    }
    
    .portal-btn.portal-about {
        padding: 14px 28px;
        font-size: clamp(13px, 2.5vw, 15px);
        min-width: 130px;
    }
    
    .portal-actions {
        align-items: center;
    }
}
