:root {
  color-scheme: light dark;
  --paper: #ffffff;
  --ink: #0a0a0a;
  --ink-2: #404040;
  --muted: #6e6e6e;
  --rule: #e8e8e8;
  --line: #d4d4d4;
  --wash: #f5f5f5;
  --ring: rgb(10 10 10 / 0.1);
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: ui-serif, "New York", Georgia, "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #0a0a0a;
    --ink: #f3f3f3;
    --ink-2: #c4c4c4;
    --muted: #949494;
    --rule: #222222;
    --line: #383838;
    --wash: #171717;
    --ring: rgb(243 243 243 / 0.14);
  }
}

* { box-sizing: border-box; }

html {
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1;
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding: clamp(56px, 20vh, 200px) 0 64px;
}

.searched main { padding-top: 40px; }

h1, h2, h3, p, dl, dd, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--line);
  text-underline-offset: 3px;
  transition: text-decoration-color 120ms;
}
a:hover { text-decoration-color: currentColor; }

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: 4px;
}

::selection { background: var(--ink); color: var(--paper); }

code { font: 13px/1.6 var(--mono); }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.muted { color: var(--muted); }

.hint {
  margin-top: 14px;
  padding-left: 2px;
  color: var(--muted);
  font-size: 14px;
}

/* Masthead */

.masthead { margin-bottom: 28px; }

.wordmark {
  font: 400 clamp(48px, 8.5vw, 68px)/1 var(--serif);
  letter-spacing: -0.025em;
}
.wordmark a { text-decoration: none; }

.tagline {
  margin-top: 12px;
  color: var(--muted);
  font-size: 17px;
}

.searched .masthead {
  display: flex;
  align-items: baseline;
  gap: 16px;
  margin-bottom: 20px;
}
.searched .wordmark { font-size: 34px; }
.searched .tagline { margin: 0; font-size: 15px; }

/* Search bar: query, filters and submit share one row */

.search {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  transition: border-color 120ms, box-shadow 120ms;
}
.search:focus-within {
  border-color: var(--ink);
  box-shadow: 0 0 0 4px var(--ring);
}

.query {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding-left: 11px;
  color: var(--muted);
  cursor: text;
}
.icon { flex: none; width: 19px; height: 19px; }

.query input {
  flex: 1;
  min-width: 0;
  height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 17px;
  outline: none;
}
.query input::placeholder { color: var(--muted); opacity: 1; }
.query input::-webkit-search-cancel-button { cursor: pointer; }

.filters { display: flex; align-items: center; }

.filter {
  position: relative;
  display: flex;
  align-items: center;
  color: var(--muted);
}
.filter::before {
  content: "";
  width: 1px;
  height: 22px;
  margin-right: 4px;
  background: var(--rule);
}

.filter-button {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 40px;
  max-width: 12rem;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: none;
  color: inherit;
  font: inherit;
  font-size: 15px;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color 120ms, color 120ms;
}
.filter-button:hover,
.filter-button[aria-expanded="true"] { background: var(--wash); color: var(--ink); }
.filter-button:focus-visible { outline-offset: -2px; }
.filter-label { overflow: hidden; text-overflow: ellipsis; }
.filter.is-set { color: var(--ink); }
.filter.is-set .filter-label { font-weight: 600; }

.menu {
  position: fixed;
  width: min(280px, 100vw - 32px);
  max-height: min(420px, 60vh);
  padding: 6px;
  overflow: hidden;
  flex-direction: column;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: 0 12px 32px rgb(0 0 0 / 0.12), 0 2px 6px rgb(0 0 0 / 0.06);
}
.menu:popover-open { display: flex; }
#format-menu { width: 180px; }

.menu-find {
  flex: none;
  height: 38px;
  margin: 2px 2px 6px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 16px;
}
.menu-find:focus { outline: none; border-color: var(--ink); }
.menu-find::placeholder { color: var(--muted); }

.menu-list { overflow-y: auto; overscroll-behavior: contain; }

.menu-group {
  padding: 10px 10px 4px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.option {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: 7px;
  font-size: 15px;
  cursor: pointer;
}
.option:hover { background: var(--wash); }
.option input {
  width: 16px;
  height: 16px;
  margin: 0;
  accent-color: var(--ink);
  cursor: inherit;
}
.option:has(input:disabled) { color: var(--muted); cursor: not-allowed; }
.option:has(input:disabled):hover { background: none; }
.option:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: -2px; }
.option input:focus-visible { outline: none; }
.option[hidden], .menu-group[hidden], .menu-empty[hidden] { display: none; }

.menu-empty { padding: 10px; color: var(--muted); font-size: 14px; }

