/* ===========================================
   VARIABLES CSS
   =========================================== */
:root {
    --wrapper: rgb(255, 215, 0);
    --book-page--page: white;
    --book-page--text: rgba(153, 101, 21, 0.9);
    --border-color: rgba(153, 101, 21, 0.4);
    --border-light: rgba(255, 255, 255, 0.8);
    --shadow-light: rgba(0, 0, 0, 0.1);
    --shadow-medium: rgba(0, 0, 0, 0.25);
    --shadow-dark: rgba(0, 0, 0, 0.3);
    --highlight-bg: #cbcaca63;
    --btn-hover: #f5f0e8;
    --btn-active: #e0d4be;
    --blue-gradient: linear-gradient(135deg, #15475d, #3a8bb7);
    --gold-gradient: linear-gradient(135deg, #ffd00093, #b38f008f);
}

/* ===========================================
   RESET & ESTILOS BASE (Mobile First)
   =========================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: #1a237e;
    font-family: 'Georgia', serif;
    user-select: none;
    padding: 10px;
}

/* ===========================================
   MOBILE - BASE (hasta 480px)
   =========================================== */

/* BOOK CONTAINER - Mobile */
.book {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 100vh;
    max-width: 100%;
    overflow: hidden;
}

.book__wrapper {
    position: relative;
    background-color: var(--wrapper);
    display: flex;
    justify-content: center;
    align-items: center;
    width: 90%;
    height: 75vh;
    min-height: 500px;
    border-radius: 5px;
   
    transition: transform 0.5s ease;
}

.book__wrapper:hover {
    cursor: pointer;
}

/* BOOK BODY - Mobile */
.book__body {
    display: flex;
    width: 99%;
    height: 97%;
    perspective: 1000px;
    position: relative;
    box-shadow:
        0 0 50px var(--shadow-dark),
        0 20px 40px var(--shadow-medium),
        inset 0 0 10px rgba(255, 255, 255, 0.15);
}

/* BOOK PAGES STRUCTURE - Mobile */
.book__page__body--left,
.book__page__body--right {
    position: absolute;
    width: 50%;
    box-shadow: inset 0 0 15px rgba(255, 255, 255, 0.3);
}

.book__page__body--left {
    left: -15px;
}

.book__page__body--right {
    right: -15px;
}

.book__page--left,
.book__page--right {
    position: relative;
    background-color: white;
    z-index: -30;
}

.book__page--right {
    border-right: 1.5px solid var(--border-light);
}

/* PAGE EDGE EFFECTS - Mobile */
.book__page--left::after,
.book__page--right::after {
    content: "";
    position: absolute;
    top: 0;
    width: 15px;
    height: 100%;
    pointer-events: none;
    z-index: 500;
}

.book__page--left::after {
    left: 0;
    background: repeating-linear-gradient(to right,
            rgba(0, 0, 0, 0.05) 0px,
            rgba(0, 0, 0, 0.05) 1px,
            transparent 3px);
    box-shadow: inset -5px 0 8px rgba(0, 0, 0, 0.1);
}

.book__page--right::after {
    right: 0;
    background: repeating-linear-gradient(to left,
            rgba(0, 0, 0, 0.07) 0px,
            rgba(0, 0, 0, 0.07) 1px,
            transparent 3px);
}

/* PAGINA STYLES - Mobile */
.pagina {
    position: absolute;
    width: 50%;
    height: 100%;
    display: flex;
    justify-content: center;
    font-size: 1.2rem;
    color: var(--book-page--text);
    background: var(--book-page--page);
    box-shadow: inset 0 0 15px rgba(255, 255, 255, 0.3);
    transform-style: preserve-3d;
    backface-visibility: hidden;
    cursor: pointer;
    transition: transform 1s ease, box-shadow 1s ease, opacity 0.3s ease;
}

.pagina-trasera {
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
    transform: rotateY(180deg) translateY(-12px);
    display: flex;
    justify-content: center;
    opacity: 0;
    font-size: 1rem;
    color: #444;
    background: #f9f9f9;
}

/* PAGE POSITIONS - Mobile */
#paginaIzquierda,
#paginaFijaIzquierda {
    left: 0;
    border-left: 1.5px solid var(--border-light);
    border-radius: 5px 0 0 5px;
    transform-origin: right center;
}

#paginaDerecha,
#paginaFijaDerecha {
    right: 0;
    border-right: 1.5px solid var(--border-light);
    border-radius: 0 5px 5px 0;
    transform-origin: left center;
}

