/* ============================================
   RRIDDL.com - Goblincore Manuscript Styles
   ============================================ */

/* --- Color Palette ---
   Deep Ink:    #1C1710
   Parchment:   #F5F0E6
   Foxing:      #B8A070
   Graphite:    #6B6358
   Iron Gall:   #3D3529
   Wax Red:     #8B2D1A
   Mid Parch:   #EDE5D3
   Dark Parch:  #E0D5BF
*/

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

html {
    scroll-behavior: smooth;
    font-size: 18px;
    overflow-x: hidden;
}

body {
    font-family: 'Crimson Pro', Georgia, serif;
    font-weight: 400;
    line-height: 1.75;
    color: #1C1710;
    background: radial-gradient(ellipse at 30% 40%, #F5F0E6 0%, #EDE5D3 60%, #E0D5BF 100%);
    background-attachment: fixed;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* Parchment noise overlay */
body::before {
    content: '';
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 1;
    filter: url(#parchment-noise);
    background: transparent;
    opacity: 0.5;
}

/* --- Typography --- */
h2 {
    font-family: 'Zilla Slab', 'Rockwell', serif;
    font-weight: 700;
    letter-spacing: 0.03em;
    line-height: 1.15;
    color: #1C1710;
}

.fira {
    font-family: 'Fira Mono', 'Courier New', monospace;
    font-weight: 400;
    font-size: 0.85em;
    letter-spacing: 0.05em;
    color: #6B6358;
}

em {
    font-style: italic;
    font-weight: 400;
}

strong {
    font-weight: 600;
}

/* --- Drop Caps --- */
.drop-cap {
    float: left;
    font-family: 'Zilla Slab', serif;
    font-weight: 700;
    font-size: 4em;
    line-height: 0.8;
    padding: 0.05em 0.15em 0 0;
    color: #1C1710;
    position: relative;
    transform: scale(0.8) rotate(-2deg);
    opacity: 0;
    transition: transform 0.6s ease-out, opacity 0.5s ease-out;
}

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

.drop-cap::before {
    content: '';
    position: absolute;
    inset: -4px;
    border: 2px solid #B8A070;
    box-shadow:
        inset 2px 2px 0 #B8A070,
        inset -2px -2px 0 #B8A070,
        3px 3px 0 rgba(184, 160, 112, 0.3);
}

.drop-cap::after {
    content: '';
    position: absolute;
    top: -8px;
    left: -8px;
    width: 12px;
    height: 12px;
    border-top: 2px solid #B8A070;
    border-left: 2px solid #B8A070;
}

/* --- Manuscript Pages (Full-bleed sections) --- */
.manuscript-page {
    min-height: 100vh;
    width: 100%;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    z-index: 2;
}

.page-content {
    max-width: 900px;
    width: 100%;
    position: relative;
}

/* Section ornaments */
.section-ornament {
    margin-top: 3rem;
    text-align: center;
    font-size: 1.4rem;
    color: #B8A070;
    letter-spacing: 0.5em;
    opacity: 0.7;
}

/* --- Scroll Progress Indicator --- */
#scroll-progress {
    position: fixed;
    right: 16px;
    top: 10%;
    height: 80%;
    width: 3px;
    z-index: 100;
}

#scroll-track {
    width: 100%;
    height: 100%;
    background: #E0D5BF;
    border-radius: 2px;
}

#scroll-seal {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #8B2D1A;
    position: absolute;
    left: 50%;
    top: 0;
    transform: translateX(-50%);
    box-shadow: 0 0 6px rgba(139, 45, 26, 0.4);
    transition: top 0.1s linear;
}

/* ============================================
   PAGE 1: THE COVER
   ============================================ */
#cover {
    min-height: 100vh;
    justify-content: center;
}

.cover-title {
    display: flex;
    justify-content: center;
    gap: 0.6rem;
    flex-wrap: wrap;
    margin-bottom: 1.5rem;
}

.illuminated-letter {
    font-family: 'Zilla Slab', serif;
    font-weight: 700;
    font-size: 5rem;
    color: #1C1710;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 5.5rem;
    height: 5.5rem;
    position: relative;
    border: 2px solid #B8A070;
    box-shadow:
        inset 3px 3px 0 rgba(184, 160, 112, 0.3),
        inset -3px -3px 0 rgba(184, 160, 112, 0.3),
        4px 4px 0 rgba(61, 53, 41, 0.15);
    background: rgba(245, 240, 230, 0.5);
    transform: translateY(20px);
    opacity: 0;
    transition: transform 0.6s ease-out, opacity 0.5s ease-out;
}

