/* The Library — homepage styles for The Haunting Project */

* { box-sizing: border-box; }

body {
    margin: 0;
    min-height: 100vh;
    background: radial-gradient(ellipse at 50% -10%, #16100d 0%, #0b0806 45%, #050403 100%);
    color: #cfc4b0;
    font-family: Georgia, 'Times New Roman', serif;
    overflow-x: hidden;
}

.candle-glow {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background: radial-gradient(ellipse at 50% 110%, rgba(216, 170, 90, 0.06), transparent 55%);
    animation: flicker 7s ease-in-out infinite;
}

@keyframes flicker {
    0%, 100% { opacity: 0.9; }
    48% { opacity: 0.6; }
    52% { opacity: 0.85; }
    70% { opacity: 0.55; }
}

.library {
    position: relative;
    z-index: 1;
    max-width: 980px;
    margin: 0 auto;
    padding: 56px 24px 80px;
}

/* Hero */
.library-hero {
    text-align: center;
    margin-bottom: 64px;
}

.library-hero h1 {
    font-family: 'IM Fell English', Georgia, serif;
    font-weight: 400;
    font-size: clamp(2.6rem, 8vw, 4.2rem);
    letter-spacing: 4px;
    margin: 0;
    color: #d8cdb8;
    text-shadow: 0 0 32px rgba(216, 205, 184, 0.14);
}

.library-hero .library-tagline {
    font-style: italic;
    color: #8a7d68;
    margin-top: 12px;
    font-size: 1.05rem;
}

/* The shelf */
.shelf-section h2,
.pages-section h2 {
    font-family: 'IM Fell English', Georgia, serif;
    font-weight: 400;
    text-align: center;
    font-size: 1.6rem;
    letter-spacing: 3px;
    color: #b3a68e;
    margin: 0 0 6px;
}

.section-lore {
    text-align: center;
    color: #8a7d68;
    font-style: italic;
    max-width: 560px;
    margin: 0 auto 44px;
    line-height: 1.7;
    font-size: 0.95rem;
}

.shelf {
    display: flex;
    justify-content: center;
    align-items: flex-end;
    gap: 48px;
    flex-wrap: wrap;
    perspective: 1200px;
    padding: 0 12px 26px;
    position: relative;
}

.shelf::after {
    /* the wooden plank */
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 0;
    width: min(860px, 100%);
    height: 14px;
    background: linear-gradient(180deg, #2a1d12, #17100a 70%, #0b0806);
    border-radius: 3px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
}

.grimoire-slot {
    text-align: center;
    width: 190px;
}

.grimoire {
    position: relative;
    width: 170px;
    height: 250px;
    margin: 0 auto;
    border-radius: 4px 10px 10px 4px;
    transform-style: preserve-3d;
    transition: transform 0.55s cubic-bezier(0.2, 0.8, 0.3, 1), box-shadow 0.55s ease;
    cursor: pointer;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.75);
}

.grimoire::before {
    /* spine */
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 14px;
    border-radius: 4px 0 0 4px;
    background: linear-gradient(90deg, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.1));
}

