/* ==========================================================================
   Fonts
   ========================================================================== */
@font-face {
    font-family: 'Redaction70';
    src: url('../assets/fonts/Redaction_70-Bold.woff2') format('woff2');
    font-weight: bold;
    font-style: normal;
}

/* ==========================================================================
   CSS Custom Properties & Base Setup
   ========================================================================== */
:root {
    /* Light Mode Colors */
    --bg-color: #FBFFF5;
    --text-color: #2c2c2c;
    --border-color: #c4c4c4;
    --accent-color: #c0392b;
    /* About link color */

    /* Typography */
    --font-main: 'Kay Pho Du', serif;
    --font-serif: 'Kay Pho Du', serif;
    --font-title: 'Redaction70', serif;
    --font-sans: 'Lato', sans-serif;

    /* Images for dynamic backgrounds */
    --img-work: url('../assets/images/home/work light.png');
    --img-talk: url('../assets/images/home/talk light.png');
    --img-play: url('../assets/images/home/play light.png');

    /* Dark Mode specific */
    --noise-opacity: 0;
    --line-opacity: 0.3;
}

/* Dark Mode Overrides */
.dark-mode {
    --bg-color: #0d0d0d;
    --text-color: #f0f0f0;
    --border-color: #444;
    --noise-opacity: 0.15;
    --noise-blend-mode: screen;
    --noise-filter: invert(1) grayscale(1) contrast(300%);
    /* Dual noise filter opacity */
    --line-opacity: 0.15;

    /* Dark mode background images */
    --img-work: url('../assets/images/home/work dark.png');
    --img-talk: url('../assets/images/home/talk dark.png');
    --img-play: url('../assets/images/home/play dark.png');
}

/* Reset & Global */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    overflow-x: hidden;
}

body {
    height: 100%;
    font-family: var(--font-main);
    font-weight: 400;
    color: var(--text-color);
    background-color: var(--bg-color);
    transition: background-color 0.4s ease, color 0.4s ease;
    overflow-x: hidden;
}

/* ==========================================================================
   Background Effects
   ========================================================================== */

/* Dual Noise Filter */
.noise-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    pointer-events: none;
    z-index: 9999;
    /* Basic Canvas Pixel Grid Mask Logic */
    background: url('data:image/svg+xml;utf8,%3Csvg viewBox="0 0 200 200" xmlns="http://www.w3.org/2000/svg"%3E%3Cfilter id="noiseFilter"%3E%3CfeTurbulence type="fractalNoise" baseFrequency="0.85" numOctaves="3" stitchTiles="stitch"/%3E%3C/filter%3E%3Crect width="100%25" height="100%25" filter="url(%23noiseFilter)"/%3E%3C/svg%3E');
    opacity: var(--noise-opacity);
    transition: opacity 0.4s ease;
    mix-blend-mode: var(--noise-blend-mode, overlay);
    filter: var(--noise-filter, none);
}

/* Vertical Background Lines */
.bg-lines {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;
    /* 5 columns layout */
    background-image: repeating-linear-gradient(to right, transparent, transparent calc(20vw - 1px), var(--border-color) calc(20vw - 1px), var(--border-color) 20vw);
    opacity: var(--line-opacity);
    pointer-events: none;
    transition: opacity 0.4s ease;
}

/* ==========================================================================
   Layout grid container
   ========================================================================== */
.grid-container {
    display: flex;
    min-height: 100vh;
    position: relative;
    padding: 2rem;
}

/* ==========================================================================
   Left Sidebar: Timeline
   ========================================================================== */
.sidebar-left {
    width: 20%;
    display: flex;
    flex-direction: column;
    margin-top: -2rem;
    margin-bottom: -2rem;
    margin-left: clamp(0.5rem, 4vw, 3rem);
}

.timeline-group {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
    height: 100%;
    font-family: var(--font-main);
    font-size: 1.0rem;
    line-height: 1.3;
}

.timeline-item {
    color: var(--text-color);
    text-decoration: none;
    opacity: 0.4;
    transition: opacity 0.2s, transform 0.2s;
    cursor: pointer;
    text-transform: uppercase;
}

.timeline-item.static-new {
    opacity: 0.4;
    cursor: default;
}

.timeline-item.static-new:hover {
    opacity: 0.4;
    font-weight: normal;
    transform: none;
}

.timeline-item:not(.static-new):hover {
    opacity: 1;
    font-weight: bold;
    transform: translateX(2px);
}

