/* AI Book Reader - Kindle-like Full Screen App */

/* Reset and Base - Full screen with no margins */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  width: 100%;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  /* Prevent zoom on iOS */
  touch-action: manipulation;
  -ms-touch-action: manipulation;
}

body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #faf8f5;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* Prevent pull-to-refresh and overscroll */
  overscroll-behavior: none;
  -webkit-overflow-scrolling: auto;
  /* Prevent pinch zoom */
  touch-action: pan-x pan-y;
  -ms-touch-action: pan-x pan-y;
}

/* App Container - Absolute full screen */
#app {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #faf8f5;
}

/* Welcome Screen */
#welcome-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Reader View - Full screen */
#reader-view {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  background: #faf8f5;
}

#reader-view.hidden {
  display: none;
}

/* Reader Header - Thin top bar */
#reader-header {
  flex-shrink: 0;
  height: 44px;
  background: #fff;
  border-bottom: 1px solid #e5e5e5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  z-index: 100;
}

/* Reading Area Container */
#reading-area {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* Book Viewer - Fills entire reading area */
#reader-container {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: #faf8f5;
}

#book-viewer {
  width: 100%;
  height: 100%;
  background: #faf8f5;
}

/* EPUB.js iframe - Full screen */
#book-viewer iframe {
  border: none !important;
  width: 100% !important;
  height: 100% !important;
  background: #faf8f5 !important;
  /* Prevent zoom inside iframe but allow text selection */
  touch-action: pan-x pan-y !important;
  -webkit-overflow-scrolling: auto !important;
}

/* Allow text selection in book viewer */
#book-viewer {
  -webkit-user-select: text;
  user-select: text;
}

/* Navigation Arrows - Subtle on sides */
.nav-arrow {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 15%;
  min-width: 44px;
  max-width: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  background: transparent;
  border: none;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.2s;
}

.nav-arrow:hover,
.nav-arrow:active {
  opacity: 1;
}

.nav-arrow i {
  font-size: 24px;
  color: #999;
}

#prev-btn {
  left: 0;
}

#next-btn {
  right: 0;
}

/* Tap zones for mobile - invisible but tappable */
.tap-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 25%;
  z-index: 40;
  background: transparent;
}

.tap-zone-left {
  left: 0;
}

.tap-zone-right {
  right: 0;
}

/* Sidebar TOC - Overlay */
#sidebar {
  position: absolute;
  top: 0;
  left: 0;
  bottom: 0;
  width: 280px;
  max-width: 80vw;
  background: #fff;
  z-index: 200;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  box-shadow: 2px 0 10px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
}

#sidebar:not(.hidden) {
  transform: translateX(0);
}

#sidebar-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.3);
  z-index: 199;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
}

#sidebar-backdrop.show {
  opacity: 1;
  pointer-events: auto;
}

#toc-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
  -webkit-overflow-scrolling: touch;
}

#toc-container a {
  display: block;
  padding: 12px 16px;
  color: #333;
  text-decoration: none;
  font-size: 15px;
  border-radius: 8px;
}

#toc-container a:active,
#toc-container a.active {
  background: #f0f0f0;
}

/* Text Selection */
::selection {
  background-color: #b4d5fe;
}

/* Floating Explain Button */
#floating-explain-btn {
  position: fixed;
  z-index: 300;
  padding: 8px 16px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 20px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  font-size: 14px;
  display: none;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

#floating-explain-btn.show {
  display: flex;
}

#floating-explain-btn i {
  color: #8b5cf6;
}

/* AI Popup - Bottom Sheet */
#ai-popup {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 400;
  display: none;
  flex-direction: column;
  justify-content: flex-end;
}

#ai-popup:not(.hidden) {
  display: flex;
}

#ai-popup-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
}

#ai-popup .sheet {
  position: relative;
  background: #fef7ed;
  border-radius: 20px 20px 0 0;
  max-height: 70vh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s ease;
}

#ai-popup:not(.hidden) .sheet {
  transform: translateY(0);
}

#chat-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
}

