/* ============================================
   GGOGGL.com - Wabi-Sabi Celestial Observatory
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --primary-terracotta: #C45B3B;
    --secondary-terracotta: #D4845A;
    --dark-ground: #3B2316;
    --warm-bg: #F5EDE3;
    --light-surface: #FAF6F0;
    --celestial-gold: #E8C668;
    --celestial-copper: #B87D4B;
    --night-sky: #1F1209;
    --text-primary: #2E1E12;
    --text-secondary: #7A5C4A;
    --highlight: #D98B7A;
    --warm-shadow: rgba(59, 35, 22, 0.15);
    --warm-shadow-hover: rgba(196, 91, 59, 0.2);
}

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

html {
    scroll-behavior: smooth;
    overflow-x: hidden;
}

body {
    font-family: 'Lora', Georgia, serif;
    font-weight: 400;
    color: var(--text-primary);
    background-color: var(--warm-bg);
    line-height: 1.7;
    overflow-x: hidden;
}

/* Paper grain texture overlay on body */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.035;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='300' height='300'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='300' height='300' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
}

/* --- Typography --- */
h1, h2 {
    font-family: 'Caveat', cursive;
    font-weight: 700;
    color: var(--text-primary);
}

h3 {
    font-family: 'Patrick Hand', cursive;
    font-weight: 400;
    color: var(--text-primary);
}

.annotation-text {
    font-family: 'Caveat Brush', cursive;
    color: var(--text-secondary);
}

/* --- Navigation --- */
#nav-goggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
}

#nav-toggle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: 2px solid var(--primary-terracotta);
    background: var(--light-surface);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease, box-shadow 0.3s ease, background-color 0.3s ease;
    box-shadow: 0 4px 12px var(--warm-shadow);
}

#nav-toggle:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 20px var(--warm-shadow-hover);
    background-color: #FFF8F2;
}

#nav-menu {
    position: absolute;
    top: 64px;
    right: 0;
    background: var(--light-surface);
    border: 1.5px solid var(--secondary-terracotta);
    border-radius: 12px;
    padding: 16px 24px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    box-shadow: 0 8px 24px var(--warm-shadow);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

#nav-menu a {
    font-family: 'Patrick Hand', cursive;
    font-size: 1.15rem;
    color: var(--text-primary);
    text-decoration: none;
    transition: color 0.2s ease;
    white-space: nowrap;
}

#nav-menu a:hover {
    color: var(--primary-terracotta);
}

.nav-menu-hidden {
    opacity: 0;
    transform: translateY(-10px) scale(0.95);
    pointer-events: none;
}

