:root {
  color-scheme: light;
  --bg: #f6f7f5;
  --panel: #ffffff;
  --panel-2: #eef2ed;
  --text: #222722;
  --muted: #667064;
  --line: #d7ddd5;
  --accent: #2e6f5b;
  --accent-2: #1f4e41;
  --danger: #9b2f2f;
  --shadow: 0 16px 40px rgba(30, 42, 34, 0.08);
  --reader-font-size: 19px;
  --reader-line-height: 1.85;
  --reader-paragraph-spacing: 0.9em;
  --reader-margin: 22px;
  font-family: Inter, "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, "Microsoft YaHei", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
}

body.theme-light {
  --bg: #f7f8fa;
  --panel: #ffffff;
  --panel-2: #edf1f4;
  --text: #1f2528;
  --muted: #64717a;
  --line: #d7dee3;
}

body.theme-paper {
  --bg: #f5f1e8;
  --panel: #fffdf7;
  --panel-2: #ede6d8;
  --text: #28231d;
  --muted: #71695d;
  --line: #d8cdbc;
}

body.theme-night {
  color-scheme: dark;
  --bg: #121513;
  --panel: #1b201d;
  --panel-2: #252c28;
  --text: #e8ece6;
  --muted: #a9b2a8;
  --line: #333d37;
  --accent: #7bc7a6;
  --accent-2: #b4e1cb;
  --danger: #ff9a9a;
  --shadow: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 6px;
  min-height: 38px;
  padding: 0 12px;
  cursor: pointer;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.danger {
  color: var(--danger);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--text);
  min-height: 40px;
  padding: 8px 10px;
}

input[type="range"] {
  padding: 0;
}

textarea {
  min-height: 96px;
  resize: vertical;
}

a {
  color: var(--accent-2);
}

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 24px;
}

.login h1,
.view h1,
.view h2 {
  margin: 0 0 18px;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  color: var(--muted);
  font-size: 14px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 5;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand strong {
  white-space: nowrap;
}

.brand span {
  color: var(--muted);
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.nav,
.actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.nav {
  justify-content: flex-end;
}

.content {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.book-card,
.panel,
.notice {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.book-card {
  padding: 16px;
  display: grid;
  gap: 12px;
  min-height: 176px;
}

.book-card h3 {
  margin: 0;
  font-size: 18px;
  line-height: 1.35;
}

.meta,
.muted {
  color: var(--muted);
  font-size: 13px;
}

.progress-bar {
  height: 8px;
  border-radius: 99px;
  background: var(--panel-2);
  overflow: hidden;
}

.progress-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
}

.view {
  display: grid;
  gap: 18px;
}

.panel {
  padding: 16px;
}

.admin-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
}

.admin-wide {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  border-bottom: 1px solid var(--line);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}

.actions-cell {
  min-width: 230px;
}

.actions-cell > * {
  margin: 0 8px 8px 0;
}

.reader-layout {
  min-height: calc(100vh - 56px);
  display: grid;
  grid-template-rows: auto auto auto 1fr;
}

.reader-bar {
  position: sticky;
  top: 56px;
  z-index: 4;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 8px 12px;
  display: grid;
  grid-template-columns: auto minmax(140px, 1fr) auto;
  align-items: center;
  gap: 8px;
}

.reader-bar.compact {
  grid-template-columns: auto 1fr auto;
}

.reader-bar select {
  min-width: 0;
}

.reader-settings {
  position: sticky;
  top: 108px;
  z-index: 3;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  padding: 12px 16px;
}

.setting-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
}

.setting-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.setting-grid span {
  color: var(--text);
}

.reader-page {
  min-height: calc(100vh - 112px);
  width: 100%;
}

.reader {
  width: min(840px, 100%);
  margin: 0 auto;
  padding: 28px var(--reader-margin) 60px;
  font-family: Georgia, "Times New Roman", "Noto Serif SC", "Songti SC", serif;
  line-height: var(--reader-line-height);
  font-size: var(--reader-font-size);
  will-change: transform;
}

body[data-reader-font="sans"] .reader {
  font-family: "Noto Sans SC", "Microsoft YaHei", "Segoe UI", sans-serif;
}

body[data-reader-font="kai"] .reader {
  font-family: "KaiTi", "STKaiti", "Noto Serif SC", serif;
}

body[data-reader-font="system"] .reader {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
}

.reader p {
  margin: 0 0 var(--reader-paragraph-spacing);
}

.reader h1,
.reader h2,
.reader h3 {
  line-height: 1.35;
  font-family: Inter, "Segoe UI", system-ui, "Microsoft YaHei", sans-serif;
}

.reader img {
  max-width: 100%;
  height: auto;
}

body.reader-paged {
  overflow: hidden;
}

body.reader-paged .reader-layout {
  height: 100vh;
  min-height: 100vh;
  overflow: hidden;
}

body.reader-paged .reader-page {
  height: calc(100vh - 112px);
  min-height: 260px;
  overflow: hidden;
  cursor: pointer;
  touch-action: manipulation;
}

body.reader-paged .reader {
  padding-bottom: 28px;
}

body.reader-paged .reader-settings:not(.hidden) + .notice + .reader-page {
  height: calc(100vh - 240px);
}

.reader-float {
  display: none;
  position: fixed;
  right: 12px;
  top: 12px;
  z-index: 9;
  min-height: 34px;
  padding: 0 10px;
}

body.reader-chrome-hidden .topbar,
body.reader-chrome-hidden .reader-bar,
body.reader-chrome-hidden .reader-settings,
body.reader-chrome-hidden #conflict.hidden {
  display: none !important;
}

