/* ========================================
   mujun.study - The Study of Contradiction
   Skeuomorphic Scholar's Desk
   ======================================== */

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

:root {
    --desk-surface: #F0E6D8;
    --walnut-dark: #3A2818;
    --pastel-sage: #B8C8B0;
    --pastel-blush: #D4B0A8;
    --brass-gold: #C8A848;
    --ink-dark: #2A2018;
    --lamp-warm: #FFF5E0;
    --sci-fi-accent: #4A7A8A;
    --sidebar-width: 280px;
    --base-unit: 12px;
    --lamp-x: 50%;
    --lamp-y: 20%;
}

html {
    scroll-behavior: smooth;
}

body {
    font-family: 'Libre Baskerville', Georgia, serif;
    color: var(--ink-dark);
    background: var(--desk-surface);
    min-height: 100vh;
    overflow-x: hidden;
}

/* --- Loading Overlay (entrance animation) --- */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(42, 32, 24, 0.4);
    z-index: 1000;
    pointer-events: none;
    opacity: 1;
    transition: opacity 1000ms ease-out;
}

#loading-overlay.faded {
    opacity: 0;
}

/* --- Desk Lamp Overlay --- */
#lamp-overlay {
    position: fixed;
    top: 0;
    left: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    height: 100%;
    background: radial-gradient(
        ellipse 600px 500px at var(--lamp-x) var(--lamp-y),
        rgba(255, 245, 224, 0.25) 0%,
        rgba(240, 230, 216, 0.05) 50%,
        transparent 100%
    );
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 1000ms ease-out;
}

#lamp-overlay.visible {
    opacity: 1;
}

/* --- Bookshelf Sidebar --- */
#sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--walnut-dark);
    background-image:
        repeating-linear-gradient(
            0deg,
            transparent,
            transparent 40px,
            rgba(0,0,0,0.05) 40px,
            rgba(0,0,0,0.05) 41px
        ),
        linear-gradient(
            90deg,
            rgba(0,0,0,0.15) 0%,
            transparent 10%,
            transparent 90%,
            rgba(0,0,0,0.1) 100%
        );
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    transform: translateX(-280px);
    transition: transform 500ms ease-out;
}

#sidebar.visible {
    transform: translateX(0);
}

.sidebar-header {
    padding: 30px 20px 20px;
    text-align: center;
    border-bottom: 1px solid rgba(200, 168, 72, 0.3);
}

.sidebar-title {
    font-family: 'Libre Baskerville', serif;
    font-size: 36px;
    font-weight: 700;
    color: var(--lamp-warm);
    display: block;
    letter-spacing: 0.05em;
}

.sidebar-subtitle {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 18px;
    color: var(--brass-gold);
    letter-spacing: 0.3em;
    display: block;
    margin-top: 4px;
}

.bookshelf {
    list-style: none;
    flex: 1;
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.book-spine {
    display: flex;
    align-items: center;
    padding: 14px 16px;
    cursor: pointer;
    position: relative;
    transition: transform 300ms ease, background 300ms ease;
    border-left: 4px solid var(--spine-color, #B8C8B0);
    background: transparent;
}

.book-spine::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    width: 4px;
    height: 100%;
    background: var(--spine-color, #B8C8B0);
    opacity: 0.8;
}

.book-spine:hover {
    transform: translateX(8px);
    background: rgba(255, 245, 224, 0.05);
}

.book-spine:hover .spine-text {
    color: var(--lamp-warm);
}

.book-spine.active {
    transform: translateX(4px);
    background: rgba(255, 245, 224, 0.08);
}

.book-spine.active .spine-text {
    color: var(--lamp-warm);
}

.spine-text {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 14px;
    font-weight: 400;
    letter-spacing: 0.08em;
    color: rgba(255, 245, 224, 0.5);
    transition: color 300ms ease;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(200, 168, 72, 0.3);
}

/* --- HUD Panels (Sci-fi digital readouts) --- */
.hud-panel {
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid var(--sci-fi-accent);
    padding: 8px 12px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: 'Special Elite', monospace;
    position: relative;
    overflow: hidden;
}

.hud-panel::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--sci-fi-accent), transparent);
    opacity: 0.6;
}

