/* =========================================================
   JM-Web 前端样式 · 深蓝主题
   配色：藏青底 + 蓝色主色 + 青色点缀
   ========================================================= */
:root {
  --bg: #070d18;
  --bg-elev: #0c1524;
  --surface: #111d31;
  --surface-2: #16253d;
  --surface-3: #1d3050;
  --border: #1e3050;
  --border-strong: #2b4571;

  --text: #e8f0fb;
  --text-dim: #93a7c4;
  --text-mute: #64799a;

  --accent: #3b82f6;
  --accent-hi: #60a5fa;
  --accent-lo: #2563eb;
  --accent-soft: rgba(59, 130, 246, .14);
  --accent-ring: rgba(59, 130, 246, .32);
  --cyan: #22d3ee;

  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
}

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

body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* ===================== 顶部栏 ===================== */
header {
  position: sticky; top: 0; z-index: 10;
  background: rgba(12, 21, 36, .88);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  padding: 14px 20px;
  display: flex; align-items: center; gap: 20px;
  border-bottom: 1px solid var(--border);
}
header h1 {
  font-size: 20px; font-weight: 800; letter-spacing: .5px;
  background: linear-gradient(120deg, var(--accent-hi), var(--cyan));
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent; color: var(--accent-hi);
}

.search-bar { display: flex; gap: 8px; flex: 1; max-width: 640px; }
.search-bar select,
.search-bar input,
.search-bar button {
  padding: 8px 12px; border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  transition: border-color .15s, box-shadow .15s, background .15s;
}
.search-bar input { flex: 1; }
.search-bar input::placeholder { color: var(--text-mute); }
.search-bar select:focus,
.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  background: var(--surface-2);
}
.search-bar button {
  background: linear-gradient(180deg, var(--accent), var(--accent-lo));
  border: 1px solid var(--accent-lo);
  color: #fff; font-weight: 600; cursor: pointer;
  box-shadow: 0 2px 12px rgba(59, 130, 246, .28);
}
.search-bar button:hover {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  box-shadow: 0 3px 16px rgba(59, 130, 246, .4);
}
.search-bar button:active { transform: translateY(1px); }

/* ===================== 结果网格 ===================== */
main { padding: 20px; max-width: 1200px; margin: 0 auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 14px; }

.card {
  background: var(--surface);
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: transform .18s ease, border-color .18s, box-shadow .18s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .3);
}
.card:hover {
  transform: translateY(-3px);
  border-color: var(--accent);
  box-shadow: 0 10px 28px rgba(0, 0, 0, .5), 0 0 0 1px var(--accent) inset;
}
.card img {
  width: 100%; aspect-ratio: 3/4; object-fit: cover; display: block;
  background: var(--surface-2);
}
.card .card-body { padding: 10px; }
.card .card-title {
  font-size: 13px; line-height: 1.4;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}
.card .card-id { font-size: 12px; color: var(--text-mute); margin-top: 4px; }

/* ===================== 详情弹窗 ===================== */
.modal {
  position: fixed; inset: 0;
  background: rgba(3, 7, 14, .78);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  z-index: 50;
}
.modal.hidden { display: none; }
.modal-box {
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  padding: 24px;
  max-width: 560px; width: 92%; max-height: 85vh;
  overflow-y: auto; position: relative;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .6);
}
#detail-title { font-size: 19px; font-weight: 700; padding-right: 28px; }
.close {
  position: absolute; top: 10px; right: 14px;
  font-size: 22px; line-height: 1;
  background: none; border: none; color: var(--text-mute); cursor: pointer;
  transition: color .15s;
}
.close:hover { color: var(--accent-hi); }

.detail-body { margin: 14px 0; font-size: 14px; line-height: 1.7; color: var(--text-dim); }
.detail-body p { margin-bottom: 6px; }
.detail-body .tags { margin: 10px 0; }
.detail-body .tags span {
  display: inline-block;
  background: var(--accent-soft);
  border: 1px solid rgba(59, 130, 246, .28);
  border-radius: 7px;
  padding: 2px 9px; margin: 2px 5px 2px 0;
  font-size: 12px; color: var(--accent-hi);
}

