/* ===== India Library — Reader Stylesheet ===== */
/* v2.0.0 — Mobile-first redesign */

:root {
  --r-bg: #FEFCF7;
  --r-text: #2D1B0E;
  --r-muted: #9B8B7A;
  --r-accent: #800000;
  --r-accent-soft: rgba(128,0,0,0.08);
  --r-toolbar-bg: #800000;
  --r-toolbar-text: #fff;
  --r-border: #E8DDD0;
  --r-shadow: rgba(45,27,14,0.12);
  --r-progress: #FF9933;
  --r-radius: 12px;
  --r-sheet-bg: #FFFFFF;
}

/* Sepia theme */
[data-theme="sepia"] {
  --r-bg: #F5E6CC;
  --r-text: #5C4A3A;
  --r-muted: #8B7E6A;
  --r-toolbar-bg: #6B4226;
  --r-border: #D4C4A8;
  --r-shadow: rgba(92,74,58,0.12);
  --r-sheet-bg: #F0DDBE;
  --r-accent-soft: rgba(107,66,38,0.1);
}

/* Dark theme */
[data-theme="dark"] {
  --r-bg: #1C1C1E;
  --r-text: #D4CFC8;
  --r-muted: #8E8E93;
  --r-toolbar-bg: #2C2C2E;
  --r-toolbar-text: #E5E5EA;
  --r-border: #38383A;
  --r-shadow: rgba(0,0,0,0.3);
  --r-progress: #FF9F0A;
  --r-sheet-bg: #2C2C2E;
  --r-accent: #FF9F0A;
  --r-accent-soft: rgba(255,159,10,0.12);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Noto Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--r-bg);
  color: var(--r-text);
}

/* ===== Shell ===== */
.reader-shell {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  background: var(--r-bg);
  z-index: 200;
}

/* ===== Toolbar ===== */
.reader-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  height: 56px;
  min-height: 56px;
  background: var(--r-toolbar-bg);
  color: var(--r-toolbar-text);
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 10;
  /* safe area for notch phones */
  padding-top: env(safe-area-inset-top, 0);
}

.reader-toolbar.hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

.tb-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: 'Playfair Display', Georgia, serif;
}

.tb-actions {
  display: flex;
  gap: 4px;
}

.tb-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  min-width: 44px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.12);
  color: inherit;
  cursor: pointer;
  transition: background 0.2s;
  text-decoration: none;
  -webkit-tap-highlight-color: transparent;
}
.tb-btn:hover { background: rgba(255,255,255,0.22); }
.tb-btn:active { background: rgba(255,255,255,0.3); }
.tb-back { margin-right: 4px; }

/* ===== Progress track ===== */
.reader-progress-track {
  height: 2px;
  background: var(--r-border);
  flex-shrink: 0;
}
.reader-progress-fill {
  height: 100%;
  width: 0%;
  background: var(--r-progress);
  transition: width 0.4s ease;
}

/* ===== Reader viewport ===== */
.reader-viewport {
  flex: 1;
  position: relative;
  overflow: hidden;
  background: var(--r-bg);
}

#reader-area {
  width: 100%;
  height: 100%;
}

/* Invisible tap zones */
.tap-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 25%;
  z-index: 2;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.tap-prev { left: 0; }
.tap-next { right: 0; }

/* Subtle tap feedback */
.tap-zone:active {
  background: radial-gradient(circle at center, rgba(128,0,0,0.04) 0%, transparent 70%);
}

/* ===== Status bar ===== */
.reader-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
  height: auto;
  min-height: 36px;
  background: var(--r-bg);
  border-top: 1px solid var(--r-border);
  font-size: 0.75rem;
  color: var(--r-muted);
  transition: transform 0.3s ease, opacity 0.3s ease;
  z-index: 10;
}

.reader-status.hidden {
  transform: translateY(100%);
  opacity: 0;
  pointer-events: none;
}

.status-chapter {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-right: 12px;
}

.status-percent {
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--r-accent);
}

/* ===== Settings bottom sheet ===== */
.sheet-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s, visibility 0.3s;
  z-index: 50;
}
.sheet-overlay.active {
  opacity: 1;
  visibility: visible;
}

.settings-sheet {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  max-height: 80vh;
  background: var(--r-sheet-bg);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -4px 24px var(--r-shadow);
  padding: 12px 24px 24px;
  padding-bottom: max(24px, env(safe-area-inset-bottom, 24px));
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 60;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.settings-sheet.open {
  transform: translateY(0);
}

.sheet-handle {
  width: 36px;
  height: 4px;
  background: var(--r-border);
  border-radius: 2px;
  margin: 0 auto 20px;
}

.sheet-section {
  margin-bottom: 24px;
}

.sheet-label {
  display: block;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--r-muted);
  margin-bottom: 10px;
}

