: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;
}

@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,
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;

    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-top: env(safe-area-inset-top);
}

#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);
}

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

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

#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: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    margin: 0;
    border-top: 1px solid var(--panel-border);
    scroll-behavior: smooth;
    min-height: calc(var(--vh, 1vh) * 100);
}

#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: env(safe-area-inset-left, 0px);
    padding-right: env(safe-area-inset-right, 0px);
    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);
}
.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;
    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: 70;
    pointer-events: auto;
}

.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;
}

.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;
}

/*
 *╭─────────────────────────────────────╮
 *│             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));
    }
}
