/* ==========================================================================
   Crease — Books page. Browse the free classics; each opens a native <dialog>.
   ========================================================================== */

/* Keep the layout still when the page scroll is locked behind the dialog. */
html { scrollbar-gutter: stable; }
html.bk-lock { overflow: hidden; }

/* ---------- Hero ---------- */
.bk-hero { padding: clamp(48px, 7vw, 92px) 0 clamp(28px, 4vw, 48px); }
.bk-hero .lead { margin-top: 16px; max-width: 34ch; }

/* ---------- Toolbar ---------- */
.bk-toolbar {
  position: sticky; top: var(--nav-h); z-index: 40;
  background: rgb(244 241 234 / 0.86);
  -webkit-backdrop-filter: saturate(1.4) blur(16px);
  backdrop-filter: saturate(1.4) blur(16px);
  border-bottom: 1px solid transparent;
  transition: border-color 0.3s;
}
.bk-toolbar.is-stuck { border-bottom-color: var(--line); }
.bk-toolbar-inner {
  display: grid; grid-template-columns: minmax(220px, 300px) minmax(0, 1fr) auto;
  align-items: center; gap: 20px; padding-block: 12px;
}

.bk-search { position: relative; }
.bk-search svg {
  position: absolute; left: 18px; top: 50%; transform: translateY(-50%);
  color: var(--muted); pointer-events: none;
}
.bk-search .field { min-height: 48px; padding-left: 46px; -webkit-appearance: none; appearance: none; }
.bk-search .field::-webkit-search-decoration { -webkit-appearance: none; }

.bk-count {
  font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums;
  white-space: nowrap; min-width: 76px; text-align: right;
}

/* Genre chips (rendered into every [data-chips] host) */
.bk-chips { position: relative; min-width: 0; }
.bk-chips-row {
  --fl: 0px; --fr: 0px;
  display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none;
  padding: 4px 3px;
  -webkit-mask-image: linear-gradient(to right, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%);
  mask-image: linear-gradient(to right, transparent 0, #000 var(--fl), #000 calc(100% - var(--fr)), transparent 100%);
}
.bk-chips-row::-webkit-scrollbar { display: none; }
.bk-chips.can-left .bk-chips-row { --fl: 36px; }
.bk-chips.can-right .bk-chips-row { --fr: 36px; }
.bk-chip {
  flex: none; min-height: 44px; padding: 0 18px;
  border: 1px solid var(--line-2); border-radius: var(--pill);
  background: transparent; color: var(--ink-2);
  font-size: 15px; font-weight: 500; line-height: 1; white-space: nowrap;
  transition: background-color 0.2s, border-color 0.2s, color 0.2s;
}
.bk-chip:hover { border-color: var(--ink); color: var(--ink); }
.bk-chip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: var(--paper); font-weight: 600; }

.bk-arrow {
  position: absolute; top: 50%; z-index: 2; width: 36px; height: 36px; margin-top: -18px;
  display: none; place-items: center; padding: 0; border: 0; border-radius: 50%;
  background: var(--ink); color: var(--paper); box-shadow: var(--shadow-sm);
  transition: transform 0.2s var(--ease);
}
.bk-arrow:hover { transform: scale(1.06); }
.bk-arrow-prev { left: 0; }
.bk-arrow-next { right: 0; }
.bk-chips.can-left .bk-arrow-prev, .bk-chips.can-right .bk-arrow-next { display: grid; }
@media (hover: none) { .bk-chips .bk-arrow { display: none !important; } }

/* On small screens only the search row stays pinned; chips scroll with the page. */
.bk-chips-flow-wrap { display: none; }
@media (max-width: 760px) {
  .bk-toolbar-inner { grid-template-columns: minmax(0, 1fr) auto; gap: 12px; padding-block: 10px; }
  .bk-chips-bar { display: none; }
  .bk-chips-flow-wrap { display: block; padding-top: 12px; }
  .bk-chips-flow .bk-chips-row { margin-inline: calc(var(--gutter) * -1); padding-inline: var(--gutter); }
  .bk-chips-flow { margin-inline: 0; }
  .bk-chips-flow.can-left .bk-chips-row { --fl: 0px; }
  .bk-count { min-width: 0; }
}

/* ---------- Grid ---------- */
.bk-library { padding-block: clamp(24px, 3vw, 36px) clamp(80px, 10vw, 128px); min-height: 60vh; }
.bk-grid {
  list-style: none; padding: 0; margin: 0;
  /* Store-like density: 7 columns at 1280, 4 at 768, 3 at 375. */
  display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 36px 24px;
}
@media (max-width: 640px) { .bk-grid { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 26px 14px; } }

