/* Gutenberg Semantic Search. Palette and patterns follow gutenberg.org's own stylesheet
   (gutenbergtools/gutenbergsite, gutenberg-globals.css); rules and reasons are in web/README.md.
   Light mode only for now. Never write a color outside this block. */
:root {
  --page: #ffffff;
  --band: #eceadf;          /* PG parchment: header band, cover fallback */
  --band-line: #d9d5bf;     /* PG parchment border */
  --tint: #eef6f9;          /* PG shelf-card tint: detail panel, "Why this book" box */
  --tint-line: #dce9ee;
  --ink: #1f2428;           /* PG heading ink */
  --ink-2: #3e444d;
  --muted: #5f6368;         /* captions; 6.0:1 on white, 5.6:1 on --tint */
  --line: #e3e7ea;          /* PG hairline */
  --accent: #427e94;        /* PG teal: search button, focus ring */
  --accent-strong: #23576b; /* PG dark teal: link text, 7.9:1 on white */
  --accent-soft: #c7dde3;   /* PG pill wash: <mark>, button hover */
  --heading: #a01f13;       /* PG library red: section rules only */
  --on-accent: #ffffff;     /* text on --accent, 4.6:1 */
  --shadow: rgba(31, 36, 40, 0.12);

  --radius-card: 12px;
  --radius-input: 6px;
  --radius-button: 4px;
  --pill: 999px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;

  color-scheme: light;
  font-family: "Open Sans", Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }
html { overflow-y: scroll; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}
a { color: var(--accent-strong); text-underline-offset: 2px; }
a:hover { text-decoration-thickness: 2px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 2px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

/* ---- header band (PG parchment) ---- */
.band { background: var(--band); border-bottom: 1px solid var(--band-line); }
.band-inner {
  max-width: 1200px; margin: 0 auto; padding: var(--s3) var(--s4);
  display: flex; align-items: baseline; flex-wrap: wrap; gap: var(--s1) var(--s4);
}
.wordmark { color: var(--ink); font-size: 20px; font-weight: 700; letter-spacing: -0.01em; text-decoration: none; }
.wordmark:hover { text-decoration: underline; }
.tagline { color: var(--ink-2); font-size: 14px; }

/* ---- layout: results left, detail panel right (so wide screens don't waste the right side) ---- */
.layout {
  flex: 1; width: 100%; max-width: 1200px; margin: 0 auto;
  padding: var(--s5) var(--s4) var(--s6);
  display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--s5);
}
@media (min-width: 1024px) {
  .layout { grid-template-columns: minmax(0, 640px) minmax(0, 1fr); gap: var(--s6); }
}

/* ---- search pill (PG: input rounded left, teal button rounded right) ---- */
.search { position: relative; }
.search-pill {
  display: flex; border: 2px solid var(--accent); border-radius: var(--pill);
  background: var(--page); overflow: hidden;
}
.search-pill:focus-within { box-shadow: 0 0 0 3px var(--accent-soft); }
.search-pill input {
  flex: 1; min-width: 0; border: 0; padding: 10px 18px; font: inherit; font-size: 16px; color: var(--ink);
  background: transparent;
}
.search-pill input:focus { outline: none; }
.search-pill input::placeholder { color: var(--muted); }
.search-button {
  border: 0; background: var(--accent); color: var(--on-accent); font-weight: 700; font-size: 15px;
  padding: 0 var(--s5); cursor: pointer;
}
.search-button:hover { background: var(--accent-strong); }
.search-button:focus-visible { outline-offset: -4px; outline-color: var(--on-accent); }

.recent {
  position: absolute; z-index: 10; left: var(--s4); right: var(--s4); top: calc(100% + var(--s1));
  margin: 0; padding: var(--s1) 0; list-style: none;
  background: var(--page); border: 1px solid var(--line); border-radius: var(--radius-input);
  box-shadow: 0 8px 24px var(--shadow);
}
.recent-label { padding: var(--s1) var(--s3); font-size: 12px; color: var(--muted); }
.recent li[role="option"] { padding: 6px var(--s3); cursor: pointer; font-size: 14px; }
.recent li[role="option"][aria-selected="true"], .recent li[role="option"]:hover { background: var(--tint); }