.timeline-date-link {
    font-weight: bold;
    margin: 0;
    letter-spacing: 0.5px;
    color: var(--text-color);
    text-decoration: none;
    transition: color 0.2s, transform 0.2s;
    cursor: pointer;
    display: block;
    white-space: nowrap;
    /* use block to match natural stacking behavior */
}

.timeline-date-link:hover {
    color: var(--accent-color);
    transform: translateX(2px);
}

/* ==========================================================================
   Center Content Area & Top Header
   ========================================================================== */
.center-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
}

.top-header {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    position: absolute;
    top: 3rem;
    left: 50%;
    transform: translateX(-50%);
    z-index: 20;
}

.header-box {
    display: flex;
    align-items: flex-end;
    gap: .9rem;
}

/* Theme Toggle Button */
.theme-toggle {
    font-size: 1rem;
    background: #ffffff;
    border: none;
    border-radius: 0;
    padding: 0.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: 3.75em;
    height: 1.875em;
    transition: background 0.4s ease;
}

.dark-mode .theme-toggle {
    background: #13614F;
}

.toggle-icon {
    width: 1.375em;
    height: 1.375em;
    background-color: transparent;
    border: 0.125em solid var(--text-color);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94), border-color 0.4s ease;
    transform: translateX(0);
}

.dark-mode .toggle-icon {
    transform: translateX(1.9375em);
}

.toggle-circle {
    display: block;
    width: 0.5em;
    height: 0.5em;
    background-color: var(--text-color);
    border-radius: 50%;
    border: none;
    transition: background-color 0.4s ease;
}

/* Title Box */
.title-box {
    padding: 0.5rem 0.8rem;
    text-align: left;
    border: none;
    background: #ffffff;
    display: flex;
    flex-direction: column;
    justify-content: center;
    transition: background 0.4s ease;
    gap: 0.15rem;
}

.dark-mode .title-box {
    background: #EC951D;
}

.title-name {
    font-size: 1.15rem;
    font-weight: bold;
    letter-spacing: 0;
    font-family: var(--font-title);
    margin: 0;
    color: var(--text-color);
    transition: color 0.4s ease;
    white-space: nowrap;
    line-height: 1.15;
}

.title-desc {
    font-size: 1.15rem;
    letter-spacing: 0;
    opacity: 1;
    font-family: var(--font-serif);
    line-height: 1.15;
    color: var(--text-color);
    margin: 0;
    transition: color 0.4s ease;
    white-space: nowrap;
}

/* Header Links (Right of namebox) */
.header-links {
    display: flex;
    flex-direction: column;
    margin-left: 1rem;
    gap: 0.15rem;
    background: transparent;
    padding: 0.5rem 0;
    justify-content: center;
}

.header-links a {
    text-decoration: none;
    color: var(--text-color);
    font-size: 1.15rem;
    text-transform: lowercase;
    font-family: var(--font-serif);
    letter-spacing: 0;
    opacity: 1;
    transition: opacity 0.2s, transform 0.2s, color 0.4s ease;
    line-height: 1.15;
    margin: 0;
    white-space: nowrap;
}

.header-links a:hover {
    opacity: 0.7;
    transform: translateX(2px);
}

/* ==========================================================================
   Staggered Center Items
   ========================================================================== */
.staggered-container {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    z-index: 5;
}

.staggered-item {
    position: relative;
    text-decoration: none;
    color: var(--text-color);
    transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    display: block;
}

.staggered-item:hover {
    z-index: 10 !important;
}

/* Placeholders for images */
.bg-placeholder {
    width: 420px;
    height: 420px;
    opacity: 1;
    transition: opacity 0.4s ease;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
}

.staggered-item:hover .bg-placeholder {
    opacity: 1;
}

.bg-work {
    background-image: var(--img-work);
}

.bg-talk {
    background-image: var(--img-talk);
}

.bg-play {
    background-image: var(--img-play);
}

/* Custom positioning to match snapshot staggering */
.item-work {
    z-index: 2;
    margin-top: -80px;
    margin-right: -60px;
}

.item-talk {
    z-index: 3;
    margin-top: 60px;
}

.item-play {
    z-index: 1;
    margin-top: -30px;
    margin-left: -60px;
}

/* Typography inside staggered items */
.staggered-title {
    position: absolute;
    font-family: var(--font-title);
    font-size: 4.5rem;
    font-weight: bold;
    letter-spacing: 2px;
    text-shadow: 2px 2px 0px rgba(0, 0, 0, 0.05);
    color: #000000;
    /* Black in light mode */
    transition: color 0.4s ease;
}