.bk-item {
  display: block; width: 100%; padding: 0; border: 0; background: none;
  color: inherit; font: inherit; text-align: left; border-radius: 10px;
  -webkit-tap-highlight-color: transparent;
}
.bk-item:focus-visible { outline-offset: 6px; border-radius: 10px; }
.bk-item .cover { transition: transform 0.35s var(--ease), box-shadow 0.35s var(--ease); }
@media (hover: hover) {
  .bk-item:hover .cover { transform: translateY(-6px); box-shadow: var(--shadow); }
}
.bk-title {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  margin-top: 14px; font-size: 15px; font-weight: 600; line-height: 1.3; letter-spacing: -0.005em;
  text-wrap: balance;
}
.bk-author {
  display: block; margin-top: 3px; font-size: 13px; line-height: 1.35; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
@media (max-width: 640px) {
  .bk-title { margin-top: 10px; font-size: 14px; }
  .bk-author { font-size: 12.5px; }
}

.bk-empty { display: grid; justify-items: center; gap: 20px; padding: 72px 0; text-align: center; }

/* ---------- Store band ---------- */
.bk-store { padding-block: clamp(80px, 11vw, 140px); }
.bk-store .lead { margin-top: 18px; }
.bk-store .beta-form { margin-top: 36px; margin-inline: auto; }
.bk-store .beta-note { text-align: center; }

/* ---------- Book dialog ---------- */
.bk-dialog {
  padding: 0; border: 0; color: var(--ink); background: var(--paper);
  width: min(900px, calc(100vw - 48px)); max-width: none; max-height: none;
  border-radius: 28px; box-shadow: var(--shadow-lg); overflow: hidden;
}
.bk-dialog::backdrop {
  background: rgb(26 27 24 / 0.52);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
}
.bk-dialog[open] { animation: bk-in 0.4s var(--ease) both; }
.bk-dialog[open]::backdrop { animation: bk-fade 0.3s ease both; }
.bk-dialog.is-closing { animation: bk-out 0.22s ease both; }
.bk-dialog.is-closing::backdrop { animation: bk-fade-out 0.22s ease both; }
@keyframes bk-in { from { opacity: 0; transform: translateY(18px) scale(0.985); } }
@keyframes bk-out { to { opacity: 0; transform: translateY(10px) scale(0.99); } }
@keyframes bk-fade { from { opacity: 0; } }
@keyframes bk-fade-out { to { opacity: 0; } }

.bk-d-close {
  position: absolute; top: 16px; right: 16px; z-index: 3;
  width: 44px; height: 44px; display: grid; place-items: center; padding: 0;
  border: 0; border-radius: 50%; background: rgb(31 30 27 / 0.07); color: var(--ink);
  transition: background-color 0.2s;
}
.bk-d-close:hover { background: rgb(31 30 27 / 0.14); }

.bk-d {
  display: grid; grid-template-columns: 300px minmax(0, 1fr); grid-template-rows: minmax(0, 1fr);
  max-height: min(700px, calc(100dvh - 48px));
}
.bk-d-media { background: var(--paper-2); display: grid; place-items: center; padding: 48px 36px; }
.bk-d-media .cover { width: 100%; max-width: 208px; border-radius: 8px; box-shadow: var(--shadow-lg); }

.bk-d-body {
  display: flex; flex-direction: column; gap: 26px; min-height: 0;
  padding: 52px 48px 40px; overflow-y: auto; overscroll-behavior: contain;
}
.bk-d-head { padding-right: 28px; }
.bk-d-title {
  margin: 0; font-size: clamp(28px, 3vw, 36px); line-height: 1.08; letter-spacing: -0.03em;
  font-weight: 700; text-wrap: balance;
}
.bk-d-meta { margin: 10px 0 0; font-size: 15px; color: var(--muted); }
.bk-d-quote { margin: 0; }
.bk-d-quote p {
  margin: 0; font-family: var(--font-book); font-style: normal; font-weight: 400;
  font-size: clamp(21px, 2.3vw, 26px); line-height: 1.4; color: var(--ink); text-wrap: pretty;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 9; overflow: hidden;
}
.bk-d-label { margin: 0 0 10px; font-size: 13px; font-weight: 600; color: var(--muted); }
.bk-d-actions { display: flex; align-items: center; gap: 8px 20px; flex-wrap: wrap; margin-top: auto; padding-top: 4px; }
.bk-d-actions .tiny { margin: 0; }

/* Phone: full-height sheet from the bottom */
@media (max-width: 720px) {
  .bk-dialog {
    width: 100%; height: calc(100dvh - 12px); margin: auto 0 0;
    border-radius: 24px 24px 0 0;
  }
  .bk-dialog[open] { animation-name: bk-sheet-in; animation-duration: 0.45s; }
  .bk-dialog.is-closing { animation-name: bk-sheet-out; animation-duration: 0.26s; }
  @keyframes bk-sheet-in { from { transform: translateY(100%); } }
  @keyframes bk-sheet-out { to { transform: translateY(100%); } }

  .bk-d-close { top: 12px; right: 12px; background: rgb(244 241 234 / 0.9); }
  .bk-d {
    display: flex; flex-direction: column; height: 100%; max-height: none;
    overflow-y: auto; overscroll-behavior: contain;
  }
  .bk-d-media { flex: none; padding: 56px 24px 24px; }
  .bk-d-media .cover { width: 120px; border-radius: 6px; box-shadow: var(--shadow); }
  .bk-d-body { flex: 1 0 auto; padding: 24px 20px 0; gap: 22px; overflow: visible; }
  .bk-d-head { padding-right: 0; }
  .bk-d-title { font-size: 28px; }
  .bk-d-quote p { font-size: 20px; line-height: 1.42; -webkit-line-clamp: 6; }
  .bk-d-actions {
    position: sticky; bottom: 0; z-index: 2; margin: auto -20px 0; padding: 14px 20px calc(14px + env(safe-area-inset-bottom));
    background: var(--paper); box-shadow: 0 -1px 0 var(--line);
  }
  .bk-d-actions .btn { flex: 1 1 100%; }
  .bk-d-actions .tiny { flex: 1 1 100%; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  .bk-dialog[open], .bk-dialog[open]::backdrop { animation: none; }
}
