/* ==========================================================================
   bada.day — Hand-Drawn Glitch-Almanac Stylesheet
   ========================================================================== */

/* CSS Custom Properties — Honeyed-Neutral Palette */
:root {
    --parchment: #F5EDDF;
    --ink: #2B1D0E;
    --ink-secondary: #3D2C1E;
    --amber: #C4956A;
    --glitch-red: #E8432A;
    --glitch-cyan: #2AE8D4;
    --obsidian: #1A120B;
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */

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

html {
    scroll-snap-type: y proximity;
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    background-color: var(--parchment);
    color: var(--ink-secondary);
    font-family: 'Alegreya', Georgia, serif;
    font-weight: 400;
    font-size: 18px;
    line-height: 1.65;
    overflow-x: hidden;
    position: relative;
}

/* Scan-line overlay */
body::after {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    background: repeating-linear-gradient(
        to bottom,
        transparent 0px,
        transparent 1px,
        rgba(0, 0, 0, 0.03) 1px,
        rgba(0, 0, 0, 0.03) 2px
    );
}

/* ==========================================================================
   Title Cartouche Section (100vh)
   ========================================================================== */

.section--title {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    scroll-snap-align: start;
    position: relative;
    padding: 34px 16px;
}

.cartouche-svg {
    width: 100%;
    max-width: 600px;
    height: auto;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

/* Path drawing animation for cartouche */
.draw-path {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
}

.cartouche-frame .frame-outer {
    stroke-dasharray: 1800;
    stroke-dashoffset: 1800;
    animation: drawPath 3s ease-out 0.5s forwards;
}

.cartouche-frame .frame-inner {
    stroke-dasharray: 1600;
    stroke-dashoffset: 1600;
    animation: drawPath 2.8s ease-out 0.7s forwards;
}

.cartouche-frame .frame-line-top1,
.cartouche-frame .frame-line-top2 {
    stroke-dasharray: 440;
    stroke-dashoffset: 440;
    animation: drawPath 1.5s ease-out 1.2s forwards;
}

.cartouche-frame .frame-line-bot1,
.cartouche-frame .frame-line-bot2 {
    stroke-dasharray: 440;
    stroke-dashoffset: 440;
    animation: drawPath 1.5s ease-out 1.5s forwards;
}

.cartouche-frame .corner-star {
    opacity: 0;
    animation: fadeIn 0.4s ease-out 2.6s forwards;
}

.cartouche-frame .orbit-deco1,
.cartouche-frame .orbit-deco2 {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    animation: drawPath 2s ease-out 1.8s forwards;
}

@keyframes drawPath {
    to {
        stroke-dashoffset: 0;
    }
}

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

/* Title text */
.title-text {
    font-family: 'Alfa Slab One', serif;
    font-size: 72px;
    font-weight: 400;
    letter-spacing: 0.03em;
    color: var(--ink);
    position: relative;
    z-index: 2;
    opacity: 0;
    animation: titleFadeIn 800ms cubic-bezier(0.25, 0.1, 0.25, 1.0) 3s forwards;
}

.title-subtitle {
    font-family: 'Alegreya', Georgia, serif;
    font-style: italic;
    font-size: 20px;
    color: var(--amber);
    letter-spacing: 0.05em;
    position: relative;
    z-index: 2;
    opacity: 0;
    animation: titleFadeIn 800ms cubic-bezier(0.25, 0.1, 0.25, 1.0) 3.3s forwards;
    margin-top: 8px;
}

@keyframes titleFadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Title glitch event at 4s */
@keyframes titleGlitch {
    0% {
        transform: translateX(0);
        filter: none;
    }
    20% {
        transform: translateX(4px);
        filter: drop-shadow(3px 0 0 rgba(232, 67, 42, 0.5)) drop-shadow(-3px 0 0 rgba(42, 232, 212, 0.4));
    }
    100% {
        transform: translateX(0);
        filter: none;
    }
}

.title-glitch-active {
    animation: titleGlitch 200ms ease-in-out forwards;
}

/* ==========================================================================
   Glitch Tear Transitions
   ========================================================================== */

.glitch-tear {
    position: relative;
    height: 40px;
    overflow: hidden;
    background: var(--parchment);
    transform: translateX(-8px);
    filter: drop-shadow(3px 0 0 rgba(232, 67, 42, 0.5)) drop-shadow(-3px 0 0 rgba(42, 232, 212, 0.4));
    clip-path: polygon(
        0% 10%, 3% 0%, 8% 15%, 12% 5%, 18% 20%, 22% 0%, 28% 12%,
        33% 3%, 38% 18%, 42% 8%, 48% 22%, 52% 5%, 58% 15%, 62% 0%,
        68% 20%, 72% 8%, 78% 18%, 82% 3%, 88% 15%, 92% 0%, 96% 12%,
        100% 5%, 100% 95%, 97% 100%, 92% 88%, 88% 100%, 82% 90%,
        78% 100%, 72% 85%, 68% 100%, 62% 92%, 58% 100%, 52% 88%,
        48% 100%, 42% 90%, 38% 100%, 33% 85%, 28% 100%, 22% 92%,
        18% 100%, 12% 88%, 8% 100%, 3% 90%, 0% 100%
    );
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.tear-date {
    font-family: 'VT323', monospace;
    font-size: 14px;
    letter-spacing: 0.08em;
    color: var(--amber);
    white-space: nowrap;
    overflow: hidden;
    display: inline-block;
    width: 0;
    border-right: 2px solid var(--amber);
}

.tear-date.typing {
    animation: typewriter 400ms steps(20) forwards, blinkCursor 600ms step-end 2;
}

@keyframes typewriter {
    from {
        width: 0;
    }
    to {
        width: 100%;
    }
}

@keyframes blinkCursor {
    50% {
        border-color: transparent;
    }
}

/* ==========================================================================
   Almanac Sections
   ========================================================================== */

.section--almanac {
    position: relative;
    min-height: 85vh;
    scroll-snap-align: start;
    padding: 55px 16px;
    display: flex;
    justify-content: center;
}

.section-content {
    max-width: 720px;
    width: 100%;
    position: relative;
}

/* Section illustration */
.section-illustration {
    margin-bottom: 34px;
    display: flex;
    justify-content: center;
}

.almanac-svg {
    width: 100%;
    max-width: 300px;
    height: auto;
}

/* Almanac SVG draw animation */
.almanac-svg .draw-path {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    transition: stroke-dashoffset 1.5s ease-out;
}

.section--almanac.revealed .almanac-svg .draw-path {
    stroke-dashoffset: 0;
}

/* RGB glitch on illustrations */
@keyframes rgbGlitch {
    0% {
        filter: none;
    }
    10% {
        filter: drop-shadow(3px 0 0 rgba(232, 67, 42, 0.5)) drop-shadow(-3px 0 0 rgba(42, 232, 212, 0.4));
    }
    100% {
        filter: none;
    }
}

.section--almanac.glitch-flash .almanac-svg {
    animation: rgbGlitch 600ms ease-in-out forwards;
}

/* Section title */
.section-title {
    font-family: 'Alfa Slab One', serif;
    font-size: 56px;
    font-weight: 400;
    letter-spacing: 0.03em;
    color: var(--ink);
    text-transform: none;
    margin-bottom: 21px;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 600ms ease-out, transform 600ms ease-out;
}

.section--almanac.revealed .section-title {
    opacity: 1;
    transform: translateY(0);
}

/* Section body text */
.section-body p {
    font-family: 'Alegreya', Georgia, serif;
    font-size: 18px;
    font-weight: 400;
    line-height: 1.65;
    color: var(--ink-secondary);
    margin-bottom: 21px;
    opacity: 0;
    transform: translateY(15px);
    transition: opacity 500ms ease-out, transform 500ms ease-out;
}

.section--almanac.revealed .section-body p {
    opacity: 1;
    transform: translateY(0);
}

/* Stagger paragraphs */
.section--almanac.revealed .section-body p:nth-child(1) { transition-delay: 150ms; }
.section--almanac.revealed .section-body p:nth-child(2) { transition-delay: 300ms; }
.section--almanac.revealed .section-body p:nth-child(3) { transition-delay: 450ms; }
.section--almanac.revealed .section-body p:nth-child(4) { transition-delay: 600ms; }

/* Marginalia */
.marginalia {
    position: absolute;
    right: -60px;
    font-family: 'Alegreya', Georgia, serif;
    font-style: italic;
    font-size: 13px;
    color: var(--amber);
    writing-mode: vertical-rl;
    transform: rotate(180deg);
    letter-spacing: 0.02em;
    white-space: nowrap;
    opacity: 0;
    transition: opacity 400ms ease-out, transform 400ms ease-out;
}

.section--almanac.revealed .marginalia {
    opacity: 1;
}

/* ==========================================================================
   Margin Stars
   ========================================================================== */

.margin-star {
    position: absolute;
    width: 12px;
    height: 12px;
    z-index: 5;
}

.star-even {
    animation: celestial-spin 20s linear infinite;
}

.star-odd {
    animation: celestial-spin-reverse 20s linear infinite;
}

@keyframes celestial-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes celestial-spin-reverse {
    from { transform: rotate(0deg); }
    to { transform: rotate(-360deg); }
}

/* Stars near glitch tears flicker */
.glitch-tear + .section--almanac .margin-star:nth-child(odd) {
    animation: celestial-spin 20s linear infinite, glitch-flicker 4s step-end infinite;
}

@keyframes glitch-flicker {
    0% { opacity: 1; }
    25% { opacity: 0.6; }
    50% { opacity: 1; }
    75% { opacity: 0.6; }
    100% { opacity: 1; }
}

/* ==========================================================================
   Colophon Section
   ========================================================================== */

.section--colophon {
    min-height: 50vh;
    scroll-snap-align: start;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 55px 16px;
    background-color: var(--parchment);
    transition: background-color 1.2s ease-in-out, color 1.2s ease-in-out;
}

.section--colophon.inverted {
    background-color: var(--obsidian);
}

.colophon-content {
    max-width: 520px;
    text-align: center;
}

.colophon-starburst {
    width: 200px;
    height: 200px;
    margin: 0 auto 34px;
}

.colophon-starburst .draw-path {
    stroke-dasharray: 400;
    stroke-dashoffset: 400;
    transition: stroke-dashoffset 2s ease-out;
}

.section--colophon.inverted .colophon-starburst .draw-path {
    stroke-dashoffset: 0;
}

.colophon-observatory {
    font-family: 'Alfa Slab One', serif;
    font-size: 28px;
    font-weight: 400;
    letter-spacing: 0.03em;
    color: var(--ink);
    margin-bottom: 8px;
    transition: color 1.2s ease-in-out;
}

.section--colophon.inverted .colophon-observatory {
    color: var(--parchment);
}

.colophon-established {
    font-family: 'VT323', monospace;
    font-size: 16px;
    letter-spacing: 0.08em;
    color: var(--amber);
    margin-bottom: 21px;
}

.colophon-description {
    font-family: 'Alegreya', Georgia, serif;
    font-size: 16px;
    line-height: 1.6;
    color: var(--ink-secondary);
    margin-bottom: 21px;
    transition: color 1.2s ease-in-out;
}

.section--colophon.inverted .colophon-description {
    color: var(--parchment);
    opacity: 0.85;
}

.colophon-catalog {
    font-family: 'VT323', monospace;
    font-size: 14px;
    letter-spacing: 0.08em;
    color: var(--amber);
}

/* ==========================================================================
   Responsive — Mobile
   ========================================================================== */

@media (max-width: 768px) {
    body {
        font-size: 16px;
        line-height: 1.6;
    }

    .title-text {
        font-size: 42px;
    }

    .title-subtitle {
        font-size: 16px;
    }

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

    .section-body p {
        font-size: 16px;
        line-height: 1.6;
    }

    .section--almanac {
        padding: 34px 16px;
        min-height: auto;
    }

    .marginalia {
        position: relative;
        right: auto;
        writing-mode: horizontal-tb;
        transform: none;
        display: block;
        margin-top: 13px;
        font-size: 12px;
        text-align: right;
    }

    .colophon-observatory {
        font-size: 22px;
    }

    .colophon-description {
        font-size: 15px;
    }

    .margin-star {
        display: none;
    }

    .cartouche-svg {
        max-width: 90%;
    }
}

@media (max-width: 480px) {
    .title-text {
        font-size: 36px;
    }

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