:root {
  --bg: #f6f1e8;
  --bg-elev: #fffdf8;
  --ink: #1c1915;
  --muted: #6b645a;
  --line: #e4dccf;
  --accent: #b45309;
  --accent-soft: rgba(180, 83, 9, 0.12);
  --shadow: 0 10px 30px rgba(28, 25, 21, 0.06);
  --radius: 14px;
  --serif: "Cormorant Garamond", Georgia, serif;
  --sans: "Source Sans 3", system-ui, sans-serif;
  --max: 1080px;
  --reader-measure: 70ch;
  --reader-lh: 1.7;
  --reader-size: 1.125rem;
}
html[data-theme="dark"] {
  --bg: #12100e;
  --bg-elev: #1c1915;
  --ink: #f3ebe1;
  --muted: #a89f92;
  --line: #2e2923;
  --accent: #f0a35e;
  --accent-soft: rgba(240, 163, 94, 0.14);
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}
*, *::before, *::after { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh;
  font-family: var(--sans); color: var(--ink);
  background: radial-gradient(1200px 500px at 10% -10%, var(--accent-soft), transparent 60%), var(--bg);
  line-height: 1.55;
}
a { color: var(--accent); text-underline-offset: 3px; }
.wrap { width: min(var(--max), calc(100% - 2rem)); margin-inline: auto; }
.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: #fff; padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: 1rem; top: 1rem; }


