/* scriptgrapher.com - Generative Art Pen Plotter */

/* ===== Reset & Base ===== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    background-color: #f7f4ef;
}

body {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 16px;
    font-weight: 400;
    line-height: 1.7;
    color: #2d2d3a;
    background-color: #f7f4ef;
    overflow-x: hidden;
    position: relative;
    cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpolygon points='4,28 8,8 12,28' fill='%231a1a2e'/%3E%3C/svg%3E") 4 28, auto;
}

/* ===== SVG Filters (hidden) ===== */
.svg-filters {
    position: absolute;
    width: 0;
    height: 0;
    overflow: hidden;
}

/* ===== Paper Overlay ===== */
#paper-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* ===== Dot Grid ===== */
#dot-grid {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    opacity: 0;
    transition: opacity 0.6s ease;
    background-image: radial-gradient(circle, #d4d0c8 1px, transparent 1px);
    background-size: 40px 40px;
    background-position: 20px 20px;
}

#dot-grid.visible {
    opacity: 0.3;
}

/* ===== Hero / Title Drawing ===== */
#hero {
    position: relative;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 1;
}

#pen-nib {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -70px);
    opacity: 0;
    transition: opacity 0.4s ease, transform 0.6s ease;
    z-index: 2;
}

#pen-nib.visible {
    opacity: 1;
    transform: translate(-50%, -60px);
}

#title-container {
    text-align: center;
    position: relative;
    z-index: 1;
}

#title-svg {
    width: 90%;
    max-width: 700px;
    height: auto;
}

#title-path {
    will-change: stroke-dashoffset;
}

#subtitle {
    font-family: 'Caveat', cursive;
    font-size: 24px;
    font-weight: 400;
    color: #5a5a7a;
    margin-top: 20px;
    opacity: 0;
    transition: opacity 0.8s ease;
}

#subtitle.visible {
    opacity: 1;
}

/* ===== Section Titles ===== */
.section-title {
    font-family: 'Caveat', cursive;
    font-size: 48px;
    font-weight: 700;
    color: #1a1a2e;
    text-align: center;
    margin-bottom: 48px;
}

/* ===== Gallery ===== */
#gallery {
    position: relative;
    z-index: 1;
    padding: 80px 5vw;
}

#gallery-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 24px;
    max-width: 1200px;
    margin: 0 auto;
}

.gallery-card {
    opacity: 0;
    transform: scale(0.96);
    transition: opacity 0.6s ease, transform 0.6s ease;
}

.gallery-card.visible {
    opacity: 1;
    transform: scale(1);
}

.card-mat {
    background: #ffffff;
    padding: 16px;
    border: 1px solid #d4d0c8;
}

.spirograph {
    width: 100%;
    aspect-ratio: 1;
    display: block;
}

.spiro-path {
    will-change: stroke-dashoffset;
}

.card-label {
    font-family: 'Space Grotesk', sans-serif;
    font-size: 13px;
    font-weight: 400;
    color: #5a5a7a;
    text-align: center;
    margin-top: 12px;
    letter-spacing: 0.05em;
}

/* ===== Algorithm Section ===== */
#algorithm {
    position: relative;
    z-index: 1;
    padding: 100px 5vw;
    max-width: 1000px;
    margin: 0 auto;
}

#algo-container {
    display: flex;
    gap: 40px;
    align-items: flex-start;
}

#algo-code {
    flex: 1;
    background: #ffffff;
    border: 1px solid #d4d0c8;
    padding: 24px;
    border-radius: 4px;
}

.code-line {
    font-family: 'Fira Code', monospace;
    font-size: 14px;
    font-weight: 400;
    color: #5a5a7a;
    line-height: 2;
    opacity: 0;
    transform: translateX(-8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    white-space: nowrap;
}

.code-line.visible {
    opacity: 1;
    transform: translateX(0);
}

.code-keyword {
    color: #2563eb;
}

.code-fn {
    color: #dc2626;
}

.code-string {
    color: #16a34a;
}

#algo-visual {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

#algo-output {
    width: 100%;
    max-width: 300px;
    aspect-ratio: 1;
    border: 1px solid #d4d0c8;
    background: #ffffff;
    padding: 16px;
}

#algo-spiro-path {
    will-change: stroke-dashoffset;
}

/* ===== Closing ===== */
#closing {
    position: relative;
    z-index: 1;
    padding: 120px 5vw;
    text-align: center;
}

.closing-text {
    font-family: 'Caveat', cursive;
    font-size: 32px;
    font-weight: 700;
    color: #1a1a2e;
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    .gallery-card {
        opacity: 1;
        transform: none;
        transition: none;
    }

    .code-line {
        opacity: 1;
        transform: none;
        transition: none;
    }

    #pen-nib {
        opacity: 1;
        transition: none;
    }

    #subtitle {
        opacity: 1;
        transition: none;
    }

    #dot-grid {
        opacity: 0.3;
        transition: none;
    }
}

/* ===== Responsive ===== */
@media (max-width: 1024px) {
    #gallery-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    #gallery-grid {
        grid-template-columns: 1fr;
        max-width: 400px;
    }

    #algo-container {
        flex-direction: column;
    }

    .section-title {
        font-size: 36px;
    }

    .closing-text {
        font-size: 24px;
    }

    #title-svg {
        width: 95%;
    }
}
