/* ============================================================
   Book sidebar visibility — desktop sticky like #TableOfContents
   ============================================================ */

/* Mobile back-to-TOC button (or any element marked for mobile-only) */
.book-toc-mobile-wrapper {
  display: inline-flex;
  margin-bottom: 1rem;
}
@media (min-width: 1024px) {
  .book-toc-mobile-wrapper {
    display: none;
  }
}

/* Desktop sticky sidebar (paired with "hidden lg:block" for show/hide) */
@media (min-width: 1024px) {
  .book-sidebar-desktop {
    position: sticky;
    top: 6rem;
    max-height: calc(100vh - 7rem);
    overflow-y: auto;
    padding-right: 0.5rem;
  }
}

/* ============================================================
   Sidebar TOC entries — bigger/looser on mobile, matches right TOC on desktop
   ============================================================ */

.book-toc-book {
  display: block;
  font-size: 1rem;       /* text-base on mobile */
  font-weight: 600;
  margin-bottom: 1rem;
}

.book-toc-chapter {
  display: block;
  font-size: 1rem;
  font-weight: 600;
}

.book-toc-sections {
  margin-left: 1rem;
  margin-top: 0.5rem;
  list-style: decimal;
  list-style-position: inside;
  font-size: 0.875rem;
}
.book-toc-sections > li + li {
  margin-top: 0.375rem;
}

.book-toc-chapters > * + * {
  margin-top: 1rem;
}

@media (min-width: 1024px) {
  .book-toc-book {
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
  }
  .book-toc-chapter {
    font-size: 0.875rem;
  }
  .book-toc-sections {
    margin-top: 0.375rem;
    font-size: 0.875rem;
  }
  .book-toc-sections > li + li {
    margin-top: 0.25rem;
  }
  .book-toc-chapters > * + * {
    margin-top: 0.75rem;
  }
}

/* ============================================================
   Current page highlight + scroll-spy active state
   Darker than DaisyUI's --p for stronger readability
   ============================================================ */

.book-toc-current,
#TableOfContents a.toc-active {
  color: oklch(var(--p));                                          /* fallback */
  color: oklch(from oklch(var(--p)) calc(l - 0.22) c h);           /* darker */
  font-weight: 600;
}

/* Forest (dark theme) — primary already dark, lighten instead */
[data-theme="forest"] .book-toc-current,
[data-theme="forest"] #TableOfContents a.toc-active {
  color: oklch(var(--p));
  color: oklch(from oklch(var(--p)) calc(l + 0.12) c h);
}

/* Middle "back to TOC" button — lives in prev/next flex row, hidden on desktop */
.book-toc-middle-button {
  display: inline-flex;
}
@media (min-width: 1024px) {
  .book-toc-middle-button {
    display: none;
  }
}

/* ============================================================
   Home page book cards (also reused for post cards)
   ============================================================ */

.book-card-row {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}
@media (min-width: 640px) {
  .book-card-row {
    grid-template-columns: 1fr 1fr;
  }
}

.book-card {
  display: flex;
  gap: 1rem;
  padding: 1rem;
  border-radius: 0.5rem;
  background-color: oklch(var(--b2) / 0.5);
  transition: background-color 0.15s ease;
  color: inherit;
  text-decoration: none;
}
.book-card:hover {
  background-color: oklch(var(--b2));
  text-decoration: none;
}

/* Forest (dark theme) — base-200 is near-black, use a subtle light overlay instead */
[data-theme="forest"] .book-card {
  background-color: oklch(var(--bc) / 0.12);
}
[data-theme="forest"] .book-card:hover {
  background-color: oklch(var(--bc) / 0.2);
}

/* ============================================================
   Top nav: convert from sticky to fixed.
   The theme's .flip-container has a hardcoded height that interferes
   with body-level scroll context for sticky in some layouts. Fixed
   is rock-solid in all cases.
   ============================================================ */
body > nav {
  position: fixed !important;
  top: 0 !important;
  left: 0;
  right: 0;
  z-index: 40;
  margin-top: 0 !important;
  background-color: oklch(var(--b1));
  border-bottom: 1px solid oklch(var(--bc) / 0.12);
}
/* Compensate body for the fixed nav being out of flow */
body {
  padding-top: 5rem;
}
@media (min-width: 1024px) {
  body {
    padding-top: 6rem;
  }
}

/* ============================================================
   /posts/ archive — two-level grouping (year → month → entries)
   ============================================================ */

