:root {
    /* Washi Paper Palette */
    --bg-color: #fcfaf7;
    /* Warmer white */
    --text-color: #2b2b2b;
    /* Soft black */
    --accent-color: #5d7c5d;
    /* Muted Moss */
    --secondary-accent: #a3bfa3;
    /* Sage */
    --ink-color: #1a1a1a;
    --paper-texture: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI0IiBoZWlnaHQ9IjQiPgo8cmVjdCB3aWR0aD0iNCIgaGVpZ2h0PSI0IiBmaWxsPSIjZmNmYWY3Ii8+CjxyZWN0IHdpZHRoPSI0IiBoZWlnaHQ9IjQiIGZpbGw9IiMwMDAiIG9wYWNpdHk9IjAuMDIiLz4KPC9zdmc+');
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    background-image: var(--paper-texture);
    color: var(--text-color);
    font-family: 'Noto Serif JP', serif;
    overflow-x: hidden;
    overflow-y: auto;
    /* Enable scrolling */
    width: 100vw;
}

/* Vignette & Texture Overlay - Fixed to viewport */
body::after {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(circle, transparent 60%, rgba(0, 0, 0, 0.05) 100%);
    pointer-events: none;
    z-index: 1;
}

/* Canvas - Fixed background */
.canvas-wrapper {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100vh;
    z-index: 0;
}

canvas {
    display: block;
    width: 100%;
    height: 100%;
    /* Ink bleed effect */
    filter: contrast(1.1) sepia(0.1) blur(0.5px);
}

/* UI Layer - First Screen */
.ui-layer {
    position: relative;
    /* Changed from absolute to relative */
    width: 100%;
    height: 100vh;
    z-index: 10;
    pointer-events: none;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto 1fr auto;
    padding: 40px;
}

/* Header */
header {
    grid-column: 1 / -1;
    grid-row: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    animation: fadeIn 1.5s ease-out;
}

h1 {
    font-size: 2.5rem;
    font-weight: 300;
    letter-spacing: 0.3em;
    color: var(--text-color);
    margin-bottom: 5px;
    position: relative;
    padding-left: 20px;
}

h1::before {
    content: "";
    position: absolute;
    left: 0;
    top: 10%;
    height: 80%;
    width: 2px;
    background-color: var(--accent-color);
}

.subtitle {
    font-size: 0.9rem;
    color: var(--secondary-accent);
    margin-left: 25px;
    font-style: italic;
    letter-spacing: 0.15em;
    font-weight: 300;
}

/* Haiku Container */
.haiku-container {
    grid-column: 2;
    grid-row: 2;
    justify-self: end;
    align-self: center;
    writing-mode: vertical-rl;
    text-orientation: upright;
    height: 60vh;
    max-height: 500px;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    pointer-events: none;
    margin-right: 20px;
    animation: fadeIn 2s ease-out 0.5s backwards;
}

.haiku-text {
    font-size: 1.6rem;
    line-height: 2.2;
    color: var(--text-color);
    font-family: 'Noto Serif JP', serif;
    letter-spacing: 0.1em;
    border-right: 1px solid rgba(93, 124, 93, 0.3);
    padding-right: 25px;
    transition: opacity 1s ease;
    /* Text outline for readability */
    text-shadow:
        2px 2px 0 var(--bg-color),
        -2px -2px 0 var(--bg-color),
        2px -2px 0 var(--bg-color),
        -2px 2px 0 var(--bg-color),
        2px 0px 0 var(--bg-color),
        -2px 0px 0 var(--bg-color),
        0px 2px 0 var(--bg-color),
        0px -2px 0 var(--bg-color);
}

/* Scroll Indicator */
.scroll-indicator {
    grid-column: 1 / -1;
    grid-row: 3;
    justify-self: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    opacity: 0.6;
    animation: fadeIn 2s ease-out 2s backwards;
}

.scroll-indicator span {
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    color: var(--accent-color);
}

.scroll-indicator .line {
    width: 1px;
    height: 40px;
    background-color: var(--accent-color);
    animation: scrollLine 2s infinite;
}

@keyframes scrollLine {
    0% {
        transform: scaleY(0);
        transform-origin: top;
    }

    50% {
        transform: scaleY(1);
        transform-origin: top;
    }

    51% {
        transform: scaleY(1);
        transform-origin: bottom;
    }

    100% {
        transform: scaleY(0);
        transform-origin: bottom;
    }
}

