:root {
  --bg: #faf7f2;
  --surface: #ffffff;
  --surface-2: #f1ece3;
  --text: #1f1b16;
  --muted: #6b6257;
  --accent: #c2410c;
  --accent-2: #0e7490;
  --kids: #7c3aed;
  --ok: #15803d;
  --warn: #b45309;
  --border: #e6dfd3;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(40, 30, 10, .08);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --serif: Georgia, "Times New Roman", serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15120f; --surface: #1f1b17; --surface-2: #2a241f; --text: #f3ede4; --muted: #b3a89a;
    --accent: #fb923c; --accent-2: #22d3ee; --kids: #c4b5fd; --ok: #4ade80; --warn: #fbbf24; --border: #3a322b;
    --shadow: 0 2px 12px rgba(0, 0, 0, .4);
  }
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: var(--font); line-height: 1.5; }
body.story-open { overflow: hidden; }
a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .4em; }
img { max-width: 100%; }
button, input, select { font: inherit; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 16px; padding: 10px 16px; background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow); }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 1.15rem; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-icon { font-size: 1.5rem; }
.search { flex: 1; display: flex; max-width: 560px; margin: 0 auto; }
.search input { flex: 1; padding: 9px 14px; border: 1px solid var(--border); border-radius: 999px 0 0 999px; background: var(--bg); color: var(--text); min-width: 0; }
.search button { padding: 0 14px; border: 1px solid var(--border); border-left: 0; border-radius: 0 999px 999px 0; background: var(--surface-2); cursor: pointer; }
.topbar-link { font-weight: 600; white-space: nowrap; }
@media (max-width: 600px) { .brand-text, .topbar-link { display: none; } }

.app { max-width: 1180px; margin: 0 auto; padding: 24px 16px 60px; }
.footer { border-top: 1px solid var(--border); color: var(--muted); font-size: .85rem; padding: 18px 16px; text-align: center; }

/* ---------- home ---------- */
.hero { text-align: center; padding: 28px 8px 36px; }
.hero h1 { font-size: clamp(1.8rem, 4vw, 2.8rem); font-family: var(--serif); }
.hero p { color: var(--muted); max-width: 620px; margin: 0 auto; font-size: 1.05rem; }
.group { margin-bottom: 40px; }
.group h2 { font-size: 1.5rem; }
.group-desc { color: var(--muted); margin: 0 0 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.tile { display: grid; grid-template-columns: auto 1fr; grid-template-rows: auto auto; gap: 4px 12px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); color: var(--text); transition: transform .15s, box-shadow .15s; }
.tile:hover { transform: translateY(-3px); box-shadow: 0 10px 24px rgba(40, 30, 10, .14); text-decoration: none; }
.tile-icon { font-size: 2rem; grid-row: span 2; align-self: start; }
.tile-name { display: block; font-weight: 700; font-size: 1.1rem; }
.tile-desc { display: block; color: var(--muted); font-size: .9rem; }
.tile-count { display: block; font-size: .8rem; color: var(--accent); margin-top: 4px; font-weight: 600; }
.tile-covers { grid-column: 2; display: flex; gap: 6px; margin-top: 8px; }
.tile-covers img { width: 38px; height: 56px; object-fit: cover; border-radius: 4px; box-shadow: 0 1px 4px rgba(0, 0, 0, .25); }
.group-children .tile { border-color: color-mix(in srgb, var(--kids) 40%, var(--border)); }
.group-children .tile-count { color: var(--kids); }

