html,
body {
    height: 100%;
    margin: 0;
    font-family: Inter, "Segoe UI", Arial, sans-serif;
    background: #f3f1eb;
    color: #202124;
    overflow: hidden;
}

#app {
    height: 100%;
}

button,
input {
    font: inherit;
}

button {
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.48;
}

h1,
h2,
p {
    margin: 0;
}

.viewer-shell {
    --surface: #fffdfa;
    --surface-muted: #ede9df;
    --panel: #242629;
    --panel-text: #f7f3e8;
    --text: #202124;
    --muted: #69645d;
    --line: #d8d0c0;
    --accent: #18736d;
    --accent-strong: #10524e;
    --danger-bg: #fff1ed;
    --danger-text: #943521;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    height: 100dvh;
    min-height: 0;
    background: var(--surface-muted);
    color: var(--text);
    overflow: hidden;
}

.viewer-shell.theme-dark {
    --surface: #17191d;
    --surface-muted: #101215;
    --panel: #0f1518;
    --panel-text: #f1eee6;
    --text: #f0eee8;
    --muted: #a9a196;
    --line: #343940;
    --accent: #66b6a9;
    --accent-strong: #8ccfc4;
    --danger-bg: #381d19;
    --danger-text: #ffb9aa;
}

.viewer-toolbar {
    z-index: 20;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 4rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.brand-block {
    display: flex;
    align-items: center;
    min-width: 0;
    gap: 0.8rem;
}

.brand-refresh {
    padding: 0;
    color: inherit;
    background: transparent;
    border: 0;
    text-align: left;
}

.brand-refresh:hover .brand-mark {
    background: var(--accent-strong);
}

.brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 2.5rem;
    width: 2.5rem;
    height: 2.5rem;
    color: #ffffff;
    background: #18736d;
    border-radius: 7px;
    font-weight: 800;
}

.brand-icon {
    width: 1.35rem;
    height: 1.35rem;
}

.brand-block h1 {
    font-size: 1.15rem;
    line-height: 1.2;
}

.brand-block p {
    margin-top: 0.1rem;
    color: var(--muted);
    font-size: 0.86rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: min(48vw, 36rem);
}

.toolbar-actions {
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.menu-button {
    display: none;
    flex: 0 0 auto;
    width: 2.5rem;
    height: 2.5rem;
    padding: 0.55rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 7px;
}

.menu-button span {
    display: block;
    height: 2px;
    margin: 0.25rem 0;
    background: var(--text);
    border-radius: 999px;
}

.mobile-menu {
    display: none;
}

.file-button,
.icon-button,
.nav-button {
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface);
    color: var(--text);
}

.help-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.help-link:hover {
    color: var(--text);
}

.file-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 4.5rem;
    height: 2.5rem;
    padding: 0 0.9rem;
    color: #fff;
    background: var(--accent);
    border-color: var(--accent);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
}

.file-input {
    display: none;
}

.icon-button {
    flex: 0 0 auto;
    min-width: 2.7rem;
    height: 2.5rem;
    padding: 0 0.7rem;
    font-weight: 700;
}

.icon-button .bi {
    font-size: 1.05rem;
    line-height: 1;
}

.font-select {
    flex: 0 1 12rem;
    min-width: 8rem;
    max-width: 16rem;
    height: 2.5rem;
    padding: 0 0.65rem;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 7px;
    font-weight: 600;
}

.viewer-alert {
    margin: 1rem;
    padding: 0.85rem 1rem;
    color: var(--danger-text);
    background: var(--danger-bg);
    border: 1px solid color-mix(in srgb, var(--danger-text) 25%, transparent);
    border-radius: 7px;
}

.viewer-workspace {
    display: grid;
    grid-template-columns: minmax(17rem, 22rem) minmax(0, 1fr);
    min-height: 0;
    overflow: hidden;
}

.viewer-shell.sidebar-collapsed .viewer-workspace {
    grid-template-columns: minmax(0, 1fr);
}

.viewer-shell.sidebar-collapsed .book-panel {
    display: none;
}

.book-panel {
    min-height: 0;
    overflow: auto;
    color: var(--panel-text);
    background: var(--panel);
    border-right: 1px solid #00000033;
}

.empty-panel,
.book-summary {
    padding: 1rem;
}

.empty-panel {
    display: grid;
    gap: 0.45rem;
    color: color-mix(in srgb, var(--panel-text) 82%, transparent);
}

.empty-panel strong {
    color: var(--panel-text);
}

.book-summary {
    border-bottom: 1px solid #ffffff1f;
}

.eyebrow {
    display: block;
    margin-bottom: 0.35rem;
    color: #a7d2ca;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0;
    text-transform: uppercase;
}

.book-summary h2 {
    font-size: 1.05rem;
    line-height: 1.3;
}

