/* ===================================================================
   EPUB Viewer – CSS Design System
   =================================================================== */

/* ── CSS Variables ─────────────────────────────────────────────── */
:root {
  --sidebar-width: 280px;
  --toolbar-height: 56px;
  --progress-height: 28px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --transition: 0.22s cubic-bezier(0.4, 0, 0.2, 1);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);
}

/* ── Dark Theme (default) ───────────────────────────────────────── */
.theme-dark {
  --bg-base: #111318;
  --bg-surface: #1a1d24;
  --bg-elevated: #22262f;
  --bg-hover: #2a2f3a;
  --border-color: rgba(255, 255, 255, 0.07);
  --text-primary: #e8eaf0;
  --text-secondary: #8b90a0;
  --text-muted: #555a6a;
  --accent: #6c8aff;
  --accent-glow: rgba(108, 138, 255, 0.25);
  --reader-bg: #1a1d24;
  --reader-text: #d4d8e8;
  --loader-color: #6c8aff;
}

/* ── Light Theme ────────────────────────────────────────────────── */
.theme-light {
  --bg-base: #f0f2f7;
  --bg-surface: #ffffff;
  --bg-elevated: #f8f9fc;
  --bg-hover: #e8eaf2;
  --border-color: rgba(0, 0, 0, 0.08);
  --text-primary: #1a1d2e;
  --text-secondary: #5a5f72;
  --text-muted: #9098b0;
  --accent: #4c6ef5;
  --accent-glow: rgba(76, 110, 245, 0.15);
  --reader-bg: #ffffff;
  --reader-text: #1a1d2e;
  --loader-color: #4c6ef5;
}

/* ── Sepia Theme ────────────────────────────────────────────────── */
.theme-sepia {
  --bg-base: #2c2416;
  --bg-surface: #f5e6c8;
  --bg-elevated: #ede0c4;
  --bg-hover: #e0d0a8;
  --border-color: rgba(100, 70, 30, 0.15);
  --text-primary: #3b2c1a;
  --text-secondary: #7a5c3a;
  --text-muted: #a08060;
  --accent: #c07030;
  --accent-glow: rgba(192, 112, 48, 0.2);
  --reader-bg: #f5e6c8;
  --reader-text: #3b2c1a;
  --loader-color: #c07030;
  --bg-base: #1e180e;
  --bg-elevated: #f0deb8;
}

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

html,
body {
  height: 100%;
  font-family: 'Inter', 'Noto Serif KR', sans-serif;
  font-size: 14px;
  background: var(--bg-base);
  color: var(--text-primary);
  overflow: hidden;
  transition: background var(--transition), color var(--transition);
}

/* ── Layout Shell ───────────────────────────────────────────────── */
body {
  display: flex;
  height: 100vh;
}

/* ===================================================================
   SIDEBAR
   =================================================================== */
.sidebar {
  position: relative;
  width: var(--sidebar-width);
  min-width: 180px;
  max-width: 480px;
  height: 100%;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: width var(--transition), transform var(--transition), background var(--transition);
  z-index: 10;
}

.sidebar.collapsed {
  width: 0 !important;
  min-width: 0 !important;
  overflow: hidden;
  border-right: none;
}

.sidebar-header {
  flex-shrink: 0;
  border-bottom: 1px solid var(--border-color);
}

.sidebar-tabs {
  display: flex;
  padding: 8px 8px 0;
  gap: 4px;
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  font-family: inherit;
  transition: all var(--transition);
}

.tab-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.tab-btn.active {
  background: var(--bg-elevated);
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

.tab-panel {
  display: none;
  flex: 1;
  overflow: hidden;
  flex-direction: column;
}

.tab-panel.active {
  display: flex;
}

.panel-search {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
}

.panel-search input {
  width: 100%;
  padding: 7px 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 12px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition);
}

.panel-search input:focus {
  border-color: var(--accent);
}

/* TOC */
.toc-nav {
  flex: 1;
  overflow-y: auto;
  padding: 8px 0;
}

.toc-nav::-webkit-scrollbar {
  width: 4px;
}

.toc-nav::-webkit-scrollbar-track {
  background: transparent;
}

.toc-nav::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.toc-item {
  list-style: none;
}