#paginaIzquierda,
#paginaDerecha {
    z-index: 5;
}

#paginaFijaIzquierda,
#paginaFijaDerecha {
    z-index: 2;
    cursor: default;
}

/* PAGE STATES */
.girada-izquierda {
    transform: rotateY(180deg);
    z-index: 10 !important;
}

.girada-derecha {
    transform: rotateY(-180deg);
    z-index: 10 !important;
}

.mostrar-trasero {
    opacity: 1 !important;
}

.reset {
    transition: none !important;
}

/* CONTENT STYLES - Mobile */
.pagina-contenido {
    position: relative;
    z-index: 2;
}

.texto-pagina {
    font-size: 0.8rem;
    line-height: 1.4;
    color: var(--book-page--text);
    padding: 12px;
    white-space: pre-wrap;
}

.contenido-scrollable {
    overflow-y: auto;
    max-height: 100%;
    padding: 12px;
    color: var(--book-page--text);
    scrollbar-width: thin;
    scrollbar-color: #6633000f transparent;
}

.numero-pagina {
    position: absolute;
    bottom: 5px;
    font-size: 0.8rem;
}

.highlight {
    background-color: var(--highlight-bg);
    color: #2c2c2c;
    transition: background-color 0.3s ease;
}

/* BOOK MIDDLE SHADOW - Mobile */
.book__middle-shadow {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 2px;
    height: 100%;
    z-index: 50;
    pointer-events: none;
    background: rgba(0, 0, 0, 0.2);
    box-shadow:
        -1px 5px 25px rgba(0, 0, 0, 0.41),
        1px 5px 25px rgba(0, 0, 0, 1);
}

/* BUTTONS - Mobile */
.btn-read {
    position: absolute;
    top: 2px;
    width: auto;
    height: 28px;
    padding: 0.4rem 0.6rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-family: inherit;
    font-weight: normal;
    color: var(--book-page--text);
    background-color: transparent;
    border: none;
    border-radius: 6px;
    box-shadow: 0 2px 4px rgba(102, 51, 0, 0.15);
    backdrop-filter: blur(4px);
    cursor: pointer;
    transition: background-color 0.3s ease, box-shadow 0.3s ease, transform 0.2s ease;
}

.btn-read--left {
    left: 5px;
    right: auto;
}

.btn-read--right {
    right: 5px;
    left: auto;
}

.btn-read:hover {
    background-color: var(--btn-hover);
    box-shadow: 0 4px 8px rgba(102, 51, 0, 0.2);
}

.btn-read:active {
    background-color: var(--btn-active);
    transform: scale(0.98);
}

/* SEPARADORES - Mobile */
.separador {
    position: absolute;
    left: -30px;
    width: 30px;
    height: 5%;
    border-radius: 8px 0 0 8px;
    background: var(--gold-gradient);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
    transform-origin: right center;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: #4a2f00;
    font-weight: 700;
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    font-size: 9px;
    user-select: none;
}

.separador:hover {
    transform: scaleX(0.9);
    box-shadow: 4px 4px 20px rgba(27, 73, 91, 0.8);
}

.separador.azul {
    top: 50%;
    background: var(--blue-gradient);
}

.separador.red {
    top: 10%;
    left: -40px;
    background-color: red;
    text-align: center;
}

