/* Reset default styles */
body {
    margin: 0;
    padding: 0;
    font-family:
        system-ui,
        -apple-system,
        sans-serif;
    background-color: #4c566a; /* Nord background */
    color: #eceff4;
    /* Prevent vertical scroll on body, we scroll the container horizontally */
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Grain overlay */
body::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: -1;
    background-image: url("/img/noise.svg");
    opacity: 0.15;
    filter: contrast(150%) brightness(100%);
}

figure {
    margin: 0;
    padding: 0;
}

/*
   Horizontal Masonry Layout using CSS Multi-column
   This creates a "waterfall" effect that flows top-to-bottom, then left-to-right.
*/
.container {
    /* Define column width - browser will fit as many as possible vertically,
       then overflow horizontally */
    column-width: 260px;
    column-gap: 16px;

    /* Fill columns sequentially (don't balance heights) */
    column-fill: auto;

    /* Fix height to viewport to force horizontal overflow */
    height: 100vh;
    width: 130vw;

    /* Enable horizontal scrolling */
    overflow-x: auto;
    overflow-y: hidden;

    /* Hide scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;

    padding: 16px;
    box-sizing: border-box;

    /* Hardware acceleration for smoother scrolling */
    will-change: scroll-position;
}

.container::-webkit-scrollbar {
    display: none;
}

/* Individual grid items */
.grid-item {
    /* Prevent items from being split across columns */
    break-inside: avoid;
    page-break-inside: avoid;

    /* Spacing between items */
    margin-bottom: 16px;

    /* Ensure items fit the column width */
    width: 100%;

    /* Force block formatting context to help with column breaking */
    display: inline-block;
}

/* Image items */
.grid-item img {
    display: block;
    width: 100%;
    height: auto;
}

/* Poem Text Items - Cartography Style */
.text-item {
    padding: 2rem 1.5rem;
    font-family: "Roboto Mono";
    font-size: 1.4rem;
    line-height: 1.2;
    text-align: center;
    color: #eceff4; /* Slightly off-white Nord */
    background-color: transparent;

    /* Cartography aesthetic: slightly wider letter spacing */
    letter-spacing: 0.02em;
}

/* Mobile Optimizations */
@media (max-width: 600px) {
    .container {
        /* Switch to Flexbox for better control over column width on mobile */
        display: flex;
        flex-direction: column;
        flex-wrap: wrap;
        align-content: flex-start; /* Prevent columns from stretching */

        height: 100vh;
        width: 100vw;

        padding: 12px;

        /* Reset multi-column properties */
        column-width: auto;
        column-gap: normal;
    }

    .grid-item {
        /* Fixed width to ensure peeking */
        width: 65vw;
        /* Use margins instead of gap for robust spacing */
        margin-bottom: 12px;
        margin-right: 12px;
        flex: 0 0 auto;
    }

    .text-item {
        font-size: 1.1rem;
        padding: 1rem 0.5rem;
    }
}
