/* theme.css and data-page.css are loaded as separate <link> tags in the
   HTML (parallel, render-blocking) instead of @import chains — a chained
   import painted the page unstyled on slow connections. Load order:
   theme -> data-page -> this file. */
/* ---------------------------------------------------------------
   Bookshelf — minimalist reading library
   Page chrome (header/toolbar/tabs/inputs) comes from data-page.css.
   ------------------------------------------------------------- */

/* Bookshelf-only variables (shared palette lives in theme.css). */
:root {
  --warn: #e0a458;
  --warn-soft: #332a1c;
  --link: #c9d4e3;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  --radius: 10px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: Georgia, "Times New Roman", serif;
  /* No page-width cap: on an ultrawide the shelf should use the full
     window (it's a cover grid, not running text). */
  --page-max: none;
}

body {
  -webkit-font-smoothing: antialiased;
}

body.modal-open {
  overflow: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ---------- Header (chrome from data-page.css) ---------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
}

/* ---------- Toolbar: source tabs + highlights chip + sync ---------- */
/* (toolbar, tab-bar, tabs, search-input, sort-select from data-page.css) */

/* Base layout from data-page.css .toolbar-meta */
.sync-status .sync-label {
  color: var(--text-muted);
}

.sync-source.stale,
.sync-source.error {
  color: var(--warn);
  font-weight: 600;
}

/* ---------- Main / states ---------- */

main {
  max-width: var(--page-max);
  margin: 0 auto;
  padding: 0 2rem 4rem;
  min-height: 40vh;
}

/* .loading / .empty-state styling comes from data-page.css — no module
   overrides (a leftover 0.95rem override made the bookshelf loading line
   bigger than the newsletters one). */

/* ---------- Book grid ---------- */

.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 1.6rem 1.1rem;
  margin-top: 1.25rem;
}

.book-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  cursor: pointer;
  border-radius: var(--radius);
  padding: 0.4rem;
  transition: transform 0.15s ease;
}


.cover-wrap {
  position: relative;
  aspect-ratio: 2 / 3;
  border-radius: 6px;
  overflow: hidden;
  background: var(--bg-elevated);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

/* The tinted card background marks books that are underway or finished
   (reading progress > 0% or read) — highlights have their own ❝ mark on
   the cover bar. */
.book-card.in-progress {
  /* longhand on purpose: the shorthand would wipe the .crt-heavy
     scanline layer out of the background stack */
  background-color: var(--bg-elevated);
}

.cover-img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.cover-placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem;
  text-align: center;
  font-family: var(--font-serif);
  font-size: 0.72rem;
  line-height: 1.25;
  color: var(--text-muted);
}

.book-meta {
  padding: 0 0.15rem;
}

.book-title {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0 0 0.15rem;
  color: var(--text);
}

.book-author {
  font-size: 0.76rem;
  color: var(--text-muted);
  margin: 0 0 0.4rem;
}

.book-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  margin-bottom: 0.3rem;
}

/* One frosted (translucent white) bar along the bottom of the cover: source
   tags left, highlight count right. Readable on any cover without the tags
   sitting "directly on the book". Grid only. */
.cover-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 5px 8px;
  /* A single dark scrim carries the contrast now that the labels have no
     chip background of their own; text sits directly in the bar. */
  background: linear-gradient(to top, rgba(8, 9, 12, 0.62), rgba(8, 9, 12, 0.28));
  backdrop-filter: blur(2px);
  pointer-events: none;
}

.cover-sources {
  display: flex;
  gap: 8px;
}

.cover-source-mark,
.cover-highlight-mark {
  font-size: 0.6rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  color: rgba(255, 255, 255, 0.92);
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55);
  white-space: nowrap;
}

