@font-face { font-family: "Cairo"; src: url("fonts/Cairo.ttf") format("truetype"); font-weight: 200 1000; font-display: swap; }
@font-face { font-family: "Alexandria"; src: url("fonts/Alexandria.ttf") format("truetype"); font-weight: 100 900; font-display: swap; }

:root {
  --bg: #f6f3ec; --surface: #fffdf8; --ink: #23201a; --muted: #6f685b; --line: #e3ddcf;
  --accent: #7e5a2a; --accent-ink: #fff; --olive: #5f6b2e; --sky: #2f6a8a; --clay: #a5563b;
  --chip: #efe9dc; --focus: #c58b2c; --warn: #a33a2a;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17150f; --surface: #211e17; --ink: #efe8d8; --muted: #a79f8c; --line: #3a3427;
    --accent: #d7a65a; --accent-ink: #1b1710; --olive: #a8b56b; --sky: #7fb7d6; --clay: #e08d70;
    --chip: #2c271d; --focus: #e2b45e; --warn: #f08b77; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17150f; --surface: #211e17; --ink: #efe8d8; --muted: #a79f8c; --line: #3a3427;
  --accent: #d7a65a; --accent-ink: #1b1710; --olive: #a8b56b; --sky: #7fb7d6; --clay: #e08d70;
  --chip: #2c271d; --focus: #e2b45e; --warn: #f08b77; color-scheme: dark;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.7 "Cairo", system-ui, sans-serif; }
a { color: inherit; }
main { max-width: 1100px; margin: 0 auto; padding: 16px 16px 64px; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

.top { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px 24px;
  border-bottom: 1px solid var(--line); background: var(--surface); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; gap: 10px; align-items: center; text-decoration: none; font-family: "Alexandria", "Cairo"; font-weight: 700; font-size: 18px; }
.brand small { display: block; font: 500 11px/1 "Alexandria", sans-serif; color: var(--muted); letter-spacing: .08em; }
.brand .mark { width: 34px; height: 34px; border-radius: 8px; background: var(--accent); color: var(--accent-ink);
  display: grid; place-items: center; font-size: 20px; }
.top nav { display: flex; gap: 18px; align-items: center; }
.top nav a { text-decoration: none; color: var(--muted); font-weight: 600; }
.top nav a:hover { color: var(--ink); }

.search input[type=search] { width: 100%; font: inherit; font-size: 19px; padding: 14px 18px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
select, input, textarea, button { font: inherit; color: var(--ink); }
select, .inline-form input, .note-form input, .note-form textarea, .reading input, .login input {
  padding: 7px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); max-width: 100%; }
button, .btn { padding: 7px 16px; border-radius: 8px; border: 0; background: var(--accent); color: var(--accent-ink);
  font-weight: 700; cursor: pointer; text-decoration: none; display: inline-block; font-size: 14px; }
.btn.ghost, button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--line); }
button.link { background: none; color: var(--muted); padding: 0; font-weight: 500; text-decoration: underline; }
.reset { color: var(--muted); font-size: 14px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin: 22px 0 6px; }
.stats div { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; }
.stats b { display: block; font: 700 26px/1.2 "Alexandria", "Cairo"; font-variant-numeric: tabular-nums; }
.stats span { color: var(--muted); font-size: 14px; }

