/* Variables CSS */
:root {
    --font-size: 16px;
    --background: #ffffff;
    --foreground: #030213;
    --card: #ffffff;
    --card-foreground: #030213;
    --primary: #030213;
    --primary-foreground: #ffffff;
    --secondary: #f3f3f5;
    --secondary-foreground: #030213;
    --muted: #ececf0;
    --muted-foreground: #717182;
    --accent: #e9ebef;
    --accent-foreground: #030213;
    --border: rgba(0, 0, 0, 0.1);
    --input-background: #f3f3f5;
    --switch-background: #cbced4;
    --radius: 0.625rem;
    
    /* Spacing */
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    
    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-base: 300ms ease;
    --transition-slow: 500ms ease;
}

/* Dark theme */
.dark-theme {
    --background: #0e1426;
    --foreground: #fafafa;
    --card: #0e1426;
    --card-foreground: #fafafa;
    --primary: #fafafa;
    --primary-foreground: #030213;
    --secondary: #1a1f35;
    --secondary-foreground: #fafafa;
    --muted: #1a1f35;
    --muted-foreground: #b5b5b5;
    --accent: #1a1f35;
    --accent-foreground: #fafafa;
    --border: rgba(255, 255, 255, 0.1);
    --input-background: #1a1f35;
    --switch-background: #1a1f35;
}

/* Reader Container - Masqué par défaut */
.reader-container {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: var(--background);
    color: var(--foreground);
    overflow: hidden;
    z-index: 1000;
    opacity: 0;
}

.reader-container.active {
    display: flex;
    flex-direction: column;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header */
.header {
    border-bottom: 1px solid var(--border);
    padding: var(--spacing-md);
    flex-shrink: 0;
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.book-title {
    font-family: Georgia, serif;
    font-size: 1.25rem;
    font-weight: 500;
    margin-bottom: 0.25rem;
}

.book-author {
    font-size: 0.875rem;
    opacity: 0.6;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Main Layout */
.main-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: 20rem;
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
    background-color: var(--background);
}

.sidebar-right {
    border-right: none;
    border-left: 1px solid var(--border);
}

.sidebar-content {
    padding: var(--spacing-lg);
}

.sidebar-title {
    font-size: 0.875rem;
    opacity: 0.6;
    margin-bottom: var(--spacing-lg);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--spacing-lg);
}

/* Table of Contents */
.toc-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.toc-item {
    width: 100%;
}

.toc-button {
    width: 100%;
    text-align: left;
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    background: transparent;
    border: none;
    color: var(--foreground);
    cursor: pointer;
    transition: all var(--transition-fast);
    font-size: 0.9375rem;
}

.toc-button:hover {
    background-color: rgba(0, 0, 0, 0.05);
}

.dark-theme .toc-button:hover {
    background-color: rgba(255, 255, 255, 0.05);
}

.toc-button.active {
    background-color: rgba(0, 0, 0, 0.1);
    font-weight: 500;
}

.dark-theme .toc-button.active {
    background-color: rgba(255, 255, 255, 0.1);
}

/* Mobile Sidebar */
.sidebar-mobile {
    position: fixed;
    inset: 0;
    z-index: 100;
    background-color: var(--background);
    display: none;
}

.sidebar-mobile.active {
    display: block;
}

/* Content Area */
.content-area {
    flex: 1;
    overflow-y: auto;
    scroll-behavior: smooth;
    scroll-padding-top: 2rem;
    position: relative;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
    /* Scrollbar personnalisée pour qu'elle soit dans la zone de flou */
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.3) transparent;
}

.content-area::-webkit-scrollbar {
    width: 8px;
}

.content-area::-webkit-scrollbar-track {
    background: transparent;
}

.content-area::-webkit-scrollbar-thumb {
    background-color: rgba(0, 0, 0, 0.3);
    border-radius: 4px;
}

.dark-theme .content-area::-webkit-scrollbar-thumb {
    background-color: rgba(255, 255, 255, 0.3);
}

