/* ============================================
   mujun.wiki -- Wabi-Sabi Knowledge Repository
   ============================================ */

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

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

body {
    font-family: 'Lora', serif;
    font-weight: 400;
    font-size: clamp(1rem, 1.7vw, 1.12rem);
    line-height: 1.9;
    color: #C8A0A8;
    background-color: #3A0E1A;
    overflow-x: hidden;
    transition: background-color 1.5s ease;
}

/* --- Typography --- */
h1 {
    font-family: 'Playfair Display', serif;
    font-weight: 700;
    font-size: clamp(2.4rem, 7vw, 5rem);
    letter-spacing: 0.03em;
    color: #E8D0D8;
    line-height: 1.15;
}

h2 {
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.4rem, 3.5vw, 2.4rem);
    letter-spacing: 0.02em;
    color: #E8D0D8;
    line-height: 1.3;
}

p {
    color: #C8A0A8;
    margin-top: 1em;
}

em {
    font-style: italic;
}

/* --- Wabi-Sabi Texture Overlay --- */
#texture-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1000;
    opacity: 0.08;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='100' height='100'%3E%3Ccircle cx='12' cy='15' r='0.8' fill='%235A2030'/%3E%3Ccircle cx='45' cy='8' r='0.6' fill='%235A2030'/%3E%3Ccircle cx='78' cy='22' r='0.9' fill='%235A2030'/%3E%3Ccircle cx='30' cy='55' r='0.7' fill='%235A2030'/%3E%3Ccircle cx='65' cy='48' r='0.5' fill='%235A2030'/%3E%3Ccircle cx='88' cy='70' r='0.8' fill='%235A2030'/%3E%3Ccircle cx='15' cy='82' r='0.6' fill='%235A2030'/%3E%3Ccircle cx='52' cy='90' r='0.9' fill='%235A2030'/%3E%3Cline x1='20' y1='35' x2='28' y2='37' stroke='%235A2030' stroke-width='0.5'/%3E%3Cline x1='60' y1='62' x2='68' y2='60' stroke='%235A2030' stroke-width='0.5'/%3E%3Cline x1='40' y1='75' x2='47' y2='78' stroke='%235A2030' stroke-width='0.5'/%3E%3C/svg%3E");
    background-repeat: repeat;
}

/* --- Chapter Base --- */
.chapter {
    min-height: 100vh;
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 1.5s ease;
}

