/* pc — a quiet catalog for a personal media archive. */

:root {
  color-scheme: light dark;

  --bg: #f7f5f1;
  --surface: #fffdfa;
  --surface-alt: #efebe4;
  --text: #1c1b19;
  --text-muted: #6b665e;
  --text-faint: #8a847a;
  --border: #ded8ce;
  --border-strong: #c8c1b5;
  --accent: #98421f;
  --accent-soft: #f1e2d8;
  --danger: #8b2e2e;
  --overlay: rgb(18 17 16 / 0.88);

  --font-display: "Iowan Old Style", "Sitka Text", "Palatino Linotype",
    Palatino, "Book Antiqua", Georgia, serif;
  --font-sans: "Avenir Next", Avenir, "Segoe UI Variable Text", "Segoe UI",
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: "Cascadia Mono", "SFMono-Regular", "JetBrains Mono", Menlo,
    Consolas, monospace;

  --radius: 4px;
  --queue-width: 17.5rem;
  --page-width: 74rem;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131211;
    --surface: #191816;
    --surface-alt: #24221f;
    --text: #e8e4dc;
    --text-muted: #a39c91;
    --text-faint: #7d766c;
    --border: #2c2a26;
    --border-strong: #423e38;
    --accent: #d89a6e;
    --accent-soft: #32241b;
    --danger: #e08c8c;
    --overlay: rgb(5 5 4 / 0.92);
  }
}

* {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding-right: var(--queue-width);
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 var(--font-sans);
  font-feature-settings: "kern" 1, "liga" 1;
  -webkit-font-smoothing: antialiased;
}

a {
  color: inherit;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  text-decoration-color: var(--border-strong);
}

a:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

h1,
h2,
h3,
p {
  margin-block: 0;
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: default;
  opacity: 0.5;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* Form controls */

input[type="search"],
input[type="text"],
input[type="number"],
select {
  min-width: 0;
  padding: 0.4rem 0.55rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 0.86rem;
}

input[type="search"] {
  font-size: 0.95rem;
}

input[type="search"]::placeholder,
input[type="text"]::placeholder {
  color: var(--text-faint);
}

select {
  padding-block: 0.3rem;
  background-color: var(--surface);
}

input[type="checkbox"] {
  width: 0.95rem;
  height: 0.95rem;
  margin: 0;
  accent-color: var(--accent);
}

button.primary,
button[type="submit"].primary {
  padding: 0.48rem 1rem;
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--surface);
  font-size: 0.86rem;
  font-weight: 600;
  letter-spacing: 0.01em;
}

button.primary:hover,
button[type="submit"].primary:hover {
  background: transparent;
  color: var(--accent);
}

button.quiet {
  padding: 0.25rem 0.55rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.78rem;
}

button.quiet:hover {
  border-color: var(--border-strong);
  color: var(--accent);
}

/* Page frame */

.page {
  width: min(100%, var(--page-width));
  margin-inline: auto;
  padding: 2.25rem clamp(1rem, 3vw, 2.5rem) 5rem;
}