/* ===================== 详情页操作按钮 ===================== */
.detail-actions { display: flex; gap: 10px; margin-top: 16px; flex-wrap: wrap; }
.read-mode-btn {
  flex: 1 1 0; min-width: 128px;
  padding: 12px 20px; border-radius: 10px;
  font-family: inherit; font-size: 15px; font-weight: 600; line-height: 1.2;
  cursor: pointer;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  transition: background .15s, border-color .15s, transform .1s, box-shadow .15s;
  box-shadow: 0 1px 0 rgba(255, 255, 255, .04) inset;
}
.read-mode-btn:hover {
  background: var(--surface-3);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.read-mode-btn:active { transform: translateY(1px); }
.read-mode-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.read-mode-btn:disabled { opacity: .5; cursor: default; transform: none; }

/* 主操作：边看边载（醒目实心） */
.read-primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-lo));
  border: 1px solid var(--accent-lo);
  color: #fff; font-weight: 800;
  box-shadow: 0 4px 18px rgba(59, 130, 246, .35);
}
.read-primary:hover {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  border-color: var(--accent);
  box-shadow: 0 6px 24px rgba(59, 130, 246, .48);
}
.read-primary:active { box-shadow: 0 1px 8px rgba(59, 130, 246, .3); }

/* ===================== 下载进度条（原先缺样式，补上） ===================== */
.download-bar {
  display: flex; align-items: center; gap: 12px;
  margin-top: 16px; padding: 12px 14px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px;
}
.download-status { font-size: 12.5px; color: var(--text-dim); flex: 1 1 auto; min-width: 0; }
.download-progress {
  flex: 0 0 130px; height: 6px; border-radius: 999px;
  background: var(--surface-3); overflow: hidden;
}
.download-progress > div {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
  border-radius: 999px;
  transition: width .25s ease;
}
.download-progress.done > div { background: linear-gradient(90deg, var(--ok), var(--cyan)); }
.download-link {
  flex: none; font-size: 12.5px; font-weight: 600;
  color: var(--accent-hi); text-decoration: none;
  padding: 5px 12px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface-2);
  transition: .15s;
}
.download-link:hover { border-color: var(--accent); color: #fff; background: var(--accent-soft); }

/* ===================== 翻页 / 空态 / toast ===================== */
.pager { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 22px; }
.pager button {
  padding: 6px 16px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 9px; cursor: pointer;
  font-family: inherit; font-size: 13.5px;
  transition: .15s;
}
.pager button:disabled { opacity: .35; cursor: default; border-color: var(--border); }
.pager button:not(:disabled):hover {
  border-color: var(--accent);
  color: var(--accent-hi);
  background: var(--accent-soft);
}
#page-info { font-size: 13px; color: var(--text-dim); white-space: nowrap; font-variant-numeric: tabular-nums; }

.empty { text-align: center; color: var(--text-mute); padding: 60px 0; font-size: 14px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  padding: 10px 20px; border-radius: 10px;
  font-size: 13px; z-index: 100;
  box-shadow: 0 10px 32px rgba(0, 0, 0, .55);
}
.hidden { display: none !important; }

/* ===================== 阅读器 ===================== */
.reader {
  position: fixed; inset: 0;
  background: #05090f;
  z-index: 60;
  display: flex; flex-direction: column;
}

/* 顶部进度条 */
.reader-progress { position: absolute; top: 0; left: 0; right: 0; height: 3px; background: rgba(147, 167, 196, .12); z-index: 5; }
.reader-progress > i {
  display: block; height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--accent), var(--cyan));
  box-shadow: 0 0 10px rgba(34, 211, 238, .6);
  transition: width .12s linear;
}

