/* ==========================================================================
   1. SYSTEM TOKENS
   ========================================================================== */

:root {
    /* Palette */
    --bg-root: #111111;
    
    /* UPDATED COLORS */
    --text-primary: #E8E8E8;
    --text-secondary: #767676;
    --text-dim: #4a4a4a;
    
    /* ACCENTS */
    --accent-lime: #9caf8d; 
    
    --border-light: rgba(255, 255, 255, 0.06);
    --border-hover: rgba(255, 255, 255, 0.18);
    
    /* Typography */
    --font-stack: 'Geist Mono', monospace;
    
    /* Motion */
    --ease-expo: cubic-bezier(0.19, 1, 0.22, 1);
}

/* ==========================================================================
   2. GLOBAL RESET
   ========================================================================== */

* { box-sizing: border-box; margin: 0; padding: 0; cursor: none; -webkit-tap-highlight-color: transparent; }

::selection { background: rgba(255, 255, 255, 0.2); color: var(--text-primary); }

:focus-visible { outline: 1px solid var(--text-primary); outline-offset: 4px; }

html { scroll-behavior: smooth; }

body {
    background-color: var(--bg-root);
    color: var(--text-primary);
    font-family: var(--font-stack);
    font-size: 13px;
    line-height: 1.5;
    height: 100vh;
    height: 100dvh; 
    width: 100vw;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* ==========================================================================
   3. AESTHETIC LAYERS & OPTIMIZATIONS
   ========================================================================== */

#bg-layer {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; z-index: -2;
    background-color: #111111;
    background-image: url('../bg.jpg'); 
    background-size: cover; background-position: center; opacity: 0.2;
}

/* PERFORMANCE: Optimized Noise Overlay */
.noise-overlay {
    position: fixed; top: 0; left: 0; width: 100%; height: 100%; pointer-events: none; z-index: 9000;
    opacity: 0.07;
    mix-blend-mode: overlay;
}

/* Mobile: Disable expensive SVG filters */
@media (max-width: 820px) {
    .noise-overlay { background-image: none; background-color: transparent; }
}

/* Desktop: Use high-quality noise */
@media (min-width: 821px) {
    .noise-overlay {
        background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noiseFilter'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='2.5' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noiseFilter)'/%3E%3C/svg%3E");
    }
}

#cursor {
    position: fixed; top: 0; left: 0; width: 11px; height: 11px;
    background-color: var(--text-primary); 
    border-radius: 50%; pointer-events: none; z-index: 13000;
    transform: translate(-50%, -50%);
    transition: width 0.2s, height 0.2s, background-color 0.2s;
    mix-blend-mode: difference;
    will-change: transform, width, height; 
}

body:hover #cursor.hovered {
    width: 14px; height: 14px;
    background-color: var(--accent-lime);
    mix-blend-mode: normal;
    opacity: 0.9;
}

/* ==========================================================================
   4. LAYOUT GRID
   ========================================================================== */

#viewport {
    width: 70vw;
    max-width: 1100px;
    height: 94vh;
    display: grid;
    grid-template-rows: 40px 1fr;
    position: relative;
    z-index: 10;
    gap: 12px;
    margin: 0 calc(15vw);
}

.sys-bar {
    display: flex; justify-content: space-between; align-items: center;
    border: 1px solid var(--border-light);
    background: rgba(15, 15, 15, 0.6); 
    backdrop-filter: blur(16px); 
    -webkit-backdrop-filter: blur(16px);
    padding: 0 20px;
    font-family: var(--font-stack); font-size: 11px;
    text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-secondary);
}

main {
    position: relative; overflow-y: auto;
    height: 100%;
    border: 1px solid var(--border-light); padding: 40px;
    scrollbar-width: none;
    background: linear-gradient(180deg, rgba(20,20,20,0.3) 0%, rgba(5,5,5,0) 100%);
    -webkit-overflow-scrolling: touch;
    content-visibility: auto; /* Performance: Lazy render off-screen content */
    contain-intrinsic-size: 1200px; 
}
main::-webkit-scrollbar { display: none; }