/* —— Library-in-progress sticky banner —— */
.chrome-top {
  position: sticky;
  top: 0;
  z-index: 25;
}
.progress-banner {
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 88%, #7c2d12), var(--accent));
  color: #fffdf8;
  border-bottom: 1px solid color-mix(in srgb, var(--accent) 70%, #000);
  box-shadow: 0 2px 10px rgba(28, 25, 21, 0.12);
}
html[data-theme="dark"] .progress-banner {
  background: linear-gradient(90deg, color-mix(in srgb, var(--accent) 55%, #3b1d0a), color-mix(in srgb, var(--accent) 85%, #1c1915));
  color: #1c1915;
  border-bottom-color: color-mix(in srgb, var(--accent) 40%, #000);
}
.progress-banner-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .55rem 0;
}
.progress-banner-text {
  margin: 0;
  font-size: .92rem;
  line-height: 1.35;
  font-weight: 500;
}
.progress-banner-text strong {
  font-weight: 700;
  letter-spacing: .01em;
}
.progress-banner-dismiss {
  flex-shrink: 0;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 999px;
  border: 1px solid rgba(255, 253, 248, 0.45);
  background: rgba(255, 253, 248, 0.18);
  color: inherit;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 0;
}
.progress-banner-dismiss:hover {
  background: rgba(255, 253, 248, 0.32);
}
.progress-banner-dismiss:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}
html[data-theme="dark"] .progress-banner-dismiss {
  border-color: rgba(28, 25, 21, 0.35);
  background: rgba(28, 25, 21, 0.12);
}
html[data-theme="dark"] .progress-banner-dismiss:hover {
  background: rgba(28, 25, 21, 0.22);
}
html[data-theme="dark"] .progress-banner-dismiss:focus-visible {
  outline-color: var(--ink);
}
@media (max-width: 640px) {
  .progress-banner-text { font-size: .85rem; }
}

.site-header {
  position: relative; z-index: 20;
  backdrop-filter: blur(10px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  border-bottom: 1px solid var(--line);
}
.header-inner { display: flex; align-items: center; justify-content: space-between; padding: .9rem 0; gap: 1rem; }
.brand { display: flex; align-items: center; gap: .75rem; color: inherit; text-decoration: none; }
.brand-mark {
  width: 2.2rem; height: 2.2rem; display: grid; place-items: center;
  border-radius: 10px; background: var(--accent-soft); color: var(--accent);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text strong { font-family: var(--serif); font-size: 1.35rem; font-weight: 600; }
.brand-text small { color: var(--muted); font-size: .78rem; }
.nav { display: flex; align-items: center; gap: 1rem; }
.nav a { color: var(--ink); text-decoration: none; font-weight: 500; }
.nav a:hover { color: var(--accent); }
.theme-toggle {
  border: 1px solid var(--line); background: var(--bg-elev); color: var(--ink);
  border-radius: 999px; width: 2.2rem; height: 2.2rem; cursor: pointer;
}

.app { padding: 2rem 0 3.5rem; }
.loading, .empty { color: var(--muted); }

.hero {
  display: grid; gap: 1rem; margin-bottom: 2.25rem; padding: 1.75rem 1.5rem;
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 4px); box-shadow: var(--shadow);
}
.hero h1 {
  margin: 0; font-family: var(--serif); font-weight: 600;
  font-size: clamp(2rem, 4vw, 2.8rem); line-height: 1.15;
}
.hero p { margin: 0; max-width: 42rem; color: var(--muted); font-size: 1.05rem; }
.stats { display: flex; flex-wrap: wrap; gap: .6rem; }
.chip {
  display: inline-flex; padding: .35rem .7rem; border-radius: 999px;
  background: var(--accent-soft); color: var(--accent); font-size: .82rem; font-weight: 600;
}

.subject-grid {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}
.subject-card {
  display: flex; flex-direction: column; gap: .55rem; min-height: 9.5rem;
  padding: 1.2rem 1.15rem; background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); text-decoration: none; color: inherit; box-shadow: var(--shadow);
  transition: transform .15s ease, border-color .15s ease;
}
.subject-card:hover {
  transform: translateY(-2px);
  border-color: color-mix(in srgb, var(--card-accent, var(--accent)) 45%, var(--line));
}
.swatch { width: 2rem; height: .35rem; border-radius: 99px; background: var(--card-accent, var(--accent)); }
.subject-card h2 { margin: 0; font-family: var(--serif); font-size: 1.45rem; font-weight: 600; }
.subject-card p { margin: 0; color: var(--muted); font-size: .92rem; flex: 1; }
.subject-card .meta { font-size: .82rem; font-weight: 600; color: var(--card-accent, var(--accent)); }

.page-head { margin-bottom: 1.5rem; }
.crumbs { color: var(--muted); font-size: .9rem; margin-bottom: .6rem; }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }
.page-head h1 {
  margin: 0 0 .4rem; font-family: var(--serif);
  font-size: clamp(1.8rem, 3.5vw, 2.4rem); font-weight: 600;
}
.lede { margin: 0; color: var(--muted); }

.toolbar { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.search {
  flex: 1; min-width: 200px; border: 1px solid var(--line); background: var(--bg-elev);
  color: var(--ink); border-radius: 10px; padding: .65rem .85rem; font: inherit;
}
.search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

.book-list { display: grid; gap: .55rem; }
.book-row {
  display: grid; grid-template-columns: 1fr auto; gap: .75rem; align-items: center;
  padding: .85rem 1rem; background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: 12px; text-decoration: none; color: inherit;
}
.book-row:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--line)); }
.book-row h3 { margin: 0; font-family: var(--serif); font-size: 1.2rem; font-weight: 600; }
.book-row .sub { color: var(--muted); font-size: .85rem; margin-top: .15rem; }
.badges { display: flex; flex-wrap: wrap; gap: .35rem; justify-content: flex-end; }
.badge {
  font-size: .72rem; font-weight: 600; letter-spacing: .02em; text-transform: uppercase;
  padding: .25rem .5rem; border-radius: 999px; background: var(--line); color: var(--muted);
}
.badge.ok { background: var(--accent-soft); color: var(--accent); }
.badge.soon { opacity: .75; }

.book-layout { display: grid; gap: 1.25rem; }
@media (min-width: 860px) {
  .book-layout { grid-template-columns: 1.4fr .9fr; align-items: start; }
}
.panel {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.2rem 1.25rem; box-shadow: var(--shadow);
}
.panel h2 { margin: 0 0 .75rem; font-family: var(--serif); font-size: 1.35rem; font-weight: 600; }
.panel h3 {
  margin: 1.1rem 0 .45rem; font-size: .78rem; text-transform: uppercase;
  letter-spacing: .06em; color: var(--muted);
}

.typed-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between;
  gap: .5rem; margin-bottom: .75rem;
}
.typed-toolbar h2 { margin: 0; }