/* ---- home guide ---- */
.guide {
  margin-top: var(--s5); padding: var(--s4) var(--s5);
  background: var(--tint); border-radius: var(--radius-card);
}
.guide-title { margin: 0 0 var(--s2); font-size: 18px; font-weight: 600; }
.guide p { margin: 0 0 var(--s3); color: var(--ink-2); }
.guide-label { font-size: 13px; color: var(--muted) !important; margin-bottom: var(--s2) !important; }
.examples { display: flex; flex-wrap: wrap; gap: var(--s2); margin-bottom: var(--s3); }
.example {
  border: 1px solid var(--accent); background: var(--page); color: var(--accent-strong);
  border-radius: var(--pill); padding: 4px 12px; font-size: 14px; cursor: pointer; min-height: 32px;
}
.example:hover { background: var(--accent-soft); }
.guide .guide-note { margin: 0; font-size: 13px; color: var(--muted); }

/* ---- status line ---- */
.status { margin-top: var(--s4); color: var(--ink-2); font-size: 14px; }
.status:empty { display: none; }
.status-box {
  padding: var(--s3) var(--s4); border: 1px solid var(--band-line); background: var(--band);
  border-radius: var(--radius-card); color: var(--ink);
}
.status-box code { font-size: 13px; background: var(--page); padding: 1px 6px; border-radius: var(--radius-button); }

/* ---- results ---- */
.results-section { margin-top: var(--s4); }
.section-head {
  margin: 0 0 var(--s2); padding-bottom: var(--s1);
  font-size: 16px; font-weight: 700; color: var(--heading); border-bottom: 2px solid var(--heading);
  display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3);
}
.section-head .count { color: var(--muted); font-size: 13px; font-weight: 400; }
.results { list-style: none; margin: 0; padding: 0; }
.results[aria-busy="true"] .result { color: var(--muted); }
.result {
  display: grid; grid-template-columns: 56px minmax(0, 1fr); gap: var(--s4);
  padding: var(--s4) 0; border-bottom: 1px solid var(--line);
}
.result.is-open { background: linear-gradient(to right, var(--tint), var(--page) 70%); }

.cover {
  width: 56px; aspect-ratio: 2 / 3; border-radius: var(--radius-button); overflow: hidden;
  background: var(--band); border: 1px solid var(--band-line);
  display: grid; place-items: center; color: var(--ink-2); font-weight: 700; font-size: 22px;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }

.result-title { margin: 0; font-size: 16px; font-weight: 700; line-height: 1.35; }
.result-title a { color: var(--ink); text-decoration: underline; text-decoration-color: var(--band-line); }
.result-title a:hover { color: var(--accent-strong); text-decoration-color: currentColor; }
.authors { margin: 2px 0 0; font-size: 14px; color: var(--ink); }
.meta { margin: 2px 0 0; font-size: 13px; color: var(--muted); }
.meta span + span { margin-left: var(--s3); }
.summary { margin: var(--s2) 0 0; font-size: 14px; color: var(--ink-2); }
.summary.clamped { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.summary-missing { font-style: italic; color: var(--muted); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: var(--s2) 0 0; padding: 0; list-style: none; }
.tag {
  font-size: 12px; line-height: 1.4; padding: 2px 8px; border-radius: var(--pill);
  background: var(--band); color: var(--ink-2);
}

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); margin-top: var(--s3); }
.text-button {
  background: none; border: 0; padding: 0; color: var(--accent-strong); font-size: 13px; cursor: pointer;
  text-decoration: underline; text-underline-offset: 2px; min-height: 24px;
}
.why-button {
  display: inline-flex; align-items: center; gap: var(--s2); min-height: 28px;
  border: 1px solid var(--tint-line); background: var(--tint); color: var(--ink);
  border-radius: var(--radius-button); padding: 2px 10px; font-size: 13px; cursor: pointer;
}
.why-button:hover { border-color: var(--accent); }
.why-button .score { font-variant-numeric: tabular-nums; font-weight: 600; }
.why-button .chev { width: 10px; height: 10px; transition: transform 0.15s; }
.why-button[aria-expanded="true"] .chev { transform: rotate(180deg); }
.read-link { font-size: 13px; }

