/* --- CORE CONFIGURATION (ENFORCED DARK MODE) --- */
:root {
    /* Set to Dark Mode colors by default */
    --bg-color: #1d1d1d;
    --text-color: #ffffff;
    
    /* Metro Colors */
    --tile-red: #d24726;
    --tile-blue: #00AEEF;
    --tile-crimson: #b01c3c;
    --tile-darkblue: #173a73;
    --tile-grey: #404040;
    --tile-green: #107c10;
    --tile-default: #2b2b2b;
    
    /* Grid Math */
    --cell-size: 65px;
    --gap-size: 10px;
    
    /* DEFAULT GRID LIMIT: 6 
       Great for Desktop/Tablet. 2+2+2=6 or 4+2=6.
    */
    --grid-limit: 6; 

    /* Animation */
    --ease-metro: cubic-bezier(0.1, 0.9, 0.2, 1);
}

/* Removed prefers-color-scheme light logic to keep it Dark Only */

* {
    box-sizing: border-box;
    user-select: none;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', 'Segoe UI Light', 'Helvetica Neue', sans-serif;
    margin: 0;
    padding: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh; 
    overflow: hidden; 
    min-height: 500px;
}

a { text-decoration: none; color: inherit; }
h1, h2, h3, p { margin: 0; }

/* --- 1. START SCREEN CONTAINER --- */
#start-screen {
    width: 100%;
    height: 100%;
    padding: 40px 60px;
    display: flex;
    flex-direction: column;
    
    /* Default: Horizontal Scroll */
    overflow-x: auto;
    overflow-y: hidden; 
    
    transition: transform 0.5s var(--ease-metro), opacity 0.4s ease;
    transform-origin: 20% 50%;
    will-change: transform, opacity;
}

#start-screen::-webkit-scrollbar { height: 12px; width: 12px; }
#start-screen::-webkit-scrollbar-thumb { background: rgba(128,128,128,0.5); border-radius: 6px; }
#start-screen::-webkit-scrollbar-track { background: transparent; }

#start-screen.zoom-out {
    transform: scale(0.85);
    opacity: 0;
    pointer-events: none;
}

.header-section {
    height: auto; 
    margin-bottom: 20px;
    animation: fade-in-left 0.6s var(--ease-metro);
    display: flex;
    flex-direction: column; 
    align-items: flex-start;
    gap: 5px;
    flex-shrink: 0; 
}

.page-title { 
    font-size: 3rem; 
    font-weight: 300; 
    color: var(--text-color);
    line-height: 1;
}

/* --- 2. GRID SYSTEM (CSS GRID) --- */
.tile-grid {
    display: grid;
    gap: var(--gap-size);
    
    /* --- HORIZONTAL MODE (DEFAULT) --- */
    grid-template-rows: repeat(var(--grid-limit), var(--cell-size));
    grid-auto-flow: column dense;
    grid-auto-columns: var(--cell-size);
    
    align-content: center;
    height: 100%;
    padding-bottom: 20px;
    padding-right: 60px;
    
    animation: fade-in-up 0.8s var(--ease-metro);
}

/* TILE BASICS */
.tile {
    position: relative;
    cursor: pointer;
    overflow: hidden; 
    transition: transform 0.1s linear, outline 0.1s;
    color: white; 
    z-index: 1;
    /* Prevent tiles from collapsing/squishing */
    min-width: var(--cell-size);
    min-height: var(--cell-size);
}
.tile:hover { outline: 3px solid rgba(128,128,128,0.4); z-index: 10; }
.tile:active { transform: scale(0.97); }

/* TILE SIZES */
.small  { grid-column: span 1; grid-row: span 1; }
.medium { grid-column: span 2; grid-row: span 2; }
.wide   { grid-column: span 4; grid-row: span 2; }
.large  { grid-column: span 4; grid-row: span 4; }

/* COLORS */
.bg-red { background-color: var(--tile-red); }
.bg-blue { background-color: var(--tile-blue); }
.bg-crimson { background-color: var(--tile-crimson); }
.bg-darkblue { background-color: var(--tile-darkblue); }
.bg-grey { background-color: var(--tile-grey); }
.bg-green { background-color: var(--tile-green); }
.bg-default { background-color: var(--tile-default); }


/* --- 3. RESPONSIVE LOGIC (VERTICAL ADAPTATION) --- */

/* Apply vertical behavior for narrow windows OR portrait screens */
@media (orientation: portrait), (max-width: 800px) {
    body {
        overflow-y: auto; 
        overflow-x: hidden;
        min-height: unset; 
    }
    #start-screen {
        overflow-y: auto; 
        overflow-x: hidden;
        height: auto; 
        min-height: 100vh;
        padding: 40px 20px; 
        display: block;
    }
    .header-section {
        margin-bottom: 30px;
    }
    .tile-grid {
        /* Change to a 4-column grid for mobile to keep tiles properly shaped */
        grid-template-columns: repeat(4, 1fr);
        grid-template-rows: auto;
        grid-auto-flow: row dense;
        
        justify-content: center; 
        width: 100%;
        max-width: 400px; /* Limits width to keep it looking like a phone menu */
        margin: 0 auto;
        height: auto;
        padding-right: 0;
    }

    /* Adjust tile spanning for 4-column layout */
    .wide { grid-column: span 4; }
    .large { grid-column: span 4; }
}

/* PREVENT SQUISHING ON TINY SCREENS */
@media (max-width: 400px) {
    :root {
        --cell-size: 70px; /* Slightly larger cells for readability on small phones */
    }
    .tile-grid {
        /* Switch to 2 columns for very narrow devices to prevent squishing */
        grid-template-columns: repeat(2, 1fr);
    }
    .wide, .large { grid-column: span 2; }
}

