/* ══════════════════════════════════════════════════════════
   THE STACK — ebook catalogue page
   Loads AFTER style.css and reuses its tokens (--c-*, --r-*,
   --g-brand, --t-base). Adds no new tokens and no new fonts.

   Every surface paints an explicit background: the live site
   currently inherits a dark body from a legacy stylesheet, and
   these rules must render identically with or without it.

   1. Page shell
   2. Hero
   3. Layer list
   4. Cover plate
   5. Detail dialog
   6. Toast
   7. Responsive
══════════════════════════════════════════════════════════ */

/* ── 1. PAGE SHELL ──────────────────────────────────────── */
.stack-page {
  background: var(--c-bg);
  color: var(--c-text);
}

.stack-main {
  background: var(--c-bg);
}

/* ── 2. HERO ────────────────────────────────────────────── */
.stack-hero {
  background: var(--g-brand);
  color: #fff;
  padding: 140px 0 72px;
}

.stack-hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 260px);
  gap: 48px;
  align-items: end;
}

.stack-hero-eyebrow {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .72);
  margin-bottom: 14px;
}

.stack-hero h1 {
  font-size: clamp(40px, 7vw, 76px);
  font-weight: 800;
  letter-spacing: -.03em;
  line-height: 1.02;
  color: #fff;
  margin: 0 0 18px;
  text-wrap: balance;
}

.stack-hero-rule {
  height: 2px;
  width: 100%;
  background: linear-gradient(90deg, rgba(255, 255, 255, .85), rgba(255, 255, 255, 0));
  margin-bottom: 20px;
}

.stack-hero-thesis {
  font-size: 18px;
  line-height: 1.6;
  color: rgba(255, 255, 255, .88);
  max-width: 36ch;
  margin: 0;
}

.stack-figs {
  display: grid;
  gap: 18px;
}

.stack-fig {
  display: grid;
  gap: 2px;
  border-left: 2px solid rgba(255, 255, 255, .55);
  padding-left: 14px;
}

.stack-fig-n {
  font-size: 22px;
  font-weight: 700;
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.stack-fig-l {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .65);
}

/* ── 3. LAYER LIST ──────────────────────────────────────── */
.stack-section {
  background: var(--c-bg);
  padding: 72px 0 96px;
}

.stack-section-head {
  margin-bottom: 28px;
}

.stack-section-head h2 {
  font-size: clamp(26px, 3.4vw, 38px);
  font-weight: 800;
  letter-spacing: -.025em;
  color: var(--c-text);
  margin: 0;
}

.stack-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 18px;
}

.layer {
  position: relative;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: transform var(--t-base), box-shadow var(--t-base), border-color var(--t-base);
}

.layer::before {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 4px;
  background: var(--g-brand);
  transition: width var(--t-base);
}

.layer:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--c-border-h);
}

.layer:hover::before { width: 7px; }

.layer-inert {
  background: var(--c-bg2);
  border-style: dashed;
  box-shadow: none;
}

.layer-inert::before { background: var(--c-border); }

.layer-inner {
  display: grid;
  grid-template-columns: 40px 104px minmax(0, 1fr) auto;
  gap: 26px;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 24px 28px 24px 20px;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
}

button.layer-inner { cursor: pointer; }

.layer-idx {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: .08em;
  color: var(--c-muted);
  font-variant-numeric: tabular-nums;
  align-self: start;
  padding-top: 4px;
}

.layer-body {
  display: grid;
  gap: 8px;
  min-width: 0;
}

.layer-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--c-text);
}

.layer-thesis {
  font-size: 15px;
  line-height: 1.55;
  color: var(--c-text2);
  max-width: 62ch;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-top: 2px;
}

.chip {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .07em;
  text-transform: uppercase;
  color: var(--c-text2);
  background: var(--c-bg);
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  padding: 4px 9px;
}

.chip-hot {
  color: var(--c-navy);
  border-color: var(--c-border-h);
  background: var(--c-surface2);
}