.toc-link {
  display: block;
  padding: 7px 16px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 13px;
  line-height: 1.4;
  cursor: pointer;
  border-radius: 0;
  transition: background var(--transition), color var(--transition);
  border-left: 2px solid transparent;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toc-link:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.toc-link.active {
  background: var(--accent-glow);
  color: var(--accent);
  border-left-color: var(--accent);
}

.toc-item.depth-1 .toc-link {
  padding-left: 28px;
  font-size: 12px;
}

.toc-item.depth-2 .toc-link {
  padding-left: 40px;
  font-size: 11px;
}

/* Bookmarks */
.bookmark-actions {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-color);
}

.btn-add-bookmark {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px;
  background: var(--accent-glow);
  border: 1px dashed var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-add-bookmark:hover {
  background: var(--accent);
  color: #fff;
}

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

.bookmark-list::-webkit-scrollbar {
  width: 4px;
}

.bookmark-list::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 2px;
}

.bookmark-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background var(--transition);
}

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

.bookmark-item-icon {
  color: var(--accent);
  flex-shrink: 0;
}

.bookmark-item-text {
  flex: 1;
  min-width: 0;
}

.bookmark-item-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bookmark-item-page {
  font-size: 11px;
  color: var(--text-muted);
}

.bookmark-delete {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 2px;
  border-radius: 4px;
  opacity: 0;
  transition: all var(--transition);
}

.bookmark-item:hover .bookmark-delete {
  opacity: 1;
}

.bookmark-delete:hover {
  color: #e05555;
  background: rgba(224, 85, 85, 0.1);
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 40px 20px;
  color: var(--text-muted);
  font-size: 12px;
  text-align: center;
}

/* Sidebar Resize Handle */
.sidebar-resize {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  z-index: 20;
}

.sidebar-resize:hover::after {
  content: '';
  position: absolute;
  top: 0;
  left: 2px;
  width: 2px;
  height: 100%;
  background: var(--accent);
  border-radius: 1px;
  opacity: 0.6;
}

/* ===================================================================
   MAIN AREA
   =================================================================== */
.main-area {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  height: 100%;
  background: var(--bg-base);
  transition: background var(--transition);
}

/* ===================================================================
   TOOLBAR
   =================================================================== */
.toolbar {
  height: var(--toolbar-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
  gap: 8px;
  backdrop-filter: blur(12px);
  transition: background var(--transition);
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.toolbar-center {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.tool-btn {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 7px 10px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 13px;
  font-family: inherit;
  font-weight: 500;
  transition: all var(--transition);
  white-space: nowrap;
}

.tool-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-color);
}

.tool-btn:active {
  transform: scale(0.96);
}

.nav-btn {
  padding: 7px 8px;
  border-radius: var(--radius-sm);
}

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

.nav-btn:disabled:active {
  transform: none;
}

.book-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.book-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.chapter-title {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.page-display {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  min-width: 80px;
  justify-content: center;
}

.page-sep {
  color: var(--text-muted);
}

#btn-open-file {
  background: var(--accent-glow);
  color: var(--accent);
  border-color: var(--accent);
}

#btn-open-file:hover {
  background: var(--accent);
  color: #fff;
}

/* ===================================================================
   READER CONTAINER
   =================================================================== */
.reader-container {
  flex: 1;
  position: relative;
  overflow: hidden;
}

/* ── Home Screen ───────────────────────────────────────────────── */
.home-screen {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-base);
  transition: background var(--transition);
}

.home-screen.drag-over .home-content {
  opacity: 0.3;
  pointer-events: none;
}

.home-screen.drag-over .drop-overlay {
  opacity: 1;
  pointer-events: auto;
}

.home-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
  padding: 40px;
  transition: opacity var(--transition);
}

.home-icon {
  width: 120px;
  height: 120px;
  background: var(--bg-elevated);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  border: 1px solid var(--border-color);
  box-shadow: 0 0 40px var(--accent-glow);
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-8px);
  }
}

.home-title {
  font-size: 28px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}

.home-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  max-width: 300px;
}

.btn-open-large {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 28px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-family: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  box-shadow: 0 4px 20px var(--accent-glow);
  margin-top: 8px;
}

.btn-open-large:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px var(--accent-glow);
}

.btn-open-large:active {
  transform: translateY(0);
}