.hud-panel::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--sci-fi-accent), transparent);
    opacity: 0.3;
}

.hud-label {
    font-size: 9px;
    letter-spacing: 0.15em;
    color: var(--sci-fi-accent);
    text-transform: uppercase;
    opacity: 0.8;
}

.hud-value {
    font-size: 18px;
    color: var(--sci-fi-accent);
    letter-spacing: 0.1em;
    text-shadow: 0 0 8px rgba(74, 122, 138, 0.5);
}

.hud-unit {
    font-size: 8px;
    letter-spacing: 0.12em;
    color: var(--sci-fi-accent);
    opacity: 0.6;
    text-transform: uppercase;
}

.sidebar-hud {
    width: 100%;
    justify-content: center;
    gap: 12px;
}

/* --- HUD Flicker Animation --- */
@keyframes hudFlicker {
    0%, 100% { opacity: 1; }
    5% { opacity: 0.3; }
    10% { opacity: 1; }
    15% { opacity: 0.6; }
    20% { opacity: 1; }
}

.hud-panel.flickering {
    animation: hudFlicker 0.4s ease-in-out;
}

/* --- Main Desk Surface --- */
#desk-surface {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    padding: 60px 48px;
    position: relative;
    background:
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23noise)' opacity='0.03'/%3E%3C/svg%3E"),
        var(--desk-surface);
}

/* --- Desk Header --- */
#desk-header {
    text-align: center;
    max-width: 700px;
    margin: 0 auto 60px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 600ms ease, transform 600ms ease;
}

#desk-header.visible {
    opacity: 1;
    transform: translateY(0);
}

.desk-title {
    font-family: 'Libre Baskerville', serif;
    font-size: clamp(22px, 2.5vw, 40px);
    font-weight: 700;
    color: var(--ink-dark);
    letter-spacing: 0.01em;
    margin-bottom: 16px;
}

.desk-subtitle {
    font-family: 'Libre Baskerville', serif;
    font-size: clamp(15px, 1vw, 16px);
    font-weight: 400;
    font-style: italic;
    color: var(--ink-dark);
    opacity: 0.7;
    line-height: 1.8;
    min-height: 1.8em;
}

.header-hud {
    margin-top: 30px;
    display: inline-flex;
}

/* --- Brass Ornament Dividers --- */
.brass-ornament {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0;
    margin: 20px auto;
    width: 200px;
    height: 16px;
    position: relative;
}

.brass-ornament::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 0;
    right: 0;
    height: 2px;
    background: var(--brass-gold);
    opacity: 0.5;
    box-shadow: 0 2px 0 0 var(--brass-gold);
}

.brass-ornament::after {
    content: '\25C6';
    position: relative;
    z-index: 1;
    font-size: 10px;
    color: var(--brass-gold);
    background: var(--desk-surface);
    padding: 0 10px;
}

.brass-ornament.small {
    width: 120px;
    margin: 12px 0;
}

.brass-ornament.small::before {
    height: 1px;
    box-shadow: none;
}

.brass-ornament.small::after {
    font-size: 7px;
    padding: 0 6px;
    background: var(--lamp-warm);
}

/* --- Brass Shimmer on Hover --- */
@keyframes brassShimmer {
    0%, 100% { opacity: 0.5; }
    50% { opacity: 0.9; }
}

/* --- Study Cards Grid --- */
#study-cards {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
    max-width: 960px;
    margin: 0 auto 60px;
}

.study-card {
    background: var(--lamp-warm);
    border: 1px solid rgba(212, 176, 168, 0.4);
    border-top: 1px solid rgba(180, 150, 140, 0.6);
    border-radius: 2px;
    padding: 28px 24px;
    position: relative;
    cursor: pointer;
    box-shadow:
        0 2px 8px rgba(42, 32, 24, 0.1),
        0 6px 20px rgba(42, 32, 24, 0.08);
    transition:
        transform 300ms ease,
        box-shadow 300ms ease;
    opacity: 0;
    transform: translateY(8px);
}

