:root {
  --bg: #ffffff;
  --fg: #1a1a1a;
  --muted: #666;
  --accent: #0070c9;
  --green: #1f8f4e;
  --border: #e2e2e2;
  --card: #f7f7f8;
  --font-scale: 1;
}

html[data-theme="dark"] {
  --bg: #16181d;
  --fg: #e6e6e6;
  --muted: #9aa0a6;
  --accent: #4aa3ff;
  --green: #43c26a;
  --border: #2a2d34;
  --card: #1e2127;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  line-height: 1.8;
}

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand {
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
}

.controls button {
  background: var(--card);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  margin-left: 6px;
  cursor: pointer;
  font-size: 14px;
}

.controls button:hover { border-color: var(--accent); }
#read-original { display: none; }
#read-original.show { display: inline-block; }
.controls a.controls-btn.primary {
  text-decoration: none;
  margin-left: 6px;
  vertical-align: middle;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 4px 10px;
  font-size: 14px;
  line-height: 1.3;
}
.controls a.controls-btn.primary:hover { filter: brightness(1.08); }

#app {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px 18px 80px;
}

/* Home + link-input */
.home { text-align: center; padding-top: 6vh; }
.home h1 { font-size: 1.6rem; margin-bottom: 20px; }
.link-row { display: flex; gap: 8px; max-width: 560px; margin: 0 auto; }
.link-input, .quick-input {
  flex: 1;
  min-width: 0;
  padding: 12px 14px;
  font-size: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
}
.link-go {
  flex: none;
  padding: 12px 18px;
  font-size: 16px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.link-go:hover { filter: brightness(1.06); }
/* "试试手气" sits between the cached count and the link input. */
.random-wrap { max-width: 560px; margin: 12px auto 18px; text-align: center; }
.link-go.random {
  padding: 11px 26px;
  border-color: var(--green);
  background: var(--green);
}
.link-go.random:hover { filter: brightness(1.08); }
.link-go.random:disabled { opacity: 0.6; cursor: default; }
.home-donate { margin-top: 14px; font-size: 0.85rem; }
.home-donate a { color: var(--green); }
.link-input:focus, .quick-input:focus { border-color: var(--accent); outline: none; }
.link-input::placeholder, .quick-input::placeholder { color: var(--muted); }
.link-input.error, .quick-input.error { border-color: #888888; }
.link-hint { color: #888888; font-size: 0.85rem; margin-top: 8px; text-align: center; }
.quick-nav { max-width: 560px; margin: 40px auto 0; }
.quick-nav .quick-hint { margin-top: 6px; text-align: left; }
.api-line { margin: 10px 0 4px; color: var(--muted); }

/* Home: expandable API doc */
.usage-title { max-width: 560px; margin: 32px auto 12px; text-align: left; font-size: 1.1rem; }
.api-doc {
  max-width: 560px;
  margin: 36px auto 0;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
}
.usage-doc { margin-top: 10px; }
.usage-doc + .api-doc { margin-top: 10px; }
.api-doc summary {
  cursor: pointer;
  padding: 12px 16px;
  color: var(--muted);
  font-size: 0.95rem;
  user-select: none;
}
.api-doc[open] summary { border-bottom: 1px solid var(--border); }
.api-doc-body {
  padding: 4px 16px 14px;
  font-size: 0.88rem;
  color: var(--muted);
}
.api-doc-body pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  overflow-x: auto;
  line-height: 1.5;
}
.api-doc-body code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.85em;
  color: var(--fg);
}
.api-doc-body a { color: var(--accent); }
.userscript-install { font-weight: 600; }

/* Novel */
.novel-head { margin-bottom: 20px; }
.novel-title { font-size: 1.5rem; margin: 0 0 8px; line-height: 1.4; }
.novel-original-title {
  margin: -2px 0 10px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.4;
}
.novel-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
  margin-bottom: 8px;
}
.novel-meta .meta-left { color: var(--muted); }
.novel-meta .model { color: var(--muted); font-size: 0.8rem; white-space: nowrap; }

