:root {
    --bg-light: #ffffff;
    --fg-light: #111;
    --bg-dark: #1f1f1f;
    --fg-dark: #f5f5f5;
    --border-light: #d0d4d9;
    --border-dark: #3a3f46;
    --accent-gradient: linear-gradient(135deg, #ffb347, #ffcc33);
    --accent-solid: #ffb347;
    --btn-bg-light: #f5f7fa;
    --btn-bg-dark: #2b2f34;
    --shadow-color-light: rgba(0, 0, 0, 0.08);
    --shadow-color-dark: rgba(0, 0, 0, 0.6);
    --focus-ring: 0 0 0 3px rgba(0, 140, 255, 0.45);
    --hover-highlight-color: rgba(0, 150, 255, 0.28);
    --hover-highlight-stroke: rgba(0, 150, 255, 0.9);
    --vh: 1vh;
    /*
     * Use the larger landscape safe-area inset on both sides. A one-sided
     * phone notch must not move the reader's visual centre.
     */
    --safe-area-inline: max(env(safe-area-inset-left, 0px), env(safe-area-inset-right, 0px));
}

@media (prefers-color-scheme: light) {
    :root {
        --bg: var(--bg-light);
        --fg: var(--fg-light);
        --border: var(--border-light);
        --panel-bg: rgba(255, 255, 255, 0.75);
        --panel-border: rgba(0, 0, 0, 0.08);
        --btn-bg: var(--btn-bg-light);
        --btn-bg-hover: #eef1f5;
        --btn-bg-active: #e2e6eb;
        --info-color: #333;
        --subtitle-color: #555;
    }
}
@media (prefers-color-scheme: dark) {
    :root {
        --bg: var(--bg-dark);
        --fg: var(--fg-dark);
        --border: var(--border-dark);
        --panel-bg: rgba(40, 40, 44, 0.68);
        --panel-border: rgba(255, 255, 255, 0.08);
        --btn-bg: var(--btn-bg-dark);
        --btn-bg-hover: #353b42;
        --btn-bg-active: #40464e;
        --info-color: #e0e0e0;
        --subtitle-color: #a8a8a8;
    }

    #pdf-canvas {
        filter: invert(0.87);
    }

    canvas {
        filter: invert(0.87);
    }
}

html.amoled-mode,
body.amoled-mode {
    color-scheme: dark;
    --bg: #000000;
    --bg-dark: #000000;
    --amoled-reader-fg: #f5f5f5;
    --color-background-dark: #000000;
    --panel-bg: rgba(0, 0, 0, 0.82);
    --panel-border: rgba(255, 255, 255, 0.1);
    --btn-bg: #050505;
    --btn-bg-hover: #111111;
    --btn-bg-active: #171717;
}

html.amoled-mode,
html.amoled-mode body,
html.amoled-mode #pdf-doc-container,
html.amoled-mode #epub-doc-container,
html.amoled-mode #viewer-wrapper,
html.amoled-mode #pdf-canvas,
html.amoled-mode foliate-view {
    background: #000000 !important;
    background-color: #000000 !important;
}

html.amoled-mode canvas,
html.amoled-mode #pdf-canvas,
html.amoled-mode .page-canvas {
    filter: none !important;
}

html.amoled-mode .dark\:bg-background-dark,
html.amoled-mode .dark\:bg-gray-800,
html.amoled-mode .dark\:bg-gray-900,
html.amoled-mode .dark\:bg-background-dark\/50,
html.amoled-mode .dark\:bg-background-dark\/60,
html.amoled-mode .dark\:bg-background-dark\/80,
html.amoled-mode .dark\:bg-background-dark\/90,
html.amoled-mode .dark\:bg-background-dark\/95 {
    background-color: #000000 !important;
}

html.amoled-mode .bg-background-light,
html.amoled-mode .bg-white,
html.amoled-mode .bg-gray-100 {
    background-color: #000000 !important;
}