.reader-top {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px;
  background: rgba(9, 16, 28, .92);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  padding-top: 12px;
}
.reader-icon-btn {
  flex: none; width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text-dim); font-size: 20px; line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: .15s;
}
.reader-icon-btn:hover { border-color: var(--accent); color: #fff; background: var(--accent-soft); }
.reader-heading { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.reader-title { font-size: 14px; font-weight: 600; color: #f2f7ff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-subtitle { font-size: 11.5px; color: var(--text-mute); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-top select {
  flex: none; max-width: 34vw; padding: 7px 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px;
  font-size: 12.5px; font-family: inherit;
}
.reader-top select:focus { outline: none; border-color: var(--accent); }

.reader-body {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  background: #05090f;
  -webkit-overflow-scrolling: touch;
}
.reader-strip {
  max-width: 860px; margin: 0 auto; padding: 10px 0 24px;
  display: flex; flex-direction: column; align-items: center;
}

/* 图片：用接近 A4 的比例占位，减少加载时滚动跳动 */
.strip-img {
  width: 100%; display: block;
  background: #0b121e;
  aspect-ratio: 1 / 1.41; object-fit: contain;
  opacity: 0; transition: opacity .2s ease;
}
.strip-img.is-loaded { aspect-ratio: auto; opacity: 1; }
.strip-img-error {
  aspect-ratio: auto; min-height: 140px; opacity: 1;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-mute); font-size: 13px;
  background: #0d1727;
  cursor: pointer;
  border: 1px dashed var(--border-strong); border-radius: 8px;
}
.strip-img-error:hover { border-color: var(--accent); color: var(--accent-hi); }

/* 状态条（章节下载中提示） */
.reader-status-bar {
  position: sticky; bottom: 0; text-align: center;
  padding: 8px 14px; margin: 0 auto;
  font-size: 12.5px; color: #c3d3e8;
  background: rgba(17, 29, 49, .94);
  backdrop-filter: blur(10px);
  border: 1px solid var(--border);
  border-radius: 999px; width: fit-content; max-width: 90%;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .5);
}
.reader-status-bar.hidden { display: none; }

.reader-end { text-align: center; color: #46597a; padding: 30px 0 18px; font-size: 13px; }

.reader-bottom {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: rgba(9, 16, 28, .96);
  border-top: 1px solid var(--border);
}
.reader-bottom button {
  flex: none; padding: 8px 16px;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text); border-radius: 9px; cursor: pointer;
  font-size: 13px; font-family: inherit; min-width: 84px;
  transition: .15s;
}
.reader-bottom button:hover:not(:disabled) {
  border-color: var(--accent); color: var(--accent-hi); background: var(--accent-soft);
}
.reader-bottom button:disabled { opacity: .35; cursor: default; border-color: var(--border); }
.reader-page { font-size: 12px; color: var(--text-mute); font-variant-numeric: tabular-nums; }

/* 单章作品：隐藏章节导航与章节选择器，只保留页码 */
.reader.reader-single .reader-subtitle,
.reader.reader-single #reader-chapter-select,
.reader.reader-single #reader-prev,
.reader.reader-single #reader-next,
.reader.reader-single .reader-end { display: none !important; }
.reader.reader-single .reader-bottom { justify-content: center; }

/* 回到顶部悬浮按钮 */
.reader-fab {
  position: absolute; right: 16px; bottom: 74px; width: 40px; height: 40px; border-radius: 50%;
  border: 1px solid var(--border-strong);
  background: rgba(22, 37, 61, .95);
  color: var(--text); font-size: 17px;
  cursor: pointer;
  box-shadow: 0 6px 22px rgba(0, 0, 0, .55);
  z-index: 6; transition: .15s;
}
.reader-fab:hover { border-color: var(--accent); color: var(--accent-hi); }
.reader-fab.hidden { display: none; }

