/* ============================================
   mystical.boo - Wabi-Sabi Technomancer's Sketchbook
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --bg-primary: #EAECEE;
    --bg-alt: #D6D9DC;
    --text-primary: #2C2F33;
    --text-secondary: #5A5E63;
    --accent-cool: #7B8A98;
    --accent-warm: #A3897A;
    --accent-warm-light: #C4A99A;
    --divider: #B5B9BD;
    --hover: #4A5568;
    --font-display: 'Libre Baskerville', Georgia, serif;
    --font-body: 'Libre Baskerville', Georgia, serif;
    --font-annotation: 'Caveat', cursive;
    --grid-gap: clamp(1rem, 2.5vw, 2rem);
}

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

html {
    scroll-behavior: smooth;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.1vw, 1.15rem);
    line-height: 1.75;
    letter-spacing: 0.005em;
    color: var(--text-primary);
    background-color: var(--bg-primary);
    overflow-x: hidden;
    position: relative;
}

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

/* --- Grain Overlay --- */
.grain-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 9999;
    opacity: 0.03;
    filter: url(#grain);
    background: var(--bg-primary);
}

/* --- Parallax Layers --- */
.parallax-bg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 0;
    will-change: transform;
}

.watermark {
    position: absolute;
    opacity: 0.04;
}

.watermark-circuit {
    width: 400px;
    height: 400px;
    top: 10%;
    right: 5%;
}

.watermark-topo {
    width: 300px;
    height: 300px;
    bottom: 15%;
    left: 8%;
}

.parallax-fg {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 100;
    will-change: transform;
}

.doodle {
    position: absolute;
    opacity: 0.15;
}

.doodle-spiral {
    width: 40px;
    height: 40px;
    top: 20%;
    left: 5%;
}

.doodle-constellation {
    width: 60px;
    height: 60px;
    top: 55%;
    right: 8%;
}

.doodle-leaf {
    width: 30px;
    height: 30px;
    bottom: 20%;
    left: 12%;
}

/* --- Navigation Compass --- */
.compass-nav {
    position: fixed;
    top: 1.5rem;
    right: 1.5rem;
    z-index: 1000;
}

.compass-btn {
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.compass-icon {
    width: 40px;
    height: 40px;
    transition: transform 0.3s ease;
}

.compass-btn:hover .compass-icon {
    animation: compass-wobble 0.8s ease-in-out infinite;
}

.compass-needle {
    transform-origin: 20px 20px;
}

@keyframes compass-wobble {
    0%, 100% { transform: rotate(-3deg); }
    50% { transform: rotate(3deg); }
}

.compass-menu {
    position: absolute;
    top: 50px;
    right: 0;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    background: var(--bg-primary);
    padding: 1rem 1.25rem;
    border: 1px solid var(--divider);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-8px);
    transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s ease;
}

.compass-menu.is-open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.compass-link {
    font-family: var(--font-annotation);
    font-size: 1.1rem;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 0.2s ease;
    white-space: nowrap;
}

.compass-link:hover {
    color: var(--hover);
}

/* --- Hero Section --- */
.hero {
    width: 100%;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-alt);
    position: relative;
    z-index: 1;
}

.hero-content {
    transform: translate(-15%, -10%);
    text-align: left;
}

.hero-title-svg {
    width: clamp(320px, 60vw, 800px);
    height: auto;
    overflow: visible;
}

.hero-title-text {
    font-family: var(--font-display);
    font-size: 96px;
    font-weight: 700;
    letter-spacing: -0.01em;
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    animation: draw-title 2.5s ease forwards 0.4s;
}

.hero-title-fill {
    font-family: var(--font-display);
    font-size: 96px;
    font-weight: 700;
    letter-spacing: -0.01em;
    opacity: 0;
    animation: fill-title 0.8s ease forwards 2.9s;
}

@keyframes draw-title {
    to {
        stroke-dashoffset: 0;
    }
}

@keyframes fill-title {
    to {
        opacity: 1;
    }
}

.hero-underline {
    width: 200px;
    margin-top: 0.5rem;
}

.hero-underline svg {
    width: 100%;
    height: auto;
}

.breath-line {
    stroke-dasharray: 210;
    stroke-dashoffset: 210;
    animation: draw-underline 1s ease forwards 3.2s;
}

