:root {
    /* Core palette */
    --background: #080200;
    --text-color: #eaeaea;
    --text-muted: #8f8f8f;
    --link-color: #6495ed;
    --date: #7188a9;

    /* Page-specific colors */
    --home-heading-color: var(--text-color);
    /* or choose appropriate color */
    --md-link-color: var(--link-color);
    --md-text-color: #a7c4c5;
    --md-heading-color: #8abeb7;
    --links-heading-color: #88c0d0;
    --links-footer-color: #b48ead;
    --gallery-heading-color: #f0c674;
    --blog-heading-color: #8ec07c;
    --projects-heading-color: #d3a7ee;
    --wired-accent-color: #c1b492;
    --wired-link-hover: #d3768d;
    --matrix-green: #51da3f;

    /* Typography */
    --h1-size: 2em;
    --h2-size: 1.75em;
    --h3-size: 1.5em;
    --h4-size: 1.4em;
    --p-size: 1.3em;
    --base-line-height: 1.6;
    --content-letter-spacing: 0.05em;

    /* Spacing */
    --space-xs: 0.25rem;
    --space-sm: 0.5rem;
    --space-md: 1rem;
    --space-lg: 1.5rem;
    --space-xl: 2rem;
    --space-xxl: 13%;
    --content-padding: 5%;
    --text-padding: var(--space-md);

    /* Container widths */
    --content-width-narrow: 600px;
    --content-width-regular: 1000px;
    --content-width-wide: 1400px;

    /* Effects */
    --transition-fast: 0.2s ease;
    --transition-medium: 0.3s ease;
    --transition-slow: 0.5s ease;
    --box-shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.2);
    --box-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.15);
    --box-shadow-lg: 0 8px 20px rgba(0, 0, 0, 0.3);
    --border-radius-sm: 4px;
    --border-radius-md: 8px;
    --border-radius-lg: 20px;
}

/* Base elements */
html {
    height: 100%;
    scroll-behavior: smooth;
    box-sizing: border-box;
    font-size: 16px;
    overflow-x: hidden;
}

*,
*::before,
*::after {
    box-sizing: inherit;
    margin: 0;
    padding: 0;
}

@font-face {
    font-family: "LoveLetterTypewriter";
    src: url(LoveLetterTypewriter.ttf) format('truetype');
    font-display: swap;
}

body {
    display: flex;
    flex-direction: column;
    font-family: 'LoveLetterTypewriter', system-ui, -apple-system, sans-serif;
    color: var(--text-color);
    background: var(--background);
    overflow-x: hidden;
    line-height: var(--base-line-height);
    padding: var(--space-md);
    margin: 0;
    -webkit-overflow-scrolling: touch;
}

a {
    text-decoration: none;
    color: var(--link-color);
    transition: color var(--transition-fast);
}

a:hover {
    color: var(--wired-link-hover);
}

/* Layout & structure */
.content {
    padding: var(--content-padding);
    color: var(--text-color);
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    max-width: var(--content-width-regular);
    margin: 0 auto;
    width: 100%;
    letter-spacing: var(--content-letter-spacing);
    line-height: var(--base-line-height);
}

:where(.content, .md) :is(h1, h2, h3, h4) {
    font-weight: 600;
    margin-top: var(--space-lg);
}

.content {
    h1 { font-size: var(--h1-size); margin-bottom: var(--space-lg); }
    h2 { font-size: var(--h2-size); margin-bottom: var(--space-md); }
    h3 { font-size: var(--h3-size); margin-bottom: var(--space-md); }
    h4 { font-size: var(--h4-size); margin-bottom: var(--space-sm); }
    p {
        font-size: var(--p-size);
        margin-bottom: var(--space-lg);
        padding-left: var(--text-padding);
        line-height: var(--base-line-height);
    }
}

.content p time {
    color: var(--text-muted);
    font-size: medium;
    font-style: italic;
}

/* Long text elements */
.longtext {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}

/* Navigation */
.navbar {
    width: 100%;
    display: flex;
    justify-content: flex-start;
    flex-wrap: wrap;
    margin-bottom: var(--space-lg);
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
    border-radius: var(--border-radius-md);
    padding: var(--space-xs);
}

