/* css/style.css - Lambacher Schwanzer Reader v2 Design System */

:root {
  /* Dark Mode (Default) */
  --bg: #09090f;
  --surface-1: #111122;
  --surface-2: #1a1a33;
  --surface-glass: rgba(17, 17, 34, 0.85);
  --border: rgba(255, 255, 255, 0.06);
  --border-hover: rgba(255, 255, 255, 0.12);
  --text-primary: #ededf5;
  --text-secondary: #8888aa;
  --text-tertiary: #555566;
  
  --accent: #f5a623;
  --accent-hover: #ffcc44;
  --accent-glow: rgba(245, 166, 35, 0.2);
  --accent-subtle: rgba(245, 166, 35, 0.08);
  
  --success: #34d399;
  --danger: #ef4444;
  
  --page-shadow: 0 20px 60px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,255,255,0.04);
  
  /* Typography */
  --font-primary: 'Inter', system-ui, -apple-system, sans-serif;
  --font-display: 'Outfit', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  
  /* Geometry */
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-pill: 99px;
  
  --topbar-h: 48px;
  --sidebar-w: 320px;
}

[data-theme="light"] {
  --bg: #f6f5f0;
  --surface-1: #ffffff;
  --surface-2: #f0efe8;
  --surface-glass: rgba(255, 255, 255, 0.85);
  --border: rgba(0, 0, 0, 0.06);
  --border-hover: rgba(0, 0, 0, 0.12);
  --text-primary: #1a1814;
  --text-secondary: #6b6560;
  --text-tertiary: #a39b92;
  
  --accent: #d08800;
  --accent-hover: #f0a500;
  --accent-glow: rgba(208, 136, 0, 0.2);
  --accent-subtle: rgba(208, 136, 0, 0.08);
  
  --page-shadow: 0 20px 60px rgba(0,0,0,0.12), 0 0 0 1px rgba(0,0,0,0.04);
}

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

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden; /* App takes full screen, internal scrolling only */
  font-family: var(--font-primary);
  background-color: var(--bg);
  color: var(--text-primary);
  font-size: clamp(0.75rem, 0.7rem + 0.25vw, 0.875rem);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* Layout */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: relative;
}

/* --- Topbar --- */
#topbar {
  height: var(--topbar-h);
  background: var(--surface-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  position: relative;
  z-index: 100;
  transition: transform 0.3s ease;
}

body.focus-mode #topbar {
  transform: translateY(-100%);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 1.1em;
  color: var(--text-primary);
  text-decoration: none;
}

.brand-icon {
  width: 24px;
  height: 24px;
  background: var(--accent);
  color: #000;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.topbar-center {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-arrows {
  display: flex;
  gap: 4px;
}

.icon-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text-primary);
  border-color: var(--border);
}

.icon-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.icon-btn.active {
  background: var(--accent-subtle);
  color: var(--accent);
  border-color: var(--accent-glow);
}

.page-input-wrapper {
  display: flex;
  align-items: center;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 8px;
  height: 32px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.page-input-wrapper input {
  background: transparent;
  border: none;
  color: var(--text-primary);
  font-family: var(--font-mono);
  width: 40px;
  text-align: right;
  outline: none;
}

.page-input-wrapper span {
  color: var(--text-tertiary);
  margin-left: 4px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-family: var(--font-mono);
  font-size: 0.75em;
  font-weight: 600;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 2px 8px;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.badge:hover {
  color: var(--text-primary);
  border-color: var(--border-hover);
}

.badge.active {
  color: var(--accent);
  border-color: var(--accent-glow);
  background: var(--accent-subtle);
}

.progress-track {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: transparent;
}

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

/* --- Main Layout --- */
#main-layout {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* --- Reader Area --- */
#reader-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 16px;
  position: relative;
  scroll-behavior: smooth;
}

/* Custom Scrollbar */
#reader-area::-webkit-scrollbar,
.sidebar-content::-webkit-scrollbar,
.modal-body::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
#reader-area::-webkit-scrollbar-track,
.sidebar-content::-webkit-scrollbar-track,
.modal-body::-webkit-scrollbar-track {
  background: transparent;
}
#reader-area::-webkit-scrollbar-thumb,
.sidebar-content::-webkit-scrollbar-thumb,
.modal-body::-webkit-scrollbar-thumb {
  background: var(--border-hover);
  border-radius: var(--radius-pill);
}

.page-wrapper {
  position: relative;
  background: #fff; /* Always white so PDF colors render correctly */
  box-shadow: var(--page-shadow);
  border-radius: 4px;
  height: calc(100vh - 120px);
  max-height: 1657px;
  max-width: 100%;
  aspect-ratio: 1243 / 1657; /* Standard page ratio */
  transform-origin: center center;
  transition: transform 0.2s ease, margin 0.2s ease;
}

.page-wrapper.fade-out {
  opacity: 0.5;
}

.page-wrapper.fade-in {
  animation: pageEnter 0.2s ease-out forwards;
}

@keyframes pageEnter {
  from { opacity: 0; }
  to { opacity: 1; }
}

#page-image {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: fill;
  border-radius: 4px;
  pointer-events: none;
}

#drawCanvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  z-index: 10;
  cursor: crosshair;
  touch-action: none;
}

/* Page Interaction Zones */
.page-click-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 20%;
  z-index: 5;
  cursor: pointer;
}
.page-click-zone.left { left: 0; cursor: w-resize; }
.page-click-zone.right { right: 0; cursor: e-resize; }

.page-loading-overlay {
  position: absolute;
  inset: 0;
  background: var(--surface-glass);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 8;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.page-loading-overlay.visible {
  opacity: 1;
}

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

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

/* --- Floating Bottom Bar --- */
#bottom-bar {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  box-shadow: var(--page-shadow);
  z-index: 90;
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#bottom-bar.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 20px);
}

body.focus-mode #bottom-bar {
  opacity: 0;
  pointer-events: none;
}

.bottom-info {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 60px;
}

.bottom-page {
  font-family: var(--font-mono);
  font-size: 0.85em;
  font-weight: 600;
  color: var(--text-primary);
}

.bottom-chapter {
  font-size: 0.7em;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.scrubber-container {
  width: 200px;
  position: relative;
  display: flex;
  align-items: center;
}

.scrubber {
  width: 100%;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

.scrubber::-webkit-slider-runnable-track {
  width: 100%;
  height: 4px;
  background: var(--border-hover);
  border-radius: 2px;
}

.scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  height: 16px;
  width: 16px;
  border-radius: 50%;
  background: var(--accent);
  margin-top: -6px;
  box-shadow: 0 0 0 2px var(--bg);
}

/* --- Sidebar --- */
#sidebar {
  width: var(--sidebar-w);
  background: var(--surface-1);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: width 0.3s ease, transform 0.3s ease;
  flex-shrink: 0;
  z-index: 80;
}

#sidebar.collapsed {
  width: 0;
  border-left-color: transparent;
}

body.focus-mode #sidebar {
  width: 0;
  border-left-color: transparent;
}

.sidebar-header {
  padding: 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  gap: 8px;
}

.sidebar-tab {
  flex: 1;
  background: transparent;
  border: none;
  padding: 8px;
  color: var(--text-secondary);
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.15s ease;
}

.sidebar-tab:hover {
  background: var(--surface-2);
  color: var(--text-primary);
}