.study-card.visible {
    opacity: 1;
    transform: translateY(0) rotate(calc(var(--rotation, 0) * 1deg));
}

.study-card:hover {
    transform: translateY(-2px) rotate(0deg);
    box-shadow:
        0 4px 12px rgba(42, 32, 24, 0.15),
        0 10px 30px rgba(42, 32, 24, 0.12);
}

.study-card:nth-child(odd) {
    --rotation: 0.5;
}

.study-card:nth-child(even) {
    --rotation: -0.5;
}

.study-card:nth-child(3) {
    --rotation: 0.3;
}

.study-card:nth-child(4) {
    --rotation: -0.7;
}

.study-card:nth-child(5) {
    --rotation: 0.8;
}

.study-card:nth-child(6) {
    --rotation: -0.4;
}

.study-card:nth-child(7) {
    --rotation: 0.2;
}

.study-card:nth-child(8) {
    --rotation: -0.3;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.card-stamp {
    font-family: 'Special Elite', monospace;
    font-size: 12px;
    color: var(--ink-dark);
    opacity: 0.4;
}

.card-hud {
    padding: 4px 8px;
    gap: 4px;
}

.card-hud .hud-value {
    font-size: 14px;
}

.card-hud .hud-unit {
    font-size: 7px;
}

.card-title {
    font-family: 'Libre Baskerville', serif;
    font-size: clamp(18px, 1.8vw, 24px);
    font-weight: 700;
    color: var(--ink-dark);
    letter-spacing: 0.01em;
    margin-bottom: 4px;
}

.card-subtitle {
    font-family: 'Libre Baskerville', serif;
    font-size: 14px;
    color: var(--ink-dark);
    opacity: 0.5;
    margin-bottom: 4px;
}

.card-body {
    font-family: 'Libre Baskerville', serif;
    font-size: clamp(15px, 1vw, 16px);
    font-weight: 400;
    line-height: 1.8;
    color: var(--ink-dark);
    margin-bottom: 16px;
}

.card-paradox {
    font-family: 'Special Elite', monospace;
    font-size: 14px;
    color: var(--ink-dark);
    opacity: 0.7;
    min-height: 1.5em;
    padding: 8px 12px;
    background: rgba(240, 230, 216, 0.5);
    border-left: 2px solid var(--brass-gold);
    margin-bottom: 16px;
}

.card-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

.card-classification {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 11px;
    letter-spacing: 0.1em;
    color: var(--sci-fi-accent);
}

.card-origin {
    font-family: 'Special Elite', monospace;
    font-size: 11px;
    color: var(--ink-dark);
    opacity: 0.4;
}

/* --- Typewriter Effect --- */
.typewriter-text {
    position: relative;
}

.typewriter-text.typing::after {
    content: '\2588';
    animation: cursorBlink 600ms step-end infinite;
    color: var(--ink-dark);
    opacity: 0.7;
    margin-left: 2px;
}

.typewriter-text.done::after {
    content: '';
}

@keyframes cursorBlink {
    0%, 100% { opacity: 0.7; }
    50% { opacity: 0; }
}

/* Character flash effect */
.typewriter-text .char-flash {
    animation: charFlash 80ms ease-out;
}

@keyframes charFlash {
    0% { color: var(--brass-gold); }
    100% { color: inherit; }
}

/* --- Desk Footer --- */
#desk-footer {
    text-align: center;
    padding: 40px 0 60px;
    max-width: 700px;
    margin: 0 auto;
}

.footer-content {
    margin-top: 20px;
}

.footer-hud {
    display: inline-flex;
    margin-bottom: 20px;
}

.footer-text {
    font-family: 'Libre Baskerville', serif;
    font-size: 14px;
    color: var(--ink-dark);
    opacity: 0.5;
    line-height: 1.8;
}

.footer-text.small {
    font-size: 12px;
    opacity: 0.35;
    margin-top: 4px;
}

/* --- Specimen Panel (Modal) --- */
.specimen-panel {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 400ms ease;
}

