:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #efede8;
  --text: #1c1b19;
  --muted: #6d6a64;
  --line: #e2dfd8;
  --accent: #d9542b;
  --accent-ink: #ffffff;
  --mark: #ffe08a;
  --mark-ink: #1c1b19;
  --warn: #b7791f;
  --shadow: 0 1px 2px rgb(0 0 0 / .06), 0 4px 14px rgb(0 0 0 / .06);
  --shadow-hover: 0 2px 6px rgb(0 0 0 / .08), 0 14px 32px rgb(0 0 0 / .14);
  --radius: 10px;
  --gutter: clamp(16px, 2.2vw, 40px);
  --card-min: 168px;
  color-scheme: light;
}
/* dark: forced by the user's preference, or by the system unless they forced light */
:root[data-theme="dark"] {
  --bg: #121212;
  --surface: #1b1b1c;
  --surface-2: #242426;
  --text: #ecebe8;
  --muted: #9b9891;
  --line: #2e2e30;
  --accent: #f0764c;
  --accent-ink: #1a0f0a;
  --mark: #6b5310;
  --mark-ink: #fff4d1;
  --warn: #e0a84a;
  --shadow: 0 1px 2px rgb(0 0 0 / .4);
  --shadow-hover: 0 12px 32px rgb(0 0 0 / .55);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #121212;
    --surface: #1b1b1c;
    --surface-2: #242426;
    --text: #ecebe8;
    --muted: #9b9891;
    --line: #2e2e30;
    --accent: #f0764c;
    --accent-ink: #1a0f0a;
    --mark: #6b5310;
    --mark-ink: #fff4d1;
    --warn: #e0a84a;
    --shadow: 0 1px 2px rgb(0 0 0 / .4);
    --shadow-hover: 0 12px 32px rgb(0 0 0 / .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
a:hover { color: var(--accent); }
code, pre { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: .9em; }
pre { background: var(--surface-2); padding: 12px 16px; border-radius: 8px; overflow-x: auto; }
.muted { color: var(--muted); }
.warn { color: var(--warn); }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 12px var(--gutter);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; }
.brand-mark {
  width: 18px; height: 24px; border-radius: 3px; background: var(--accent);
  box-shadow: 4px 3px 0 -1px color-mix(in srgb, var(--accent) 45%, transparent);
}
.searchbar {
  flex: 1; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 0 6px 0 14px; height: 42px; max-width: 760px;
  transition: border-color .15s, box-shadow .15s;
}
.searchbar:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
.searchbar svg { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; stroke-linecap: round; flex: none; }
.searchbar input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: inherit; font: inherit; height: 100%;
}
.searchbar select {
  appearance: none; -webkit-appearance: none;
  height: 30px; max-width: 240px; flex: none; cursor: pointer;
  border: 1px solid transparent; border-radius: 999px;
  padding: 0 30px 0 14px;
  background-color: var(--surface-2);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12'%3E%3Cpath d='M3 4.5 6 7.5 9 4.5' fill='none' stroke='%23888' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 11px center; background-size: 12px;
  color: var(--text); font: inherit; font-size: 13px; font-weight: 550;
  text-overflow: ellipsis; white-space: nowrap;
  transition: border-color .15s, background-color .15s;
}
.searchbar select:hover { border-color: var(--line); background-color: var(--surface); }
.searchbar select:focus-visible { outline: 0; border-color: var(--accent); }
.searchbar select.scoped { background-color: color-mix(in srgb, var(--accent) 14%, var(--surface)); color: var(--accent); }
.searchbar select option { color: var(--text); background: var(--surface); font-weight: 400; }
.searchbar .divider { width: 1px; height: 20px; background: var(--line); flex: none; }
.scope-chip {
  font-size: 12px; white-space: nowrap; background: var(--surface-2); color: var(--muted);
  border-radius: 999px; padding: 4px 10px;
}

