* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

:root {
    --bg-color: #1a1a2e;
    --panel-bg: #16213e;
    --accent: #e94560;
    --text-primary: #eee;
    --text-secondary: #aaa;
    --spine-width: 50px;
    --cover-height: 85vh;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
}

.app {
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    position: relative;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 3px;
}

/* Kiosk idle state: hide controls and cursor until the viewer moves */
body.idle,
body.idle * {
    cursor: none !important;
}

body.idle .settings-toggle {
    opacity: 0;
    pointer-events: none;
}

/* Settings Toggle */
.settings-toggle {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    background: var(--panel-bg);
    border: none;
    color: var(--text-primary);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.settings-toggle:hover {
    background: var(--accent);
    transform: rotate(90deg);
}

body.settings-open .settings-toggle {
    opacity: 0;
    pointer-events: none;
}

/* Settings Panel */
.settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 380px;
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    background: var(--panel-bg);
    z-index: 999;
    transform: translateX(calc(100% + 40px));
    visibility: hidden;
    transition: transform 0.3s ease, visibility 0s linear 0.3s;
    box-shadow: -5px 0 30px rgba(0, 0, 0, 0.5);
    overflow-y: auto;
    overscroll-behavior: contain;
}

.settings-panel.open {
    transform: translateX(0);
    visibility: visible;
    transition: transform 0.3s ease, visibility 0s;
}

.settings-header {
    position: sticky;
    top: 0;
    background: var(--panel-bg);
    z-index: 1;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 25px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-header h2 {
    font-family: 'Playfair Display', serif;
    font-size: 1.5rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 2rem;
    cursor: pointer;
    line-height: 1;
}

.settings-content {
    padding: 25px;
}

.setting-group {
    margin-bottom: 25px;
}

.setting-group label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-secondary);
}

.setting-group input[type="text"],
.setting-group input[type="number"],
.setting-group select {
    width: 100%;
    padding: 12px 15px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 1rem;
}

.setting-group input[type="text"]:focus,
.setting-group input[type="number"]:focus,
.setting-group select:focus {
    outline: none;
    border-color: var(--accent);
}

.setting-group input[type="checkbox"] {
    margin-right: 10px;
    transform: scale(1.2);
}

.setting-group input[type="range"] {
    width: calc(100% - 40px);
    margin-right: 10px;
}

.setting-group input[type="color"] {
    width: 60px;
    height: 40px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
}

.help-text {
    margin-top: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.setting-group.hidden,
.setting-group input.hidden {
    display: none !important;
}

#custom-shelf {
    margin-top: 10px;
}

.settings-divider {
    margin: 30px 0 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--accent);
}

.settings-status {
    min-height: 1.2em;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text-secondary);
}

.settings-status.error {
    color: #ff8a8a;
}

.settings-status.success {
    color: #8fd19e;
}

.btn-row {
    display: flex;
    gap: 10px;
}

.btn-row .btn-secondary {
    flex: 1;
    padding: 12px 8px;
}

.btn-secondary.btn-inline {
    margin-top: 10px;
}

.shortcut-hints {
    margin-top: 25px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    line-height: 2;
}

kbd {
    display: inline-block;
    min-width: 1.6em;
    padding: 0 5px;
    margin: 0 1px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 4px;
    background: rgba(255, 255, 255, 0.06);
    font-family: inherit;
    font-size: 0.75rem;
    line-height: 1.6;
    text-align: center;
}

#scroll-speed-group.visible,
#fade-settings-group.visible {
    display: block !important;
}

.btn-primary {
    width: 100%;
    padding: 15px;
    background: var(--accent);
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    margin-bottom: 10px;
}

.btn-primary:hover:not(:disabled) {
    background: #ff6b6b;
    transform: translateY(-2px);
}

.btn-primary:disabled {
    opacity: 0.7;
    cursor: progress;
}

.btn-secondary {
    width: 100%;
    padding: 12px;
    background: transparent;
    border: 2px solid var(--accent);
    border-radius: 8px;
    color: var(--accent);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-secondary:hover {
    background: var(--accent);
    color: white;
}

/* Loading State */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
    z-index: 500;
}

.loading.visible {
    display: flex;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Welcome State */
.welcome {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-color);
}

.welcome.hidden {
    display: none;
}

.welcome-content {
    text-align: center;
    padding: 40px;
}

.welcome-content h1 {
    font-family: 'Playfair Display', serif;
    font-size: 3rem;
    margin-bottom: 15px;
}