.nav-menu-visible {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

/* --- ACT 1: Opening Vista --- */
.opening-vista {
    position: relative;
    width: 100%;
    height: 200vh;
    background: var(--night-sky);
    overflow: hidden;
}

#star-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

.opening-content {
    position: sticky;
    top: 0;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 2;
    pointer-events: none;
}

.title-main {
    font-size: clamp(2.5rem, 8vw, 6rem);
    letter-spacing: 0.15em;
    color: var(--light-surface);
    text-shadow: 0 0 40px rgba(232, 198, 104, 0.3);
    display: flex;
    gap: 0.05em;
}

.title-main .letter {
    display: inline-block;
    opacity: 0;
    transform: translateY(20px);
    animation: letterBounceIn 0.6s ease forwards;
}

.title-main .letter[data-index="0"] { animation-delay: 0.3s; }
.title-main .letter[data-index="1"] { animation-delay: 0.5s; }
.title-main .letter[data-index="2"] { animation-delay: 0.7s; }
.title-main .letter[data-index="3"] { animation-delay: 0.9s; }
.title-main .letter[data-index="4"] { animation-delay: 1.1s; }
.title-main .letter[data-index="5"] { animation-delay: 1.3s; }

@keyframes letterBounceIn {
    0% {
        opacity: 0;
        transform: translateY(20px) rotate(-3deg);
    }
    60% {
        opacity: 1;
        transform: translateY(-5px) rotate(1deg);
    }
    80% {
        transform: translateY(3px) rotate(-0.5deg);
    }
    100% {
        opacity: 1;
        transform: translateY(0) rotate(0deg);
    }
}

/* Goggle-O styling */
.goggle-o {
    position: relative;
}

.goggle-o::before,
.goggle-o::after {
    content: '';
    position: absolute;
    border: 2px solid var(--celestial-gold);
    border-radius: 50%;
    opacity: 0.4;
    pointer-events: none;
}

.goggle-o::before {
    width: 110%;
    height: 110%;
    top: -5%;
    left: -5%;
}

.goggle-o::after {
    width: 130%;
    height: 130%;
    top: -15%;
    left: 20%;
}

.subtitle {
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    color: var(--secondary-terracotta);
    margin-top: 1rem;
    opacity: 0;
    animation: fadeIn 1s ease 2s forwards;
    transform: rotate(-1deg);
}

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

.horizon-silhouette {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 20vh;
    background: linear-gradient(to top, var(--primary-terracotta), transparent);
    clip-path: polygon(
        0% 100%,
        0% 70%,
        5% 65%,
        10% 68%,
        15% 55%,
        20% 58%,
        25% 45%,
        30% 50%,
        35% 40%,
        40% 42%,
        45% 35%,
        50% 38%,
        55% 32%,
        60% 36%,
        65% 28%,
        70% 34%,
        75% 30%,
        80% 38%,
        85% 42%,
        90% 36%,
        95% 50%,
        100% 45%,
        100% 100%
    );
    z-index: 1;
    opacity: 0.85;
}

/* --- ACT 2: Transition Zone --- */
.transition-zone {
    position: relative;
    min-height: 60vh;
    background: linear-gradient(to bottom, var(--dark-ground), var(--warm-bg));
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.star-band {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 120px;
    overflow: hidden;
}

#band-canvas {
    width: 100%;
    height: 100%;
}

.transition-text-wrapper {
    position: relative;
    z-index: 2;
    padding: 4rem 2rem;
}

.handwritten-reveal {
    font-family: 'Caveat', cursive;
    font-size: clamp(1.8rem, 4vw, 3rem);
    color: var(--light-surface);
    opacity: 0;
    transform: translateY(1px);
    transition: opacity 1.2s ease, transform 1.2s ease;
    letter-spacing: 0.05em;
}

.handwritten-reveal.revealed {
    opacity: 1;
    transform: translateY(0);
}

/* Typewriter clip effect */
.handwritten-reveal.typing {
    display: inline-block;
    clip-path: inset(0 100% 0 0);
    animation: typeReveal 1.5s steps(14, end) forwards, wobbleWrite 1.5s ease-in-out forwards;
}

@keyframes typeReveal {
    to { clip-path: inset(0 0 0 0); }
}

@keyframes wobbleWrite {
    0%, 100% { transform: translateY(0); }
    10% { transform: translateY(-1px); }
    30% { transform: translateY(2px); }
    50% { transform: translateY(-1.5px); }
    70% { transform: translateY(1px); }
    90% { transform: translateY(-0.5px); }
}

/* --- ACT 3: Card Constellation --- */
.card-constellation {
    position: relative;
    padding: 4rem 2rem 2rem;
    background: var(--warm-bg);
    min-height: 100vh;
}

.section-intro {
    text-align: center;
    margin-bottom: 3rem;
    padding-top: 2rem;
}

.section-heading {
    font-size: clamp(2rem, 5vw, 4.5rem);
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.crescent-separator {
    display: flex;
    justify-content: center;
    opacity: 0.7;
}

/* Card Grid */
.card-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: clamp(16px, 3vw, 40px);
    max-width: 1200px;
    margin: 0 auto 4rem;
    padding: 1rem;
}

@media (max-width: 900px) {
    .card-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

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

/* Observation Cards */
.obs-card {
    position: relative;
    background: var(--light-surface);
    border-radius: 12px;
    padding: 2rem 1.8rem 2.5rem;
    transform: rotate(var(--rotation, 0deg));
    box-shadow:
        4px 6px 16px var(--warm-shadow),
        -1px -1px 4px rgba(250, 246, 240, 0.3);
    transition: transform 0.3s ease-out, box-shadow 0.3s ease;
    will-change: transform;
    cursor: default;
    /* Wavy border via clip-path */
    clip-path: polygon(
        1% 2%, 3% 0%, 8% 1%, 15% 0%, 22% 1%, 30% 0%, 38% 0.5%, 45% 0%, 52% 1%, 60% 0%, 68% 0.5%, 75% 0%, 82% 1%, 90% 0%, 96% 0.5%, 99% 1%,
        100% 5%, 99.5% 12%, 100% 20%, 99.5% 28%, 100% 36%, 99.5% 44%, 100% 52%, 99.5% 60%, 100% 68%, 99.5% 76%, 100% 84%, 99.5% 92%, 100% 98%,
        98% 100%, 92% 99.5%, 85% 100%, 78% 99.5%, 70% 100%, 62% 99.5%, 55% 100%, 48% 99.5%, 40% 100%, 32% 99.5%, 25% 100%, 18% 99.5%, 10% 100%, 4% 99.5%, 0% 99%,
        0.5% 94%, 0% 86%, 0.5% 78%, 0% 70%, 0.5% 62%, 0% 54%, 0.5% 46%, 0% 38%, 0.5% 30%, 0% 22%, 0.5% 14%, 0% 6%
    );
    /* Card entrance animation */
    opacity: 0;
    transform: rotate(var(--rotation, 0deg)) translateY(40px);
}

.obs-card.card-visible {
    opacity: 1;
    transform: rotate(var(--rotation, 0deg)) translateY(0);
    transition: opacity 0.6s ease calc(var(--i) * 120ms),
                transform 0.6s ease calc(var(--i) * 120ms),
                box-shadow 0.3s ease;
}

.obs-card:hover {
    box-shadow:
        0 20px 40px var(--warm-shadow-hover),
        -1px -1px 4px rgba(250, 246, 240, 0.3);
}

.card-star-corner {
    position: absolute;
    opacity: 0.7;
}

.card-star-corner.top-left { top: 8px; left: 8px; }
.card-star-corner.top-right { top: 8px; right: 8px; }
.card-star-corner.bottom-left { bottom: 8px; left: 8px; }
.card-star-corner.bottom-right { bottom: 8px; right: 8px; }

.card-title {
    font-size: 1.35rem;
    margin-bottom: 0.75rem;
    color: var(--primary-terracotta);
}

.card-body {
    font-size: 0.95rem;
    line-height: 1.75;
    color: var(--text-primary);
    margin-bottom: 1.2rem;
}

.card-annotation {
    font-family: 'Caveat Brush', cursive;
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: inline-block;
    transform: rotate(-1.5deg);
    opacity: 0.75;
}

/* --- Star Break (Interstitial) --- */
.star-break {
    position: relative;
    width: 100%;
    height: 160px;
    background: var(--dark-ground);
    margin: 3rem 0;
    border-radius: 4px;
    overflow: hidden;
}

.star-break canvas {
    width: 100%;
    height: 100%;
}

/* --- ACT 4: Closing Meditation --- */
.closing-meditation {
    position: relative;
    min-height: 100vh;
    background: var(--night-sky);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    overflow: hidden;
}

#closing-star-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
}

.mandala-card {
    position: relative;
    z-index: 2;
    background: rgba(250, 246, 240, 0.05);
    border: 1px solid rgba(212, 132, 90, 0.25);
    border-radius: 16px;
    padding: 3rem;
    width: min(90vw, 440px);
    height: min(90vw, 440px);
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 60px rgba(196, 91, 59, 0.1);
}

#mandala-svg {
    width: 100%;
    height: 100%;
}