@keyframes draw-underline {
    to {
        stroke-dashoffset: 0;
    }
}

.hero-subtitle {
    font-family: var(--font-annotation);
    font-size: clamp(0.9rem, 1vw, 1.1rem);
    color: var(--text-secondary);
    margin-top: 1rem;
    opacity: 0;
    animation: fade-in-subtitle 0.8s ease forwards 3.7s;
}

@keyframes fade-in-subtitle {
    to {
        opacity: 1;
    }
}

/* --- Sections --- */
.section {
    position: relative;
    z-index: 1;
    padding: clamp(3rem, 6vw, 6rem) clamp(1.5rem, 4vw, 4rem);
    max-width: 1400px;
    margin: 0 auto;
}

.section-divider {
    width: 100%;
    margin-bottom: 1.5rem;
}

.divider-line {
    width: 100%;
    height: auto;
}

.divider-line path {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
}

.divider-line.is-drawn path {
    animation: draw-divider 1s ease forwards;
}

@keyframes draw-divider {
    to {
        stroke-dashoffset: 0;
    }
}

.section-heading {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.4rem, 3vw, 2.2rem);
    letter-spacing: -0.01em;
    line-height: 1.15;
    color: var(--text-primary);
    margin-bottom: clamp(1.5rem, 3vw, 3rem);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.section-heading.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.section-heading-offset {
    padding-left: 2rem;
}

/* --- Portfolio Grid (Sketches) --- */
.portfolio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: var(--grid-gap);
}

/* --- Cards --- */
.card {
    grid-row: span 1;
    position: relative;
    opacity: 0;
    transform: translateY(24px) rotate(-1.5deg);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.card.is-visible {
    opacity: 1;
    transform: translateY(0) rotate(0deg);
}

.card:nth-child(1) { --entry-rotation: -1.5deg; }
.card:nth-child(2) { --entry-rotation: 0.8deg; }
.card:nth-child(3) { --entry-rotation: -2deg; }
.card:nth-child(4) { --entry-rotation: 1.2deg; }
.card:nth-child(5) { --entry-rotation: -0.5deg; }
.card:nth-child(6) { --entry-rotation: 1.5deg; }

.card {
    transform: translateY(24px) rotate(var(--entry-rotation, -1.5deg));
}

.card.is-visible {
    transform: translateY(0) rotate(0deg);
}

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

.card-extra-tall {
    grid-row: span 3;
}

.card-inner {
    background: var(--bg-primary);
    border: 1px solid var(--divider);
    padding: clamp(1.25rem, 2vw, 2rem);
    height: 100%;
    position: relative;
    clip-path: polygon(
        0% 0%,
        100% 0%,
        100% calc(100% - 12px),
        calc(100% - 3px) calc(100% - 8px),
        calc(100% - 8px) calc(100% - 3px),
        calc(100% - 12px) calc(100% - 6px),
        calc(100% - 18px) 100%,
        calc(100% - 24px) calc(100% - 4px),
        calc(100% - 30px) calc(100% - 1px),
        calc(100% - 36px) calc(100% - 5px),
        calc(100% - 42px) 100%,
        0% 100%
    );
    transition: box-shadow 0.3s ease, clip-path 0.3s ease;
}

.card-inner:hover {
    box-shadow: 0 4px 20px rgba(44, 47, 51, 0.08);
    clip-path: polygon(
        0% 0%,
        100% 0%,
        100% calc(100% - 14px),
        calc(100% - 3px) calc(100% - 10px),
        calc(100% - 8px) calc(100% - 5px),
        calc(100% - 12px) calc(100% - 8px),
        calc(100% - 18px) calc(100% - 2px),
        calc(100% - 24px) calc(100% - 6px),
        calc(100% - 30px) calc(100% - 3px),
        calc(100% - 36px) calc(100% - 7px),
        calc(100% - 42px) calc(100% - 2px),
        0% 100%
    );
}

/* Kintsugi crack overlay */
.card-kintsugi {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 2;
}

.card-kintsugi svg {
    width: 100%;
    height: 100%;
}

.kintsugi-line {
    transition: stroke 0.3s ease;
}

.card-inner:hover .kintsugi-line {
    stroke: var(--accent-warm-light);
}

.card-sketch {
    width: 100%;
    height: auto;
    margin-bottom: 1rem;
    display: block;
}

.card-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.1rem, 1.5vw, 1.3rem);
    letter-spacing: -0.01em;
    line-height: 1.15;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.card-body {
    font-family: var(--font-body);
    font-size: clamp(0.9rem, 1vw, 1rem);
    line-height: 1.75;
    color: var(--text-secondary);
    max-width: 38em;
}