.quality-report {
  position: fixed;
  top: var(--quality-report-top, 68px);
  right: 16px;
  z-index: 20;
  transition: top 160ms ease, left 180ms ease, right 180ms ease;
  touch-action: none;
}
.quality-report[data-side="left"] { left: 16px; right: auto; }
.quality-report[data-side="right"] { left: auto; right: 16px; }
.quality-report.collapsed[data-side="left"] { left: -18px; }
.quality-report.collapsed[data-side="right"] { right: -18px; }
.quality-report.dragging {
  left: var(--quality-report-drag-left) !important;
  right: auto !important;
  transition: none;
  cursor: grabbing;
}
.quality-report.dragging button { cursor: grabbing; }
.quality-report button {
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--card);
  color: var(--muted);
  padding: 5px 12px;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
}
.quality-report button:hover { border-color: var(--accent); color: var(--accent); }
.quality-report-fab {
  width: 42px;
  height: 42px;
  padding: 0 !important;
  font-size: 1.35rem !important;
  line-height: 1;
}
.report-overlay {
  position: fixed;
  inset: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.45);
}
.report-modal {
  width: 90%;
  max-width: 340px;
  padding: 24px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--fg);
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
}
.report-message { margin: 0 0 8px; font-size: 1rem; }
.report-warning { margin: 0 0 20px; color: var(--muted); font-size: 0.85rem; line-height: 1.6; }
.report-actions { display: flex; gap: 10px; }
.report-actions button { flex: 1; padding: 9px 0; border: 1px solid var(--border); border-radius: 8px; background: var(--card); color: var(--fg); cursor: pointer; font-size: 1.1rem; }
.report-actions button { touch-action: manipulation; }
.report-actions button:hover { border-color: var(--accent); }
.report-actions .report-confirm { border-color: var(--accent); background: var(--accent); color: #fff; }
.report-actions .report-confirm:hover { filter: brightness(1.08); }
.report-actions button:disabled { opacity: 0.55; cursor: default; }

.reports-page { max-width: 600px; margin: 0 auto; }
.reports-page h1 { text-align: center; font-size: 1.4rem; margin: 0 0 24px; }
.reports-list { border-top: 1px solid var(--border); }
.report-header { display: flex; align-items: center; gap: 14px; padding: 0 4px 7px; color: var(--muted); font-size: 0.85rem; }
.report-header span:first-child { flex: 1; }
.report-header span:last-child { min-width: 3em; text-align: right; }
.report-row { display: flex; align-items: center; gap: 14px; padding: 11px 4px; border-bottom: 1px solid var(--border); }
.report-row a { flex: 1; color: var(--accent); text-decoration: none; }
.report-row > span { min-width: 3em; color: var(--muted); text-align: right; }
.report-delete { flex: none; border: 1px solid #c44; border-radius: 6px; background: transparent; color: #c44; padding: 4px 9px; cursor: pointer; }
.report-delete:disabled { opacity: 0.5; cursor: default; }
.reports-quick-nav { margin-top: 44px; }
.developer-clear { border-color: #c44 !important; background: #c44 !important; color: #fff !important; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.tag {
  font-size: 0.8rem;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 10px;
  text-decoration: none;
}
.caption {
  position: relative;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  color: var(--muted);
}
.caption-body {
  color: var(--muted);
  font-size: 0.92rem;
  white-space: pre-wrap;
  /* Collapse to 8 rendered lines on the user's device; longer text gets a
     gradient fade + floating toggle (measured by JS). */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 8;
  overflow: hidden;
}
.caption.expanded .caption-body { -webkit-line-clamp: none; overflow: visible; }
.caption-gradient {
  position: absolute;
  left: 1px;
  right: 1px;
  bottom: 1px;
  height: 42px;
  background: linear-gradient(to bottom, rgba(0, 0, 0, 0), var(--card));
  pointer-events: none;
}
.caption.expanded .caption-gradient { display: none; }
.caption-toggle {
  position: absolute;
  left: 50%;
  bottom: 8px;
  transform: translateX(-50%);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--accent);
  border-radius: 999px;
  padding: 3px 14px;
  cursor: pointer;
  font-size: 0.85rem;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
}
.caption.expanded .caption-toggle {
  position: static;
  transform: none;
  display: block;
  width: fit-content;
  margin: 10px auto 0;
  box-shadow: none;
}

.content {
  font-size: calc(1.05rem * var(--font-scale));
}
.content p { margin: 0 0 1em; }
.content h2.chapter {
  font-size: 1.2em;
  margin: 1.4em 0 0.8em;
  text-align: center;
}
.content hr.page-break {
  border: none;
  margin: 3em 0;
  height: 16px;
  position: relative;
  overflow: visible;
  background: none;
}
.content hr.page-break::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: 50%;
  height: 2px;
  background: linear-gradient(to right, transparent, var(--accent) 20%, var(--accent) 80%, transparent);
  opacity: .55;
}
.content hr.page-break::after {
  content: "◆";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg);
  padding: 0 .6em;
  font-size: .8em;
  line-height: 1;
  color: var(--accent);
}
.content a.jump {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid var(--accent);
}