.archive-year-group {
  margin-bottom: 3rem;
}
.archive-year-group:last-child {
  margin-bottom: 0;
}

.archive-year {
  font-size: 1.875rem;       /* text-3xl */
  font-weight: 600;
  border-bottom: 1px solid oklch(var(--bc) / 0.25);
  padding-bottom: 0.5rem;
  margin-bottom: 1.5rem;
}

.archive-month-group + .archive-month-group {
  margin-top: 2rem;            /* empty-line space between months */
}

.archive-month {
  font-size: 1rem;
  font-weight: 500;
  color: oklch(var(--bc) / 0.7);
  margin-bottom: 0.75rem;
  margin-left: 0.5rem;
}

.archive-list {
  list-style: none;
  padding-left: 1.5rem;
  margin: 0;
}
.archive-list > li {
  padding: 0.25rem 0;
}
.archive-list a {
  color: inherit;
  text-decoration: none;
}
.archive-list a:hover {
  text-decoration: underline;
}
.archive-book {
  color: oklch(var(--bc) / 0.55);
  font-size: 0.875rem;
  margin-right: 0.25rem;
}

/* ============================================================
   Desktop nav: instant tooltip showing each icon's meaning on hover.
   Uses the existing `title` attribute via attr() in ::after pseudo-element.
   Limited to pointing-device (mouse/trackpad) — touch devices skip it.
   ============================================================ */
@media (hover: hover) {
  body > nav .group[title] {
    position: relative;
  }
  body > nav .group[title]:hover::after {
    content: attr(title);
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    margin-top: 0.25rem;
    padding: 0.25rem 0.5rem;
    background-color: oklch(var(--n));
    color: oklch(var(--nc));
    border-radius: 0.375rem;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
    pointer-events: none;
    z-index: 60;
    opacity: 0.95;
  }
}

/* ============================================================
   Mobile footer theme toggle — icons too small / look like dots,
   bump the icon size so moon/sun/desktop are recognizable
   ============================================================ */
@media (max-width: 1023px) {
  footer ion-icon[name$="-outline"] {
    font-size: 1.25rem;
  }
}

.book-card-cover {
  flex-shrink: 0;
  width: 5rem;
  height: 5rem;
  border-radius: 0.5rem;
  object-fit: cover;
}

.book-card-body {
  flex: 1;
  min-width: 0;
}

.book-card-title {
  font-size: 1rem;
  font-weight: 600;
  margin-bottom: 0.25rem;
}

.book-card-desc {
  font-size: 0.8125rem;
  color: oklch(var(--bc) / 0.7);
  margin-bottom: 0.375rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.4;
}

.book-card-meta {
  font-size: 0.75rem;
  color: oklch(var(--bc) / 0.55);
}

/* ============================================================
   Book-root listing page — loose, big-print TOC of chapters & sections
   (Used at /books/<book>/ for nested books)
   ============================================================ */

.book-list-chapters {
  list-style: none;
  padding-left: 0;
  margin-left: 0;
}
.book-list-chapters > li {
  display: flex;
  align-items: baseline;
  column-gap: 0.75rem;
  row-gap: 0.5rem;
  flex-wrap: wrap;
}
.book-list-chapters > li + li {
  margin-top: 0.5rem;
}
.book-list-chapter-link {
  font-size: 1.125rem;       /* text-lg */
  font-weight: 600;
}

/* Sections: 2-column grid (title-with-counter-inside | rating).
   Counter sits inside the <a> via ::before so it's right next to the title
   with just a space between them. Column 1 sizes to max-content (widest
   "N. title"), so ratings stay vertically aligned across rows. */
.book-list-sections {
  flex-basis: 100%;          /* wrap below the chapter link */
  list-style: none;
  padding-left: 0;
  margin-left: 1.5rem;
  font-size: 1rem;
  counter-reset: section-counter;
  display: grid;
  grid-template-columns: minmax(0, max-content) auto;
  row-gap: 0.5rem;
  column-gap: 0.75rem;
  align-items: baseline;
}
.book-list-sections > li {
  display: contents;
}
.book-list-sections > li > a::before {
  counter-increment: section-counter;
  content: counter(section-counter) ".";
  color: oklch(var(--bc) / 0.55);
  margin-right: 0.5rem;
}
.book-list-sections > li > a {
  min-width: 0;
  overflow-wrap: anywhere;
}

.recipe-rating {
  font-size: 0.875rem;
  white-space: nowrap;
  letter-spacing: 0.05em;
  color: inherit;
}
