/* ==========================================================================
   Itihasa — shared design system
   A reading room for Indian epics, styled after manuscript & temple motifs.
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Yatra+One&family=Hind:wght@400;500;600;700&family=Hind+Siliguri:wght@400;500;600&display=swap');

:root {
  /* --- Palette --- */
  --ink: #2b1b12;
  --ink-soft: #6b5642;
  --ink-faint: #9c8a76;
  --paper: #faf3e7;
  --paper-raised: #fffdf9;
  --line: #e7d7ba;
  --line-strong: #d8c29a;

  --primary: #7a1f2b;        /* temple maroon */
  --primary-dark: #591620;
  --primary-tint: #f4e3e0;

  --accent: #c1861f;         /* marigold gold */
  --accent-soft: #f0c975;
  --accent-tint: #fbf0d9;

  --secondary: #2c3e63;      /* dusk indigo, for "coming soon" state */
  --secondary-tint: #e6e9f0;

  /* --- Type --- */
  --font-display: 'Yatra One', 'Hind Siliguri', system-ui, serif;
  --font-body: 'Hind', 'Hind Siliguri', system-ui, -apple-system, sans-serif;

  /* --- Elevation --- */
  --shadow-sm: 0 1px 3px rgba(43, 27, 18, 0.08), 0 1px 2px rgba(43, 27, 18, 0.06);
  --shadow-md: 0 6px 20px rgba(43, 27, 18, 0.10), 0 2px 6px rgba(43, 27, 18, 0.06);
  --shadow-lg: 0 20px 45px rgba(43, 27, 18, 0.18);

  /* --- Shape --- */
  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 22px;

  --container: 1120px;
  --header-h: 68px;
}

* { box-sizing: border-box; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  font-family: var(--font-body);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 15% -10%, var(--accent-tint) 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, var(--primary-tint) 0%, transparent 50%),
    var(--paper);
  line-height: 1.6;
}

a { color: inherit; }

::selection {
  background: var(--accent-soft);
  color: var(--ink);
}

:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* --------------------------------------------------------------------
   Site header
   -------------------------------------------------------------------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-dark) 100%);
  box-shadow: var(--shadow-md);
  border-bottom: 3px solid var(--accent);
}

.site-header__inner {
  width: 100%;
  max-width: var(--container);
  height: var(--header-h);
  margin: 0 auto;
  padding: 0 20px;
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff8ec;
  flex: 1;
  min-width: 0;
}

.brand__mark {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
}

.brand__text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
  min-width: 0;
}

.brand__title {
  font-family: var(--font-display);
  font-size: 1.35rem;
  letter-spacing: 0.3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand__subtitle {
  font-size: 0.72rem;
  color: var(--accent-soft);
  letter-spacing: 0.4px;
  white-space: nowrap;
}

.header-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  color: #fff8ec;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  transition: background 0.2s ease, transform 0.2s ease;
  white-space: nowrap;
}

.header-back:hover {
  background: rgba(255, 255, 255, 0.22);
  transform: translateX(-2px);
}

/* --------------------------------------------------------------------
   Breadcrumb
   -------------------------------------------------------------------- */

.breadcrumb {
  max-width: var(--container);
  margin: 0 auto;
  width: 100%;
  padding: 14px 20px 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.breadcrumb a {
  text-decoration: none;
  color: var(--primary);
  font-weight: 600;
}

.breadcrumb a:hover { text-decoration: underline; }

.breadcrumb__sep {
  color: var(--ink-faint);
}

.breadcrumb__current {
  color: var(--ink-soft);
}

/* --------------------------------------------------------------------
   Main / page shell
   -------------------------------------------------------------------- */

main {
  flex: 1;
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 20px 20px 56px;
}

.page-hero {
  padding: 28px 4px 8px;
}

.page-hero__eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--primary);
  background: var(--primary-tint);
  padding: 5px 12px;
  border-radius: 999px;
  margin-bottom: 14px;
}