.closing-message {
    position: relative;
    z-index: 2;
    font-size: clamp(1.2rem, 3vw, 2rem);
    color: var(--secondary-terracotta);
    margin-top: 2.5rem;
    opacity: 0;
    transform: rotate(-1deg);
    transition: opacity 1.5s ease;
}

.closing-message.visible {
    opacity: 1;
}

/* --- Constellation Overlay --- */
.constellation-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.5s ease;
}

.constellation-overlay.active {
    opacity: 1;
}

.constellation-overlay line {
    stroke: var(--secondary-terracotta);
    stroke-opacity: 0.3;
    stroke-width: 0.5;
    stroke-dasharray: var(--line-length, 100);
    stroke-dashoffset: var(--line-length, 100);
    transition: stroke-dashoffset 2s ease-in-out;
}

.constellation-overlay line.drawn {
    stroke-dashoffset: 0;
}

/* --- Star click ripple --- */
.star-ripple {
    position: absolute;
    border-radius: 50%;
    border: 1px solid var(--celestial-gold);
    opacity: 0;
    pointer-events: none;
    animation: rippleExpand 0.8s ease-out forwards;
    z-index: 3;
}

@keyframes rippleExpand {
    0% {
        width: 0;
        height: 0;
        opacity: 0.8;
        transform: translate(-50%, -50%);
    }
    100% {
        width: 80px;
        height: 80px;
        opacity: 0;
        transform: translate(-50%, -50%);
    }
}

/* Star label on click */
.star-label {
    position: absolute;
    font-family: 'Caveat Brush', cursive;
    font-size: 0.8rem;
    color: var(--celestial-gold);
    pointer-events: none;
    opacity: 0;
    transform: translate(-50%, -130%) rotate(-2deg);
    animation: labelAppear 2s ease forwards;
    z-index: 3;
    white-space: nowrap;
}

@keyframes labelAppear {
    0% { opacity: 0; transform: translate(-50%, -110%) rotate(-2deg); }
    15% { opacity: 1; transform: translate(-50%, -130%) rotate(-2deg); }
    80% { opacity: 1; transform: translate(-50%, -130%) rotate(-2deg); }
    100% { opacity: 0; transform: translate(-50%, -140%) rotate(-2deg); }
}

/* --- Scroll-driven background transition for opening --- */
.opening-vista {
    transition: background-color 0.3s ease;
}

/* --- Responsive adjustments --- */
@media (max-width: 560px) {
    .opening-content {
        padding: 0 1rem;
    }

    .title-main {
        letter-spacing: 0.08em;
    }

    .mandala-card {
        padding: 1.5rem;
    }

    #nav-goggle {
        top: 12px;
        right: 12px;
    }

    #nav-toggle {
        width: 48px;
        height: 48px;
    }

    .obs-card {
        padding: 1.5rem 1.3rem 2rem;
    }
}

/* --- Selection color --- */
::selection {
    background: var(--highlight);
    color: var(--night-sky);
}