.welcome-content p {
    color: var(--text-secondary);
    margin-bottom: 30px;
    font-size: 1.1rem;
}

.welcome-content .btn-primary {
    width: auto;
    padding: 15px 40px;
}

.welcome-content .welcome-error {
    max-width: 480px;
    margin: -10px auto 30px;
    padding: 12px 16px;
    border-radius: 8px;
    background: rgba(233, 69, 96, 0.12);
    border: 1px solid rgba(233, 69, 96, 0.4);
    color: #ffb3b3;
    font-size: 0.95rem;
    line-height: 1.5;
}

/* Bookshelf */
.bookshelf {
    display: none;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 0;
}

.bookshelf.visible {
    display: flex;
    align-items: center;
}

.books-container {
    display: flex;
    align-items: center;
    height: 100%;
    padding: 10px 50px;
    gap: 20px;
}

/* Book Cover View */
.book-item.cover-view {
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.3s ease;
    position: relative;
}

.book-item.cover-view:hover {
    transform: scale(1.05) translateY(-10px);
    z-index: 10;
}

.book-item.cover-view img {
    height: var(--cover-height);
    width: auto;
    /* Reserve a book-shaped slot until the image loads so the shelf doesn't jump */
    aspect-ratio: 2 / 3;
    background: rgba(255, 255, 255, 0.06);
    border-radius: 4px;
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.05);
    display: block;
}

.book-item.cover-view img.loaded {
    aspect-ratio: auto;
    background: none;
}

.book-item:focus-visible {
    outline-offset: 6px;
    border-radius: 6px;
}

.book-item.cover-view .no-cover {
    height: var(--cover-height);
    width: calc(var(--cover-height) * 0.65);
    background: linear-gradient(145deg, #2d3436, #1e272e);
    border-radius: 4px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    text-align: center;
    box-shadow: 
        0 10px 30px rgba(0, 0, 0, 0.4),
        0 0 0 1px rgba(255, 255, 255, 0.05);
}

.book-item.cover-view .no-cover .title {
    font-family: 'Playfair Display', serif;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 15px;
    line-height: 1.3;
}

.book-item.cover-view .no-cover .author {
    font-size: 1.1rem;
    color: var(--text-secondary);
}

/* Book Spine View */
.books-container.spine-view {
    align-items: flex-end;
    padding-bottom: 50px;
}

.book-item.spine-view {
    flex-shrink: 0;
    cursor: pointer;
    transition: transform 0.3s ease;
    position: relative;
}

.book-item.spine-view:hover {
    transform: translateY(-20px);
    z-index: 10;
}

.book-spine {
    width: var(--spine-width);
    height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 3px 6px 6px 3px;
    box-shadow: 
        inset -3px 0 8px rgba(0, 0, 0, 0.3),
        3px 3px 10px rgba(0, 0, 0, 0.3);
    position: relative;
    overflow: hidden;
}

.book-spine::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 4px;
    background: linear-gradient(to right, rgba(0, 0, 0, 0.3), transparent);
}

.book-spine::after {
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 6px;
    background: linear-gradient(to left, rgba(0, 0, 0, 0.2), transparent);
    border-radius: 0 6px 6px 0;
}

.spine-text {
    writing-mode: vertical-rl;
    text-orientation: mixed;
    transform: rotate(180deg);
    font-size: 0.9rem;
    font-weight: 500;
    padding: 15px 5px;
    text-align: center;
    line-height: 1.2;
    max-height: 75vh;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.spine-title {
    font-family: 'Playfair Display', serif;
    font-weight: 600;
    font-size: 1rem;
}

.spine-author {
    font-size: 0.8rem;
    opacity: 0.8;
    margin-top: 8px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 2000;
    padding: 20px;
}

.modal.visible {
    display: flex;
}

.modal-content {
    background: var(--panel-bg);
    border-radius: 16px;
    max-width: 900px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    box-shadow: 0 25px 80px rgba(0, 0, 0, 0.5);
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 20px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    cursor: pointer;
    z-index: 10;
    transition: color 0.3s ease;
}

.modal-close:hover {
    color: var(--accent);
}

.modal-nav {
    position: fixed;
    top: 50%;
    transform: translateY(-50%);
    width: 56px;
    height: 56px;
    border: none;
    border-radius: 50%;
    background: rgba(22, 33, 62, 0.85);
    color: var(--text-primary);
    font-size: 2.2rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-bottom: 4px;
    transition: background 0.2s ease;
    z-index: 2001;
}

.modal-nav:hover {
    background: var(--accent);
}

.modal-prev {
    left: 20px;
}

.modal-next {
    right: 20px;
}

.modal-body {
    display: flex;
    gap: 40px;
    padding: 40px;
}

.modal-cover {
    flex-shrink: 0;
}

.modal-cover img {
    width: 250px;
    height: auto;
    border-radius: 8px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.4);
}