.dark-mode .staggered-title {
    color: #ffffff;
    /* White in dark mode */
}

/* Custom internal positioning based on image */
.item-work .staggered-title {
    top: 10%;
    left: 10%;
}

.item-talk .staggered-title {
    bottom: 5%;
    left: 44%;
}

.item-play .staggered-title {
    top: 40%;
    left: 35%;
}

/* ==========================================================================
   Corner Elements
   ========================================================================== */
.top-right {
    position: absolute;
    top: 3rem;
    right: 3rem;
    z-index: 20;
}

.search-box {
    background: #ebe6df;
    padding: 0.4rem 1rem;
    width: 220px;
    display: flex;
    align-items: center;
    transition: all 0.1s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    box-sizing: border-box;
    overflow: hidden;
    opacity: 1;
}

.search-box input {
    background: transparent;
    border: none;
    font-family: var(--font-serif);
    font-size: 1.4rem;
    color: #555;
    outline: none;
    width: 100%;
    padding: 0;
    transition: opacity 0.1s ease;
}

.search-icon {
    min-width: 20px;
    stroke: #555;
    display: none;
}

.dark-mode .search-box {
    background: #332842;
}

.dark-mode .search-box input {
    color: #ddd;
}

.dark-mode .search-icon {
    stroke: #ddd;
}

.bottom-right {
    position: absolute;
    bottom: 4rem;
    right: 3rem;
    z-index: 20;
}

.bottom-box {
    background: transparent;
    padding: 0.4rem 1.5rem;
    width: 220px;
    transition: background 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-family: var(--font-serif);
    font-size: 1.6rem; /* matches about link */
    color: #555;
    box-sizing: border-box;
}

.dark-mode .bottom-box {
    background: transparent;
    color: #ddd;
}

.about-link {
    font-family: var(--font-serif);
    font-size: 1.6rem;
    color: var(--accent-color);
    text-decoration: none;
    transition: color 0.3s, transform 0.3s;
    display: inline-block;
}

.about-link:hover {
    color: #e74c3c;
    transform: translateY(-2px);
}

/* ==========================================================================
   Responsive Design (3 screens)
   ========================================================================== */

/* Tablet (768px - 1024px) */
@media (max-width: 1024px) {
    .bg-placeholder {
        width: 320px;
        height: 320px;
    }

    .staggered-title {
        font-size: 3.5rem;
    }

    .item-work {
        margin-top: -60px;
        margin-right: -30px;
    }

    .item-talk {
        margin-top: 40px;
    }

    .item-play {
        margin-top: -20px;
        margin-left: -30px;
    }

    .sidebar-left {
        width: 15%;
    }

    .top-right {
        top: 2rem;
        right: 2rem;
    }

    .bottom-right {
        bottom: 2rem;
        right: 2rem;
    }

    /* Expanding Search Box for Mobile/Tablet */
    .search-box {
        width: 44px;
        height: 44px;
        padding: 0;
        justify-content: center;
        cursor: pointer;
        margin: 0;
        border-radius: 0;
    }

    .search-icon {
        display: block;
    }

    .search-box input {
        width: 0;
        opacity: 0;
        pointer-events: none;
    }

    .search-box.expanded {
        width: 220px;
        padding: 0 1rem;
        justify-content: flex-start;
        cursor: text;
    }

    .search-box.expanded .search-icon {
        margin-right: 0.5rem;
    }

    .search-box.expanded input {
        width: 100%;
        opacity: 1;
        pointer-events: auto;
    }
}