/* ---------- layout ---------- */
.page { padding: 20px var(--gutter) 64px; }
.hero { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin: 8px 0 20px; }
.hero h1 { margin: 2px 0 4px; font-size: clamp(24px, 2.4vw, 34px); letter-spacing: -.02em; line-height: 1.15; }
.hero p { margin: 0; }
.crumb { font-size: 13px; color: var(--muted); }
.crumb::after { content: " /"; opacity: .5; }
.section-h { font-size: 18px; margin: 36px 0 14px; letter-spacing: -.01em; }
.section-h .muted { font-weight: 400; font-size: 14px; margin-left: 6px; }
.year-h { position: sticky; top: 67px; z-index: 5; background: var(--bg); padding: 8px 0; margin: 20px 0 8px; }

.seg { display: inline-flex; background: var(--surface-2); border-radius: 999px; padding: 3px; }
.seg a { padding: 6px 14px; border-radius: 999px; font-size: 13px; color: var(--muted); }
.seg a.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.year-jump { display: flex; flex-wrap: wrap; gap: 4px; margin: -4px 0 8px; }
.year-jump a { font-size: 12px; padding: 3px 9px; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-variant-numeric: tabular-nums; }
.year-jump a:hover { background: var(--accent); color: var(--accent-ink); }

/* ---------- cards ---------- */
.grid {
  display: grid; gap: 28px 20px;
  grid-template-columns: repeat(auto-fill, minmax(var(--card-min), 1fr));
}
.grid-titles { --card-min: 190px; }
.card { display: block; min-width: 0; }
.cover {
  position: relative; aspect-ratio: 210 / 285; border-radius: 6px; overflow: hidden;
  background: var(--surface-2); box-shadow: var(--shadow);
  transition: transform .18s ease, box-shadow .18s ease;
}
.cover img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.card:hover .cover { transform: translateY(-3px); box-shadow: var(--shadow-hover); }
.cover-missing {
  display: grid; place-items: center; height: 100%; padding: 16px; text-align: center;
  font-weight: 700; color: var(--muted); font-size: 14px;
}
.card-meta { padding: 10px 2px 0; }
.card-title { font-weight: 650; line-height: 1.3; }
.card-label { font-weight: 550; line-height: 1.3; }
.title-card .card-title { font-size: 15.5px; }
.card-sub { color: var(--muted); font-size: 12.5px; margin-top: 2px; }
.card:hover .card-title, .card:hover .card-label { color: var(--accent); }

.badge {
  position: absolute; left: 8px; bottom: 8px;
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: rgb(0 0 0 / .72); color: #fff; backdrop-filter: blur(4px);
}
.badge + .badge { left: auto; right: 8px; }
.badge-warn { background: color-mix(in srgb, var(--warn) 90%, black); }
.badge.static { position: static; background: var(--surface-2); color: var(--muted); }
.count {
  position: absolute; top: 8px; right: 8px; min-width: 28px; text-align: center;
  font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--accent); color: var(--accent-ink); box-shadow: 0 2px 8px rgb(0 0 0 / .25);
}

.strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: 150px; gap: 20px;
  overflow-x: auto; padding: 4px 2px 16px; scroll-snap-type: x proximity;
}
.strip .card { scroll-snap-align: start; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  font-size: 13.5px; font-weight: 550; white-space: nowrap; max-width: 260px; overflow: hidden; text-overflow: ellipsis;
}
.btn:hover { border-color: var(--accent); }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { color: var(--accent-ink); filter: brightness(1.07); }

