/* ============================================================
   ethica.dev -- Styles
   Baroque philosophical cabinet / Spinoza's Ethics
   ============================================================ */

/* --- CSS Custom Properties --- */
:root {
    /* Color Palette */
    --manuscript-night: #1A1610;
    --vellum-dark: #2A2318;
    --burnished-gold: #C9A84C;
    --crimson-seal: #8B2500;
    --crimson-highlight: #A63A15;
    --crimson-shadow: #5C1800;
    --warm-ivory: #D6CCBB;
    --aged-parchment: #A69274;
    --warm-stone: #8A7D6B;
    --verdigris: #4A7C6F;
    --deep-umber: #3D2E1A;
    --light-gold: #D4A853;

    /* Typography Sizes */
    --body-size: 18px;
    --body-lh: 1.72;
    --marginalia-size: 14px;
    --ui-size: 12px;
}

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

html {
    scroll-behavior: smooth;
    font-size: 16px;
    background: var(--manuscript-night);
}

body {
    font-family: 'Lora', Georgia, 'Times New Roman', serif;
    font-size: var(--body-size);
    line-height: var(--body-lh);
    color: var(--warm-ivory);
    background: var(--manuscript-night);
    font-feature-settings: "onum" 1;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Parchment Grain Overlay --- */
#parchment-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    mix-blend-mode: soft-light;
    opacity: 0.05;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.65' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)' opacity='0.5'/%3E%3C/svg%3E");
    background-size: 200px 200px;
}

/* --- Axiom Progress Bar --- */
#axiom-bar {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: transparent;
    z-index: 9999;
}

#axiom-fill {
    height: 100%;
    width: 0%;
    background: var(--burnished-gold);
    transition: width 0.1s ease-out;
    box-shadow: 0 0 8px rgba(201, 168, 76, 0.4);
}

#axiom-fill.shimmer {
    animation: axiomShimmer 1.2s ease-in-out;
}

@keyframes axiomShimmer {
    0% { box-shadow: 0 0 8px rgba(201, 168, 76, 0.4); opacity: 0.3; }
    50% { box-shadow: 0 0 20px rgba(201, 168, 76, 0.8); opacity: 1; }
    100% { box-shadow: 0 0 8px rgba(201, 168, 76, 0.4); opacity: 1; }
}

/* --- Full-Viewport Sections --- */
.full-viewport {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
}

/* --- Opening Sequence --- */
#opening {
    background: var(--manuscript-night);
}

#opening .geometric-diagram {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 1.5s ease;
    z-index: 1;
}

#opening .geometric-diagram.visible {
    opacity: 0.2;
}

#opening .geometric-diagram.faded {
    opacity: 0.1;
    transform: translate(-50%, -55%);
    transition: opacity 1s ease, transform 2s ease;
}

#main-title {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 900;
    font-size: clamp(3rem, 8vw, 7rem);
    letter-spacing: 0.15em;
    color: var(--burnished-gold);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.8s ease, transform 0.8s ease;
    z-index: 2;
    text-align: center;
    font-variant-ligatures: discretionary-ligatures;
    font-feature-settings: "swsh" 1;
}

#main-title.visible {
    opacity: 1;
    transform: translateY(0);
}

#main-subtitle {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 300;
    font-style: italic;
    font-size: clamp(1rem, 2.5vw, 1.5rem);
    color: var(--aged-parchment);
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.8s ease, transform 0.8s ease;
    z-index: 2;
    margin-top: 1rem;
    letter-spacing: 0.06em;
}

#main-subtitle.visible {
    opacity: 1;
    transform: translateY(0);
}

/* --- SVG Draw Path Animation --- */
.draw-path {
    stroke-dasharray: 2000;
    stroke-dashoffset: 2000;
    transition: stroke-dashoffset 2.5s ease-out;
}

.draw-path.animate {
    stroke-dashoffset: 0;
}

/* --- Book Interstitials --- */
.book-interstitial {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--vellum-dark);
    position: relative;
    overflow: hidden;
}

.book-interstitial .geometric-diagram {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    opacity: 0;
    transition: opacity 1s ease;
    z-index: 1;
}

.book-interstitial .geometric-diagram.visible {
    opacity: 0.15;
}

.book-numeral {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 900;
    font-size: clamp(5rem, 15vw, 12rem);
    color: var(--burnished-gold);
    opacity: 0.4;
    z-index: 2;
    line-height: 1;
    text-align: center;
}

.book-proposition {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 300;
    font-style: italic;
    font-size: 1.2rem;
    color: var(--aged-parchment);
    z-index: 2;
    margin-top: 1.5rem;
    text-align: center;
    max-width: 500px;
    padding: 0 2rem;
    line-height: 1.6;
}

.book-theme {
    font-family: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
    font-weight: 300;
    font-size: var(--ui-size);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--warm-stone);
    z-index: 2;
    margin-top: 2rem;
}

/* --- Codex Grid Layout --- */
.book-content {
    background: var(--manuscript-night);
    padding: 6rem 2rem;
    position: relative;
}

