/* ============ 纯净漫画阅读器 样式 ============ */
:root {
  --bg: #101216;
  --panel: #171a20;
  --panel-2: #1e2229;
  --border: #2a2f38;
  --text: #e6e8ec;
  --text-dim: #98a1ad;
  --accent: #5aa7f0;
  --accent-weak: rgba(90, 167, 240, 0.14);
  --danger: #e26d6d;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --radius: 10px;
  --topbar-h: 56px;
  --sidebar-w: 300px;
}

html[data-theme="light"] {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #eef0f3;
  --border: #dfe3e9;
  --text: #1d2129;
  --text-dim: #69717d;
  --accent: #2f6fd6;
  --accent-weak: rgba(47, 111, 214, 0.1);
  --shadow: 0 12px 32px rgba(20, 30, 50, 0.12);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Microsoft YaHei", "Noto Sans SC", sans-serif;
  font-size: 15px;
  line-height: 1.55;
  transition: background 0.2s, color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 12px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  z-index: 50;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 16px;
  white-space: nowrap;
  color: var(--text);
}
.brand svg { color: var(--accent); flex: none; }

.url-form {
  flex: 1;
  display: flex;
  gap: 8px;
  min-width: 0;
}

.url-form input {
  flex: 1;
  min-width: 0;
  height: 38px;
  padding: 0 14px;
  font-size: 15px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color 0.15s;
}
.url-form input:focus { border-color: var(--accent); }
.url-form input::placeholder { color: var(--text-dim); }

/* ---------- 历史记录下拉 ---------- */
.url-wrap { position: relative; flex: 1; min-width: 0; }

.history-drop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  max-width: 640px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  z-index: 60;
}
.history-list { max-height: 320px; overflow-y: auto; padding: 6px; }
.history-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.history-item:hover { background: var(--panel-2); }
.history-info { flex: 1; min-width: 0; }
.history-title {
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-url {
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.history-time { flex: none; font-size: 12px; color: var(--text-dim); }
.history-del {
  flex: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 6px;
}
.history-del:hover { color: var(--danger); background: var(--panel-2); }
.history-empty { padding: 18px; text-align: center; color: var(--text-dim); font-size: 13px; }
.history-foot {
  display: flex;
  justify-content: flex-end;
  padding: 6px 10px;
  border-top: 1px solid var(--border);
}
.history-foot button {
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 12.5px;
  cursor: pointer;
  padding: 5px 10px;
  border-radius: 6px;
}
.history-foot button:hover { color: var(--danger); }

/* 历史模态列表 */
.history-modal-list {
  max-height: 60vh;
  overflow-y: auto;
  margin: 0 -4px;
  padding: 0 4px;
}
.history-modal-list .history-item { padding: 10px; }
.history-modal-list .history-item:hover { background: var(--panel-2); }

.top-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

/* ---------- 按钮 ---------- */
.btn {
  height: 38px;
  padding: 0 16px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s, border-color 0.15s, opacity 0.15s;
  background: transparent;
  color: var(--text);
}
.btn.primary {
  background: var(--accent);
  color: #fff;
}
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.ghost {
  border-color: var(--border);
  background: var(--panel-2);
  color: var(--text);
}
.btn.ghost:hover { border-color: var(--accent); color: var(--accent); }
.btn.ghost:disabled { opacity: 0.45; cursor: not-allowed; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--panel-2);
  color: var(--text-dim);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}
.icon-btn:hover { color: var(--accent); border-color: var(--accent); }

html[data-theme="dark"] .icon-sun { display: none; }
html[data-theme="light"] .icon-moon { display: none; }

/* ---------- 布局 ---------- */
.layout {
  display: flex;
  height: 100%;
  padding-top: var(--topbar-h);
}

.sidebar {
  flex: none;
  width: var(--sidebar-w);
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-right: 1px solid var(--border);
  transition: margin-left 0.2s;
  z-index: 40;
}
.sidebar.collapsed { margin-left: calc(var(--sidebar-w) * -1); }

.sidebar-head {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
}
.comic-title {
  flex: 1;
  min-width: 0;
  font-size: 14px;
  font-weight: 700;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-all;
}
.sidebar-close { display: none; }

.chapter-list-wrap {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}
.chapter-list {
  margin: 0;
  padding: 0;
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.chapter-list li button {
  width: 100%;
  text-align: left;
  padding: 9px 12px;
  font-size: 13.5px;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background 0.12s;
}
.chapter-list li button:hover { background: var(--panel-2); }
.chapter-list li button.active {
  background: var(--accent-weak);
  color: var(--accent);
  font-weight: 600;
}
.list-empty {
  padding: 24px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
  line-height: 1.8;
}

/* ---------- 主区域 ---------- */
.main {
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow: hidden;
  position: relative;
}

.empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-dim);
  text-align: center;
  padding: 20px;
}
.empty svg { color: var(--border); }
.empty-main { font-size: 17px; color: var(--text); margin: 0; font-weight: 600; }
.empty-sub { font-size: 13px; margin: 0; }

