/* ========================================
   ppuzzle.org — Imperfect Puzzle Atelier
   ======================================== */

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

/* Fonts */
:root {
    --ground: #f5f0e8;
    --sumi: #2d2926;
    --graphite: #4a4540;
    --gold: #c9943e;
    --ochre: #b5651d;
    --sienna: #d4a76a;
    --kiln: #1e1b18;
    --soap: #e8d5b7;
    --bone: #c4b89a;
    --mid: #8b7355;
}

html {
    scroll-behavior: smooth;
}

body {
    background-color: var(--ground);
    color: var(--graphite);
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.72;
    overflow-x: hidden;
    position: relative;
}

/* Paper texture overlay */
body::after {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.04;
    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.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='256' height='256' filter='url(%23n)' opacity='1'/%3E%3C/svg%3E");
    background-repeat: repeat;
    background-size: 256px 256px;
}

/* ---- CRACK OVERLAY ---- */
#crack-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

#crack-svg {
    width: 100vw;
    height: 100vh;
}

#crack-svg path {
    filter: drop-shadow(0 0 4px rgba(201, 148, 62, 0.25));
}

.crack-drawn {
    stroke-dashoffset: 0 !important;
    transition: stroke-dashoffset 1.8s ease-out;
}

/* ---- HERO ---- */
#hero {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

.hero-title {
    font-family: 'Unbounded', sans-serif;
    font-weight: 900;
    font-size: clamp(3.5rem, 10vw, 8rem);
    letter-spacing: -0.04em;
    color: var(--sumi);
    opacity: 0;
    transition: opacity 0.6s ease;
}

.hero-title.visible {
    opacity: 1;
}

.hero-letter {
    display: inline-block;
    transform: rotate(var(--r, 0deg));
    opacity: 0;
    transition: opacity 0.5s ease;
}

.hero-letter.shown {
    opacity: 1;
}

.hero-subtitle {
    font-family: 'Caveat', cursive;
    font-size: clamp(1.2rem, 2vw, 2rem);
    color: var(--mid);
    opacity: 0;
    transition: opacity 0.6s ease;
    margin-top: 0.5rem;
}

.hero-subtitle.visible {
    opacity: 1;
}

/* ---- PUZZLE PIECES (decorative SVG) ---- */
.puzzle-piece {
    position: absolute;
    pointer-events: none;
    opacity: 0.6;
}

.puzzle-piece path {
    stroke-dasharray: 800;
    stroke-dashoffset: 800;
    transition: stroke-dashoffset 1.5s ease-out;
}

.puzzle-piece.drawn path {
    stroke-dashoffset: 160; /* stop at ~80% */
}

.piece-hero {
    width: 200px;
    height: 200px;
    bottom: 15%;
    right: 10%;
}

