:root {
    --bg-color: #0f172a;
    --text-color: #f8fafc;
    --accent-color: #38bdf8;
    --secondary-color: #1e293b;
    --pivot-color: #fb7185;
    --font-main: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* Tema claro alternativo */
body.light-mode {
    --bg-color: #f8fafc;
    --text-color: #0f172a;
    --accent-color: #2563eb;
    --secondary-color: #e2e8f0;
    --pivot-color: #ef4444;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: var(--font-main);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

#app {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 20px;
    transition: opacity 0.3s ease;
}

.hidden {
    display: none !important;
}

/* Setup Screen */
#setup-screen {
    justify-content: center;
    align-items: center;
    text-align: center;
}

.hero h1 {
    font-size: 3rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(to right, var(--accent-color), #818cf8);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.hero p {
    color: #94a3b8;
    margin-bottom: 2rem;
}

.file-upload input {
    display: none;
}

.btn-primary {
    background: var(--accent-color);
    color: var(--bg-color);
    padding: 16px 32px;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    display: inline-block;
    transition: transform 0.2s;
}

.btn-primary:active {
    transform: scale(0.95);
}

.recent-hint {
    margin-top: 2rem;
    font-size: 0.8rem;
    color: #64748b;
}

/* Reader Screen */
#reader-screen {
    padding: 0;
    justify-content: space-between;
}

.top-bar {
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(15, 23, 42, 0.8);
    backdrop-filter: blur(10px);
    z-index: 20;
    transition: opacity 0.5s ease, transform 0.5s ease;
}

.top-bar-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.audio-select {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: var(--text-color);
    border-radius: 10px;
    padding: 8px 10px;
    font-weight: 600;
    font-size: 0.85rem;
    appearance: none;
}

.audio-select option {
    background: #0f172a;
    color: #e2e8f0;
}

.light-mode .audio-select {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.08);
    color: #0f172a;
}

.light-mode .audio-select option {
    background: #f8fafc;
    color: #0f172a;
}

.progress-info {
    text-align: center;
    flex: 1;
    display: flex;
    flex-direction: column;
}

#book-title {
    font-size: 0.75rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
    margin: 0 auto;
}

#read-percentage {
    font-size: 0.8rem;
    font-weight: bold;
    color: var(--accent-color);
}

.icon-btn {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn.active {
    color: var(--accent-color);
}

#toggle-tts:not(.active) {
    opacity: 0.5;
}

/* Reader Core */
.reader-container {
    position: relative;
    flex: 1;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: hidden;
}

#word-display {
    font-size: 3.5rem;
    font-weight: 700;
    display: flex;
    font-family: 'Courier New', Courier, monospace; /* Monospaced often helps in RSVP */
}

@media (max-width: 600px) {
    #word-display {
        font-size: 2.5rem;
    }
}

.pivot {
    color: var(--pivot-color);
    transition: color 0.3s ease;
}

.no-highlight .pivot {
    color: inherit;
}

.prefix {
    text-align: right;
    min-width: 5.5ch;
}

.suffix {
    text-align: left;
    min-width: 5.5ch;
}

.focus-lines {
    display: none; /* ocultar linhas de foco acima/abaixo da palavra */
}

/* Controls */
.controls-panel {
    background: var(--secondary-color);
    padding: 20px;
    border-radius: 30px 30px 0 0;
    display: flex;
    flex-direction: column;
    gap: 20px;
    transition: opacity 0.5s ease, transform 0.5s ease;
    z-index: 10;
}

.mini-preview {
    background: rgba(12, 22, 46, 0.75);
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 16px;
    padding: 12px 14px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 600;
    font-size: 0.9rem;
    color: #cbd5e1;
}

.preview-header small {
    font-weight: 500;
    color: #94a3b8;
}

.preview-text {
    font-size: 1rem;
    line-height: 1.6;
    color: #e2e8f0;
    max-height: 140px;
    overflow: hidden;
    text-align: justify;
    letter-spacing: 0.01em;
    font-family: 'Merriweather', 'Georgia', serif;
}

.preview-text .preview-highlight {
    background: linear-gradient(120deg, rgba(251, 121, 97, 0.28), rgba(251, 180, 120, 0.32));
    color: #fff;
    padding: 0 4px;
    border-radius: 4px;
    box-decoration-break: clone;
    -webkit-box-decoration-break: clone;
}

.preview-wrapper {
    padding: 0 16px 6px 16px;
}

.keyboard-hint {
    text-align: center;
    font-size: 0.7rem;
    color: #64748b;
    padding: 10px;
    transition: opacity 0.5s ease;
}

/* Focus Mode */
.focus-mode .top-bar {
    opacity: 0;
    transform: translateY(-20px);
    pointer-events: none;
}

.focus-mode .controls-panel {
    opacity: 0;
    transform: translateY(20px);
    pointer-events: none;
}

.focus-mode .keyboard-hint {
    opacity: 0;
}

/* manter a prévia visível mesmo no modo foco */
.focus-mode .preview-wrapper {
    opacity: 1;
    transform: none;
    pointer-events: auto;
}

/* Modo áudio (TTS) esconde cursor e mini resumo */
.tts-mode #word-display {
    opacity: 0;
    pointer-events: none;
}

.tts-mode .preview-wrapper {
    display: none;
}

.tts-status {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.55);
    color: #e2e8f0;
    padding: 12px 16px;
    border-radius: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
    text-align: center;
    min-width: 220px;
    z-index: 50;
}

.light-mode .tts-status {
    background: rgba(0, 0, 0, 0.08);
    color: #0f172a;
}

/* Ensure the reader container covers the full area when UI is hidden */
.reader-container {
    cursor: pointer;
}

.speed-control {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 30px;
}

.wpm-display {
    text-align: center;
}

#wpm-value {
    font-size: 2rem;
    font-weight: 800;
    display: block;
}

.speed-btn {
    background: #334155;
    border: none;
    color: white;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.playback-controls {
    display: flex;
    justify-content: center;
}

.main-play-btn {
    background: var(--accent-color);
    color: var(--bg-color);
    border: none;
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 10px 25px rgba(56, 189, 248, 0.3);
}

.timeline input {
    width: 100%;
    accent-color: var(--accent-color);
}

.keyboard-hint {
    text-align: center;
    font-size: 0.7rem;
    color: #64748b;
    padding: 10px;
}

/* Modal Settings */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-content {
    background: var(--secondary-color);
    padding: 30px;
    border-radius: 20px;
    max-width: 400px;
    width: 100%;
    position: relative;
    box-shadow: 0 20px 50px rgba(0,0,0,0.5);
}

.modal-content h3 {
    margin-bottom: 15px;
    color: var(--accent-color);
}

.modal-content p {
    font-size: 0.9rem;
    line-height: 1.6;
    color: #cbd5e1;
    margin-bottom: 25px;
}

.close-modal {
    position: absolute;
    top: 15px;
    right: 15px;
    background: none;
    border: none;
    color: #64748b;
    cursor: pointer;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 10px 0;
    border-top: 1px solid #334155;
}

.radio-group {
    display: flex;
    gap: 10px;
}

.radio-option {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.95rem;
    color: #e2e8f0;
}

/* Switch UI */
.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background-color: #334155;
    transition: .4s;
    border-radius: 24px;
}

.slider:before {
    position: absolute;
    content: "";
    height: 18px;
    width: 18px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-color);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Loader */
#loader {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--secondary-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