/* Chat Bubbles */
.chat-bubble-user {
  background: #f97316;
  color: #fff;
  padding: 10px 14px;
  border-radius: 18px 18px 4px 18px;
  max-width: 80%;
  margin-left: auto;
  font-size: 14px;
}

.chat-bubble-ai {
  background: #fff;
  color: #333;
  padding: 10px 14px;
  border-radius: 18px 18px 18px 4px;
  max-width: 85%;
  font-size: 14px;
  line-height: 1.5;
  border: 1px solid #e5e5e5;
}

/* Follow-up Input */
#followup-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #ddd;
  border-radius: 24px;
  font-size: 15px;
  outline: none;
  background: #fff;
}

#followup-input:focus {
  border-color: #f97316;
}

#followup-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: none;
  background: #e5e5e5;
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

#followup-send:active {
  background: #f97316;
  color: #fff;
}

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  z-index: 500;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay:not(.hidden) {
  display: flex;
}

.modal-content {
  background: #fff;
  border-radius: 16px;
  width: 100%;
  max-width: 500px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Loading Overlay */
#loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(255,255,255,0.9);
  z-index: 600;
  display: none;
  align-items: center;
  justify-content: center;
}

#loading-overlay:not(.hidden) {
  display: flex;
}

/* Utility */
.hidden {
  display: none !important;
}

/* Animation */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-4px); }
}

.animate-bounce {
  animation: bounce 0.6s infinite;
}

/* Safe area for notched phones */
@supports (padding: env(safe-area-inset-top)) {
  #reader-header {
    padding-top: env(safe-area-inset-top);
    height: calc(44px + env(safe-area-inset-top));
  }
  
  #ai-popup .sheet {
    padding-bottom: env(safe-area-inset-bottom);
  }
  
  /* PWA standalone mode - account for status bar */
  body.pwa-standalone #app {
    padding-top: env(safe-area-inset-top);
  }
  
  body.pwa-standalone #welcome-screen {
    padding-top: env(safe-area-inset-top);
  }
}

/* PWA Standalone mode adjustments */
body.pwa-standalone {
  /* Ensure full viewport usage */
  height: 100vh;
  height: -webkit-fill-available;
}

/* PWA Install Banner (hidden when installed) */
.pwa-install-prompt {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(135deg, #f97316 0%, #ea580c 100%);
  color: white;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  z-index: 700;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.2);
}

body.pwa-standalone .pwa-install-prompt {
  display: none;
}

.pwa-install-prompt button {
  background: white;
  color: #f97316;
  border: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.pwa-install-prompt .dismiss {
  background: transparent;
  color: white;
  padding: 8px;
}

/* Range Slider Styling */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 3px;
  background: #e5e5e5;
  outline: none;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #3b82f6;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input[type="range"]::-moz-range-thumb {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #3b82f6;
  cursor: pointer;
  border: 2px solid #fff;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

/* Font Settings Button States */
.font-btn, .spacing-btn, .theme-btn {
  transition: border-color 0.2s, transform 0.1s;
}

.font-btn:active, .spacing-btn:active, .theme-btn:active {
  transform: scale(0.97);
}

/* Theme body classes */
body.theme-sepia {
  background: #f8f4e8;
}

body.theme-dark {
  background: #1a1a1a;
}

body.theme-dark #app {
  background: #1a1a1a;
}

body.theme-dark #welcome-screen,
body.theme-dark #reader-view {
  background: #1a1a1a;
}

body.theme-dark #reader-header {
  background: #2d2d2d;
  border-color: #404040;
}

body.theme-dark #reader-header button {
  color: #ccc;
}

body.theme-dark #book-viewer {
  background: #1a1a1a;
}

body.theme-dark .modal-content {
  background: #2d2d2d;
  color: #e5e5e5;
}

body.theme-dark .modal-content button {
  color: #e5e5e5;
}

body.theme-sepia #app,
body.theme-sepia #welcome-screen,
body.theme-sepia #reader-view,
body.theme-sepia #book-viewer,
body.theme-sepia #reader-container {
  background: #f8f4e8;
}