.why {
  margin-top: var(--s3); padding: var(--s3) var(--s4);
  background: var(--tint); border: 1px solid var(--tint-line); border-radius: var(--radius-card);
  font-size: 14px;
}
.why-source { margin: 0 0 var(--s2); font-weight: 600; }
.why blockquote {
  margin: 0 0 var(--s2); padding-left: var(--s3); border-left: 3px solid var(--accent); color: var(--ink);
}
.why p { margin: 0 0 var(--s1); }
.why .why-caption, .why .why-loading { color: var(--muted); font-size: 13px; }
.why .why-parts-title { margin-top: var(--s3); font-weight: 600; }
.why-parts { border-collapse: collapse; font-size: 13px; }
.why-parts th { text-align: left; font-weight: 400; color: var(--ink-2); padding: 2px var(--s4) 2px 0; }
.why-parts td { padding: 2px 0; }
.why-parts .score { font-variant-numeric: tabular-nums; font-weight: 600; }
.why .why-note { color: var(--muted); font-size: 13px; margin: var(--s2) 0 0; }
mark { background: var(--accent-soft); color: inherit; padding: 0 2px; border-radius: 2px; }

.more-button {
  display: block; margin: var(--s5) auto 0; padding: 8px var(--s5); min-height: 36px;
  border: 2px solid var(--accent); background: var(--page); color: var(--accent-strong);
  border-radius: var(--pill); font-weight: 600; cursor: pointer;
}
.more-button:hover { background: var(--accent-soft); }

/* ---- detail panel ---- */
.panel {
  align-self: start; background: var(--tint); border-radius: var(--radius-card);
  padding: var(--s4) var(--s5);
}
.panel:focus { outline: none; }
@media (min-width: 1024px) {
  .panel { position: sticky; top: var(--s4); max-height: calc(100vh - 2 * var(--s4)); overflow-y: auto; }
}
@media (max-width: 1023px) {
  .panel { display: none; }
  .panel.is-open {
    display: block; position: fixed; inset: 0; z-index: 20; border-radius: 0; overflow-y: auto;
    padding: var(--s4);
  }
  body.sheet-open { overflow: hidden; }
}
.panel-empty p { margin: 0; color: var(--muted); font-size: 14px; }
.panel-top { display: flex; gap: var(--s4); align-items: flex-start; }
.panel-top .cover { width: 88px; font-size: 32px; flex-shrink: 0; }
.panel-title { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.3; }
.panel-subtitle { margin: var(--s1) 0 0; color: var(--ink-2); }
.close-button {
  margin-left: auto; flex-shrink: 0; width: 32px; height: 32px; border-radius: var(--radius-button);
  border: 1px solid var(--tint-line); background: var(--page); cursor: pointer; font-size: 18px; line-height: 1;
}
.close-button:hover { border-color: var(--accent); }

.facts { width: 100%; border-collapse: collapse; margin: var(--s4) 0; font-size: 14px; }
.facts th, .facts td { text-align: left; vertical-align: top; padding: 6px 0; border-bottom: 1px solid var(--tint-line); }
.facts th { width: 34%; padding-right: var(--s3); color: var(--muted); font-weight: 600; font-size: 13px; }
.facts ul { margin: 0; padding: 0; list-style: none; }

.panel h3 {
  margin: var(--s5) 0 var(--s2); font-size: 14px; font-weight: 700; color: var(--heading);
  border-bottom: 2px solid var(--heading); padding-bottom: 2px;
}
.panel .label-note { font-weight: 400; color: var(--muted); font-size: 12px; margin-left: var(--s2); }
.panel p { margin: 0 0 var(--s2); font-size: 14px; color: var(--ink-2); }
.toc { margin: 0; padding-left: 20px; font-size: 14px; color: var(--ink-2); }
.toc li { margin: 2px 0; }

/* ---- footer ---- */
.footer { border-top: 1px solid var(--band-line); background: var(--band); }
.footer p { max-width: 1200px; margin: 0 auto; padding: var(--s3) var(--s4); font-size: 12px; color: var(--ink-2); }

@media (max-width: 480px) {
  .layout { padding-top: var(--s4); }
  .search-button { padding: 0 var(--s4); }
  .result { grid-template-columns: 44px minmax(0, 1fr); gap: var(--s3); }
  .cover { width: 44px; font-size: 18px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