/* ===================== 移动端适配 ===================== */
@media (max-width: 768px) {
  header {
    flex-wrap: wrap; gap: 10px; padding: 10px 12px;
    padding-top: calc(10px + env(safe-area-inset-top));
  }
  header h1 { font-size: 18px; }
  .search-bar { flex: 1 1 100%; max-width: none; flex-wrap: wrap; gap: 8px; }
  .search-bar select { flex: 0 0 auto; min-width: 84px; }
  .search-bar input { flex: 1 1 120px; min-width: 0; }
  .search-bar select, .search-bar input, .search-bar button {
    height: 40px; font-size: 15px;
  }
  .search-bar input, .search-bar select { font-size: 16px; }
  .search-bar button { flex: 0 0 auto; padding: 0 18px; }

  main { padding: 12px; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
  .card .card-body { padding: 8px; }
  .card .card-title { font-size: 13px; }
  .card-id { font-size: 11.5px; }

  .pager { gap: 10px; margin-top: 16px; }
  .pager button { padding: 9px 18px; font-size: 14px; }

  .modal { align-items: flex-end; }
  .modal-box {
    width: 100%; max-width: none; max-height: 90vh; max-height: 90dvh;
    border-radius: 18px 18px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
    border-bottom: none;
  }
  .close { top: 8px; right: 10px; font-size: 26px; padding: 6px 10px; }
  #detail-title { font-size: 17px; padding-right: 34px; }
  .detail-body { font-size: 14px; }
  .detail-body .tags span { font-size: 12px; padding: 3px 9px; }

  .detail-actions { gap: 8px; margin-top: 14px; }
  .read-mode-btn { flex: 1 1 0; min-width: 0; padding: 13px 10px; font-size: 14.5px; margin-right: 0; }
  .download-bar { flex-wrap: wrap; }
  .download-progress { flex: 1 1 100%; }

  .reader-strip { padding: 4px 0 12px; }
  .reader-top {
    gap: 8px; padding: 8px 10px;
    padding-top: calc(8px + env(safe-area-inset-top));
  }
  .reader-icon-btn { width: 38px; height: 38px; font-size: 22px; }
  .reader-title { font-size: 13.5px; }
  .reader-subtitle { font-size: 11px; }
  .reader-top select { max-width: 30vw; font-size: 12.5px; padding: 8px; height: 38px; }
  .reader-status-bar { font-size: 12px; padding: 7px 12px; }
  .reader-bottom { gap: 8px; padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); }
  .reader-bottom button { flex: 1 1 0; min-width: 0; padding: 12px 8px; font-size: 14px; }
  .reader-page { flex: 0 0 auto; min-width: 54px; text-align: center; font-size: 12px; }
  .reader-fab { right: 12px; bottom: calc(70px + env(safe-area-inset-bottom)); width: 42px; height: 42px; font-size: 18px; }

  .login-card { padding: 26px 20px; }
  #login-input { font-size: 16px; padding: 13px 14px; }
  .paste-btn { padding: 0 12px; font-size: 15px; }
  #login-btn { padding: 13px; font-size: 15px; }
}

/* 超小屏（<=380px）进一步压缩 */
@media (max-width: 380px) {
  .grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  header h1 { font-size: 16px; }
  .search-bar select { min-width: 72px; font-size: 14px !important; }
  .reader-top select { max-width: 26vw; }
}

/* 横屏手机：压缩阅读器上下栏高度，多留阅读区 */
@media (max-width: 900px) and (orientation: landscape) {
  .reader-top { padding-top: calc(6px + env(safe-area-inset-top)); padding-bottom: 6px; }
  .reader-bottom { padding-top: 6px; padding-bottom: calc(6px + env(safe-area-inset-bottom)); }
  .reader-title, .reader-subtitle { display: none; }
  .reader-strip { max-width: 100%; }
}

/* 触摸设备：去掉 hover 位移，避免点击后"粘住" */
@media (hover: none) {
  .card:hover { transform: none; border-color: var(--border); box-shadow: 0 1px 2px rgba(0,0,0,.3); }
  .card:active { transform: scale(.985); border-color: var(--accent); }
  .reader-bottom button:hover, .reader-icon-btn:hover { border-color: var(--border); color: var(--text-dim); background: var(--surface); }
}

