* {
    box-sizing: border-box;
}

/* =========================
   BASE
========================= */

html {
    margin: 0;
    padding: 0;
    background: #111;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    padding: 0;
    background: #111;
    color: #fff;

    font-family:
        Arial,
        Helvetica,
        sans-serif;

    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

/* =========================
   READER
========================= */

.reader-content {
    width: 100%;
    max-width: 1000px;

    margin: 0 auto;
    padding: 0;

    min-height: 300px;
}

/* =========================
   CHAPTER IMAGES
========================= */

.chapter-image {
    display: block;

    width: 100%;
    max-width: 1000px;
    height: auto;

    /* Floor height only — applies while the image is still loading.
       Once loaded, the image renders at its real full size as
       before; this only stops the box from collapsing to 0 during
       load, which is what was pulling the bottom nav to the top. */
    min-height: 500px;

    margin: 0 auto;
    padding: 0;

    border: 0;
    outline: none;

    background: #1b1b1b;

    user-select: none;
    -webkit-user-select: none;
    -webkit-user-drag: none;

    image-rendering: auto;
}

.reader-content img {
    vertical-align: top;
}

/* =========================
   CHAPTER NAVIGATION
========================= */

.chapter-navigation {
    width: 100%;
    max-width: 1000px;

    margin: 0 auto;
    padding: 18px 0;

    display: flex;
    align-items: center;
    justify-content: center;

    gap: 10px;
}

/* =========================
   NAVIGATION BUTTON
========================= */

.nav-button {
    min-width: 145px;
    height: 46px;

    padding: 0 18px;

    display: inline-flex;
    align-items: center;
    justify-content: center;

    gap: 8px;

    border: 1px solid #333;
    border-radius: 8px;

    background: #1b1b1b;
    color: #fff;

    text-decoration: none;

    font-size: 14px;
    font-weight: 600;
    line-height: 1;

    cursor: pointer;

    transition:
        background-color 0.2s ease,
        border-color 0.2s ease,
        color 0.2s ease,
        transform 0.15s ease;
}

.nav-button:hover {
    background: #292929;
    border-color: #555;
    color: #fff;
}

.nav-button:active {
    transform: scale(0.97);
}

.nav-button.disabled {
    opacity: 0.35;
    pointer-events: none;
    cursor: default;
}

/* =========================
   SVG ICONS
========================= */

.nav-icon {
    width: 18px;
    height: 18px;

    flex: 0 0 18px;

    display: block;

    stroke: currentColor;
}

/* =========================
   TOP NAVIGATION
========================= */

.top-navigation {
    padding-top: 18px;
    padding-bottom: 18px;
}

/* =========================
   BOTTOM NAVIGATION
========================= */

.bottom-navigation {
    padding-top: 18px;
    padding-bottom: 30px;
}

/* =========================
   LOADING
========================= */

.loading {
    width: 100%;
    min-height: 300px;

    display: flex;
    flex-direction: column;

    align-items: center;
    justify-content: center;

    gap: 14px;

    color: #aaa;

    font-size: 14px;
    font-weight: 400;

    text-align: center;
}

/* =========================
   LOADING SPINNER
========================= */

.spinner {
    width: 38px;
    height: 38px;

    border: 3px solid #333;
    border-top-color: #fff;

    border-radius: 50%;

    animation: chapter-spinner 0.8s linear infinite;
}

@keyframes chapter-spinner {
    from {
        transform: rotate(0deg);
    }

    to {
        transform: rotate(360deg);
    }
}

/* =========================
   ERROR
========================= */

.error {
    width: 100%;
    min-height: 300px;

    padding: 40px 20px;

    display: flex;
    flex-direction: column;

    align-items: center;
    justify-content: center;

    text-align: center;
}

.error-title {
    margin: 0 0 8px;

    color: #fff;

    font-size: 21px;
    font-weight: 700;

    line-height: 1.3;
}

.error-text {
    margin: 0;

    color: #999;

    font-size: 14px;
    font-weight: 400;

    line-height: 1.5;
}

/* =========================
   DESKTOP
========================= */

@media (min-width: 601px) {

    .chapter-navigation {
        padding-left: 0;
        padding-right: 0;
    }

    .nav-button {
        min-width: 145px;
    }

    .reader-content {
        max-width: 1000px;
    }

    .chapter-image {
        max-width: 1000px;
    }
}

/* =========================
   LARGE DESKTOP
========================= */

@media (min-width: 1200px) {

    .chapter-navigation {
        padding-top: 20px;
        padding-bottom: 20px;
    }

    .top-navigation {
        padding-top: 22px;
        padding-bottom: 20px;
    }

    .bottom-navigation {
        padding-top: 20px;
        padding-bottom: 35px;
    }

    .nav-button {
        min-width: 155px;
        height: 48px;

        font-size: 14px;
    }

    .nav-icon {
        width: 19px;
        height: 19px;

        flex-basis: 19px;
    }
}

/* =========================
   TABLET
========================= */

@media (max-width: 900px) and (min-width: 601px) {

    .chapter-navigation {
        padding-left: 12px;
        padding-right: 12px;
    }

    .nav-button {
        min-width: 135px;
    }
}

/* =========================
   MOBILE
========================= */

@media (max-width: 600px) {

    .chapter-navigation {
        width: 100%;

        margin: 0;
        padding: 10px 6px;

        gap: 5px;
    }

    .nav-button {
        min-width: 0;
        width: 0;

        flex: 1 1 0;

        height: 42px;

        padding: 0 5px;

        gap: 5px;

        border-radius: 7px;

        font-size: 12px;

        white-space: nowrap;
        overflow: hidden;
    }

    .nav-icon {
        width: 16px;
        height: 16px;

        flex: 0 0 16px;
    }

    .top-navigation {
        padding-top: 10px;
        padding-bottom: 10px;
    }

    .bottom-navigation {
        padding-top: 10px;
        padding-bottom: 18px;
    }

    .reader-content {
        width: 100%;
        max-width: none;

        margin: 0;
        padding: 0;
    }

    .chapter-image {
        width: 100%;
        max-width: none;

        margin: 0;
        padding: 0;
    }

    .loading {
        min-height: 250px;
        padding: 20px;
        font-size: 13px;
    }

    .spinner {
        width: 34px;
        height: 34px;
    }

    .error {
        min-height: 250px;
        padding: 30px 15px;
    }

    .error-title {
        font-size: 18px;
    }

    .error-text {
        font-size: 13px;
    }
}

/* =========================
   SMALL MOBILE
========================= */

@media (max-width: 380px) {

    .chapter-navigation {
        padding-left: 4px;
        padding-right: 4px;
        gap: 4px;
    }

    .nav-button {
        height: 40px;

        padding-left: 3px;
        padding-right: 3px;

        gap: 4px;

        font-size: 11px;
    }

    .nav-icon {
        width: 15px;
        height: 15px;

        flex-basis: 15px;
    }

    .top-navigation {
        padding-top: 8px;
        padding-bottom: 8px;
    }

    .bottom-navigation {
        padding-top: 8px;
        padding-bottom: 14px;
    }
}

/* =========================
   ACCESSIBILITY
========================= */

.nav-button:focus-visible {
    outline: 2px solid #fff;
    outline-offset: 2px;
}

/* =========================
   REDUCE MOTION
========================= */

@media (prefers-reduced-motion: reduce) {

    html {
        scroll-behavior: auto;
    }

    .nav-button {
        transition: none;
    }

    .spinner {
        animation: none;
    }
}