.content-area:active {
    cursor: grabbing;
}

/* Reading Indicator */
.reading-indicator {
    position: fixed;
    pointer-events: none;
    z-index: 10;
    top: 50%;
    transform: translateY(-50%);
}

.reading-indicator-mobile {
    left: 0.5rem;
    display: block;
}

.reading-indicator-desktop {
    left: calc(50% - 24rem - 40px);
    display: none;
}

.reading-dot {
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background-color: currentColor;
    opacity: 0.6;
    animation: pulse 2s ease-in-out infinite;
}

.reading-line {
    width: 2rem;
    height: 2px;
    background: linear-gradient(to right, transparent, currentColor);
    opacity: 0.4;
    margin-right: 0.5rem;
}

@keyframes pulse {
    0%, 100% {
        opacity: 0.6;
    }
    50% {
        opacity: 1;
    }
}

/* Blur Overlays */
.blur-overlay {
    position: fixed;
    pointer-events: none;
    z-index: 5;
    left: 20rem;
    right: 0; /* Inclure la scrollbar */
    height: 35vh;
}

.blur-overlay-top {
    top: 4.5rem;
}

.blur-overlay-bottom {
    bottom: -20px; /* Descendre un peu pour mieux couvrir */
    /* Utiliser calc pour s'assurer qu'il couvre jusqu'en bas même avec scrollbar */
    height: calc(50vh + 70px);
    min-height: 470px;
    /* S'assurer que le flou est plus fort en bas */
}

.blur-overlay.fullscreen {
    left: 0;
    right: 0;
}

.blur-overlay.fullscreen.blur-overlay-bottom {
    bottom: -20px;
    height: calc(50vh + 70px);
    min-height: 470px;
}

.blur-overlay.fullscreen.blur-overlay-top {
    top: 0;
}

.blur-layer {
    position: absolute;
    inset: 0;
    backdrop-filter: blur(1px);
    -webkit-backdrop-filter: blur(1px);
    mask-image: linear-gradient(to bottom, transparent 0%, black 60%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 60%, transparent 100%);
}

.blur-layer-2 {
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    mask-image: linear-gradient(to bottom, transparent 0%, black 40%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 40%, transparent 100%);
}

.blur-layer-3 {
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    mask-image: linear-gradient(to bottom, transparent 0%, black 20%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 20%, transparent 100%);
}

.blur-overlay-bottom .blur-layer {
    mask-image: linear-gradient(to top, transparent 0%, black 60%, transparent 100%);
    -webkit-mask-image: linear-gradient(to top, transparent 0%, black 60%, transparent 100%);
}

.blur-overlay-bottom .blur-layer-2 {
    mask-image: linear-gradient(to top, transparent 0%, black 40%, transparent 100%);
    -webkit-mask-image: linear-gradient(to top, transparent 0%, black 40%, transparent 100%);
}

.blur-overlay-bottom .blur-layer-3 {
    mask-image: linear-gradient(to top, transparent 0%, black 20%, transparent 100%);
    -webkit-mask-image: linear-gradient(to top, transparent 0%, black 20%, transparent 100%);
}

/* Renforcer le flou en bas pour couvrir la dernière ligne */
.blur-overlay-bottom .blur-layer {
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
}

.blur-overlay-bottom .blur-layer-2 {
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
}

.blur-overlay-bottom .blur-layer-3 {
    backdrop-filter: blur(5px);
    -webkit-backdrop-filter: blur(5px);
}

.blur-gradient {
    position: absolute;
    inset: 0;
}

.blur-overlay-top .blur-gradient {
    background: linear-gradient(to bottom, rgba(255, 255, 255, 0.3) 0%, transparent 100%);
}

.dark-theme .blur-overlay-top .blur-gradient {
    background: linear-gradient(to bottom, rgba(14, 20, 38, 0.3) 0%, transparent 100%);
}

.blur-overlay-bottom .blur-gradient {
    background: linear-gradient(to top, rgba(255, 255, 255, 0.3) 0%, transparent 100%);
}