/* 阅读器沉浸模式（移动端轻点图片切换） */
.reader.reader-immersive .reader-top,
.reader.reader-immersive .reader-bottom { display: none; }
.reader.reader-immersive .reader-progress { opacity: 0; }

/* ===================== 登录门禁 ===================== */
body.login-locked > header,
body.login-locked > main,
body.login-locked > #detail-modal,
body.login-locked > #reader-view { display: none !important; }

#login-view {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  background:
    radial-gradient(900px 460px at 12% -12%, rgba(59, 130, 246, .18), transparent 62%),
    radial-gradient(820px 420px at 104% 8%, rgba(34, 211, 238, .12), transparent 58%),
    radial-gradient(700px 500px at 50% 115%, rgba(37, 99, 235, .10), transparent 60%),
    var(--bg);
  overflow-y: auto;
}
#login-view.hidden { display: none; }

.login-card {
  width: min(380px, 94vw);
  background: rgba(17, 29, 49, .82);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--border-strong);
  border-radius: 18px;
  padding: 30px 28px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, .6), 0 0 0 1px rgba(59, 130, 246, .08) inset;
  margin: auto;
}
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.login-mark {
  width: 34px; height: 34px; border-radius: 10px; flex: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 800; color: #fff; letter-spacing: .5px;
  background: linear-gradient(135deg, var(--accent-hi), var(--cyan));
  box-shadow: 0 4px 16px rgba(59, 130, 246, .45);
}
.login-name { font-size: 14px; font-weight: 700; color: var(--text); }
.login-card h1 { font-size: 19px; font-weight: 800; margin-bottom: 6px; color: var(--text); }
.login-sub { color: var(--text-mute); font-size: 13px; margin-bottom: 22px; }

.login-input-row { display: flex; gap: 8px; align-items: stretch; }
.login-input-row #login-input { flex: 1; min-width: 0; }
#login-input {
  width: 100%; padding: 12px 14px; border-radius: 11px; outline: none;
  background: var(--surface); border: 1px solid var(--border);
  color: var(--text);
  font-size: 16px; letter-spacing: 2px; font-family: inherit;
  transition: .18s;
}
#login-input::placeholder { color: var(--text-mute); letter-spacing: 1px; }
#login-input:focus {
  border-color: var(--accent);
  background: var(--surface-2);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.paste-btn {
  flex: none; padding: 0 16px; border-radius: 11px; cursor: pointer; font-family: inherit;
  font-size: 14px; font-weight: 600; white-space: nowrap;
  background: var(--surface-2); border: 1px solid var(--border-strong);
  color: var(--text-dim);
  transition: background .15s, border-color .15s, color .15s;
}
.paste-btn:hover { border-color: var(--accent); color: var(--accent-hi); background: var(--accent-soft); }
.paste-btn:active { transform: scale(.97); }
.paste-btn:disabled { opacity: .5; cursor: default; }
.paste-btn.ok { border-color: var(--ok); color: var(--ok); }

#login-btn {
  width: 100%; margin-top: 14px; padding: 12px; border: none; border-radius: 11px;
  cursor: pointer; font-size: 15px; font-weight: 700; font-family: inherit;
  color: #fff;
  background: linear-gradient(180deg, var(--accent), var(--accent-lo));
  box-shadow: 0 6px 20px rgba(59, 130, 246, .38);
  transition: .18s;
}
#login-btn:hover {
  background: linear-gradient(180deg, var(--accent-hi), var(--accent));
  box-shadow: 0 8px 26px rgba(59, 130, 246, .5);
}
#login-btn:active { transform: scale(.985); }
#login-btn:disabled { opacity: .55; cursor: default; transform: none; }

.login-msg { margin-top: 12px; font-size: 12.5px; min-height: 18px; color: var(--text-mute); }
.login-msg.err { color: var(--danger); }
