:root {
  color-scheme: light dark;
  --bg: #1a1a1a;
  --panel: #242424;
  --input: #1d1d1d;
  --fg: #f2f0ec;
  --muted: #aaa49c;
  --line: #3d3a36;
  --accent: #d8b98c;
  --ink: #241d15;
  --danger: #e8a39a;
  font-family:
    system-ui,
    -apple-system,
    "PingFang SC",
    sans-serif;
  background: var(--bg);
  color: var(--fg);
}
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    color-scheme: light;
    --bg: #fff;
    --panel: #f7f5f2;
    --input: #fff;
    --fg: #1c1916;
    --muted: #746d63;
    --line: #ded9d1;
    --accent: #705638;
    --ink: #fff;
    --danger: #a2392c;
  }
}
:root[data-theme="light"] {
  color-scheme: light;
  --bg: #fff;
  --panel: #f7f5f2;
  --input: #fff;
  --fg: #1c1916;
  --muted: #746d63;
  --line: #ded9d1;
  --accent: #705638;
  --ink: #fff;
  --danger: #a2392c;
}
* {
  box-sizing: border-box;
}
body {
  margin: 0;
}
button,
input,
select,
.button {
  font: inherit;
}
button,
.button {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 14px;
  background: var(--panel);
  color: var(--fg);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
button:hover,
.button:hover {
  border-color: var(--accent);
}
button:disabled {
  opacity: 0.45;
  cursor: default;
}
button.primary,
.primary {
  background: var(--accent);
  color: var(--ink);
  border-color: var(--accent);
}
.ghost {
  background: transparent;
}
.danger {
  color: var(--danger);
}
input,
select {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  background: var(--input);
  color: var(--fg);
  min-width: 0;
  max-width: 100%;
}
input[type="checkbox"] {
  accent-color: var(--accent);
}
label {
  display: flex;
  flex-direction: column;
  gap: 7px;
}
h1,
h2,
p {
  margin-top: 0;
}
h1 {
  font-size: 20px;
  margin: 0;
}
h2 {
  font-size: 22px;
}
p {
  line-height: 1.65;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--line);
}
#username {
  margin-left: auto;
  color: var(--muted);
  font-size: 13px;
}
main {
  max-width: 1120px;
  margin: auto;
  padding: 24px;
}
.tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}
.tabs button {
  background: transparent;
}
.tabs .on {
  background: var(--panel);
  border-color: var(--accent);
  color: var(--accent);
}
.intro {
  margin: 30px 0 24px;
}
.intro p,
.muted {
  color: var(--muted);
  font-size: 14px;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 20px;
  margin: 16px 0;
}
.row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.row > input:first-child {
  flex: 1;
  min-width: 180px;
}
.secondary {
  margin: 12px 0;
}
.secondary select {
  flex: 1;
  max-width: 75%;
}
#page-range input {
  width: 100px;
}
#page-range label {
  font-size: 13px;
}
#scan-form > label {
  margin-bottom: 8px;
}
#image-tools > label {
  margin: 16px 0;
}
.results-tools {
  margin: 24px 0 16px;
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 18px;
}
.card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: var(--panel);
}
.card img {
  display: block;
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: contain;
  background: var(--input);
}
.card .body {
  padding: 12px;
}
.card h3 {
  font-size: 14px;
  line-height: 1.6;
  margin: 0 0 8px;
  overflow-wrap: anywhere;
}
.card button {
  font-size: 13px;
}
.card .check {
  position: absolute;
  top: 8px;
  left: 8px;
  background: var(--panel);
  padding: 8px;
  border-radius: 8px;
}
.card img[data-view] {
  cursor: zoom-in;
}
.card .error {
  font-size: 12px;
  color: var(--danger);
  padding: 8px;
  overflow-wrap: anywhere;
}
.pager {
  display: flex;
  justify-content: center;
  gap: 18px;
  align-items: center;
  margin: 24px 0;
}
.detail {
  display: grid;
  grid-template-columns: 130px 1fr;
  gap: 20px;
}
.detail img {
  width: 100%;
  border-radius: 8px;
}
.detail p {
  white-space: pre-wrap;
}
.notice {
  border: 1px solid var(--accent);
  background: var(--panel);
  padding: 14px;
  border-radius: 12px;
  overflow-wrap: anywhere;
}
.books {
  margin-top: 20px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.books .row {
  gap: 6px;
}
.books .cover {
  height: 180px;
  aspect-ratio: auto;
}
.books .body {
  padding: 16px;
}
dialog {
  background: var(--bg);
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px;
  width: min(850px, 94vw);
  max-height: 90dvh;
}
dialog::backdrop {
  background: #000a;
}
.dialog-head {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.dialog-head h2 {
  margin: 0;
}
.fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin: 20px 0;
}
.edit-pages {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
  margin: 20px 0;
  max-height: 45vh;
  overflow: auto;
}
.edit-page {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 6px;
}
.edit-page img {
  width: 100%;
  height: 130px;
  object-fit: contain;
  cursor: zoom-in;
}
.edit-page .row {
  gap: 3px;
  justify-content: center;
}
.edit-page button {
  padding: 6px 8px;
  font-size: 12px;
}
#viewer {
  width: min(1100px, 96vw);
}
#viewer-image {
  display: block;
  max-width: 100%;
  max-height: 75vh;
  margin: auto;
  object-fit: contain;
}
#viewer-label {
  font-size: 13px;
}
footer {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}
[hidden] {
  display: none !important;
}
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}
@media (max-width: 600px) {
  main {
    padding: 16px;
  }
  .topbar {
    padding: 12px;
    gap: 10px;
  }
  .topbar .button {
    font-size: 13px;
    padding: 8px;
  }
  #username {
    max-width: 70px;
    overflow: hidden;
  }
  .panel {
    padding: 14px;
  }
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }
  .books {
    grid-template-columns: 1fr;
  }
  .detail {
    grid-template-columns: 90px 1fr;
    gap: 12px;
  }
  .fields {
    grid-template-columns: 1fr;
  }
  .intro {
    margin-top: 24px;
  }
  h2 {
    font-size: 19px;
  }
  dialog {
    padding: 14px;
  }
  .edit-pages {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .row > button {
    flex-shrink: 0;
  }
}