.illuminated-letter.visible {
    transform: translateY(0);
    opacity: 1;
}

.illuminated-letter:nth-child(1) { transition-delay: 0s; transform: translateY(20px) rotate(-3deg); }
.illuminated-letter:nth-child(2) { transition-delay: 0.1s; transform: translateY(25px) rotate(2deg); }
.illuminated-letter:nth-child(3) { transition-delay: 0.2s; transform: translateY(15px) rotate(-1deg); }
.illuminated-letter:nth-child(4) { transition-delay: 0.25s; transform: translateY(22px) rotate(3deg); }
.illuminated-letter:nth-child(5) { transition-delay: 0.3s; transform: translateY(18px) rotate(-2deg); }
.illuminated-letter:nth-child(6) { transition-delay: 0.35s; transform: translateY(24px) rotate(1deg); }

.illuminated-letter.visible:nth-child(1) { transform: translateY(-5px) rotate(-2deg); }
.illuminated-letter.visible:nth-child(2) { transform: translateY(3px) rotate(1deg); }
.illuminated-letter.visible:nth-child(3) { transform: translateY(-2px) rotate(0deg); }
.illuminated-letter.visible:nth-child(4) { transform: translateY(5px) rotate(2deg); }
.illuminated-letter.visible:nth-child(5) { transform: translateY(-3px) rotate(-1deg); }
.illuminated-letter.visible:nth-child(6) { transform: translateY(2px) rotate(1deg); }

.illuminated-letter::before {
    content: '';
    position: absolute;
    top: -6px;
    left: -6px;
    width: 14px;
    height: 14px;
    border-top: 2px solid #B8A070;
    border-left: 2px solid #B8A070;
}

.illuminated-letter::after {
    content: '';
    position: absolute;
    bottom: -6px;
    right: -6px;
    width: 14px;
    height: 14px;
    border-bottom: 2px solid #B8A070;
    border-right: 2px solid #B8A070;
}

.cover-subtitle {
    text-align: center;
    font-family: 'Crimson Pro', serif;
    font-style: italic;
    font-size: 1.3rem;
    color: #6B6358;
    letter-spacing: 0.15em;
    margin-bottom: 3rem;
    opacity: 0;
    transition: opacity 1s ease-out 0.6s;
}

.cover-subtitle.visible {
    opacity: 1;
}

/* Cabinet of Curiosities */
.riddle-box {
    display: flex;
    justify-content: center;
    margin-bottom: 2rem;
}

.cabinet {
    width: 260px;
    position: relative;
}

.cabinet-top {
    width: 280px;
    height: 12px;
    background: #3D3529;
    border-radius: 3px 3px 0 0;
    margin: 0 auto;
    position: relative;
}

.cabinet-top::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 10px;
    right: 10px;
    height: 4px;
    background: linear-gradient(to bottom, #3D3529, transparent);
}

.cabinet-drawers {
    border: 2px solid #3D3529;
    border-top: none;
    padding: 8px;
    background: rgba(237, 229, 211, 0.5);
}

.drawer-row {
    display: flex;
    gap: 6px;
    margin-bottom: 6px;
}

.drawer-row:last-child {
    margin-bottom: 0;
}

.drawer {
    flex: 1;
    height: 50px;
    border: 1.5px solid #6B6358;
    background: rgba(245, 240, 230, 0.6);
    position: relative;
    cursor: pointer;
    transition: background 0.3s ease, box-shadow 0.3s ease;
}

.drawer::before {
    content: attr(data-label);
    position: absolute;
    top: 4px;
    left: 6px;
    font-family: 'Fira Mono', monospace;
    font-size: 0.55rem;
    color: #B8A070;
    letter-spacing: 0.05em;
}

.drawer::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 16px;
    height: 8px;
    border: 1px solid #6B6358;
    border-radius: 2px;
    background: #B8A070;
    opacity: 0.5;
}

.drawer:hover {
    background: rgba(184, 160, 112, 0.15);
    box-shadow: inset 0 0 8px rgba(184, 160, 112, 0.3);
}

.drawer.large {
    flex: 1.5;
    height: 55px;
}

.cabinet-feet {
    display: flex;
    justify-content: space-between;
    padding: 0 20px;
}

.foot {
    width: 30px;
    height: 12px;
    background: #3D3529;
    border-radius: 0 0 8px 8px;
}

/* Cover marginalia */
.marginalia {
    position: absolute;
    opacity: 0.6;
}

.cover-margin-left {
    left: -80px;
    top: 30%;
    width: 60px;
}

.cover-margin-right {
    right: -70px;
    top: 25%;
    width: 50px;
}

