/* ============================================================
   bada.moe — A Technical Grimoire
   Colors: #1A1A2E, #6C3483, #C0392B, #1E8449, #B7950B,
           #F5ECD7, #E8D5B7, #2D2D44, #B8A080
   Fonts: Cormorant Garamond, Lora, Caveat, Source Code Pro
   ============================================================ */

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

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

body {
    background-color: #F5ECD7;
    color: #2D2D44;
    font-family: 'Lora', serif;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* --- Binding Gutter --- */
.binding-gutter {
    position: fixed;
    top: 0;
    left: 12%;
    width: 1px;
    height: 100vh;
    background: #B8A080;
    opacity: 0.3;
    z-index: 1;
    pointer-events: none;
}

/* --- Scroll Progress Indicator --- */
.scroll-progress {
    position: fixed;
    top: 0;
    left: calc(12% + 6px);
    width: 4px;
    height: 100vh;
    z-index: 2;
    pointer-events: none;
}

.scroll-progress-svg {
    width: 4px;
    height: 100%;
}

.scroll-progress-fill {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 0.1s linear;
}

/* --- Compass Rose Navigation --- */
.compass-rose {
    position: fixed;
    top: 24px;
    right: 24px;
    width: 48px;
    height: 48px;
    z-index: 100;
    cursor: pointer;
    transition: transform 0.3s ease;
}

.compass-rose:hover {
    transform: scale(1.1);
}

.compass-svg {
    animation: slowRotate 120s linear infinite;
}

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

/* --- Table of Contents Panel --- */
.toc-panel {
    position: fixed;
    top: 0;
    right: -360px;
    width: 340px;
    height: 100vh;
    background-color: #E8D5B7;
    z-index: 99;
    padding: 40px 30px;
    transition: right 0.3s ease-out;
    box-shadow: -4px 0 20px rgba(26, 26, 46, 0.1);
    overflow-y: auto;
}

.toc-panel.open {
    right: 0;
}

.toc-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 30px;
    padding-bottom: 15px;
    border-bottom: 1px solid #B8A080;
}

.toc-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.6rem;
    font-weight: 600;
    color: #1A1A2E;
    font-style: italic;
}

.toc-close {
    background: none;
    border: none;
    font-size: 1.8rem;
    color: #1A1A2E;
    cursor: pointer;
    line-height: 1;
    padding: 4px 8px;
}

.toc-close:hover {
    color: #6C3483;
}

.toc-list {
    list-style: none;
}

.toc-entry {
    padding: 12px 0;
    cursor: pointer;
    border-bottom: 1px solid transparent;
    transition: border-color 0.2s ease;
    position: relative;
}

.toc-entry::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 1px;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='2'%3E%3Cpath d='M0 1 Q50 0 100 1 Q150 2 200 1' fill='none' stroke='%23B8A080' stroke-width='0.8'/%3E%3C/svg%3E");
    background-repeat: repeat-x;
    background-size: 200px 2px;
    opacity: 0.5;
}

.toc-entry:hover {
    border-bottom-color: transparent;
}

.toc-entry:hover .toc-desc {
    color: #6C3483;
}

.toc-numeral {
    font-family: 'Cormorant Garamond', serif;
    font-weight: 700;
    font-size: 1.2rem;
    color: #B7950B;
    margin-right: 14px;
    display: inline-block;
    min-width: 30px;
}

.toc-desc {
    font-family: 'Caveat', cursive;
    font-size: 1.2rem;
    color: #2D2D44;
    transition: color 0.2s ease;
}