.menu-foot {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 6px;
  padding: 8px 6px 2px 10px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 13px;
}
.menu-clear {
  padding: 4px 8px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.menu-clear:hover { background: var(--wash); }

.chevron { flex: none; width: 12px; height: 12px; }

.search [type=submit] {
  height: 44px;
  margin-left: 6px;
  padding: 0 20px;
  border: 0;
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 120ms;
}
.search [type=submit]:hover { opacity: 0.86; }
.search [type=submit]:active { opacity: 0.72; }

/* Results */

.results { margin-top: 36px; }

.results-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--ink);
}
.results-head h2,
.status h2 {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}
.results-head p { color: var(--muted); font-size: 14px; }

.notice {
  padding: 28px 0;
  color: var(--ink-2);
}

.edition {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 16px;
  align-items: baseline;
  padding: 22px 0;
  border-bottom: 1px solid var(--rule);
}
.edition .meta,
.edition .locations { grid-column: 1 / -1; }

.edition h3 {
  min-width: 0;
  font-size: 18px;
  font-weight: 600;
  line-height: 1.35;
  letter-spacing: -0.005em;
  overflow-wrap: anywhere;
}
.edition h3 code { font-size: 15px; font-weight: 500; }

.external {
  grid-row: 1;
  grid-column: 2;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  text-decoration: none;
}
.external:hover { color: var(--ink); }

.meta {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 8px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 14.5px;
}
.meta .dot { color: var(--line); }

.locations { margin-top: 14px; display: grid; gap: 10px; }

.torrent {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 2px 10px;
  font-size: 14.5px;
  font-weight: 500;
  overflow-wrap: anywhere;
}
.torrent .muted { font-size: 13px; font-weight: 400; }

.path {
  margin-top: 4px;
  padding: 7px 10px;
  border-radius: 8px;
  background: var(--wash);
  color: var(--ink-2);
  overflow-wrap: anywhere;
}
.path .inside {
  margin: 0 8px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.02em;
}

.pages {
  display: flex;
  justify-content: space-between;
  padding-top: 20px;
  font-size: 15px;
  font-weight: 500;
}
.pages a { text-decoration: none; }
.pages a:hover { text-decoration: underline; }

/* Index status */

.status {
  margin-top: 64px;
  padding-top: 14px;
  border-top: 1px solid var(--ink);
}
.searched .status { margin-top: 80px; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 20px;
  margin-top: 18px;
}
.stats dt { color: var(--muted); font-size: 13px; }
.stats dd {
  margin-top: 2px;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}
.stats small { color: var(--muted); font-size: 15px; font-weight: 500; }

.progress {
  margin-top: 18px;
  display: grid;
  gap: 4px;
  color: var(--ink-2);
  font-size: 14px;
}

details { margin-top: 22px; font-size: 14px; }
summary {
  width: fit-content;
  color: var(--ink-2);
  cursor: pointer;
}
summary:hover { color: var(--ink); }

table {
  width: 100%;
  margin-top: 12px;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
th, td {
  padding: 7px 0;
  border-bottom: 1px solid var(--rule);
  text-align: right;
  font-weight: 400;
}
thead th { color: var(--muted); font-size: 12.5px; }
th:first-child { text-align: left; }
tbody th { font-weight: 500; }

.updated {
  margin-top: 18px;
  color: var(--muted);
  font-size: 13px;
}

footer {
  width: min(100% - 32px, 760px);
  margin: 0 auto;
  padding: 20px 0 32px;
  border-top: 1px solid var(--rule);
  color: var(--muted);
  font-size: 14px;
}
footer a { text-decoration: none; }
footer a:hover { color: var(--ink); text-decoration: underline; }

@media (max-width: 640px) {
  main { padding-top: 48px; }
  .searched main { padding-top: 24px; }

  .search {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas: "query button" "filters filters";
  }
  .query { grid-area: query; }
  .search [type=submit] { grid-area: button; padding: 0 16px; }
  .filters {
    grid-area: filters;
    display: grid;
    grid-template-columns: 1fr 1fr;
    margin-top: 5px;
    padding-top: 5px;
    border-top: 1px solid var(--rule);
  }
  .filter::before { display: none; }
  .filter + .filter::before { display: block; }
  .filter-button { width: 100%; max-width: none; justify-content: space-between; }

  .searched .masthead { display: block; }
  .searched .tagline { display: none; }
  .searched .wordmark { font-size: 30px; }

  .edition { grid-template-columns: minmax(0, 1fr); }
  .external { grid-column: 1; grid-row: 3; margin-top: 4px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); row-gap: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