/* VOICE SELECTOR - Mobile */
.voice-selector {
    position: absolute;
    top: 0;
    margin: 5px;
    background: var(--wrapper);
    padding: 0.7rem;
    border-radius: 10px;
    width: 220px;
    font-family: inherit;
    box-shadow: 0 4px 12px var(--shadow-medium);
    border: 2px solid var(--border-color);
    color: var(--book-page--text);
    z-index: 520;
    visibility: hidden;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.voice-selector.visible {
    visibility: visible;
    opacity: 1;
}

.voice-selector label {
    display: block;
    font-size: 1rem;
    font-weight: bold;
    margin-bottom: 0.6rem;
    color: var(--book-page--text);
}

.voice-selector select {
    width: 100%;
    padding: 0.5rem 0.8rem;
    font-size: 0.9rem;
    font-family: inherit;
    color: var(--book-page--text);
    background-color: #fff8e1;
    border: 1px solid rgba(153, 101, 21, 0.3);
    border-radius: 8px;
    box-shadow: inset 0 1px 3px var(--shadow-light);
    appearance: none;
    background-image: url("data:image/svg+xml;utf8,<svg fill='rgba(153,101,21,0.8)' height='20' viewBox='0 0 24 24' width='20' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
    background-repeat: no-repeat;
    background-position: right 0.8rem center;
    background-size: 0.8rem;
    transition: background-color 0.3s ease, box-shadow 0.3s ease;
    cursor: pointer;
}

.voice-selector select:hover {
    background-color: #fff3cd;
}

.voice-selector select:focus {
    outline: none;
    box-shadow: 0 0 0 3px rgba(153, 101, 21, 0.3);
}

/* MODAL STYLES - Mobile */
.modal-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.6);
    display: none;
    justify-content: center;
    align-items: flex-start;
    z-index: 1000;
}

.modal-overlay.show {
    display: flex;
}

.modal-content {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background-color: white;
    padding: 1rem;
    border-radius: 10px;
    width: 98%;
    height: 75vh;
    box-shadow: 0 4px 20px var(--shadow-dark);
    display: flex;
    flex-direction: column;
}

.modal-close {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 1.5rem;
    font-weight: bold;
    color: #333;
    cursor: pointer;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: bold;
    margin-bottom: 1rem;
    color: #333;
}

.modal-body {
    flex: 1;
    display: flex;
}