/* Mobile (< 768px) */
@media (max-width: 768px) {
    .grid-container {
        flex-direction: column;
        padding: 1.5rem;
        overflow-y: auto;
    }

    .bg-lines {
        display: none;
        /* Cleaner look without lines on mobile */
    }

    .sidebar-left {
        width: 100%;
        margin: 0;
        margin-bottom: 2rem;
    }

    .timeline-group {
        flex-direction: column;
        row-gap: 0.1rem;
        align-items: flex-start;
        height: auto;
        justify-content: flex-start;
    }

    .timeline-row {
        display: flex;
        flex-direction: row;
        width: 100%;
        column-gap: 0.6rem;
        justify-content: flex-start;
        align-items: baseline;
        overflow: hidden;
        line-height: 1.1;
    }

    .timeline-date {
        margin-top: 0;
        width: 100%;
    }

    .timeline-item {
        display: inline-block;
    }

    .center-content {
        padding-top: 0;
    }

    .top-header {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        display: grid;
        grid-template-columns: auto max-content;
        justify-content: center;
        column-gap: 0.9rem;
        row-gap: 0.5rem;
        margin-bottom: 4rem;
        margin-top: 1rem;
    }

    .header-box {
        display: contents;
    }

    .theme-toggle {
        grid-column: 1;
        grid-row: 1;
        align-self: end;
    }

    .title-box {
        grid-column: 2;
        grid-row: 1;
    }

    .theme-toggle {
        font-size: clamp(0.74rem, 3.5vw, 1rem);
    }

    .title-name, .title-desc,
    .header-links a,
    .search-box input,
    .timeline-item, .timeline-date-link {
        font-size: clamp(0.85rem, 4vw, 1.15rem);
    }

    .header-links {
        grid-column: 2;
        grid-row: 2;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        width: calc(100% - 3rem);
        margin-left: 0;
        gap: 0;
        align-items: center;
        position: relative;
        padding: 0;
        min-height: 44px;
    }

    .search-box.expanded {
        position: absolute;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        width: 100%;
        z-index: 10;
    }



    .header-links:has(.search-box.expanded) a {
        opacity: 0;
        pointer-events: none;
    }

    /* Harmonic Vertical Stack */
    .staggered-container {
        position: relative;
        top: auto;
        left: auto;
        transform: none;
        display: flex;
        flex-direction: column;
        gap: 0;
        align-items: center;
        min-height: auto;
        padding-bottom: 5rem;
        width: 100%;
    }

    .staggered-item {
        position: relative;
        top: auto;
        left: auto;
        transform: none !important;
        /* disable hover scaling on mobile to prevent layout shifts */
    }

    .item-work {
        margin-top: 0;
        margin-right: 30px;
        margin-left: 0;
    }

    .item-talk {
        margin-top: -50px;
        margin-left: 30px;
        margin-right: 0;
    }

    .item-play {
        margin-top: -50px;
        margin-right: 30px;
        margin-left: 0;
    }

    .bg-placeholder {
        width: calc(100vw - 10rem);
        max-width: 340px;
        height: calc(100vw - 10rem);
        max-height: 340px;
    }

    .staggered-title {
        font-size: clamp(2rem, 12vw, 4.5rem);
    }

    .top-right {
        position: static;
        margin-bottom: 2rem;
        text-align: center;
        display: flex;
        justify-content: center;
    }



    .bottom-right {
        position: static;
        display: flex;
        justify-content: center;
        margin-top: 2rem;
        margin-bottom: 1rem;
    }

    .bottom-box, .about-link {
        font-size: clamp(1.18rem, 5.5vw, 1.6rem);
    }
}

/* ==========================================================================
   ASCII Background
   ========================================================================== */
#ascii-container {
    position: fixed; /* Fixed keeps it behind scrolling content */
    top: 0; left: 0;
    width: 100vw; height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 0; /* Changed from -1 so it stays in the normal flow behind relative elements */
    background-color: transparent; /* Changed from solid color to ensure it does not cover body lines */
    overflow: hidden;
    transition: opacity 0.4s ease;
}

/* Hide in dark mode */
body.dark-mode #ascii-container {
    opacity: 0;
    pointer-events: none;
}

#ascii-bg {
    position: absolute;
    margin: 0; padding: 0;
    width: max-content;
    height: max-content;
    
    /* MUST MATCH YOUR EXPORT SETTINGS */
    font-family: monospace;
    font-size: 10px;
    line-height: 8px;
    letter-spacing: 4.5px;
    
    white-space: pre;
    text-align: center;            
    
    /* Removed GPU Color Masking as the exported script is in B&W mode */
    color: #757575;
    
    transform-origin: center;
    will-change: transform;
}

/* ==========================================================================
   View Transitions (Theme Toggle)
   ========================================================================== */
::view-transition,
::view-transition-group(*),
::view-transition-image-pair(*),
::view-transition-old(*),
::view-transition-new(*) {
    pointer-events: none !important;
}
::view-transition-group(root) {
    animation-duration: var(--vt-duration, 0.05s);
}
::view-transition-old(root),
::view-transition-new(root) {
    animation: none;
    mix-blend-mode: normal;
}
::view-transition-old(root) {
    z-index: 1;
}
::view-transition-new(root) {
    z-index: 2;
    mask: var(--mask-ref, none);
    -webkit-mask: var(--mask-ref, none);
    mask-size: var(--mask-size, cover);
    -webkit-mask-size: var(--mask-size, cover);
    image-rendering: pixelated;
}