/**
 * CasketEmpty Secure EPUB Reader Styles
 * Location: /inc/css/reader.css
 */

:root {
  --reader-bg: #f9f9fb;
  --reader-text: #222222;
  --reader-surface: #ffffff;
  --reader-border: #e0e0e0;
  --reader-accent: #2e7d32;
  --reader-header-h: 56px;
  --reader-footer-h: 44px;
}

[data-theme="sepia"] {
  --reader-bg: #f4ecd8;
  --reader-text: #5b4636;
  --reader-surface: #ede3cc;
  --reader-border: #dcd0b8;
}

[data-theme="dark"] {
  --reader-bg: #18191a;
  --reader-text: #e4e6eb;
  --reader-surface: #242526;
  --reader-border: #3a3b3c;
  --reader-accent: #66bb6a;
}

/* Standalone Reader Body & Hide Floating Cart */
body.ce-reader-standalone {
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: var(--reader-bg);
}

body.ce-reader-standalone .ce-floating-cart-btn {
  display: none !important;
}

/* Reader Shell */
.reader-app-wrapper {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  background-color: var(--reader-bg);
  color: var(--reader-text);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
}

/* Top Toolbar */
.reader-header {
  height: var(--reader-header-h);
  background-color: var(--reader-surface);
  border-bottom: 1px solid var(--reader-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 100;
  box-shadow: 0 2px 6px rgba(0,0,0,0.04);
}

.reader-header-left,
.reader-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.reader-book-title {
  font-size: 1.05rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 45vw;
}

.reader-tool-btn {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  color: var(--reader-text);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.9rem;
  transition: all 0.2s ease;
}

.reader-tool-btn:hover {
  background-color: rgba(0,0,0,0.06);
}

[data-theme="dark"] .reader-tool-btn:hover {
  background-color: rgba(255,255,255,0.08);
}

/* Main Viewport */
.reader-main {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#viewer {
  width: 100%;
  height: 100%;
  max-width: 1360px;
  margin: 0 auto;
  position: relative;
  background-color: transparent;
  transition: transform 0.18s ease;
}

/* Page Navigation Buttons */
.reader-nav-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 72px;
  background: rgba(0, 0, 0, 0.05);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--reader-text);
  z-index: 50;
  opacity: 0.35;
  transition: all 0.2s ease;
}

.reader-nav-arrow:hover {
  opacity: 0.9;
  background: rgba(0, 0, 0, 0.12);
}

[data-theme="dark"] .reader-nav-arrow {
  background: rgba(255, 255, 255, 0.08);
}
[data-theme="dark"] .reader-nav-arrow:hover {
  background: rgba(255, 255, 255, 0.18);
}

.reader-nav-prev {
  left: 12px;
}

.reader-nav-next {
  right: 12px;
}

/* Watermark Overlay (Anti-Piracy Leak Tracking - Subtle & Non-intrusive) */
.reader-watermark-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 40;
  overflow: hidden;
  opacity: 0.035;
  display: flex;
  flex-wrap: wrap;
  align-content: space-evenly;
  justify-content: space-evenly;
  transform: rotate(-18deg);
}

.reader-watermark-item {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: 1.5px;
  color: #000000;
  padding: 80px 60px;
  white-space: nowrap;
  user-select: none;
}

[data-theme="dark"] .reader-watermark-item {
  color: #ffffff;
  opacity: 0.8;
}

/* Bottom Progress Bar */
.reader-footer {
  height: var(--reader-footer-h);
  background-color: var(--reader-surface);
  border-top: 1px solid var(--reader-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  font-size: 0.85rem;
  z-index: 50;
}

.reader-progress-track {
  flex: 1;
  margin: 0 16px;
  height: 4px;
  background-color: var(--reader-border);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}

.reader-progress-bar {
  width: 0%;
  height: 100%;
  background-color: var(--reader-accent);
  transition: width 0.3s ease;
}

/* TOC Drawer */
.reader-drawer {
  position: fixed;
  top: 0;
  left: -320px;
  width: 320px;
  height: 100vh;
  background: var(--reader-surface);
  box-shadow: 4px 0 16px rgba(0,0,0,0.15);
  z-index: 2000;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
}

.reader-drawer.open {
  left: 0;
}

.reader-drawer-header {
  padding: 16px;
  border-bottom: 1px solid var(--reader-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: bold;
}

.reader-toc-list {
  flex: 1;
  overflow-y: auto;
  list-style: none;
  padding: 8px 0;
  margin: 0;
}

.reader-toc-item {
  padding: 12px 18px;
  cursor: pointer;
  font-size: 0.95rem;
  border-bottom: 1px solid rgba(0,0,0,0.03);
  transition: background 0.15s ease;
}

.reader-toc-item:hover {
  background-color: rgba(0,0,0,0.05);
  color: var(--reader-accent);
}

.reader-drawer-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.4);
  z-index: 1999;
  display: none;
}

