/* --- CSS VARIABLES & THEMES --- */
:root {
    /* Light Mode */
    --bg-color: #f4f3ee;
    --text-color: #1a1a1a;
    --accent-primary: #ff5a5f; 
    --accent-secondary: #8c52ff; 
    --accent-tertiary: #2ec4b6; 
    --card-bg: #ffffff;
    --border-color: #000000;
    --shadow-color: #000000;
    --border-width: 3px;
    --shadow-offset: 8px; 
    --highlight-text: #f4f3ee; 
}

[data-theme="dark"] {
    /* Dark Mode */
    --bg-color: #0d0d0d;
    --text-color: #e0e0e0;
    --accent-primary: #ff2a6d; 
    --accent-secondary: #d1f7ff;
    --accent-tertiary: #05d9e8;
    --card-bg: #1a1a1a;
    --border-color: #ffffff;
    --shadow-color: #ff2a6d;
    --shadow-offset: 6px;
    --highlight-text: #000000;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    overflow-x: hidden; 
}

body {
    font-family: 'Space Grotesk', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    transition: background-color 0.4s ease, color 0.4s ease;
    overflow-x: hidden;
    line-height: 1.7;
    width: 100%;
}

/* --- UTILITIES --- */
.mono { font-family: 'JetBrains Mono', monospace; }

.container {
    max-width: 1300px; 
    margin: 0 auto;
    padding: 0 50px; 
}

/* --- HEADER --- */
header {
    display: none;
}

nav { display: flex; justify-content: space-between; align-items: center; }
.logo { font-size: 1.8rem; font-weight: 900; text-transform: uppercase; letter-spacing: -1px; }

/* Highlight animation for bento cards */
@keyframes highlight-glow {
    0%, 100% { 
        background-color: var(--card-bg);
    }
    25% { 
        background-color: var(--accent-tertiary);
    }
    50% {
        background-color: var(--card-bg);
    }
    75% {
        background-color: var(--accent-tertiary);
    }
}

.bento-highlight {
    animation: highlight-glow 1s ease-in-out;
}

.controls { display: flex; gap: 15px; }
.toggle-btn { background: transparent; border: 2px solid var(--border-color); padding: 8px 12px; font-family: 'JetBrains Mono', monospace; font-weight: bold; cursor: pointer; color: var(--text-color); box-shadow: 3px 3px 0px var(--shadow-color); transition: transform 0.1s; display: flex; align-items: center; gap: 8px; }
.toggle-btn:active { transform: translate(2px, 2px); box-shadow: 1px 1px 0px var(--shadow-color); }

/* Flag Icons */
.flag-icon {
    width: 20px;
    height: 14px;
    display: inline-block;
    border: 1px solid var(--border-color);
}

.flag-vn {
    background: #da251d;
    position: relative;
}

.flag-vn::after {
    content: '★';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: #ffff00;
    font-size: 9px;
    line-height: 1;
}

.flag-us {
    background: 
        linear-gradient(to bottom, 
            #b22234 0%, #b22234 7.69%, 
            white 7.69%, white 15.38%,
            #b22234 15.38%, #b22234 23.07%,
            white 23.07%, white 30.76%,
            #b22234 30.76%, #b22234 38.45%,
            white 38.45%, white 46.14%,
            #b22234 46.14%, #b22234 53.83%,
            white 53.83%, white 61.52%,
            #b22234 61.52%, #b22234 69.21%,
            white 69.21%, white 76.9%,
            #b22234 76.9%, #b22234 84.59%,
            white 84.59%, white 92.28%,
            #b22234 92.28%, #b22234 100%
        );
    position: relative;
}

.flag-us::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 40%;
    height: 53.83%;
    background: #3c3b6e;
}

/* --- HERO SECTION --- */
.hero {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: flex-start; 
    padding-top: 100px;
    overflow: hidden; 
}

.hero-content { 
    width: 100%; 
    position: relative;
}

.hero h1 {
    font-size: clamp(3rem, 11vw, 9rem); 
    line-height: 1;
    text-transform: uppercase;
    font-weight: 900;
    margin-bottom: 40px;
    letter-spacing: -3px;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}

