/* ============================================
   scire.dev - Dark-Mode Scholarly Dashboard
   ============================================ */

/* --- CSS Custom Properties --- */
:root {
    --bg-primary: #0d0f14;
    --bg-secondary: #161923;
    --bg-tertiary: #1e2233;
    --text-primary: #e8e0d4;
    --text-secondary: #a89f91;
    --text-tertiary: #6b6359;
    --accent-rose: #e8a0b4;
    --accent-blue: #8eb8d4;
    --accent-sage: #8ec4a8;
    --accent-amber: #d4c08e;
    --accent-lavender: #b4a0d4;
    --border-gold: #c4a882;
    --font-display: 'Cormorant Garamond', Georgia, serif;
    --font-body: 'EB Garamond', Georgia, serif;
    --font-mono: 'Source Code Pro', monospace;
    --golden: 1.618;
    --base: 1rem;
    --space-1: 1rem;
    --space-2: 1.618rem;
    --space-3: 2.618rem;
    --space-4: 4.236rem;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    background-color: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-weight: 400;
    line-height: 1.72;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* --- Entry Overlay --- */
#entry-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background-color: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.8s ease;
}

#entry-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.entry-content {
    text-align: center;
}

#book-sigil {
    opacity: 0;
}

#book-sigil.animate {
    opacity: 1;
}

#book-path-left,
#book-path-right,
#book-spine {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
}

#book-sigil.animate #book-path-left,
#book-sigil.animate #book-path-right {
    animation: draw-path 1.8s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

#book-sigil.animate #book-spine {
    animation: draw-path 1.2s cubic-bezier(0.25, 0.1, 0.25, 1) 0.3s forwards;
}

.entry-title {
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(2.6rem, 5vw, 4.8rem);
    letter-spacing: 0.04em;
    line-height: 1.15;
    color: var(--text-primary);
    opacity: 0;
    transform: translateY(12px);
}

.entry-title.animate {
    animation: fade-rise 1.2s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.entry-subtitle {
    font-family: var(--font-body);
    font-style: italic;
    font-size: 1rem;
    color: var(--text-secondary);
    opacity: 0;
    transform: translateY(12px);
    margin-top: var(--space-1);
}

.entry-subtitle.animate {
    animation: fade-rise 1.2s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

/* --- Dashboard Layout --- */
#dashboard {
    display: grid;
    grid-template-columns: 25vw 1fr 20vw;
    min-height: 100vh;
    position: relative;
}

#dashboard.hidden {
    opacity: 0;
    pointer-events: none;
}

#dashboard.visible {
    opacity: 1;
    pointer-events: auto;
    transition: opacity 0.8s ease;
}

/* --- Scriptorium (Left Panel) --- */
#scriptorium {
    background-color: var(--bg-primary);
    border-right: 1px solid rgba(196, 168, 130, 0.15);
    padding: var(--space-4) var(--space-2);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transform: translateX(-100%);
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

#scriptorium.slide-in {
    transform: translateX(0);
}

.sigil-container {
    margin-bottom: var(--space-4);
    text-align: center;
}

.nav-sigil {
    opacity: 0.8;
    animation: sigil-breathe 6s ease-in-out infinite;
}

.nav-chapters {
    list-style: none;
}

.nav-chapters li {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    margin-bottom: var(--space-2);
}

.folio-num {
    font-family: var(--font-mono);
    font-weight: 300;
    font-size: clamp(0.72rem, 0.9vw, 0.85rem);
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    opacity: 0.7;
    min-width: 1.5rem;
    text-align: right;
}

.nav-link {
    font-family: var(--font-display);
    font-style: italic;
    font-weight: 300;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-decoration: none;
    position: relative;
    transition: color 0.3s ease;
    padding-bottom: 2px;
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background-color: var(--accent-rose);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 0.4s ease;
}

.nav-link:hover {
    color: var(--text-primary);
}

.nav-link.active {
    color: var(--text-primary);
}

.nav-link.active::after {
    transform: scaleX(1);
}

/* --- Primary Folio (Center Panel) --- */
#primary-folio {
    padding: var(--space-4) clamp(1.5rem, 5vw, 4.236rem);
    max-width: 100%;
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease 0.3s, transform 0.8s ease 0.3s;
}

#primary-folio.fade-in {
    opacity: 1;
    transform: translateY(0);
}

/* --- Folio Sections --- */
.folio-section {
    min-height: 100vh;
    padding: var(--space-4) 0;
    display: flex;
    flex-direction: column;
    align-items: center;
}

.folio-section + .folio-section {
    border-top: none;
}