.home-features {
  display: flex;
  gap: 24px;
  margin-top: 8px;
}

.feature-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.feature-item svg {
  color: var(--accent);
  opacity: 0.7;
}

/* Drop Overlay */
.drop-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(108, 138, 255, 0.08);
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  margin: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.theme-light .drop-overlay {
  background: rgba(76, 110, 245, 0.06);
}

.theme-sepia .drop-overlay {
  background: rgba(192, 112, 48, 0.06);
}

.drop-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  color: var(--accent);
  font-size: 18px;
  font-weight: 600;
}

/* ── Viewer Wrap ────────────────────────────────────────────────── */
/* position:absolute + inset:0 so it fills reader-container exactly.
   This ensures clientWidth/clientHeight are accurate before renderTo(). */
.viewer-wrap {
  position: absolute;
  inset: 0;
  background: var(--reader-bg);
  transition: background var(--transition);
  display: flex;
  flex-direction: column;
  /* overflow hidden prevents iframe scroll leak */
  overflow: hidden;
}

.viewer-inner {
  flex: 1;
  min-height: 0;
  /* critical: allow flex child to shrink */
  display: flex;
  align-items: stretch;
  position: relative;
  overflow: hidden;
}

#viewer {
  flex: 1;
  min-width: 0;
  min-height: 0;
  /* critical: gives epub.js a measurable box */
  overflow: hidden;
  /* epub.js injects an iframe here; make sure it fills */
}

/* epub.js iframe must fill its wrapper */
#viewer iframe,
#viewer .epub-container {
  display: block !important;
  width: 100% !important;
  height: 100% !important;
}

/* ── Page click / nav areas ─────────────────────────────────────── */
.page-click-area {
  position: absolute;
  top: 0;
  bottom: 0;
  width: 100px;
  border: none;
  cursor: pointer;
  z-index: 5;
  display: flex;
  align-items: center;
  background: transparent;
  transition: background var(--transition);
}

/* Arrow icon via ::after pseudo */
.page-click-area::after {
  content: '';
  display: block;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-md);
  opacity: 0;
  transform: scale(0.7);
  transition: opacity 0.18s ease, transform 0.18s ease;
  /* SVG chevron as background-image */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236c8aff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='15 18 9 12 15 6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: center;
  background-size: 18px;
  flex-shrink: 0;
}

.page-click-prev {
  left: 0;
  justify-content: flex-start;
  padding-left: 14px;
  background: linear-gradient(to right, rgba(0, 0, 0, 0.05) 0%, transparent 100%);
}

.page-click-next {
  right: 0;
  justify-content: flex-end;
  padding-right: 14px;
  background: linear-gradient(to left, rgba(0, 0, 0, 0.05) 0%, transparent 100%);
}

/* Next arrow points right — flip the chevron */
.page-click-next::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%236c8aff' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='9 18 15 12 9 6'/%3E%3C/svg%3E");
}

/* Show arrow on hover */
.page-click-area:hover::after {
  opacity: 1;
  transform: scale(1);
}

.page-click-area:active::after {
  transform: scale(0.92);
}

/* Dark-mode background is slightly darker gradient */
.theme-dark .page-click-prev {
  background: linear-gradient(to right, rgba(0, 0, 0, 0.18) 0%, transparent 100%);
}

.theme-dark .page-click-next {
  background: linear-gradient(to left, rgba(0, 0, 0, 0.18) 0%, transparent 100%);
}

/* Light theme arrow color */
.theme-light .page-click-prev::after,
.theme-light .page-click-next::after {
  border-color: rgba(0, 0, 0, 0.08);
  background-color: #fff;
}

.theme-light .page-click-prev::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%234c6ef5' stroke-width='2.5'%3E%3Cpolyline points='15 18 9 12 15 6'/%3E%3C/svg%3E");
}

.theme-light .page-click-next::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%234c6ef5' stroke-width='2.5'%3E%3Cpolyline points='9 18 15 12 9 6'/%3E%3C/svg%3E");
}

/* Sepia theme */
.theme-sepia .page-click-prev::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23c07030' stroke-width='2.5'%3E%3Cpolyline points='15 18 9 12 15 6'/%3E%3C/svg%3E");
}