.specimen-panel.open {
    opacity: 1;
    pointer-events: all;
}

.specimen-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(42, 32, 24, 0.65);
}

.specimen-journal {
    position: relative;
    width: 90%;
    max-width: 900px;
    max-height: 85vh;
    background: var(--lamp-warm);
    border-radius: 3px;
    display: flex;
    overflow: hidden;
    box-shadow:
        0 8px 40px rgba(42, 32, 24, 0.3),
        0 2px 8px rgba(42, 32, 24, 0.2);
    transform: scale(0.95);
    transition: transform 400ms ease;
}

.specimen-panel.open .specimen-journal {
    transform: scale(1);
}

.journal-spine {
    width: 24px;
    background: linear-gradient(
        90deg,
        var(--walnut-dark) 0%,
        rgba(58, 40, 24, 0.8) 40%,
        rgba(58, 40, 24, 0.3) 100%
    );
    flex-shrink: 0;
}

.journal-left {
    flex: 1;
    padding: 36px 32px;
    overflow-y: auto;
    border-right: 1px solid rgba(212, 176, 168, 0.3);
}

.journal-right {
    width: 300px;
    padding: 36px 24px;
    background: rgba(240, 230, 216, 0.5);
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.specimen-close {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: none;
    font-size: 28px;
    color: var(--ink-dark);
    opacity: 0.4;
    cursor: pointer;
    transition: opacity 200ms ease;
    z-index: 2;
}

.specimen-close:hover {
    opacity: 0.8;
}

.specimen-title {
    font-family: 'Libre Baskerville', serif;
    font-size: clamp(22px, 2.5vw, 32px);
    font-weight: 700;
    color: var(--ink-dark);
    margin-bottom: 8px;
}

.specimen-subtitle {
    font-family: 'Libre Baskerville', serif;
    font-size: 16px;
    font-style: italic;
    color: var(--ink-dark);
    opacity: 0.5;
    margin-bottom: 16px;
}

.specimen-body {
    font-family: 'Libre Baskerville', serif;
    font-size: clamp(15px, 1vw, 16px);
    line-height: 1.8;
    color: var(--ink-dark);
}

.specimen-hud {
    width: 100%;
    justify-content: center;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 16px;
}

.specimen-hud .hud-value {
    font-size: 36px;
}

.specimen-details {
    margin-top: 16px;
}

.specimen-details p {
    font-family: 'Special Elite', monospace;
    font-size: 12px;
    color: var(--ink-dark);
    opacity: 0.6;
    margin-bottom: 6px;
}

.specimen-paradox-box {
    background: rgba(240, 230, 216, 0.8);
    border-left: 3px solid var(--brass-gold);
    padding: 16px;
}

.specimen-paradox {
    font-family: 'Special Elite', monospace;
    font-size: 14px;
    color: var(--ink-dark);
    opacity: 0.8;
    line-height: 1.6;
    font-style: italic;
}

.specimen-notes h3 {
    font-family: 'Bebas Neue', sans-serif;
    font-size: 14px;
    letter-spacing: 0.1em;
    color: var(--ink-dark);
    opacity: 0.5;
    margin-bottom: 8px;
}

.specimen-notes-text {
    font-family: 'Libre Baskerville', serif;
    font-size: 13px;
    line-height: 1.7;
    color: var(--ink-dark);
    opacity: 0.6;
}

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

@media (max-width: 768px) {
    :root {
        --sidebar-width: 0px;
    }

    #sidebar {
        transform: translateX(-280px);
        width: 280px;
    }

    #sidebar.visible {
        transform: translateX(0);
        box-shadow: 4px 0 30px rgba(0,0,0,0.5);
    }

    #desk-surface {
        margin-left: 0;
        padding: 40px 20px;
    }

    #lamp-overlay {
        left: 0;
        width: 100%;
    }

    .specimen-journal {
        flex-direction: column;
    }

    .journal-spine {
        width: 100%;
        height: 12px;
    }

    .journal-right {
        width: 100%;
    }
}