.codex-grid {
    display: grid;
    grid-template-columns: 1fr 200px;
    gap: 3rem;
    max-width: 920px;
    margin: 0 auto;
    /* Offset slightly left of center */
    margin-left: auto;
    margin-right: auto;
    position: relative;
}

.main-column {
    max-width: 680px;
}

/* --- Propositions --- */
.proposition {
    background: var(--vellum-dark);
    border-left: 2px solid var(--burnished-gold);
    padding: 1.5rem;
    margin: 2rem 0;
    position: relative;
}

.proposition-number {
    display: block;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 600;
    font-size: 1rem;
    color: var(--light-gold);
    margin-bottom: 0.75rem;
    letter-spacing: 0.03em;
}

.proposition p {
    font-family: 'Lora', Georgia, serif;
    font-size: var(--body-size);
    line-height: var(--body-lh);
    color: var(--warm-ivory);
}

/* --- Body Text --- */
.body-text {
    margin: 1.5rem 0;
    color: var(--warm-ivory);
    font-feature-settings: "onum" 1;
}

/* --- Definitions --- */
.definition {
    font-style: italic;
    margin: 2rem 0;
    padding: 1rem 1.5rem;
    border-left: 1px solid var(--deep-umber);
    color: var(--warm-ivory);
}

.definition em {
    color: var(--aged-parchment);
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 400;
}

.definition strong {
    color: var(--burnished-gold);
    font-weight: 500;
}

/* --- Scholia --- */
.scholium {
    margin: 2.5rem 0;
    padding: 1.5rem;
    background: rgba(42, 35, 24, 0.4);
    border-radius: 2px;
}

.scholium-label {
    display: block;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 600;
    font-style: italic;
    font-size: 0.95rem;
    color: var(--light-gold);
    margin-bottom: 0.75rem;
    letter-spacing: 0.02em;
}

.scholium p {
    font-size: 16px;
    line-height: 1.7;
    color: var(--aged-parchment);
}

/* --- Quill Flourish Dividers --- */
.quill-divider {
    display: flex;
    justify-content: center;
    margin: 2.5rem 0;
}

.quill-divider svg {
    width: 30%;
    max-width: 200px;
    height: auto;
}

.quill-path {
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 1.5s ease-out;
}

.quill-path.animate {
    stroke-dashoffset: 0;
}

/* --- Marginalia Column --- */
.marginalia-column {
    position: relative;
}

.marginalia {
    margin-bottom: 3rem;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.4s ease, transform 0.4s ease;
}

.marginalia.visible {
    opacity: 1;
    transform: translateY(0);
}

.marginalia p {
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-weight: 300;
    font-style: italic;
    font-size: var(--marginalia-size);
    line-height: 1.55;
    color: var(--aged-parchment);
}

.marginalia em {
    font-style: normal;
    color: var(--warm-stone);
}

.manicule,
.pilcrow,
.asterism {
    display: block;
    font-family: 'Cormorant Garamond', 'Georgia', serif;
    font-style: italic;
    font-size: 16px;
    color: var(--aged-parchment);
    margin-bottom: 0.4rem;
}

/* --- Links & Cross-references --- */
a {
    color: var(--verdigris);
    text-decoration: none;
    position: relative;
    transition: color 0.2s ease;
}

a::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 0;
    height: 1px;
    background: var(--burnished-gold);
    transition: width 0.2s ease;
}

a:hover::after {
    width: 100%;
}

a:hover {
    color: var(--burnished-gold);
}

/* --- Key Terms --- */
.key-term {
    color: var(--crimson-seal);
    text-decoration: none;
    border-bottom: 1px dotted var(--crimson-seal);
    cursor: help;
}

/* --- Closing / Footer --- */
#closing {
    background: var(--manuscript-night);
    padding: 4rem 2rem;
}

.closing-content {
    max-width: 680px;
    text-align: center;
}

.closing-proposition {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 2vw, 1.4rem);
    color: var(--burnished-gold);
    line-height: 1.8;
    margin-bottom: 2rem;
    opacity: 0.9;
}

.closing-divider {
    margin: 2rem auto;
}

.closing-credits {
    font-family: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
    font-weight: 300;
    font-size: 11px;
    color: var(--warm-stone);
    letter-spacing: 0.08em;
    text-transform: uppercase;
    line-height: 1.8;
}

/* --- Wax Seal Navigation --- */
#wax-seal {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    z-index: 9998;
}

#seal-icon {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--crimson-seal);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    position: relative;
    box-shadow:
        inset 0 2px 4px rgba(166, 58, 21, 0.6),
        inset 0 -2px 4px rgba(92, 24, 0, 0.8),
        0 2px 8px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(166, 58, 21, 0.3);
    animation: sealPulse 3s ease-in-out infinite;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    /* Irregular edge via clip-path */
    clip-path: polygon(
        50% 0%, 62% 2%, 74% 5%, 83% 10%, 90% 18%,
        96% 28%, 100% 40%, 99% 52%, 97% 64%, 93% 74%,
        87% 83%, 78% 90%, 68% 96%, 56% 99%, 44% 100%,
        32% 97%, 22% 92%, 14% 85%, 8% 75%, 3% 64%,
        0% 52%, 1% 40%, 4% 28%, 10% 18%, 18% 10%,
        28% 4%, 38% 1%
    );
}