.cover-margin-seal {
    right: -60px;
    bottom: 20%;
    width: 50px;
}

.cover-quill {
    left: -70px;
    bottom: 25%;
    width: 40px;
}

/* ============================================
   PAGE 2: THE INDEX
   ============================================ */
#index .page-content {
    max-width: 680px;
}

.chapter-heading {
    font-size: 2.4rem;
    margin-bottom: 1rem;
    text-align: center;
}

.chapter-epigraph {
    text-align: center;
    color: #6B6358;
    margin-bottom: 2.5rem;
    font-size: 1rem;
    line-height: 1.6;
}

.index-entries {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.index-entry {
    display: flex;
    align-items: baseline;
    padding: 0.8rem 0;
    cursor: pointer;
    position: relative;
}

.entry-title {
    font-family: 'Crimson Pro', serif;
    font-weight: 600;
    font-size: 1.15rem;
    color: #1C1710;
    white-space: nowrap;
    transition: color 0.3s ease;
}

.entry-title::before {
    content: attr(data-chapter) '. ';
    font-family: 'Fira Mono', monospace;
    font-size: 0.8em;
    color: #B8A070;
    margin-right: 0.3em;
}

.index-entry:nth-child(1) .entry-title::before { content: 'I. '; }
.index-entry:nth-child(2) .entry-title::before { content: 'II. '; }
.index-entry:nth-child(3) .entry-title::before { content: 'III. '; }
.index-entry:nth-child(4) .entry-title::before { content: 'IV. '; }
.index-entry:nth-child(5) .entry-title::before { content: 'V. '; }

.leader-line {
    flex: 1;
    height: 1px;
    margin: 0 0.5rem;
    position: relative;
    overflow: hidden;
}

.leader-line::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: radial-gradient(circle, #6B6358 1px, transparent 1px);
    background-size: 8px 3px;
    background-repeat: repeat-x;
    background-position: left center;
    transform-origin: left;
    transform: scaleX(0);
    transition: transform 0.6s ease-out;
}

.index-entry:hover .leader-line::after,
.index-entry.leader-visible .leader-line::after {
    transform: scaleX(1);
}

.entry-page {
    font-family: 'Fira Mono', monospace;
    font-size: 0.8rem;
    color: #B8A070;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.index-entry:hover .entry-title {
    color: #8B2D1A;
}

/* Marginal notes for index */
.marginal-note {
    position: absolute;
    width: 140px;
    font-size: 0.75rem;
    color: #6B6358;
    font-style: italic;
    line-height: 1.4;
}

.index-margin-left {
    left: -180px;
    top: 50%;
}

.index-margin-right {
    right: -180px;
    top: 65%;
}

.note-connector {
    display: block;
    width: 30px;
    border-bottom: 1px dotted #B8A070;
    margin-bottom: 4px;
}

.index-margin-left .note-connector {
    margin-left: auto;
}

/* ============================================
   PAGE 3: THE BESTIARY
   ============================================ */
#bestiary .page-content {
    max-width: 1000px;
}

.specimen-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-top: 1rem;
}

.specimen-card {
    opacity: 0;
    transform: translateY(20px);
    transition: opacity 0.8s ease-out, transform 0.8s ease-out;
}

.specimen-card.visible {
    opacity: 1;
    transform: translateY(0);
}

.specimen-card:nth-child(1) { transition-delay: 0s; }
.specimen-card:nth-child(2) { transition-delay: 0.15s; transform: translateY(30px); }
.specimen-card:nth-child(3) { transition-delay: 0.25s; }
.specimen-card:nth-child(4) { transition-delay: 0.35s; transform: translateY(25px); }

.specimen-card-wide {
    grid-column: 1 / -1;
    transition-delay: 0.45s;
}

/* Irregular alignment: odd cards shifted slightly */
.specimen-card:nth-child(odd) {
    margin-top: 1rem;
}

.specimen-card:nth-child(even) {
    margin-top: -0.5rem;
}

.specimen-frame {
    border: 2px solid #3D3529;
    padding: 1.2rem;
    background: rgba(245, 240, 230, 0.4);
    position: relative;
}

.specimen-frame::before {
    content: '';
    position: absolute;
    inset: 4px;
    border: 1px solid #6B6358;
    pointer-events: none;
}

.specimen-illustration {
    display: flex;
    justify-content: center;
    padding: 1rem 0;
    filter: grayscale(100%) sepia(30%) contrast(1.2);
}

.specimen-svg {
    width: 140px;
    height: 140px;
}

.specimen-card-wide .specimen-svg {
    width: 240px;
    height: 120px;
}