@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }

    .noise-overlay {
        opacity: 0.02;
        mix-blend-mode: normal;
    }
}

/* ==========================================================================
   5. COMPONENT UI
   ========================================================================== */

h1 {
    font-family: var(--font-stack); font-size: 14px; color: var(--text-dim);
    text-transform: uppercase; letter-spacing: 0.1em; margin-bottom: 2rem;
    display: flex; align-items: center; gap: 12px; font-weight: 600;
}
h1::after { content: ''; flex: 1; height: 1px; background: var(--border-light); }

.grid-row {
    display: grid; align-items: baseline; 
    padding: 18px 12px;
    border-bottom: 1px solid var(--border-light);
    text-decoration: none; color: var(--text-secondary);
    transition: all 0.2s var(--ease-expo); position: relative;
}

.grid-row.default { grid-template-columns: 40px 1fr 1fr 80px; }
.grid-row.project { grid-template-columns: 40px 160px 180px 1fr 20px; gap: 10px; }

.grid-row:hover {
    color: var(--text-primary); background: rgba(255,255,255,0.03);
    border-bottom: 1px solid rgba(255,255,255,0.08); padding-left: 20px;
}

.row-idx { font-family: var(--font-stack); font-size: 10px; color: var(--text-dim); }
.row-title { 
    font-family: var(--font-stack); font-size: 15px; 
    text-transform: uppercase; color: var(--text-primary); 
    font-weight: 500; letter-spacing: 0.02em; 
}
.row-meta { font-size: 12px; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.05em; }
.row-desc { font-size: 14px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; opacity: 0.8; }
.row-end { text-align: right; font-family: var(--font-stack); font-size: 10px; }


/* Projects - new layout */
.project-row {
    display: grid;
    grid-template-columns: 40px 220px 1fr;
    gap: 24px;
    padding: 24px 12px;
    border-bottom: 1px solid var(--border-light);
    align-items: start;
}

.project-idx {
    font-family: var(--font-stack);
    font-size: 10px;
    color: var(--text-dim);
    text-transform: uppercase;
}

.project-media {
    display: flex;
    align-items: flex-start;
}

.project-img {
    width: 100%;
    max-width: 200px;
    height: auto;
    border: none;
    background: transparent;
    box-shadow: none;
    object-fit: contain;
}

.project-img-fallback {
    width: 200px;
    height: 140px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    border: 1px solid var(--border-light);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-size: 10px;
}

.project-body {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.project-title-row {
    display: flex;
    align-items: baseline;
    justify-content: flex-start;
    gap: 16px;
    flex-wrap: wrap;
}

.project-title {
    font-family: var(--font-stack);
    font-size: 16px;
    text-transform: uppercase;
    color: var(--text-primary);
    letter-spacing: 0.04em;
}

.project-links {
    display: flex;
    gap: 10px;
    font-size: 13px;
    color: var(--text-secondary);
    align-items: baseline;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.project-link {
    color: var(--text-secondary);
    text-decoration: none;
}

.project-link:hover {
    color: var(--text-primary);
}

.project-desc {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    max-width: none;
}

.project-stack {
    color: var(--text-dim);
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.arrow-icon { 
    opacity: 0; transform: translateX(-5px); transition: all 0.3s ease; 
    display: flex; justify-content: flex-end; color: var(--text-secondary); 
}
.grid-row:hover .arrow-icon { opacity: 1; transform: translateX(0); color: var(--accent-lime); }

.intro-text {
    font-family: var(--font-stack); font-size: 22px; line-height: 1.6;
    color: var(--text-primary); margin-bottom: 4rem; width: 100%; 
    max-width: none;
}
.intro-text a { color: var(--text-primary); text-decoration: underline; text-decoration-color: var(--border-light); cursor: none; }
.intro-text a:hover { color: var(--accent-lime); text-decoration-color: var(--accent-lime); }

.identity-grid {
    display: grid; grid-template-columns: 200px 1fr; gap: 30px;
    margin-bottom: 4rem; align-items: stretch; 
}

.mefetch-img-box {
    width: 200px; height: auto; min-height: 200px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border-light);
    display: flex; justify-content: center; align-items: center;
    color: var(--text-dim); font-size: 10px; text-transform: uppercase; letter-spacing: 0.1em;
    overflow: hidden;
}
.mefetch-img-box img { width: 100%; height: 100%; object-fit: cover; display: block; }

.stats-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-light);
    padding: 24px; border-radius: 2px;
}
.stat-item { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 10px; color: var(--text-dim); letter-spacing: 0.1em; text-transform: uppercase; }
.stat-value { color: var(--text-primary); font-size: 13px; text-transform: lowercase; }