.page-hero h1 {
  font-family: var(--font-display);
  font-size: clamp(1.7rem, 4vw, 2.5rem);
  margin: 0 0 8px;
  color: var(--ink);
  line-height: 1.25;
}

.page-hero p {
  margin: 0;
  max-width: 62ch;
  color: var(--ink-soft);
  font-size: 1rem;
}

/* --------------------------------------------------------------------
   Grids & cards
   -------------------------------------------------------------------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
  margin-top: 22px;
}

.grid--languages {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  max-width: 640px;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  padding: 20px;
  text-align: left;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: transform 0.22s ease, box-shadow 0.22s ease, border-color 0.22s ease;
  text-decoration: none;
  color: inherit;
  overflow: hidden;
  min-width: 0;
}

.card:hover,
.card:focus-visible {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--accent-soft);
}

.card:active {
  transform: translateY(-1px);
}

.card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  min-width: 0;
}

.card__title {
  font-family: var(--font-display);
  font-size: 1.3rem;
  margin: 0;
  color: var(--ink);
  line-height: 1.3;
  overflow-wrap: break-word;
  word-break: break-word;
}

.card__subtitle {
  font-size: 0.86rem;
  color: var(--ink-soft);
  margin: 0;
  overflow-wrap: break-word;
}

.card__eyebrow {
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* status badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  padding: 4px 9px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}

.badge--available {
  background: var(--accent-tint);
  color: #8a5c0f;
}

.badge--soon {
  background: var(--secondary-tint);
  color: var(--secondary);
}

/* diya (lamp) signature icon: lit = available, unlit = coming soon */
.diya {
  width: 26px;
  height: 26px;
  flex-shrink: 0;
}

.diya .diya-flame {
  transform-origin: 13px 8px;
}

.diya--lit .diya-flame {
  fill: var(--accent);
  animation: diya-flicker 2.4s ease-in-out infinite;
}

.diya--lit .diya-glow {
  opacity: 1;
}

.diya--unlit .diya-flame {
  fill: var(--ink-faint);
  opacity: 0.5;
}

.diya--unlit .diya-glow {
  opacity: 0;
}

.diya-glow {
  opacity: 0;
  transition: opacity 0.3s ease;
}

@keyframes diya-flicker {
  0%, 100% { transform: scale(1) rotate(0deg); opacity: 1; }
  25%      { transform: scale(1.06) rotate(-2deg); opacity: 0.92; }
  50%      { transform: scale(0.97) rotate(1deg); opacity: 1; }
  75%      { transform: scale(1.04) rotate(2deg); opacity: 0.95; }
}

/* --------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: 999px;
  border: none;
  font-family: var(--font-body);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}

.btn--primary {
  background: var(--primary);
  color: #fff8ec;
  box-shadow: var(--shadow-sm);
}

.btn--primary:hover { background: var(--primary-dark); }

.btn--ghost {
  background: transparent;
  color: var(--primary);
  border: 1.5px solid var(--line-strong);
}

.btn--ghost:hover {
  background: var(--primary-tint);
  border-color: var(--primary);
}

.btn:disabled {
  background: #ece3d2;
  color: var(--ink-faint);
  cursor: not-allowed;
  box-shadow: none;
}

.btn:active:not(:disabled) { transform: translateY(1px); }

.btn--icon-only {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
}

/* --------------------------------------------------------------------
   Footer
   -------------------------------------------------------------------- */

.site-footer {
  border-top: 1px solid var(--line);
  background: var(--paper-raised);
  padding: 22px 20px 28px;
  text-align: center;
}

.site-footer__inner {
  max-width: var(--container);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.site-footer p {
  margin: 0;
  font-size: 0.82rem;
  color: var(--ink-faint);
}

.share-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: #25d366;
  color: #fff;
  border-radius: 999px;
  text-decoration: none;
  font-size: 0.85rem;
  font-weight: 600;
  transition: background 0.2s ease, transform 0.15s ease;
}