/* --- Opening Sequence --- */
.opening {
    position: relative;
    height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.opening-line-svg {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100px;
    height: 60vh;
    z-index: 1;
}

.opening-line {
    stroke-dasharray: 600;
    stroke-dashoffset: 600;
    animation: drawLine 1.8s cubic-bezier(0.25, 0.1, 0.25, 1.0) 0.3s forwards;
}

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

.opening-title {
    position: relative;
    z-index: 2;
    text-align: center;
    opacity: 0;
    animation: fadeInTitle 1.2s ease 1.8s forwards;
}

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

.title-svg {
    width: clamp(280px, 50vw, 500px);
    height: auto;
    margin-bottom: 16px;
}

.title-text {
    opacity: 0;
    animation: fadeInTitle 1s ease 2.2s forwards;
}

.cartouche-path {
    stroke-dasharray: 1200;
    stroke-dashoffset: 1200;
    animation: drawLine 2s cubic-bezier(0.25, 0.1, 0.25, 1.0) 1.8s forwards;
}

.opening-subtitle {
    font-family: 'Caveat', cursive;
    font-size: clamp(1rem, 2vw, 1.3rem);
    color: #6C3483;
    opacity: 0;
    animation: fadeInTitle 0.8s ease 2.8s forwards;
    line-height: 1.55;
}

/* --- Ghost Construction Lines --- */
.ghost-lines {
    height: 40vh;
    position: relative;
    pointer-events: none;
}

/* --- Plates --- */
.plate {
    position: relative;
    width: 100%;
    padding: 60px 0 80px;
    margin-bottom: 0;
}

.plate-inner {
    position: relative;
    width: clamp(340px, 60%, 900px);
    margin-left: auto;
    margin-right: auto;
    padding-left: 14%;
    padding-right: 2%;
}

/* Plate border */
.plate-border {
    position: absolute;
    top: 20px;
    left: 12%;
    width: 76%;
    height: calc(100% - 40px);
    pointer-events: none;
    z-index: 0;
}

.plate-border-path {
    stroke-dasharray: 3200;
    stroke-dashoffset: 3200;
    transition: stroke-dashoffset 1.2s cubic-bezier(0.25, 0.1, 0.25, 1.0);
}

.plate.revealed .plate-border-path {
    stroke-dashoffset: 0;
}

/* Plate number */
.plate-number {
    position: relative;
    z-index: 2;
    margin-bottom: 8px;
    opacity: 0;
    transition: opacity 0.4s ease 0.3s;
}

.plate.revealed .plate-number {
    opacity: 1;
}

.plate-numeral-svg {
    height: 36px;
    width: auto;
}

/* Plate title */
.plate-title {
    font-family: 'Cormorant Garamond', serif;
    font-size: clamp(2rem, 4.5vw, 3.6rem);
    font-weight: 600;
    font-style: italic;
    color: #1A1A2E;
    letter-spacing: 0.02em;
    line-height: 1.15;
    margin-bottom: 30px;
    position: relative;
    z-index: 2;
    opacity: 0;
    transition: opacity 0.5s ease 0.5s;
}

.plate.revealed .plate-title {
    opacity: 1;
}

/* Construction lines */
.construction-lines {
    position: absolute;
    top: 0;
    left: 10%;
    width: 80%;
    height: 100%;
    z-index: 0;
    pointer-events: none;
}

.construction-svg {
    width: 100%;
    height: 100%;
}

/* Illustration */
.illustration {
    position: relative;
    z-index: 2;
    margin-bottom: 30px;
}

.plate-illustration {
    width: 100%;
    height: auto;
    max-width: 600px;
    display: block;
}

/* Draw path animation */
.draw-path {
    stroke-dasharray: var(--path-length, 1000);
    stroke-dashoffset: var(--path-length, 1000);
    transition: stroke-dashoffset 0.6s ease;
    opacity: 0;
}

.plate.revealed .draw-path {
    stroke-dashoffset: 0;
    opacity: 1;
}

/* Hoverable parts in illustrations */
.hoverable-part {
    transition: filter 0.3s ease;
    cursor: pointer;
}

.hoverable-part:hover,
.hoverable-part.highlight {
    filter: drop-shadow(0 0 6px rgba(183, 149, 11, 0.4));
}

/* --- Annotations --- */
.annotations {
    position: relative;
    z-index: 3;
    margin-bottom: 24px;
}

.annotation {
    margin-bottom: 14px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.4s ease, transform 0.4s ease, background-color 0.3s ease;
    padding: 4px 8px;
    border-radius: 2px;
}

.plate.revealed .annotation {
    opacity: 1;
    transform: translateY(0);
}

.annotation.highlight {
    background-color: rgba(183, 149, 11, 0.12);
}

.annotation-text {
    font-family: 'Caveat', cursive;
    font-size: clamp(0.85rem, 1.6vw, 1.05rem);
    line-height: 1.55;
}

.annotation-text.primary {
    color: #6C3483;
}

.annotation-text.measurement {
    color: #C0392B;
    font-family: 'Caveat', cursive;
}

.annotation-text.label {
    color: #1E8449;
}

.annotation-text.crossref {
    color: #B7950B;
}

.annotation-note {
    margin-top: 10px;
    padding-left: 12px;
    border-left: 2px solid #B8A080;
}

/* Leader lines (marching ants on hover) */
.measurement-line,
.label-line {
    cursor: pointer;
}

.measurement-line:hover,
.label-line:hover {
    animation: marchingAnts 0.4s linear infinite;
}

@keyframes marchingAnts {
    to { stroke-dashoffset: -10; }
}

/* --- Plate Body Text --- */
.plate-body {
    position: relative;
    z-index: 2;
    max-width: 560px;
    opacity: 0;
    transition: opacity 0.6s ease;
}

.plate.revealed .plate-body {
    opacity: 1;
}

.plate-body p {
    font-family: 'Lora', serif;
    font-size: clamp(1rem, 1.8vw, 1.15rem);
    line-height: 1.72;
    letter-spacing: 0.005em;
    color: #2D2D44;
}

/* Monospace for inline technical values */
code, .mono {
    font-family: 'Source Code Pro', monospace;
    font-size: 0.9em;
    color: #1A1A2E;
}

/* --- Colophon --- */
.colophon {
    text-align: center;
    padding: 80px 20px 120px;
}

.colophon-svg {
    width: 200px;
    height: 80px;
    margin-bottom: 16px;
}

.flourish-path {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
}

.colophon.revealed .flourish-path {
    stroke-dashoffset: 0;
    transition: stroke-dashoffset 1.5s ease;
}

.colophon-text {
    font-family: 'Cormorant Garamond', serif;
    font-size: 1.2rem;
    font-style: italic;
    color: #B7950B;
    letter-spacing: 0.05em;
    opacity: 0;
    transition: opacity 0.8s ease 0.5s;
}

.colophon.revealed .colophon-text {
    opacity: 1;
}

/* --- Stagger delays for annotations within revealed plates --- */
.plate.revealed .annotation:nth-child(1) { transition-delay: 0.8s; }
.plate.revealed .annotation:nth-child(2) { transition-delay: 0.95s; }
.plate.revealed .annotation:nth-child(3) { transition-delay: 1.1s; }
.plate.revealed .annotation:nth-child(4) { transition-delay: 1.25s; }
.plate.revealed .annotation:nth-child(5) { transition-delay: 1.4s; }
.plate.revealed .annotation:nth-child(6) { transition-delay: 1.55s; }
.plate.revealed .annotation:nth-child(7) { transition-delay: 1.7s; }

/* Stagger delays for draw-paths */
.plate.revealed .draw-path:nth-child(1) { transition-delay: 0.3s; }
.plate.revealed .draw-path:nth-child(2) { transition-delay: 0.38s; }
.plate.revealed .draw-path:nth-child(3) { transition-delay: 0.46s; }
.plate.revealed .draw-path:nth-child(4) { transition-delay: 0.54s; }
.plate.revealed .draw-path:nth-child(5) { transition-delay: 0.62s; }
.plate.revealed .draw-path:nth-child(6) { transition-delay: 0.7s; }
.plate.revealed .draw-path:nth-child(7) { transition-delay: 0.78s; }
.plate.revealed .draw-path:nth-child(8) { transition-delay: 0.86s; }
.plate.revealed .draw-path:nth-child(9) { transition-delay: 0.94s; }
.plate.revealed .draw-path:nth-child(10) { transition-delay: 1.02s; }
.plate.revealed .draw-path:nth-child(11) { transition-delay: 1.1s; }
.plate.revealed .draw-path:nth-child(12) { transition-delay: 1.18s; }
.plate.revealed .draw-path:nth-child(13) { transition-delay: 1.26s; }
.plate.revealed .draw-path:nth-child(14) { transition-delay: 1.34s; }
.plate.revealed .draw-path:nth-child(15) { transition-delay: 1.42s; }
.plate.revealed .draw-path:nth-child(16) { transition-delay: 1.5s; }
.plate.revealed .draw-path:nth-child(17) { transition-delay: 1.58s; }
.plate.revealed .draw-path:nth-child(18) { transition-delay: 1.66s; }
.plate.revealed .draw-path:nth-child(19) { transition-delay: 1.74s; }
.plate.revealed .draw-path:nth-child(20) { transition-delay: 1.82s; }

/* Body text appears last */
.plate.revealed .plate-body {
    transition-delay: 1.8s;
}

/* --- Responsive: Below 900px --- */
@media (max-width: 900px) {
    .binding-gutter {
        display: none;
    }

    .scroll-progress {
        left: 8px;
    }

    .plate-inner {
        width: 92%;
        padding-left: 5%;
        padding-right: 5%;
    }

    .plate-border {
        left: 2%;
        width: 96%;
    }

    .annotations {
        position: relative;
        width: 100%;
    }

    .annotation-note {
        margin-left: 0;
    }

    .compass-rose {
        width: 36px;
        height: 36px;
        top: 16px;
        right: 16px;
    }

    .compass-svg {
        width: 36px;
        height: 36px;
    }

    .toc-panel {
        width: 85vw;
        right: -85vw;
    }

    .ghost-lines {
        height: 25vh;
    }
}

/* Large screens: annotation margin */
@media (min-width: 1200px) {
    .plate-inner {
        position: relative;
    }

    .annotations {
        position: absolute;
        top: 120px;
        right: -30%;
        width: 28%;
    }

    .annotation-note {
        margin-left: 0;
    }
}

/* --- Selection styling --- */
::selection {
    background-color: rgba(108, 52, 131, 0.2);
    color: #1A1A2E;
}