.about-grid { 
    display: flex; 
    flex-direction: column; 
    gap: 0; 
    margin-bottom: 20px; 
    border: 1px solid var(--border-light);
}

.about-row { 
    display: grid; 
    grid-template-columns: 200px 1fr; 
    align-items: center; 
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-light);
}

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

.about-key { 
    color: var(--text-dim); 
    font-size: 10px; 
    text-transform: uppercase; 
    letter-spacing: 0.1em; 
}

.about-val { 
    color: var(--text-primary); 
    font-size: 13px;
    line-height: 1.5;
}
.about-bio { margin-top: 30px; line-height: 1.8; color: var(--text-secondary); max-width: 700px; font-size: 14px; }
.about-bio { max-width: 900px; width: min(100%, 900px); }

#project-preview {
    position: fixed; pointer-events: none; z-index: 50; width: auto; max-width: 450px;
    background: #161616; border: 1px solid var(--border-light);
    opacity: 0; transform: scale(0.95); transition: opacity 0.3s ease, transform 0.3s ease;
    display: flex; flex-direction: column; overflow: hidden;
    box-shadow: 0 20px 50px rgba(0,0,0,0.8);
}
#project-preview img { 
    width: 100%; max-height: 350px; object-fit: contain; background: #111111;
    border-bottom: 1px solid var(--border-light); display: block; 
}
#project-preview.active { opacity: 1; transform: scale(1); }
.preview-info { padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.preview-title { font-family: var(--font-stack); font-size: 14px; color: var(--accent-lime); text-transform: uppercase; font-weight: 600; }
.preview-desc { font-size: 12px; color: var(--text-secondary); line-height: 1.5; }

.mobile-preview-img { display: none; }

/* Centered image preview modal */
#image-preview-modal {
    position: fixed; inset: 0; z-index: 12000;
    display: none;
    align-items: center; justify-content: center;
    padding: 6vh 6vw;
}

#image-preview-modal.active {
    display: flex;
}

.image-preview-backdrop {
    position: absolute; inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    pointer-events: auto;
}

.image-preview-content {
    position: relative; z-index: 1;
    width: 100%; height: 100%;
    display: flex; align-items: center; justify-content: center;
    pointer-events: none;
}

#image-preview-img {
    width: auto;
    height: auto;
    max-width: 70%;
    max-height: 70%;
    object-fit: contain;
    border: 1px solid var(--text-secondary);
    background: transparent;
    pointer-events: auto;
}

/* ==========================================================================
   6. ANIMATIONS & LOADER
   ========================================================================== */

.fade-up {
    animation: fadeUp 0.8s var(--ease-expo) forwards;
    opacity: 0; transform: translateY(20px); filter: blur(12px);
    will-change: transform, opacity, filter;
}
@keyframes fadeUp { to { opacity: 1; transform: translateY(0); filter: blur(0); } }