.share-btn:hover { background: #1da851; transform: translateY(-1px); }

/* --------------------------------------------------------------------
   Empty / error / loading states
   -------------------------------------------------------------------- */

.state-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 10px;
  padding: 48px 20px;
  color: var(--ink-soft);
}

.state-panel__icon {
  font-size: 2.2rem;
}

.skeleton {
  border-radius: var(--radius-md);
  background: linear-gradient(100deg, var(--line) 20%, var(--paper) 40%, var(--line) 60%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

@keyframes shimmer {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* --------------------------------------------------------------------
   Install toast
   -------------------------------------------------------------------- */

.install-toast {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 80;
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--primary);
  color: #fff8ec;
  padding: 10px 12px 10px 16px;
  border-radius: 999px;
  box-shadow: var(--shadow-lg);
  font-size: 0.88rem;
  font-weight: 600;
  animation: rise 0.3s ease;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.install-toast button {
  border: none;
  background: var(--accent);
  color: var(--ink);
  padding: 7px 13px;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.82rem;
}

.install-toast__dismiss {
  background: transparent !important;
  color: rgba(255,248,236,0.7) !important;
  font-size: 1.1rem !important;
  padding: 2px 6px !important;
  line-height: 1;
}

/* --------------------------------------------------------------------
   Reader (story.html)
   -------------------------------------------------------------------- */

/* The progress bar lives *inside* the sticky header box (see .site-header
   below) rather than as its own sticky sibling. Two independently-sticky
   elements stacked on top of each other can drift apart on mobile browsers
   when the address bar collapses/expands during scroll — the header slides
   away while the bar stays pinned to its old offset. Nesting it removes
   that failure mode entirely: there's only ever one sticky box. */
.progress-track {
  height: 4px;
  background: rgba(255, 255, 255, 0.25);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent-soft) 0%, var(--accent) 100%);
  transition: width 0.3s ease;
  width: 0%;
}

.reader {
  background: var(--paper-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: clamp(22px, 5vw, 48px);
  margin-top: 20px;
  position: relative;
}

.reader::before {
  content: "";
  position: absolute;
  inset: 10px;
  border: 1px solid var(--line);
  border-radius: calc(var(--radius-lg) - 6px);
  pointer-events: none;
  opacity: 0.6;
}

.reader-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px 10px;
  margin-bottom: 18px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  color: var(--ink-faint);
  min-width: 0;
}

.reader-meta span {
  overflow-wrap: break-word;
}

.story-text {
  font-size: 1.08rem;
  color: var(--ink);
  position: relative;
  z-index: 1;
}

.story-text p { margin: 0 0 1.1em; }
.story-text strong { color: var(--primary-dark); }
.story-text u { text-decoration-color: var(--accent); text-underline-offset: 3px; }

.story-text > p:first-of-type::first-letter {
  font-family: var(--font-display);
  font-size: 2.6rem;
  color: var(--primary);
  float: left;
  line-height: 1;
  padding-right: 8px;
  padding-top: 2px;
}

.reader-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 28px;
  flex-wrap: wrap;
}

.reader-nav__page {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-soft);
  min-width: 92px;
  text-align: center;
}

.jump-form {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
}

.jump-form input {
  width: 84px;
  padding: 9px 10px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius-sm);
  text-align: center;
  font-family: var(--font-body);
  font-size: 0.9rem;
  background: var(--paper-raised);
  color: var(--ink);
}

.jump-form input:focus {
  border-color: var(--accent);
}

.back-row {
  text-align: center;
  margin-top: 26px;
}

/* --------------------------------------------------------------------
   Responsive tweaks
   -------------------------------------------------------------------- */

@media (max-width: 480px) {
  .brand__subtitle { display: none; }
  .header-back span.label { display: none; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
}

@media (max-width: 380px) {
  .grid { grid-template-columns: 1fr; }
}