.dark-theme .blur-overlay-bottom .blur-gradient {
    background: linear-gradient(to top, rgba(14, 20, 38, 0.3) 0%, transparent 100%);
}

/* Book Content */
.book-content {
    max-width: 48rem;
    margin: 0 auto;
    padding: 3rem 1.5rem;
    /* Ajouter une marge importante en haut pour commencer au milieu de l'écran */
    padding-top: calc(50vh - 4.5rem);
    min-height: calc(100vh - 4.5rem);
}

.book-header {
    margin-bottom: 4rem;
    text-align: center;
    /* Espacement supplémentaire pour commencer au milieu */
    margin-top: 2rem;
}

.story-title-container {
    margin-bottom: 4rem;
    text-align: center;
}

.story-title-main {
    font-family: Georgia, serif;
    font-size: 2rem;
    margin-bottom: 0.5rem;
    color: var(--foreground);
}

.story-title-main .word {
    display: inline-block;
    margin-right: 0.5rem;
}

.story-title-author {
    opacity: 0.6;
    font-size: 1rem;
}

.book-title-large {
    font-family: Georgia, serif;
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.book-author-large {
    opacity: 0.6;
}

/* Chapters */
.chapter {
    margin-bottom: 4rem;
    scroll-margin-top: 2rem;
}

.chapter-title {
    font-family: Georgia, serif;
    font-size: 1.5rem;
    margin-bottom: 2rem;
}

.chapter-content {
    margin-bottom: 1.5rem;
}

.paragraph {
    margin-bottom: 1.5rem;
    text-indent: 2rem;
    text-align: justify;
}

.paragraph:first-child {
    text-indent: 0;
}

.chapter-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 3rem 0;
    gap: 0.5rem;
}

.separator-dot {
    width: 0.25rem;
    height: 0.25rem;
    border-radius: 50%;
    background-color: currentColor;
    opacity: 0.3;
}

.book-end {
    text-align: center;
    padding: 4rem 0;
    opacity: 0.6;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
    outline: none;
    white-space: nowrap;
}

.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-ghost {
    background: transparent;
    color: var(--foreground);
}

.btn-ghost:hover {
    background-color: var(--accent);
}

.btn-icon {
    padding: 0.5rem;
    width: 2.25rem;
    height: 2.25rem;
}

.btn-outline {
    border: 1px solid var(--border);
    background-color: var(--background);
    color: var(--foreground);
}

.btn-outline:hover {
    background-color: var(--accent);
}