.modal-form {
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-label {
    font-weight: 600;
    color: #444;
    font-size: 0.9rem;
    margin-top: 15px;
}

.modal-input,
.modal-textarea {
    padding: 0.5rem 0.8rem;
    border: 2px solid #ccc;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    font-family: 'Segoe UI', sans-serif;
    transition: border-color 0.3s ease;
}

.modal-textarea {
    width: 100%;
    height: 100%;
    resize: none;
    box-shadow: inset 0 2px 5px var(--shadow-light);
}

.modal-input:focus,
.modal-textarea:focus {
    outline: none;
    border-color: #6c63ff;
}

.modal-buttons {
    display: flex;
    gap: 0.8rem;
    margin-top: 0.5rem;
}

.btn {
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-size: 0.9rem;
    cursor: pointer;
    border: none;
    font-weight: 600;
    transition: background-color 0.3s ease;
}

.btn-save {
    background-color: #6c63ff;
    color: white;
}

.btn-save:hover {
    background-color: #5848c2;
}

.btn-clear {
    background-color: #ccc;
    color: #444;
}

.btn-clear:hover {
    background-color: #999;
}


/* ===========================================
   MOBILE MEDIANO (481px - 600px)
   =========================================== */
@media screen and (min-width: 481px) and (max-width: 600px) {
    .book__wrapper {
        width: 90%;
        height: 80vh;
        min-height: 550px;
    }

    .book__body {
        width: 90%;
        height: 97%;
    }

    .texto-pagina,
    .contenido-scrollable {
        padding: 15px;
        font-size: 0.85rem;
    }

    .pagina {
        font-size: 1.4rem;
    }

    .pagina-trasera {
        font-size: 1.1rem;
        transform: rotateY(180deg) translateY(-15px);
    }

    .book__page__body--left {
        left: -15px;
    }

    .book__page__body--right {
        right: -15px;
    }

    .book__page--left::after,
    .book__page--right::after {
        width: 15px;
    }

    .separador {
        left: -35px;
        width: 35px;
        height: 6%;
        font-size: 10px;
    }

    .separador.red {
        left: -45px;
    }

    .voice-selector {
        width: 250px;
        padding: 0.8rem;
    }

    .modal-content {
        height: 80vh;
        padding: 1.2rem;
    }
}

/* ===========================================
   TABLET (601px - 768px)
   =========================================== */
@media screen and (min-width: 601px) and (max-width: 768px) {
    body {
        padding: 15px 0;
    }

    .book {
        padding: 10px;
    }

    .book__wrapper {
        width: 90%;
        min-height: 600px;
        height: 85vh;
    }

    .book__body {
        width: 90%;
        height: 98%;
    }

    .book__page__body--left {
        left: -20px;
    }

    .book__page__body--right {
        right: -20px;
    }

    .book__page--left::after,
    .book__page--right::after {
        width: 20px;
    }

    .texto-pagina,
    .contenido-scrollable {
        padding: 20px;
        font-size: 0.9rem;
        line-height: 1.5;
    }

    .pagina {
        font-size: 1.6rem;
    }

    .pagina-trasera {
        font-size: 1.2rem;
        transform: rotateY(180deg) translateY(-20px);
    }

    .btn-read {
        height: 30px;
        padding: 0.5rem 0.8rem;
        font-size: 0.9rem;
        top: 2px;
    }

    .btn-read--left {
        left: 5px;
    }

    .btn-read--right {
        right: 5px;
    }

    .separador {
        left: -40px;
        width: 40px;
        height: 7%;
        font-size: 11px;
    }

    .separador.red {
        left: -50px;
    }

    .voice-selector {
        width: 280px;
        padding: 1rem;
        margin: 5px;
    }

    .book__middle-shadow {
        width: 2px;
    }

    .modal-content {
        width: 95%;
        height: 85vh;
        padding: 1.5rem;
    }
}

/* ===========================================
   TABLET GRANDE (769px - 1024px)
   =========================================== */
@media screen and (min-width: 769px) and (max-width: 1024px) {
    body {
        padding: 20px 0;
        align-items: flex-start;
    }

    .book {
         width: 90%;
        max-width: 95%;
        height: auto;
        min-height: 100vh;
        padding: 20px 10px;
    }

    .book__wrapper {
        width: 85%;
        min-height: 650px;
        min-width: 95%;
        height: 88vh;
    }

    .book__body {
        width: 95%;
    }

    .texto-pagina,
    .contenido-scrollable {
        padding: 25px;
        font-size: 0.95rem;
    }

    .pagina {
        font-size: 1.8rem;
    }

    .pagina-trasera {
        font-size: 1.4rem;
        transform: rotateY(180deg) translateY(-25px);
    }

    .book__page__body--left {
        left: -25px;
    }

    .book__page__body--right {
        right: -25px;
    }

    .book__page--left::after,
    .book__page--right::after {
        width: 25px;
    }

    .separador {
        left: -45px;
        width: 45px;
        height: 8%;
        font-size: 12px;
    }

    .separador.red {
        left: -55px;
    }

    .btn-read {
        padding: 0.6rem 1rem;
        font-size: 0.95rem;
    }

    .voice-selector {
        width: 300px;
        padding: 1.2rem 1.5rem;
        margin: 10px;
    }

    .voice-selector label {
        font-size: 1.1rem;
    }

    .voice-selector select {
        padding: 0.6rem 1rem;
        font-size: 1rem;
    }

    .modal-content {
        width: 90%;
        height: 90vh;
        padding: 2rem;
    }

    .modal-title {
        font-size: 1.8rem;
    }
}

/* ===========================================
   LAPTOPS (1025px - 1200px)
   =========================================== */
@media screen and (min-width: 1025px) and (max-width: 1200px) {
    .book {
        max-width: 90%;
    }

    .book__wrapper {
        width: 80%;
        min-height: 700px;
    }

    .book__body {
        width: 93%;
    }

    .texto-pagina,
    .contenido-scrollable {
        padding: 30px;
        font-size: 1rem;
    }

    .pagina {
        font-size: 2rem;
    }

    .pagina-trasera {
        font-size: 1.5rem;
        transform: rotateY(180deg) translateY(-30px);
    }

    .book__page__body--left {
        left: -25px;
    }

    .book__page__body--right {
        right: -25px;
    }

    .book__page--left::after,
    .book__page--right::after {
        width: 25px;
    }

    .separador {
        left: -50px;
        width: 50px;
    }

    .separador.red {
        left: -60px;
    }
}

/* ===========================================
   ESCRITORIO (1201px en adelante)
   =========================================== */
@media screen and (min-width: 1201px) {
    body {
        padding: 0;
    }

    .book {
        max-width: 80%;
        padding: 0;
    }

    .book__wrapper {
        width: 70%;
        height: 90%;
        min-width: 90%;
        min-height: 800px;
        border-radius: 7px;
    }

    .book__body {
        width: 91%;
        height: 99%;
        perspective: 1500px;
    }

    .book__page__body--left {
        left: -30px;
    }

    .book__page__body--right {
        right: -30px;
    }

    .book__page--left::after,
    .book__page--right::after {
        width: 30px;
    }

    .texto-pagina,
    .contenido-scrollable {
        padding: 40px;
        font-size: 1.1rem;
        line-height: 1.6;
    }

    .pagina {
        font-size: 2rem;
    }

    .pagina-trasera {
        transform: rotateY(180deg) translateY(-40px);
        font-size: 1.5rem;
    }

    .numero-pagina {
        bottom: 10px;
        font-size: 1rem;
    }

    .btn-read {
        height: 35px;
        padding: 0.75rem 1.25rem;
        font-size: 1.05rem;
        top: 1px;
    }

    .btn-read--left {
        left: 2px;
    }

    .btn-read--right {
        right: 2px;
    }

    .separador {
        left: -59px;
        width: 60px;
        height: 9%;
        font-size: 13px;
    }

    .separador.red {
        left: -70px;
    }

    .book__middle-shadow {
        width: 3px;
    }

    .voice-selector {
        width: 300px;
        padding: 1.2rem 1.5rem;
    }

    .modal-content {
        width: 90%;
        height: 90vh;
    }
}

/* ===========================================
   AJUSTES DE ORIENTACIÓN
   =========================================== */

/* Landscape en móviles */
@media screen and (max-height: 600px) and (orientation: landscape) {
    .book__wrapper {
        height: 95vh;
        min-height: 350px;
    }

    .book__body {
        height: 98%;
    }

    .texto-pagina,
    .contenido-scrollable {
        padding: 15px;
        font-size: 0.8rem;
    }

    .pagina-trasera {
        transform: rotateY(180deg) translateY(-15px);
    }

    .separador {
        height: 12%;
    }
}

/* Portrait en tablets */
@media screen and (orientation: portrait) and (min-width: 769px) and (max-width: 1024px) {
    .book__wrapper {
        height: 88vh;
        min-height: 700px;
    }
}

/* Pantallas muy grandes */
@media screen and (min-width: 1600px) {
    .book {
        max-width: 1400px;
    }

    .book__wrapper {
        max-width: 1200px;
        min-height: 900px;
    }

    .texto-pagina,
    .contenido-scrollable {
        padding: 50px;
        font-size: 1.2rem;
        line-height: 1.7;
    }

    .pagina-trasera {
        transform: rotateY(180deg) translateY(-50px);
        font-size: 1.7rem;
    }
}