.reader-drawer-overlay.active {
  display: block;
}

/* Shelf / Book Chooser Modal */
.reader-shelf-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.6);
  z-index: 3000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.reader-shelf-modal.active {
  display: flex;
}

.reader-shelf-card {
  background: var(--reader-surface);
  color: var(--reader-text);
  border-radius: 12px;
  max-width: 760px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.25);
}

.reader-shelf-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 20px;
  margin-top: 20px;
}

.reader-shelf-item {
  border: 1px solid var(--reader-border);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  position: relative;
}

.reader-shelf-item.is-owned {
  border-color: #a5d6a7;
  background: rgba(46, 125, 50, 0.02);
}

.reader-shelf-item.not-owned {
  border-color: #ffe0b2;
  background: rgba(239, 108, 0, 0.02);
}

.reader-shelf-item:hover {
  transform: translateY(-4px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.1);
  border-color: var(--reader-accent);
}

.reader-shelf-cover {
  width: 140px;
  height: 200px;
  object-fit: cover;
  border-radius: 6px;
  margin-bottom: 12px;
  box-shadow: 0 4px 10px rgba(0,0,0,0.15);
}

/* Loading Spinner */
.reader-loader {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--reader-bg);
  z-index: 80;
}

.reader-spinner {
  width: 44px;
  height: 44px;
  border: 4px solid rgba(0,0,0,0.1);
  border-top-color: var(--reader-accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

/* Print Protection */
@media print {
  body {
    display: none !important;
  }
}

/* Responsive adjustments */
@media only screen and (max-width: 600px) {
  .reader-book-title {
    max-width: 32vw;
    font-size: 0.9rem;
  }
  .reader-nav-arrow {
    width: 36px;
    height: 60px;
  }
}

/* ---- Accessibility: large system font / elderly users (2026-11-20) ----
   Fixed pixel heights clipped text when the OS/browser font scale is large.
   Let bars grow, let buttons wrap, and let gate cards scroll. */
:root {
  --reader-header-h: auto;
  --reader-footer-h: auto;
}
.reader-header { min-height: 56px; flex-wrap: wrap; row-gap: 4px; padding-top: 6px; padding-bottom: 6px; }
.reader-header-left, .reader-header-right { flex-wrap: wrap; min-width: 0; }
.reader-footer { min-height: 44px; padding-top: 6px; padding-bottom: 6px; gap: 8px; }
.reader-tool-btn { min-height: 44px; min-width: 44px; justify-content: center; }
.reader-book-title { flex: 1 1 auto; min-width: 0; }

body.ce-reader-standalone .btn,
body.ce-reader-standalone .btn-large,
body.ce-reader-standalone .btn-small {
  height: auto;
  min-height: 48px;
  line-height: 1.35;
  padding: 10px 20px;
  white-space: normal;
  text-overflow: clip;
  overflow: visible;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}
body.ce-reader-standalone .btn i.left,
body.ce-reader-standalone .btn-large i.left,
body.ce-reader-standalone .btn-small i.left { float: none; margin: 0; height: auto; line-height: 1; }

#viewer .ce-gate {
  box-sizing: border-box;
  max-height: calc(100% - 24px);
  overflow-y: auto;
  margin-left: 12px;
  margin-right: 12px;
}
@media only screen and (max-width: 600px) {
  #viewer .ce-gate { margin-top: 12px !important; padding: 24px 16px !important; }
  #viewer .ce-gate h4 { font-size: 1.5rem; }
}


/* Phones at normal font: single-row header. The truncated book title ("คู่มือศึกษาพระคัมภี...") is dropped;
   the shelf button / footer already tell the reader where they are. Large system fonts still wrap (rules above). */
@media only screen and (max-width: 600px) {
  .reader-header { padding-left: 8px; padding-right: 8px; }
  .reader-header-left, .reader-header-right { gap: 2px; }
  .reader-book-title { display: none; }
  .reader-pill-long { display: none; }
  #sample-badge-pill { margin-left: 2px !important; padding: 3px 8px !important; }
  /* Sample mode has the extra pill; drop the "100%" readout so everything still fits on one row */
  .reader-header:has(#sample-badge-pill[style*="inline-flex"]) #font-size-label { display: none; }
}