.masthead {
  margin-bottom: 0.5rem;
  padding-bottom: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.masthead-line {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.35rem 1rem;
  margin-bottom: 1.35rem;
}

.masthead h1 {
  font-family: var(--font-display);
  font-size: 1.7rem;
  font-weight: 400;
  letter-spacing: -0.015em;
  line-height: 1.1;
}

.masthead .count {
  margin-left: 0.3rem;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 0.62em;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0;
}

.masthead-note {
  color: var(--text-faint);
  font-size: 0.74rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

/* Filters */

.filters {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
}

.search-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
}

.search-row input[type="search"] {
  flex: 1 1 auto;
  width: 100%;
  padding: 0.6rem 0.75rem;
}

.filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 1.4rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.field {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

.filter-group {
  display: flex;
  align-items: baseline;
  gap: 0.35rem 0.8rem;
  flex-wrap: wrap;
}

.filter-label {
  min-width: 4.5rem;
  color: var(--text-faint);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.chip-check {
  position: relative;
  cursor: pointer;
}

.chip-check > input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.chip-check > span {
  display: inline-flex;
  align-items: center;
  min-height: 1.65rem;
  padding: 0.08rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: 0.78rem;
  line-height: 1.35;
  transition: border-color 120ms ease, color 120ms ease,
    background-color 120ms ease;
}

.chip-check:hover > span {
  border-color: var(--border-strong);
  color: var(--text);
}

.chip-check > input:checked + span {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.chip-check > input:focus-visible + span {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Work entries */

.work {
  padding: 2.1rem 0;
  border-bottom: 1px solid var(--border);
}

.work-header {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem 1rem;
}

.work-heading {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.2rem 0.6rem;
  min-width: 0;
}

.same-code {
  align-self: center;
  display: inline-flex;
  color: var(--text-faint);
  line-height: 1;
  text-decoration: none;
}

.same-code svg {
  width: 13px;
  height: 13px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.5;
}

.same-code:hover {
  color: var(--accent);
}

.code {
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.035em;
  text-decoration: none;
}

.work h2 {
  font-family: var(--font-display);
  font-size: clamp(1.2rem, 1.4vw, 1.42rem);
  font-weight: 400;
  letter-spacing: -0.01em;
  line-height: 1.3;
  overflow-wrap: anywhere;
}

.work-sources {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  align-self: center;
}

.source {
  display: inline-flex;
  align-items: center;
  padding: 0.02rem 0.32rem;
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  line-height: 1.5;
  text-decoration: none;
  text-transform: uppercase;
}

a.source:hover {
  border-color: var(--accent);
  color: var(--accent);
}

a.source.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.hide-work {
  margin-left: auto;
  flex-shrink: 0;
}

.work-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.9rem;
  margin-top: 0.55rem;
}

.published-at {
  color: var(--text-muted);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.genres,
.stars {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
}

.genre,
.star {
  display: inline-flex;
  align-items: center;
  padding: 0.02rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: 0.74rem;
  line-height: 1.55;
  text-decoration: none;
}

.genre:hover,
.star:hover {
  border-color: var(--border-strong);
  color: var(--text);
}

.genre.selected,
.star.selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.star.new {
  padding-inline: 0.32rem;
  border-color: transparent;
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 0.78rem;
}

.star.new:hover {
  border-color: var(--border);
  color: var(--accent);
}

/* Gallery */

.gallery {
  margin: 1.05rem 0 0;
}

.gallery img {
  display: block;
  border-radius: 3px;
  background: var(--surface-alt);
  cursor: zoom-in;
  transition: opacity 160ms ease, filter 160ms ease;
}

.gallery img.cover {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: min(78vh, 60rem);
  margin-inline: auto;
  object-fit: contain;
}

.gallery .stills {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(125px, 1fr));
  grid-auto-rows: 132px;
  gap: 6px;
  margin-top: 6px;
}

.gallery .still {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery img.errored {
  opacity: 0.28;
  filter: grayscale(1);
}

/* Torrent table */

.torrents {
  margin-top: 0.9rem;
}

.torrents table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.torrents thead {
  color: var(--text-faint);
  font-size: 0.66rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.torrents th,
.torrents td {
  padding: 0.35rem 0.45rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-weight: 400;
  vertical-align: baseline;
}

.torrents th {
  white-space: nowrap;
}

.torrents td {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.torrents tbody tr:last-child th,
.torrents tbody tr:last-child td {
  border-bottom: none;
}

.torrents tbody button {
  max-width: 100%;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 0.8rem;
  text-align: left;
  white-space: normal;
}

.torrents tbody button:hover {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.torrents tfoot td {
  border-bottom: none;
  padding-top: 0.55rem;
}

.torrents tfoot button {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem;
}

.torrents tfoot button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Pager and footer */

.pager {
  padding: 1.6rem 0;
  border-bottom: 1px solid var(--border);
}

.pager a {
  display: inline-flex;
  align-items: baseline;
  gap: 0.55rem;
  font-size: 0.9rem;
  text-decoration: none;
}

.pager a::after {
  content: "\2192";
  color: var(--accent);
}

.pager-count {
  color: var(--text-faint);
  font-size: 0.76rem;
  font-variant-numeric: tabular-nums;
}

.page-footer {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1.25rem 2rem;
  padding-top: 1.5rem;
}

.page-footer form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem 0.7rem;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.bulk-read {
  padding-left: 0.45rem;
  border-left: 2px solid var(--border);
}

.bulk-read input[type="number"] {
  width: 4.5rem;
  text-align: right;
}

.tools {
  display: flex;
  flex-wrap: wrap;
  gap: 1.25rem 2rem;
}

.tools input[type="text"] {
  width: 12rem;
}

.tools input[type="file"] {
  max-width: 13rem;
  font-size: 0.78rem;
}

/* Download queue */

#download-queue {
  position: fixed;
  inset: 0 0 0 auto;
  z-index: 10;
  width: var(--queue-width);
  height: 100%;
  padding: 1.25rem 1rem;
  overflow-y: auto;
  border-left: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
}

.queue-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.5rem;
  margin-bottom: 0.9rem;
}

#download-queue h2 {
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.queue-actions {
  display: flex;
  gap: 0.3rem;
}

.queue-actions button {
  padding: 0.1rem 0.35rem;
  border: 1px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: var(--text-faint);
  font-size: 0.68rem;
}

.queue-actions button:hover {
  border-color: var(--border);
  color: var(--accent);
}

#download-queue h3 {
  margin: 0.9rem 0 0.3rem;
  color: var(--text-faint);
  font-size: 0.64rem;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

#download-status {
  min-height: 1.2em;
  margin-bottom: 0.4rem;
  color: var(--text-muted);
  font-size: 0.76rem;
}

#download-queue .job {
  display: flex;
  align-items: baseline;
  gap: 0.35rem;
  padding: 0.12rem 0;
}

#download-queue .job .code {
  color: var(--text);
  font-size: 0.72rem;
}

#download-queue .job .progress {
  color: var(--text-faint);
  font-size: 0.7rem;
  font-variant-numeric: tabular-nums;
}

#download-queue .job.failed .progress {
  color: var(--danger);
}

#download-queue .empty {
  color: var(--text-faint);
  font-size: 0.76rem;
}