.navbar a {
    color: var(--text-color);
    text-decoration: none;
    padding: var(--space-sm) var(--space-md);
    margin-right: var(--space-sm);
    transition: all var(--transition-medium);
    border-radius: var(--border-radius-sm);
    --link-accent: var(--link-color);
}

.navbar a[href*="index.html"],
.navbar a[href="./"] {
    --link-accent: var(--home-heading-color);
}

.navbar a[href*="blog.html"] {
    --link-accent: var(--blog-heading-color);
}

.navbar a[href*="gallery.html"] {
    --link-accent: var(--gallery-heading-color);
}

.navbar a[href*="links.html"] {
    --link-accent: var(--links-heading-color);
}

.navbar a[href*="wired.html"] {
    --link-accent: var(--wired-accent-color);
}

.navbar a[href*="projects.html"] {
    --link-accent: var(--projects-heading-color);
}

.navbar a:hover,
.navbar a.active {
    color: var(--link-accent);
    transform: translateY(-2px);
}

/* Components */
.img-responsive,
.front img {
    max-width: 100%;
    height: auto;
    display: block;
    border-radius: var(--border-radius-md);
    box-shadow: var(--box-shadow-md);
    transition: transform var(--transition-medium);
    margin-bottom: 0;
}

.img-responsive:hover,
.front img:hover {
    transform: scale(1.02);
}

.letters img {
    max-width: 133%;
}

/* Gallery layout and styling */
.gallery {
    width: 100%;
    max-width: 1600px;
    margin: 0 auto;
    padding: var(--space-lg);
    column-count: 2;
    column-gap: 1rem;
    column-fill: balance;
}

.gallery-item {
    position: relative;
    display: block;
    margin-bottom: 1rem;
    overflow: hidden;
    border-radius: var(--border-radius-md);
    break-inside: avoid;
    transition: all var(--transition-medium);
    cursor: pointer;
}

.gallery-item:hover {
    transform: translateY(-2px);
    box-shadow: var(--box-shadow-lg);
}

.gallery-item::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.1);
    opacity: 0;
    transition: opacity var(--transition-medium);
    z-index: 1;
    pointer-events: none;
}

.gallery-item:hover::before {
    opacity: 1;
}

.gallery-item img {
    display: block;
    width: 100%;
    height: auto;
    border-radius: var(--border-radius-md);
    box-shadow: var(--box-shadow-md);
    transition: all var(--transition-medium);
    backface-visibility: hidden;
    will-change: transform;
    object-fit: cover;
}

.gallery-item:hover img {
    transform: scale(1.01);
}

/* Image overlay for captions - shown on hover */
.image-overlay {
    position: absolute;
    bottom: -1px;
    left: 0;
    right: 0;
    background: linear-gradient(transparent 50%, rgba(0, 0, 0, 0.9));
    color: white;
    padding: 1.25rem 1rem 1rem;
    transform: translateY(100%);
    transition: all var(--transition-medium) cubic-bezier(0.4, 0, 0.2, 1);
    border-radius: 0 0 var(--border-radius-md) var(--border-radius-md);
    opacity: 0;
    z-index: 2;
}

.gallery-item:hover .image-overlay,
.gallery-item:focus .image-overlay {
    transform: translateY(0);
    opacity: 1;
}

.image-title {
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    opacity: 1;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
    letter-spacing: 0.025em;
    line-height: 1.3;
    margin: 0;
    transition: all var(--transition-fast);
}

/* Hero and featured item variations & Loading states */
.gallery-item.hero-item {
    grid-column: span 2;
}

.gallery-item.featured-item img {
    box-shadow: 0 4px 20px rgba(240, 198, 116, 0.3);
}

.gallery-item.hero-item img {
    box-shadow: 0 8px 32px rgba(240, 198, 116, 0.4);
}

.gallery img.loading {
    opacity: 0.7;
    filter: blur(2px);
}

.gallery img.loaded {
    animation: fadeIn 0.6s ease-in-out;
    opacity: 1;
    filter: none;
}

/* Gallery entrance animation */
.gallery-entrance {
    opacity: 0;
    transform: translateY(20px);
    animation: galleryEnter 0.6s ease-out forwards;
}

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