/* Content Layer - New Sections */
.content-layer {
    position: relative;
    z-index: 5;
    background: linear-gradient(to bottom, transparent 0%, var(--bg-color) 20%);
    margin-top: -10vh;
    /* Overlap slightly */
    padding-top: 10vh;
}

.section {
    min-height: 80vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 80px 20px;
    opacity: 0;
    /* For scroll animation */
    transform: translateY(20px);
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.section.visible {
    opacity: 1;
    transform: translateY(0);
}

.section-content {
    max-width: 800px;
    width: 100%;
    text-align: center;
}

.section h2 {
    font-size: 1rem;
    color: var(--accent-color);
    letter-spacing: 0.2em;
    text-transform: uppercase;
    margin-bottom: 10px;
}

.section h3 {
    font-size: 2rem;
    font-weight: 400;
    margin-bottom: 40px;
    letter-spacing: 0.1em;
}

.section p {
    font-size: 1.1rem;
    line-height: 2;
    margin-bottom: 30px;
    color: rgba(43, 43, 43, 0.8);
}

/* Algorithm Section Specifics */
.code-snippet {
    background: rgba(255, 255, 255, 0.5);
    padding: 30px;
    border-left: 2px solid var(--accent-color);
    margin: 40px auto;
    text-align: left;
    font-family: monospace;
    font-size: 0.9rem;
    color: var(--ink-color);
    width: fit-content;
}



/* Footer */
footer {
    padding: 60px 20px;
    text-align: center;
    border-top: 1px solid rgba(0, 0, 0, 0.05);
    margin-top: 60px;
}

.footer-content p {
    font-size: 0.8rem;
    color: #999;
    margin-bottom: 10px;
}

/* Controls - Keep fixed but adjust z-index */
.controls {
    position: fixed;
    right: 40px;
    bottom: 40px;
    display: flex;
    justify-content: flex-end;
    align-items: flex-end;
    pointer-events: auto;
    z-index: 100;
    /* Always on top */
    animation: fadeIn 2s ease-out 1s backwards;
}

/* Button */
button#regenerateBtn {
    background: rgba(255, 255, 255, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    color: var(--accent-color);
    border: 1px solid var(--accent-color);
    padding: 12px 30px;
    font-family: 'Noto Serif JP', serif;
    font-size: 0.85rem;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    cursor: pointer;
    transition: all 0.4s ease;
    border-radius: 50px;
    /* Pill shape */
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

button#regenerateBtn:hover {
    background: var(--accent-color);
    color: var(--bg-color);
    box-shadow: 0 4px 15px rgba(93, 124, 93, 0.3);
    transform: translateY(-1px);
}

button#regenerateBtn:active {
    transform: translateY(1px);
}

/* Animations */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

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

/* Mobile Responsive */
@media (max-width: 768px) {
    .ui-layer {
        padding: 20px;
        grid-template-rows: auto 1fr auto;
        grid-template-columns: 1fr;
    }

    header {
        align-items: center;
        text-align: center;
    }

    h1 {
        font-size: 1.8rem;
        padding-left: 0;
        margin-bottom: 5px;
    }

    h1::before {
        display: none;
        /* Remove side bar on mobile for cleaner look */
    }

    .subtitle {
        margin-left: 0;
        font-size: 0.8rem;
    }

    .haiku-container {
        grid-column: 1;
        grid-row: 2;
        justify-self: center;
        align-self: center;
        margin-right: 0;
        height: auto;
        max-height: 60vh;
        /* Keep vertical for aesthetic, but maybe adjust size */
    }

    .haiku-text {
        font-size: 1.3rem;
        line-height: 1.8;
        border-right: none;
        /* Remove border on mobile */
        padding-right: 0;
        padding-top: 20px;
        border-top: 1px solid rgba(93, 124, 93, 0.3);
        /* Top border instead */
    }

    .controls {
        left: 0;
        right: 0;
        bottom: 20px;
        justify-content: center;
    }

    button#regenerateBtn {
        padding: 12px 40px;
        background: rgba(255, 255, 255, 0.7);
        /* More opaque on mobile */
    }

    .section {
        padding: 60px 20px;
        min-height: auto;
        /* Allow variable height on mobile */
    }

    .section h3 {
        font-size: 1.5rem;
    }
}