/**
 * Client-Side e-Book Reader - Stylesheet
 * Version: 1.0.2
 * 
 * Includes modern glassmorphism aesthetics, responsive canvas viewport,
 * high-contrast visible control toolbar, and Tamil script layout safeguards.
 */

:root {
  --csfr-bg: #0f172a;
  --csfr-card-bg: #1e293b;
  --csfr-surface: #334155;
  --csfr-surface-hover: #475569;
  --csfr-border: rgba(255, 255, 255, 0.22);
  --csfr-border-hover: #818cf8;
  --csfr-primary: #6366f1;
  --csfr-primary-hover: #4f46e5;
  --csfr-primary-glow: rgba(99, 102, 241, 0.4);
  --csfr-accent: #10b981;
  --csfr-text: #ffffff;
  --csfr-text-muted: #cbd5e1;
  --csfr-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.5), 0 10px 10px -5px rgba(0, 0, 0, 0.3);
  --csfr-radius: 16px;
  --csfr-transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  --csfr-font-stack: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Latha", "Vijaya", "Mukta Malar", "Noto Sans Tamil", sans-serif;
}

/* Base Wrapper */
.csfr-wrapper {
  font-family: var(--csfr-font-stack);
  width: 100%;
  max-width: 1200px;
  margin: 2rem auto;
  padding: 1.5rem;
  background: var(--csfr-bg);
  color: var(--csfr-text);
  border-radius: var(--csfr-radius);
  box-shadow: var(--csfr-shadow);
  box-sizing: border-box;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header & Info */
.csfr-header {
  margin-bottom: 1.5rem;
}

.csfr-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.csfr-title {
  font-size: 1.65rem;
  font-weight: 700;
  color: #ffffff;
  margin: 0;
  letter-spacing: -0.025em;
}

.csfr-subtitle {
  font-size: 0.9rem;
  color: var(--csfr-text-muted);
  margin: 0.5rem 0 0 0;
  word-break: break-word;
}

.csfr-btn-change {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.9rem;
  background: #334155;
  color: #ffffff;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--csfr-transition);
}

.csfr-btn-change:hover {
  background: var(--csfr-primary);
  border-color: #818cf8;
}

/* Drag and Drop Zone */
.csfr-upload-zone {
  border: 2px dashed rgba(255, 255, 255, 0.25);
  border-radius: calc(var(--csfr-radius) - 4px);
  padding: 3rem 1.5rem;
  text-align: center;
  background: var(--csfr-card-bg);
  backdrop-filter: blur(12px);
  cursor: pointer;
  transition: var(--csfr-transition);
  position: relative;
  overflow: hidden;
}

.csfr-upload-zone:hover,
.csfr-upload-zone.csfr-dragover {
  border-color: var(--csfr-primary);
  background: rgba(99, 102, 241, 0.12);
  box-shadow: 0 0 25px var(--csfr-primary-glow);
  transform: translateY(-2px);
}

.csfr-upload-icon {
  width: 64px;
  height: 64px;
  margin: 0 auto 1rem auto;
  color: var(--csfr-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(99, 102, 241, 0.2);
  border-radius: 50%;
  transition: var(--csfr-transition);
}

.csfr-upload-zone:hover .csfr-upload-icon {
  transform: scale(1.1);
  background: var(--csfr-primary);
  color: #ffffff;
}

.csfr-upload-icon svg {
  width: 32px;
  height: 32px;
  fill: none;
  stroke: currentColor;
}

.csfr-upload-title {
  font-size: 1.15rem;
  font-weight: 600;
  margin: 0 0 0.5rem 0;
  color: #ffffff;
}

.csfr-upload-hint {
  font-size: 0.85rem;
  color: var(--csfr-text-muted);
  margin: 0 0 1.5rem 0;
}

.csfr-btn-upload {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1.75rem;
  background: var(--csfr-primary);
  color: #ffffff;
  font-weight: 600;
  font-size: 0.95rem;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--csfr-transition);
  box-shadow: 0 4px 12px var(--csfr-primary-glow);
}

.csfr-btn-upload:hover {
  background: var(--csfr-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 16px var(--csfr-primary-glow);
}

.csfr-btn-upload svg {
  fill: none;
  stroke: #ffffff;
}

.csfr-file-input {
  display: none;
}

/* Status / Alert Bar */
.csfr-status-bar {
  display: none;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  margin-top: 1rem;
  border-radius: 8px;
  font-size: 0.875rem;
  background: #1e293b;
  border: 1px solid var(--csfr-border);
}

.csfr-status-bar.csfr-active {
  display: flex;
}

.csfr-status-bar.csfr-info {
  border-left: 4px solid var(--csfr-primary);
}

.csfr-status-bar.csfr-success {
  border-left: 4px solid var(--csfr-accent);
}

.csfr-status-bar.csfr-error {
  border-left: 4px solid #ef4444;
}

.csfr-status-msg {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.csfr-loader {
  width: 16px;
  height: 16px;
  border: 2px solid var(--csfr-text-muted);
  border-top-color: var(--csfr-primary);
  border-radius: 50%;
  animation: csfr-spin 0.8s linear infinite;
}

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

/* Main Reader Viewport */
.csfr-viewport-container {
  display: none;
  position: relative;
  width: 100%;
  height: 75vh;
  min-height: 500px;
  max-height: 900px;
  margin-top: 1.5rem;
  background: #020617;
  border-radius: calc(var(--csfr-radius) - 4px);
  border: 1px solid var(--csfr-border);
  overflow: hidden;
  box-shadow: inset 0 2px 10px rgba(0, 0, 0, 0.7);
}

.csfr-viewport-container.csfr-active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

/* Canvas & Page-Flip Engine Container */
.csfr-stage {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: 1rem;
  box-sizing: border-box;
  position: relative;
}

.csfr-flipbook-element {
  margin: auto;
  box-shadow: 0 15px 35px rgba(0, 0, 0, 0.6);
  transition: transform 0.2s ease-out;
  transform-origin: center center;
}

/* EPUB Container */
.csfr-epub-viewport {
  width: 100%;
  height: 100%;
  position: relative;
  background: #ffffff;
  border-radius: 8px;
  overflow: hidden;
}

/* Tamil & Reflowable Script Layout Safeguard */
.csfr-epub-viewport iframe,
.csfr-flipbook-element page-content,
.csfr-page-canvas {
  font-family: var(--csfr-font-stack) !important;
  font-feature-settings: "kern" 1, "liga" 1;
  text-rendering: optimizeLegibility;
}

.csfr-page-canvas {
  display: block;
  max-width: 100%;
  max-height: 100%;
  background: #ffffff;
  box-shadow: 0 4px 15px rgba(0,0,0,0.3);
}

/* Page item wrapper inside Flipbook */
.csfr-page {
  background-color: #ffffff;
  background-size: cover;
  box-shadow: inset 0 0 15px rgba(0, 0, 0, 0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  overflow: hidden;
}

.csfr-page canvas {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain;
}

/* Bottom Toolbar & High Contrast Controls */
.csfr-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  margin-top: 1rem;
  background: #1e293b;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: calc(var(--csfr-radius) - 6px);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  flex-wrap: wrap;
}

.csfr-toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.65rem;
}

/* Control Icon Buttons - High Contrast Visible Icons */
.csfr-btn-icon {
  width: 44px;
  height: 44px;
  min-width: 44px;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: #334155;
  color: #ffffff !important;
  border: 1px solid rgba(255, 255, 255, 0.3) !important;
  border-radius: 8px;
  cursor: pointer;
  transition: var(--csfr-transition);
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.4);
  padding: 0;
}

.csfr-btn-icon:hover:not(:disabled) {
  background: var(--csfr-primary);
  border-color: #818cf8 !important;
  color: #ffffff !important;
  transform: translateY(-2px);
  box-shadow: 0 4px 14px var(--csfr-primary-glow);
}

.csfr-btn-icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
  background: #1e293b;
  border-color: rgba(255, 255, 255, 0.1) !important;
}