.specimen-label {
    border-top: 1px solid #6B6358;
    padding-top: 0.8rem;
    text-align: center;
}

.specimen-number {
    display: block;
    font-family: 'Fira Mono', monospace;
    font-size: 0.75rem;
    color: #B8A070;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    margin-bottom: 0.3rem;
}

.specimen-name {
    display: block;
    font-family: 'Crimson Pro', serif;
    font-size: 1.1rem;
    color: #1C1710;
    margin-bottom: 0.4rem;
}

.specimen-desc {
    display: block;
    font-size: 0.85rem;
    color: #6B6358;
    line-height: 1.5;
}

/* ============================================
   PAGE 4: THE MARGINALIA
   ============================================ */
#marginalia .page-content {
    display: grid;
    grid-template-columns: 1fr 2.5fr 1fr;
    gap: 2rem;
    max-width: 1100px;
    align-items: start;
}

.marginalia-left-column,
.marginalia-right-column {
    padding-top: 4rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    align-items: center;
}

.marginalia-center-column {
    max-width: 680px;
    margin: 0 auto;
}

.manuscript-text p {
    margin-bottom: 1.5rem;
    text-align: justify;
    hyphens: auto;
}

/* Ink-spread reveal for text */
.manuscript-text p {
    opacity: 0;
    clip-path: circle(0% at 50% 50%);
    transition: opacity 1.2s ease-out, clip-path 1.2s ease-out;
}

.manuscript-text p.text-visible {
    opacity: 1;
    clip-path: circle(100% at 50% 50%);
}

.riddle-prompt {
    text-align: center;
    padding: 1.5rem 2rem;
    border-top: 1px solid #B8A070;
    border-bottom: 1px solid #B8A070;
    margin: 2rem 0;
    position: relative;
}

.riddle-prompt::before,
.riddle-prompt::after {
    content: '✻';
    position: absolute;
    color: #B8A070;
    font-size: 0.8rem;
}

.riddle-prompt::before {
    top: -0.5em;
    left: 50%;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at 50% 50%, #F5F0E6 0%, #EDE5D3 100%);
    padding: 0 0.5em;
}

.riddle-prompt::after {
    bottom: -0.5em;
    left: 50%;
    transform: translateX(-50%);
    background: radial-gradient(ellipse at 50% 50%, #F5F0E6 0%, #EDE5D3 100%);
    padding: 0 0.5em;
}

/* Margin creatures */
.margin-creature {
    width: 50px;
    opacity: 0.5;
    transition: opacity 0.5s ease;
}

.margin-creature.active {
    opacity: 0.8;
}

.creature-svg {
    width: 100%;
    height: auto;
}

/* Creature animations */
.moth-anim.active svg {
    animation: moth-flutter 2s ease-in-out infinite;
}

@keyframes moth-flutter {
    0%, 100% { transform: translateY(0) rotate(0deg); }
    25% { transform: translateY(-5px) rotate(3deg); }
    50% { transform: translateY(-2px) rotate(-2deg); }
    75% { transform: translateY(-7px) rotate(1deg); }
}

.mushroom-anim.active svg {
    animation: mushroom-grow 3s ease-out forwards;
}

@keyframes mushroom-grow {
    0% { transform: scaleY(0.5); transform-origin: bottom; opacity: 0.3; }
    100% { transform: scaleY(1); transform-origin: bottom; opacity: 1; }
}

.bookworm-anim.active svg {
    animation: bookworm-inch 4s ease-in-out infinite;
}

@keyframes bookworm-inch {
    0%, 100% { transform: translateY(0); }
    25% { transform: translateY(-8px) scaleY(0.9); }
    50% { transform: translateY(-4px) scaleY(1.1); }
    75% { transform: translateY(-12px) scaleY(0.95); }
}

.scholar-anim.active svg {
    animation: scholar-read 5s ease-in-out infinite;
}

@keyframes scholar-read {
    0%, 100% { transform: rotate(0deg); }
    30% { transform: rotate(-3deg); }
    60% { transform: rotate(2deg); }
}

/* Margin annotations */
.margin-annotation {
    font-size: 0.72rem;
    color: #6B6358;
    font-style: italic;
    line-height: 1.4;
    text-align: center;
    max-width: 120px;
}

.annotation-mark {
    display: block;
    font-size: 1rem;
    color: #B8A070;
    font-style: normal;
    margin-bottom: 0.2rem;
}

/* ============================================
   PAGE 5: THE COLOPHON
   ============================================ */
#colophon {
    min-height: 100vh;
    justify-content: center;
}

.colophon-heading {
    margin-bottom: 2rem;
}

