* { 
  box-sizing: border-box; 
  margin: 0; 
  padding: 0; 
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg-color: #f4f4f9;
  --viewer-bg: #ffffff;
  --panel-bg: #ffffff;
  --text-color: #333333;
  --border-color: #e0e0e0;
  --hover-bg: #f0f0f4;
  --accent-color: #0066cc;
  --nav-btn-color: #000000;
  --danger-color: #d9534f;
  --progress-bg: #e0e0e0;
}

body.dark-mode {
  --bg-color: #121212;
  --viewer-bg: #121212;
  --panel-bg: #1e1e1e;
  --text-color: #e0e0e0;
  --border-color: #333333;
  --hover-bg: #2a2a2a;
  --accent-color: #64b5f6;
  --nav-btn-color: #ffffff;
  --danger-color: #e57373;
  --progress-bg: #2a2a2a;
}

body { 
  font-family: 'Inter', system-ui, -apple-system, sans-serif; 
  height: 100vh; 
  display: flex; 
  flex-direction: column; 
  background: var(--bg-color); 
  color: var(--text-color); 
  overflow: hidden; 
  touch-action: manipulation;
}

/* Landing Page inicial */
body.landing-mode {
  height: 100vh;
  background: url("bg.svg") no-repeat fixed center;
  background-size: cover;
  display: flex;
  justify-content: center;  
  align-items: center;
  padding: 0;
  margin: 0;
}

#empty-state { 
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
}

#landing-logo { 
  width: 80vw; 
  max-width: 100%;
  opacity: 0.8; 
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.2s, transform 0.2s;
}

#landing-logo:active, #landing-logo:hover {
  opacity: 1;
  transform: scale(1.02);
}

/* Viewer Lector */
#viewer-container { 
  flex: 1; 
  width: 100%; 
  height: 100%; 
  position: relative; 
  display: flex; 
  justify-content: center; 
  align-items: center; 
  overflow: hidden; 
  touch-action: pan-y;
}

#viewer { 
  width: 100%; 
  height: 100%; 
  background: var(--viewer-bg); 
}

/* Botones flotantes laterales */
.nav-edge {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 60px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--nav-btn-color);
  font-size: 2.5rem;
  cursor: pointer;
  opacity: 0.04;
  transition: opacity 0.2s ease, background 0.2s ease;
  z-index: 20;
  user-select: none;
  border: none;
  outline: none;
  touch-action: manipulation;
}
.nav-edge:hover, .nav-edge:active {
  opacity: 0.8;
  background: rgba(128, 128, 128, 0.15);
}
.nav-edge.left { left: 0; }
.nav-edge.right { right: 0; }

/* Footer / Barra inferior */
footer { 
  background: linear-gradient(to right, var(--progress-bg) 0%, var(--progress-bg) var(--progress, 0%), var(--panel-bg) var(--progress, 0%), var(--panel-bg) 100%); 
  border-top: 1px solid var(--border-color); 
  height: 40px; 
  padding: 0 0.8rem; 
  padding-bottom: 0.1rem;
  display: flex; 
  align-items: center; 
  justify-content: space-between; 
  gap: 1rem; 
  z-index: 10; 
  width: 100%; 
  transition: background 0.3s ease;
}

.controls { 
  display: flex; 
  gap: 0.5rem; 
  align-items: center; 
  min-width: 0; 
  height: 100%;
}

.btn { 
  background: var(--accent-color); 
  color: white; 
  border: none; 
  padding: 0 0.8rem; 
  border-radius: 4px; 
  cursor: pointer; 
  font-size: 0.85rem; 
  font-weight: 500; 
  transition: background 0.2s; 
  white-space: nowrap; 
  height: 80%;
  display: flex;
  align-items: center;
  touch-action: manipulation;
}
.btn:hover { filter: brightness(0.9); }
input[type="file"] { display: none; }

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-color);
  padding: 0 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1.6rem;
  line-height: 1;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
  touch-action: manipulation;
}
.btn-icon:hover, .btn-icon:active { background: var(--hover-bg); }