.count { color: var(--muted); margin: 18px 0 6px; font-size: 14px; }
.results { list-style: none; padding: 0; margin: 0; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.results li { padding: 12px 16px; border-bottom: 1px solid var(--line); display: grid; gap: 2px; }
.results li:last-child { border-bottom: 0; }
.results .title { font-weight: 700; font-size: 17px; text-decoration: none; }
.results .title:hover { color: var(--accent); }
.results .author { color: var(--muted); font-size: 14px; }
.results .empty { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 4px; }
.chip { font-size: 12px; padding: 1px 8px; border-radius: 99px; background: var(--chip); color: var(--muted); font-weight: 600; white-space: nowrap; }
.chip.src-physical { color: var(--clay); }
.chip.src-passport { color: var(--olive); }
.chip.src-drive { color: var(--sky); }
.chip.pick { background: var(--accent); color: var(--accent-ink); }
.chip.pick2 { color: var(--accent); }
.chip.st-reading { background: var(--olive); color: var(--surface); }
.chip.st-done { background: var(--sky); color: var(--surface); }
.copies { font-size: 12px; color: var(--muted); }
.pager { display: flex; justify-content: space-between; margin-top: 16px; }

.work h1 { font: 700 clamp(26px, 4vw, 38px)/1.3 "Alexandria", "Cairo"; margin: 6px 0 4px; }
.crumbs { font-size: 13px; color: var(--muted); margin: 8px 0 0; }
.crumbs a { color: var(--muted); }
.by { font-size: 18px; margin: 0; }
.meta { color: var(--muted); margin: 2px 0 16px; }
.grid { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; align-items: start; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; margin-bottom: 16px; min-width: 0; }
.card h2 { font: 700 18px/1.4 "Alexandria", "Cairo"; margin: 0 0 10px; }
.card h2 small { color: var(--muted); font: 500 13px "Cairo"; }
.card h3 { font-size: 15px; margin: 18px 0 8px; }
.card.muted { background: transparent; }
.copies { width: 100%; border-collapse: collapse; }
table.copies td { padding: 8px 6px; border-top: 1px solid var(--line); vertical-align: top; font-size: 14px; }
table.copies tr:first-child td { border-top: 0; }
td.loc { color: var(--muted); word-break: break-word; }
td.act { white-space: nowrap; }
td.act form { display: inline; }
td.size { color: var(--muted); white-space: nowrap; font-size: 12px; }
.warn { color: var(--warn); font-style: normal; }
.small { font-size: 13px; color: var(--muted); }
.reading { display: grid; gap: 10px; }
.reading label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.reading .inline { display: flex; align-items: center; gap: 6px; }
.reading input[type=number] { width: 90px; }
.lists { display: flex; flex-wrap: wrap; gap: 6px; }
.toggle { background: var(--chip); color: var(--ink); font-weight: 600; }
.toggle.on { background: var(--olive); color: var(--surface); }
.why { font-size: 14px; margin: 8px 0 0; }
.note-form { display: grid; grid-template-columns: 1fr 120px auto; gap: 8px; align-items: start; }
.note-form textarea { grid-column: 1 / -1; }
.note { border-top: 1px solid var(--line); padding: 10px 0; }
.note p { margin: 0 0 2px; white-space: pre-wrap; }
.note form { display: inline; margin-inline-start: 10px; }
.mini { margin: 0; padding-inline-start: 18px; }
.mini li { margin: 4px 0; }
.inline-form { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.login { max-width: 360px; margin: 60px auto; display: grid; gap: 10px; }
.flash { max-width: 1100px; margin: 12px auto 0; padding: 0 16px; }
.flash p { background: var(--chip); border-radius: 8px; padding: 8px 12px; margin: 0; }

@media (max-width: 760px) {
  .top { padding: 10px 16px; }
  .top nav { gap: 12px; font-size: 14px; }
  .brand small { display: none; }
  .grid { grid-template-columns: 1fr; }
  .filters select { flex: 1 1 45%; }
  .note-form { grid-template-columns: 1fr auto; }
  table.copies td.size { display: none; }
  td.act { white-space: normal; }
}

.chip.trk { background: transparent; border: 1px solid var(--line); }
.chip.trk-1 { color: var(--sky); } .chip.trk-2 { color: var(--olive); } .chip.trk-3 { color: var(--accent); }
.chip.trk-4 { color: var(--clay); } .chip.trk-5 { color: var(--ink); }
.scores { font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; margin-inline-start: auto; }
table.tracks { width: 100%; border-collapse: collapse; margin-bottom: 10px; }
table.tracks td { padding: 6px 4px; border-top: 1px solid var(--line); vertical-align: middle; }
table.tracks tr:first-child td { border-top: 0; }
td.bar { width: 90px; }
td.bar span { display: block; height: 6px; border-radius: 3px; background: var(--chip); position: relative; overflow: hidden; }
td.bar span::after { content: ''; position: absolute; inset-block: 0; inset-inline-start: 0; width: 0; background: var(--accent); border-radius: 3px; }
td.bar span.v0::after { width: 0%; }
td.bar span.v1::after { width: 20%; }
td.bar span.v2::after { width: 40%; }
td.bar span.v3::after { width: 60%; }
td.bar span.v4::after { width: 80%; }
td.bar span.v5::after { width: 100%; }
.scorebox { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.scorebox div { background: var(--chip); border-radius: 10px; padding: 10px; text-align: center; }
.scorebox b { display: block; font: 700 26px/1.2 "Alexandria", "Cairo"; font-variant-numeric: tabular-nums; }
.scorebox span { font-size: 12px; color: var(--muted); }
#tracks label { display: grid; gap: 4px; margin: 8px 0; }
#tracks input[type=number] { width: 90px; padding: 6px 8px; border-radius: 8px; border: 1px solid var(--line); background: var(--surface); }