/* Markdown styling */
.md {
    margin-left: 10%;
    padding: var(--space-lg) var(--space-xl);
    width: 80%;
    max-width: 900px;
    box-sizing: border-box;
    margin-top: var(--space-lg);
    margin-bottom: var(--space-lg);
    border-radius: var(--border-radius-lg);
    background: rgba(15, 15, 15, 0.7);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    box-shadow: var(--box-shadow-md);
}

.md a {
    color: var(--md-link-color);
    text-decoration: underline;
    transition: color var(--transition-fast);
}

.md a:hover {
    color: var(--wired-link-hover);
}

.md p {
    color: var(--md-text-color);
    font-size: var(--p-size);
    line-height: 1.7;
    margin-bottom: var(--space-md);
}


.md h1::after,
.md h2::after {
    content: '';
    position: relative;
    display: block;
    margin-top: var(--space-xs);
    width: 80px;
    height: 3px;
    background: linear-gradient(90deg, var(--md-link-color), var(--matrix-green));
    border-radius: var(--border-radius-sm);
}

canvas {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: -1;
    pointer-events: none !important;
    user-select: none !important;
    -webkit-user-select: none !important;
    -moz-user-select: none !important;
    -ms-user-select: none !important;
}

/* Contact list */
.contact-list {
    list-style: none;
    padding: 0;
    margin-bottom: var(--space-lg);
    padding-left: var(--text-padding);
}

.contact-list li {
    margin-bottom: var(--space-md);
}

.contact-list a {
    display: inline-block;
    font-size: 1.2em;
    transition: transform var(--transition-medium), color var(--transition-medium);
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--border-radius-sm);
}

.contact-list a:hover {
    transform: translateX(5px);
}

/* Page-specific heading colors */
.links h1 {
    color: var(--links-heading-color);
}

.projects h1 {
    color: var(--projects-heading-color);
}

.blog h1 {
    color: var(--blog-heading-color);
}

#gallery {
    color: var(--gallery-heading-color);
}

/* Treasures page specific */
.treasures .content {
    margin-left: var(--space-lg);
}

.treasures zero-md {
    margin-left: var(--space-lg);
    padding-left: auto;
}

.treasures h1 {
    cursor: pointer;
    transition: color 0.3s ease;
}

.treasures h1:hover {
    color: var(--matrix-green);
}

.treasures .md h1::after {
    background: linear-gradient(90deg, var(--matrix-green), var(--md-link-color));
}

/* Links page footer */
.links footer a {
    color: var(--links-footer-color);
}

.content.md zero-md {
    display: block;
    width: 100%;
    margin-bottom: var(--space-lg);
}

.content.md a img {
    display: inline-block;
    margin: var(--space-sm) 0;
    transition: transform var(--transition-medium);
}

.content.md a img:hover {
    transform: scale(1.05);
}

.content.md footer {
    margin-top: var(--space-lg);
    text-align: center;
    width: 100%;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    padding-top: var(--space-md);
}

.content.md footer p {
    font-size: 0.9em;
    margin-bottom: 0;
}

/* Wired page */
.wired .content a,
.wired .navbar a:hover {
    color: var(--wired-link-hover);
    text-decoration-color: currentColor;
}

.wired .content a:hover,
.wired .navbar #wired:hover,
.wired h1 {
    color: var(--wired-accent-color);
}

.wired .lain img {
    float: right;
    transform: rotate(2deg);
    transition: transform var(--transition-medium);
}

.wired .lain img:hover {
    transform: rotate(-1deg) scale(1.03);
}

/* Animations */
.floatLetters {
    position: relative;
    z-index: -10;
    height: 0;
}

.letters {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    pointer-events: none;
}

.letters li {
    position: absolute;
    display: block;
    list-style: none;
    width: 20px;
    height: 20px;
    background: transparent;
    animation: animateLetters 25s linear infinite;
    bottom: -150px;
    z-index: -10;
}

.letters li:nth-child(1) {
    left: 25%;
    width: 60px;
    height: 60px;
    animation-delay: 0s;
    font-size: 35px;
}

