/* === Siri Saddharmaya — shared styles === */

:root {
  --bg: #FAF7F2;
  --surface: #FFFFFF;
  --surface-2: #F2EDE4;
  --ink: #1F2A37;
  --ink-soft: #4A5563;
  --sage: #3D7A6A;
  --sage-deep: #2E5F53;
  --saffron: #C58B3A;
  --rose: #B86A6A;
  --line: #E6DFD2;
}

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  background: var(--bg);
  color: var(--ink);
  font-family: 'Inter', 'Noto Sans Sinhala', system-ui, -apple-system, BlinkMacSystemFont,
    'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 18px;
  line-height: 1.75;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:lang(si),
.sinhala {
  font-family: 'Noto Sans Sinhala', 'Inter', system-ui, sans-serif;
  line-height: 1.85;
}

h1, h2, h3, h4, h5 { font-family: 'Noto Sans Sinhala', 'Inter', system-ui, sans-serif; }

/* Skip link */
.skip-link {
  position: absolute;
  left: -1000px;
  top: -1000px;
  background: var(--ink);
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  z-index: 100;
}
.skip-link:focus { left: 16px; top: 16px; }

/* Focus ring */
:focus-visible {
  outline: 3px solid var(--saffron);
  outline-offset: 2px;
  border-radius: 4px;
}

/* Carousel — cinematic cross-fade + Ken Burns */
.carousel {
  position: relative;
  overflow: hidden;
  border-radius: 18px;
  background: var(--surface2);
  aspect-ratio: 1440 / 507;
}
.carousel-track {
  position: absolute;
  inset: 0;
}
.carousel-slide {
  position: absolute;
  inset: 0;
  opacity: 0;
  visibility: hidden;
  transition: opacity 900ms ease, visibility 0s linear 900ms;
  pointer-events: none;
}
.carousel-slide.is-active {
  opacity: 1;
  visibility: visible;
  transition: opacity 900ms ease, visibility 0s linear 0s;
  pointer-events: auto;
  z-index: 1;
}
.carousel-slide > .aspect-hero {
  width: 100%;
  height: 100%;
  aspect-ratio: auto;
  overflow: hidden;
  background: var(--surface2);
}
.carousel-slide img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  transform: scale(1);
  transform-origin: 50% 50%;
}
.carousel-slide.is-active img {
  animation: ss-kenburns 10s ease-out forwards;
}
@keyframes ss-kenburns {
  from { transform: scale(1); }
  to   { transform: scale(1.05); }
}

/* Dots */
.carousel-dots {
  position: absolute;
  left: 0; right: 0; bottom: 18px;
  display: flex;
  justify-content: center;
  gap: 10px;
  z-index: 6;
}
.carousel-dots button {
  width: 44px; height: 44px;
  padding: 0;
  display: grid; place-items: center;
  background: transparent;
  border: 0;
  cursor: pointer;
}
.carousel-dots button::before {
  content: "";
  width: 12px; height: 12px;
  border-radius: 999px;
  background: rgba(255,255,255,0.7);
  border: 1.5px solid rgba(15,22,30,0.2);
  box-shadow: 0 2px 6px rgba(0,0,0,0.18);
  transition: transform .25s ease, background .25s ease, width .25s ease;
}
.carousel-dots button[aria-current="true"]::before {
  background: var(--saffron);
  width: 28px;
  border-color: transparent;
}

/* Arrows — larger, higher contrast, elderly-friendly */
.carousel-arrow {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  background: rgba(255,255,255,0.92);
  color: var(--ink);
  border: none;
  width: 52px; height: 52px;
  border-radius: 999px;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  display: grid; place-items: center;
  box-shadow: 0 8px 22px rgba(0,0,0,0.18);
  z-index: 6;
  opacity: 0;
  transition: opacity .25s ease, background .2s ease, transform .2s ease;
}
.carousel:hover .carousel-arrow,
.carousel:focus-within .carousel-arrow {
  opacity: 1;
}
.carousel-arrow:hover { background: #fff; }
.carousel-arrow:focus-visible { opacity: 1; }
.carousel-arrow.prev { left: 14px; }
.carousel-arrow.next { right: 14px; }
/* Pause / play toggle */
.carousel-pause {
  position: absolute;
  top: 14px; right: 14px;
  width: 40px; height: 40px;
  border-radius: 999px;
  background: rgba(15,22,30,0.55);
  color: #fff;
  border: 0;
  display: grid; place-items: center;
  cursor: pointer;
  z-index: 6;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  transition: background .2s ease;
}
.carousel-pause:hover { background: rgba(15,22,30,0.75); }
.carousel-pause svg { width: 18px; height: 18px; }
.carousel-pause .icon-play { display: none; }
.carousel-pause[aria-pressed="true"] .icon-pause { display: none; }
.carousel-pause[aria-pressed="true"] .icon-play { display: block; }

/* Progress bar */
.carousel-progress {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: rgba(255,255,255,0.25);
  z-index: 5;
  overflow: hidden;
}
.carousel-progress > span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--saffron);
  transform-origin: left center;
  will-change: width;
}

