/* ── EbookReader Theme System ── */
/* Light mode (default) */
:root {
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e9ecef;
  --bg-card: #ffffff;
  --bg-input: #ffffff;
  --bg-toolbar: #ffffff;
  --bg-reader: #e0e0e0;
  --bg-overlay: rgba(0,0,0,0.4);
  
  --text-primary: #212529;
  --text-secondary: #495057;
  --text-muted: #6c757d;
  --text-inverse: #ffffff;
  
  --border-color: #dee2e6;
  --border-light: #e9ecef;
  
  --accent: #7c3aed;
  --accent-hover: #6d28d9;
  --accent-light: rgba(124,58,237,0.1);
  
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  
  --transition: 0.2s ease;
}

/* Dark mode */
[data-theme="dark"] {
  --bg-primary: #0f0f1a;
  --bg-secondary: #1a1a2e;
  --bg-tertiary: #16213e;
  --bg-card: #1a1a2e;
  --bg-input: #0f0f1a;
  --bg-toolbar: #16213e;
  --bg-reader: #1a1a2e;
  --bg-overlay: rgba(0,0,0,0.6);
  
  --text-primary: #e0e0e0;
  --text-secondary: #b0b0b0;
  --text-muted: #888888;
  --text-inverse: #ffffff;
  
  --border-color: #2a2a4a;
  --border-light: #1e1e3a;
  
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 30px rgba(0,0,0,0.5);
}

/* ── Base Reset ── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg-primary);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.6;
  transition: background var(--transition), color var(--transition);
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

/* ── Theme Toggle Button ── */
.theme-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border-color);
  color: var(--text-primary);
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  transition: all var(--transition);
  flex-shrink: 0;
}
.theme-toggle:hover {
  background: var(--accent-light);
  border-color: var(--accent);
  transform: rotate(15deg);
}
.theme-toggle:active { transform: scale(0.95) rotate(30deg); }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn-primary {
  background: var(--accent);
  color: var(--text-inverse);
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline {
  background: transparent;
  border-color: var(--border-color);
  color: var(--text-primary);
}
.btn-outline:hover { background: var(--bg-tertiary); }
.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover { background: var(--danger-hover); }
.btn-sm { padding: 5px 12px; font-size: 0.8rem; }

/* ── Form Controls ── */
.form-control {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.95rem;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-control:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
.form-label {
  display: block;
  margin-bottom: 6px;
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c757d' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
}

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}
.card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
}
.card-img {
  width: 100%;
  height: 200px;
  object-fit: cover;
  background: var(--bg-tertiary);
}
.card-body { padding: 16px; }
.card-title {
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.card-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

/* ── Navbar ── */
.navbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(10px);
}
.navbar .container {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}
.navbar-brand {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.navbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* ── Container ── */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 20px;
}

/* ── Toolbar (reader) ── */
.toolbar {
  background: var(--bg-toolbar);
  border-bottom: 1px solid var(--border-color);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
  flex-wrap: wrap;
}
.toolbar .title {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 0.95rem;
}
.toolbar .spacer { flex: 1; }

/* ── Responsive Grid ── */
.row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 20px;
}

/* ── Badge ── */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-tertiary);
  color: var(--text-muted);
}
.badge-accent {
  background: var(--accent-light);
  color: var(--accent);
}

/* ── Hero Section ── */
.hero {
  padding: 3rem 20px;
  text-align: center;
}
.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.5rem);
  font-weight: 800;
  margin-bottom: 0.5rem;
}
.hero p {
  color: var(--text-muted);
  font-size: 1.05rem;
}

/* ── Page Flip Reader Styles ── */
.reader-wrapper {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-reader);
  overflow: hidden;
  position: relative;
  transition: background var(--transition);
}

.flip-book {
  box-shadow: var(--shadow-lg);
}

/* Page flip container */
.stf__wrapper {
  /* StPageFlip handles positioning */
}

/* Page content inside flip */
.flip-page {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: white; /* pages are always white like real paper */
  overflow: hidden;
}
.flip-page img,
.flip-page canvas {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

/* EPUB rendered content in flip */
.flip-page-content {
  padding: 20px 24px;
  color: #1a1a1a;
  font-size: 16px;
  line-height: 1.8;
  width: 100%;
  height: 100%;
  overflow-y: auto;
}
.flip-page-content h1,
.flip-page-content h2,
.flip-page-content h3 {
  margin: 12px 0 8px;
  color: #111;
}
.flip-page-content p {
  margin: 8px 0;
}

/* Page number overlay */
.page-indicator {
  position: absolute;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-overlay);
  color: white;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 500;
  pointer-events: none;
  z-index: 10;
  backdrop-filter: blur(4px);
}

/* ── Loading Spinner ── */
.spinner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--text-muted);
  padding: 40px;
  font-size: 1rem;
}
.spinner::before {
  content: '';
  width: 24px;
  height: 24px;
  border: 3px solid var(--border-color);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Mobile Controls ── */
.mobile-controls {
  display: none;
  position: absolute;
  bottom: 80px;
  left: 0;
  right: 0;
  justify-content: space-between;
  padding: 0 16px;
  pointer-events: none;
  z-index: 10;
}
.mobile-controls button {
  pointer-events: all;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--bg-overlay);
  color: white;
  border: none;
  font-size: 1.2rem;
  cursor: pointer;
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
}
.mobile-controls button:active { background: var(--accent); }

/* ── Responsive Breakpoints ── */
@media (max-width: 768px) {
  .toolbar { padding: 6px 12px; gap: 8px; }
  .toolbar .title { font-size: 0.85rem; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .btn { padding: 7px 14px; font-size: 0.82rem; }
  .hero { padding: 2rem 16px; }
  .hero h1 { font-size: 1.6rem; }
  .row { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 12px; }
  .card-img { height: 150px; }
  .mobile-controls { display: flex; }
  
  /* StPageFlip single-page mode on mobile */
  .reader-wrapper {
    padding: 8px;
  }
}

@media (max-width: 480px) {
  .toolbar { gap: 6px; }
  .toolbar .title { font-size: 0.8rem; max-width: 120px; }
  .toolbar .back-link span { display: none; }
  .toolbar .back-link::after { content: '←'; }
  .row { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .card-img { height: 130px; }
  .hero h1 { font-size: 1.4rem; }
}

@media (min-width: 769px) and (max-width: 1024px) {
  .reader-wrapper {
    padding: 16px;
  }
}