.chapter-1 { background-color: #3A0E1A; }
.chapter-2 { background-color: #2A0810; }
.chapter-3 { background-color: #0A0408; }
.chapter-4 { background-color: #0A0408; }

.chapter-inner {
    position: relative;
    width: 100%;
    max-width: 900px;
    padding: 80px 40px;
    z-index: 2;
}

.chapter-title {
    text-align: center;
    margin-bottom: 60px;
}

/* --- Entry IDs (Metadata) --- */
.entry-id {
    font-family: 'IBM Plex Mono', monospace;
    font-weight: 400;
    font-size: 0.75rem;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #8A5A6A;
    display: block;
    margin-bottom: 8px;
}

/* --- Redacted Text --- */
.redacted {
    background: #5A2030;
    color: transparent;
    border-radius: 2px;
    padding: 0 8px;
    display: inline-block;
    min-width: 100px;
}

h2.redacted {
    min-width: 180px;
    height: 1.4em;
    display: inline-block;
}

/* --- Trailing Text --- */
.trailing {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 70%;
}

p.trailing {
    white-space: normal;
}

/* =============================================
   CHAPTER I -- The Imperfect Index
   ============================================= */

/* Spine Line */
.spine-line {
    position: absolute;
    left: 50%;
    top: 0;
    bottom: 0;
    width: 1px;
    background-color: rgba(200, 160, 168, 0.5);
    transform: translateX(-50%);
    z-index: 0;
}

/* Index Entries */
.index-entries {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 36px;
}

.index-entry {
    position: relative;
    max-width: 50%;
    padding: 12px 24px;
}

.entry-left {
    align-self: flex-start;
    text-align: right;
    margin-right: auto;
}

.entry-right {
    align-self: flex-end;
    text-align: left;
    margin-left: auto;
}

.index-entry .entry-title {
    font-family: 'Playfair Display', serif;
    font-weight: 400;
    font-style: italic;
    font-size: clamp(1.1rem, 2.5vw, 1.6rem);
    color: #E8D0D8;
    display: block;
}

.index-entry .entry-id {
    margin-bottom: 6px;
}

/* Neon glow underline */
.entry-glow {
    display: block;
    height: 1px;
    margin-top: 8px;
    background: #FF6B8A;
    opacity: 0.6;
    filter: blur(0.5px);
    animation: glowPulseIrregular var(--pulse-duration, 3s) ease-in-out infinite alternate;
}

@keyframes glowPulseIrregular {
    0% { opacity: 0.3; }
    30% { opacity: 0.7; }
    60% { opacity: 0.4; }
    100% { opacity: 0.65; }
}

/* =============================================
   CHAPTER II -- The Knowledge Cracks
   ============================================= */

.cracked-grid {
    display: flex;
    flex-direction: column;
    gap: 80px;
}

.cracked-container {
    position: relative;
    padding: 48px 40px;
    background-color: rgba(58, 14, 26, 0.4);
}

.cracked-variant-1 {
    clip-path: polygon(2% 0%, 98% 3%, 100% 45%, 95% 48%, 97% 100%, 5% 97%, 0% 55%, 3% 50%);
}

.cracked-variant-2 {
    clip-path: polygon(0% 2%, 96% 0%, 100% 52%, 98% 55%, 100% 98%, 3% 100%, 0% 48%, 2% 45%);
}

.cracked-variant-3 {
    clip-path: polygon(3% 0%, 100% 2%, 97% 50%, 100% 53%, 98% 100%, 0% 97%, 2% 52%, 0% 48%);
}

/* Crack Glow Behind Containers */
.crack-glow {
    position: absolute;
    top: -40px;
    left: -40px;
    right: -40px;
    bottom: -40px;
    z-index: -1;
    filter: blur(20px);
    animation: glowPulse 4s ease-in-out infinite alternate;
}

.glow-pink {
    background: radial-gradient(ellipse at center, #FF6B8A 0%, transparent 70%);
}

.glow-cyan {
    background: radial-gradient(ellipse at center, #8AE0FF 0%, transparent 70%);
}

@keyframes glowPulse {
    from { opacity: 0.4; }
    to { opacity: 0.7; }
}

.cracked-content {
    position: relative;
    z-index: 2;
}

.cracked-content h2 {
    margin-bottom: 12px;
    margin-top: 0;
}

/* =============================================
   CHAPTER III -- The Crystalline Archive
   ============================================= */

.archive-stream {
    display: flex;
    flex-direction: column;
}

.archive-entry {
    padding: 40px 0;
}

.archive-entry h2 {
    margin-bottom: 8px;
}

/* Glitch Dividers */
.glitch-divider {
    border: none;
    height: 1px;
    background-color: #5A2030;
    margin: 40px 0;
    position: relative;
    animation: glitchLine 6s infinite;
}

@keyframes glitchLine {
    0%, 90%, 100% {
        transform: translateX(0);
        filter: none;
    }
    92% {
        transform: translateX(-3px);
        filter: drop-shadow(3px 0 #FF6B8A) drop-shadow(-3px 0 #8AE0FF);
    }
    94% {
        transform: translateX(3px);
        filter: drop-shadow(-3px 0 #FF6B8A) drop-shadow(3px 0 #8AE0FF);
    }
}

/* Crystalline SVG Clusters */
.crystal-cluster {
    position: absolute;
    pointer-events: none;
    z-index: 1;
}

.crystal-left {
    left: -80px;
}

.crystal-right {
    right: -80px;
}

.crystal-sm {
    width: 80px;
    height: 80px;
    top: 10%;
}

.crystal-md {
    width: 140px;
    height: 140px;
    top: 40%;
}

.crystal-lg {
    width: 200px;
    height: 200px;
    top: 70%;
}

.crystal-cluster polygon {
    filter: drop-shadow(0 0 4px rgba(255, 107, 138, 0.5));
}

/* =============================================
   CHAPTER IV -- The Unfinished Page
   ============================================= */

.chapter-4 {
    min-height: 100vh;
    display: flex;
    align-items: flex-start;
    padding-top: 10vh;
}

.chapter-4 .chapter-inner {
    padding-bottom: 60px;
}

.unfinished-content {
    display: flex;
    flex-direction: column;
    gap: 48px;
}

.fading-entry {
    transition: opacity 0.3s ease;
}

.fading-1 {
    opacity: 0.85;
}

.fading-2 {
    opacity: 0.55;
}

.fading-3 {
    opacity: 0.3;
}

.fading-4 {
    opacity: 0.12;
}

.fading-entry h2 {
    margin-bottom: 8px;
}

/* Final Glow Dot */
.final-glow-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #FF6B8A;
    margin: 80px auto 0;
    box-shadow: 0 0 12px #FF6B8A, 0 0 24px #FF6B8A, 0 0 48px rgba(255, 107, 138, 0.4);
    animation: dotPulse 3s ease-in-out infinite;
}

@keyframes dotPulse {
    0%, 100% {
        opacity: 0.4;
        box-shadow: 0 0 8px #FF6B8A, 0 0 16px rgba(255, 107, 138, 0.3);
    }
    50% {
        opacity: 1;
        box-shadow: 0 0 16px #FF6B8A, 0 0 32px #FF6B8A, 0 0 64px rgba(255, 107, 138, 0.5);
    }
}

/* =============================================
   Responsive
   ============================================= */

@media (max-width: 768px) {
    .chapter-inner {
        padding: 60px 24px;
        max-width: 100%;
    }

    .index-entry {
        max-width: 85%;
    }

    .entry-left,
    .entry-right {
        text-align: left;
        margin-left: 0;
        margin-right: 0;
        align-self: flex-start;
    }

    .spine-line {
        left: 20px;
    }

    .cracked-container {
        padding: 36px 24px;
    }

    .crystal-cluster {
        display: none;
    }

    .chapter-title {
        margin-bottom: 40px;
    }
}

@media (max-width: 480px) {
    .chapter-inner {
        padding: 40px 16px;
        max-width: 100%;
    }

    .index-entry {
        max-width: 95%;
        padding: 8px 12px;
    }

    .cracked-container {
        padding: 24px 16px;
    }

    .index-entries {
        gap: 24px;
    }

    .chapter-title {
        margin-bottom: 32px;
    }

    h1 {
        font-size: clamp(1.8rem, 5vw, 3rem);
    }

    h2 {
        font-size: clamp(1rem, 2.5vw, 1.6rem);
    }
}