.book-summary p {
    margin-top: 0.4rem;
    color: color-mix(in srgb, var(--panel-text) 72%, transparent);
    font-size: 0.88rem;
}

.toc-list {
    display: grid;
    padding: 0.5rem;
}

.toc-item {
    width: 100%;
    min-height: 2.35rem;
    padding: 0.45rem 0.55rem 0.45rem calc(0.55rem + var(--toc-depth, 0) * 0.9rem);
    color: color-mix(in srgb, var(--panel-text) 82%, transparent);
    background: transparent;
    border: 0;
    border-radius: 6px;
    text-align: left;
    line-height: 1.25;
}

.toc-item:hover,
.toc-item.active {
    color: var(--panel-text);
    background: #ffffff1f;
}

.mobile-toc-list .toc-item {
    color: color-mix(in srgb, var(--text) 84%, transparent);
}

.mobile-toc-list .toc-item:hover,
.mobile-toc-list .toc-item.active {
    color: var(--text);
    background: color-mix(in srgb, var(--accent) 16%, transparent);
}

.reading-surface {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    min-width: 0;
    min-height: 0;
    overflow: hidden;
    padding: 0;
}

.drop-zone {
    display: grid;
    place-items: center;
    align-content: center;
    min-height: 100%;
    padding: 2rem;
    color: var(--muted);
    background: var(--surface);
    border: 1px dashed var(--line);
    border-radius: 8px;
    text-align: center;
}

.drop-icon {
    display: grid;
    place-items: center;
    width: 5rem;
    height: 6.5rem;
    margin-bottom: 1.2rem;
    color: #fff;
    background: #18736d;
    border-radius: 5px;
    font-size: 0.8rem;
    font-weight: 800;
}

.drop-zone h2 {
    color: var(--text);
    font-size: 1.45rem;
}

.drop-zone p {
    max-width: 34rem;
    margin-top: 0.65rem;
    line-height: 1.6;
}

.reader-header {
    position: relative;
    z-index: 15;
    display: grid;
    grid-template-columns: 7rem minmax(0, 1fr) 7rem;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    margin: 0;
    padding: 0.65rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    box-shadow: 0 8px 22px #0000000f;
}

.reader-header div {
    min-width: 0;
    text-align: center;
}

.reader-header span {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
}

.reader-header h2 {
    margin-top: 0.1rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 1rem;
}

.nav-button {
    height: 2.25rem;
    padding: 0 0.75rem;
    font-weight: 700;
}

.chapter-scroll {
    min-height: 0;
    overflow: auto;
    padding: 1rem;
}

.chapter-scroll:focus {
    outline: none;
}

.chapter-content {
    max-width: var(--reader-content-width, 64rem);
    min-height: 100%;
    margin: 0 auto;
    padding: clamp(1.5rem, 4vw, 3.5rem);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 12px 40px #00000014;
    font-family: var(--reader-font-family, inherit);
    font-size: var(--reader-font-size, 18px);
    line-height: var(--reader-line-height, 1.75);
}

.chapter-content :where(p, li, blockquote, figcaption, td, th, dd, dt, div, span) {
    font-family: var(--reader-font-family, inherit) !important;
    font-size: var(--reader-font-size, 18px) !important;
    line-height: var(--reader-line-height, 1.75) !important;
}

.chapter-content :where(h1) {
    font-size: calc(var(--reader-font-size, 18px) * 1.8) !important;
}

.chapter-content :where(h2) {
    font-size: calc(var(--reader-font-size, 18px) * 1.45) !important;
}

.chapter-content :where(h3) {
    font-size: calc(var(--reader-font-size, 18px) * 1.22) !important;
}

.chapter-content img,
.chapter-content svg,
.chapter-content video {
    max-width: 100%;
    height: auto;
}

.chapter-content a {
    color: var(--accent-strong);
}

.chapter-content p {
    margin: 0 0 1em;
}

.chapter-content h1,
.chapter-content h2,
.chapter-content h3 {
    margin: 1.4em 0 0.6em;
    line-height: 1.25;
}

.help-shell {
    --surface: #fffdfa;
    --surface-muted: #ede9df;
    --text: #202124;
    --muted: #69645d;
    --line: #d8d0c0;
    --accent: #18736d;
    min-height: 100dvh;
    background: var(--surface-muted);
    color: var(--text);
}

.help-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    min-height: 4rem;
    padding: 0.75rem 1rem;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
}

.help-brand {
    color: inherit;
    text-decoration: none;
}

.help-brand:hover {
    color: inherit;
}

.help-content {
    display: grid;
    gap: 1rem;
    width: min(58rem, calc(100% - 2rem));
    margin: 0 auto;
    padding: 1rem 0 2rem;
}

