:root {
  --bg: #14161a;
  --bg-elevated: #1d2026;
  --text: #f2f3f5;
  --text-dim: #9aa0a8;
  --accent: #29d17f;
  --border: #2a2d34;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Apple SD Gothic Neo", "Malgun Gothic", "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ---------- 공통 상단바 ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(14px + env(safe-area-inset-top)) 16px 14px;
  background: rgba(20, 22, 26, 0.92);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}

.topbar h1 {
  font-size: 18px;
  margin: 0;
}

.topbar .back {
  font-size: 20px;
  padding: 4px 8px;
  border-radius: 8px;
  color: var(--text-dim);
}
.topbar .back:hover {
  background: var(--bg-elevated);
  color: var(--text);
}

.scan-status-text {
  margin-left: auto;
  flex-shrink: 0;
  font-size: 11px;
  color: var(--text-dim);
  white-space: nowrap;
}

.rescan-btn {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}
.rescan-btn:hover {
  background: rgba(255, 255, 255, 0.16);
}
.rescan-btn:disabled {
  cursor: default;
  opacity: 0.6;
}
.rescan-btn.spinning {
  animation: rescan-spin 0.8s linear infinite;
}
@keyframes rescan-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* ---------- 검색/정렬 툴바 (index.html) ---------- */

.toolbar {
  display: flex;
  gap: 8px;
  padding: 12px 16px 0;
  max-width: 1100px;
  margin: 0 auto;
}

.search-input,
.sort-select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 14px;
}

.search-input {
  flex: 1;
  min-width: 0;
}

.search-input::placeholder {
  color: var(--text-dim);
}

.sort-select {
  flex-shrink: 0;
}

/* ---------- 상태 필터 탭 (index.html) ---------- */

.filter-tabs {
  display: flex;
  gap: 6px;
  padding: 10px 16px 0;
  max-width: 1100px;
  margin: 0 auto;
  overflow-x: auto;
}

.filter-tab {
  flex-shrink: 0;
  padding: 7px 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}

.filter-tab:hover {
  border-color: var(--accent);
}

.filter-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a1a12;
  font-weight: 600;
}

.filter-tab-divider {
  flex-shrink: 0;
  width: 1px;
  margin: 4px 4px;
  background: var(--border);
}

.platform-filter-tab {
  font-size: 12px;
  padding: 6px 12px;
  color: var(--text-dim);
  background: transparent;
}
.platform-filter-tab.active {
  background: rgba(41, 209, 127, 0.15);
  border-color: var(--accent);
  color: var(--accent);
  font-weight: 600;
}

/* ---------- 읽음/안읽음 처리 패널 (index.html) ---------- */

.read-action-panel {
  max-width: 1100px;
  margin: 10px auto 0;
  padding: 0 16px;
}

.read-action-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 10px 10px 0 0;
  padding: 10px 14px;
  font-size: 14px;
  font-weight: 600;
}

.read-action-close {
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
  line-height: 1;
}
.read-action-close:hover {
  color: var(--text);
}

#readActionBody {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: 0 0 10px 10px;
  padding: 12px 14px;
}

.read-action-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.read-action-grid button,
.read-action-picker-buttons button {
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
}
.read-action-grid button:hover,
.read-action-picker-buttons button:hover {
  border-color: var(--accent);
}

.read-action-picker {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.read-action-picker-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
}

.read-action-picker-row {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.picker-series-title {
  font-size: 12px;
  color: var(--text-dim);
}

.picker-loading {
  color: var(--text-dim);
  font-size: 13px;
  padding: 8px 0;
}

.read-action-picker select {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.read-action-picker-buttons {
  display: flex;
  gap: 8px;
}
.read-action-picker-buttons button {
  flex: 1;
}
.read-action-picker-buttons button.ghost {
  background: transparent;
  color: var(--text-dim);
}

/* ---------- 설정 패널: 라이브러리 관리 / 백업 (index.html, 사이드바 형태) ---------- */

.settings-panel-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
}

.settings-section {
  padding: 4px 0 14px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 14px;
}
.settings-section:last-child {
  border-bottom: none;
  margin-bottom: 0;
  padding-bottom: 0;
}

.settings-section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 8px;
}

.settings-hint {
  font-size: 12px;
  color: var(--text-dim);
  margin: 6px 0;
}