/* Título y Subtítulo */
.toc-container { 
  position: relative; 
  display: flex; 
  align-items: center; 
  min-width: 0; 
  height: 100%;
}
.book-header-display { 
  display: flex; 
  align-items: center; 
  gap: 0.4rem; 
  cursor: pointer; 
  user-select: none;
  padding: 0 0.4rem;
  border-radius: 4px;
  transition: background 0.2s;
  min-width: 0;
  height: 100%;
  touch-action: manipulation;
}
.book-header-display:hover, .book-header-display:active { background: var(--hover-bg); }

.title-main { 
  font-weight: 700; 
  font-size: 1rem;
  line-height: 1;
  color: var(--text-color);
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis; 
  max-width: 140px;
  display: flex;
  align-items: center;
}

.title-sep { 
  opacity: 0.4; 
  font-size: 1rem; 
  line-height: 1;
  font-weight: 300;
  display: flex;
  align-items: center;
}

.chapter-sub { 
  font-weight: 400; 
  font-size: 0.9rem; 
  line-height: 1;
  opacity: 0.8;
  color: var(--text-color);
  white-space: nowrap; 
  overflow: hidden; 
  text-overflow: ellipsis; 
  max-width: 160px;
  display: flex;
  align-items: center;
}

.dropdown-arrow {
  font-size: 0.75rem;
  opacity: 0.6;
  margin-left: 0.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
}

/* Dropdowns generales */
.dropdown-menu { 
  display: none; 
  position: absolute; 
  bottom: 125%; 
  background: var(--panel-bg); 
  border: 1px solid var(--border-color); 
  border-radius: 8px; 
  box-shadow: 0 4px 16px rgba(0,0,0,0.2); 
  z-index: 100; 
  color: var(--text-color);
}
.dropdown-menu.open { display: block; }

/* Desplegable TOC */
.toc-dropdown { 
  left: 0; 
  max-height: 300px; 
  overflow-y: auto; 
  width: 280px; 
}
.toc-item { 
  padding: 0.8rem 1rem; 
  cursor: pointer; 
  font-size: 0.9rem; 
  border-bottom: 1px solid var(--border-color); 
  text-overflow: ellipsis; 
  overflow: hidden; 
  white-space: nowrap; 
  touch-action: manipulation;
}
.toc-item:hover, .toc-item:active { background: var(--hover-bg); color: var(--accent-color); }

/* Menú de Opciones */
.options-wrapper { 
  position: relative; 
  height: 100%; 
  display: flex; 
  align-items: center; 
}
.options-menu {
  right: 0;
  width: 260px;
  max-height: 80vh;
  overflow-y: auto;
  padding: 1rem;
  display: none;
  flex-direction: column;
  gap: 0.9rem;
}
.options-menu.open { display: flex; }

.option-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}
.option-group label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  opacity: 0.7;
}

.btn-toggle-option {
  width: 100%;
  padding: 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--hover-bg);
  color: var(--text-color);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  text-align: center;
  transition: background 0.2s;
  touch-action: manipulation;
}
.btn-toggle-option:hover { filter: brightness(0.95); }

.btn-reset {
  border-color: var(--danger-color);
  color: var(--danger-color);
  background: transparent;
  font-weight: 600;
}
.btn-reset:hover {
  background: var(--danger-color);
  color: white;
}

.select-input {
  width: 100%;
  padding: 0.5rem;
  border-radius: 6px;
  border: 1px solid var(--border-color);
  background: var(--hover-bg);
  color: var(--text-color);
  font-size: 0.85rem;
  outline: none;
  font-family: inherit;
}

.size-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--hover-bg);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.3rem;
}
.size-btn {
  background: transparent;
  border: none;
  color: var(--text-color);
  font-size: 1rem;
  font-weight: bold;
  padding: 0.4rem 0.9rem;
  cursor: pointer;
  border-radius: 4px;
  touch-action: manipulation;
}
.size-btn:hover, .size-btn:active { background: var(--panel-bg); }
.size-val { font-size: 0.85rem; font-weight: 600; }

@media (min-width: 600px) {
  .title-main { max-width: 220px; font-size: 1.1rem; }
  .chapter-sub { max-width: 260px; font-size: 1rem; }
  footer { height: 30px; }
  .toc-dropdown { width: 320px; }
  .toc-item { padding: 0.6rem 1rem; font-size: 0.85rem; }
}