.hero-static-line {
    display: block;
    margin-bottom: 10px; 
}

.hero-dynamic-wrapper {
    display: inline-flex; 
    align-items: center; 
    white-space: nowrap; 
    width: max-content;
    max-width: none;
    transform-origin: left center;
    transition: transform 0.4s cubic-bezier(0.25, 1, 0.5, 1);
}

/* --- TYPEWRITER --- */
.typewriter-box {
    font-family: 'JetBrains Mono', monospace;
    background-color: var(--accent-primary);
    color: var(--highlight-text);
    display: inline-flex;
    align-items: center;
    justify-content: flex-start;
    padding: 0.1em 0.4em; 
    min-height: 1.1em;
    border-radius: 4px;
    transition: none;
    vertical-align: baseline;
}

.typewriter-text { 
    white-space: pre; 
    line-height: 1;
    min-width: 0.5ch;
    display: inline-block;
}

.typewriter-text:empty::before {
    content: '\200b';
    display: inline-block;
}

.cursor-block {
    display: inline-block;
    width: 0.5em; 
    height: 0.8em;
    background-color: var(--highlight-text);
    margin-left: 0.2em;
    animation: cursor-blink 0.8s step-end infinite;
    flex-shrink: 0;
    vertical-align: baseline;
}
@keyframes cursor-blink { 0%, 100% { opacity: 1; } 50% { opacity: 0; } }

/* Language transition animation */
@keyframes langFadeOut {
    0% { opacity: 1; transform: translateY(0); }
    100% { opacity: 0; transform: translateY(-10px); }
}

@keyframes langFadeIn {
    0% { opacity: 0; transform: translateY(10px); }
    100% { opacity: 1; transform: translateY(0); }
}

.lang-transition-out {
    animation: langFadeOut 0.2s ease-out forwards !important;
}

.lang-transition-in {
    animation: langFadeIn 0.3s ease-out forwards !important;
}

.hero p {
    font-size: 1.4rem; margin-bottom: 50px; max-width: 650px;
    font-family: 'JetBrains Mono', monospace;
}

/* --- NEO BRUTALIST COMPONENTS --- */
.neo-box {
    border: var(--border-width) solid var(--border-color);
    background: var(--card-bg);
    box-shadow: var(--shadow-offset) var(--shadow-offset) 0px var(--shadow-color);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
    width: calc(100% - var(--shadow-offset)); 
    margin-bottom: 0;
}

.neo-box:hover { 
    transform: translate(-4px, -4px); 
    box-shadow: calc(var(--shadow-offset) + 4px) calc(var(--shadow-offset) + 4px) 0px var(--shadow-color); 
}

.neo-btn {
    display: inline-block; padding: 16px 32px; font-weight: 800; text-transform: uppercase; text-decoration: none;
    color: #000000; background-color: var(--accent-tertiary); border: var(--border-width) solid var(--border-color);
    box-shadow: 6px 6px 0px var(--shadow-color); cursor: pointer; font-family: 'JetBrains Mono', monospace;
    transition: all 0.1s cubic-bezier(0.25, 0.46, 0.45, 0.94);
    max-width: 100%;
}
.neo-btn:active { transform: translate(4px, 4px); box-shadow: 2px 2px 0px var(--shadow-color); }

/* --- SECTIONS & TITLES --- */
.section { padding: 80px 0; }

.section-title { 
    font-size: clamp(2.2rem, 5vw, 4rem); 
    text-transform: uppercase; 
    margin-top: 30px;
    margin-bottom: 40px; 
    position: relative; 
    display: inline-block; 
    z-index: 1; 
    line-height: 1.2; 
    overflow-wrap: break-word;
    word-break: break-word;
    max-width: 100%;
}

.section-title::after { content: ''; position: absolute; width: 100%; height: 40%; background: var(--accent-primary); bottom: 5px; left: 10px; z-index: -1; opacity: 0.6; }

/* GRID LAYOUT */
.grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); 
    gap: 50px;
    margin-bottom: var(--shadow-offset);
}

/* PROJECT CARDS */
.project-card { 
    padding: 40px; 
    display: flex; 
    flex-direction: column; 
    height: 100%; 
}

