/* Layout: a library shelf. A sticky search bar, then one shelf per category;
   each book is a small coloured cover beside its title card. */
:root {
  --bg: #eef1f5;
  --surface: #ffffff;
  --ink: #18203a;
  --muted: #586079;
  --line: #d6dbe6;
  --accent: #0b6782;
  --accent-ink: #ffffff;
  --gold: #b07800;
  --soon: #8a90a3;
  --cover-ink: #ffffff;

  --c-hindu-scriptures: #c75a12;
  --c-world-scriptures: #7a3e9d;
  --c-philosophy-strategy: #2f5f9e;
  --c-mind-decisions: #0b7a6c;
  --c-money-business: #8d6a00;
  --c-science-history: #a8324a;
  --c-living-well: #4d7a1f;

  --f-display: "Rozha One", "Tiro Devanagari Hindi", Georgia, serif;
  --f-body: "Mukta", "Nirmala UI", "Segoe UI", system-ui, sans-serif;
  --f-kids: "Baloo 2", "Mukta", "Nirmala UI", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;

  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.1875rem;
  --step-2: 1.5rem;
  --step-3: clamp(2rem, 6vw, 3rem);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #11141e; --surface: #1a1e2c; --ink: #e7eaf3; --muted: #9aa1b8; --line: #2c3246;
    --accent: #4cb3d0; --accent-ink: #0b1620; --gold: #e7b33a; --soon: #6f768c; --cover-ink: #10131c;
    --c-hindu-scriptures: #e8823f; --c-world-scriptures: #a979c9; --c-philosophy-strategy: #6b98d8;
    --c-mind-decisions: #3fb3a1; --c-money-business: #cfa52a; --c-science-history: #d9667d; --c-living-well: #86b553;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #11141e; --surface: #1a1e2c; --ink: #e7eaf3; --muted: #9aa1b8; --line: #2c3246;
  --accent: #4cb3d0; --accent-ink: #0b1620; --gold: #e7b33a; --soon: #6f768c; --cover-ink: #10131c;
  --c-hindu-scriptures: #e8823f; --c-world-scriptures: #a979c9; --c-philosophy-strategy: #6b98d8;
  --c-mind-decisions: #3fb3a1; --c-money-business: #cfa52a; --c-science-history: #d9667d; --c-living-well: #86b553;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: var(--step-0);
  line-height: 1.55;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body::before {
  content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px);
  z-index: 10; background: var(--bg);
}
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.wrap {
  width: 100%;
  max-width: 72rem;
  margin-inline: auto;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

/* Masthead */
.masthead-inner {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 16px 24px; padding-block: 28px 18px;
}
.brand { min-width: 0; }
.brand-name {
  margin: 0; font-family: var(--f-display); font-weight: 400;
  font-size: var(--step-3); line-height: 1.05; letter-spacing: 0.005em; text-wrap: balance;
}
.brand-tag { margin: 6px 0 0; color: var(--muted); max-width: 40rem; text-wrap: pretty; }

.lang {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
}
.lang button {
  font: 500 var(--step-0)/1 var(--f-body); color: var(--muted);
  background: transparent; border: 0; border-radius: 999px;
  padding: 9px 16px; min-height: 40px; cursor: pointer;
}
.lang button[lang="hi"] { font-size: 1.05rem; }
.lang button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }
.lang button:not([aria-pressed="true"]):hover { color: var(--ink); }

/* Toolbar */
.toolbar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.toolbar-inner { display: flex; flex-direction: column; gap: 10px; padding-block: 10px 12px; }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 0 12px; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); }
.search svg { width: 18px; height: 18px; flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font: inherit; font-size: 1rem; padding: 11px 0; outline: none;
}
.search input::placeholder { color: var(--muted); }
.chips {
  display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none;
  margin-inline: -4px; padding: 2px 4px;
}
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 6px;
  font: 500 var(--step--1)/1 var(--f-body); color: var(--ink);
  background: var(--surface); border: 1px solid var(--line); border-radius: 999px;
  padding: 8px 12px; min-height: 34px; cursor: pointer; white-space: nowrap;
}
.chip .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--cat, var(--muted)); }
.chip .n { font-family: var(--f-mono); color: var(--muted); font-size: 0.75rem; }
.chip[aria-pressed="true"] { border-color: var(--cat, var(--accent)); box-shadow: inset 0 0 0 1px var(--cat, var(--accent)); }

/* Intro lines */
.stats { margin: 22px 0 2px; font-family: var(--f-mono); font-size: var(--step--1); color: var(--muted); font-variant-numeric: tabular-nums; }
.note { margin: 0 0 8px; color: var(--muted); font-size: var(--step--1); }

