:root {
    --gold: #8b4513;
    --blue: #003366;
    --glass: rgba(255, 255, 255, 0.28);
    --sidebar-w: 300px;
    --sidebar-peek: 44px;
}

body, html { margin: 0; padding: 0; background-color: #000; font-family: 'Segoe UI', Tahoma, sans-serif; color: #000; overflow-x: hidden; }

/* --- SIDEBAR --- */
#sidebar {
    position: fixed; top: 0; left: calc(var(--sidebar-w) * -1 + var(--sidebar-peek));
    width: var(--sidebar-w); height: 100vh; background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(25px); z-index: 2000; transition: left 0.35s ease-in-out;
    display: flex; flex-direction: column; border-right: 1px solid rgba(255,255,255,0.1);
}
/* Apertura/cierre del menú: clase .open (controlada por JS, para tocar con
   el dedo en móvil o clicar la pestaña) y, además, :hover en dispositivos
   con ratón real —se despliega al pasar por encima y se repliega al alejarse—.
   La pestaña ya no deja pasar los clics a las opciones de debajo (ver
   .sidebar-tab), así que combinar ambos mecanismos ya no genera clics
   accidentales sobre capítulos u otras opciones del menú. */
#sidebar.open { left: 0; background: rgba(255, 255, 255, 0.98); }

@media (hover: hover) and (pointer: fine) {
    #sidebar:hover { left: 0; background: rgba(255, 255, 255, 0.98); }
}

/* Pestaña "MENÚ": siempre visible y clicable, abre/cierra el menú */
.sidebar-tab {
    position: absolute; top: 0; right: 0; width: var(--sidebar-peek); height: 100%;
    display: flex; align-items: center; justify-content: center;
    background: rgba(10, 10, 10, 0.88); border-left: 1px solid rgba(255,255,255,0.18);
    cursor: pointer; z-index: 5;
}
.sidebar-tab span {
    writing-mode: vertical-lr; text-orientation: upright;
    color: #f3c46b; font-weight: 800; font-size: 1.05rem;
    letter-spacing: 0.2em; text-transform: uppercase;
    text-shadow: 0 1px 3px rgba(0,0,0,0.9);
    pointer-events: none;
}