.sidebar-tab.active {
  background: var(--surface-2);
  color: var(--accent);
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.sidebar-panel {
  display: none;
}

.sidebar-panel.active {
  display: block;
}

/* Chapter Accordion */
.chapter-item {
  margin-bottom: 8px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.chapter-header {
  padding: 10px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-weight: 600;
  font-size: 0.9em;
  color: var(--text-primary);
  transition: background 0.15s;
}

.chapter-header:hover {
  background: var(--border);
}

.chapter-title {
  display: flex;
  gap: 8px;
}

.chapter-num {
  color: var(--accent);
}

.chapter-pages {
  font-family: var(--font-mono);
  font-size: 0.8em;
  color: var(--text-tertiary);
}

.chapter-body {
  display: none;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 4px 0;
}

.chapter-item.expanded .chapter-body {
  display: block;
}

.section-item {
  padding: 6px 12px 6px 36px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  font-size: 0.85em;
  color: var(--text-secondary);
  transition: all 0.15s;
}

.section-item:hover {
  color: var(--text-primary);
  background: var(--surface-2);
}

.section-item.active {
  color: var(--accent);
  position: relative;
}

.section-item.active::before {
  content: '';
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 6px;
  height: 6px;
  background: var(--accent);
  border-radius: 50%;
}

.section-page {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.lk-badge {
  font-size: 0.7em;
  font-weight: 700;
  background: var(--surface-1);
  border: 1px solid var(--border-hover);
  padding: 1px 4px;
  border-radius: 3px;
  margin-left: 6px;
  color: var(--text-tertiary);
}

/* Bookmarks */
.bookmark-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.bookmark-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.bookmark-item:hover {
  border-color: var(--border-hover);
  background: var(--bg);
}

.bookmark-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bookmark-icon {
  color: var(--accent);
}

.bookmark-del {
  color: var(--text-tertiary);
  cursor: pointer;
  padding: 4px;
}

.bookmark-del:hover {
  color: var(--danger);
}

/* Buttons */
.btn {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-primary);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-family: var(--font-primary);
  font-size: 0.9em;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s ease;
}

.btn:hover {
  background: var(--border);
  border-color: var(--border-hover);
}

.btn-primary {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}

.btn-primary:hover {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #000;
}

.btn-block {
  width: 100%;
}

/* --- Modals --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--page-shadow);
  width: 90%;
  max-width: 500px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  transform: scale(0.95) translateY(10px);
  transition: transform 0.2s ease;
}

.modal-overlay.open .modal {
  transform: scale(1) translateY(0);
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-family: var(--font-display);
  font-size: 1.2em;
  font-weight: 600;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-tertiary);
  cursor: pointer;
  font-size: 1.2em;
}

.modal-close:hover {
  color: var(--text-primary);
}

.modal-body {
  padding: 20px;
  overflow-y: auto;
}

.modal-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

/* Download Modal Specifics */
.dl-option {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dl-option:hover {
  background: var(--surface-2);
}

.dl-option.selected {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.dl-radio {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid var(--border-hover);
  display: flex;
  align-items: center;
  justify-content: center;
}

.dl-option.selected .dl-radio::after {
  content: '';
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
}

.dl-info {
  flex: 1;
}

.dl-title {
  font-weight: 600;
  margin-bottom: 2px;
}

.dl-desc {
  font-size: 0.85em;
  color: var(--text-secondary);
}

.dl-format {
  font-family: var(--font-mono);
  font-size: 0.75em;
  font-weight: 600;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
}

.dl-inputs {
  margin-top: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.dl-inputs input, .dl-inputs select {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  font-family: var(--font-primary);
  outline: none;
}

.dl-inputs input:focus, .dl-inputs select:focus {
  border-color: var(--accent);
}

.dl-res-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 20px;
  margin-bottom: 24px;
}

.dl-res-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px;
  text-align: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.dl-res-card:hover {
  background: var(--surface-2);
}

.dl-res-card.selected {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.dl-res-title {
  font-weight: 600;
  margin-bottom: 4px;
}

.dl-res-dpi {
  font-size: 0.8em;
  color: var(--text-secondary);
}

/* --- Drawing Toolbar --- */
#draw-toolbar {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-glass);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  padding: 6px;
  display: flex;
  gap: 4px;
  box-shadow: var(--page-shadow);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

#draw-toolbar.active {
  opacity: 1;
  pointer-events: all;
  transform: translateX(-50%) translateY(0);
}

#draw-toolbar .icon-btn {
  width: 36px;
  height: 36px;
}

/* Focus exit button */
#focus-exit {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 300;
  opacity: 0;
  pointer-events: none;
  background: var(--surface-glass);
  border: 1px solid var(--border);
}

body.focus-mode #focus-exit {
  opacity: 1;
  pointer-events: all;
}

/* Responsive */
@media (max-width: 1023px) {
  #sidebar {
    position: fixed;
    top: 0;
    right: 0;
    height: 100vh;
    transform: translateX(100%);
    box-shadow: var(--page-shadow);
  }
  
  #sidebar.collapsed {
    transform: translateX(100%);
    width: var(--sidebar-w); /* keep width, just translate out */
  }
  
  #sidebar:not(.collapsed) {
    transform: translateX(0);
  }
}

@media (max-width: 767px) {
  :root {
    --sidebar-w: 100%;
  }
  
  .topbar-center .icon-btn {
    display: none; /* Hide zoom on mobile */
  }
  
  .page-input-wrapper input {
    width: 32px;
  }
  
  #sidebar {
    top: auto;
    bottom: 0;
    height: 60vh;
    border-top: 1px solid var(--border);
    border-left: none;
    transform: translateY(100%);
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  }
  
  #sidebar.collapsed {
    transform: translateY(100%);
  }
  
  #sidebar:not(.collapsed) {
    transform: translateY(0);
  }
  
  #bottom-bar {
    width: calc(100% - 32px);
    justify-content: space-between;
  }
  
  .scrubber-container {
    width: 100px;
  }
}

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

/* Grid View Modals */
.grid-chapter {
  margin-bottom: 32px;
}
.grid-chapter-title {
  font-family: var(--font-display);
  font-size: 1.2em;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  padding-bottom: 8px;
}
.grid-pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(60px, 1fr));
  gap: 12px;
}
.grid-page {
  aspect-ratio: 1 / 1.33;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 0.9em;
  transition: all 0.15s ease;
  position: relative;
  overflow: hidden;
}
.grid-page:hover {
  border-color: var(--accent);
  background: var(--accent-subtle);
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}
.grid-page.current {
  border-color: var(--accent);
  background: var(--accent);
  color: #000;
  font-weight: 700;
}