#redirect-list {
  overflow-wrap: anywhere;
  line-height: 1.7;
}

.storage-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin: 20px 0;
}
.storage-stat {
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  padding: 18px;
  min-width: 0;
}
.storage-stat strong {
  display: block;
  font-size: 26px;
  margin: 8px 0;
  overflow-wrap: anywhere;
}
.storage-stat p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
}
.storage-heading {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 26px;
}
.storage-heading h3 {
  margin: 0;
  font-size: 17px;
}
.storage-books {
  margin-top: 16px;
}
.storage-book {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}
.storage-book-info {
  flex: 1;
  min-width: 0;
}
.storage-book-info h3 {
  font-size: 15px;
  margin: 0 0 6px;
  overflow-wrap: anywhere;
}
.storage-book-info p {
  margin: 0;
}
.storage-book-size {
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
@media (max-width: 600px) {
  .storage-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }
  .storage-stat {
    padding: 14px;
  }
  .storage-stat strong {
    font-size: 23px;
  }
  .storage-book {
    flex-wrap: wrap;
    gap: 10px;
  }
  .storage-book .row {
    width: 100%;
  }
}

#source {
  flex: 1;
  min-width: 0;
  width: 100%;
  resize: vertical;
  font:
    13px/1.7 ui-monospace,
    monospace;
  overflow-wrap: anywhere;
}
textarea {
  border: 1px solid var(--line);
  border-radius: 9px;
  padding: 10px 12px;
  background: var(--input);
  color: var(--fg);
}
.url-editor {
  margin: 18px 0;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input);
}
.url-editor-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.url-editor h3 {
  margin: 0;
  font-size: 16px;
}
.url-kind {
  color: var(--accent);
  font-size: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
}
.url-fields {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 16px;
}
.url-fields label {
  min-width: 0;
  font-size: 14px;
}
.url-fields input,
.url-fields select {
  width: 100%;
}
.url-fields small {
  color: var(--muted);
  font:
    12px ui-monospace,
    monospace;
  font-weight: normal;
}
.url-field-hint {
  color: var(--muted);
  font-size: 12px;
}
.url-field-wide {
  grid-column: 1 / -1;
}
.url-fields .changed {
  border-color: var(--accent);
}
.url-editor details {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}
.url-editor details summary {
  cursor: pointer;
}
.url-editor-actions {
  margin-top: 20px;
}
.url-editor-status {
  margin-left: auto;
  color: var(--accent);
  font-size: 12px;
}
.url-preview {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}
.url-preview > span {
  color: var(--muted);
  font-size: 12px;
}
.url-preview code {
  display: block;
  margin-top: 8px;
  overflow-wrap: anywhere;
  font:
    12px/1.8 ui-monospace,
    monospace;
  color: var(--muted);
}
.url-preview mark {
  background: var(--panel);
  color: var(--accent);
  border-radius: 3px;
  padding: 1px 2px;
}
#url-parameter-hint {
  margin: 14px 0;
}
@media (max-width: 600px) {
  .url-editor {
    padding: 14px;
  }
  .url-fields {
    grid-template-columns: minmax(0, 1fr);
  }
  .url-editor-status {
    margin-left: 0;
    width: 100%;
  }
}

html.source-privacy-pending body > :not(#source-lock),
html.source-privacy-locked body > :not(#source-lock) { display: none !important; }