.sheet-hint {
  font-size: 0.85rem;
  color: var(--r-muted);
  padding: 8px 0;
}

/* Font size controls */
.font-size-row {
  display: flex;
  align-items: center;
  gap: 16px;
  justify-content: center;
}

.size-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 2px solid var(--r-border);
  background: var(--r-sheet-bg);
  color: var(--r-text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.size-btn:active {
  border-color: var(--r-accent);
  background: var(--r-accent-soft);
}

.size-value {
  font-weight: 600;
  font-size: 1rem;
  min-width: 50px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* Theme chips */
.theme-row {
  display: flex;
  gap: 10px;
}

.theme-chip {
  flex: 1;
  padding: 14px 0;
  border-radius: var(--r-radius);
  border: 2px solid var(--r-border);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  font-family: 'Noto Sans', sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.theme-chip.light {
  background: #FEFCF7;
  color: #2D1B0E;
  border-color: #E8DDD0;
}
.theme-chip.sepia {
  background: #F5E6CC;
  color: #5C4A3A;
  border-color: #D4C4A8;
}
.theme-chip.dark {
  background: #1C1C1E;
  color: #D4CFC8;
  border-color: #38383A;
}

.theme-chip.active {
  border-color: var(--r-accent);
  box-shadow: 0 0 0 2px var(--r-accent);
}

/* Font chips */
.font-row {
  display: flex;
  gap: 10px;
}

.font-chip {
  flex: 1;
  padding: 12px 0;
  border-radius: var(--r-radius);
  border: 2px solid var(--r-border);
  background: var(--r-sheet-bg);
  color: var(--r-text);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}

.font-chip.active {
  border-color: var(--r-accent);
  background: var(--r-accent-soft);
}

/* TOC list */
.toc-list {
  max-height: 240px;
  overflow-y: auto;
}

.toc-item {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  min-height: 44px;
  color: var(--r-text);
  border-radius: 8px;
  font-size: 0.9rem;
  text-decoration: none;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.toc-item:hover, .toc-item:active {
  background: var(--r-accent-soft);
  color: var(--r-accent);
}

/* Bookmarks */
.bm-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 0;
  border-bottom: 1px solid var(--r-border);
}

.bm-text {
  flex: 1;
  font-size: 0.85rem;
  color: var(--r-text);
}

.bm-go {
  padding: 8px 14px;
  border: none;
  border-radius: 8px;
  background: var(--r-accent);
  color: #fff;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  -webkit-tap-highlight-color: transparent;
}

.bm-del {
  padding: 8px 10px;
  border: none;
  border-radius: 8px;
  background: var(--r-accent-soft);
  color: var(--r-muted);
  font-size: 1rem;
  cursor: pointer;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-tap-highlight-color: transparent;
}

/* ===== Toast ===== */
.reader-toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%) translateY(16px);
  background: var(--r-toolbar-bg);
  color: var(--r-toolbar-text);
  padding: 10px 24px;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 200;
  pointer-events: none;
  white-space: nowrap;
}
.reader-toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ===== Loading overlay ===== */
.reader-loading {
  position: fixed;
  inset: 0;
  background: var(--r-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 100;
  transition: opacity 0.3s;
}
.reader-loading.fade-out { opacity: 0; pointer-events: none; }

.reader-loading p {
  font-size: 0.9rem;
  color: var(--r-muted);
  font-weight: 500;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--r-border);
  border-top-color: var(--r-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ===== Desktop tweaks ===== */
@media (min-width: 769px) {
  .reader-toolbar { height: 52px; padding: 0 24px; }
  .tb-btn { width: 40px; height: 40px; min-width: 40px; }

  /* Constrain reading width for comfort */
  #reader-area {
    max-width: 720px;
    margin: 0 auto;
  }

  .reader-status { padding: 8px 24px; }

  .settings-sheet {
    max-width: 420px;
    left: auto;
    right: 24px;
    bottom: 24px;
    border-radius: 20px;
  }
}

/* ===== Small phone adjustments ===== */
@media (max-width: 380px) {
  .tb-title { font-size: 0.85rem; }
  .tb-btn { width: 40px; height: 40px; min-width: 40px; }
  .settings-sheet { padding: 12px 16px 20px; }
}