.modal-info {
    flex: 1;
}

.modal-info h2 {
    font-family: 'Playfair Display', serif;
    font-size: 2rem;
    margin-bottom: 10px;
    line-height: 1.2;
}

.modal-author {
    font-size: 1.2rem;
    color: var(--text-secondary);
    margin-bottom: 25px;
}

.modal-meta {
    display: flex;
    gap: 30px;
    margin-bottom: 25px;
}

.rating-display {
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.rating-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.stars {
    color: #ffd700;
    font-size: 1.2rem;
    letter-spacing: 2px;
}

.modal-details {
    margin-bottom: 25px;
    padding: 20px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
}

.modal-details p {
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.modal-details p:last-child {
    margin-bottom: 0;
}

.modal-review {
    margin-bottom: 25px;
    padding: 20px;
    background: rgba(233, 69, 96, 0.1);
    border-left: 4px solid var(--accent);
    border-radius: 0 8px 8px 0;
}

.modal-review h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--accent);
}

.modal-review p {
    line-height: 1.7;
    color: var(--text-primary);
    white-space: pre-wrap;
}

.modal-description {
    margin-bottom: 25px;
}

.modal-description h3 {
    font-size: 1rem;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.modal-description p {
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-line;
    display: -webkit-box;
    -webkit-line-clamp: 8;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.modal-info .btn-secondary {
    width: auto;
    padding: 12px 30px;
}

/* Responsive */
@media (max-width: 1040px) {
    /* Leave room beside the modal for the prev/next buttons */
    .modal {
        padding: 20px 68px;
    }

    .modal-nav {
        width: 48px;
        height: 48px;
    }

    .modal-prev {
        left: 10px;
    }

    .modal-next {
        right: 10px;
    }
}

@media (max-width: 768px) {
    .modal {
        padding: 12px 12px 80px;
    }

    .modal-content {
        max-height: 100%;
    }

    .modal-body {
        flex-direction: column;
        align-items: center;
        text-align: center;
    }

    .modal-cover img {
        width: 180px;
    }

    .settings-panel {
        width: 100%;
    }

    .modal-meta {
        justify-content: center;
    }

    .modal-body {
        padding: 50px 24px 30px;
        gap: 24px;
    }

    .modal-info h2 {
        font-size: 1.6rem;
    }

    .modal-review {
        text-align: left;
    }

    .modal-nav {
        top: auto;
        bottom: 16px;
        transform: none;
    }

    .modal-prev {
        left: calc(50% - 58px);
    }

    .modal-next {
        right: calc(50% - 58px);
    }

    .welcome-content h1 {
        font-size: 2.2rem;
    }
}

/* Scrollbar styling */
.bookshelf::-webkit-scrollbar {
    height: 10px;
}

.bookshelf::-webkit-scrollbar-track {
    background: rgba(255, 255, 255, 0.05);
}

.bookshelf::-webkit-scrollbar-thumb {
    background: var(--accent);
    border-radius: 5px;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translate(-50%, 20px);
    max-width: calc(100% - 40px);
    padding: 12px 22px;
    border-radius: 999px;
    background: var(--panel-bg);
    color: var(--text-primary);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
    font-size: 0.95rem;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 3000;
}

.toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

.toast.error {
    border: 1px solid rgba(233, 69, 96, 0.6);
}

/* Auto-scroll indicator */
.auto-scroll-indicator {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--panel-bg);
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: none;
    z-index: 100;
}

.auto-scroll-indicator.visible {
    display: block;
}

/* Fade mode styles */
.bookshelf.fade-mode {
    overflow: hidden;
}

.bookshelf.fade-mode .books-container {
    justify-content: center;
    transition: opacity var(--fade-duration, 1s) ease-in-out;
}

.bookshelf.fade-mode .books-container.fading-out {
    opacity: 0;
}

.bookshelf.fade-mode .books-container.fading-in {
    opacity: 1;
}

@media (prefers-reduced-motion: reduce) {
    .settings-toggle:hover,
    .book-item.cover-view:hover,
    .book-item.spine-view:hover,
    .btn-primary:hover:not(:disabled) {
        transform: none;
    }

    .spinner {
        animation-duration: 3s;
    }
}