@media (min-width: 821px) {
    #bg-layer { opacity: 0.16; }
    .noise-overlay { opacity: 0.05; }

    #viewport { gap: 10px; }

    .sys-bar {
        border-color: rgba(255, 255, 255, 0.045);
        background: rgba(17, 17, 17, 0.58);
    }

    main {
        border-color: rgba(255, 255, 255, 0.045);
        background: linear-gradient(180deg, rgba(18, 18, 18, 0.26) 0%, rgba(17, 17, 17, 0) 100%);
    }

    .grid-row {
        padding: 16px 12px;
        border-bottom-color: rgba(255, 255, 255, 0.045);
        transition: background-color 160ms ease, border-color 160ms ease, color 160ms ease, padding-left 160ms ease;
    }

    .grid-row:hover {
        background: rgba(255, 255, 255, 0.018);
        border-bottom-color: rgba(255, 255, 255, 0.08);
        padding-left: 16px;
    }

    .project-row {
        padding: 20px 12px;
        border-bottom-color: rgba(255, 255, 255, 0.045);
        transition: background-color 160ms ease, border-color 160ms ease;
    }

    .project-row:hover {
        background: rgba(255, 255, 255, 0.018);
        border-bottom-color: rgba(255, 255, 255, 0.08);
    }

    .about-grid { border-color: rgba(255, 255, 255, 0.045); }

    .about-row {
        padding: 16px 18px;
        border-bottom-color: rgba(255, 255, 255, 0.045);
        transition: background-color 160ms ease, border-color 160ms ease;
    }

    .about-row:hover {
        background: rgba(255, 255, 255, 0.018);
        border-bottom-color: rgba(255, 255, 255, 0.08);
    }

    .stats-grid {
        border-color: rgba(255, 255, 255, 0.045);
        background: rgba(255, 255, 255, 0.014);
    }

    .row-meta,
    .project-stack,
    .about-key { color: #666666; }

    .grid-row:hover .arrow-icon,
    .intro-text a:hover,
    .preview-title { color: var(--text-secondary); }

    .intro-text a:hover { text-decoration-color: var(--text-secondary); }
}

/* REVERTED LOADER STYLES */
#loader {
    position: fixed; inset: 0; background: var(--bg-root); z-index: 10000;
    display: flex; justify-content: center; align-items: center; flex-direction: column; gap: 20px;
    /* Clean opacity transition, no blur */
    transition: opacity 0.5s ease;
}

.loader-bar { width: 200px; height: 1px; background: var(--border-light); position: relative; overflow: hidden; }
.loader-fill { position: absolute; left: 0; top: 0; height: 100%; width: 0%; background: var(--text-primary); transition: width 0.5s ease; }
#loader-text { font-family: var(--font-stack); font-size: 10px; letter-spacing: 0.2em; color: var(--text-dim); text-transform: uppercase; }


/* ==========================================================================
   7. MOBILE & TABLET ADAPTATION
   ========================================================================== */