.layer-buy {
  display: grid;
  gap: 10px;
  justify-items: end;
  align-content: center;
}

.layer-price {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: -.02em;
  color: var(--c-navy);
  font-variant-numeric: tabular-nums;
  line-height: 1.15;
}

.layer-price small {
  display: block;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--c-muted);
  margin-top: 2px;
}

.layer-cta { pointer-events: none; }

.layer-soon {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--c-muted);
}

/* ── 4. COVER PLATE ─────────────────────────────────────
   Typographic stand-in — no cover art exists yet. Replacing
   the inner spans with <img> keeps the layout identical.
─────────────────────────────────────────────────────── */
.plate {
  aspect-ratio: 2 / 3;
  background: var(--g-brand);
  border-radius: var(--r-sm);
  padding: 12px 11px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.plate-title {
  font-size: 12px;
  font-weight: 800;
  line-height: 1.12;
  letter-spacing: -.01em;
  color: #fff;
}

.plate-foot {
  font-size: 7px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .7);
}

.layer-inert .plate { background: var(--c-muted); }

/* ── 5. DETAIL DIALOG ───────────────────────────────────── */
.book-sheet {
  width: min(1000px, calc(100vw - 32px));
  max-width: none;
  max-height: min(88vh, 860px);
  /* style.css resets `* { margin: 0 }`, which kills the UA's
     `margin: auto` on dialog:modal and pins it to the top-left. */
  margin: auto;
  padding: 0;
  border: 1px solid var(--c-border);
  border-radius: var(--r-xl);
  background: var(--c-surface);
  color: var(--c-text);
  box-shadow: 0 40px 90px -30px rgba(26, 35, 64, .5);
  overflow: hidden;
}

.book-sheet::backdrop {
  background: rgba(26, 35, 64, .58);
  backdrop-filter: blur(3px);
}

.sheet {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  max-height: inherit;
  height: min(88vh, 860px);
}

.sheet-top {
  display: grid;
  grid-template-columns: 76px minmax(0, 1fr) auto;
  gap: 22px;
  align-items: start;
  padding: 24px 28px;
  border-bottom: 1px solid var(--c-border);
  background: var(--c-bg2);
}

.sheet-head h3 {
  font-size: clamp(22px, 2.8vw, 32px);
  font-weight: 800;
  letter-spacing: -.025em;
  color: var(--c-text);
  margin: 0 0 6px;
}

.sheet-by {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--c-muted);
  margin: 0;
}

.sheet-close {
  font-size: 16px;
  line-height: 1;
  padding: 9px 12px;
  border: 1px solid var(--c-border);
  border-radius: var(--r-sm);
  background: var(--c-surface);
  color: var(--c-text2);
  cursor: pointer;
  transition: all var(--t-fast);
}

.sheet-close:hover {
  border-color: var(--c-border-h);
  color: var(--c-navy);
}

.sheet-body {
  overflow-y: auto;
  padding: 28px;
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr);
  gap: 44px;
  align-items: start;
  background: var(--c-surface);
}

.sheet-col {
  display: grid;
  gap: 30px;
}

.sheet-sec {
  display: grid;
  gap: 12px;
}

.sheet-sec h4 {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--c-navy);
  margin: 0;
}

.sheet-sec p {
  font-size: 15px;
  line-height: 1.68;
  color: var(--c-text2);
  max-width: 64ch;
  margin: 0;
}

.gets {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 9px;
}

.gets li {
  position: relative;
  padding-left: 22px;
  font-size: 15px;
  line-height: 1.55;
  color: var(--c-text2);
}

.gets li::before {
  content: "+";
  position: absolute;
  left: 0;
  font-weight: 700;
  color: var(--c-sky);
}

.stance {
  border-left: 2px solid var(--c-border-h);
  padding-left: 14px;
  font-size: 14px;
}

.sheet-toc {
  gap: 18px;
}

.toc-part {
  display: grid;
  gap: 8px;
}

.toc-part h5 {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--c-muted);
  border-bottom: 1px solid var(--c-border);
  padding-bottom: 7px;
  margin: 0;
}