.theme-sepia .page-click-next::after {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='18' height='18' viewBox='0 0 24 24' fill='none' stroke='%23c07030' stroke-width='2.5'%3E%3Cpolyline points='9 18 15 12 9 6'/%3E%3C/svg%3E");
}

/* ── Loading Screen ────────────────────────────────────────────── */
.loading-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  background: var(--bg-base);
  color: var(--text-secondary);
  font-size: 14px;
}

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

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

/* ===================================================================
   PROGRESS BAR
   =================================================================== */
.progress-bar-wrap {
  height: var(--progress-height);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-color);
  flex-shrink: 0;
  transition: background var(--transition);
}

.progress-bar-inner {
  flex: 1;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  width: 0%;
  transition: width 0.4s ease;
}

.progress-label {
  font-size: 11px;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  width: 36px;
  text-align: right;
  flex-shrink: 0;
}

/* ===================================================================
   SETTINGS PANEL
   =================================================================== */
.settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}

.settings-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-panel {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 380px;
  max-width: 90vw;
  box-shadow: var(--shadow-lg);
  transform: translateY(16px) scale(0.97);
  transition: transform var(--transition);
}

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

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

.settings-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.btn-close-settings {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.btn-close-settings:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.settings-section {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
}

.settings-section:last-child {
  border-bottom: none;
}

.settings-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  /* 기존 secondary → primary 로 대비 강화 */
  text-transform: none;
  /* uppercase 제거 → 한글 가독성 개선 */
  letter-spacing: 0;
  margin-bottom: 12px;
}

.settings-label span {
  font-size: 12px;
  font-weight: 500;
  color: var(--accent);
}

/* Theme Buttons */
.theme-buttons {
  display: flex;
  gap: 8px;
}

.theme-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px;
  background: var(--bg-elevated);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.theme-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

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

.theme-preview {
  width: 44px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid rgba(0, 0, 0, 0.1);
}

.dark-preview {
  background: linear-gradient(135deg, #111318 50%, #6c8aff 50%);
}

.light-preview {
  background: linear-gradient(135deg, #f0f2f7 50%, #4c6ef5 50%);
}

.sepia-preview {
  background: linear-gradient(135deg, #f5e6c8 50%, #c07030 50%);
}

/* Sliders */
.slider-wrap {
  display: flex;
  align-items: center;
  gap: 10px;
}

.slider-wrap .big-a {
  font-size: 18px;
}

input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  background: var(--bg-elevated);
  border-radius: 2px;
  outline: none;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
  transition: transform var(--transition);
}

input[type="range"]::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

/* Layout Buttons */
.layout-buttons {
  display: flex;
  gap: 8px;
}

.layout-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  background: var(--bg-elevated);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
}

.layout-btn:hover {
  border-color: var(--accent);
  color: var(--text-primary);
}

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

/* ===================================================================
   SCROLLBAR (Global)
   =================================================================== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-color);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ===================================================================
   EPUB.js iframe overrides (injected via rendition themes)
   =================================================================== */
.epub-container {
  width: 100% !important;
  height: 100% !important;
}

/* ===================================================================
   RESPONSIVE
   =================================================================== */
@media (max-width: 680px) {
  :root {
    --sidebar-width: 240px;
  }

  .book-title,
  .chapter-title {
    max-width: 140px;
  }

  .home-features {
    gap: 16px;
  }

  .page-click-area {
    width: 50px;
  }
}

@media (max-width: 480px) {
  .sidebar {
    position: absolute;
    z-index: 50;
  }

  .sidebar.collapsed {
    transform: translateX(-100%);
    width: var(--sidebar-width) !important;
  }

  .home-features {
    display: none;
  }
}

/* ===================================================================
   FONT SELECTOR
   =================================================================== */
.font-selector-wrap {
  display: flex;
  gap: 8px;
  align-items: stretch;
  flex-wrap: wrap;
  /* 버튼이 길어질 때 진배 */
}

.font-select {
  flex: 1;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color var(--transition);
  /* 드롭다운 화살표 */
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%238b90a0' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 30px;
}

.font-select:focus {
  border-color: var(--accent);
}

.btn-load-fonts {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  padding: 8px 10px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  white-space: normal;
  /* 필요시 줄바꾸올 허용 */
  flex-shrink: 1;
  flex-basis: auto;
  /* 콘텐츠 크기에 맞게 성장 */
  min-width: 0;
  /* 오버플로우 방지 */
  max-width: 120px;
  /* 너무 길어지면 다음 줄로 */
  transition: all var(--transition);
  text-align: center;
}

.btn-load-fonts:hover {
  background: var(--accent-glow);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-load-fonts:disabled {
  opacity: 0.6;
  cursor: default;
}

/* 폰트 미리보기 */
.font-preview {
  margin-top: 10px;
  padding: 10px 14px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 15px;
  line-height: 1.6;
  transition: font-family 0.2s;
  min-height: 44px;
}
/* ========================================================================= */
/* 8. TTS (TEXT-TO-SPEECH) PANEL                                             */
/* ========================================================================= */
.tts-panel {
  position: absolute;
  bottom: 60px;
  right: 20px;
  background-color: var(--bg-color);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 16px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 250px;
  z-index: 900;
  transition: opacity 0.2s, transform 0.2s;
  backdrop-filter: blur(8px);
}
.theme-dark .tts-panel {
  box-shadow: 0 10px 25px rgba(0,0,0,0.5);
}
.tts-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
}
.tts-btn {
  background: transparent;
  border: none;
  color: var(--text-base);
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}
.tts-btn:hover {
  background-color: var(--hover-bg);
  color: var(--primary-color);
}
#btn-tts-play, #btn-tts-pause {
  width: 44px;
  height: 44px;
  background-color: var(--primary-color);
  color: white;
}
#btn-tts-play:hover, #btn-tts-pause:hover {
  background-color: var(--primary-hover);
  transform: scale(1.05);
}
.tts-settings {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-top: 1px solid var(--border-color);
  padding-top: 12px;
}
.tts-select {
  width: 100%;
  padding: 6px 8px;
  border-radius: 6px;
  background-color: var(--bg-element);
  color: var(--text-base);
  border: 1px solid var(--border-color);
  font-size: 0.85rem;
}
.tts-speed-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
}
.tts-speed-wrap input {
  flex: 1;
}