.piece-section1 {
    width: 250px;
    height: 250px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.piece-section2 {
    width: 220px;
    height: 220px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.piece-section3 {
    width: 240px;
    height: 240px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.piece-closing {
    width: 300px;
    height: 300px;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0.3;
}

/* ---- Z-SECTIONS ---- */
.z-section {
    min-height: 100vh;
    position: relative;
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    padding: 4rem 5vw;
    gap: 2rem;
}

.z-quad {
    display: flex;
    align-items: flex-start;
    justify-content: flex-start;
    position: relative;
    padding: 2rem;
}

.z-tl { align-items: flex-start; justify-content: flex-start; }
.z-tr { align-items: flex-start; justify-content: flex-end; }
.z-bl { align-items: flex-end; justify-content: flex-start; }
.z-br { align-items: flex-end; justify-content: flex-end; }

.z-content {
    opacity: 0;
    transform: translateX(-30px);
    transition: opacity 0.6s ease, transform 0.6s ease, filter 0.6s ease;
    filter: blur(8px);
    max-width: 500px;
}

.z-tr .z-content { transform: translateX(30px); }
.z-bl .z-content { transform: translateX(-30px); }
.z-br .z-content { transform: translateX(30px); }

.z-content.revealed {
    opacity: 1;
    transform: translateX(0);
    filter: blur(0);
}

/* Skeleton shapes */
.skeleton-shape {
    position: absolute;
    inset: 2rem;
    clip-path: polygon(5% 0%, 95% 3%, 100% 92%, 8% 100%, 0% 60%);
    background: linear-gradient(90deg, var(--ground) 25%, var(--soap) 50%, var(--ground) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.5s infinite;
    pointer-events: none;
    z-index: 0;
}

.skeleton-shape.hidden {
    opacity: 0;
    transition: opacity 0.4s ease;
}

@keyframes shimmer {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* ---- TYPOGRAPHY ---- */
.display-heading {
    font-family: 'Unbounded', sans-serif;
    font-weight: 900;
    font-size: clamp(2.5rem, 6vw, 5rem);
    letter-spacing: -0.04em;
    color: var(--sumi);
    line-height: 1.05;
    margin-bottom: 1.5rem;
}

.display-heading em {
    font-style: normal;
    color: var(--gold);
}

.heading-light {
    color: var(--ground);
}

.heading-light em {
    color: var(--gold);
}

.body-text {
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.72;
    color: var(--graphite);
    max-width: 38ch;
}

.text-light {
    color: var(--soap);
}

.accent-text {
    font-family: 'Caveat', cursive;
    color: var(--mid);
}

/* ---- MISSING PIECE ---- */
.missing-piece {
    width: 180px;
    height: 180px;
    border: 1px dashed var(--bone);
    clip-path: polygon(10% 0%, 40% 0%, 45% 10%, 55% 10%, 60% 0%, 90% 0%, 100% 40%, 90% 45%, 90% 55%, 100% 60%, 100% 100%, 0% 100%, 0% 60%, 10% 55%, 10% 45%, 0% 40%);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 1s ease;
    position: relative;
}

.missing-piece.visible {
    opacity: 1;
}

.missing-label {
    font-family: 'Caveat', cursive;
    font-size: clamp(0.85rem, 1.4vw, 1.1rem);
    color: var(--mid);
    text-align: center;
    /* Reset clip-path on label so text is visible */
}

.missing-piece-dark {
    border-color: var(--gold);
}

.missing-label-dark {
    color: var(--gold);
}

/* ---- MIXED MEDIA FRAGMENTS ---- */
.mixed-media-fragment {
    background: rgba(212, 167, 106, 0.2);
    padding: 2rem;
    position: relative;
    clip-path: polygon(3% 0%, 97% 2%, 100% 95%, 5% 100%);
    box-shadow: 4px 8px 20px rgba(201, 148, 62, 0.15);
    max-width: 300px;
}

.fragment-dark {
    background: rgba(201, 148, 62, 0.15);
}

.fragment-drawing {
    width: 120px;
    height: 120px;
    display: block;
    margin: 0 auto 1rem;
}

.fragment-text {
    font-family: 'Caveat', cursive;
    font-size: 1.2rem;
    color: var(--mid);
    display: block;
    text-align: center;
    transform: rotate(-2deg);
}

.fragment-dark .fragment-text {
    color: var(--gold);
}

/* ---- CRACK SEAMS ---- */
.crack-seam {
    width: 100%;
    height: 20px;
    position: relative;
    overflow: visible;
}

.crack-seam svg {
    width: 100%;
    height: 20px;
    display: block;
}

.seam-path {
    filter: drop-shadow(0 0 4px rgba(201, 148, 62, 0.25));
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 1.2s ease-out;
}

.seam-path.drawn {
    stroke-dashoffset: 0;
}

/* ---- DARK SECTION ---- */
.z-section-dark {
    background-color: var(--kiln);
    transition: background-color 0.8s ease;
}

.z-section-dark .skeleton-shape {
    background: linear-gradient(90deg, var(--kiln) 25%, #3a3530 50%, var(--kiln) 75%);
    background-size: 200% 100%;
}

.z-section-dark .bubble {
    border-color: var(--gold);
    color: var(--gold);
    box-shadow: 0 0 8px rgba(201, 148, 62, 0.35);
}

/* ---- BUBBLES ---- */
.bubble-cluster {
    position: absolute;
    bottom: 5%;
    left: 50%;
    transform: translateX(-50%);
    width: 300px;
    height: 200px;
    pointer-events: none;
    z-index: 5;
}

.bubble {
    position: absolute;
    width: var(--size, 40px);
    height: var(--size, 40px);
    border-radius: 50%;
    border: 1px solid var(--soap);
    background: rgba(232, 213, 183, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: 'Source Serif 4', Georgia, serif;
    font-size: calc(var(--size, 40px) * 0.4);
    color: var(--mid);
    pointer-events: auto;
    cursor: pointer;
    bottom: 0;
    left: calc(50% + var(--drift, 0px));
    animation: bubbleFloat var(--dur, 8s) var(--delay, 0s) infinite ease-in-out;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1), border-color 0.3s ease;
}

.bubble:hover {
    transform: scale(1.3);
    border-color: var(--gold);
}

.bubble.popped {
    animation: bubblePop 0.5s forwards;
    pointer-events: none;
}

@keyframes bubbleFloat {
    0% {
        transform: translateY(0) translateX(0);
        opacity: 0.8;
    }
    50% {
        transform: translateY(calc(var(--size, 40px) * -1.5)) translateX(calc(var(--drift, 0px) * 0.5));
        opacity: 1;
    }
    100% {
        transform: translateY(calc(var(--size, 40px) * -3)) translateX(0);
        opacity: 0;
    }
}

@keyframes bubblePop {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.5);
        opacity: 0.5;
        border-width: 3px;
    }
    100% {
        transform: scale(2);
        opacity: 0;
    }
}

/* ---- CLOSING SECTION ---- */
#section-closing {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    min-height: 100vh;
}

.closing-content {
    position: relative;
    z-index: 2;
    opacity: 0;
    transform: translateY(30px);
    transition: opacity 1s ease, transform 1s ease;
}

.closing-content.revealed {
    opacity: 1;
    transform: translateY(0);
}

.closing-text {
    max-width: 50ch;
    margin: 2rem auto;
    font-size: clamp(1.1rem, 1.5vw, 1.3rem);
}

.closing-annotation {
    font-family: 'Caveat', cursive;
    font-size: 1.3rem;
    color: var(--gold);
    margin-top: 2rem;
}

/* ---- RADIAL NAV ---- */
#radial-nav {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 100;
}

#nav-puzzle-icon {
    width: 48px;
    height: 48px;
    cursor: pointer;
    animation: navSpin 30s linear infinite;
    transform-origin: 52% 50%;
}

#nav-puzzle-icon svg {
    width: 100%;
    height: 100%;
}

@keyframes navSpin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

#nav-menu {
    position: absolute;
    bottom: 60px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    align-items: flex-end;
    transition: opacity 0.3s ease, transform 0.3s ease;
}

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

.nav-link {
    font-family: 'Caveat', cursive;
    font-size: 1.1rem;
    color: var(--gold);
    text-decoration: none;
    background: rgba(245, 240, 232, 0.9);
    padding: 0.3rem 0.8rem;
    border-radius: 4px;
    transition: color 0.2s ease, background 0.2s ease;
    white-space: nowrap;
}

.nav-link:hover {
    color: var(--ochre);
    background: rgba(245, 240, 232, 1);
}

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
    .z-section {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
        padding: 2rem 4vw;
    }

    .z-quad {
        justify-content: center !important;
    }

    .bubble-cluster {
        width: 200px;
    }

    .display-heading {
        font-size: clamp(2rem, 8vw, 3.5rem);
    }

    .piece-hero,
    .piece-section1,
    .piece-section2,
    .piece-section3 {
        width: 120px;
        height: 120px;
    }
}