html.amoled-mode .bg-background-light\/80,
html.amoled-mode .bg-background-light\/90,
html.amoled-mode .bg-white\/50,
html.amoled-mode .bg-white\/60,
html.amoled-mode .bg-white\/70,
html.amoled-mode .bg-white\/80,
html.amoled-mode .bg-white\/95 {
    background-color: rgba(0, 0, 0, 0.82) !important;
}

html.amoled-mode #config-menu,
html.amoled-mode #highlight-menu,
html.amoled-mode #login-menu,
html.amoled-mode #controls,
html.amoled-mode #info-box {
    background: rgba(0, 0, 0, 0.88) !important;
    background-color: rgba(0, 0, 0, 0.88) !important;
}

html.amoled-mode #config-menu {
    background: #000000 !important;
    background-color: #000000 !important;
    border: 1px solid rgba(255, 255, 255, 0.14);
}

#config-menu {
    z-index: 10050;
    width: 24rem;
    max-width: calc(100vw - 1.5rem);
}

#config-menu:not(.hidden) {
    display: flex;
    flex-direction: column;
}

#config-menu > :not(.settings-content) {
    flex-shrink: 0;
}

.settings-tabs {
    display: flex;
    margin-bottom: 1rem;
    border-bottom: 1px solid color-mix(in srgb, currentColor 15%, transparent);
}

.settings-tabs [role="tab"] {
    flex: 1;
    padding: 0.625rem 0.5rem;
    margin-bottom: -1px;
    border-bottom: 2px solid transparent;
    background: transparent;
    font-family: inherit;
    font-size: 0.875rem;
    font-weight: 600;
    color: #64748b;
    transition: color 150ms, border-color 150ms;
}

.settings-tabs [aria-selected="true"] {
    color: var(--color-primary);
    border-bottom-color: currentColor;
}

.settings-tabs button:hover {
    color: var(--color-primary);
}

.settings-tabs button:focus-visible,
.settings-panel:focus-visible {
    outline: 2px solid currentColor;
    outline-offset: -2px;
}

.settings-content {
    /* Overlapping panels reserve the natural height of the tallest tab. */
    display: grid;
}

.settings-panel {
    grid-area: 1 / 1;
    align-self: start;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.settings-panel[aria-hidden="true"] {
    visibility: hidden;
    pointer-events: none;
}

.settings-display-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
}

.settings-display-controls button {
    justify-content: flex-start;
    gap: 0.5rem;
    min-height: 2.75rem;
    padding: 0.5rem;
    border: 1px solid color-mix(in srgb, currentColor 15%, transparent);
    border-radius: 0.5rem;
    font-family: inherit;
    color: #475569;
}

.settings-display-controls button:hover {
    border-color: var(--color-primary);
}

.settings-display-controls button[aria-pressed="true"] {
    color: var(--color-primary);
    border-color: currentColor;
    background-color: color-mix(in srgb, var(--color-primary) 8%, transparent);
}

.settings-display-controls button > :first-child {
    flex-shrink: 0;
}

.settings-control-label {
    font-size: 0.75rem;
    color: inherit;
    text-align: left;
}

@media (prefers-color-scheme: dark) {
    .settings-tabs [role="tab"],
    .settings-display-controls button {
        color: #94a3b8;
    }

    .settings-tabs [aria-selected="true"],
    .settings-tabs button:hover,
    .settings-display-controls button[aria-pressed="true"] {
        color: #a99aff;
    }
}

html.amoled-mode .settings-tabs [aria-selected="true"],
html.amoled-mode .settings-tabs button:hover,
html.amoled-mode .settings-display-controls button {
    color: var(--amoled-reader-fg);
}

#config-menu > nav {
    margin-top: 1rem;
    padding-bottom: 0;
}

.settings-email-hint:has(~ :not([hidden])) {
    display: none;
}

html.amoled-mode #config-menu button.bg-primary\/10 {
    background-color: rgba(255, 255, 255, 0.1) !important;
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.32),
        0 0 12px rgba(255, 255, 255, 0.18);
}

html.amoled-mode #config-menu button.text-primary,
html.amoled-mode #config-menu button.text-primary .material-symbols-outlined,
html.amoled-mode #config-menu button .text-primary {
    color: var(--amoled-reader-fg) !important;
}