body.reader-chrome-hidden .reader-float {
  display: block;
}

body.reader-chrome-hidden.reader-paged .reader-page {
  height: 100vh;
}

body.android-app.reader-active .topbar {
  display: none;
}

body.android-app.reader-active .reader-bar {
  top: 0;
}

body.android-app.reader-active .reader-settings {
  top: 48px;
}

body.android-app.reader-paged .reader-page {
  height: calc(100vh - 48px);
}

.pdf-frame {
  width: 100%;
  min-height: calc(100vh - 118px);
  border: 0;
  background: #fff;
}

.notice {
  padding: 12px 14px;
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
}

.error {
  color: var(--danger);
  margin-top: 10px;
}

.hidden {
  display: none !important;
}

body.eink {
  --bg: #fff;
  --panel: #fff;
  --panel-2: #eee;
  --text: #000;
  --muted: #333;
  --line: #000;
  --accent: #000;
  --accent-2: #000;
  --shadow: none;
}

body.eink *,
body.eink *::before,
body.eink *::after {
  transition: none !important;
  animation: none !important;
  box-shadow: none !important;
}

body.eink .reader {
  font-family: "Noto Serif SC", "Songti SC", serif;
  font-size: max(20px, var(--reader-font-size));
}

@media (max-width: 760px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
    padding: 10px 12px;
  }

  .nav {
    width: 100%;
    justify-content: flex-start;
  }

  .content {
    padding-top: 16px;
  }

  .admin-grid {
    grid-template-columns: 1fr;
  }

  .reader-bar {
    top: 96px;
    grid-template-columns: 1fr;
  }

  .reader-settings {
    top: 190px;
  }

  .reader {
    padding-top: 20px;
  }

  body.reader-paged .reader-page {
    height: calc(100vh - 190px);
  }

  body.android-app.reader-active .reader-bar {
    grid-template-columns: auto 1fr;
  }

  body.android-app.reader-active .reader-bar .actions {
    grid-column: 1 / -1;
  }

  body.android-app.reader-paged .reader-page,
  body.reader-chrome-hidden.reader-paged .reader-page {
    height: 100vh;
  }
}