.scope-toggle-buttons {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}
.scope-btn {
  flex: 1;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
}
.scope-btn:hover {
  border-color: var(--accent);
}
.scope-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #0a1a12;
  font-weight: 600;
}

.lib-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 30vh;
  overflow-y: auto;
}

.lib-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
}

.lib-name {
  font-size: 13px;
  word-break: break-all;
}

.lib-action-btn {
  flex-shrink: 0;
  padding: 5px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  font-size: 12px;
  cursor: pointer;
}
.lib-action-btn:hover {
  border-color: var(--accent);
  color: var(--text);
}
.lib-action-btn.add {
  border-color: var(--accent);
  color: var(--accent);
}

.mark-all-btn {
  flex: 1;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  display: inline-block;
}
.mark-all-btn:hover {
  border-color: var(--accent);
}
.mark-all-btn.ghost {
  background: transparent;
  color: var(--text-dim);
}

/* ---------- 시리즈 그리드 (index.html) ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 18px 14px;
  padding: 18px;
  max-width: 1100px;
  margin: 0 auto;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  min-width: 0; /* 그리드 아이템이 내부 이미지의 원본 크기에 맞춰 늘어나는 것 방지 */
}

.card .cover-wrap {
  position: relative;
  width: 100%;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  background: var(--bg-elevated);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.4);
  transition: transform 0.15s ease;
}

.card:hover .cover-wrap {
  transform: translateY(-3px);
}

.card .cover-wrap img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  z-index: 0;
}

.card .platform-tag {
  position: absolute;
  top: 6px;
  left: 6px;
  z-index: 1;
  font-size: 10px;
  padding: 2px 6px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.6);
  color: var(--text);
  letter-spacing: 0.02em;
}

.card .unread-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 1;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--accent);
  color: #0a1a12;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

.card.selected .cover-wrap {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.card .select-toggle {
  position: absolute;
  bottom: 6px;
  right: 6px;
  z-index: 1;
  width: 24px;
  height: 24px;
  border-radius: 999px;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  cursor: pointer;
}
.card .select-toggle:hover {
  background: rgba(0, 0, 0, 0.8);
}
.card.selected .select-toggle {
  background: var(--accent);
  color: #0a1a12;
}

.card .chapter-list-toggle {
  position: absolute;
  bottom: 6px;
  left: 6px;
  z-index: 1;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: none;
  background: rgba(0, 0, 0, 0.55);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
}
.card .chapter-list-toggle:hover {
  background: rgba(0, 0, 0, 0.8);
}

.card .title {
  font-size: 13px;
  line-height: 1.3;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.card .chapter-count {
  font-size: 12px;
  color: var(--text-dim);
}

.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-dim);
}

/* ---------- 리더 (reader.html) ---------- */

.reader-body {
  background: #000;
}

.reader-topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
  background: linear-gradient(rgba(0,0,0,0.85), rgba(0,0,0,0.55) 70%, rgba(0,0,0,0));
  transition: opacity 0.2s ease;
}

.reader-topbar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.reader-topbar #chapterTitle {
  flex: 1;
  font-size: 14px;
  color: var(--text-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.reader-topbar.hidden {
  opacity: 0;
  pointer-events: none;
}

.reader-zoom-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 480px;
  margin: 0 auto;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0.55) 30%, rgba(0,0,0,0.85));
  transition: opacity 0.2s ease;
}

.reader-zoom-bar.hidden {
  opacity: 0;
  pointer-events: none;
}

.reader-zoom-icon {
  flex-shrink: 0;
  color: var(--text-dim);
  font-size: 14px;
  width: 16px;
  text-align: center;
  user-select: none;
}

.reader-zoom-slider {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.2);
  outline: none;
  touch-action: pan-x; /* 모바일에서 이 슬라이더를 끌 때 세로 스크롤 제스처로 오인되지 않게 */
}
.reader-zoom-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  cursor: pointer;
}
.reader-zoom-slider::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  cursor: pointer;
}

.reader-zoom-value {
  flex-shrink: 0;
  width: 38px;
  text-align: right;
  font-size: 12px;
  color: var(--text-dim);
}

.sidebar-toggle {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  font-size: 16px;
  cursor: pointer;
}
.sidebar-toggle:hover {
  background: rgba(255, 255, 255, 0.16);
}

.reader-control {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  border: none;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
}
.reader-control:hover {
  background: rgba(255, 255, 255, 0.16);
}

