/* BookIt search page. Warm paper palette, light and dark. */
:root {
  --bg: #f6f2ea;
  --surface: #fffdf9;
  --surface-2: #efe8dc;
  --ink: #1f1b16;
  --muted: #6b6257;
  --line: #e0d8ca;
  --accent: #b4532a;
  --accent-hover: #983f1b;
  --accent-ink: #ffffff;
  --focus: #2f6fdf;
  --shadow: 0 1px 2px rgb(31 27 22 / 6%), 0 6px 20px rgb(31 27 22 / 7%);
  --radius: 12px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141210;
    --surface: #1d1a17;
    --surface-2: #29251f;
    --ink: #ede6db;
    --muted: #a69c8e;
    --line: #35302a;
    --accent: #e48a5c;
    --accent-hover: #f0a079;
    --accent-ink: #1a120d;
    --focus: #7aa7ff;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 8px 24px rgb(0 0 0 / 30%);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
}
img { display: block; max-width: 100%; }
a { color: var(--accent); }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; border-radius: 8px; z-index: 10; }
.skip:focus { left: 8px; }
.muted { color: var(--muted); }

.wrap { width: 100%; max-width: 1200px; margin: 0 auto; padding: 0 16px; }
@media (min-width: 720px) { .wrap { padding: 0 24px; } }

/* ---- Header & hero ---- */
.site-header { padding: 14px 0 0; }
.header-row { display: flex; align-items: center; }
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink); font: 700 20px/1 var(--serif); letter-spacing: .2px; }
.brand img { border-radius: 7px; }

.hero { padding-top: clamp(28px, 7vw, 72px); padding-bottom: 8px; text-align: center; }
.hero h1 { font: 700 clamp(30px, 6vw, 52px)/1.08 var(--serif); margin: 0 0 12px; letter-spacing: -.5px; text-wrap: balance; }
.lede { color: var(--muted); margin: 0 auto 26px; max-width: 34em; font-size: clamp(15px, 2.2vw, 18px); text-wrap: pretty; }

.search {
  display: flex; gap: 8px; max-width: 760px; margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px;
  padding: 6px; box-shadow: var(--shadow);
}
.search:focus-within { border-color: var(--accent); }
.search-field { flex: 1; display: flex; align-items: center; min-width: 0; }
.search-icon { display: grid; place-items: center; width: 40px; color: var(--muted); flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; background: transparent; outline: none;
  font-size: 18px; padding: 10px 6px 10px 0;
}
.search input::-webkit-search-cancel-button { cursor: pointer; }
.lang select {
  height: 100%; border: 0; border-left: 1px solid var(--line); background: transparent;
  padding: 0 10px; color: var(--muted); cursor: pointer; max-width: 150px;
}
.search-go { padding-inline: 22px; border-radius: 11px; }
@media (max-width: 599px) {
  .search { flex-wrap: wrap; gap: 6px; }
  .search-field { flex-basis: 100%; border-bottom: 1px solid var(--line); }
  .lang { flex: 1; display: flex; }
  .lang select { border-left: 0; width: 100%; max-width: none; height: 42px; padding-left: 10px; }
  .search-go { height: 42px; }
}

