/* AgoralGlobal store — Direction 6 "Combined" (ground truth §5.10).
   True black, gold accents, off-white text. Thin dividers. No glows, shadows or gradients.
   Playfair Display = book titles; Source Sans 3 = interface; JetBrains Mono = numbers only. */

/* ── Fonts (self-hosted, SIL OFL — licences in /fonts) ─────────────────── */
@font-face {
  font-family: "Playfair Display"; font-style: normal; font-weight: 400 900; font-display: swap;
  src: url("/fonts/playfair-display-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Playfair Display"; font-style: normal; font-weight: 400 900; font-display: swap;
  src: url("/fonts/playfair-display-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Playfair Display"; font-style: italic; font-weight: 400 900; font-display: swap;
  src: url("/fonts/playfair-display-latin-wght-italic.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Sans 3"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url("/fonts/source-sans-3-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Source Sans 3"; font-style: normal; font-weight: 200 900; font-display: swap;
  src: url("/fonts/source-sans-3-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 100 800; font-display: swap;
  src: url("/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329,
    U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "JetBrains Mono"; font-style: normal; font-weight: 100 800; font-display: swap;
  src: url("/fonts/jetbrains-mono-latin-ext-wght-normal.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329,
    U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ── Tokens ────────────────────────────────────────────────────────────── */
:root {
  --bg: #0a0a0f;
  --panel: #111118;
  --cover-black: #050508;
  --line: #2a2a33;
  --line-strong: #3d3d48;
  --text: #ece7dc;
  --muted: #aaa59a;        /* 7.9:1 on --bg */
  --gold: #d4a44c;         /* 8.9:1 on --bg */
  --gold-soft: #e3bd73;
  --on-gold: #0a0a0f;
  --error: #f08a7a;        /* 7.6:1 on --bg; always paired with words */
  --success: #9fcf9a;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: "Source Sans 3", "Segoe UI", system-ui, -apple-system, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Consolas, monospace;
  --radius: 4px;
  --pad: clamp(16px, 4vw, 40px);
  --max: 1280px;
  color-scheme: dark;
}

/* ── Base ──────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font-family: var(--sans); font-size: 1.0625rem; line-height: 1.5;
}
main { flex: 1; outline: none; }
h1, h2, h3 { margin: 0; font-weight: 600; line-height: 1.2; }
h1 { font-family: var(--serif); font-size: clamp(1.75rem, 4vw, 2.5rem); font-weight: 600; outline: none; }
p { margin: 0 0 0.75em; }
a { color: var(--gold); text-underline-offset: 0.18em; }
a:hover { color: var(--gold-soft); }
img { max-width: 100%; display: block; }
button, input, select { font: inherit; color: inherit; }
.mono { font-family: var(--mono); font-size: 0.92em; font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--gold); outline-offset: 3px; border-radius: 2px; }
h1:focus-visible, main:focus-visible { outline: none; }

.skip-link {
  position: absolute; left: 8px; top: -100px; z-index: 100; padding: 8px 14px;
  background: var(--gold); color: var(--on-gold); font-weight: 600; text-decoration: none; border-radius: var(--radius);
}
.skip-link:focus { top: 8px; }

/* ── TEST banner ───────────────────────────────────────────────────────── */
.test-banner {
  border-bottom: 1px solid var(--gold); color: var(--gold); background: var(--bg);
  text-align: center; font-size: 0.9rem; font-weight: 600; letter-spacing: 0.02em; padding: 6px var(--pad);
}

/* ── Header ────────────────────────────────────────────────────────────── */
.site-header { border-bottom: 1px solid var(--line); }
.header-inner {
  max-width: var(--max); margin: 0 auto; padding: 14px var(--pad);
  display: grid; grid-template-columns: auto 1fr auto; gap: 12px 28px; align-items: center;
}
.wordmark {
  font-family: var(--serif); font-size: 1.55rem; font-weight: 600; color: var(--gold); text-decoration: none;
  letter-spacing: 0.01em; white-space: nowrap;
}
.wordmark:hover { color: var(--gold-soft); }
.search { display: flex; gap: 0; max-width: 560px; width: 100%; justify-self: center; }
.search input {
  flex: 1; min-width: 0; padding: 9px 12px; background: var(--panel); border: 1px solid var(--line-strong);
  border-right: 0; border-radius: var(--radius) 0 0 var(--radius);
}
.search input::placeholder { color: #8c887f; }
.search .btn { border-radius: 0 var(--radius) var(--radius) 0; border: 1px solid var(--line-strong); }
.site-nav { display: flex; align-items: center; gap: 22px; white-space: nowrap; }
.site-nav > a { color: var(--text); text-decoration: none; padding: 6px 0; border-bottom: 1px solid transparent; }
.site-nav > a:hover { color: var(--gold); }
.site-nav > a[aria-current="page"] { color: var(--gold); border-bottom-color: var(--gold); }
.count {
  display: inline-block; margin-left: 6px; min-width: 1.6em; padding: 0 6px; text-align: center;
  border: 1px solid var(--gold); border-radius: 999px; color: var(--gold); font-size: 0.85rem; line-height: 1.45;
}
.account-area { min-width: 64px; display: flex; justify-content: flex-end; }
.signin-link { color: var(--text); text-decoration: none; padding: 6px 12px; border: 1px solid var(--line-strong);
  border-radius: var(--radius); }
.signin-link:hover { border-color: var(--gold); color: var(--gold); }
.account-menu { position: relative; }
.account-menu summary {
  list-style: none; cursor: pointer; padding: 6px 10px; border: 1px solid var(--line-strong); border-radius: var(--radius);
  max-width: 180px; overflow: hidden; text-overflow: ellipsis;
}
.account-menu summary::-webkit-details-marker { display: none; }
.account-menu summary::after { content: " ▾"; color: var(--gold); }
.account-menu[open] summary { border-color: var(--gold); }
.menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20; min-width: 180px; margin: 0; padding: 6px 0;
  list-style: none; background: var(--panel); border: 1px solid var(--line-strong); border-radius: var(--radius);
}
.menu-item {
  display: block; width: 100%; padding: 8px 14px; text-align: left; background: none; border: 0; cursor: pointer;
  color: var(--text); text-decoration: none;
}
.menu-item:hover { background: #1b1b24; color: var(--gold); }

/* ── Layout ────────────────────────────────────────────────────────────── */
.page { max-width: var(--max); margin: 0 auto; padding: 28px var(--pad) 56px; }
.page.narrow { max-width: 640px; }
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px 24px;
  padding-bottom: 16px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.section-label {
  font-family: var(--sans); font-size: 0.82rem; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--gold); margin-bottom: 12px;
}
.lead { color: var(--muted); font-size: 1.1rem; }
.note { color: var(--muted); font-size: 0.92rem; }
.status { margin: 0 0 14px; }
.status-quiet { color: var(--muted); }
.status-error, .form-error, .field-error { color: var(--error); }
.status-success { color: var(--success); }

/* ── Buttons & fields ──────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35em; min-height: 44px;
  padding: 9px 18px; border-radius: var(--radius); border: 1px solid transparent; cursor: pointer;
  font-weight: 600; text-decoration: none; line-height: 1.2; text-align: center;
}
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-primary { background: var(--gold); color: var(--on-gold); border-color: var(--gold); }
.btn-primary:hover:not(:disabled) { background: var(--gold-soft); border-color: var(--gold-soft); color: var(--on-gold); }
.btn-secondary { background: transparent; color: var(--gold); border-color: var(--gold); }
.btn-secondary:hover:not(:disabled) { background: #1a160c; color: var(--gold-soft); }
.btn-quiet { background: var(--panel); color: var(--text); border-color: var(--line-strong); }
.btn-quiet:hover:not(:disabled) { border-color: var(--gold); color: var(--gold); }
.btn-danger { background: transparent; color: var(--error); border-color: var(--error); }
.btn-wide { width: 100%; }
.action-buttons { display: flex; flex-wrap: wrap; gap: 10px; margin: 8px 0 10px; }

.field { margin-bottom: 18px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-weight: 600; }
.field input, .field select {
  width: 100%; padding: 10px 12px; min-height: 44px; background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: var(--radius);
}
.field input[aria-invalid="true"] { border-color: var(--error); }
.field-inline { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.field-inline label { font-weight: 400; color: var(--muted); font-size: 0.95rem; }
.field-inline select { width: auto; min-height: 40px; padding: 6px 10px; }
.hint { color: var(--muted); font-size: 0.9rem; margin: 0; }
.field-error { font-size: 0.95rem; margin: 0; }
.form-error { margin: 0 0 14px; padding: 10px 12px; border: 1px solid var(--error); border-radius: var(--radius); }
.password-row { display: flex; gap: 8px; }
.password-row input { flex: 1; min-width: 0; }
.reveal { min-width: 72px; }
.auth-form { margin-top: 22px; }
.switch { margin-top: 20px; color: var(--muted); }
.inline-row { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-row input { flex: 1; min-width: 180px; width: auto; }

/* ── Filters & grid ────────────────────────────────────────────────────── */
.filters { display: flex; flex-wrap: wrap; gap: 10px 20px; }
.grid {
  list-style: none; margin: 0; padding: 0; display: grid; gap: 28px 22px;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 150px), 1fr));
}
@media (min-width: 900px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }
.card { position: relative; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.card .cover { margin-bottom: 8px; }
.card-title { font-family: var(--serif); font-size: 1.08rem; font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.card-link { color: var(--text); text-decoration: none; }
.card-link::after { content: ""; position: absolute; inset: 0; }
.card:hover .card-link { color: var(--gold); }
.card-link:focus-visible { outline: none; }
.card:has(.card-link:focus-visible) { outline: 2px solid var(--gold); outline-offset: 6px; border-radius: 2px; }
.card-author { color: var(--muted); margin: 0; font-size: 0.95rem; overflow-wrap: anywhere; }
.card-meta { margin: 2px 0 0; color: var(--text); font-size: 0.92rem; }
.card-meta .price { color: var(--gold); }
.card-rent { margin: 0; color: var(--muted); font-size: 0.9rem; }
.sep { margin: 0 6px; color: var(--muted); }
.badge {
  align-self: flex-start; display: inline-block; padding: 1px 8px; font-size: 0.8rem; font-weight: 600;
  letter-spacing: 0.02em; border: 1px solid var(--line-strong); border-radius: 999px; color: var(--text);
}
.badge-human { border-color: var(--gold); color: var(--gold); }
.load-more-row { display: flex; justify-content: center; margin-top: 36px; }

/* ── Covers (real image over a generated placeholder) ──────────────────── */
.cover {
  position: relative; aspect-ratio: 1 / 1; width: 100%; overflow: hidden; container-type: inline-size;
  background: var(--cover-black); border-radius: 2px;
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.cover-ph {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6cqi; padding: 10cqi 9cqi; text-align: center; background: var(--cover-black);
  border: 1px solid var(--gold); outline: 1px solid rgba(212, 164, 76, 0.35); outline-offset: -5cqi;
}
.cover-ph-title {
  font-family: var(--serif); font-weight: 600; color: var(--text); font-size: 10cqi; line-height: 1.15;
  display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere;
}
.cover-ph-long .cover-ph-title { font-size: 9cqi; -webkit-line-clamp: 4; }
.cover-ph-xlong .cover-ph-title { font-size: 8cqi; -webkit-line-clamp: 5; }
.cover-ph-title { flex: 0 0 auto; }
.cover-ph-rule { width: 18cqi; height: 1px; background: var(--gold); flex: none; }
.cover-ph-author {
  font-family: var(--sans); color: var(--gold); font-size: 6.5cqi; letter-spacing: 0.08em; text-transform: uppercase;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
@container (max-width: 120px) {
  .cover-ph { gap: 5cqi; padding: 8cqi; outline: 0; }
  .cover-ph .cover-ph-title { font-size: 12cqi; -webkit-line-clamp: 4; }
  .cover-ph-author, .cover-ph-rule { display: none; }
}

/* ── Book page ─────────────────────────────────────────────────────────── */
.book-top { display: grid; grid-template-columns: minmax(0, 340px) minmax(0, 1fr); gap: 40px; align-items: start; }
.book-title { font-size: clamp(1.9rem, 4.2vw, 2.9rem); overflow-wrap: anywhere; }
.book-subtitle { font-family: var(--serif); font-style: italic; color: var(--muted); font-size: 1.2rem; margin-top: 8px; }
.book-byline { margin: 14px 0 2px; font-size: 1.1rem; }
.book-narrator { color: var(--muted); margin-bottom: 10px; }
.book-badges { margin: 8px 0 14px; }
.book-price { font-size: 1.35rem; margin-bottom: 6px; }
.book-price > .mono { color: var(--gold); }
.book-rent-from { font-size: 1rem; color: var(--muted); }
.actions { padding: 16px 0; margin: 10px 0 18px; border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.ownership { font-weight: 600; color: var(--gold); font-size: 1.1rem; margin-bottom: 8px; outline: none; }
.confirm-question { font-size: 1.08rem; margin-bottom: 6px; }
.confirm-question em { font-family: var(--serif); font-style: italic; }
.open-in-app { margin-top: 6px; }
.app-note { margin: 8px 0 0; }
.facts { margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px 24px; }
.fact dt { color: var(--muted); font-size: 0.85rem; }
.fact dd { margin: 0; overflow-wrap: break-word; min-width: 0; }
.book-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 34px; margin-top: 40px; max-width: 820px; }
.book-section { padding-top: 18px; border-top: 1px solid var(--line); }
.preview { width: 100%; max-width: 520px; }
.chapters { list-style: none; margin: 0; padding: 0; counter-reset: ch; }
.chapters li {
  display: flex; justify-content: space-between; gap: 16px; padding: 8px 0; border-bottom: 1px solid var(--line);
  counter-increment: ch;
}
.chapters li::before { content: counter(ch); font-family: var(--mono); color: var(--muted); min-width: 2.2em; font-size: 0.9em; }
.chapter-title { flex: 1; font-family: var(--serif); }
.chapter-time { color: var(--muted); }

/* ── Library ───────────────────────────────────────────────────────────── */
.library-section { margin-bottom: 44px; }
.library-section .section-label { padding-bottom: 10px; border-bottom: 1px solid var(--line); margin-bottom: 0; }
.shelf { list-style: none; margin: 0; padding: 0; }
.shelf-item {
  display: grid; grid-template-columns: 96px minmax(0, 1fr) auto; gap: 18px; align-items: start;
  padding: 18px 0; border-bottom: 1px solid var(--line);
}
.shelf-title { font-family: var(--serif); font-size: 1.2rem; overflow-wrap: anywhere; }
.shelf-title a { color: var(--text); text-decoration: none; }
.shelf-title a:hover { color: var(--gold); text-decoration: underline; }
.shelf-author { color: var(--muted); margin: 2px 0 6px; }
.shelf-info .badge { margin-bottom: 6px; }
.rental-state { margin: 4px 0; font-weight: 600; }
.rental-state[data-state="renting"] { color: var(--gold); }
.rental-state[data-state="ended"] { color: var(--error); }
.progress { margin: 2px 0 0; font-size: 0.95rem; }
.shelf-actions { max-width: 260px; }
.shelf-actions .app-note { font-size: 0.85rem; }
.empty { color: var(--muted); padding: 18px 0; }

/* ── Account ───────────────────────────────────────────────────────────── */
.account-section { margin-top: 34px; }
.account-section .facts { margin-bottom: 18px; display: flex; flex-wrap: wrap; gap: 12px 40px; }
.account-email { overflow-wrap: anywhere; }
.devices { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.device { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 10px 20px; padding: 14px 0;
  border-bottom: 1px solid var(--line); }
.device-name { font-weight: 600; margin: 0 0 2px; }
.device-meta { color: var(--muted); font-size: 0.92rem; margin: 0; }
.device-actions { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.device-actions .confirm-question { font-size: 0.98rem; margin: 0; }
.device-actions .action-buttons { margin: 4px 0 0; }
.tag {
  display: inline-block; margin-left: 10px; padding: 0 8px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em;
  color: var(--gold); border: 1px solid var(--gold); border-radius: 999px; vertical-align: 2px;
}

/* ── Footer ────────────────────────────────────────────────────────────── */
.site-footer { border-top: 1px solid var(--line); margin-top: 24px; }
.footer-inner { max-width: var(--max); margin: 0 auto; padding: 24px var(--pad) 32px; color: var(--muted); font-size: 0.92rem; }
.footer-links { list-style: none; margin: 0 0 10px; padding: 0; display: flex; flex-wrap: wrap; gap: 6px 22px; }
.footer-links a { color: var(--text); }
.app-promo { color: var(--text); }
.fine { margin: 0; font-size: 0.85rem; }
html.in-app .app-promo { display: none; }
.noscript { padding: 20px var(--pad); }

/* ── Small screens ─────────────────────────────────────────────────────── */
@media (max-width: 860px) {
  .header-inner { grid-template-columns: auto 1fr; }
  .site-nav { justify-self: end; gap: 14px; }
  .search { grid-column: 1 / -1; grid-row: 2; max-width: none; }
  .book-top { grid-template-columns: minmax(0, 1fr); gap: 24px; }
  .book-cover { max-width: 300px; width: 70%; }
}
@media (max-width: 520px) {
  body { font-size: 1rem; }
  .header-inner { grid-template-columns: minmax(0, 1fr); gap: 10px; padding-top: 12px; padding-bottom: 12px; }
  .wordmark { font-size: 1.4rem; }
  .site-nav { justify-self: stretch; justify-content: space-between; }
  .search { grid-row: 3; }
  .page { padding-top: 20px; }
  .page-head { flex-direction: column; align-items: stretch; }
  .filters { justify-content: space-between; }
  .grid { gap: 24px 14px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .shelf-item { grid-template-columns: 72px minmax(0, 1fr); gap: 14px; }
  .shelf-actions { grid-column: 1 / -1; max-width: none; }
  .device-actions { align-items: flex-start; width: 100%; }
  .account-menu summary { max-width: 130px; }
}

/* ── Motion ────────────────────────────────────────────────────────────── */
@media (prefers-reduced-motion: no-preference) {
  .btn, .site-nav > a, .menu-item, .card-link, .signin-link { transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