/* ---------- category ---------- */
.crumbs { color: var(--muted); font-size: .9rem; margin-bottom: 12px; }
.cat-head h1 { font-size: 2rem; }
.cat-head p { color: var(--muted); margin-top: 0; }
.cat-head.kids h1 { color: var(--kids); }
.filters { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 12px 0 20px; }
.filters input, .filters select { padding: 8px 12px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); }
.filters input { flex: 1; min-width: 180px; }
.filters button { padding: 8px 14px; border: 0; border-radius: 8px; background: var(--accent); color: #fff; cursor: pointer; }
.count { color: var(--muted); font-size: .9rem; margin-left: auto; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 18px 14px; }
.card { display: flex; flex-direction: column; color: var(--text); }
.card:hover { text-decoration: none; }
.card:hover .cover { transform: translateY(-3px); box-shadow: 0 10px 20px rgba(0, 0, 0, .22); }
.card-title { font-weight: 600; font-size: .92rem; margin-top: 8px; line-height: 1.25; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card-author { color: var(--muted); font-size: .8rem; }
.cover { position: relative; aspect-ratio: 2 / 3; border-radius: 8px; overflow: hidden; background: linear-gradient(160deg, hsl(var(--hue, 30) 45% 38%), hsl(calc(var(--hue, 30) + 40) 50% 22%)); box-shadow: 0 3px 8px rgba(0, 0, 0, .2); transition: transform .15s, box-shadow .15s; }
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; position: relative; z-index: 1; }
.cover-fallback { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; padding: 12px; color: #fff; font-family: var(--serif); font-size: .95rem; text-shadow: 0 1px 3px rgba(0, 0, 0, .5); }
.cover.big { width: 100%; max-width: 260px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 18px; margin-top: 30px; }
.pager a { padding: 8px 16px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); }
.pager a.disabled { pointer-events: none; opacity: .4; }
.empty, .loading, .error { text-align: center; color: var(--muted); padding: 60px 0; }
.spinner { display: inline-block; width: 18px; height: 18px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; margin-right: 10px; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- book ---------- */
.book { display: grid; grid-template-columns: 260px 1fr; gap: 32px; }
@media (max-width: 760px) { .book { grid-template-columns: 1fr; } .book-side { display: flex; gap: 16px; } .cover.big { width: 150px; } }
.book h1 { font-family: var(--serif); font-size: clamp(1.6rem, 3.5vw, 2.4rem); }
.subtitle { color: var(--muted); margin-top: -6px; font-style: italic; }
.byline { font-size: 1.05rem; margin-top: 0; }
.book-links { display: flex; flex-direction: column; gap: 8px; margin-top: 14px; }
.btn { display: inline-block; padding: 9px 16px; border-radius: 10px; background: var(--accent); color: #fff; border: 0; cursor: pointer; font-weight: 600; text-align: center; }
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn.ghost { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn.big { font-size: 1.15rem; padding: 14px 26px; background: var(--kids); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); color: var(--text); font-size: .82rem; border: 1px solid var(--border); }
.chip.ok { background: color-mix(in srgb, var(--ok) 14%, transparent); color: var(--ok); border-color: var(--ok); font-weight: 600; }
.chip.warn { background: color-mix(in srgb, var(--warn) 14%, transparent); color: var(--warn); border-color: var(--warn); font-weight: 600; }
.chip.soft { font-size: .78rem; }
.summary { margin-top: 24px; padding: 20px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.summary-head { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between; }
.listen { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: .85rem; color: var(--muted); }
.listen label { display: flex; align-items: center; gap: 6px; }
.listen input[type=range] { width: 90px; }
.listen select { max-width: 170px; padding: 4px; border-radius: 6px; border: 1px solid var(--border); background: var(--bg); color: var(--text); }
.summary-text { font-size: 1.08rem; line-height: 1.7; font-family: var(--serif); }
.summary-text .w.on, .story-text .w.on { background: color-mix(in srgb, var(--accent) 30%, transparent); border-radius: 4px; }
.note { color: var(--muted); font-size: .82rem; }
.note.warn { color: var(--warn); }
.story-cta { display: flex; flex-wrap: wrap; gap: 20px; align-items: center; justify-content: space-between; margin-top: 20px; padding: 20px; border-radius: var(--radius); background: linear-gradient(135deg, color-mix(in srgb, var(--kids) 16%, var(--surface)), color-mix(in srgb, var(--accent-2) 12%, var(--surface))); border: 1px solid var(--border); }
.story-cta h2 { margin-bottom: 4px; }
.story-cta p { margin: 0 0 8px; color: var(--muted); max-width: 520px; }
.opt { font-size: .9rem; display: flex; align-items: center; gap: 6px; }
.meta { margin-top: 24px; }
.meta h3 { font-size: .95rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 16px; }
.book.kids h1 { color: var(--kids); }

/* ---------- story mode ---------- */
.story { position: fixed; inset: 0; z-index: 100; color: #fff; display: flex; flex-direction: column; font-family: var(--font); }
.story-bg { position: absolute; inset: 0; transition: background 1.2s ease; }
.story-bg::after { content: ""; position: absolute; inset: -50%; background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, .18), transparent 40%), radial-gradient(circle at 70% 70%, rgba(255, 255, 255, .12), transparent 45%); animation: drift 24s ease-in-out infinite alternate; }
@keyframes drift { from { transform: translate(-4%, -3%) rotate(0deg); } to { transform: translate(4%, 3%) rotate(8deg); } }
.story-shapes { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.story-shapes span { position: absolute; bottom: -40px; opacity: .35; animation: rise linear infinite; }
@keyframes rise { from { transform: translateY(0) rotate(0); } to { transform: translateY(-115vh) rotate(360deg); } }
.story-progress { position: absolute; top: 0; left: 0; right: 0; height: 5px; background: rgba(255, 255, 255, .2); }
.story-progress-bar { height: 100%; background: #fff; transition: width .5s ease; }
.story-close { position: absolute; top: 14px; right: 14px; z-index: 3; width: 42px; height: 42px; border-radius: 50%; border: 0; background: rgba(0, 0, 0, .35); color: #fff; font-size: 1.2rem; cursor: pointer; }
.story-stage { position: relative; z-index: 2; flex: 1; display: grid; grid-template-columns: minmax(0, 320px) minmax(0, 1fr); gap: 40px; align-items: center; padding: 60px clamp(20px, 6vw, 90px) 20px; max-width: 1200px; margin: 0 auto; width: 100%; }
@media (max-width: 760px) { .story-stage { grid-template-columns: 1fr; gap: 16px; padding-top: 70px; text-align: center; } .story-cover-wrap { max-width: 150px; margin: 0 auto; } }
.story-cover-wrap { border-radius: 14px; overflow: hidden; box-shadow: 0 20px 50px rgba(0, 0, 0, .45); animation: kenburns 14s ease-in-out forwards; transform-origin: center; }
.story-cover { display: block; width: 100%; }
@keyframes kenburns { from { transform: scale(1) translate(0, 0); } to { transform: scale(1.12) translate(-2%, 2%); } }
.story-mascot { position: absolute; left: clamp(20px, 6vw, 90px); bottom: 10px; font-size: 3rem; animation: bounce 2.4s ease-in-out infinite; filter: drop-shadow(0 6px 10px rgba(0, 0, 0, .3)); }
@keyframes bounce { 0%, 100% { transform: translateY(0) rotate(-6deg); } 50% { transform: translateY(-16px) rotate(6deg); } }
.story-caption { font-size: clamp(1.3rem, 2.6vw, 2.1rem); line-height: 1.5; font-family: var(--serif); text-shadow: 0 2px 10px rgba(0, 0, 0, .4); }
.story-text { margin: 0; }
.story-text .w { display: inline-block; opacity: 0; transform: translateY(12px); animation: wordin .5s ease forwards; padding: 0 2px; border-radius: 6px; transition: background .15s; }
.story-text .w.on { background: rgba(255, 255, 255, .28); }
@keyframes wordin { to { opacity: 1; transform: translateY(0); } }
.story-stage.is-card .story-caption { text-align: center; grid-column: 1 / -1; }
.story-stage.is-card .story-cover-wrap { display: none; }
.story-h { font-size: clamp(2rem, 6vw, 4rem); animation: popin .8s cubic-bezier(.2, 1.4, .4, 1) both; }
.story-sub { font-size: 1.3rem; opacity: .9; animation: wordin 1s .4s ease both; }
.story-links { animation: wordin 1s .8s ease both; display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.story-links a, .story-links button { padding: 10px 18px; border-radius: 999px; background: rgba(255, 255, 255, .2); color: #fff; border: 1px solid rgba(255, 255, 255, .5); font-size: 1rem; cursor: pointer; font-family: var(--font); }
@keyframes popin { from { opacity: 0; transform: scale(.6); } to { opacity: 1; transform: scale(1); } }
.story-controls { position: relative; z-index: 2; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px; padding: 14px 16px 22px; background: linear-gradient(transparent, rgba(0, 0, 0, .35)); }
.story-controls button { width: 46px; height: 46px; border-radius: 50%; border: 0; background: rgba(255, 255, 255, .2); color: #fff; font-size: 1.1rem; cursor: pointer; }
.story-controls .story-play { width: 60px; height: 60px; background: #fff; color: #222; font-size: 1.4rem; }
.story-counter { font-size: .9rem; opacity: .85; min-width: 60px; text-align: center; }
.story-opt { font-size: .85rem; display: flex; align-items: center; gap: 6px; opacity: .9; }
.story-opt select { max-width: 150px; border-radius: 6px; padding: 3px; }
.story-note { position: relative; z-index: 2; text-align: center; font-size: .8rem; opacity: .8; padding-bottom: 10px; }
@media (prefers-reduced-motion: reduce) { .story-cover-wrap, .story-mascot, .story-shapes span, .story-bg::after { animation: none !important; } .story-text .w { animation-duration: .01s; } }

/* ---------- regional sub-categories ---------- */
:root { --indian: #c2410c; --indian-bg: #fff1e6; }
@media (prefers-color-scheme: dark) { :root { --indian: #fdba74; --indian-bg: #3a2416; } }
.indian-band { margin: 0 0 36px; padding: 20px 22px; border-radius: var(--radius); background: linear-gradient(135deg, var(--indian-bg), color-mix(in srgb, #15803d 10%, var(--surface))); border: 1px solid color-mix(in srgb, var(--indian) 35%, var(--border)); }
.indian-band h2 { color: var(--indian); font-size: 1.4rem; }
.indian-band p { margin: 0 0 12px; color: var(--muted); }
.indian-links { display: flex; flex-wrap: wrap; gap: 8px; }
.indian-links a { padding: 7px 14px; border-radius: 999px; background: var(--surface); border: 1px solid color-mix(in srgb, var(--indian) 45%, var(--border)); color: var(--text); font-size: .92rem; }
.indian-links a:hover { background: var(--indian); color: #fff; text-decoration: none; }
.indian-links b { color: var(--indian); margin-left: 4px; }
.indian-links a:hover b { color: #fff; }

.tile { display: flex; flex-direction: column; gap: 10px; }
.tile-main { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; color: var(--text); }
.tile-main:hover { text-decoration: none; }
.tile-regions { display: flex; flex-wrap: wrap; gap: 5px; padding-top: 10px; border-top: 1px dashed var(--border); }
.rchip { font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); white-space: nowrap; }
.rchip:hover { border-color: var(--accent-2); text-decoration: none; }
.rchip b { font-weight: 600; color: var(--muted); }
.rchip.indian { background: var(--indian-bg); border-color: var(--indian); color: var(--indian); font-weight: 600; order: -1; }
.rchip.indian b { color: var(--indian); }

.rtabs { display: flex; flex-wrap: wrap; gap: 8px; margin: 14px 0 4px; }
.rtab { padding: 8px 16px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 500; }
.rtab:hover { text-decoration: none; border-color: var(--accent-2); }
.rtab b { font-weight: 600; color: var(--muted); margin-left: 2px; }
.rtab.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.rtab.active b { color: inherit; opacity: .8; }
.rtab.indian { border: 2px solid var(--indian); color: var(--indian); background: var(--indian-bg); font-weight: 700; padding: 8px 18px; }
.rtab.indian b { color: var(--indian); }
.rtab.indian.active { background: var(--indian); color: #fff; }
.rtab.indian.active b { color: #fff; }
.rtab.empty { opacity: .45; cursor: not-allowed; }
.h-region { font-size: .7em; color: var(--muted); font-weight: 500; }
.cat-head .h-region { color: var(--indian); }

.card { position: relative; }
.card-badge { position: absolute; top: 6px; left: 6px; z-index: 2; font-size: .7rem; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--indian-bg); color: var(--indian); border: 1px solid var(--indian); }
.chip.indian { background: var(--indian-bg); color: var(--indian); border-color: var(--indian); font-weight: 600; }

/* ---------- Hindi books ---------- */
:lang(hi) { font-family: "Nirmala UI", "Noto Sans Devanagari", "Mangal", "Kohinoor Devanagari", var(--font); }
.book-hi .summary-text, .story[lang="hi"] .story-caption { font-family: "Noto Serif Devanagari", "Nirmala UI", "Mangal", serif; line-height: 1.9; }
.cover-hi { background: linear-gradient(160deg, hsl(var(--hue, 25) 70% 42%), hsl(calc(var(--hue, 25) + 30) 65% 24%)); }
.cover-hi .cover-fallback { flex-direction: column; gap: 8px; padding: 14px; }
.cover-hi .cover-fallback b { font-size: 1.25rem; line-height: 1.35; font-weight: 700; }
.cover-hi .cover-fallback small { font-size: .8rem; opacity: .9; }
.cover-hi.big .cover-fallback b { font-size: 1.9rem; }
.cover-hi::after { content: "❁"; position: absolute; bottom: 8px; right: 10px; color: rgba(255,255,255,.55); font-size: 1.1rem; }
.mini-cover { display: inline-flex; align-items: center; justify-content: center; width: 38px; height: 56px; padding: 2px; border-radius: 4px; font-size: .55rem; line-height: 1.15; text-align: center; color: #fff; overflow: hidden;
  background: linear-gradient(160deg, hsl(var(--hue, 25) 70% 42%), hsl(calc(var(--hue, 25) + 30) 65% 24%)); box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.group-hindi .tile { border-color: color-mix(in srgb, var(--indian) 45%, var(--border)); background: linear-gradient(180deg, var(--indian-bg), var(--surface) 60%); }
.group-hindi h2 { color: var(--indian); }
.hindi-matches { margin-bottom: 28px; }
.hindi-matches h2 { color: var(--indian); font-size: 1.3rem; }
.muted { color: var(--muted); font-weight: normal; }
.story-title-card { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; aspect-ratio: 2 / 3; padding: 20px; text-align: center; color: #fff;
  background: linear-gradient(160deg, rgba(255,255,255,.22), rgba(0,0,0,.25)); border: 2px solid rgba(255,255,255,.5); }
.story-title-card span { font-size: clamp(1.6rem, 3vw, 2.6rem); font-weight: 700; line-height: 1.3; }
.story-title-card small { font-size: 1rem; opacity: .9; }

/* ---------- visitor counter (footer) ---------- */
.visitor-counter { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 6px; align-items: baseline; margin: 0 0 10px; padding: 6px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: .95rem; }
.visitor-counter b { color: var(--indian); font-variant-numeric: tabular-nums; }
.visitor-counter .vc-en { color: var(--muted); font-size: .8rem; }

/* The hidden attribute must win over component display rules (e.g. .btn). */
[hidden] { display: none !important; }

/* ---------- visitor counter (top bar) ---------- */
.visitor-badge { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.vb-label { font-size: .9rem; color: var(--muted); white-space: nowrap; }
.vb-digits { display: inline-flex; gap: 4px; }
.vb-digit {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 30px; border-radius: 6px;
  font: 700 1.15rem/1 Georgia, "Times New Roman", serif; color: #fff;
  text-shadow: 0 1px 1px rgba(0, 40, 90, .55);
  background:
    linear-gradient(180deg, rgba(255,255,255,.38) 0%, rgba(255,255,255,.12) 48%, rgba(255,255,255,0) 52%),
    linear-gradient(180deg, #4cc3f5 0%, #1a9be3 55%, #0d78c8 100%);
  border: 1px solid #0a6db8;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.55), 0 2px 3px rgba(0, 60, 120, .35);
  animation: vbIn .45s ease both;
}
@keyframes vbIn { from { opacity: 0; transform: translateY(-6px) scale(.9); } to { opacity: 1; transform: none; } }
@media (max-width: 760px) {
  .topbar { flex-wrap: wrap; }
  .visitor-badge { order: 5; width: 100%; justify-content: center; padding-top: 2px; }
  .vb-label { font-size: .8rem; }
  .vb-digit { width: 22px; height: 26px; font-size: 1rem; }
}
@media (prefers-reduced-motion: reduce) { .vb-digit { animation: none; } }

/* The hidden attribute must win over component display rules (e.g. .btn). */
[hidden] { display: none !important; }

/* ---------- visitor counter ---------- */
.visitor-counter { display: inline-flex; flex-wrap: wrap; justify-content: center; gap: 6px; align-items: baseline; margin: 0 0 10px; padding: 6px 14px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--border); color: var(--text); font-size: .95rem; }
.visitor-counter b { color: var(--indian); font-variant-numeric: tabular-nums; }
.visitor-counter .vc-en { color: var(--muted); font-size: .8rem; }
