:root {
    --color-press: #FFD700;
    --color-press-rgb: 255, 215, 0;
    --bg-color: #0a0a0a;
    --text-color: #f0f0f0;
    --text-secondary: #a0a0a0;
    --error-color: #ff4444;

    --font-heading: 'Syne', sans-serif;
    --font-body: 'Inter', sans-serif;

    --shelf-height: 250px;
    --book-height: 200px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-body);
    overflow: hidden;
    /* Prevent scrolling for the bookshelf app */
    height: 100vh;
    width: 100vw;
}

/* Transitions */
.hidden {
    display: none !important;
}

/* Login Screen (Glassmorphism) */
.unlock-container {
    position: fixed;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: radial-gradient(circle at center, rgba(var(--color-press-rgb), 0.1) 0%, #000 100%);
    z-index: 2000;
    transition: opacity 0.8s ease, transform 0.8s ease;
}

.unlock-container.fade-out {
    opacity: 0;
    transform: scale(1.1);
    pointer-events: none;
}

.unlock-glass {
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 3rem;
    border-radius: 24px;
    width: 90%;
    max-width: 400px;
    text-align: center;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
}

.branding {
    margin-bottom: 2rem;
}

.brand-sub {
    font-family: var(--font-heading);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.4em;
    color: var(--color-press);
    display: block;
    margin-bottom: 0.2rem;
}

.logo {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 2.5rem;
    text-transform: uppercase;
    color: #fff;
    letter-spacing: 0.1em;
    text-shadow: 0 0 20px rgba(var(--color-press-rgb), 0.3);
    animation: logo-glow 4s infinite alternate;
}

@keyframes logo-glow {
    from {
        text-shadow: 0 0 10px rgba(var(--color-press-rgb), 0.2);
    }

    to {
        text-shadow: 0 0 30px rgba(var(--color-press-rgb), 0.6);
    }
}

.unlock-instruction {
    color: var(--text-secondary);
    margin-bottom: 2rem;
    font-size: 0.95rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

#password-input {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 1rem;
    border-radius: 12px;
    color: #fff;
    font-family: inherit;
    font-size: 1rem;
    text-align: center;
    transition: all 0.3s;
}

#password-input:focus {
    outline: none;
    border-color: var(--color-press);
    background: rgba(255, 255, 255, 0.08);
}

#unlock-button {
    background: var(--color-press);
    color: #000;
    border: none;
    padding: 1rem;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

#unlock-button:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(var(--color-press-rgb), 0.3);
}

.error-message {
    color: var(--error-color);
    margin-top: 1rem;
    font-size: 0.85rem;
    opacity: 0;
    transition: opacity 0.3s;
}

.error-message.show {
    opacity: 1;
}

/* Library Content Container */
.content-container {
    height: 100vh;
    display: flex;
    flex-direction: column;
    padding: 2rem;
    opacity: 0;
    transition: opacity 1s ease;
}

.content-container.visible {
    opacity: 1;
}

.library-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 3rem;
}

.library-hint {
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 2rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--color-press);
    text-shadow: 0 0 20px rgba(var(--color-press-rgb), 0.3);
}

/* Bookshelf Scene */
.bookshelf-scene {
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    perspective: 1000px;
}

.bookshelf {
    width: 95%;
    max-width: 1200px;
    height: 50vh;
    border-left: 4px solid rgba(255, 255, 255, 0.05);
    border-right: 4px solid rgba(255, 255, 255, 0.05);
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.01) 0%, rgba(255, 255, 255, 0.03) 100%);
    position: relative;
    padding: 0 10px;
    border-bottom: 20px solid #111;
}