html.amoled-mode .playbar,
html.amoled-mode .playbar button,
html.amoled-mode .playbar .material-symbols-outlined {
    color: color-mix(in srgb, var(--amoled-reader-fg) 72%, #000000) !important;
}

html.amoled-mode .playbar [id="play-toggle"] {
    background-color: color-mix(in srgb, var(--amoled-reader-fg) 12%, #000000) !important;
    --tw-shadow-color: rgba(255, 255, 255, 0.3);
    --tw-ring-color: rgba(255, 255, 255, 0.35);
}

html.amoled-mode .playbar .bg-slate-300,
html.amoled-mode .playbar .dark\:bg-slate-700 {
    background-color: color-mix(in srgb, var(--amoled-reader-fg) 16%, #000000) !important;
}

html.amoled-mode .translate-popup {
    color: var(--amoled-reader-fg) !important;
}

html.amoled-mode .translate-popup,
html.amoled-mode .translate-popup * {
    color: var(--amoled-reader-fg) !important;
}

html.amoled-mode .translation-setup-prompt {
    background: #000000 !important;
    background-color: #000000 !important;
    border-color: rgba(255, 255, 255, 0.16) !important;
}

html.amoled-mode .translation-setup-prompt,
html.amoled-mode .translation-setup-prompt * {
    color: #e5e7eb !important;
}

html.amoled-mode .translation-setup-prompt select,
html.amoled-mode .translation-setup-prompt input,
html.amoled-mode .translation-setup-prompt button {
    background-color: #000000 !important;
    border-color: rgba(255, 255, 255, 0.16) !important;
}

html.amoled-mode .translation-setup-prompt option {
    background-color: #000000 !important;
    color: #e5e7eb !important;
}

html.amoled-mode .pdf-page-wrapper {
    border: 1px solid rgba(255, 255, 255, 0.1);
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.04),
        0 10px 28px rgba(255, 255, 255, 0.08);
}

html.amoled-mode .pdf-page-wrapper:hover {
    box-shadow:
        0 0 0 1px rgba(255, 255, 255, 0.08),
        0 12px 32px rgba(255, 255, 255, 0.12);
}

html.amoled-mode .text-slate-800,
html.amoled-mode .text-slate-700,
html.amoled-mode .text-gray-900,
html.amoled-mode .text-gray-800,
html.amoled-mode .text-gray-700 {
    color: #e5e7eb !important;
}

html.amoled-mode .text-slate-600,
html.amoled-mode .text-slate-500,
html.amoled-mode .text-gray-600,
html.amoled-mode .text-gray-500 {
    color: #cbd5e1 !important;
}

html.amoled-mode .border-gray-300,
html.amoled-mode .border-slate-300,
html.amoled-mode .border-slate-200 {
    border-color: rgba(255, 255, 255, 0.16) !important;
}

html.amoled-mode #previous-pdf-container .lr-document-thumbnail {
    background: #000000 !important;
    background-color: #000000 !important;
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}

html.amoled-mode #previous-pdf-container .lr-document-thumbnail .material-symbols-outlined {
    color: #a3a3a3 !important;
}

html.amoled-mode #previous-pdf-container .lr-pdf-thumbnail-canvas {
    background: #ffffff !important;
    filter: invert(1) hue-rotate(180deg) contrast(0.92) brightness(0.86) !important;
}

html.amoled-mode #previous-pdf-container .lr-epub-thumbnail img {
    background: #000000 !important;
    background-color: #000000 !important;
    filter: invert(1) hue-rotate(180deg) contrast(0.92) brightness(0.86) !important;
}

@media (prefers-color-scheme: dark) {
    html:not(.amoled-mode) #previous-pdf-container .lr-epub-thumbnail img {
        background: #ffffff !important;
        background-color: #ffffff !important;
        filter: invert(1) hue-rotate(180deg) contrast(0.78) brightness(0.9) !important;
    }
}

