:root {
  color-scheme: light dark;
  --bg: #f4f3ef;
  --surface: #ffffff;
  --surface-2: #ebe9e3;
  --surface-dark: #151719;
  --text: #17191b;
  --muted: #656863;
  --line: #d9d7d0;
  --accent: #b53b2f;
  --accent-strong: #8e261e;
  --accent-soft: #f5ddd8;
  --gold: #a47721;
  --focus: #006fb9;
  --shadow: 0 8px 24px rgba(28, 25, 20, 0.09);
  --radius: 6px;
  --header-height: 72px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101214;
    --surface: #1a1d20;
    --surface-2: #24282b;
    --text: #f3f1eb;
    --muted: #a9aca8;
    --line: #353a3d;
    --accent: #ef7165;
    --accent-strong: #ff9188;
    --accent-soft: #482521;
    --gold: #d8ad55;
    --focus: #58b7ee;
    --shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
  }
}

* { box-sizing: border-box; }
html { background: var(--bg); scroll-behavior: smooth; }
body {
  min-height: 100dvh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", "Microsoft YaHei", system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  letter-spacing: 0;
}
button, input, select { color: inherit; font: inherit; letter-spacing: 0; }
button, select, a { touch-action: manipulation; }
a { color: inherit; text-decoration: none; }
img, video { max-width: 100%; }
button { cursor: pointer; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.sr-only, .skip-link:not(:focus) { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.skip-link { position: fixed; z-index: 1000; top: 8px; left: 8px; padding: 10px 14px; background: var(--surface); border-radius: var(--radius); }

.app-header {
  position: sticky;
  z-index: 30;
  top: 0;
  min-height: var(--header-height);
  padding-top: env(safe-area-inset-top);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(18px);
}
.header-inner { width: min(100% - 32px, 1280px); min-height: var(--header-height); margin: 0 auto; display: flex; align-items: center; gap: 12px; }
.brand { display: inline-flex; flex: 0 0 auto; }
.brand-mark { display: grid; width: 42px; height: 42px; place-items: center; color: #fff; background: var(--accent); border-radius: 4px; font-family: Georgia, "Songti SC", serif; font-size: 22px; font-weight: 700; }
.brand-mark-large { width: 52px; height: 52px; font-size: 26px; }
.header-copy { min-width: 0; }
.header-title { overflow: hidden; font-size: 17px; font-weight: 750; text-overflow: ellipsis; white-space: nowrap; }
.header-subtitle { overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.icon-button { display: inline-grid; width: 48px; height: 48px; flex: 0 0 48px; padding: 0; place-items: center; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); font-size: 22px; line-height: 1; }
.icon-button:hover { border-color: var(--accent); color: var(--accent); }
.icon-button:active, .primary-button:active, .segment:active { background: var(--surface-2); }

.page-shell { width: min(100% - 32px, 1280px); margin: 0 auto; padding: 24px 0 max(64px, env(safe-area-inset-bottom)); }
.library-toolbar { display: grid; grid-template-columns: minmax(260px, 1fr) auto; gap: 12px; align-items: center; margin-bottom: 24px; }
.search-field { min-width: 0; height: 48px; display: flex; align-items: center; gap: 10px; padding: 0 14px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.search-field span { color: var(--muted); font-size: 24px; }
.search-field input { width: 100%; min-width: 0; height: 44px; padding: 0; border: 0; outline: 0; background: transparent; }
.filter-row { display: flex; align-items: center; gap: 8px; }
select { min-height: 48px; max-width: 220px; padding: 0 36px 0 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.segments { min-height: 48px; display: inline-flex; align-items: center; padding: 3px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); }
.segment { min-width: 58px; min-height: 40px; padding: 7px 12px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-size: 14px; }
.segment.active { background: var(--surface-dark); color: #fff; }

.work-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 24px 16px; }
.work-card { min-width: 0; }
.work-link { display: block; }
.work-cover { position: relative; overflow: hidden; width: 100%; aspect-ratio: 3 / 4; border-radius: var(--radius); background: var(--surface-2); box-shadow: var(--shadow); }
.work-cover img { width: 100%; height: 100%; display: block; object-fit: cover; transition: transform 220ms ease; }
.work-link:hover .work-cover img { transform: scale(1.025); }
.cover-placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: var(--muted); font-family: Georgia, "Songti SC", serif; font-size: 48px; }
.kind-badge { position: absolute; top: 8px; left: 8px; padding: 4px 8px; border-radius: 4px; background: rgba(18, 20, 21, 0.82); color: #fff; font-size: 12px; font-weight: 650; }
.progress-line { position: absolute; right: 0; bottom: 0; left: 0; height: 4px; background: linear-gradient(90deg, var(--accent) var(--progress, 0%), transparent var(--progress, 0%)); }
.work-copy { padding: 12px 2px 0; }
.work-copy h2 { margin: 0; overflow-wrap: anywhere; font-size: 15px; line-height: 1.4; }
.work-copy p { margin: 5px 0 0; overflow: hidden; color: var(--muted); font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.work-meta { display: flex; flex-wrap: wrap; gap: 5px 12px; margin-top: 8px; color: var(--muted); font-size: 12px; }
.empty-state { min-height: 260px; place-content: center; gap: 6px; text-align: center; color: var(--muted); }
.empty-state:not([hidden]) { display: grid; }
.empty-state strong { color: var(--text); font-size: 18px; }
.toast { position: fixed; z-index: 100; right: 20px; bottom: max(20px, env(safe-area-inset-bottom)); max-width: min(360px, calc(100% - 32px)); padding: 12px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); }

.detail-shell { padding-top: 32px; }
.work-hero { display: grid; grid-template-columns: minmax(180px, 280px) minmax(0, 1fr); gap: 40px; align-items: end; }
.detail-cover { overflow: hidden; aspect-ratio: 3 / 4; border-radius: var(--radius); background: var(--surface-2); box-shadow: var(--shadow); }
.detail-cover img { width: 100%; height: 100%; display: block; object-fit: cover; }
.detail-copy { padding-bottom: 8px; }
.eyebrow { color: var(--accent); font-size: 13px; font-weight: 750; }
.detail-copy h1 { max-width: 820px; margin: 8px 0 10px; overflow-wrap: anywhere; font-family: Georgia, "Songti SC", serif; font-size: 34px; line-height: 1.25; }
.detail-copy > p { margin: 0; color: var(--muted); }
.detail-copy dl { display: flex; gap: 28px; margin: 28px 0; }
.detail-copy dl div { display: grid; gap: 2px; }
.detail-copy dt { color: var(--muted); font-size: 12px; }
.detail-copy dd { margin: 0; font-size: 18px; font-variant-numeric: tabular-nums; font-weight: 700; }
.primary-button { min-height: 48px; display: inline-flex; align-items: center; justify-content: center; padding: 10px 22px; border: 1px solid var(--accent); border-radius: var(--radius); background: var(--accent); color: #fff; font-weight: 700; }
.primary-button:hover { background: var(--accent-strong); }
.chapter-section { margin-top: 48px; }
.section-heading { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; margin-bottom: 14px; }
.section-heading h2 { margin: 0; font-size: 20px; }
.section-heading span { color: var(--muted); font-size: 13px; }
.chapter-list { border-top: 1px solid var(--line); }
.chapter-row { min-height: 72px; display: grid; grid-template-columns: 46px minmax(0, 1fr) auto 44px; align-items: center; gap: 10px; border-bottom: 1px solid var(--line); }
.chapter-row:hover { background: var(--surface); }
.chapter-index { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; text-align: center; }
.chapter-copy { min-width: 0; display: grid; gap: 3px; }
.chapter-copy strong { overflow-wrap: anywhere; }
.chapter-copy small, .chapter-progress { color: var(--muted); font-size: 12px; }
.chapter-progress { text-align: right; }
.row-arrow { text-align: center; font-size: 20px; }

.login-page { background: var(--surface-dark); color: #fff; }
.login-shell { min-height: 100dvh; display: grid; padding: 24px; place-items: center; }
.login-panel { width: min(100%, 420px); padding: 36px 32px; border: 1px solid #34383b; border-radius: var(--radius); background: #1d2022; box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 32px; font-family: Georgia, "Songti SC", serif; font-size: 24px; font-weight: 700; }
.login-panel h1 { margin: 0 0 8px; font-size: 24px; }
.login-panel > p { margin: 0 0 28px; color: #afb3b5; }
.login-form { display: grid; gap: 10px; }
.login-form label { font-size: 14px; font-weight: 650; }
.password-row { display: grid; grid-template-columns: minmax(0, 1fr) 48px; gap: 8px; }
.password-row input { min-width: 0; min-height: 48px; padding: 10px 12px; border: 1px solid #44494c; border-radius: var(--radius); background: #121416; color: #fff; }
.password-row .icon-button { border-color: #44494c; background: #121416; color: #fff; font-size: 14px; }
.login-form .primary-button { width: 100%; margin-top: 10px; }
.form-error { margin-bottom: 18px; padding: 10px 12px; border-left: 4px solid #ef7165; background: #3d2524; font-size: 14px; }

.reader-page { background: #090a0b; color: #f6f4ef; }
.reader-header { position: fixed; z-index: 50; top: 0; right: 0; left: 0; padding-top: env(safe-area-inset-top); background: rgba(18, 20, 22, 0.96); border-bottom: 1px solid #303437; transition: transform 200ms ease, opacity 160ms ease; }
.reader-title-row { min-height: 64px; display: grid; grid-template-columns: 48px minmax(0, 1fr) 48px; gap: 12px; align-items: center; padding: 8px 16px; }
.reader-title-row .icon-button { border-color: #383d40; background: #1d2022; color: #fff; }
.reader-title-row > div { min-width: 0; display: grid; text-align: center; }
.reader-title-row strong, .reader-title-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reader-title-row span { color: #aeb2b4; font-size: 12px; }
.reader-controls { min-height: 52px; display: flex; align-items: center; justify-content: center; gap: 12px; padding: 0 16px 8px; }
.reader-controls .segments { min-height: 40px; border-color: #353a3d; background: #1d2022; }
.reader-controls .segment { min-width: 54px; min-height: 32px; padding: 4px 10px; color: #b5b9bb; }
.reader-controls .segment.active { background: #f1eee6; color: #141617; }
.page-indicator { min-width: 68px; color: #b5b9bb; font-size: 13px; font-variant-numeric: tabular-nums; text-align: center; }
.reader-main { min-height: 100dvh; padding: calc(124px + env(safe-area-inset-top)) 0 calc(70px + env(safe-area-inset-bottom)); }
.reader-stream { width: min(100%, 1120px); margin: 0 auto; }
.reader-item { margin: 0 auto 6px; text-align: center; }
.reader-item img { width: 100%; height: auto; display: block; margin: 0 auto; background: #111; }
.reader-item img[data-src] { background: #151719; }
.reader-item video { width: min(100%, 1120px); max-height: 84dvh; display: block; margin: 0 auto; background: #000; }
.reader-item figcaption { padding: 6px 12px; color: #8e9395; font-size: 12px; }
.reader-main.fit-height .reader-item img { width: auto; max-width: 100%; max-height: calc(100dvh - 190px); object-fit: contain; }
.reader-main.mode-paged .reader-stream { min-height: calc(100dvh - 194px); display: grid; align-items: center; }
.reader-main.mode-paged .reader-item { display: none; margin-bottom: 0; }
.reader-main.mode-paged .reader-item.active { display: block; }
.reader-main.mode-paged .reader-item img { width: auto; max-width: 100%; max-height: calc(100dvh - 200px); object-fit: contain; }
.reader-footer { position: fixed; z-index: 50; right: 0; bottom: 0; left: 0; min-height: calc(58px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr auto 1fr; align-items: start; padding: 0 16px env(safe-area-inset-bottom); background: rgba(18, 20, 22, 0.96); border-top: 1px solid #303437; transition: transform 200ms ease, opacity 160ms ease; }
.reader-nav, .reader-center { min-height: 58px; display: flex; align-items: center; gap: 9px; padding: 0 10px; border: 0; background: transparent; color: #f2f0ea; }
.reader-nav:last-child { justify-content: flex-end; }
.reader-nav.disabled { color: #5f6467; }
.reader-center { min-width: 76px; justify-content: center; color: #aeb2b4; font-size: 13px; font-variant-numeric: tabular-nums; }
.reader-page.ui-hidden .reader-header { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.reader-page.ui-hidden .reader-footer { transform: translateY(100%); opacity: 0; pointer-events: none; }
.reader-page.ui-hidden .reader-main { padding-top: 0; padding-bottom: 0; }
.package-frame { width: 100%; height: calc(100dvh - 194px); display: block; border: 0; background: #fff; }
.package-reader .reader-controls { display: none; }
.package-reader .reader-main { padding-top: calc(72px + env(safe-area-inset-top)); }
.package-reader .package-frame { height: calc(100dvh - 130px - env(safe-area-inset-top) - env(safe-area-inset-bottom)); }

@media (max-width: 1100px) { .work-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@media (max-width: 820px) {
  .library-toolbar { grid-template-columns: 1fr; }
  .filter-row { display: grid; grid-template-columns: minmax(0, 1fr) auto 48px; }
  select { width: 100%; max-width: none; }
  .work-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .work-hero { grid-template-columns: 200px minmax(0, 1fr); gap: 24px; }
}
@media (max-width: 560px) {
  :root { --header-height: 64px; }
  .header-inner, .page-shell { width: min(100% - 24px, 1280px); }
  .header-subtitle { max-width: 230px; }
  .page-shell { padding-top: 16px; }
  .filter-row { grid-template-columns: 1fr 48px; }
  .filter-row .segments { grid-column: 1 / -1; grid-row: 2; display: grid; grid-template-columns: repeat(3, 1fr); }
  .filter-row .segment { width: 100%; }
  .work-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 20px 10px; }
  .work-copy h2 { font-size: 14px; }
  .work-meta { display: none; }
  .work-hero { grid-template-columns: 112px minmax(0, 1fr); gap: 16px; align-items: start; }
  .detail-copy h1 { margin-top: 4px; font-size: 20px; }
  .detail-copy dl { gap: 16px; margin: 14px 0; }
  .detail-copy dt { font-size: 11px; }
  .detail-copy dd { font-size: 15px; }
  .continue-button { width: 100%; padding-inline: 12px; }
  .chapter-section { margin-top: 32px; }
  .chapter-row { grid-template-columns: 36px minmax(0, 1fr) 30px; }
  .chapter-progress { display: none; }
  .login-shell { padding: 16px; }
  .login-panel { padding: 28px 22px; }
  .reader-title-row { padding-inline: 10px; }
  .reader-controls { justify-content: space-between; gap: 6px; padding-inline: 10px; }
  .reader-controls .segment { min-width: 48px; padding-inline: 7px; }
  .reader-nav span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