.toc-part ol {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 6px;
}

.toc-part li {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 8px;
  font-size: 15px;
  line-height: 1.45;
  color: var(--c-text);
}

.toc-part li b {
  font-size: 12px;
  font-weight: 600;
  color: var(--c-sky);
  font-variant-numeric: tabular-nums;
  padding-top: 3px;
}

.sheet-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  flex-wrap: wrap;
  padding: 18px 28px;
  border-top: 1px solid var(--c-border);
  background: var(--c-bg2);
}

.foot-price {
  display: flex;
  align-items: baseline;
  gap: 12px;
}

.was {
  font-size: 15px;
  color: var(--c-muted);
  text-decoration: line-through;
  font-variant-numeric: tabular-nums;
}

.foot-pay {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.secure {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .09em;
  text-transform: uppercase;
  color: var(--c-muted);
}

/* ── 6. TOAST ───────────────────────────────────────────── */
.stack-toast {
  position: fixed;
  left: 50%;
  bottom: 26px;
  transform: translateX(-50%) translateY(12px);
  max-width: min(460px, calc(100vw - 32px));
  background: var(--c-text);
  color: #fff;
  font-size: 14px;
  line-height: 1.5;
  text-align: center;
  padding: 13px 18px;
  border-radius: var(--r-md);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--t-base), transform var(--t-base);
  z-index: 999;
}

.stack-toast.is-on {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── 7. RESPONSIVE ──────────────────────────────────────── */
@media (max-width: 900px) {
  .stack-hero-grid { grid-template-columns: 1fr; align-items: start; gap: 34px; }
  .stack-figs { grid-template-columns: repeat(3, auto); justify-content: start; gap: 26px; }
  .sheet-body { grid-template-columns: 1fr; gap: 30px; }
}

@media (max-width: 768px) {
  .stack-hero { padding: 116px 0 56px; }
  .stack-section { padding: 56px 0 72px; }

  .layer-inner {
    grid-template-columns: 40px minmax(0, 1fr);
    grid-template-areas:
      "idx plate"
      "body body"
      "buy  buy";
    gap: 16px;
    align-items: start;
    padding: 20px;
  }
  .layer-idx  { grid-area: idx; }
  .plate      { grid-area: plate; width: 92px; }
  .layer-body { grid-area: body; }
  .layer-buy  { grid-area: buy; justify-items: stretch; }
  .layer-cta  { justify-content: center; }

  .sheet-top { grid-template-columns: minmax(0, 1fr) auto; gap: 16px; padding: 20px; }
  .sheet-top .plate { display: none; }
  .sheet-body { padding: 20px; }
  .sheet-foot { padding: 16px 20px; }
  .foot-pay { width: 100%; justify-content: space-between; }
}

@media (max-width: 480px) {
  .book-sheet { width: 100vw; max-height: 100vh; border-radius: 0; border: 0; }
  .sheet { height: 100vh; }
  .stack-figs { grid-template-columns: 1fr; gap: 16px; }
}

@media (prefers-reduced-motion: reduce) {
  .layer, .stack-toast { transition: none; }
  .layer:hover { transform: none; }
}

/* ── 8. WORDPRESS ADDITIONS ─────────────────────────────
   Real cover art (Featured image) replaces the typographic
   plate without changing the layout box.
─────────────────────────────────────────────────────── */
.plate-img {
  display: block;
  padding: 0;
  background: var(--c-surface2);
}

.plate-img img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  border-radius: inherit;
}

.stack-empty {
  color: var(--c-text2);
  font-size: 16px;
  background: var(--c-bg2);
  border: 1px dashed var(--c-border);
  border-radius: var(--r-lg);
  padding: 28px;
}

/* ── 9. TOOLBAR: SEARCH + VIEW TOGGLE ───────────────
   Injected by stack.js, so nothing renders without JS.
────────────────────────────────────────────────── */
.stack-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 22px;
}