html,
body {
    font-family:
        system-ui,
        -apple-system,
        Segoe UI,
        Roboto,
        Ubuntu,
        Cantarell,
        "Noto Sans",
        Arial,
        sans-serif;
    background: var(--bg);
    color: var(--fg);
    -webkit-font-smoothing: antialiased;
    height: 100dvh;

    display: flex;
    flex-direction: column;
    overflow: hidden;
}

html {
    padding: 0;
}

body {
    box-sizing: border-box;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    padding-left: var(--safe-area-inline);
    padding-right: var(--safe-area-inline);
    padding-top: env(safe-area-inset-top, 0px);
}

#controls.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    padding: 10px 14px;
    background: var(--panel-bg);
    backdrop-filter: blur(14px) saturate(1.4);
    -webkit-backdrop-filter: blur(14px) saturate(1.4);
    border-bottom: 1px solid var(--panel-border);
    box-shadow:
        0 4px 14px -4px var(--shadow-color-light),
        0 2px 4px -1px var(--shadow-color-light);
    transition: background 0.35s;
    position: relative;
    z-index: 10;
}
.book-tts-info {
    width: 90%;
    margin: 5px auto;
    display: flex;
    border: 1px solid var(--border);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
    border-radius: 6px;
}

@media (prefers-color-scheme: dark) {
    #controls.toolbar {
        box-shadow:
            0 4px 18px -6px var(--shadow-color-dark),
            0 2px 6px -2px var(--shadow-color-dark);
    }
}

#login-user {
    font: inherit;
    border: 1px solid var(--border);
    background: var(--btn-bg);
    color: var(--fg);
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition:
        background 0.25s,
        border-color 0.25s,
        transform 0.15s;
    min-height: 40px;
}

select,
input[type="color"] {
    font: inherit;
    border: 1px solid var(--border);
    background: var(--btn-bg);
    color: var(--fg);
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    font-size: 14px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    transition:
        background 0.25s,
        border-color 0.25s,
        transform 0.15s;
    min-height: 40px;
}
select:focus-visible,
input[type="color"]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}
select:hover:not(:disabled),
input[type="color"]:hover:not(:disabled) {
    background: var(--btn-bg-hover);
}

#viewer-region {
    flex: 1 1 auto;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    position: relative;
    margin: 10px;
}

#viewer-wrapper {
    flex: 1 1 auto;
    display: flex;
    justify-content: center;
    overflow: auto;
    padding: 3px 0 24px;
}
#pdf-canvas {
    border: 1px solid var(--border);
    border-radius: 14px;
    background: var(--bg);
    display: block;
    box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.25);
    max-width: calc(100vw - 40px);
}

#pdf-doc-container {
    flex: 1 1 auto;
    position: relative;
    overflow-y: auto;
    overflow-x: hidden;
    background: var(--bg);
    padding-top: calc(env(safe-area-inset-top, 0px) + 24px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 48px);
    padding-left: 0;
    padding-right: 0;
    margin: 0;
    border-top: 1px solid var(--panel-border);
    scroll-behavior: smooth;
    min-height: calc(var(--vh, 1vh) * 100);
}

html.reader-scrollbars-hidden,
html.reader-scrollbars-hidden body,
html.reader-scrollbars-hidden #pdf-doc-container,
html.reader-scrollbars-hidden #viewer-wrapper {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

html.reader-scrollbars-hidden::-webkit-scrollbar,
html.reader-scrollbars-hidden body::-webkit-scrollbar,
html.reader-scrollbars-hidden #pdf-doc-container::-webkit-scrollbar,
html.reader-scrollbars-hidden #viewer-wrapper::-webkit-scrollbar {
    width: 0;
    height: 0;
    display: none;
}

#epub-doc-container {
    flex: 1 1 auto;
    position: relative;
    overflow: hidden;
    background: var(--bg);
    padding-top: calc(env(safe-area-inset-top, 0px) + 24px);
    padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 48px);
    padding-left: 0;
    padding-right: 0;
    margin: 0;
    border-top: 1px solid var(--panel-border);
    min-height: calc(var(--vh, 1vh) * 100);
    display: none;
}
.pdf-page-wrapper {
    position: relative;
    margin: 0 auto 32px auto;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
    background: transparent;
    border-radius: 6px;
    overflow: hidden;
    transition: box-shadow 0.25s;
}
.pdf-page-wrapper:hover {
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}

