/* FlipBook Viewer */
:root {
  --bg: #f5f5f5;
  --bg-surface: #ffffff;
  --bg-panel: #fafafa;
  --text: #1a1a1a;
  --text-muted: #666;
  --border: #e0e0e0;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --toolbar-bg: rgba(255,255,255,0.92);
  --thumb-active: #2563eb;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 6px;
  --transition: 150ms ease;
}

html.dark {
  --bg: #111111;
  --bg-surface: #1a1a1a;
  --bg-panel: #151515;
  --text: #e5e5e5;
  --text-muted: #888;
  --border: #2a2a2a;
  --toolbar-bg: rgba(17,17,17,0.92);
  --shadow: 0 1px 3px rgba(0,0,0,0.3);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Toolbar */
#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  height: 48px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  z-index: 100;
  flex-shrink: 0;
}

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

.toolbar-left { flex: 1; min-width: 0; }
.toolbar-center { flex: 0 0 auto; }
.toolbar-right { flex: 1; justify-content: flex-end; }

.title {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: -0.01em;
}

#toolbar button {
  background: none;
  border: 1px solid transparent;
  color: var(--text);
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius);
  font-size: 16px;
  line-height: 1;
  transition: background var(--transition), border-color var(--transition);
  user-select: none;
}

#toolbar button:hover {
  background: var(--bg-surface);
  border-color: var(--border);
}

#toolbar button:active {
  transform: scale(0.96);
}

#page-indicator {
  font-size: 13px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  display: flex;
  align-items: center;
  gap: 4px;
}

#page-input {
  width: 48px;
  text-align: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 4px;
  font-size: 13px;
  background: var(--bg-surface);
  color: var(--text);
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
}

#page-input::-webkit-inner-spin-button,
#page-input::-webkit-outer-spin-button {
  -webkit-appearance: none;
}

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

/* Thumbnail panel */
#thumbnail-panel {
  width: 180px;
  flex-shrink: 0;
  overflow-y: auto;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  transition: margin-left var(--transition);
}

#thumbnail-panel.hidden {
  margin-left: -180px;
  visibility: hidden;
}

#thumbnail-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.thumb-item {
  cursor: pointer;
  border-radius: var(--radius);
  overflow: hidden;
  border: 2px solid transparent;
  transition: border-color var(--transition), box-shadow var(--transition);
  position: relative;
}

.thumb-item:hover {
  border-color: var(--border);
  box-shadow: var(--shadow);
}

.thumb-item.active {
  border-color: var(--thumb-active);
  box-shadow: 0 0 0 1px var(--thumb-active);
}

.thumb-item img {
  width: 100%;
  display: block;
  background: var(--bg-surface);
}

.thumb-label {
  position: absolute;
  bottom: 4px;
  right: 4px;
  background: rgba(0,0,0,0.6);
  color: #fff;
  font-size: 10px;
  padding: 1px 5px;
  border-radius: 3px;
  font-variant-numeric: tabular-nums;
}

/* Viewer */
#viewer {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
}

#page-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  width: 100%;
  padding: 24px;
  position: relative;
}

#page-image {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  box-shadow: var(--shadow-lg);
  border-radius: 2px;
  background: var(--bg-surface);
  transition: opacity 120ms ease;
}

#page-image.loading {
  opacity: 0.4;
}

/* Loading indicator */
#loading-indicator {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

#loading-indicator.hidden { display: none; }

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

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

/* Play controls (video mode) */
#play-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--toolbar-bg);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  width: 100%;
  flex-shrink: 0;
}

#play-controls.hidden { display: none; }

#play-controls button {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
}

#scrubber {
  flex: 1;
  height: 4px;
  -webkit-appearance: none;
  appearance: none;
  background: var(--border);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

#scrubber::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  background: var(--accent);
  border-radius: 50%;
  cursor: pointer;
}

#scrubber::-moz-range-thumb {
  width: 14px;
  height: 14px;
  background: var(--accent);
  border: none;
  border-radius: 50%;
  cursor: pointer;
}

#time-display {
  font-size: 12px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
}

/* Branding footer */
#branding {
  text-align: center;
  padding: 6px;
  font-size: 11px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

#branding a {
  color: var(--text-muted);
  text-decoration: none;
  transition: color var(--transition);
}

#branding a:hover {
  color: var(--accent);
}

/* Jump dialog */
#jump-dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  background: var(--bg-surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

#jump-dialog::backdrop {
  background: rgba(0,0,0,0.3);
}

#jump-dialog label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

#jump-dialog input {
  width: 72px;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
}

#jump-dialog button {
  margin-left: 12px;
  padding: 6px 16px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 13px;
}

/* Responsive */
@media (max-width: 640px) {
  #toolbar { padding: 0 8px; }
  .title { font-size: 12px; }
  #thumbnail-panel { width: 120px; }
  #thumbnail-panel.hidden { margin-left: -120px; }
  #page-container { padding: 12px; }
  #branding { font-size: 10px; }
}

@media (max-width: 480px) {
  .toolbar-left .title { max-width: 100px; }
  #thumbnail-panel { width: 100px; }
  #thumbnail-panel.hidden { margin-left: -100px; }
}

/* Fullscreen */
:fullscreen #toolbar { display: none; }
:fullscreen #branding { display: none; }
:fullscreen #page-container { padding: 0; }
:fullscreen body { background: #000; }
:fullscreen #page-image { max-height: 100vh; border-radius: 0; box-shadow: none; }