.project-img { width: 100%; height: 250px; background-color: #ddd; border: 2px solid var(--border-color); margin-bottom: 25px; display: flex; align-items: center; justify-content: center; font-weight: 900; font-size: 3rem; color: rgba(0,0,0,0.2); position: relative; overflow: hidden; }
.project-img::before { content: ''; position: absolute; top:0; left:0; width:100%; height:100%; background: linear-gradient(45deg, transparent 45%, rgba(0,0,0,0.1) 50%, transparent 55%); background-size: 200% 200%; animation: shimmer 3s infinite; }
@keyframes shimmer { 0% {background-position: 100% 100%} 100% {background-position: 0% 0%} }

.tags { margin: 20px 0; display: flex; gap: 12px; flex-wrap: wrap; }
.tag { background: transparent; border: 1px solid var(--border-color); color: var(--text-color); padding: 6px 12px; font-size: 0.85rem; font-weight: 700; text-transform: uppercase; }

/* SKILLS */
.skills-wrapper { 
    border: var(--border-width) solid var(--border-color); 
    padding: 50px; 
    background: var(--card-bg); 
    box-shadow: var(--shadow-offset) var(--shadow-offset) 0px var(--shadow-color);
    width: calc(100% - var(--shadow-offset));
    margin-bottom: var(--shadow-offset);
}

.skills-grid { display: flex; flex-wrap: wrap; gap: 20px; }
.skill-item { padding: 15px 30px; font-weight: 800; font-size: 1.2rem; background: var(--accent-secondary); color: #000; border: 2px solid var(--border-color); transition: transform 0.2s; }
.skill-item:hover { transform: translateY(-5px); }

/* CONTACT */
.contact-content { }
.contact-content .neo-box { max-width: 100%; }

footer { border-top: var(--border-width) solid var(--border-color); padding: 60px 0; text-align: center; background: var(--text-color); color: var(--bg-color); }

/* --- ANIMATION --- */

.marquee-container { 
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    background: var(--accent-secondary); 
    color: #000; 
    border-bottom: var(--border-width) solid var(--border-color); 
    padding: 15px 0; 
    overflow: hidden; 
    white-space: nowrap; 
    z-index: 1000;
}

[data-theme="dark"] .marquee-container {
    background: var(--accent-secondary);
    color: #000;
}

.marquee-wrapper { display: flex; }
.marquee-content { 
    display: inline-block; 
    animation: marquee 30s linear infinite; 
    font-weight: 900; 
    font-size: 1.5rem; 
    text-transform: uppercase;
    padding-right: 0;
}

/* Gradient overlay for controls area */
.marquee-container::after {
    content: '';
    position: absolute;
    top: 0;
    right: 0;
    width: 200px;
    height: 100%;
    background: linear-gradient(to left, var(--accent-secondary) 30%, transparent);
    pointer-events: none;
    z-index: 5;
}

.marquee-controls {
    display: flex;
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    gap: 10px;
    z-index: 10;
}

.marquee-controls .toggle-btn {
    background: #000;
    color: var(--accent-secondary);
    border-color: #000;
    box-shadow: 2px 2px 0px rgba(0, 0, 0, 0.3);
    padding: 6px 10px;
    font-size: 0.85rem;
}

[data-theme="dark"] .marquee-controls .toggle-btn {
    background: #fff;
    color: #000;
    border-color: #fff;
}

@keyframes marquee { 
    0% { transform: translateX(0); } 
    100% { transform: translateX(-100%); } 
}

/* Adjust body padding for fixed marquee */
body {
    padding-top: 60px;
}

.hero {
    padding-top: 40px;
}

/* Marquee adjustments for desktop */
@media (min-width: 1200px) {
    .marquee-container::after {
        width: 300px;
    }

    .marquee-controls {
        right: 50px;
        gap: 12px;
    }

    .marquee-controls .toggle-btn {
        font-size: 0.9rem;
    }

    .bento-container {
        padding-top: 80px;
    }

    body {
        padding-top: 0;
    }

    .hero {
        padding-top: 100px;
    }
}

.reveal { opacity: 0; transform: translateY(60px); transition: all 0.8s cubic-bezier(0.5, 0, 0, 1); }
.reveal.active { opacity: 1; transform: translateY(0); }

/* BENTO LAYOUT FOR DESKTOP */
@media (min-width: 1200px) {
    body {
        overflow-y: auto;
    }

    .bento-container {
        display: grid;
        grid-template-columns: repeat(12, 1fr);
        grid-template-rows: auto;
        gap: 30px;
        padding: 120px 50px 50px;
        max-width: 100vw;
        margin: 0 auto;
        min-height: 100vh;
    }

    .bento-hero {
        grid-column: 1 / 8;
        grid-row: 1 / 3;
        display: flex;
        flex-direction: column;
        justify-content: center;
        padding: 60px;
        min-height: 500px;
    }

    .bento-hero h1 {
        font-size: clamp(3rem, 5vw, 6rem);
        margin-bottom: 30px;
        line-height: 1.1;
        min-height: 2.2em;
    }

    .bento-hero .hero-static-line {
        display: block;
        min-height: 1.1em;
    }

    .bento-hero .hero-dynamic-wrapper {
        display: block;
        min-height: 1.1em;
    }

    .bento-hero p {
        opacity: 1;
        margin-bottom: 30px;
    }

    .bento-profile {
        grid-column: 8 / 13;
        grid-row: 1 / 2;
        padding: 40px;
        display: flex;
        flex-direction: column;
        justify-content: center;
    }

    .bento-skills {
        grid-column: 8 / 13;
        grid-row: 2 / 3;
        padding: 40px;
    }

    .bento-skills .skills-grid {
        gap: 12px;
    }

    .bento-skills .skill-item {
        padding: 10px 20px;
        font-size: 0.95rem;
    }

    .bento-contact {
        grid-column: 1 / 13;
        grid-row: 3 / 4;
        padding: 50px;
    }

    .bento-contact .neo-box {
        width: 100%;
        max-width: none;
        min-width: auto;
    }

    /* Projects container - separate grid for projects */
    #bento-projects {
        grid-column: 1 / 13;
        grid-row: 4 / 5;
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
        gap: 30px;
        width: 100%;
    }

    /* All project cards use auto placement */
    #bento-projects .project-card {
        width: 100%;
    }

    .section {
        display: none;
    }

    .hero {
        display: none;
    }

    .marquee-container {
        display: block !important;
    }

    footer {
        display: none;
    }

    .bento-layout {
        display: grid;
    }

    .bento-layout .project-card {
        padding: 30px;
        height: 100%;
    }

    .bento-layout .project-img {
        height: 180px;
        font-size: 2rem;
    }

    .bento-layout h3 {
        font-size: 1.4rem !important;
    }

    .bento-layout .tags {
        margin: 15px 0;
        gap: 8px;
    }

    .bento-layout .tag {
        font-size: 0.75rem;
        padding: 4px 8px;
    }

    .bento-section-title {
        font-size: 2rem;
        margin-bottom: 25px;
    }

    .bento-contact h3 {
        font-size: 2rem !important;
        margin-bottom: 20px;
    }

    .bento-contact p {
        font-size: 1.1rem;
        margin-bottom: 30px;
    }

    .bento-contact .neo-box {
        padding: 35px;
    }
}

/* RESPONSIVE ADJUSTMENTS */
@media (max-width: 1199px) {
    .bento-layout {
        display: none !important;
    }
}

@media (max-width: 900px) {
    .container { 
        padding: 0 25px; 
    }
    
    .project-card {
        padding: 30px !important;
    }
    
    .skills-wrapper {
        padding: 35px !important;
    }
    
    .neo-box.contact-form {
        padding: 30px !important;
    }

    .hero h1 { font-size: 3.5rem; }
    
    .contact-content .neo-box {
        min-width: auto !important;
        width: 100%;
    }
    
    .neo-box, .skills-wrapper {
        width: calc(100% - var(--shadow-offset));
    }
}

@media (max-width: 600px) {
    .container {
        padding: 0 20px;
    }
    
    .project-card,
    .skills-wrapper,
    .neo-box.contact-form {
        padding: 25px !important;
    }
    
    .section-title {
        font-size: clamp(1.8rem, 8vw, 3rem);
    }
}
