:root {
  --bg-light: #f5f7fa;
  --text-light: #333;
  --bg-dark: #1e1e1e;
  --text-dark: #f5f5f5;
  /* Red Aesthetic */
  --accent-color: #D32F2F;
  --accent-light: #FF6659;
}

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Roboto', sans-serif;
  background: var(--bg-light);
  color: var(--text-light);
  transition: background-color 0.3s, color 0.3s;
  height: 100%;
  overflow: hidden; /* Main container handles scroll */
}

body.dark {
  background: var(--bg-dark);
  color: var(--text-dark);
}

.hidden { display: none !important; }

/* SVG Icons - ensure they scale */
.icon {
  width: 24px;
  height: 24px;
  fill: currentColor;
  vertical-align: middle;
}

/* =========================================
   LIBRARY SCREEN
   ========================================= */
#libraryScreen {
  padding: 2rem;
  text-align: center;
  height: 100%;
  box-sizing: border-box;
  overflow-y: auto;
}
.book-list {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 1rem;
}
.book-item {
  width: 150px;
  text-align: center;
  cursor: pointer;
}
.book-cover {
  width: 150px;
  height: 200px;
  object-fit: cover;
  border: 2px solid var(--accent-color);
  border-radius: 4px;
}
.book-title {
  margin-top: 0.5rem;
  font-size: 0.9rem;
  font-weight: bold;
}

/* =========================================
   READER SCREEN
   ========================================= */
#readerScreen {
  position: relative;
  width: 100%;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* TOOLBAR */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: linear-gradient(90deg, var(--accent-color), #B71C1C);
  color: #fff;
  padding: 0.5rem 1rem;
  z-index: 1000;
  flex-shrink: 0;
}
.toolbar button {
  background: rgba(255,255,255,0.2);
  border: none;
  padding: 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
}
.toolbar button:hover {
  background: rgba(255,255,255,0.3);
}
.spacer { flex: 1; }

/* READER CONTAINER */
#readerContainer {
  position: relative;
  flex: 1;
  overflow: hidden; /* epub.js handles its own overflow usually */
}
#reader {
  width: 100%;
  height: 100%;
  /* Fade-in */
  opacity: 0;
  transition: opacity 0.2s ease-in-out;
}

/* TOC Sidebar (Desktop) / Overlay (Mobile) */
#toc {
  background: #fff;
  color: #333;
  border-right: 1px solid #ccc;
  overflow-y: auto;
  transition: transform 0.3s ease;
  z-index: 900;
}
body.dark #toc {
  background: #222;
  color: #f5f5f5;
  border-right: 1px solid #444;
}
#toc ul { list-style: none; margin: 0; padding: 1rem; }
#toc li { margin-bottom: 0.5rem; }
#toc a { text-decoration: none; color: inherit; display: block; padding: 0.2rem 0; }
#toc a:hover { color: var(--accent-color); }

/* Bookmark Modal */
.modal {
  position: fixed;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(0,0,0,0.5);
  z-index: 2000;
  display: flex;
  justify-content: center;
  align-items: center;
}
.modal-content {
  background: #fff;
  color: #333;
  padding: 1.5rem;
  border-radius: 6px;
  max-width: 90%;
  max-height: 80%;
  overflow-y: auto;
  width: 400px;
}
body.dark .modal-content {
  background: #2e2e2e;
  color: #f5f5f5;
}

/* =========================================
   RESPONSIVE DESIGN
   ========================================= */

/* DESKTOP MODE (Default/Large Screens) */
@media (min-width: 769px) {
  /* Toolbar at Top */
  .toolbar {
    order: -1; /* Top */
  }

  #toc {
    position: absolute;
    top: 0;
    left: 0;
    width: 250px;
    height: 100%;
    transform: translateX(-100%); /* Hidden by default */
  }
  #toc.active {
    transform: translateX(0);
  }
}

/* MOBILE MODE (Small Screens) */
@media (max-width: 768px) {
  /* Toolbar at Bottom */
  .toolbar {
    order: 1; /* Bottom */
    justify-content: space-around;
    padding: 0.5rem;
  }

  /* Simplify toolbar for mobile */
  .toolbar span#pageInfo {
    display: none; /* Hide page info to save space, or move it */
  }

  #readerContainer {
    /* For scrolled-doc, we might need padding-bottom so content isn't behind toolbar */
    padding-bottom: 0;
  }

  /* TOC as Full Overlay */
  #toc {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    transform: translateY(-100%);
  }
  #toc.active {
    transform: translateY(0);
  }
}