/*
 * Layout-detection canvases use the unscaled PDF viewport as their drawing
 * coordinate system. Keep their CSS box tied to the page wrapper so they
 * follow both the normal page scale and the focused text-width fit/offset.
 */
.pdf-page-wrapper > .ignored-overlay,
.pdf-page-wrapper > .layout-debug-overlay {
    width: 100%;
    height: 100%;
    display: block;
}

.pdf-word-highlight {
    position: absolute;
    background-color: rgba(12, 163, 223, 0.3);
    pointer-events: none;
    border-radius: 2px;
    z-index: 20;
}

.pdf-word-highlight.saved-highlight {
    outline-offset: 1px;
}

.persistent-highlight {
    position: absolute;
    opacity: 0.45;
    mix-blend-mode: multiply;
    border-radius: 2px;
    pointer-events: none;
    z-index: 10;
}
.persistent-highlight.current-playing {
    outline: 2px solid #ff9800;
}

.hover-highlight {
    position: absolute;
    background: var(--hover-highlight-color);
    pointer-events: none;
    border-radius: 2px;
    outline: 1px solid var(--hover-highlight-stroke);
    z-index: 30;
}

.pdf-text-selection {
    position: absolute;
    pointer-events: none;
    border-radius: 2px;
    background: rgba(120, 200, 255, 0.28);
    outline: 1px solid rgba(120, 200, 255, 0.65);
    z-index: 50;
}

.pdf-selection-menu {
    position: fixed;
    transform: translate(-10px, 12px);
    display: flex;
    gap: 8px;
    padding: 8px;
    border-radius: 10px;
    background: rgba(20, 20, 24, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 9999;
}

.pdf-selection-menu-btn {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.08);
    color: rgba(255, 255, 255, 0.92);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 13px;
    cursor: pointer;
}

.pdf-selection-menu-btn:hover {
    background: rgba(255, 255, 255, 0.14);
}

.pdf-active-phrase-actions {
    position: absolute;
    box-sizing: border-box;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px;
    border-radius: 999px;
    background: rgba(20, 20, 24, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    z-index: 10000;
    pointer-events: auto;
    isolation: isolate;
    touch-action: manipulation;
}

.pdf-active-phrase-btn {
    appearance: none;
    width: 28px;
    height: 28px;
    border-radius: 999px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.09);
    color: rgba(255, 255, 255, 0.95);
    cursor: pointer;
}

.pdf-active-phrase-btn:hover {
    background: rgba(255, 255, 255, 0.18);
}

.pdf-active-phrase-btn.is-active {
    background: rgba(255, 196, 38, 0.25);
    border-color: rgba(255, 196, 38, 0.9);
    color: #ffe9aa;
}

.pdf-active-phrase-btn .material-symbols-outlined {
    font-size: 18px;
    line-height: 1;
}

@media (max-width: 640px) {
    .pdf-active-phrase-actions {
        gap: 5px;
    }
}

.pdf-comment-marker {
    position: absolute;
    transform: translate(6px, -6px);
    width: 22px;
    height: 22px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(20, 20, 24, 0.92);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
    z-index: 60;
    pointer-events: auto;
    cursor: default;
}

/* Compact slider style for translation setup popup */
.translation-speed-slider {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: color-mix(in srgb, var(--btn-bg) 88%, #cbd5e1 12%);
    outline: none;
    opacity: 0.9;
    transition: opacity 0.2s ease;
}

.translation-speed-slider:hover {
    opacity: 1;
}

.translation-speed-slider:focus-visible {
    box-shadow: var(--focus-ring);
}

.translation-speed-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid #4f3bc7;
    background: var(--color-primary, #654ef0);
    cursor: pointer;
}

.translation-speed-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 999px;
    border: 1px solid #4f3bc7;
    background: var(--color-primary, #654ef0);
    cursor: pointer;
}

#stopwatch-input {
    appearance: textfield;
    -moz-appearance: textfield;
}