/* ---------- reader ---------- */
body.reading { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.reader { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.reader-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 10px var(--gutter); border-bottom: 1px solid var(--line); background: var(--surface);
}
.reader-id { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; min-width: 0; }
.reader-id strong { font-size: 17px; letter-spacing: -.01em; }
.reader-id .muted { font-size: 13px; }
.reader-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.viewer { flex: 1; width: 100%; border: 0; background: var(--surface-2); display: block; }
.notice {
  margin: 0; padding: 10px var(--gutter); font-size: 13.5px;
  background: color-mix(in srgb, var(--warn) 14%, var(--surface)); border-bottom: 1px solid var(--line);
}
.page > .notice { border-radius: 8px; border: 1px solid var(--line); margin-bottom: 16px; }

/* ---------- search ---------- */
.chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 18px; font-size: 13px; }
.chip { padding: 4px 12px; border-radius: 999px; background: var(--surface); border: 1px solid var(--line); }
.results {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 640px), 1fr));
}
.result {
  display: grid; grid-template-columns: 96px 1fr; gap: 16px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
  min-width: 0;
}
.result-cover { display: block; aspect-ratio: 210/285; border-radius: 4px; overflow: hidden; background: var(--surface-2); box-shadow: var(--shadow); align-self: start; }
.result-cover img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.result-cover .cover-missing { font-size: 11px; padding: 6px; }
.result-body { min-width: 0; }
.result-body header { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.result-title { font-weight: 650; font-size: 15.5px; }
.result-title span { font-weight: 500; color: var(--muted); }
.result-body header .muted { font-size: 12.5px; }
.dl { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.hits { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.hits a { display: grid; grid-template-columns: 44px 1fr; gap: 8px; padding: 5px 8px; margin: 0 -8px; border-radius: 6px; font-size: 13.5px; line-height: 1.45; }
.hits a:hover { background: var(--surface-2); color: inherit; }
.pg { color: var(--accent); font-weight: 650; font-variant-numeric: tabular-nums; }
.snip { color: var(--muted); overflow-wrap: anywhere; }
mark { background: var(--mark); color: var(--mark-ink); border-radius: 2px; padding: 0 1px; }
.more-hits { margin-top: 6px; font-size: 13px; }
.more-hits summary { cursor: pointer; color: var(--muted); }
.page-pills { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; }
.page-pills a { font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); font-variant-numeric: tabular-nums; }
.load-more { text-align: center; margin-top: 28px; }

.empty { text-align: center; padding: 64px 16px; color: var(--muted); }
.empty h2 { color: var(--text); margin-bottom: 6px; }
.empty pre { display: inline-block; text-align: left; }

/* ---------- small screens ---------- */
@media (max-width: 720px) {
  .topbar { gap: 12px; flex-wrap: wrap; }
  .brand span:last-child { display: none; }
  .searchbar { order: 2; flex-basis: 100%; }
  .searchbar select { max-width: 120px; }
  .year-h { top: 118px; }
  :root { --card-min: 130px; }
  .grid-titles { --card-min: 140px; }
  .grid { gap: 20px 14px; }
  .result { grid-template-columns: 64px 1fr; gap: 12px; }
  .reader-bar .btn { height: 30px; padding: 0 10px; }
}
.hero h1 .q { color: var(--accent); }

/* ---------- account / sign-in ---------- */
.account-nav { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 13.5px; white-space: nowrap; }
.account-nav form { margin: 0; }
.account-nav a { color: var(--muted); }
.account-nav a:hover, .linkish:hover { color: var(--accent); }
.linkish { background: none; border: 0; padding: 0; font: inherit; color: var(--muted); cursor: pointer; }
.auth { max-width: 380px; margin: 12vh auto 0; padding: 0 var(--gutter); }
.auth h1 { font-size: 24px; letter-spacing: -.02em; margin: 0 0 4px; }
.auth > p { margin: 0 0 20px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); }
.stack { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; font-size: 13px; font-weight: 550; color: var(--muted); }
.field input, .field select {
  height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font: inherit; font-weight: 400;
}
.field input:focus, .field select:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 22%, transparent); }
button.btn { cursor: pointer; font-family: inherit; justify-content: center; height: 40px; }
.form-error { margin: 0; padding: 9px 12px; border-radius: 8px; font-size: 13.5px; background: color-mix(in srgb, var(--accent) 12%, var(--surface)); border: 1px solid color-mix(in srgb, var(--accent) 40%, var(--line)); }
.form-ok { margin: 0; padding: 9px 12px; border-radius: 8px; font-size: 13.5px; background: var(--surface-2); }
.settings { max-width: 520px; margin: 0 auto; }
.settings .section-h { margin: 28px 0 12px; }
.user-icon { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 50%; background: var(--surface); border: 1px solid var(--line); }
.user-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.user-icon:hover { border-color: var(--accent); }