#toggle-download-queue {
  display: none;
}

/* Lightbox */

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2.5rem;
  background: var(--overlay);
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: min(94vw, 1600px);
  max-height: calc(100vh - 5rem);
  border-radius: 2px;
  object-fit: contain;
  box-shadow: 0 24px 80px rgb(0 0 0 / 0.35);
  cursor: default;
}

.lightbox img:not([src]) {
  display: none;
}

.lightbox-close {
  position: absolute;
  top: 0.9rem;
  right: 1rem;
  width: 2.2rem;
  height: 2.2rem;
  padding: 0;
  border: 1px solid rgb(255 255 255 / 0.25);
  border-radius: 50%;
  background: rgb(0 0 0 / 0.25);
  color: #fff;
  font-size: 1.15rem;
  line-height: 1;
}

.lightbox-close:hover {
  border-color: #fff;
  background: rgb(0 0 0 / 0.45);
}

.lightbox-status {
  position: absolute;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%);
  color: rgb(255 255 255 / 0.85);
  font-size: 0.8rem;
  white-space: nowrap;
}

.lightbox-status[hidden] {
  display: none;
}

body.lightbox-open {
  overflow: hidden;
}

/* Genre table */

.table-page {
  padding-right: 0;
}

.table-page .page {
  max-width: 90rem;
}

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

.data-table {
  width: 100%;
  margin-top: 1.25rem;
  border-collapse: collapse;
  font-size: 0.84rem;
}

.data-table thead {
  color: var(--text-faint);
  font-size: 0.66rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.data-table th,
.data-table td {
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-weight: 400;
  vertical-align: top;
}

.data-table tbody tr:hover {
  background: var(--surface-alt);
}

.data-table td.number {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.source-metadata,
.source-metadata > dt,
.source-metadata > dd {
  display: inline;
  margin: 0;
}

.source-metadata > dd {
  margin-right: 0.6rem;
  color: var(--text-muted);
  font-family: var(--font-mono);
  font-size: 0.76rem;
}

.data-table button.primary {
  margin-top: 1rem;
}

/* Login */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.login-box {
  width: 100%;
  max-width: 21rem;
  padding: 2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.login-box h1 {
  font-family: var(--font-display);
  font-size: 1.55rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  text-align: center;
}

.login-note {
  margin-top: 0.4rem;
  color: var(--text-muted);
  font-size: 0.82rem;
  text-align: center;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

.login-form label {
  color: var(--text-faint);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.login-form input[type="text"] {
  padding: 0.7rem;
  font-family: var(--font-mono);
  font-size: 1.2rem;
  letter-spacing: 0.42em;
  text-align: center;
}

.login-form button {
  margin-top: 0.25rem;
}

.error {
  margin-top: 1rem;
  color: var(--danger);
  font-size: 0.82rem;
  text-align: center;
}

/* Responsive */

@media (max-width: 960px) {
  body {
    padding-right: 0;
    padding-bottom: 35vh;
  }

  #download-queue {
    top: auto;
    bottom: 0;
    left: 0;
    right: 0;
    width: auto;
    height: 35vh;
    border-top: 1px solid var(--border);
    border-left: 0;
  }

  #download-queue.collapsed {
    height: 2.9rem;
    overflow: hidden;
  }

  #toggle-download-queue {
    display: inline-block;
  }

  .page {
    padding-top: 1.5rem;
  }

  .page-footer {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 560px) {
  .gallery .stills {
    grid-template-columns: repeat(auto-fill, minmax(105px, 1fr));
    grid-auto-rows: 112px;
  }

  .work-header {
    flex-wrap: wrap;
  }

  .hide-work {
    margin-left: 0;
  }

  .filter-label {
    min-width: 100%;
  }

  .tools {
    flex-direction: column;
  }

  .tools input[type="text"],
  .tools input[type="file"] {
    width: 100%;
    max-width: none;
  }
}