.letters li:nth-child(2) {
    left: 10%;
    width: 20px;
    height: 20px;
    animation-delay: 2s;
    animation-duration: 12s;
}

.letters li:nth-child(3) {
    right: 30%;
    width: 10px;
    height: 10px;
    animation-delay: 1s;
    font-size: 10px;
}

.letters li:nth-child(4) {
    right: 35%;
    width: 20px;
    height: 20px;
    animation-delay: 4s;
    animation-duration: 10s;
}

.letters li:nth-child(5) {
    right: 50%;
    width: 25px;
    height: 25px;
    animation-delay: 3s;
    animation-duration: 8s;
}

.letters li:nth-child(6) {
    right: 10%;
    width: 25px;
    height: 25px;
    animation-delay: 12s;
    animation-duration: 10s;
}

.letters li:nth-child(7) {
    right: 60%;
    width: 25px;
    height: 25px;
    animation-delay: 10s;
    animation-duration: 8s;
}

@keyframes animateLetters {
    0% {
        transform: translateY(0) rotate(0deg);
        opacity: 1;
        border-radius: 0;
    }

    80% {
        transform: translateY(-800px) rotate(720deg);
        opacity: 0;
        border-radius: 50%;
    }

    100% {
        transform: translateY(-1000px) rotate(720deg);
        opacity: 0;
        border-radius: 50%;
    }
}

.no-margin {
    margin: 0 !important;
}

/* Glass Modal Styles */
.glass-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    justify-content: center;
    align-items: center;
    background: rgba(10, 10, 15, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    z-index: 1000;
}

.glass-modal-content {
    position: relative;
    max-width: 95%;
    max-height: 90vh;
    margin: 0 auto;
    padding: 0;
    background: transparent;
    border-radius: 12px;
    overflow: hidden;
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.4s ease, opacity 0.4s ease;
}

.glass-modal.active {
    display: flex;
    animation: fadeIn 0.3s forwards;
}

.glass-modal.active .glass-modal-content {
    animation: slideUp 0.4s forwards;
}

.modal-image {
    display: block;
    max-width: 100%;
    max-height: 85vh;
    width: auto;
    height: auto;
    border-radius: 12px;
    object-fit: contain;
    background: transparent;
}

/* Modal Navigation */
.modal-nav {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    cursor: pointer;
    z-index: 1010;
    transition: all 0.3s ease;
    opacity: 0.8;
}

.modal-nav:hover {
    background: rgba(255, 255, 255, 0.2);
    opacity: 1;
    transform: translateY(-50%) scale(1.1);
}

.modal-nav-prev {
    left: 20px;
}

.modal-nav-next {
    right: 20px;
}

.modal-nav svg {
    width: 24px;
    height: 24px;
    fill: white;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    cursor: pointer;
    z-index: 1010;
    transition: all 0.3s ease;
    opacity: 0.8;
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.2);
    opacity: 1;
    transform: scale(1.1);
}

.modal-close:before,
.modal-close:after {
    content: '';
    position: absolute;
    width: 18px;
    height: 2px;
    background: white;
    border-radius: 1px;
}

.modal-close:before {
    transform: rotate(45deg);
}

.modal-close:after {
    transform: rotate(-45deg);
}

/* Modal Caption - positioned outside image */
.modal-caption {
    position: absolute;
    bottom: -60px;
    left: 50%;
    transform: translateX(-50%);
    padding: 15px 20px;
    color: var(--text-color);
    font-size: 1.1em;
    text-align: center;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 25px;
    opacity: 0;
    transform: translateX(-50%) translateY(20px);
    transition: opacity 0.4s ease, transform 0.4s ease;
    white-space: nowrap;
    max-width: 90vw;
    overflow: hidden;
    text-overflow: ellipsis;
}



/* Modal Animations & Effects */
.pulse {
    animation: pulse 1s ease;
}

.modal-loader {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 40px;
    height: 40px;
    z-index: 1005;
}

.modal-loader:after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    border: 3px solid rgba(255, 255, 255, 0.2);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

/* Animation Keyframes */
@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

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