/* --- 4. ANIMATION & APPS --- */
.tile-slider { width: 100%; height: 100%; position: relative; will-change: transform; transform: translate3d(0,0,0); }
.live .tile-slider { animation: tile-slide 10s infinite cubic-bezier(0.05, 0.9, 0.1, 1); }
.delay-1 .tile-slider { animation-delay: 0.5s; }
.delay-2 .tile-slider { animation-delay: 2.5s; }
.delay-3 .tile-slider { animation-delay: 5s; }
.delay-4 .tile-slider { animation-delay: 7.5s; }

@keyframes tile-slide {
    0%, 45% { transform: translate3d(0, 0, 0); }
    52%, 93% { transform: translate3d(0, -100%, 0); }
    100% { transform: translate3d(0, 0, 0); }
}

.tile-face { 
    position: absolute; top: 0; left: 0; width: 100%; height: 100%; 
    padding: 12px; display: flex; flex-direction: column; 
    justify-content: space-between; backface-visibility: hidden; 
}
.face-front { top: 0; background: inherit; z-index: 2; }
.face-back  { top: 100%; background: inherit; z-index: 1; }

.tile-center-icon { flex-grow: 1; display: flex; align-items: center; justify-content: center; font-size: 48px; }

/* TEXT PROTECTION: Added padding-bottom to ensure main text never hits the label */
.tile-text-main { 
    font-size: 14px; 
    font-weight: 500; 
    line-height: 1.2; 
    overflow: hidden; 
    display: -webkit-box; 
    -webkit-line-clamp: 2; 
    -webkit-box-orient: vertical; 
    word-break: break-word; 
    margin-bottom: 20px; 
}

/* LABEL PROTECTION: Added semi-opaque background to separate label from flipping content */
.tile-label { 
    font-size: 12px; 
    font-weight: 600; 
    background: rgba(0,0,0,0.3); 
    padding: 2px 4px;
    display: inline-block;
}

.app-container { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: var(--bg-color); color: var(--text-color); z-index: 100; display: flex; flex-direction: column; transform: translate3d(100%, 0, 0); transition: transform 0.5s var(--ease-metro); box-shadow: -20px 0 50px rgba(0,0,0,0.5); }
.app-container.active { transform: translate3d(0, 0, 0); }
.app-header { flex-shrink: 0; padding: 20px 40px; display: flex; align-items: center; gap: 20px; }
.app-header h2 { font-weight: 300; font-size: 2.5rem; }
.back-button { width: 48px; height: 48px; border: 2px solid currentColor; border-radius: 50%; background: transparent; color: inherit; font-size: 24px; cursor: pointer; display: flex; align-items: center; justify-content: center; padding-bottom: 4px; }
.back-button:hover { background: rgba(128,128,128,0.2); }
.app-content { flex-grow: 1; overflow-y: auto; padding: 20px 40px 80px 40px; max-width: 1200px; width: 100%; margin: 0 auto; }

.highlight-green { color: #107c10; font-weight: bold; }
.highlight-red { color: #d24726; font-weight: bold; }
.qa-block { margin-bottom: 20px; }
.qa-q { color: #d24726; font-weight: bold; }
.qa-a { color: #107c10; font-weight: bold; }

@keyframes fade-in-left { from { opacity: 0; transform: translate3d(50px, 0, 0); } to { opacity: 1; transform: translate3d(0, 0, 0); } }
@keyframes fade-in-up { from { opacity: 0; transform: translate3d(0, 50px, 0); } to { opacity: 1; transform: translate3d(0, 0, 0); } }

/* --- NEW CSS FOR LINK TILES --- */
.link-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 16px;
    margin-top: 20px;
}

.link-card {
    background-color: #121212; /* Darker than bg */
    border: 1px solid #333;
    border-radius: 12px;
    padding: 16px;
    display: flex;
    align-items: center;
    gap: 16px;
    transition: background-color 0.2s ease, transform 0.1s ease;
    position: relative;
}

.link-card:hover {
    background-color: #1f1f1f;
    text-decoration: none;
    border-color: #555;
}

.link-card:active {
    transform: scale(0.98);
}

.link-icon {
    font-size: 28px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.link-info {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.link-name {
    font-size: 14px;
    color: #aaa;
    font-weight: 600;
    margin-bottom: 4px;
}

.link-url {
    font-size: 16px;
    color: #fff;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-weight: 500;
}

/* --- NEW CSS FOR MOBILE POPUP --- */
.mobile-popup-overlay {
    display: none; /* Hidden by default */
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 20px;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.mobile-popup-overlay.show {
    display: flex;
    opacity: 1;
}

.mobile-popup-content {
    background: var(--bg-color);
    border: 2px solid var(--tile-red); /* Using red to grab attention */
    padding: 30px;
    max-width: 500px;
    width: 100%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0,0,0,0.5);
    animation: fade-in-up 0.4s var(--ease-metro);
}

.popup-title {
    color: var(--tile-red);
    font-size: 1.5rem;
    margin-bottom: 15px;
    font-weight: bold;
}

.popup-text {
    font-size: 1rem;
    line-height: 1.5;
    margin-bottom: 25px;
    color: #ddd;
}

.popup-btn {
    background: var(--tile-blue);
    color: white;
    border: none;
    padding: 10px 20px;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s, opacity 0.2s;
    font-family: inherit;
}

.popup-btn:active {
    transform: scale(0.95);
}

.popup-btn:hover {
    opacity: 0.9;
}