.stack-search { position: relative; flex: 1 1 260px; max-width: 420px; }

.stack-search-icon {
  position: absolute;
  left: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 17px;
  height: 17px;
  color: var(--c-muted);
  pointer-events: none;
}

.stack-search input {
  width: 100%;
  font: inherit;
  font-size: 15px;
  color: var(--c-text);
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  padding: 11px 14px 11px 40px;
  transition: border-color var(--t-base), box-shadow var(--t-base);
  -webkit-appearance: none;
  appearance: none;
}

.stack-search input::placeholder { color: var(--c-muted); }

.stack-search input:focus {
  outline: none;
  border-color: var(--c-border-h);
  box-shadow: 0 0 0 3px rgba(33, 156, 216, .14);
}

.stack-views {
  display: inline-flex;
  border: 1px solid var(--c-border);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--c-surface);
}

.stack-view-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--c-text2);
  background: none;
  border: 0;
  padding: 10px 15px;
  cursor: pointer;
  transition: background var(--t-fast), color var(--t-fast);
}

.stack-view-btn + .stack-view-btn { border-left: 1px solid var(--c-border); }
.stack-view-btn svg { width: 15px; height: 15px; fill: currentColor; }
.stack-view-btn:hover { color: var(--c-navy); }
.stack-view-btn[aria-pressed="true"] { background: var(--g-brand); color: #fff; }

.stack-noresults {
  color: var(--c-text2);
  font-size: 16px;
  background: var(--c-bg2);
  border: 1px dashed var(--c-border);
  border-radius: var(--r-lg);
  padding: 26px;
  text-align: center;
}

.screen-reader-text {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(1px, 1px, 1px, 1px);
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ── 10. GRID VIEW (default) ───────────────────────
   Same markup as the list; only the layout changes.
────────────────────────────────────────────────── */
.stack-list.is-grid {
  grid-template-columns: repeat(auto-fill, minmax(232px, 1fr));
  gap: 24px;
  align-items: stretch;
}

.stack-list.is-grid .layer::before { display: none; }

.stack-list.is-grid .layer-inner {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 14px;
  padding: 16px;
  height: 100%;
}

.stack-list.is-grid .layer-idx { display: none; }

.stack-list.is-grid .plate {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: var(--r-md);
}

.stack-list.is-grid .layer-body { gap: 6px; flex: 1 1 auto; }
.stack-list.is-grid .layer-title { font-size: 17px; line-height: 1.25; }

.stack-list.is-grid .layer-thesis {
  font-size: 13.5px;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.stack-list.is-grid .chip { display: none; }
.stack-list.is-grid .chip-hot { display: inline-block; }

/* Price on the left, "View inside" on the right, one row. */
.stack-list.is-grid .layer-buy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-top: 1px solid var(--c-border);
  padding-top: 12px;
}

.stack-list.is-grid .layer-price { font-size: 20px; }

.stack-list.is-grid .layer-cta {
  width: auto;
  flex: 0 0 auto;
  padding: 9px 14px;
  font-size: 13px;
}

/* A "coming soon" card has no price, so centre its label instead. */
.stack-list.is-grid .layer-soon { flex: 1 1 auto; text-align: center; }

@media (max-width: 560px) {
  .stack-list.is-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 16px; }
  .stack-list.is-grid .layer-inner { padding: 12px; gap: 11px; }
  .stack-list.is-grid .layer-title { font-size: 15px; }
  .stack-list.is-grid .layer-thesis { display: none; }

  /* Two-up cards are ~170px wide here — price and button cannot sit
     side by side without the button spilling past the card edge, so
     stack them. They stay on one row from 560px up. */
  .stack-list.is-grid .layer-buy { flex-direction: column; align-items: stretch; gap: 8px; }
  .stack-list.is-grid .layer-cta { width: 100%; justify-content: center; }
  .stack-toolbar { gap: 12px; }
  .stack-search { max-width: none; }
  .stack-views { width: 100%; }
  .stack-view-btn { flex: 1; justify-content: center; }
}