.btn-outline:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.icon {
    width: 1.25rem;
    height: 1.25rem;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Play/Pause Button */
.btn-play {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    width: 3.5rem;
    height: 3.5rem;
    border-radius: 50%;
    background-color: var(--primary);
    color: var(--primary-foreground);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    z-index: 20;
    border: none;
    cursor: pointer;
    transition: all var(--transition-fast);
}

.btn-play:hover {
    transform: scale(1.05);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
}

.btn-play.playing {
    background-color: var(--primary);
}

.btn-play:not(.playing) {
    background-color: var(--secondary);
    color: var(--secondary-foreground);
}

.icon-play,
.icon-pause {
    width: 1.5rem;
    height: 1.5rem;
    fill: currentColor;
}

.icon-play {
    margin-left: 0.125rem;
}

.icon-pause {
    display: none;
}

.btn-play.playing .icon-play {
    display: none;
}

.btn-play.playing .icon-pause {
    display: block;
}

/* Settings Button */
.btn-settings {
    position: fixed;
    bottom: 1.5rem;
    left: 1.5rem;
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    background-color: var(--background);
    border: 1px solid var(--border);
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 20;
}

/* Reading Controls */
.reading-controls {
    display: flex;
    flex-direction: column;
    gap: 2rem;
}

.control-group {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.control-group-title {
    opacity: 0.8;
    font-size: 0.875rem;
}

.control-section {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.control-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.control-label {
    opacity: 0.8;
    font-size: 0.875rem;
}

.control-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.control-value {
    min-width: 3rem;
    text-align: center;
    font-size: 0.875rem;
}

.control-description {
    font-size: 0.75rem;
    opacity: 0.5;
    margin-top: 0.25rem;
}

/* Theme Selector */
.theme-selector {
    display: flex;
    gap: 0.5rem;
}

.theme-button {
    flex: 1;
    justify-content: flex-start;
}

.theme-button.active {
    background-color: var(--primary);
    color: var(--primary-foreground);
}

.theme-button:not(.active) {
    border: 1px solid var(--border);
}

/* Switch */
.switch-label {
    cursor: pointer;
    font-size: 0.875rem;
}

.switch {
    position: relative;
    display: inline-block;
    width: 2rem;
    height: 1.15rem;
    flex-shrink: 0;
}

.switch-input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--switch-background);
    transition: var(--transition-fast);
    border-radius: 9999px;
    border: 1px solid transparent;
}

.switch-slider:before {
    position: absolute;
    content: "";
    height: 1rem;
    width: 1rem;
    left: 0;
    bottom: 0;
    background-color: var(--card);
    transition: var(--transition-fast);
    border-radius: 50%;
    transform: translateX(0);
}

.switch-input:checked + .switch-slider {
    background-color: var(--primary);
}

.switch-input:checked + .switch-slider:before {
    transform: translateX(calc(100% - 2px));
}

.switch-input:disabled + .switch-slider {
    opacity: 0.5;
    cursor: not-allowed;
}

.dark-theme .switch-slider:before {
    background-color: var(--card-foreground);
}

.dark-theme .switch-input:checked + .switch-slider:before {
    background-color: var(--primary-foreground);
}

/* Sheet (Mobile Settings) */
.sheet-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 40;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-base), visibility var(--transition-base);
}

.sheet-overlay.active {
    opacity: 1;
    visibility: visible;
}

.sheet {
    position: fixed;
    z-index: 50;
    background-color: var(--background);
    border-top: 1px solid var(--border);
    max-height: 85vh;
    overflow-y: auto;
    transition: transform var(--transition-base);
}

.sheet-bottom {
    bottom: 0;
    left: 0;
    right: 0;
    transform: translateY(100%);
    border-radius: var(--radius) var(--radius) 0 0;
}

.sheet.active {
    transform: translateY(0);
}

.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--border);
}

.sheet-title {
    font-size: 1.125rem;
    font-weight: 500;
}

.sheet-content {
    padding: var(--spacing-lg);
}

/* Utility Classes */
.desktop-only {
    display: none;
}

.mobile-only {
    display: block;
}

.hidden {
    display: none !important;
}

/* Responsive */
@media (min-width: 768px) {
    .reading-indicator-mobile {
        display: none;
    }
    
    .reading-indicator-desktop {
        display: flex;
        align-items: center;
    }
    
    .book-content {
        padding: 4rem 3rem;
        /* Ajuster le padding-top pour tablette */
        padding-top: calc(50vh - 4.5rem);
    }
}

@media (max-width: 767px) {
    .book-content {
        /* Sur mobile, moins de padding en haut mais toujours centré */
        padding-top: calc(40vh - 2rem);
    }
}

@media (min-width: 1024px) {
    .desktop-only {
        display: block;
    }
    
    .mobile-only {
        display: none;
    }
    
    .blur-overlay {
        left: 20rem;
        right: 20rem;
    }
}

/* Fullscreen Mode */
.fullscreen-mode .header {
    display: none;
}

.fullscreen-mode .sidebar {
    display: none;
}

.fullscreen-mode .blur-overlay {
    left: 0;
    right: 0;
}

.fullscreen-mode .blur-overlay-top {
    top: 0;
}

.fullscreen-mode .btn-settings {
    display: none;
}

/* Dyslexic Font */
.dyslexic-font {
    font-family: 'Comic Sans MS', 'OpenDyslexic', Verdana, sans-serif;
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