@keyframes pulse {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.05);
    }

    100% {
        transform: scale(1);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* Mobile-first Base Styles */
.navbar {
    justify-content: center;
}

.navbar a {
    margin: var(--space-xs);
    text-align: center;
}

.modal-caption {
    font-size: 0.9em;
    padding: var(--space-xs);
}

.md {
    margin: var(--space-md) auto;
    padding: var(--space-md);
    width: 95%;
}

/* --- Responsive Enhancements (Mobile-First) --- */
@media (min-width: 600px) {
    body {
        padding: 3% 10%;
    }

    .navbar a {
        float: left;
        margin-right: 0.5%;
        font-size: 1.3em;
    }

    .md {
        padding-left: var(--space-lg);
        width: 70%;
        backdrop-filter: blur(12px);
        -webkit-backdrop-filter: blur(12px);
    }

    .markdown-body {
        padding-left: 10rem;
    }

    .gallery {
        column-count: 2;
        padding: var(--space-lg);
        column-gap: 1rem;
    }

    .modal-caption {
        font-size: 1.1rem;
        padding: 1rem 1.5rem;
        bottom: -70px;
    }

    .modal-nav {
        width: 60px;
        height: 60px;
    }

    .modal-nav svg {
        width: 28px;
        height: 28px;
    }
}

@media (min-width: 900px) {
    body {
        padding: 3% 15%;
    }

    .gallery {
        column-count: 3;
        column-gap: 1.25rem;
    }

    .md {
        padding-left: var(--space-xxl);
        backdrop-filter: blur(15px);
        -webkit-backdrop-filter: blur(15px);
    }

    .glass-modal-content {
        margin: 0;
        max-width: 90%;
    }

    .modal-caption {
        bottom: -80px;
        font-size: 1.2rem;
    }
}

@media (min-width: 1200px) {
    .content {
        max-width: var(--content-width-wide);
    }

    .gallery {
        column-count: 4;
        column-gap: 1.5rem;
    }

    .md {
        margin-left: 10%;
        width: 80%;
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
    }

    .glass-modal .modal-image {
        max-height: 85vh;
    }

    .modal-caption {
        bottom: -90px;
        font-size: 1.3rem;
        padding: 1.25rem 2rem;
    }
}

@media (min-width: 1600px) {
    .gallery {
        column-count: 5;
        column-gap: 1.5rem;
    }
}

/* Mobile-specific adjustments */
@media (max-width: 599px) {
    .gallery {
        column-count: 1;
        column-gap: 0.75rem;
        padding: var(--space-md);
    }

    .modal-nav {
        display: none;
        /* Hide navigation arrows on mobile to prevent overlay issues */
    }

    .modal-close {
        top: 10px;
        right: 10px;
        width: 35px;
        height: 35px;
    }

    .modal-caption {
        bottom: -50px;
        font-size: 0.9rem;
        padding: 0.75rem 1rem;
        max-width: 95vw;
        left: 50%;
        transform: translateX(-50%);
    }

    .glass-modal-content {
        max-width: 98%;
        max-height: 85vh;
    }

    .modal-image {
        max-height: 80vh;
    }

    /* Gallery hover effects on mobile */
    .gallery-item:hover {
        transform: none;
        /* Disable transform on mobile for better touch experience */
    }

    .gallery-item:hover::before {
        opacity: 0.7;
        /* Slightly reduce overlay on mobile */
    }

    .image-overlay {
        /* On mobile, make overlay slightly more visible by default for touch accessibility */
        background: linear-gradient(transparent 40%, rgba(0, 0, 0, 0.9));
        padding: 1.75rem 0.75rem 1rem;
    }

    .gallery-item:hover .image-overlay {
        transform: translateY(0);
        opacity: 1;
    }

    .image-title {
        font-size: 0.85rem;
        padding: 0.5rem 0;
    }
}

/* Accessibility improvements for captions */
.gallery-item:focus .image-overlay,
.gallery-item:focus-within .image-overlay {
    transform: translateY(0);
    opacity: 1;
}

.gallery-item:focus::before,
.gallery-item:focus-within::before {
    opacity: 1;
}

.gallery-item:focus {
    outline: 2px solid var(--gallery-heading-color);
    outline-offset: 2px;
    transform: translateY(-2px);
}