@media (max-width: 820px) {
    /* 1. Global Mobile Resets */
    body { align-items: flex-start; }
    #viewport {
        width: 100vw;
        max-width: none;
        margin: 0;
        padding: 0;
        grid-template-rows: 48px 1fr;
        height: 100dvh;
        gap: 0;
        overflow: hidden;
    }
    #bg-layer, #cursor, .arrow-icon, .hide-mobile, #project-preview, .hide-mobile-key { display: none !important; }
    .hide-touch { display: none !important; }

    /* 2. Top Bar */
    .sys-bar {
        position: relative; z-index: 50;
        min-height: 48px;
        padding: 0 14px;
        background: rgba(17, 17, 17, 0.42);
        backdrop-filter: blur(24px) saturate(120%);
        -webkit-backdrop-filter: blur(24px) saturate(120%);
        border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    }

    /* 3. Main Content Area */
    main {
        margin-top: -48px;
        padding: 66px 16px 76px 16px;
        border: none;
        -webkit-overflow-scrolling: touch;
    }
    * { cursor: auto; }

    /* --- 4. HOMEPAGE GRID LOGIC --- */
    /* Target only the table containing standard menu items */
    .grid-table:has(.default) {
        display: block;
        width: 100%;
    }

    .grid-row.default {
        background: transparent;
        border: none;
        border-bottom: 1px solid var(--border-light);
        border-radius: 0;
        padding: 16px 6px;
        margin-bottom: 0;
        display: grid;
        grid-template-columns: 32px 1fr auto;
        align-items: center;
        text-align: left;
        min-height: 58px;
        transition: background-color 100ms ease, border-color 100ms ease, opacity 100ms ease;
    }

    /* Touch Feedback (Active State) */
    .grid-row.default:active {
        background: rgba(255, 255, 255, 0.05);
        border-bottom-color: rgba(255, 255, 255, 0.16);
        opacity: 0.98;
    }

    /* Tile Typography */
    .row-title { 
        font-size: 14px; 
        color: var(--text-primary); 
        font-weight: 600; 
        text-transform: uppercase;
        letter-spacing: 0.05em;
    }
    .row-meta { 
        color: var(--text-dim); 
        font-size: 10px; 
        margin-top: 0; 
        text-align: right;
        justify-self: end;
    }
    
    /* Hide non-tile elements on Home Grid */
    .grid-row.default .row-desc,
    .grid-row.default .arrow-icon { display: none; }

    /* Hide keybinds on mobile */
    .grid-row.default .row-end { display: none; }

    /* --- 5. PROJECTS PAGE (Maintain Vertical List) --- */
    .grid-table:has(.project) {
        display: block;
    }
    .project-row {
        grid-template-columns: 1fr;
        gap: 14px;
        padding: 16px 12px;
        border: 1px solid var(--border-light);
        border-radius: 14px;
        background: rgba(255, 255, 255, 0.03);
        margin-bottom: 10px;
        min-height: 58px;
        transition: background-color 100ms ease, border-color 100ms ease, opacity 100ms ease;
    }

    .project-row:active {
        background: rgba(255, 255, 255, 0.05);
        border-color: rgba(255, 255, 255, 0.16);
        opacity: 0.98;
    }

    .project-idx {
        display: block;
        font-size: 10px;
        color: var(--text-dim);
    }

    .project-media {
        justify-content: flex-start;
    }

    .project-img {
        max-width: 100%;
        width: 100%;
        height: auto;
        border-radius: 12px;
        pointer-events: none;
    }

    .project-img-fallback {
        width: 220px;
        height: 140px;
    }

    .project-title { font-size: 16px; }
    .project-desc { font-size: 13px; max-width: none; line-height: 1.5; }
    .project-stack { font-size: 10px; }

    /* --- 6. OTHER SECTIONS --- */
    .identity-grid { grid-template-columns: 1fr; gap: 20px; margin-bottom: 2rem; }
    .mefetch-img-box { display: none !important; }
    .intro-text { font-size: 20px; line-height: 1.45; margin-bottom: 2rem; margin-top: 0; }
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; padding: 16px; border-radius: 14px; }

    /* TECHNICAL SKILLS MOBILE */
    .about-grid { border: 1px solid var(--border-light); border-radius: 14px; gap: 0; overflow: hidden; }
    .about-row {
        grid-template-columns: 140px 1fr;
        gap: 0;
        padding: 16px 14px;
        border: none;
        border-bottom: 1px solid var(--border-light);
        border-radius: 0;
        background: transparent;
        align-items: center;
        min-height: 58px;
        transition: background-color 100ms ease, border-color 100ms ease, opacity 100ms ease;
    }
    .about-row:active {
        background: rgba(255, 255, 255, 0.05);
        border-bottom-color: rgba(255, 255, 255, 0.16);
        opacity: 0.98;
    }
    .about-key { margin-bottom: 0; color: var(--text-dim); }
    .about-val { font-size: 13px; }

}