.help-section {
    padding: clamp(1rem, 3vw, 1.5rem);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.help-section h2 {
    margin-bottom: 0.65rem;
    font-size: 1.25rem;
}

.help-section p {
    color: var(--muted);
    line-height: 1.7;
}

.help-section p + p {
    margin-top: 0.75rem;
}

.license-list {
    display: grid;
    gap: 0.75rem;
    margin: 0;
    padding: 0;
    list-style: none;
}

.license-list li {
    display: grid;
    gap: 0.2rem;
    padding: 0.75rem;
    border: 1px solid var(--line);
    border-radius: 7px;
}

.license-list span {
    color: var(--muted);
    line-height: 1.55;
}

#blazor-error-ui {
    color-scheme: light only;
    display: none;
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    z-index: 1000;
    max-width: 32rem;
    padding: 0.85rem 2.5rem 0.85rem 1rem;
    color: #fff;
    background: #9d2c1e;
    border-radius: 7px;
    box-shadow: 0 12px 34px #00000035;
}

#blazor-error-ui .dismiss {
    position: absolute;
    top: 0.55rem;
    right: 0.75rem;
    color: inherit;
    cursor: pointer;
}

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: #d8d0c0;
    stroke-width: 0.6rem;
    transform: rotate(-90deg);
    transform-origin: 50% 50%;
}

.loading-progress circle:last-child {
    stroke: #18736d;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
    text-align: center;
    font-weight: 700;
}

.loading-progress-text:after {
    content: var(--blazor-load-percentage-text, "Loading");
}

@media (max-width: 860px) {
    html,
    body {
        height: auto;
        min-height: 100%;
        overflow: auto;
    }

    #app {
        height: auto;
        min-height: 100dvh;
    }

    .viewer-shell {
        display: block;
        height: auto;
        min-height: 100dvh;
        overflow: visible;
    }

    .viewer-toolbar {
        align-items: center;
        flex-direction: row;
        min-height: 4rem;
    }

    .brand-block p {
        max-width: calc(100vw - 6rem);
    }

    .toolbar-actions {
        display: none;
    }

    .menu-button {
        display: block;
    }

    .mobile-menu {
        position: fixed;
        top: 4rem;
        right: 0.75rem;
        left: 0.75rem;
        z-index: 30;
        display: none;
        max-height: calc(100dvh - 5rem);
        overflow: auto;
        padding: 0.75rem;
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: 8px;
        box-shadow: 0 18px 48px #00000030;
    }

    .mobile-menu.open {
        display: block;
    }

    .mobile-menu-actions {
        display: flex;
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .mobile-book-summary {
        margin-top: 0.75rem;
        padding-top: 0.75rem;
        border-top: 1px solid var(--line);
    }

    .mobile-book-summary h2 {
        font-size: 1rem;
        line-height: 1.3;
    }

    .mobile-book-summary p {
        margin-top: 0.25rem;
        color: var(--muted);
        font-size: 0.88rem;
    }

    .mobile-toc-list {
        display: grid;
        max-height: 45dvh;
        margin-top: 0.65rem;
        overflow: auto;
    }

    .viewer-workspace {
        display: block;
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr);
        overflow: visible;
    }

    .book-panel {
        display: none;
    }

    .reading-surface {
        display: block;
        min-height: 0;
        overflow: visible;
        padding: 0;
    }

    .reader-header {
        grid-template-columns: 5.5rem minmax(0, 1fr) 5.5rem;
        gap: 0.5rem;
        padding: 0.6rem 0.75rem;
    }

    .chapter-scroll {
        overflow: visible;
        padding: 0.75rem;
        touch-action: pan-y;
    }

    .nav-button,
    .icon-button {
        padding: 0 0.5rem;
        font-size: 0.88rem;
    }

    .font-select {
        flex: 1 1 12rem;
        max-width: none;
        font-size: 0.88rem;
    }

    .chapter-content {
        max-width: calc(100vw - 1.5rem) !important;
        margin: 0 auto;
        padding: 1.1rem;
    }
}

@media (max-width: 520px) {
    .viewer-toolbar {
        padding: 0.65rem 0.75rem;
    }

    .brand-mark {
        flex-basis: 2.25rem;
        width: 2.25rem;
        height: 2.25rem;
    }

    .brand-block h1 {
        font-size: 1rem;
    }

    .brand-block p {
        font-size: 0.8rem;
        max-width: calc(100vw - 7.5rem);
    }

    .mobile-menu {
        right: 0.5rem;
        left: 0.5rem;
    }

    .reader-header {
        grid-template-columns: 1fr 1fr;
        padding: 0.55rem 0.75rem;
    }

    .reader-header div {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .reader-header .nav-button:first-child {
        grid-column: 1;
        grid-row: 2;
    }

    .reader-header .nav-button:last-child {
        grid-column: 2;
        grid-row: 2;
    }
}