/* Hide all carousel chrome — autoplay + swipe handle navigation */
.carousel-arrow,
.carousel-pause,
.carousel-dots {
  display: none;
}

/* Mobile: slimmer corners + slimmer progress bar */
@media (max-width: 640px) {
  .carousel {
    border-radius: 14px;
  }
  .carousel-progress {
    height: 2px;
  }
}

/* Accessibility: honor reduced motion — no Ken Burns, no crossfade */
@media (prefers-reduced-motion: reduce) {
  .carousel-slide { transition: none; }
  .carousel-slide.is-active img { animation: none; transform: none; }
  .carousel-progress > span { transition: none; }
}

/* Lightbox */
.lb {
  position: fixed; inset: 0;
  background: rgba(15, 22, 30, 0.88);
  display: none;
  align-items: center; justify-content: center;
  padding: 24px;
  z-index: 90;
  overflow: auto;
}
.lb.open { display: flex; }
.lb-inner {
  position: relative;
  max-width: min(1100px, 100%);
  max-height: 92vh;
  width: 100%;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.lb-inner img {
  max-width: 100%;
  max-height: 88vh;
  object-fit: contain;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
  background: #fff;
}
.lb-inner iframe {
  width: min(960px, 100%);
  aspect-ratio: 16 / 9;
  border: 0;
  border-radius: 12px;
  background: #000;
  box-shadow: 0 20px 60px rgba(0,0,0,0.4);
}
.lb-close {
  position: absolute;
  top: -14px; right: -14px;
  width: 44px; height: 44px;
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  border: none;
  font-size: 22px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(0,0,0,0.3);
}
@media (max-width: 640px) {
  .lb { padding: 12px; }
  .lb-close { top: 4px; right: 4px; }
}

/* Reveal-on-scroll */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity .7s ease, transform .7s ease; }
.reveal.visible { opacity: 1; transform: none; }

/* Tabs */
.tab-btn {
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 10px 20px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: background .2s, color .2s, border-color .2s;
  font-size: 16px;
}
.tab-btn:hover { background: var(--surface-2); }
.tab-btn[aria-selected="true"] {
  background: var(--sage);
  color: #fff;
  border-color: var(--sage);
}

/* Card hover */
.book-card { transition: transform .25s ease, box-shadow .25s ease; }
.book-card:hover { transform: translateY(-3px); box-shadow: 0 18px 36px rgba(31,42,55,0.12); }
button.book-card { display: flex; flex-direction: column; }

/* Mobile menu */
.mobile-menu {
  position: fixed; inset: 0;
  background: var(--bg);
  z-index: 80;
  transform: translateX(100%);
  transition: transform .3s ease;
  overflow-y: auto;
}
.mobile-menu.open { transform: translateX(0); }
.mobile-menu nav a,
.mobile-menu nav button {
  display: block;
  padding: 16px 24px;
  font-size: 18px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
  text-decoration: none;
  width: 100%;
  text-align: left;
  background: none;
  border-left: none; border-right: none; border-top: none;
}
.mobile-menu nav a:hover,
.mobile-menu nav button:hover {
  background: var(--surface-2);
  color: var(--sage-deep);
}

/* Accordion groups inside mobile menu */
.mobile-menu nav details.mm-group { border-bottom: 1px solid var(--line); }
.mobile-menu nav details.mm-group > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  font-size: 18px;
  color: var(--ink);
  cursor: pointer;
  list-style: none;
}
.mobile-menu nav details.mm-group > summary::-webkit-details-marker { display: none; }
.mobile-menu nav details.mm-group > summary::after {
  content: "";
  width: 10px; height: 10px;
  border-right: 2px solid var(--ink-soft);
  border-bottom: 2px solid var(--ink-soft);
  transform: rotate(45deg);
  transition: transform .25s ease;
  margin-left: 12px;
}
.mobile-menu nav details.mm-group[open] > summary::after { transform: rotate(-135deg); }
.mobile-menu nav details.mm-group > .mm-sub > a {
  padding: 12px 24px 12px 40px;
  font-size: 16px;
  border-bottom: none;
  color: var(--ink-soft);
}
.mobile-menu nav details.mm-group > .mm-sub > a:hover {
  background: var(--surface-2);
  color: var(--sage-deep);
}