/* Comfortable reading measure */
.typed-box {
  max-width: var(--reader-measure);
  margin-inline: auto;
  max-height: min(70vh, 48rem);
  overflow: auto;
  padding: 1.15rem 1.25rem 1.5rem;
  border-radius: 10px;
  background: color-mix(in srgb, var(--bg) 70%, var(--bg-elev));
  border: 1px solid var(--line);
  font-family: var(--serif);
  font-size: var(--reader-size);
  line-height: var(--reader-lh);
  color: var(--ink);
}
.typed-box p {
  margin: 0 0 1.05em;
  max-width: var(--reader-measure);
  text-wrap: pretty;
  overflow-wrap: break-word;
  hyphens: auto;
}
.typed-box p:last-child { margin-bottom: 0; }
.typed-box:focus { outline: 2px solid var(--accent); outline-offset: 2px; }

.placeholder {
  border: 1px dashed var(--line); border-radius: 12px; padding: 1.25rem;
  color: var(--muted); background: color-mix(in srgb, var(--bg) 55%, transparent);
}
.player-fake {
  width: 100%; height: 3rem; border-radius: 999px; margin-bottom: .65rem;
  background: repeating-linear-gradient(-45deg, var(--line), var(--line) 8px, transparent 8px, transparent 16px);
  opacity: .55;
}
.actions { display: flex; flex-wrap: wrap; gap: .55rem; margin-top: .85rem; }
.btn {
  display: inline-flex; align-items: center; gap: .4rem;
  padding: .55rem .9rem; border-radius: 999px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); text-decoration: none; font-weight: 600; font-size: .9rem;
  cursor: pointer; font-family: inherit;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
html[data-theme="dark"] .btn.primary { color: #1c1915; }
.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.about-card { max-width: 40rem; }
.about-card ul { padding-left: 1.1rem; }
.muted { color: var(--muted); }

.site-footer { border-top: 1px solid var(--line); padding: 1.5rem 0 2rem; color: var(--muted); font-size: .9rem; }
.footer-inner p { margin: .2rem 0; }

.empty { color: var(--muted); padding: 1rem 0; }
.sub { color: var(--muted); font-size: .85rem; margin-top: .15rem; }
.meta { font-size: .82rem; font-weight: 600; color: var(--card-accent, var(--accent)); }

.audio-player audio { width: 100%; margin-top: .25rem; }

/* —— Immersive / full-page reader —— */
body.reader-focus {
  overflow: hidden;
  background: var(--bg);
}
body.reader-focus .chrome-top,
body.reader-focus .site-header,
body.reader-focus .progress-banner,
body.reader-focus .site-footer,
body.reader-focus .page-head,
body.reader-focus .book-aside {
  display: none !important;
}
body.reader-focus main.wrap {
  width: 100%;
  max-width: none;
  margin: 0;
}
body.reader-focus .app {
  padding: 0;
  height: 100dvh;
  height: 100vh;
}
body.reader-focus .book-layout {
  display: block;
  height: 100%;
}
body.reader-focus .typed-panel {
  height: 100%;
  border: none;
  border-radius: 0;
  box-shadow: none;
  padding: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
}
body.reader-focus .typed-toolbar {
  position: sticky;
  top: 0;
  z-index: 30;
  margin: 0;
  padding: .65rem 1rem;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
body.reader-focus .typed-box {
  flex: 1;
  max-width: min(var(--reader-measure), calc(100% - 2rem));
  max-height: none;
  margin: 0 auto;
  width: 100%;
  border: none;
  border-radius: 0;
  background: transparent;
  padding: 1.25rem 1rem 3rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  font-size: clamp(1.1rem, 2.4vw, 1.28rem);
  line-height: 1.75;
}
body.reader-focus .focus-exit-hint {
  display: inline;
  color: var(--muted);
  font-size: .8rem;
  font-weight: 500;
  margin-left: .35rem;
}
.focus-exit-hint { display: none; }

@media (max-width: 640px) {
  :root {
    --reader-size: 1.05rem;
    --reader-lh: 1.65;
  }
  .typed-box { padding: 1rem; }
  body.reader-focus .typed-toolbar { padding: .55rem .75rem; }
}