.sidebar-header { padding: 30px; font-weight: 900; color: var(--gold); font-size: 1.6rem; text-align: center; }
#menu-list { list-style: none; padding: 0; margin: 0; flex-grow: 1; overflow-y: auto; }
.menu-section-title { padding: 20px 25px 5px; font-size: 0.7rem; color: var(--gold); font-weight: 800; text-transform: uppercase; letter-spacing: 1.5px; opacity: 0.8; }
.menu-item { padding: 10px 25px; cursor: pointer; font-size: 0.8rem; font-weight: 600; color: #333; transition: 0.2s; text-transform: uppercase; }
.menu-item:hover { background: var(--gold); color: #fff; padding-left: 35px; }

/* --- LECTOR E IMÁGENES --- */
#reader-overlay { position: fixed; top: 0; left: 0; width: 100vw; height: 100vh; background: rgba(0,0,0,0.85); z-index: 3000; display: flex; justify-content: center; align-items: center; }
.reader-hidden { opacity: 0; pointer-events: none; }
.reader-content { background: #fff; width: 90%; max-width: 1000px; height: 90vh; border-radius: 15px; padding: 40px; overflow-y: auto; position: relative; }
.close-reader { position: sticky; top: -20px; float: right; background: var(--gold); color: #fff; border: none; padding: 10px 20px; cursor: pointer; border-radius: 5px; font-weight: bold; z-index: 100; }
.reader-image { display: block; max-width: 100%; max-height: 70vh; width: auto; height: auto; margin: 20px auto; border-radius: 8px; box-shadow: 0 10px 20px rgba(0,0,0,0.2); }

/* Referencias cruzadas clicables ("Capítulo N" / "Apéndice N") dentro del texto */
.xref-link { color: var(--gold); font-weight: 700; cursor: pointer; border-bottom: 1px dotted var(--gold); }
.xref-link:hover { background: rgba(139,69,19,0.1); }

/* --- ENCUESTA APAISADA --- */
.survey-form { display: flex; flex-direction: column; gap: 20px; margin-top: 10px; width: 100%; }
.form-row-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 15px; }
.check-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 10px; background: #f4f4f4; padding: 20px; border-radius: 10px; }
.survey-form label { font-size: 0.85rem; font-weight: 800; color: var(--blue); text-transform: uppercase; }
.survey-form textarea { width: 100%; min-height: 220px; padding: 15px; font-size: 1.1rem; border: 2px solid #eee; border-radius: 10px; box-sizing: border-box; }

/* --- FONDOS Y SECCIONES --- */
#bg-container { position: fixed; width: 100vw; height: 100vh; z-index: 0; pointer-events: none; }
.layer { position: absolute; width: 100%; height: 100%; background-size: cover; background-position: center; transition: opacity 1.8s ease-in-out; opacity: 0; }
.screen { min-height: 100vh; display: flex; justify-content: center; align-items: center; padding: 100px 40px; border: 1px solid transparent; }
.glass-card { background: var(--glass); backdrop-filter: blur(25px); border-radius: 20px; padding: 4rem; max-width: 950px; width: 100%; }
.gold-title { color: var(--gold); font-size: 2.8rem; font-weight: 800; margin-bottom: 2rem; }

/* --- COMPONENTES --- */
.formula-highlight { display: flex; justify-content: center; margin: 3rem 0; padding: 2rem; background: rgba(255,255,255,0.4); border-radius: 15px; }
.term-link { color: var(--blue); font-weight: 700; border-bottom: 2px solid var(--blue); cursor: help; }
.tooltip { position: fixed; padding: 15px; background: #fff; border: 2px solid var(--gold); border-radius: 8px; z-index: 10000; display: none; max-width: 350px; box-shadow: 0 10px 20px rgba(0,0,0,0.3); }
#music-btn { position: fixed; top: 20px; right: 20px; z-index: 1000; background: #fff; padding: 10px 20px; border-radius: 30px; cursor: pointer; font-weight: bold; }

/* --- NARRACIÓN POR VOZ (TTS) --- */
.tts-read-btn {
    display: inline-flex; align-items: center; gap: 6px;
    margin-top: 18px; float: right;
    font-size: 0.7rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase;
    color: var(--gold); background: #fff;
    border: 1px solid rgba(139,69,19,0.4);
    padding: 8px 16px; border-radius: 20px; cursor: pointer;
    transition: all 0.2s;
}
.tts-read-btn:hover { background: rgba(139,69,19,0.08); }
.tts-read-btn.speaking { background: var(--gold); color: #fff; }

#tts-bar {
    position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%) translateY(20px);
    z-index: 5000;
    display: flex; align-items: center; gap: 10px;
    background: rgba(255,255,255,0.97);
    border: 1px solid #eee; border-top: 2px solid var(--gold);
    border-radius: 40px; padding: 10px 20px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.18);
    backdrop-filter: blur(20px);
    transition: opacity 0.4s, transform 0.4s;
    opacity: 0; pointer-events: none;
}
#tts-bar.active { opacity: 1; pointer-events: all; transform: translateX(-50%) translateY(0); }
#tts-title {
    font-size: 0.7rem; letter-spacing: 0.05em; color: #888; text-transform: uppercase;
    max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tts-btn {
    background: none; border: none; cursor: pointer;
    color: var(--gold); font-size: 1.1rem; padding: 4px 8px;
    border-radius: 50%; transition: background 0.2s;
    display: flex; align-items: center; justify-content: center;
}
.tts-btn:hover { background: rgba(139,69,19,0.12); }
.tts-btn.stop { color: #c0392b; }
#tts-progress { width: 100px; height: 3px; background: rgba(139,69,19,0.15); border-radius: 2px; overflow: hidden; }
#tts-progress-bar { height: 100%; width: 0%; background: var(--gold); transition: width 0.3s; }

#tts-settings {
    position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
    margin-bottom: 12px; background: #fff; border: 1px solid #eee; border-radius: 14px;
    padding: 16px 20px; box-shadow: 0 8px 24px rgba(0,0,0,0.15);
    display: none; flex-direction: column; gap: 12px; width: 220px;
}
#tts-settings.open { display: flex; }
#tts-settings label { display: flex; flex-direction: column; gap: 4px; font-size: 0.7rem; font-weight: 700; color: #555; text-transform: uppercase; letter-spacing: 0.04em; }
#tts-settings select, #tts-settings input[type="range"] { width: 100%; }
#tts-settings select { padding: 6px; border-radius: 6px; border: 1px solid #ddd; font-size: 0.85rem; text-transform: none; }

/* --- TIPOGRAFÍA DEL CONTENIDO (capítulos, apéndices, textos) --- */
#reader-body, .content-body {
    font-size: 1rem; line-height: 1.75; color: #2b2b2b;
}
#reader-body p, .content-body p {
    margin: 0 0 1.1em; text-align: justify;
}
#reader-body h3.subheading, .content-body h3.subheading {
    color: var(--gold); font-size: 1.15rem; font-weight: 800;
    margin: 1.8em 0 0.7em; padding-bottom: 6px;
    border-bottom: 2px solid rgba(139,69,19,0.2);
}
#reader-body h3.subheading:first-child, .content-body h3.subheading:first-child { margin-top: 0; }
#reader-body ul, .content-body ul,
#reader-body ol, .content-body ol {
    margin: 0 0 1.2em; padding-left: 1.6em;
}
#reader-body li, .content-body li {
    margin-bottom: 0.5em; line-height: 1.6;
}
#reader-body ul li::marker { color: var(--gold); }
#reader-body ol li::marker { color: var(--gold); font-weight: 700; }

/* --- HOJA DE CÁLCULO EMBEBIDA (Google Sheets) --- */
.reader-content.reader-wide { max-width: 96vw; width: 96vw; height: 92vh; }
.sheet-embed-frame { width: 100%; height: 78vh; border: 1px solid #eee; border-radius: 8px; }