.reader-fullscreen .reader-topbar {
  /* 브라우저 전체 화면이 지원되지 않는 환경에서도 리더 자체가
     화면 전체를 사용하는 상태로 자동 복원되도록 함 */
  position: fixed;
}

.reader-fullscreen .pages img {
  /* 전체 화면에서도 원본보다 크게 확대하지 않는다.
     화면보다 큰 이미지만 뷰포트 폭에 맞춰 축소한다. */
  width: auto;
  max-width: 100vw;
  height: auto;
}

.reader-fullscreen .pages .page-placeholder {
  max-width: 100vw;
}

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.pages.positioning {
  visibility: hidden;
}

.positioning-overlay {
  position: fixed;
  inset: 0;
  z-index: 15;
  background: #000;
  color: var(--text-dim);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pages img {
  width: var(--reader-image-width, 100%);
  max-width: var(--reader-image-width, 720px);
  display: block;
  background: #111;
}

.pages .page-placeholder {
  width: var(--reader-image-width, 100%);
  max-width: var(--reader-image-width, 720px);
  aspect-ratio: 3 / 4;
  background: #111;
}

.next-chapter {
  max-width: 720px;
  margin: 0 auto;
  padding: 40px 20px 80px;
  text-align: center;
}

.next-chapter .next-card {
  display: inline-block;
  padding: 16px 28px;
  border-radius: 12px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  cursor: pointer;
}

.next-chapter .next-card:hover {
  border-color: var(--accent);
}

.next-chapter .eyebrow {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 4px;
}

.next-chapter .next-title {
  font-size: 16px;
  color: var(--accent);
}

.overlap-reveal-wrap {
  /* 레이아웃 흐름에서 공간을 차지하지 않게(높이 0) 해서 이미지 사이에 틈이 안 생기게 함.
     버튼은 이 지점 위에 절대위치로 살짝 겹쳐서 떠 있음 */
  position: relative;
  height: 0;
  width: 100%;
  max-width: 720px;
}

.overlap-reveal-btn {
  position: absolute;
  right: 10px;
  bottom: 0;
  transform: translateY(-50%);
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 1.5px solid #ffb35c;
  background: rgba(10, 11, 13, 0.75); /* 웹툰 배경이 흰색이든 검은색이든 항상 대비되도록 자체 배경 */
  color: #ffb35c;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  opacity: 0.75;
  z-index: 5;
  transition: opacity 0.15s ease, transform 0.15s ease;
}
.overlap-reveal-btn:hover {
  opacity: 1;
  transform: translateY(-50%) scale(1.1);
}
.overlap-reveal-btn:disabled {
  display: none;
}

/* ---------- 사이드 회차 패널 (reader.html) ---------- */

.sidebar {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(300px, 82vw);
  background: var(--bg-elevated);
  border-left: 1px solid var(--border);
  z-index: 40;
  display: flex;
  flex-direction: column;
  transform: translateX(100%);
  transition: transform 0.22s ease;
}

.sidebar.open {
  transform: translateX(0);
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + env(safe-area-inset-top)) 16px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}

.sidebar-close {
  border: none;
  background: none;
  color: var(--text-dim);
  font-size: 20px;
  cursor: pointer;
  line-height: 1;
}
.sidebar-close:hover {
  color: var(--text);
}

.series-info-panel {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  max-height: 40vh;
  overflow-y: auto;
}
.series-info-row {
  margin-bottom: 4px;
}
.series-info-row b {
  color: var(--text);
  font-weight: 600;
  margin-right: 6px;
}
.series-info-summary {
  margin-top: 8px;
  line-height: 1.5;
  color: var(--text-dim);
}
.series-info-link {
  display: inline-block;
  margin-top: 10px;
  color: var(--accent);
  font-size: 12px;
}

.sidebar-list {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0;
}

.sidebar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  font-size: 14px;
  color: var(--text-dim);
  cursor: pointer;
  border-left: 3px solid transparent;
}

.sidebar-row:hover {
  background: rgba(255, 255, 255, 0.04);
}

.sidebar-row.active {
  color: var(--accent);
  border-left-color: var(--accent);
  background: rgba(41, 209, 127, 0.08);
  font-weight: 600;
}

.sidebar-row-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-row-status {
  flex-shrink: 0;
  font-size: 11px;
  font-weight: 600;
}

.sidebar-row-status.read {
  color: var(--text-dim);
}

.sidebar-row-status.reading {
  color: var(--accent);
}

.sidebar-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

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