.nav-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 40px;
}
.nav-row a, .nav-row span {
  flex: 1;
  text-align: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--fg);
}
.nav-row a:hover { border-color: var(--accent); }

.pixiv-link {
  display: inline-block;
  margin-top: 16px;
  color: var(--accent);
  text-decoration: none;
}

.notice {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  text-align: center;
  color: var(--muted);
}

.status-line { color: var(--muted); text-align: center; padding: 40px 0; }
.spinner::after {
  content: "";
  display: inline-block;
  width: 14px; height: 14px;
  margin-left: 8px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed;
  left: 50%;
  bottom: 30px;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  max-width: 90vw;
  z-index: 100;
}

.footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 20px 16px 28px;
  border-top: 1px solid var(--border);
}
.footer a { color: var(--muted); }
.footer-policy { margin-top: 8px; }
.footer-policy a { color: var(--accent); }
.footer-donate { margin-left: 10px; color: var(--muted); }

.legal {
  max-width: 720px;
  margin: 0 auto;
  padding: 24px 20px 40px;
  font-size: calc(0.95rem * var(--font-scale));
  line-height: 1.9;
}
.legal h1 {
  font-size: 1.6em;
  text-align: center;
  margin: 0.6em 0 0.2em;
}
.legal h2 {
  font-size: 1.15em;
  margin: 1.6em 0 0.6em;
  color: var(--accent);
}
.legal .legal-meta {
  text-align: center;
  color: var(--muted);
  font-size: 0.85em;
  margin: 0 0 1.4em;
}
.legal p { margin: 0.5em 0; }
.legal a { color: var(--accent); }

/* Author work-list (confirm page) */
.user-page { max-width: 760px; margin: 0 auto; }
.user-heading { font-size: 1.5rem; margin: 0 0 30px; line-height: 1.4; text-align: center; }
.user-refreshed {
  color: var(--muted);
  font-size: 0.82rem;
  text-align: center;
  margin: -14px 0 18px;
}
.user-actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin: 0 auto 22px;
  max-width: 340px;
}
.user-btn {
  width: 100%;
  max-width: 320px;
  text-align: center;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--fg);
  font-size: 1.02rem;
  text-decoration: none;
  cursor: pointer;
}
.user-btn:hover { border-color: var(--accent); }
.user-btn.highlight { border: none; background: var(--accent); color: #fff; font-weight: 600; }
.user-btn.highlight:hover { filter: brightness(1.08); }
.age-overlay {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}
.age-modal {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 28px 22px;
  max-width: 320px;
  width: 90%;
  text-align: center;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}
.age-message {
  margin: 0 0 22px;
  font-size: 1rem;
  line-height: 1.6;
}
.age-actions {
  display: flex;
  gap: 12px;
}
/* Both choices are deliberately identical: no leading/CTA styling. */
.age-btn {
  flex: 1;
  padding: 11px 0;
  font-size: 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--fg);
  cursor: pointer;
}
.age-btn:hover { border-color: var(--accent); }
.user-loading { margin: 10px 0; }
.user-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin: 0 0 12px;
  flex-wrap: wrap;
}
.user-toolbar #user-count { color: var(--muted); font-size: 0.9rem; }
.user-sort { display: inline-flex; gap: 6px; }
.user-sort button {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 4px 12px;
  cursor: pointer;
  font-size: 0.85rem;
}
.user-sort button.on { border-color: var(--accent); color: var(--accent); }
.user-list-body { display: flex; flex-direction: column; gap: 10px; }
.user-card {
  display: block;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  text-decoration: none;
  color: var(--fg);
  background: var(--card);
}
.user-card:hover { border-color: var(--accent); }
.user-card-title { font-size: 1.02rem; line-height: 1.4; }
.user-card-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px 12px;
  align-items: center;
}
.user-card-badge {
  color: #1a7f37;
  border: 1px solid #1a7f37;
  border-radius: 999px;
  padding: 1px 8px;
  font-size: 0.75rem;
}
/* SSR / home cached-count stat */
.cached-count {
  margin: 4px auto 26px;
}
.cached-count .cached-num {
  display: block;
  font-size: 2.4rem;
  font-weight: 700;
  line-height: 1.1;
  color: #0096fa;
}
.cached-num.bump { animation: numbump 0.6s ease; }
@keyframes numbump {
  0% { opacity: 0.2; transform: translateY(6px); }
  100% { opacity: 1; transform: none; }
}
.cached-count .cached-label {
  color: var(--muted);
  font-size: 0.9rem;
}