.csfr-btn-icon svg {
  width: 20px !important;
  height: 20px !important;
  display: block !important;
  stroke: #ffffff !important;
  fill: none !important;
  stroke-width: 2.5px !important;
  stroke-linecap: round !important;
  stroke-linejoin: round !important;
}

.csfr-btn-icon svg * {
  stroke: #ffffff !important;
}

/* Page Navigation Display */
.csfr-page-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: #f1f5f9;
}

.csfr-page-input {
  width: 55px;
  padding: 0.4rem 0.5rem;
  background: #0f172a;
  border: 1px solid rgba(255, 255, 255, 0.3);
  border-radius: 6px;
  color: #ffffff;
  font-weight: 700;
  text-align: center;
  font-size: 0.95rem;
  outline: none;
  transition: var(--csfr-transition);
}

.csfr-page-input:focus {
  border-color: var(--csfr-primary);
  box-shadow: 0 0 0 3px var(--csfr-primary-glow);
}

.csfr-zoom-level {
  font-size: 0.9rem;
  font-weight: 700;
  color: #f1f5f9;
  min-width: 50px;
  text-align: center;
}

/* Fullscreen Mode Fixes */
.csfr-wrapper:-webkit-full-screen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  margin: 0 !important;
  border-radius: 0 !important;
  padding: 1.5rem !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: space-between !important;
}

.csfr-wrapper:fullscreen {
  width: 100vw !important;
  height: 100vh !important;
  max-width: none !important;
  margin: 0 !important;
  border-radius: 0 !important;
  padding: 1.5rem !important;
  display: flex !important;
  flex-direction: column !important;
  justify-content: space-between !important;
}

.csfr-wrapper:fullscreen .csfr-viewport-container {
  height: 82vh;
  max-height: none;
}

/* Mobile & Responsive Adjustments */
@media (max-width: 768px) {
  .csfr-wrapper {
    padding: 1rem;
    margin: 1rem 0;
  }

  .csfr-toolbar {
    justify-content: center;
  }

  .csfr-viewport-container {
    height: 60vh;
    min-height: 380px;
  }

  .csfr-upload-zone {
    padding: 2rem 1rem;
  }
}