.badge {
  font-size: 0.68rem;
  letter-spacing: 0.02em;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

/* ---------- Reading status ---------- */

.status-line {
  font-size: 0.72rem;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.status-read {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.12rem 0.55rem;
  border-radius: 999px;
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--accent);
}

.status-unread {
  color: var(--text-faint);
}

/* The bar IS the percentage: fixed-width track, fill = 0–100%. */
.progress-track {
  flex: 0 0 5rem;
  width: 5rem;
  height: 4px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.progress-label {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
}

/* ---------- Category lanes (opt-in grouped view) ---------- */

.lane {
  margin-top: 2rem;
}

.lane-header {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font: inherit;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 0 0.1rem 0.55rem;
  cursor: pointer;
  text-align: left;
}

.lane-header:hover,
.lane-header:focus-visible {
  color: var(--accent);
}

.lane-chevron {
  font-size: 0.72rem;
  transition: transform 0.15s ease;
}

.lane.collapsed .lane-chevron {
  transform: rotate(-90deg);
}

.lane-count {
  font-weight: 400;
  color: var(--text-faint);
}

.lane .book-grid {
  margin-top: 1rem;
}

.lane.collapsed .book-grid {
  display: none;
}

/* ---------- Detail modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(12, 10, 8, 0.55);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 3.5rem 1.5rem;
  z-index: 100;
  overflow-y: auto;
}

.modal-backdrop[hidden] {
  display: none;
}

/* The panel is focused programmatically on open (to catch arrow keys);
   a focus ring there is meaningless noise. */
.modal:focus, .modal:focus-visible { outline: none; }

.modal {
  position: relative;
  background-color: var(--bg);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.35);
  width: min(1060px, 100%);
  max-height: calc(100vh - 6rem);
  overflow-y: auto;
  padding: 2.25rem 2.5rem 2.5rem;
}

/* Same idiom as the header's "[ESC] back home" line — a quiet text
   affordance instead of a floating × button. */
.modal-close {
  position: sticky;
  top: 0;
  float: right;
  margin: -0.5rem -0.5rem 0 0;
  padding: 0.2rem 0.4rem;
  font: inherit;
  font-size: 0.78rem;
  border: none;
  background: none;
  color: var(--text-faint);
  cursor: pointer;
  z-index: 2;
}

.modal-close .key-hint {
  color: var(--accent);
  font-weight: 700;
}

.modal-close:hover {
  color: var(--accent);
}

.detail-header {
  display: flex;
  gap: 2.5rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  align-items: flex-start;
}

.detail-cover {
  position: relative;
  z-index: 4;
  width: 220px;
  flex: 0 0 220px;
  aspect-ratio: 2 / 3;
  border-radius: 8px;
  overflow: hidden;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.35);
}

.detail-cover .cover-img {
  object-fit: cover;
}

.detail-cover .cover-placeholder {
  font-size: 1.15rem;
}

.detail-info {
  flex: 1 1 320px;
  min-width: 0;
  padding-top: 0.4rem;
}