/* TTS Highlight */
.tts-playing-word {
  background-color: rgba(99, 102, 241, 0.3) !important;
  border-radius: 2px;
  transition: background-color 0.1s;
}

/* ===================================================================
   PROFILE SELECTOR MODAL
   =================================================================== */
#profile-modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
  animation: profile-fadein 0.25s ease;
}

#profile-modal-overlay.fade-out {
  animation: profile-fadeout 0.35s ease forwards;
}

@keyframes profile-fadein {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes profile-fadeout {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(1.04); }
}

.profile-modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px 36px 36px;
  width: min(380px, 90vw);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-lg), 0 0 60px var(--accent-glow);
  animation: profile-slidein 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes profile-slidein {
  from { opacity: 0; transform: translateY(24px) scale(0.95); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.profile-modal-icon {
  width: 80px;
  height: 80px;
  background: var(--bg-surface);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  border: 1px solid var(--border-color);
  box-shadow: 0 0 30px var(--accent-glow);
  margin-bottom: 4px;
}

.profile-modal-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.4px;
}

.profile-modal-sub {
  font-size: 13px;
  color: var(--text-secondary);
  text-align: center;
  line-height: 1.6;
  margin-bottom: 8px;
}

.profile-btn-group {
  display: flex;
  gap: 10px;
  width: 100%;
  margin-top: 4px;
}

.profile-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 18px 10px 14px;
  background: var(--bg-surface);
  border: 1.5px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

.profile-btn:hover {
  border-color: var(--accent);
  background: var(--accent-glow);
  transform: translateY(-3px);
  box-shadow: 0 6px 20px var(--accent-glow);
}

.profile-btn.selected {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
  transform: scale(1.05);
}

.profile-btn-emoji {
  font-size: 26px;
  line-height: 1;
}

.profile-btn-label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

/* ===================================================================
   PROFILE INDICATOR (Toolbar)
   =================================================================== */
#profile-indicator {
  display: flex;
  align-items: center;
  padding: 5px 10px;
  background: var(--accent-glow);
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  user-select: none;
  letter-spacing: 0.3px;
}

#profile-indicator:hover {
  background: var(--accent);
  color: #fff;
  transform: scale(1.04);
}
