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

html,
body {
    width: 100%;
    height: 100%;
    height: calc(var(--real-vh, 1vh) * 100);
    overflow: hidden;
}

body {
    font-family: 'Georgia', 'Garamond', serif;
    background-color: #fafaf5;
    color: #333;
    display: flex;
    flex-direction: column;
}

.control-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background-color: #fff;
    border-bottom: 2px solid #ddd;
    flex-wrap: wrap;
}

.controls-left,
.controls-center,
.controls-right {
    display: flex;
    gap: 8px;
    align-items: center;
}

.controls-right {
    position: relative;
}

.btn {
    padding: 8px 12px;
    background-color: #f0f0f0;
    border: 1px solid #ccc;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    user-select: none;
}

.btn:hover {
    background-color: #e8e8e8;
}

.mode-btn.active {
    background-color: #4CAF50;
    color: white;
    border-color: #4CAF50;
}

.font-display {
    font-size: 11px;
    color: #666;
    min-width: 35px;
    text-align: center;
}

.reader-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 20px;
}

.reader-container::-webkit-scrollbar {
    width: 8px;
}

.reader-container::-webkit-scrollbar-track {
    background: #f1f1f1;
}

.reader-container::-webkit-scrollbar-thumb {
    background: #888;
    border-radius: 4px;
}

.content {
    line-height: 1.8;
    word-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

.content h1 {
    margin: 20px 0 15px 0;
    font-size: 1.6em;
    font-weight: bold;
}

.content h2 {
    margin: 18px 0 12px 0;
    font-size: 1.3em;
    font-weight: bold;
}

.content p {
    margin: 10px 0;
    text-align: justify;
}

.bookmarks-panel {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    width: 80%;
    max-width: 400px;
    height: 100vh;
    background-color: white;
    border-left: 1px solid #ddd;
    z-index: 1000;
    flex-direction: column;
}

.bookmarks-panel.active {
    display: flex;
}

.bookmarks-header {
    padding: 12px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
}

.bookmarks-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.bookmark-item {
    padding: 10px;
    margin: 5px 0;
    background-color: #f9f9f9;
    border-left: 3px solid #4CAF50;
    cursor: pointer;
    font-size: 12px;
}

.status-bar {
    padding: 8px 12px;
    padding-bottom: max(12px, calc(8px + env(safe-area-inset-bottom, 0px)));
    background-color: #f5f5f5;
    border-top: 2px solid #ddd;
    font-size: 11px;
    color: #666;
    display: flex;
    justify-content: space-between;
    flex-shrink: 0;
}

/* PORTRAIT MODE */
body.force-portrait {
    flex-direction: column;
}

body.force-portrait .control-bar {
    border-bottom: 3px solid #4CAF50;
}

body.force-portrait .reader-container {
    padding: 20px;
}

body.force-portrait .status-bar {
    border-top: 3px solid #4CAF50;
}

/* LANDSCAPE MODE - 90 DEGREES ROTATED */
/* Center the body (swapping vw/vh), then rotate — this fills the viewport exactly */
body.force-landscape {
    position: fixed;
    top: calc((var(--real-vh, 1vh) * 100 - var(--real-vw, 1vw) * 100) / 2);
    left: calc((var(--real-vw, 1vw) * 100 - var(--real-vh, 1vh) * 100) / 2);
    width: calc(var(--real-vh, 1vh) * 100);
    height: calc(var(--real-vw, 1vw) * 100);
    transform: rotate(90deg);
    transform-origin: center center;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

body.force-landscape .control-bar {
    border-bottom: 3px solid #2196F3;
    padding: 10px;
    flex-shrink: 0;
}

body.force-landscape .reader-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 15px;
    touch-action: none;
    -webkit-overflow-scrolling: touch;
}

body.force-landscape .content {
    width: 100%;
    max-width: none;
}

body.force-landscape .status-bar {
    border-top: 3px solid #2196F3;
    flex-shrink: 0;
}

.library-select {
    min-width: 180px;
    max-width: 220px;
    padding: 8px 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    background: #fff;
    font-size: 13px;
}

/* Library Panel */
.library-panel {
    position: absolute;
    top: 100%;
    right: 0;
    background: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 100;
    width: min(50vw, calc(100vw - 24px));
    min-width: 160px;
    max-width: calc(100vw - 24px);
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.library-panel.active {
    display: flex !important;
}

.library-header {
    padding: 12px 16px;
    border-bottom: 1px solid #ddd;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.library-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.library-item {
    padding: 12px 14px;
    margin: 6px 0;
    background: #f9f9f9;
    border-left: 3px solid #2196F3;
    border-radius: 3px;
    cursor: pointer;
    font-size: 13px;
    word-break: break-all;
}

.library-item:hover {
    background: #e8f4fd;
}

.library-item.active-book {
    border-left-color: #4CAF50;
    font-weight: bold;
}

.books-list {
    width: 100%;
}

.book-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid #eee;
    cursor: pointer;
}

.book-item:hover {
    background: #f5f5f5;
}

.book-name {
    display: block;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.book-delete-btn {
    background: #ff4444;
    color: white;
    border: none;
    padding: 4px 8px;
    border-radius: 3px;
    cursor: pointer;
    font-size: 12px;
    margin-left: 8px;
    flex-shrink: 0;
    white-space: nowrap;
}

.book-delete-btn:hover {
    background: #cc0000;
}

@media (max-width: 480px) {
    .controls-right {
        width: auto;
        flex: 0 0 auto;
        justify-content: flex-start;
    }

    .library-panel {
        position: fixed;
        top: calc(64px + env(safe-area-inset-top, 0px));
        left: 8px;
        right: 8px;
        width: auto;
        min-width: 0;
        max-width: none;
        max-height: min(50vh, 320px);
        border-radius: 10px;
        overscroll-behavior: contain;
        z-index: 1000;
    }

    .book-item {
        grid-template-columns: 1fr;
        align-items: start;
    }

    .book-name {
        white-space: normal;
        overflow-wrap: anywhere;
    }

    .book-delete-btn {
        justify-self: start;
        margin-left: 0;
    }
}


/* EPUB chapter dividers */
.epub-chapter {
    margin-bottom: 2em;
    padding-bottom: 1.5em;
    border-bottom: 1px solid #e0e0d8;
}

.epub-chapter:last-child {
    border-bottom: none;
}

.epub-chapter img {
    max-width: 100%;
    height: auto;
    display: block;
    margin: 10px auto;
}

.landscape .reader-container {
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x;
}

.landscape .content>* {
    display: inline-block;
    vertical-align: top;
    /* Set width as needed */
}

@media (max-width: 600px) {
    .control-bar {
        padding: 8px;
    }

    .btn {
        padding: 6px 8px;
        font-size: 12px;
    }
}