#seal-icon:hover {
    transform: rotate(5deg);
    box-shadow:
        inset 0 2px 4px rgba(166, 58, 21, 0.6),
        inset 0 -2px 4px rgba(92, 24, 0, 0.8),
        0 4px 16px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(166, 58, 21, 0.3);
}

.seal-letter {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 900;
    font-size: 22px;
    color: rgba(26, 22, 16, 0.7);
    text-shadow:
        0 1px 0 rgba(166, 58, 21, 0.8),
        0 -1px 0 rgba(92, 24, 0, 0.5);
    user-select: none;
}

@keyframes sealPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.03); }
}

/* --- Radial Menu --- */
#radial-menu {
    position: absolute;
    bottom: 60px;
    right: 0;
    pointer-events: none;
}

#radial-menu.hidden {
    display: block;
}

#radial-menu.hidden .radial-item {
    opacity: 0;
    transform: scale(0.3);
    pointer-events: none;
}

.radial-item {
    position: absolute;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--vellum-dark);
    border: 1px solid var(--burnished-gold);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    opacity: 0;
    transform: scale(0.3);
    transition: opacity 0.3s ease, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
    pointer-events: none;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.radial-item::after {
    display: none;
}

#radial-menu.open .radial-item {
    opacity: 1;
    pointer-events: auto;
}

#radial-menu.open .radial-item:nth-child(1) {
    transform: translate(-140px, -40px);
    transition-delay: 0s;
}
#radial-menu.open .radial-item:nth-child(2) {
    transform: translate(-120px, -100px);
    transition-delay: 0.04s;
}
#radial-menu.open .radial-item:nth-child(3) {
    transform: translate(-80px, -150px);
    transition-delay: 0.08s;
}
#radial-menu.open .radial-item:nth-child(4) {
    transform: translate(-30px, -185px);
    transition-delay: 0.12s;
}
#radial-menu.open .radial-item:nth-child(5) {
    transform: translate(25px, -200px);
    transition-delay: 0.16s;
}

.radial-item:hover {
    background: var(--burnished-gold);
    border-color: var(--burnished-gold);
}

.radial-item:hover .radial-numeral {
    color: var(--manuscript-night);
}

.radial-item:hover .radial-label {
    color: var(--manuscript-night);
}

.radial-numeral {
    font-family: 'Playfair Display', 'Georgia', serif;
    font-weight: 700;
    font-size: 13px;
    color: var(--burnished-gold);
    line-height: 1;
    transition: color 0.2s ease;
}

.radial-label {
    font-family: 'IBM Plex Sans', 'Helvetica Neue', sans-serif;
    font-weight: 400;
    font-size: 7px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--warm-stone);
    line-height: 1;
    margin-top: 2px;
    transition: color 0.2s ease;
}

/* --- Geometric Diagram Parallax Container --- */
.geometric-diagram {
    will-change: transform;
}

.geometric-diagram svg {
    max-width: 100%;
    height: auto;
}

/* --- Responsive: Mobile (<1024px) --- */
@media (max-width: 1024px) {
    .codex-grid {
        grid-template-columns: 1fr;
        gap: 0;
        max-width: 680px;
    }

    .marginalia-column {
        display: none;
    }

    .book-content {
        padding: 4rem 1.5rem;
    }

    #wax-seal {
        bottom: 1.5rem;
        right: 1.5rem;
    }

    #seal-icon {
        width: 46px;
        height: 46px;
    }

    .seal-letter {
        font-size: 20px;
    }
}

/* --- Responsive: Small Screens (<768px) --- */
@media (max-width: 768px) {
    .book-interstitial {
        padding: 2rem;
    }

    .book-numeral {
        font-size: clamp(4rem, 12vw, 8rem);
    }

    .proposition {
        padding: 1.2rem;
        margin: 1.5rem 0;
    }

    .book-content {
        padding: 3rem 1rem;
    }

    .codex-grid {
        max-width: 100%;
    }

    #radial-menu.open .radial-item:nth-child(1) {
        transform: translate(-110px, -30px);
    }
    #radial-menu.open .radial-item:nth-child(2) {
        transform: translate(-100px, -80px);
    }
    #radial-menu.open .radial-item:nth-child(3) {
        transform: translate(-65px, -125px);
    }
    #radial-menu.open .radial-item:nth-child(4) {
        transform: translate(-20px, -155px);
    }
    #radial-menu.open .radial-item:nth-child(5) {
        transform: translate(25px, -170px);
    }
}

/* --- Selection Color --- */
::selection {
    background: rgba(201, 168, 76, 0.3);
    color: var(--warm-ivory);
}

/* --- Scrollbar Styling --- */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: var(--manuscript-night);
}

::-webkit-scrollbar-thumb {
    background: var(--deep-umber);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--warm-stone);
}