.section-sigil-container {
    margin-bottom: var(--space-2);
    opacity: 0;
}

.section-sigil-container.visible .section-sigil .sigil-path {
    stroke-dasharray: 300;
    stroke-dashoffset: 300;
    animation: draw-path 1.2s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.section-sigil {
    cursor: pointer;
    transition: transform 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.section-sigil:hover {
    transform: rotate(15deg);
}

.section-sigil:hover .sigil-path {
    stroke: var(--text-primary);
    transition: stroke 0.3s ease;
}

.section-heading {
    font-family: var(--font-display);
    font-weight: 600;
    font-size: clamp(1.4rem, 2.5vw, 2.2rem);
    letter-spacing: 0.02em;
    line-height: 1.3;
    color: var(--text-primary);
    text-align: center;
    margin-bottom: var(--space-1);
    opacity: 0;
    transform: translateY(15px);
}

.section-heading.visible {
    animation: fade-rise 0.6s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

.rubricated {
    color: var(--accent-rose);
    font-weight: 600;
}

.folio-rule {
    border: none;
    height: 1px;
    background-color: rgba(196, 168, 130, 0.2);
    width: 0;
    max-width: 42rem;
    margin: 0 auto var(--space-3);
    transition: width 0.6s cubic-bezier(0.25, 0.1, 0.25, 1);
}

.folio-rule.visible {
    width: 100%;
}

.folio-content {
    max-width: 42rem;
    width: 100%;
}

.folio-content p {
    font-family: var(--font-body);
    font-weight: 400;
    font-size: clamp(1rem, 1.2vw, 1.15rem);
    line-height: 1.72;
    color: var(--text-primary);
    margin-bottom: 1.618em;
    opacity: 0;
    transform: translateY(10px);
}

.folio-content p.visible {
    animation: fade-rise 0.5s cubic-bezier(0.25, 0.1, 0.25, 1) forwards;
}

/* --- Drop Cap --- */
.drop-cap {
    float: left;
    font-family: var(--font-display);
    font-weight: 600;
    font-size: 3.2em;
    line-height: 0.8;
    color: var(--accent-rose);
    padding-right: 0.08em;
    margin-top: 0.05em;
    opacity: 0;
    transform: scale(0.8);
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.drop-cap.visible {
    opacity: 1;
    transform: scale(1);
}

/* --- Reference Markers --- */
.ref-marker {
    font-family: var(--font-mono);
    font-size: 0.7em;
    color: var(--accent-blue);
    cursor: pointer;
    position: relative;
    transition: color 0.2s ease;
}

.ref-marker:hover {
    color: var(--text-primary);
}

/* --- Colophon Ornament --- */
.colophon-ornament {
    margin-top: var(--space-3);
    text-align: center;
    opacity: 0.4;
}

/* --- Apparatus Criticus (Right Panel) --- */
#apparatus {
    background-color: var(--bg-primary);
    border-left: 1px solid rgba(196, 168, 130, 0.15);
    padding: var(--space-4) var(--space-2);
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    transform: translateX(100%);
    transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

#apparatus.slide-in {
    transform: translateX(0);
}

.apparatus-card {
    border: 1px solid rgba(196, 168, 130, 0.2);
    padding: var(--space-2);
    margin-bottom: var(--space-2);
    background: transparent;
    opacity: 0;
    transform: translateY(12px);
}

.apparatus-card.visible {
    animation: fade-rise 0.2s ease forwards;
}

.apparatus-card[data-accent="rose"] {
    border-color: rgba(232, 160, 180, 0.3);
}

.apparatus-card[data-accent="blue"] {
    border-color: rgba(142, 184, 212, 0.3);
}

.apparatus-card[data-accent="sage"] {
    border-color: rgba(142, 196, 168, 0.3);
}

.apparatus-card[data-accent="amber"] {
    border-color: rgba(212, 192, 142, 0.3);
}

.apparatus-card[data-accent="lavender"] {
    border-color: rgba(180, 160, 212, 0.3);
}

.apparatus-label {
    font-family: var(--font-mono);
    font-weight: 300;
    font-size: clamp(0.72rem, 0.9vw, 0.85rem);
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    opacity: 0.7;
    text-transform: uppercase;
    margin-bottom: var(--space-1);
}

.ref-num {
    color: var(--accent-blue);
}

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

.annotation-text em {
    color: var(--accent-amber);
    font-style: italic;
}

/* --- Widget: Progress Ring --- */
.widget-ring {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    height: 60px;
    margin: 0 auto;
}

.progress-ring {
    stroke-dasharray: 150.8;
    stroke-dashoffset: 150.8;
    transform: rotate(-90deg);
    transform-origin: center;
    transition: stroke-dashoffset 1.5s ease;
}

.progress-ring.animate {
    stroke-dashoffset: 40.7;
}

.ring-label {
    position: absolute;
    font-family: var(--font-mono);
    font-weight: 400;
    font-size: 0.72rem;
    color: var(--accent-sage);
    letter-spacing: 0.06em;
}

/* --- Widget: Bars --- */
.widget-bars {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.bar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.bar-label {
    font-family: var(--font-mono);
    font-weight: 300;
    font-size: 0.65rem;
    color: var(--text-tertiary);
    letter-spacing: 0.06em;
    min-width: 4.5rem;
}

.bar-track {
    flex: 1;
    height: 3px;
    background-color: var(--bg-tertiary);
    border-radius: 1.5px;
    overflow: hidden;
}

.bar-fill {
    height: 100%;
    border-radius: 1.5px;
    transform: scaleX(0);
    transform-origin: left;
    transition: transform 1s ease;
}

.bar-fill.animate {
    transform: scaleX(1);
}

/* --- Widget: Sparkline --- */
.widget-sparkline {
    padding: 0.5rem 0;
}

.sparkline-path {
    stroke-dasharray: 200;
    stroke-dashoffset: 200;
    transition: stroke-dashoffset 1.5s ease;
}

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

/* --- Widget: List --- */
.widget-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.list-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-family: var(--font-mono);
    font-size: 0.7rem;
    letter-spacing: 0.04em;
}

.list-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}

.list-text {
    color: var(--text-secondary);
    flex: 1;
}

.list-status {
    color: var(--text-tertiary);
    font-weight: 300;
}

/* --- Connection Lines SVG --- */
.connection-svg {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 500;
}

.connection-line {
    stroke: rgba(142, 184, 212, 0.5);
    stroke-width: 1;
    fill: none;
    stroke-dasharray: 500;
    stroke-dashoffset: 500;
    transition: stroke-dashoffset 0.4s ease;
}

.connection-line.active {
    stroke-dashoffset: 0;
}

/* --- Background Pattern --- */
.bg-pattern-svg {
    position: fixed;
    inset: 0;
    z-index: -1;
    pointer-events: none;
    display: none;
}

@media (min-width: 1440px) {
    .bg-pattern-svg {
        display: block;
    }
}

/* --- Mobile Menu Toggle --- */
#mobile-menu-toggle {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 900;
    background: var(--bg-secondary);
    border: 1px solid rgba(196, 168, 130, 0.2);
    padding: 0.5rem;
    cursor: pointer;
    border-radius: 2px;
}

/* --- Animations --- */
@keyframes draw-path {
    to {
        stroke-dashoffset: 0;
    }
}

@keyframes fade-rise {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes sigil-breathe {
    0%, 100% { opacity: 0.8; }
    50% { opacity: 1; }
}

/* --- Responsive: Below 1024px --- */
@media (max-width: 1024px) {
    #dashboard {
        grid-template-columns: 1fr;
    }

    #scriptorium {
        position: fixed;
        top: 0;
        left: 0;
        width: 280px;
        height: 100vh;
        z-index: 800;
        transform: translateX(-100%);
        background-color: var(--bg-primary);
    }

    #scriptorium.slide-in {
        transform: translateX(0);
    }

    #scriptorium.mobile-open {
        transform: translateX(0);
    }

    #apparatus {
        position: fixed;
        top: 0;
        right: 0;
        width: 280px;
        height: 100vh;
        z-index: 800;
        transform: translateX(100%);
        background-color: var(--bg-primary);
    }

    #apparatus.slide-in {
        transform: translateX(100%);
    }

    #apparatus.mobile-open {
        transform: translateX(0);
    }

    #primary-folio {
        padding: var(--space-3) clamp(1.5rem, 5vw, 4rem);
    }

    #mobile-menu-toggle {
        display: block;
    }

    #mobile-menu-toggle.hidden {
        display: none;
    }

    .folio-section {
        min-height: auto;
        padding: var(--space-3) 0;
    }
}

/* --- Responsive: Below 768px --- */
@media (max-width: 768px) {
    .section-heading {
        font-size: clamp(1.2rem, 4vw, 1.6rem);
    }

    .drop-cap {
        font-size: 2.4em;
    }

    .folio-content {
        max-width: 100%;
    }
}

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

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: rgba(196, 168, 130, 0.2);
    border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(196, 168, 130, 0.4);
}

/* --- Selection --- */
::selection {
    background-color: rgba(232, 160, 180, 0.25);
    color: var(--text-primary);
}