.colophon-body {
    max-width: 600px;
    margin: 0 auto;
    text-align: center;
}

.colophon-text {
    margin-bottom: 1.5rem;
    font-size: 0.95rem;
    color: #3D3529;
    line-height: 1.8;
    text-align: center;
}

.printers-mark {
    font-size: 2rem;
    color: #B8A070;
    margin-bottom: 2rem;
    letter-spacing: 0.5em;
}

.colophon-ornament {
    font-size: 1.8rem;
    color: #B8A070;
    margin: 2rem 0;
}

/* Wax Seal */
.wax-seal {
    display: flex;
    justify-content: center;
    margin: 2rem 0;
    transform: scale(1.3) rotate(-15deg);
    opacity: 0;
    transition: transform 0.8s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.6s ease-out;
}

.wax-seal.stamped {
    transform: scale(1) rotate(0deg);
    opacity: 1;
}

.seal-svg {
    width: 120px;
    height: 120px;
    filter: drop-shadow(0 4px 12px rgba(139, 45, 26, 0));
    transition: filter 0.8s ease-out;
}

.wax-seal.stamped .seal-svg {
    filter: drop-shadow(0 4px 12px rgba(139, 45, 26, 0.4));
}

.colophon-final {
    margin-top: 2rem;
    font-size: 0.8rem;
    letter-spacing: 0.15em;
}

/* ============================================
   TRAVELING BEETLE
   ============================================ */
#traveling-beetle {
    position: fixed;
    bottom: 12px;
    left: -50px;
    z-index: 50;
    width: 35px;
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.beetle-traveler {
    width: 100%;
    height: auto;
}

/* ============================================
   INK BLOT EFFECTS
   ============================================ */
.ink-blot {
    position: absolute;
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(28, 23, 16, 0.15) 0%, transparent 70%);
    transform: scale(0);
    transition: transform 1.5s ease-out;
    pointer-events: none;
}

.ink-blot.spread {
    transform: scale(1);
}

/* ============================================
   RESPONSIVE
   ============================================ */
@media (max-width: 900px) {
    html {
        font-size: 16px;
    }

    .illuminated-letter {
        font-size: 3.5rem;
        width: 4rem;
        height: 4rem;
    }

    .marginalia {
        display: none;
    }

    .marginal-note {
        display: none;
    }

    #marginalia .page-content {
        grid-template-columns: 1fr;
    }

    .marginalia-left-column,
    .marginalia-right-column {
        flex-direction: row;
        justify-content: center;
        padding-top: 1rem;
    }

    .specimen-grid {
        grid-template-columns: 1fr;
    }

    .specimen-card-wide {
        grid-column: 1;
    }

    .specimen-card:nth-child(odd),
    .specimen-card:nth-child(even) {
        margin-top: 0;
    }
}

@media (max-width: 600px) {
    .manuscript-page {
        padding: 3rem 1.2rem;
    }

    .illuminated-letter {
        font-size: 2.5rem;
        width: 3rem;
        height: 3rem;
    }

    .cover-title {
        gap: 0.3rem;
    }

    .chapter-heading {
        font-size: 1.8rem;
    }

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

    #scroll-progress {
        display: none;
    }
}

/* ============================================
   FOXING STAINS (decorative background marks)
   ============================================ */
.manuscript-page::before {
    content: '';
    position: absolute;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(184, 160, 112, 0.08) 0%, transparent 70%);
    pointer-events: none;
}

#cover::before {
    top: 15%;
    right: 8%;
    width: 180px;
    height: 180px;
}

#index::before {
    bottom: 10%;
    left: 5%;
    width: 150px;
    height: 150px;
}

#bestiary::before {
    top: 20%;
    left: 10%;
}

#marginalia::before {
    top: 8%;
    right: 12%;
    width: 200px;
    height: 200px;
}

#colophon::before {
    bottom: 15%;
    left: 8%;
    width: 160px;
    height: 160px;
}

/* Additional foxing stains */
.manuscript-page::after {
    content: '';
    position: absolute;
    width: 90px;
    height: 90px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(184, 160, 112, 0.06) 0%, transparent 70%);
    pointer-events: none;
}

#cover::after {
    bottom: 20%;
    left: 12%;
}

#index::after {
    top: 15%;
    right: 10%;
    width: 110px;
    height: 110px;
}

#bestiary::after {
    bottom: 12%;
    right: 15%;
    width: 130px;
    height: 130px;
}

#marginalia::after {
    bottom: 20%;
    left: 5%;
}

#colophon::after {
    top: 10%;
    right: 15%;
    width: 100px;
    height: 100px;
}