.grimoire::after {
    /* page block */
    content: "";
    position: absolute;
    right: -5px;
    top: 6px;
    bottom: 6px;
    width: 5px;
    border-radius: 0 2px 2px 0;
    background: repeating-linear-gradient(180deg, #b9ac93 0 2px, #8f8570 2px 3px);
    opacity: 0.85;
}

.grimoire-title {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 18px;
    font-family: 'IM Fell English', Georgia, serif;
    letter-spacing: 2px;
    text-align: center;
}

.grimoire-slot .slot-label {
    margin-top: 22px;
    font-size: 0.95rem;
    color: #b3a68e;
}

.grimoire-slot .slot-status {
    font-size: 0.72rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: #6f6353;
    margin-top: 4px;
}

/* The Unwritten — pale, faintly luminous, restless */
.grimoire.unwritten {
    background:
        radial-gradient(ellipse at 30% 20%, rgba(216, 205, 184, 0.16), transparent 60%),
        linear-gradient(160deg, #3d3628 0%, #241f16 55%, #171310 100%);
    animation: breathe 9s ease-in-out infinite;
}

.grimoire.unwritten .grimoire-title {
    color: #e8dfca;
    text-shadow: 0 0 14px rgba(232, 223, 202, 0.35);
}

.grimoire.unwritten .glyphs {
    font-size: 0.8rem;
    letter-spacing: 4px;
    color: #9a8d74;
    margin-top: 10px;
    min-height: 1.2em;
}

.grimoire.unwritten:hover {
    transform: translateY(-16px) rotateY(-14deg) rotateZ(-1.5deg) scale(1.05);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.85), 0 0 60px rgba(216, 205, 184, 0.16);
}

@keyframes breathe {
    0%, 100% { box-shadow: 0 18px 40px rgba(0, 0, 0, 0.75); }
    50% { box-shadow: 0 18px 40px rgba(0, 0, 0, 0.75), 0 0 34px rgba(216, 205, 184, 0.10); }
}

/* The Unbound — the archive; stuffed with loose pages, tied with cord */
.grimoire.unbound {
    background:
        linear-gradient(0deg, transparent 0 46%, rgba(90, 74, 52, 0.55) 46% 52%, transparent 52%),
        radial-gradient(ellipse at 70% 15%, rgba(150, 120, 80, 0.14), transparent 55%),
        linear-gradient(160deg, #34281a 0%, #201709 55%, #140e08 100%);
}

.grimoire.unbound .grimoire-title {
    color: #cbbc9d;
    text-shadow: 0 0 12px rgba(203, 188, 157, 0.2);
}

.grimoire.unbound::after {
    /* an overstuffed, uneven page block */
    right: -8px;
    top: 3px;
    bottom: 3px;
    width: 8px;
    background: repeating-linear-gradient(180deg, #c4b393 0 3px, #8f8570 3px 4px, #a99b7d 4px 7px);
    opacity: 0.95;
}

.grimoire.unbound .loose-slip {
    position: absolute;
    right: -10px;
    width: 30px;
    height: 12px;
    background: linear-gradient(90deg, #b3a483, #8f8168);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
    transition: transform 0.5s cubic-bezier(0.2, 0.8, 0.3, 1);
}

.grimoire.unbound .slip-1 { top: 14%; transform: rotate(4deg); }
.grimoire.unbound .slip-2 { top: 47%; transform: rotate(-3deg); }
.grimoire.unbound .slip-3 { top: 78%; transform: rotate(6deg); }

.grimoire.unbound:hover {
    transform: translateY(-16px) rotateY(-14deg) rotateZ(1.5deg) scale(1.05);
    box-shadow: 0 30px 60px rgba(0, 0, 0, 0.85), 0 0 44px rgba(203, 188, 157, 0.1);
}

.grimoire.unbound:hover .slip-1 { transform: rotate(9deg) translateX(7px); }
.grimoire.unbound:hover .slip-2 { transform: rotate(-8deg) translateX(10px); }
.grimoire.unbound:hover .slip-3 { transform: rotate(12deg) translateX(6px); }

/* Sealed grimoire — bound in iron */
.grimoire.sealed-iron {
    background:
        linear-gradient(90deg, transparent 0 30%, rgba(20, 18, 16, 0.9) 30% 38%, transparent 38% 62%, rgba(20, 18, 16, 0.9) 62% 70%, transparent 70%),
        linear-gradient(160deg, #26211c 0%, #14100d 60%, #0a0806 100%);
    cursor: not-allowed;
}

.grimoire.sealed-iron .grimoire-title { color: #4a423a; }

.grimoire.sealed-iron:hover {
    transform: translateY(-4px);
    animation: heartbeat 1.6s ease-in-out infinite;
}

@keyframes heartbeat {
    0%, 100% { box-shadow: 0 18px 40px rgba(0, 0, 0, 0.75); }
    12% { box-shadow: 0 18px 40px rgba(0, 0, 0, 0.75), 0 0 26px rgba(120, 30, 20, 0.25); }
    24% { box-shadow: 0 18px 40px rgba(0, 0, 0, 0.75); }
    36% { box-shadow: 0 18px 40px rgba(0, 0, 0, 0.75), 0 0 34px rgba(120, 30, 20, 0.32); }
}

/* Sealed grimoire — wax seal */
.grimoire.sealed-wax {
    background: linear-gradient(160deg, #2c1a16 0%, #1a0f0c 60%, #0d0705 100%);
    cursor: not-allowed;
}

.grimoire.sealed-wax .grimoire-title { color: #52362f; }

.grimoire.sealed-wax .wax {
    position: absolute;
    left: 50%;
    top: 58%;
    transform: translate(-50%, -50%);
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: radial-gradient(circle at 35% 30%, #7d2a20, #4d150f 65%, #350d09);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.7), inset 0 0 10px rgba(0, 0, 0, 0.5);
}

.grimoire.sealed-wax:hover {
    animation: shudder 0.45s linear infinite;
}

@keyframes shudder {
    0%, 100% { transform: translate(0, -4px); }
    25% { transform: translate(-1.5px, -4px) rotateZ(-0.4deg); }
    75% { transform: translate(1.5px, -4px) rotateZ(0.4deg); }
}

/* Loose pages */
.pages-section { margin-top: 88px; }

.pages-countdown {
    text-align: center;
    font-size: 0.8rem;
    letter-spacing: 3px;
    text-transform: uppercase;
    color: #6f6353;
    margin: 52px 0 0;
}

.drawers {
    display: flex;
    justify-content: center;
    gap: 18px;
    flex-wrap: wrap;
}

.drawer {
    display: block;
    text-decoration: none;
    width: 168px;
    padding: 18px 16px 14px;
    border: 1px solid rgba(138, 125, 104, 0.22);
    background: linear-gradient(180deg, rgba(30, 23, 17, 0.75), rgba(13, 10, 7, 0.6));
    color: #b3a68e;
    text-align: center;
    transition: border-color 0.4s ease, transform 0.4s ease, box-shadow 0.4s ease;
}

.drawer:hover {
    border-color: rgba(216, 205, 184, 0.45);
    transform: translateY(-4px);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.6);
}

.drawer .drawer-year {
    font-family: 'IM Fell English', Georgia, serif;
    font-size: 1.4rem;
    color: #d8cdb8;
}

.drawer .drawer-count {
    display: block;
    font-size: 0.75rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    color: #6f6353;
    margin-top: 6px;
}

/* Footer */
.library-footer {
    margin-top: 96px;
    text-align: center;
    color: #6f6353;
    font-size: 0.85rem;
    line-height: 1.8;
}

.library-footer .lore-description {
    max-width: 640px;
    margin: 0 auto 24px;
    font-style: italic;
    opacity: 0.8;
}

.library-footer a {
    color: #8a7d68;
    text-decoration: none;
}

.library-footer a:hover { color: #cfc4b0; }

@media (prefers-reduced-motion: reduce) {
    .candle-glow,
    .grimoire,
    .grimoire:hover,
    .drawer { animation: none !important; transition: none !important; }
}

@media (max-width: 640px) {
    .shelf { gap: 30px; }
    .grimoire-slot { width: 150px; }
    .grimoire { width: 136px; height: 204px; }
}