.chips { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin: 18px auto 0; max-width: 820px; }
.chip {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 6px 14px; font-size: 14px; cursor: pointer;
  transition: background .15s, border-color .15s;
}
.chip:hover { border-color: var(--accent); }
.chip[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.chip-sm { font-size: 13px; padding: 4px 11px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 16px; border-radius: 10px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  font-weight: 600; font-size: 15px; text-decoration: none; cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: var(--accent-ink); }
.btn-sm { min-height: 36px; padding: 0 10px; font-size: 14px; border-radius: 9px; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn {
  display: inline-grid; place-items: center; width: 40px; height: 40px; border-radius: 10px;
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }
.linkish { border: 0; background: none; color: var(--accent); cursor: pointer; font-size: 14px; padding: 4px; }

/* ---- Continue reading ---- */
.shelf-section { margin-top: 36px; }
.shelf-section h2, .results-head h2 { font: 700 22px/1.2 var(--serif); margin: 0; }
.shelf {
  display: flex; gap: 12px; overflow-x: auto; padding: 12px 2px 6px; margin-top: 2px;
  scroll-snap-type: x mandatory; scrollbar-width: thin;
}
.mini {
  position: relative; flex: none; width: 280px; scroll-snap-align: start;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
}
.mini-link { display: flex; gap: 12px; padding: 10px; color: inherit; text-decoration: none; }
.mini-cover { width: 56px; flex: none; border-radius: 6px; }
.mini-cover .ph-title { font-size: 8px; }
.mini-cover .ph-author { display: none; }
.mini-text { display: flex; flex-direction: column; min-width: 0; gap: 2px; padding-right: 22px; }
.mini-text strong { font: 600 15px/1.25 var(--serif); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.mini-author { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.meter { display: block; height: 4px; background: var(--surface-2); border-radius: 4px; margin-top: auto; overflow: hidden; }
.meter span { display: block; height: 100%; background: var(--accent); }
.mini-pct { font-size: 12px; color: var(--muted); }
.mini-remove { position: absolute; top: 4px; right: 4px; width: 30px; height: 30px; }
.mini-remove svg { width: 16px; height: 16px; }

/* ---- Results ---- */
.results-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 40px 0 16px; }
.grid {
  display: grid; gap: 24px 16px;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
}
@media (min-width: 720px) { .grid { grid-template-columns: repeat(auto-fill, minmax(172px, 1fr)); gap: 32px 22px; } }

.card { display: flex; flex-direction: column; min-width: 0; }
.cover {
  position: relative; display: block; width: 100%; aspect-ratio: 2 / 3; padding: 0; border: 0;
  border-radius: 8px; overflow: hidden; background: var(--surface-2); cursor: pointer;
  box-shadow: 0 1px 2px rgb(0 0 0 / 12%), 0 6px 16px rgb(31 27 22 / 12%);
}
.cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.card .cover { transition: transform .18s ease, box-shadow .18s ease; }
.card .cover:hover { transform: translateY(-3px); box-shadow: 0 2px 4px rgb(0 0 0 / 12%), 0 14px 28px rgb(31 27 22 / 18%); }

.ph {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between;
  padding: 14% 12%; text-align: left; color: #fff8ee;
  background:
    linear-gradient(90deg, rgb(0 0 0 / 22%) 0 5%, rgb(255 255 255 / 8%) 5% 6.5%, transparent 6.5%),
    linear-gradient(160deg, hsl(var(--h) 38% 40%), hsl(calc(var(--h) + 25) 42% 24%));
}
.ph-title { font: 600 clamp(12px, 1.5vw, 16px)/1.2 var(--serif); display: -webkit-box; -webkit-line-clamp: 6; -webkit-box-orient: vertical; overflow: hidden; }
.ph-author { font-size: 11px; opacity: .85; letter-spacing: .3px; text-transform: uppercase; }

.card-body { padding: 10px 2px 0; flex: 1; }
.card-title { margin: 0; font: 600 16px/1.25 var(--serif); }
.card-title button {
  all: unset; cursor: pointer; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.card-title button:hover { color: var(--accent); }
.card-title button:focus-visible { outline: 2px solid var(--focus); }
.card-author { margin: 3px 0 0; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-meta { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.card-actions { display: flex; gap: 6px; margin-top: 10px; }
.card-actions .btn-primary { flex: 1; }

.skeleton .cover, .sk-line {
  background: linear-gradient(90deg, var(--surface-2) 0 40%, var(--line) 50%, var(--surface-2) 60% 100%);
  background-size: 300% 100%; animation: shimmer 1.3s linear infinite; box-shadow: none; cursor: default;
}
.sk-line { height: 12px; border-radius: 6px; margin-top: 12px; }
.sk-line.short { width: 60%; margin-top: 8px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: 0 0; } }
@media (prefers-reduced-motion: reduce) {
  .skeleton .cover, .sk-line { animation: none; }
  .card .cover { transition: none; }
}

.status { text-align: center; color: var(--muted); padding: 8px 0; }
.status p { margin: 24px auto 12px; max-width: 32em; }
.more-row { display: flex; justify-content: center; margin: 28px 0 8px; }

/* ---- Details sheet ---- */
.sheet {
  border: 0; padding: 0; background: var(--surface); color: var(--ink);
  width: min(760px, calc(100vw - 32px)); max-height: calc(100dvh - 48px);
  border-radius: 18px; box-shadow: 0 24px 80px rgb(0 0 0 / 35%);
}
.sheet::backdrop { background: rgb(20 16 12 / 55%); backdrop-filter: blur(2px); }
.sheet[open] { animation: rise .2s ease-out; }
@keyframes rise { from { transform: translateY(12px); opacity: 0; } }
.sheet-inner { position: relative; display: grid; grid-template-columns: 200px 1fr; gap: 24px; padding: 28px; }
.sheet-close { position: absolute; top: 10px; right: 10px; }
.sheet-cover { cursor: default; }
.sheet-body { min-width: 0; }
.sheet-body h2 { font: 700 26px/1.15 var(--serif); margin: 0 36px 6px 0; text-wrap: balance; }
.sheet-author { margin: 0; font-size: 17px; }
.sheet-facts { margin: 6px 0 0; color: var(--muted); font-size: 14px; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; margin: 20px 0 4px; }
.sheet-summary { margin: 18px 0 0; line-height: 1.6; color: var(--ink); }
.sheet-subjects { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 18px; }
.sheet-source { margin: 18px 0 0; font-size: 14px; }
.sheet-source a { display: inline-flex; align-items: center; gap: 4px; }
@media (max-width: 599px) {
  .sheet {
    width: 100vw; max-width: none; max-height: 92dvh; margin: auto 0 0; border-radius: 18px 18px 0 0;
  }
  .sheet-inner { grid-template-columns: 96px 1fr; gap: 2px 16px; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); }
  .sheet-body h2 { font-size: 21px; }
  .sheet-actions, .sheet-summary, .sheet-subjects, .sheet-source { grid-column: 1 / -1; }
  .sheet-body { display: contents; }
  .sheet-body > h2, .sheet-body > .sheet-author, .sheet-body > .sheet-facts { grid-column: 2; }
  .sheet-cover { grid-row: 1 / span 3; align-self: start; }
  .sheet-actions .btn { flex: 1; }
  .sheet-actions .btn-primary { flex: 1 1 100%; }
}

/* ---- Footer & toast ---- */
.site-footer { margin-top: 64px; padding-top: 20px; padding-bottom: calc(32px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); color: var(--muted); font-size: 13px; }
.site-footer p { max-width: 60em; margin: 0; }
.toast {
  position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); z-index: 50;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  box-shadow: var(--shadow); transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