.detail-title {
  font-size: 1.45rem;
  font-weight: 700;
  margin: 0 0 0.4rem;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.detail-author {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin: 0 0 1.1rem;
}

.detail-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-faint);
  margin-top: 0.6rem;
}
.badge-link {
  text-decoration: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.badge-link:hover { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Description (backcover text) ---------- */

.detail-description {
  margin-bottom: 2rem;
  max-width: 68ch;
}

.description-body {
  font-size: 0.9rem;
  line-height: 1.65;
  color: var(--text-muted);
}

.description-body p {
  margin: 0 0 0.7em;
}

.description-body.clamped {
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.description-toggle {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  border: none;
  background: none;
  color: var(--accent);
  padding: 0.25rem 0;
  cursor: pointer;
}

/* ---------- Annotations ---------- */

.annotations-heading {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  margin: 0 0 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.annotations-count {
  font-weight: 400;
  margin-left: 0.3rem;
}

/* Cards in responsive columns; column layout packs variable-height
   highlight cards better than a row grid. */
.annotation-grid {
  columns: 3 280px;
  column-gap: 1.1rem;
}

.annotation-card {
  break-inside: avoid;
  padding: 0.9rem 1rem 0.75rem;
  margin: 0 0 1.1rem;
}

.annotation-text {
  font-size: 0.82rem;
  line-height: 1.7;
  margin: 0 0 0.5rem;
  color: var(--text);
}

.annotation-note {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 0.3rem 0 0.5rem;
  font-style: italic;
}

.annotation-meta {
  font-size: 0.72rem;
  color: var(--text-faint);
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem;
}

.annotation-meta .meta-sep {
  opacity: 0.6;
}

.annotation-source {
  font-weight: 600;
  color: var(--text-muted);
}

.annotation-loc {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.annotation-type-note .annotation-text {
  font-size: 0.9rem;
  font-style: italic;
}

.no-highlights {
  color: var(--text-muted);
  font-size: 0.9rem;
  padding: 1.5rem 0;
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .site-header {
    padding: 1.5rem 1.25rem 0.5rem;
  }
  main {
    padding: 0 1.25rem 3rem;
  }
  .masthead {
    align-items: flex-start;
  }
  .controls {
    width: 100%;
  }
  .search-input {
    min-width: 0;
    flex: 1 1 100%;
  }
  .sync-status {
    margin-left: 0;
    flex-basis: 100%;
  }
  .modal-backdrop {
    padding: 1rem 0.5rem;
  }
  .modal {
    padding: 1.5rem 1.25rem 1.75rem;
    max-height: calc(100vh - 2rem);
  }
  .detail-header {
    gap: 1.5rem;
  }
  .detail-cover {
    width: 140px;
    flex-basis: 140px;
  }
  .detail-title {
    font-size: 1.5rem;
  }
}

/* =====================================================================
   Terminal design layer
   Monospace chrome, ASCII banner, CRT scanlines, dashed dividers.
   ===================================================================== */

/* Terminal layer overrides — body inherits var(--mono) from theme.css,
   so only size/weight adjustments belong here, NOT font-family. Elements
   that need a different family (annotation-text → serif) set it above. */
.book-title { font-size: 0.75rem; font-weight: 700; letter-spacing: -0.01em; line-height: 1.35; }
.book-author { font-size: 0.68rem; }
.counts-line { font-variant-numeric: tabular-nums; }

/* --- ASCII banner (base from data-page.css, width formula is ours) --- */
.ascii-banner {
  /* 44 monospace chars wide (~26.5em at 0.6em/char): scale with the
     viewport on narrow screens so the full title fits, cap at 16px. */
  font-size: min(16px, calc((100vw - 2.5rem) / 26.5));
}
.banner-link { display: inline-block; }

/* CRT scanline overlay comes from theme.css; surface lifting from
   data-page.css. Bookshelf extras: */
.cover-wrap { z-index: 12; }
/* search/sort carry their own background lines via data-page.css */
.controls { position: relative; z-index: 11; }

/* --- Book cards --- */
/* All cards carry .crt-heavy (scanlines behind text, text reads clean). */
.book-card {
  border: 1px solid transparent;
}
.book-card:hover,
.book-card:focus-visible {
  transform: none;
}
.book-card:hover .book-title,
.book-card:focus-visible .book-title { color: var(--text); }

.book-card.in-progress {
  border: 1px solid var(--border);
}
.book-card.in-progress:hover,
.book-card.in-progress:focus-visible {
  border-color: var(--accent);
  background-color: var(--accent-soft);
}

/* --- Dashed ASCII dividers (toolbar divider from data-page.css) --- */
.lane-header { border-bottom: 1px dashed var(--border); }
.annotations-heading { border-bottom: 1px dashed var(--border); }
.lane-chevron { display: none; }

/* --- Detail modal --- */
/* Modal sits above body::after (backdrop z-index 100), so it needs its
   own scanline overlay to match the page-level CRT look. */
.modal::after {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.22) 0 1px, transparent 1px 3px);
}
.modal-close { z-index: 2; }



.search-input:focus {
  outline: none;
  border-color: var(--border);
}
/* Mouse focus stays quiet (rule above), but keyboard focus must be
   visible: Tab into the search box lights the accent border. */
.search-input:focus-visible {
  border-color: var(--accent);
}
/* Masthead controls (search + sort-select) need a fixed height because
   they sit in .controls (not .toolbar) where no tab-bar sets the row. */
.controls .search-input,
.controls .sort-select {
  height: 2.2rem;
  padding-top: 0;
  padding-bottom: 0;
}

/* --- Cover images: edge-to-edge fill --- */
.cover-img { object-fit: cover; }

/* --- Navigation links --- */
.home-link { color: inherit; }
.home-link:hover { color: var(--accent); }
