/* talegrapher.com - Pop-Art Storytelling Atlas */
/* Palette: Sepia-Nostalgic with Pop-Art Punctuation */

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

:root {
    --aged-parchment: #f5edd4;
    --fresh-linen: #faf6eb;
    --dark-oak: #2d1b06;
    --warm-walnut: #4a3520;
    --aged-gold: #d4a060;
    --lichtenstein-red: #c62828;
    --comic-blue: #1565c0;
    --speech-yellow: #f9a825;
    --faded-leather: #8a6840;
    --dusty-amber: #c4a270;
    --library-midnight: #1a0f04;
    --burnt-sienna: #8a2e10;
    --page-margin: max(3rem, 8vw);
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--aged-parchment);
    color: var(--dark-oak);
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    line-height: 1.7;
    overflow-x: hidden;
}

/* ===== SVG Thread Layer ===== */
#thread-layer {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
}

/* ===== ACT I - The Blank Page ===== */
#act-one {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    position: relative;
    padding: var(--page-margin);
}

.blank-page-inner {
    width: 100%;
    max-width: 900px;
    position: relative;
    padding-top: 20vh;
}

#site-title {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: clamp(2rem, 6vw, 5rem);
    color: var(--dark-oak);
    text-shadow: 2px 2px 0 var(--aged-gold);
    letter-spacing: -0.02em;
    text-align: center;
    min-height: 1.2em;
}

#site-title .char {
    display: inline-block;
    opacity: 0;
    transform: translateY(-40px);
    animation: bounceIn 0.6s cubic-bezier(0.22, 1, 0.36, 1) forwards;
}

@keyframes bounceIn {
    0% {
        transform: translateY(-40px);
        opacity: 0;
    }
    60% {
        transform: translateY(6px);
        opacity: 1;
    }
    80% {
        transform: translateY(-3px);
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.horizontal-rule {
    width: 100%;
    height: 2px;
    background: var(--aged-gold);
    margin: 2rem auto;
    transform: scaleX(0);
    animation: ruleExpand 1.2s cubic-bezier(0.22, 1, 0.36, 1) 1s forwards;
}

@keyframes ruleExpand {
    to {
        transform: scaleX(1);
    }
}

.tagline {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    color: var(--burnt-sienna);
    text-align: center;
    opacity: 0;
    animation: fadeIn 0.8s ease 2s forwards;
}

@keyframes fadeIn {
    to {
        opacity: 1;
    }
}

/* ===== ACT II - Comic Panel Grid ===== */
#act-two {
    padding: 0 var(--page-margin);
    position: relative;
    z-index: 2;
}

.comic-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(2rem, 5vw, 6rem);
    max-width: 1200px;
    margin: 0 auto;
    padding-bottom: 10vh;
}

/* Panel base */
.panel {
    background: var(--fresh-linen);
    border: 4px solid var(--dark-oak);
    border-radius: 12px;
    padding: clamp(1.5rem, 3vw, 2.5rem);
    position: relative;
    box-shadow: 4px 4px 0px var(--dark-oak);
    overflow: hidden;
    opacity: 0;
    transition: transform 0.2s ease, border-color 0.2s ease;
}

.panel.is-visible {
    opacity: 1;
}

.panel:hover {
    transform: scale(1.015);
    border-color: var(--lichtenstein-red);
}

.panel:hover .ben-day-overlay {
    background-size: 4px 4px;
}

/* Panel sizes */
.panel-wide {
    grid-column: span 2;
}

.panel-tall {
    grid-row: span 2;
}

/* Empty panel slots */
.panel-empty {
    border: 2px dotted var(--dusty-amber);
    border-radius: 12px;
    opacity: 0.2;
    min-height: 100px;
}

/* Panel content layout */
.panel-content.panel-text-left,
.panel-content.panel-text-right {
    display: flex;
    gap: clamp(1rem, 2vw, 2rem);
    align-items: center;
}

.panel-content.panel-text-right {
    flex-direction: row;
}

.panel-content.panel-text-left .panel-text,
.panel-content.panel-text-right .panel-text {
    flex: 1;
}

.panel-content.panel-text-left .panel-illustration,
.panel-content.panel-text-right .panel-illustration {
    flex: 0 0 40%;
    max-width: 240px;
}

.panel-content.panel-vertical {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.panel-content.panel-vertical .panel-illustration {
    max-width: 200px;
    margin: 0 auto;
}

/* Panel typography */
.panel-title {
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: clamp(1.5rem, 4vw, 3.5rem);
    color: var(--dark-oak);
    text-shadow: 2px 2px 0 var(--aged-gold);
    margin-bottom: 0.5em;
    line-height: 1.2;
}

.panel-body {
    font-family: 'Nunito Sans', sans-serif;
    font-weight: 400;
    font-size: clamp(0.95rem, 1.8vw, 1.15rem);
    line-height: 1.7;
    color: var(--warm-walnut);
    max-width: 52ch;
    margin-bottom: 0.75em;
}

.panel-body:last-child {
    margin-bottom: 0;
}

/* Corner stamps */
.panel-corner-stamp {
    position: absolute;
    top: 8px;
    left: 8px;
    z-index: 3;
}

.panel-corner-stamp.stamp-right {
    left: auto;
    right: 8px;
}

/* Ben-Day dot overlay */
.ben-day-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: radial-gradient(circle, var(--dusty-amber) 1px, transparent 1px);
    background-size: 6px 6px;
    opacity: 0.12;
    pointer-events: none;
    transition: background-size 0.3s ease;
    z-index: 0;
}