.card-leaf {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    width: 20px;
    height: 20px;
    opacity: 0.4;
}

/* --- Marginalia Grid --- */
.marginalia-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: var(--grid-gap);
}

.margin-note {
    background: transparent;
    padding: clamp(1rem, 1.5vw, 1.5rem);
    position: relative;
    border-left: 2px solid var(--divider);
    opacity: 0;
    transform: translateY(16px);
    transition: opacity 0.5s ease-out, transform 0.5s ease-out;
}

.margin-note.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.margin-note-wide {
    grid-column: span 2;
}

.margin-text {
    font-family: var(--font-annotation);
    font-size: clamp(0.9rem, 1vw, 1.1rem);
    color: var(--text-secondary);
    line-height: 1.6;
}

.margin-doodle {
    width: 40px;
    height: 40px;
    margin-top: 0.75rem;
    opacity: 0.5;
}

.margin-sketch {
    width: 100%;
    height: auto;
    margin-bottom: 0.75rem;
    opacity: 0.7;
}

/* Annotation word-by-word reveal */
.annotation-reveal .word {
    display: inline-block;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.annotation-reveal .word.is-shown {
    opacity: 1;
}

/* --- Traces Section --- */
.section-traces {
    background: transparent;
}

.traces-stack {
    display: flex;
    flex-direction: column;
    gap: clamp(3rem, 5vw, 5rem);
    max-width: 800px;
    margin: 0 auto;
}

.trace-item {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.6s ease-out, transform 0.6s ease-out;
}

.trace-item.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.trace-content {
    display: flex;
    gap: clamp(1.5rem, 2.5vw, 2.5rem);
    align-items: flex-start;
}

.trace-sketch {
    flex-shrink: 0;
    width: 120px;
    height: 120px;
}

.trace-text {
    flex: 1;
}

.trace-title {
    font-family: var(--font-display);
    font-weight: 700;
    font-size: clamp(1.2rem, 2vw, 1.6rem);
    letter-spacing: -0.01em;
    line-height: 1.15;
    margin-bottom: 0.5rem;
    color: var(--text-primary);
}

.trace-body {
    font-family: var(--font-body);
    font-size: clamp(0.95rem, 1.05vw, 1.1rem);
    line-height: 1.75;
    color: var(--text-secondary);
    max-width: 38em;
}

/* --- Footer --- */
.site-footer {
    position: relative;
    z-index: 1;
    text-align: center;
    padding: clamp(3rem, 5vw, 5rem) clamp(1.5rem, 4vw, 4rem);
    padding-bottom: clamp(2rem, 4vw, 4rem);
}

.footer-divider {
    width: min(600px, 80%);
    height: auto;
    margin: 0 auto 2rem;
    display: block;
}

.footer-text {
    font-family: var(--font-display);
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.2rem);
    color: var(--text-secondary);
    letter-spacing: -0.01em;
}

.footer-annotation {
    font-family: var(--font-annotation);
    font-size: clamp(0.85rem, 0.95vw, 1rem);
    color: var(--divider);
    margin-top: 0.5rem;
}

/* --- Responsive --- */
@media (max-width: 768px) {
    .hero-content {
        transform: translate(-5%, -5%);
    }

    .compass-nav {
        top: 1rem;
        right: 1rem;
    }

    .margin-note-wide {
        grid-column: span 1;
    }

    .trace-content {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .trace-sketch {
        width: 100px;
        height: 100px;
    }

    .section {
        padding: clamp(2rem, 4vw, 4rem) clamp(1rem, 3vw, 2rem);
    }

    .section-heading-offset {
        padding-left: 0;
    }

    .parallax-bg,
    .parallax-fg {
        display: none;
    }
}

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

    .marginalia-grid {
        grid-template-columns: 1fr;
    }

    .card-tall,
    .card-extra-tall {
        grid-row: span 1;
    }
}