/* Shelves */
.shelf { padding-top: 30px; }
.shelf-head {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 12px;
  padding-bottom: 10px; margin-bottom: 14px; border-bottom: 2px solid var(--cat);
}
.shelf-title { margin: 0; font-family: var(--f-display); font-weight: 400; font-size: var(--step-2); line-height: 1.2; text-wrap: balance; }
.shelf-alt { color: var(--muted); font-size: var(--step-0); }
.shelf-count { margin-left: auto; font-family: var(--f-mono); font-size: 0.75rem; color: var(--muted); font-variant-numeric: tabular-nums; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 20rem), 1fr)); gap: 12px; }

.book {
  position: relative; display: flex; gap: 14px; min-width: 0;
  padding: 14px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  color: inherit; text-decoration: none;
}
.book.ready:hover { border-color: var(--cat); }
.book.ready:hover .open { text-decoration: underline; }
.book-link { color: inherit; text-decoration: none; }
.book-link::after { content: ""; position: absolute; inset: 0; border-radius: inherit; }
.book-link:focus-visible { outline: none; }
.book-link:focus-visible::after { outline: 3px solid var(--accent); outline-offset: 2px; }
.claude-link {
  position: relative; z-index: 1; margin-left: auto;
  font-family: var(--f-body); font-size: 0.75rem; color: var(--muted);
}
.claude-link:hover { color: var(--accent); }
.cover {
  flex: none; align-self: flex-start; width: 52px; aspect-ratio: 2 / 3; max-width: 100%; border-radius: 3px 6px 6px 3px;
  background: var(--cat); color: var(--cover-ink);
  display: grid; place-items: center;
  font-family: var(--f-display); font-size: 1.5rem; line-height: 1;
  box-shadow: inset 5px 0 0 rgb(0 0 0 / 0.18), inset -1px 0 0 rgb(255 255 255 / 0.18);
}
.book.soon .cover {
  background: transparent; color: var(--soon);
  border: 1.5px dashed var(--soon); box-shadow: none;
}
.book-body { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.book-title { margin: 0; font-weight: 700; font-size: var(--step-1); line-height: 1.25; text-wrap: balance; }
.book-alt { color: var(--muted); font-size: var(--step--1); line-height: 1.3; }
.book-author { color: var(--muted); font-size: var(--step--1); }
.book-summary { margin: 4px 0 0; font-size: 0.95rem; text-wrap: pretty; }
.book-meta {
  margin-top: auto; padding-top: 8px; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px;
  font-family: var(--f-mono); font-size: 0.72rem; color: var(--muted);
}
.open { font-family: var(--f-body); font-size: var(--step--1); font-weight: 700; color: var(--accent); }
.badge {
  font-family: var(--f-body); font-size: 0.75rem; font-weight: 500;
  border: 1px solid var(--line); border-radius: 999px; padding: 1px 9px; color: var(--muted);
}
.fallback { font-size: 0.78rem; color: var(--gold); }

.empty { margin: 40px 0; color: var(--muted); text-align: center; }
.foot { padding-block: 40px 32px; color: var(--muted); font-size: var(--step--1); font-family: var(--f-mono); }

/* Kids view: rounder, bigger, friendlier */
[data-view="kids"] body { font-family: var(--f-kids); }
[data-view="kids"] .brand-name,
[data-view="kids"] .shelf-title { font-family: var(--f-kids); font-weight: 700; }
[data-view="kids"] .cover { font-family: var(--f-kids); font-weight: 700; border-radius: 12px; }
[data-view="kids"] .book { border-radius: 18px; border-width: 2px; }
[data-view="kids"] .book-summary { font-size: 1.02rem; }
[data-view="kids"] .chip, [data-view="kids"] .lang button { font-family: var(--f-kids); }

/* Hindi view: Devanagari needs a little more line height */
[data-view="hi"] { --f-mono: var(--f-body); } /* the mono face has no Devanagari */
[data-view="hi"] body { line-height: 1.65; }
[data-view="hi"] .book-title { line-height: 1.4; }

@media (min-width: 760px) {
  .toolbar-inner { flex-direction: row; align-items: center; }
  .search { flex: 0 1 22rem; }
  .chips { flex: 1; flex-wrap: wrap; overflow: visible; }
}
@media (prefers-reduced-motion: no-preference) {
  .book { transition: border-color 0.15s, transform 0.15s; }
  .book.ready:hover { transform: translateY(-1px); }
}