/* SVG illustrations */
.panel-illustration svg {
    width: 100%;
    height: auto;
    display: block;
}

/* Annotations (tooltip words) */
.annotation {
    text-decoration: underline;
    text-decoration-style: wavy;
    text-decoration-color: var(--aged-gold);
    text-underline-offset: 3px;
    cursor: help;
    position: relative;
}

.annotation::after {
    content: attr(data-tooltip);
    position: absolute;
    bottom: calc(100% + 12px);
    left: 50%;
    transform: translateX(-50%) scale(0.9);
    background: var(--speech-yellow);
    color: var(--dark-oak);
    font-family: 'Nunito', sans-serif;
    font-weight: 800;
    font-size: 0.8rem;
    line-height: 1.4;
    padding: 0.6em 1em;
    border-radius: 8px;
    border: 2px solid var(--dark-oak);
    white-space: nowrap;
    max-width: 280px;
    white-space: normal;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 10;
    box-shadow: 2px 2px 0 var(--dark-oak);
}

.annotation::before {
    content: '';
    position: absolute;
    bottom: calc(100% + 4px);
    left: 50%;
    transform: translateX(-50%);
    border: 6px solid transparent;
    border-top-color: var(--dark-oak);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s ease;
    z-index: 11;
}

.annotation:hover::after {
    opacity: 1;
    transform: translateX(-50%) scale(1);
}

.annotation:hover::before {
    opacity: 1;
}

/* Code snippet */
.code-snippet {
    font-family: 'Cousine', monospace;
    font-size: 0.85rem;
    color: var(--faded-leather);
    background: rgba(245, 237, 212, 0.6);
    padding: 0.15em 0.5em;
    border-radius: 4px;
    border: 1px solid var(--dusty-amber);
}

/* Bounce animations for panels */
@keyframes bounceFromLeft {
    0% {
        transform: translateX(-30px);
        opacity: 0;
    }
    60% {
        transform: translateX(5px);
        opacity: 1;
    }
    80% {
        transform: translateX(-2px);
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes bounceFromRight {
    0% {
        transform: translateX(30px);
        opacity: 0;
    }
    60% {
        transform: translateX(-5px);
        opacity: 1;
    }
    80% {
        transform: translateX(2px);
    }
    100% {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes bounceFromBelow {
    0% {
        transform: translateY(30px);
        opacity: 0;
    }
    60% {
        transform: translateY(-5px);
        opacity: 1;
    }
    80% {
        transform: translateY(2px);
    }
    100% {
        transform: translateY(0);
        opacity: 1;
    }
}

.panel.bounce-left.is-visible {
    animation: bounceFromLeft 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.panel.bounce-right.is-visible {
    animation: bounceFromRight 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.panel.bounce-up.is-visible {
    animation: bounceFromBelow 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

/* ===== ACT III - Colophon ===== */
#act-three {
    min-height: 50vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--page-margin);
    position: relative;
}

.colophon-panel {
    position: relative;
    text-align: center;
    padding: clamp(3rem, 6vw, 6rem);
    opacity: 0;
}

.colophon-panel.is-visible {
    animation: bounceFromBelow 0.8s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.fin-border {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    pointer-events: none;
}

.fin-border-svg {
    width: 100%;
    height: 100%;
}

#fin-rect {
    animation: dashRotate 20s linear infinite;
}

@keyframes dashRotate {
    to {
        stroke-dashoffset: -240;
    }
}

.fin-text {
    font-family: 'Playfair Display', serif;
    font-style: italic;
    font-size: clamp(2rem, 5vw, 4rem);
    color: var(--burnt-sienna);
    margin-bottom: 0.5em;
}

.colophon-credits {
    font-family: 'Nunito Sans', sans-serif;
    font-size: 0.85rem;
    color: var(--faded-leather);
}

/* Scroll to top */
.scroll-to-top {
    margin-top: 3rem;
    cursor: pointer;
    animation: gentleBounce 2s ease-in-out infinite;
}

@keyframes gentleBounce {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
}

.scroll-to-top svg {
    display: block;
}

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

    .panel-wide {
        grid-column: span 2;
    }

    .panel-content.panel-text-left,
    .panel-content.panel-text-right {
        flex-direction: column;
    }

    .panel-content.panel-text-left .panel-illustration,
    .panel-content.panel-text-right .panel-illustration {
        max-width: 100%;
        flex: none;
    }

    .panel-empty:nth-child(3n) {
        display: none;
    }
}

@media (max-width: 600px) {
    .comic-grid {
        grid-template-columns: 1fr;
    }

    .panel-wide,
    .panel-tall {
        grid-column: span 1;
        grid-row: span 1;
    }

    .panel-empty {
        display: none;
    }

    .annotation::after {
        max-width: 200px;
        font-size: 0.7rem;
    }
}

/* ===== Reduced Motion ===== */
@media (prefers-reduced-motion: reduce) {
    #site-title .char {
        animation: none;
        opacity: 1;
        transform: none;
    }

    .horizontal-rule {
        animation: none;
        transform: scaleX(1);
    }

    .tagline {
        animation: none;
        opacity: 1;
    }

    .panel.bounce-left.is-visible,
    .panel.bounce-right.is-visible,
    .panel.bounce-up.is-visible,
    .colophon-panel.is-visible {
        animation: fadeIn 0.4s ease forwards;
    }

    .scroll-to-top {
        animation: none;
    }

    #fin-rect {
        animation: none;
    }
}