#stopwatch-input::-webkit-inner-spin-button,
#stopwatch-input::-webkit-outer-spin-button {
    margin: 0;
    -webkit-appearance: none;
}

.pdf-comment-marker .material-symbols-outlined {
    font-size: 16px;
    line-height: 1;
}

.pdf-comment-tooltip {
    position: fixed;
    max-width: min(360px, 92vw);
    padding: 10px 12px;
    border-radius: 10px;
    background: rgba(20, 20, 24, 0.96);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: rgba(255, 255, 255, 0.92);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    z-index: 99999;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 13px;
}

.highlight-color-option {
    border: 2px solid transparent;
    outline: none;
    cursor: pointer;
    transition:
        transform 0.2s ease,
        box-shadow 0.2s ease,
        border-color 0.2s ease;
}

.highlight-color-option.is-active {
    transform: scale(1.08);
    box-shadow: 0 0 0 2px rgba(19, 127, 236, 0.35);
    border-color: rgba(19, 127, 236, 0.7);
}

#drop-overlay {
    position: fixed;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, rgba(0, 150, 255, 0.25), rgba(0, 150, 255, 0.1));
    border: 3px dashed #0096ff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: clamp(1.5rem, 3.5vw, 2.4rem);
    font-weight: 600;
    color: #0096ff;
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.25s ease;
    z-index: 1000;
    backdrop-filter: blur(6px);
}
#drop-overlay.active {
    opacity: 1;
}

.toolbar .btn-group {
    display: flex;
    gap: 8px;
    align-items: stretch;
}
.toolbar .spacer {
    flex: 1 1 auto;
    min-width: 40px;
}

@media (min-width: 680px) {
    .btn-group {
        margin-left: 20px;
    }
}

@media (max-width: 680px) {
    html,
    body {
        overflow: auto !important;
        font-size: 15px;
        min-height: calc(var(--vh, 1vh) * 100);
        height: calc(var(--vh, 1vh) * 100);
    }
    #controls.toolbar {
        flex-direction: column;
        align-items: stretch;
        padding: 8px 4px;
        gap: 4px;
    }
    .toolbar .btn-group,
    .select-cluster {
        width: 100%;
        justify-content: center;
        gap: 4px;
        flex-wrap: wrap;
    }

    .icon-btn {
        width: 12px;
        height: 12px;
    }
    .icon-btn .label {
        display: none;
    }

    select,
    input[type="color"] {
        flex: 1;
        min-height: 46px;
        font-size: 16px;
    }
    #viewer-region {
        margin: 0;
        padding: 0;
    }
}

body,
html {
    overflow: auto !important;
    min-height: calc(var(--vh, 1vh) * 100);
    height: calc(var(--vh, 1vh) * 100);
}

#controls.toolbar--collapsed .btn-group > :not([data-essential="true"]) {
    display: none !important;
}

/* Opcional: esconde completamente (para modo “imersivo”) */
#controls.toolbar--hidden {
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}

#controls:not(.toolbar--hidden) {
    transition: opacity 0.25s;
}

#controls.toolbar--collapsed .select-cluster {
    display: none !important;
}

.pdf-hf-overlay-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
}
.pdf-hf-overlay-line-header {
    background: rgba(255, 0, 0, 0.1);
    position: absolute;
    border: 2px solid rgba(255, 0, 0, 0.2);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(255, 0, 0, 0.2);
}
.pdf-hf-overlay-line-footer {
    background: rgba(0, 0, 255, 0.2);
    position: absolute;
    border: 2px solid rgba(0, 0, 255, 0.8);
    border-radius: 4px;
    box-shadow: 0 2px 8px rgba(0, 0, 255, 0.3);
}
.pdf-hf-overlay-word {
    border: 1px dotted rgba(0, 0, 0, 0.3);
    position: absolute;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}
.pdf-hf-debug-info {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 8px 12px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 12px;
    z-index: 20;
    max-width: 300px;
    white-space: pre-wrap;
}

/*
 *╭─────────────────────────────────────╮
 *│          Layout Detection           │
 *╰─────────────────────────────────────╯
*/