.shelf {
    position: absolute;
    bottom: 0;
    left: -10px;
    right: -10px;
    height: 12px;
    background: linear-gradient(to bottom, #2a2a2a 0%, #1a1a1a 100%);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8);
    border-radius: 2px;
}

/* Books */
.book {
    position: absolute;
    /* No transitions here, Matter.js handles the motion */
    cursor: grab;
    user-select: none;
    display: flex;
    align-items: flex-end;
    /* Title at bottom of spine usually */
    transform-origin: center center;
    will-change: transform;
}

.book:active {
    cursor: grabbing;
}

.book-spine {
    width: 100%;
    height: 100%;
    border-radius: 3px 3px 0 0;
    display: flex;
    justify-content: flex-start;
    /* Title starts from top */
    align-items: center;
    padding: 15px 5px;
    box-shadow: inset -2px 0 5px rgba(0, 0, 0, 0.3), 2px 0 5px rgba(0, 0, 0, 0.2);
    writing-mode: vertical-rl;
    text-orientation: mixed;
    color: rgba(0, 0, 0, 0.8);
    font-weight: 700;
    font-family: var(--font-heading);
    text-transform: uppercase;
    font-size: 0.7rem;
    border: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-ghost {
    position: absolute;
    border: 2px dashed rgba(255, 255, 255, 0.4);
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
    pointer-events: none;
    z-index: 5;
    opacity: 0;
    transition: opacity 0.2s, transform 0.2s;
    /* Move up slightly to prevent shelf clipping */
    margin-top: -2px;
}

.book-ghost.visible {
    opacity: 1;
}

.library-instructions {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(10px);
    color: var(--color-press);
    padding: 0.8rem 1.5rem;
    border-radius: 50px;
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    z-index: 1000;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.5s ease;
    border: 1px solid rgba(var(--color-press-rgb), 0.3);
}

.library-instructions.show {
    opacity: 1;
}


/* Book States */
.book.standing {
    transform: rotate(0deg);
}

.book.flat {
    /* Rotating around bottom-left makes the book fall left and sit on the shelf edge */
    transform: rotate(-90deg);
    transform-origin: bottom left;
}

/* Reader Overlay */
.reader-overlay {
    position: fixed;
    inset: 0;
    background: #000;
    z-index: 3000;
    display: flex;
    flex-direction: column;
    padding: 0;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.5s ease;
}

.reader-overlay.visible {
    opacity: 1;
    pointer-events: all;
}

.reader-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 3rem;
    background: #000;
}

.close-btn {
    background: none;
    border: none;
    color: var(--color-press);
    cursor: pointer;
    font-family: var(--font-heading);
    font-size: 0.9rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: opacity 0.3s;
}

.close-btn:hover {
    opacity: 0.7;
}

#reading-title {
    font-family: var(--font-heading);
    font-size: 1rem;
    text-transform: uppercase;
    color: var(--text-secondary);
    max-width: 50%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Reader Wrapper & Inner zones */
.reader-wrapper {
    flex: 1;
    width: 100%;
    max-width: 1400px;
    /* Wider for desktop efficiency */
    margin: 0 auto;
    position: relative;
    background: #fff;
    border-radius: 8px;
    box-shadow: 0 0 50px rgba(0, 0, 0, 0.5);
    overflow: hidden;
}

.epub-viewer {
    width: 100%;
    height: 100%;
}

.trigger-zone,
.nav-zone {
    position: absolute;
    z-index: 100;
    touch-action: manipulation;
}

.trigger-zone.top {
    top: 0;
    left: 0;
    width: 100%;
    height: 80px;
    cursor: default;
}

.nav-zone {
    top: 80px;
    bottom: 0;
    width: 25%;
    cursor: pointer;
}

.nav-zone.left {
    left: 0;
}

.nav-zone.right {
    right: 0;
}

/* Floating Controls (Liquid Glass) */
.reader-controls {
    position: absolute;
    top: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(-20px);
    width: auto;
    padding: 0.6rem 1.5rem;

    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(15px);
    -webkit-backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 50px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.3);

    display: flex;
    align-items: center;
    gap: 1.5rem;
    z-index: 200;

    opacity: 0;
    pointer-events: none;
    transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.reader-controls.visible {
    opacity: 1 !important;
    pointer-events: all;
    transform: translateX(-50%) translateY(0) !important;
}

/* Instant tint updates */
.reader-controls.light-theme-active,
.reader-controls.sepia-theme-active {
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s ease;
}

.control-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.control-btn {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.8);
    cursor: pointer;
    font-size: 1rem;
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    transition: all 0.2s;
    font-family: var(--font-body);
    font-weight: 600;
}

.control-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: white;
    text-shadow: 0 0 10px rgba(var(--color-press-rgb), 0.5);
}

/* Inverted controls for Light Theme */
.reader-controls.light-theme-active {
    background: rgba(0, 0, 0, 0.05);
    border: 1px solid rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.1);
}

.reader-controls.light-theme-active .control-btn {
    color: rgba(0, 0, 0, 0.6);
}

.reader-controls.light-theme-active .control-btn:hover {
    background: rgba(0, 0, 0, 0.1);
    color: black;
    text-shadow: none;
}

.theme-btn {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.2);
    cursor: pointer;
    transition: transform 0.2s;
}

.theme-btn:hover {
    transform: scale(1.2);
}

.theme-btn.light {
    background: #f9f9f9;
}

.theme-btn.sepia {
    background: #f4ecd8;
}

.theme-btn.dark {
    background: #1a1a1a;
}

.reader-progress {
    position: absolute;
    bottom: 25px;
    left: 50%;
    transform: translateX(-50%);
    font-family: var(--font-heading);
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.25em;
    text-transform: uppercase;
    color: var(--text-secondary);
    /* Dynamic based on theme later */
    opacity: 0;
    transition: opacity 0.4s ease;
    z-index: 300;
    pointer-events: none;
    text-shadow: 0 1px 10px rgba(0, 0, 0, 0.2);
}

.reader-footer {
    padding: 2rem;
    background: #000;
    display: flex;
    justify-content: center;
}

.reader-nav {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
}

.nav-btn {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 0.6rem 2.5rem;
    border-radius: 40px;
    cursor: pointer;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    transition: all 0.3s;
}

.nav-btn:hover {
    background: #fff;
    color: #000;
}

/* Responsive */
@media (max-width: 768px) {
    .library-header {
        flex-direction: column;
        align-items: center;
        gap: 1rem;
        text-align: center;
    }
}