/* ---------- 阅读器 ---------- */
.reader {
  height: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.reader-toolbar {
  flex: none;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
  flex-wrap: wrap;
}
.reader-meta {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.chapter-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.page-info { font-size: 12px; color: var(--text-dim); }
.toolbar-right { display: flex; gap: 6px; flex: none; }

.images-wrap {
  flex: 1;
  overflow-y: auto;
  outline: none;
  padding: 0;
}

/* 滚动模式：整页无缝长条 */
.images-wrap.scroll .comic-img {
  display: block;
  width: 100%;
  max-width: 860px;
  margin: 0 auto;
}

/* 单页模式：逐页分页 */
.images-wrap.page .page-box {
  max-width: 860px;
  margin: 0 auto;
  padding: 24px 8px;
}
.images-wrap.page .comic-img {
  display: block;
  width: 100%;
  border-radius: 4px;
}

.comic-img.loading {
  min-height: 120px;
  background:
    linear-gradient(90deg, transparent, rgba(128, 138, 150, 0.12), transparent)
    0 0 / 60% 100% no-repeat,
    var(--panel-2);
  animation: shimmer 1.4s infinite linear;
}
@keyframes shimmer {
  from { background-position: -60% 0; }
  to { background-position: 160% 0; }
}

.comic-img.error {
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--danger);
  font-size: 13px;
  background: var(--panel-2);
}

.chapter-nav {
  flex: none;
  display: flex;
  justify-content: center;
  gap: 12px;
  padding: 14px 12px;
  border-top: 1px solid var(--border);
  background: var(--panel);
}

/* ---------- 通用显隐 ---------- */
.hidden { display: none !important; }

/* ---------- 弹窗 ---------- */
.modal {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(8, 10, 14, 0.55);
  padding: 16px;
}
.modal.hidden { display: none; }

.modal-box {
  width: 100%;
  max-width: 480px;
  max-height: 86vh;
  overflow-y: auto;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.modal-head h2 { margin: 0; font-size: 17px; }
.modal-tip {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-dim);
}
.modal form label {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-dim);
}
.modal form input {
  display: block;
  width: 100%;
  margin-top: 5px;
  height: 38px;
  padding: 0 12px;
  font-size: 14px;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
}
.modal form input:focus { border-color: var(--accent); }
.modal-actions { margin-top: 16px; text-align: right; }

.rule-list { margin-top: 18px; border-top: 1px solid var(--border); padding-top: 10px; }
.rule-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
}
.rule-item .rule-host { font-weight: 600; word-break: break-all; }
.rule-item .rule-del {
  flex: none;
  border: none;
  background: transparent;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
  padding: 4px 8px;
  border-radius: 6px;
}
.rule-item .rule-del:hover { background: var(--danger); color: #fff; }
.rule-empty { color: var(--text-dim); font-size: 13px; text-align: center; padding: 12px 0; }

/* ---------- 提示 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  max-width: min(88vw, 520px);
  padding: 10px 18px;
  font-size: 14px;
  border-radius: 10px;
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  z-index: 100;
}
.toast.hidden { display: none; }
.toast.error { border-color: var(--danger); color: var(--danger); }

/* ---------- 响应式 ---------- */
@media (min-width: 720px) {
  .url-form input { max-width: 640px; }
}

@media (max-width: 719px) {
  .topbar { gap: 6px; padding: 0 8px; }
  .brand span { display: none; }
  .url-form input { font-size: 14px; padding: 0 10px; }
  .btn { padding: 0 10px; }
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    bottom: 0;
    left: 0;
    width: 100%;
    box-shadow: var(--shadow);
  }
  .sidebar.collapsed { margin-left: -100%; }
  .sidebar-close { display: inline-flex; }

  /* 阅读器工具栏：第一行 上一话|章节名|下一话，第二行 模式/倒序 右对齐 */
  .reader-toolbar {
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 6px 8px;
    padding: 6px 8px;
  }
  #prevBtn { grid-column: 1; }
  .reader-meta { grid-column: 2; text-align: center; align-self: center; }
  #nextBtn { grid-column: 3; }
  .toolbar-right { grid-column: 1 / -1; justify-content: flex-end; }

  .reader-toolbar .btn { padding: 0 8px; font-size: 13px; }
  .chapter-nav { flex-wrap: wrap; }
  .history-drop { max-height: 60vh; }
  .history-list { max-height: 46vh; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