/* Header dropdown */
.has-dropdown { position: relative; }
.has-dropdown > .dropdown {
  position: absolute;
  top: 100%; left: 0;
  background: var(--surface);
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 16px 36px rgba(31,42,55,0.10);
  padding: 8px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(6px);
  transition: opacity .18s, transform .18s;
  z-index: 50;
  /* Constrain to viewport so long menus stay reachable on short laptop screens */
  max-height: calc(100vh - 96px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
/* Right-align dropdowns marked as such so they don't overflow the viewport */
.has-dropdown > .dropdown.dropdown-right {
  left: auto;
  right: 0;
}
.has-dropdown:hover > .dropdown,
.has-dropdown:focus-within > .dropdown {
  opacity: 1;
  pointer-events: auto;
  transform: none;
}
.dropdown a {
  display: block;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 16px;
}
.dropdown a:hover { background: var(--surface-2); color: var(--sage-deep); }
/* Subtle scrollbar styling so long dropdowns feel native */
.dropdown::-webkit-scrollbar { width: 8px; }
.dropdown::-webkit-scrollbar-thumb {
  background: rgba(31,42,55,0.18);
  border-radius: 999px;
}
.dropdown::-webkit-scrollbar-thumb:hover { background: rgba(31,42,55,0.32); }
.dropdown::-webkit-scrollbar-track { background: transparent; }

/* Aspect helpers */
.aspect-book { aspect-ratio: 644 / 420; }
.aspect-tile { aspect-ratio: 300 / 214; }
.aspect-tile-img { aspect-ratio: 300 / 156; }
.aspect-hero { aspect-ratio: 1440 / 507; }
.aspect-portrait { aspect-ratio: 723 / 527; }
.aspect-video { aspect-ratio: 16 / 9; }

/* Prose for Sinhala body */
.prose-si p { margin: 0 0 1.1em; text-align: justify; }
.prose-si p:last-child { margin-bottom: 0; }

/* Header */
.site-header {
  position: sticky; top: 0;
  background: rgba(250, 247, 242, 0.92);
  backdrop-filter: saturate(140%) blur(8px);
  -webkit-backdrop-filter: saturate(140%) blur(8px);
  border-bottom: 1px solid var(--line);
  z-index: 60;
}

/* Search input */
.search-input {
  width: 100%;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  padding: 0 44px 0 18px;
  font-size: 16px;
  color: var(--ink);
  transition: border-color .2s, box-shadow .2s;
}
.search-input::placeholder { color: var(--ink-soft); }
.search-input:focus { outline: none; border-color: var(--sage); box-shadow: 0 0 0 4px rgba(61,122,106,0.15); }
.search-input:focus-visible { outline: none; }

/* Buttons */
.btn-primary {
  background: var(--sage);
  color: #fff;
  border: none;
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 8px;
  transition: background .2s, transform .2s;
}
.btn-primary:hover { background: var(--sage-deep); transform: translateY(-1px); color: #fff; }
.btn-outline {
  background: transparent;
  color: var(--sage-deep);
  border: 1px solid var(--sage);
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
  display: inline-flex; align-items: center; gap: 8px;
}
.btn-outline:hover { background: var(--sage); color: #fff; }

/* YouTube facade (lite-embed pattern) */
.yt-facade {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
  margin: 0;
  border: 0;
  background: #000;
  cursor: pointer;
  overflow: hidden;
  font: inherit;
  color: inherit;
}
.yt-facade img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transform: scale(1.03);
  transition: transform .35s ease, opacity .25s ease;
}
.yt-facade:hover img,
.yt-facade:focus-visible img { transform: scale(1.06); opacity: .92; }
.yt-facade::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(0,0,0,0) 55%, rgba(0,0,0,0.45) 100%);
  pointer-events: none;
}
.yt-facade .yt-play {
  position: absolute;
  top: 50%; left: 50%;
  width: 72px; height: 72px;
  transform: translate(-50%, -50%);
  border-radius: 999px;
  background: rgba(197,139,58,0.92);
  display: grid;
  place-items: center;
  color: #fff;
  box-shadow: 0 8px 24px rgba(0,0,0,0.35);
  transition: background .2s, transform .2s;
  pointer-events: none;
}
.yt-facade:hover .yt-play,
.yt-facade:focus-visible .yt-play {
  background: var(--sage);
  transform: translate(-50%, -50%) scale(1.06);
}
.yt-facade .yt-play svg { width: 28px; height: 28px; margin-left: 4px; }
.yt-facade.is-loaded { cursor: default; }
.yt-facade.is-loaded::before,
.yt-facade.is-loaded .yt-play,
.yt-facade.is-loaded img { display: none; }

/* Thripitaka search */
[data-tp-card][hidden] { display: none !important; }
.tp-search-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 22px 20px;
  box-shadow: 0 10px 30px rgba(31,42,55,0.06);
}
.tp-no-results {
  text-align: center;
  color: var(--ink-soft);
  padding: 32px 16px;
  font-size: 17px;
}
.tp-count {
  text-align: center;
  color: var(--ink-soft);
  font-size: 14px;
  margin-top: 10px;
}
mark.tp-hl {
  background: rgba(197,139,58,0.25);
  color: inherit;
  border-radius: 3px;
  padding: 0 2px;
}

/* Print-friendly */
@media print {
  .site-header, .site-footer, .lb, .carousel-arrow, .carousel-dots, .carousel-pause, .carousel-progress { display: none !important; }
}