.pdf-hf-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 30;
}
.pdf-hf-overlay-box {
    position: absolute;
    border: 2px solid rgba(48, 199, 90, 0.9);
    background: rgba(48, 199, 90, 0.18);
    border-radius: 4px;
    font: 12px/1.2 sans-serif;
    color: #0b2a13;
    box-sizing: border-box;
}
.pdf-hf-overlay-box-label {
    position: absolute;
    left: 0;
    top: -20px;
    padding: 0 6px;
    height: 18px;
    display: flex;
    align-items: center;
    border-radius: 3px;
    background: rgba(48, 199, 90, 0.95);
    color: #03130a;
    font-weight: 600;
    white-space: nowrap;
}

.not-sure-layout-controls {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 32;
}

.not-sure-layout-region {
    position: absolute;
    display: block;
    padding: 0;
    border: 1.5px dashed rgba(128, 128, 128, 0.72);
    border-radius: 4px;
    background: rgba(200, 200, 200, 0.12);
    cursor: pointer;
    pointer-events: auto;
}

.not-sure-layout-region:hover {
    background: rgba(200, 200, 200, 0.2);
}

.not-sure-layout-add {
    position: absolute;
    top: 50%;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 999px;
    background: rgba(105, 105, 105, 0.9);
    color: rgba(255, 255, 255, 0.9);
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.28);
    cursor: pointer;
    transform: translateY(-50%);
}

.not-sure-layout-add:hover {
    background: rgba(82, 82, 82, 0.96);
}

.not-sure-layout-add .material-symbols-outlined {
    font-size: 18px;
    line-height: 1;
}

.not-sure-layout-add-left {
    left: -12px;
}

.not-sure-layout-add-right {
    right: -12px;
}

/*
 *╭─────────────────────────────────────╮
 *│             Need Review             │
 *╰─────────────────────────────────────╯
*/
#pdf-container {
    position: fixed;
    inset: 0;
    background: #fff;
}

.group:hover .group-hover-block {
    display: block;
}

.peer:checked ~ .peer-checked-block {
    display: block;
}

@media (max-width: 768px) {
    /* Compress floating toolbar on mobile */
    .fixed.bottom-4.inset-x-0 > div {
        flex-wrap: wrap;
        gap: 0.25rem;
        padding: 0.5rem;
        max-width: 95vw;
        margin: 0 auto;
    }

    .fixed.bottom-4.inset-x-0 button {
        padding: 0.4rem;
    }

    .fixed.bottom-4.inset-x-0 .material-symbols-outlined {
        font-size: 1.25rem !important;
    }
}

/*
 *╭─────────────────────────────────────╮
 *│       EPUB document rendering       │
 *╰─────────────────────────────────────╯
*/
.epub-container {
    max-width: 900px;
    margin: 0 auto;
    padding: 2rem 1.5rem 4rem;
    box-sizing: border-box;
}

.epub-chapter {
    margin-bottom: 2rem;
}

.epub-chapter-title {
    font-size: 1.35rem;
    font-weight: 600;
    margin: 1.5rem 0 1rem;
}

.epub-sentence {
    margin: 0 0 0.75rem;
    line-height: 1.6;
    border-radius: 6px;
    padding: 0.35rem 0.45rem;
    transition:
        background-color 0.2s ease,
        box-shadow 0.2s ease;
}

.epub-sentence-active {
    box-shadow: 0 0 0 2px rgba(12, 163, 223, 0.45);
}

.epub-sentence-hover {
    box-shadow: 0 0 0 2px rgba(12, 163, 223, 0.25);
}

.epub-sentence-hover:not([data-has-saved-highlight="true"]) {
    background-color: rgba(12, 163, 223, 0.15);
}

#epub-doc-container foliate-view {
    display: block;
    width: 100%;
    height: 100%;
}
#previous-pdf-container {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    box-sizing: border-box;
    overflow-x: hidden;
}

#previous-pdf-container > * {
    min-width: 0;
    box-sizing: border-box;
}

@media (min-width: 640px) {
    #previous-pdf-container {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (min-width: 1024px) {
    #previous-pdf-container {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }
}
