/* ==========================================================================
   MAITHILI DIGITAL COMMONS - Core Design System & Tokens
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Lora:ital,wght@0,400;0,500;0,600;0,700;1,400;1,600&family=Noto+Sans+Devanagari:wght@400;500;600;700&family=Noto+Serif+Devanagari:wght@400;500;600;700;800&family=Noto+Sans+Kaithi&family=Noto+Sans+Tirhuta&display=swap');

/* ==========================================================================
   SELF-HOSTED WEB FONTS - Tirhuta (Mithilakshar) & Kaithi
   Guarantees 100% rendering across all browsers, operating systems, and
   offline/ad-blocked environments without missing-glyph tofu or giant 'X'.
   ========================================================================== */

/* Tirhuta / Mithilakshar Regular */
@font-face {
  font-family: 'Noto Sans Tirhuta';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: local('Noto Sans Tirhuta'),
       local('NotoSansTirhuta'),
       local('Noto Sans Tirhuta Regular'),
       url('/static/fonts/NotoSansTirhuta-Regular.woff2') format('woff2'),
       url('/static/fonts/NotoSansTirhuta-Regular.ttf') format('truetype');
  unicode-range: U+0951-0952, U+0964-0965, U+09F4-09F7, U+1CD5, U+1CE2, U+1CF2, U+200C-200D, U+25CC, U+A830-A839, U+11480-114DF;
}

/* Tirhuta Bold synthesis mapping: prevents browser fallback to Latin bold on strong/h1-h6 */
@font-face {
  font-family: 'Noto Sans Tirhuta';
  font-style: normal;
  font-weight: 500 900;
  font-display: swap;
  src: local('Noto Sans Tirhuta'),
       local('NotoSansTirhuta'),
       url('/static/fonts/NotoSansTirhuta-Regular.woff2') format('woff2'),
       url('/static/fonts/NotoSansTirhuta-Regular.ttf') format('truetype');
  unicode-range: U+0951-0952, U+0964-0965, U+09F4-09F7, U+1CD5, U+1CE2, U+1CF2, U+200C-200D, U+25CC, U+A830-A839, U+11480-114DF;
}

/* Kaithi Regular */
@font-face {
  font-family: 'Noto Sans Kaithi';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: local('Noto Sans Kaithi'),
       local('NotoSansKaithi'),
       local('Noto Sans Kaithi Regular'),
       url('/static/fonts/NotoSansKaithi-Regular.woff2') format('woff2'),
       url('/static/fonts/NotoSansKaithi-Regular.ttf') format('truetype');
  unicode-range: U+0966-096F, U+200C-200D, U+2010, U+25CC, U+2E31, U+A830-A839, U+11080-110CF;
}

/* Kaithi Bold synthesis mapping */
@font-face {
  font-family: 'Noto Sans Kaithi';
  font-style: normal;
  font-weight: 500 900;
  font-display: swap;
  src: local('Noto Sans Kaithi'),
       local('NotoSansKaithi'),
       url('/static/fonts/NotoSansKaithi-Regular.woff2') format('woff2'),
       url('/static/fonts/NotoSansKaithi-Regular.ttf') format('truetype');
  unicode-range: U+0966-096F, U+200C-200D, U+2010, U+25CC, U+2E31, U+A830-A839, U+11080-110CF;
}

:root {
  /* Sober Literary Cultural Color Palette */
  --color-terracotta: #8F341F;
  --color-terracotta-dark: #702514;
  --color-terracotta-light: #F7EFE9;
  
  --color-indigo: #253344;
  --color-indigo-dark: #192330;
  --color-indigo-light: #EDF3F8;
  --color-indigo-text: #253344;

  --color-primary-700: #702514;
  --color-primary-200: #F1DCD6;

  --color-gold: #B67823;
  --color-gold-light: #FAF5EB;
  --color-gold-bright: #C7862B;

  --color-emerald: #2E7D5B;
  --color-emerald-light: #EDF7F2;

  /* Surfaces & Warm Book Paper Backgrounds */
  --bg-parchment: #FAF7F2;
  --bg-surface: #FFFFFF;
  --bg-surface-elevated: #FFFFFF;
  --bg-surface-subtle: #F4EFE7;

  /* Text & Classical Book Press Ink */
  --text-primary: #211E1A;
  --text-secondary: #58534C;
  --text-tertiary: #8C867D;
  --text-inverted: #FFFFFF;

  /* Borders & Dividers */
  --border-subtle: #E8E2D6;
  --border-medium: #D2C9BD;
  --border-focus: #8F341F;

  /* Aliases for legacy template variables */
  --color-bg-card: var(--bg-surface);
  --color-border: var(--border-subtle);
  --color-border-subtle: var(--border-subtle);

  /* Shadows - subtle, refined paper elevation */
  --shadow-xs: 0 1px 2px 0 rgba(33, 30, 26, 0.03);
  --shadow-sm: 0 1px 3px 0 rgba(33, 30, 26, 0.05), 0 1px 2px -1px rgba(33, 30, 26, 0.04);
  --shadow-md: 0 4px 6px -1px rgba(33, 30, 26, 0.06), 0 2px 4px -2px rgba(33, 30, 26, 0.04);
  --shadow-lg: 0 10px 15px -3px rgba(33, 30, 26, 0.06), 0 4px 6px -4px rgba(33, 30, 26, 0.03);
  --shadow-xl: 0 20px 25px -5px rgba(33, 30, 26, 0.07), 0 8px 10px -6px rgba(33, 30, 26, 0.04);

  /* Literary Typography Stack */
  --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-devanagari: 'Noto Sans Devanagari', 'Inter', system-ui, sans-serif;
  --font-serif: 'Lora', 'Georgia', 'Cambria', serif;
  --font-serif-devanagari: 'Noto Serif Devanagari', 'Lora', 'Georgia', serif;
  --font-literary: 'Noto Serif Devanagari', 'Lora', 'Georgia', serif;
  --font-display: 'Noto Serif Devanagari', 'Lora', 'Georgia', serif;
  --font-tirhuta: 'Noto Sans Tirhuta', 'Mithila', 'Tirhuta', 'Noto Sans Devanagari', sans-serif;
  --font-kaithi: 'Noto Sans Kaithi', 'Kaithi', 'Noto Sans Devanagari', sans-serif;

  /* Layout */
  --container-max-width: 1240px;
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-normal: 250ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* Dark Theme Variables - Sober Library Night */
[data-theme="dark"] {
  --bg-parchment: #13171E;
  --bg-surface: #19202B;
  --bg-surface-elevated: #212A38;
  --bg-surface-subtle: #242E3D;

  --text-primary: #EDE9E3;
  --text-secondary: #A6A097;
  --text-tertiary: #757067;

  --border-subtle: #283344;
  --border-medium: #39475D;

  --color-terracotta: #D9755F;
  --color-terracotta-dark: #B85842;
  --color-terracotta-light: rgba(217, 117, 95, 0.16);
  --color-indigo: #8EA4BF;
  --color-indigo-text: #A8BCD4;
  --color-indigo-light: rgba(142, 164, 191, 0.16);
  --color-gold: #D69742;
  --color-gold-light: rgba(214, 151, 66, 0.16);
  --color-gold-bright: #E5A852;

  --color-primary-700: #FFA38F;
  --color-primary-200: #4B261D;
}

/* Global Dark Mode High-Contrast Protections for Hardcoded Inlines */
[data-theme="dark"] [style*="color: var(--color-indigo)" i],
[data-theme="dark"] [style*="color:var(--color-indigo)" i] {
  color: #93C5FD !important;
}

[data-theme="dark"] [style*="color: #111827" i],
[data-theme="dark"] [style*="color:#111827" i],
[data-theme="dark"] [style*="color: #1F2937" i],
[data-theme="dark"] [style*="color:#1F2937" i],
[data-theme="dark"] [style*="color: #18202F" i],
[data-theme="dark"] [style*="color:#18202F" i],
[data-theme="dark"] [style*="color: #2D3748" i],
[data-theme="dark"] [style*="color:#2D3748" i],
[data-theme="dark"] [style*="color: #1a202c" i],
[data-theme="dark"] [style*="color:#1a202c" i],
[data-theme="dark"] [style*="color: #000" i],
[data-theme="dark"] [style*="color:#000" i],
[data-theme="dark"] [style*="color: #000000" i],
[data-theme="dark"] [style*="color:#000000" i],
[data-theme="dark"] [style*="color: black" i],
[data-theme="dark"] [style*="color:black" i],
[data-theme="dark"] [style*="color: #222" i],
[data-theme="dark"] [style*="color:#222" i],
[data-theme="dark"] [style*="color: #333" i],
[data-theme="dark"] [style*="color:#333" i] {
  color: var(--text-primary) !important;
}

[data-theme="dark"] [style*="color: #374151" i],
[data-theme="dark"] [style*="color:#374151" i],
[data-theme="dark"] [style*="color: #4B5563" i],
[data-theme="dark"] [style*="color:#4B5563" i],
[data-theme="dark"] [style*="color: #4b5563" i],
[data-theme="dark"] [style*="color:#4b5563" i],
[data-theme="dark"] [style*="color: #4a5568" i],
[data-theme="dark"] [style*="color:#4a5568" i] {
  color: var(--text-secondary) !important;
}

[data-theme="dark"] [style*="color: #6B7280" i],
[data-theme="dark"] [style*="color:#6B7280" i],
[data-theme="dark"] [style*="color: #9CA3AF" i],
[data-theme="dark"] [style*="color:#9CA3AF" i],
[data-theme="dark"] [style*="color: #718096" i],
[data-theme="dark"] [style*="color:#718096" i] {
  color: var(--text-tertiary) !important;
}

[data-theme="dark"] [style*="color: #059669" i],
[data-theme="dark"] [style*="color:#059669" i],
[data-theme="dark"] [style*="color: #047857" i],
[data-theme="dark"] [style*="color:#047857" i],
[data-theme="dark"] [style*="color: #065F46" i],
[data-theme="dark"] [style*="color:#065F46" i],
[data-theme="dark"] [style*="color: #2e7d32" i],
[data-theme="dark"] [style*="color:#2e7d32" i] {
  color: #34D399 !important;
}

[data-theme="dark"] [style*="color: #b45309" i],
[data-theme="dark"] [style*="color:#b45309" i],
[data-theme="dark"] [style*="color: #92400E" i],
[data-theme="dark"] [style*="color:#92400E" i],
[data-theme="dark"] [style*="color: #D97706" i],
[data-theme="dark"] [style*="color:#D97706" i] {
  color: #FCD34D !important;
}

[data-theme="dark"] [style*="color: #1E40AF" i],
[data-theme="dark"] [style*="color:#1E40AF" i],
[data-theme="dark"] [style*="color: #1D4ED8" i],
[data-theme="dark"] [style*="color:#1D4ED8" i],
[data-theme="dark"] [style*="color: #2563EB" i],
[data-theme="dark"] [style*="color:#2563EB" i],
[data-theme="dark"] [style*="color: #2563eb" i],
[data-theme="dark"] [style*="color:#2563eb" i],
[data-theme="dark"] [style*="color: #3730A3" i],
[data-theme="dark"] [style*="color:#3730A3" i],
[data-theme="dark"] [style*="color: #4338CA" i],
[data-theme="dark"] [style*="color:#4338CA" i],
[data-theme="dark"] [style*="color: #4F46E5" i],
[data-theme="dark"] [style*="color:#4F46E5" i] {
  color: #93C5FD !important;
}

/* Ensure containers and surfaces with hardcoded light backgrounds adapt in dark mode */
[data-theme="dark"] [style*="background: #ffffff" i],
[data-theme="dark"] [style*="background:#ffffff" i],
[data-theme="dark"] [style*="background: #fff" i],
[data-theme="dark"] [style*="background:#fff" i],
[data-theme="dark"] [style*="background: white" i],
[data-theme="dark"] [style*="background:white" i] {
  background: var(--bg-surface) !important;
  border-color: var(--border-subtle) !important;
}

[data-theme="dark"] [style*="background: #FAFAFA" i],
[data-theme="dark"] [style*="background:#FAFAFA" i],
[data-theme="dark"] [style*="background: #F9FAFB" i],
[data-theme="dark"] [style*="background:#F9FAFB" i],
[data-theme="dark"] [style*="background: #F3F4F6" i],
[data-theme="dark"] [style*="background:#F3F4F6" i],
[data-theme="dark"] [style*="background: #e0e0e0" i],
[data-theme="dark"] [style*="background:#e0e0e0" i] {
  background: var(--bg-surface-subtle) !important;
  border-color: var(--border-subtle) !important;
}

/* Hardcoded Light Badge Background Adaptations */
[data-theme="dark"] [style*="background: #EFF6FF" i],
[data-theme="dark"] [style*="background:#EFF6FF" i],
[data-theme="dark"] [style*="background: #eff6ff" i],
[data-theme="dark"] [style*="background:#eff6ff" i],
[data-theme="dark"] [style*="background: #EEF2FF" i],
[data-theme="dark"] [style*="background:#EEF2FF" i],
[data-theme="dark"] [style*="background: #e0e7ff" i],
[data-theme="dark"] [style*="background:#e0e7ff" i],
[data-theme="dark"] [style*="background: #E0E7FF" i],
[data-theme="dark"] [style*="background:#E0E7FF" i] {
  background: rgba(96, 165, 250, 0.18) !important;
  color: #93C5FD !important;
}

[data-theme="dark"] [style*="background: #ECFDF5" i],
[data-theme="dark"] [style*="background:#ECFDF5" i] {
  background: rgba(16, 185, 129, 0.18) !important;
  color: #34D399 !important;
}

[data-theme="dark"] [style*="background: #FEF3C7" i],
[data-theme="dark"] [style*="background:#FEF3C7" i],
[data-theme="dark"] [style*="background: #FFFBEB" i],
[data-theme="dark"] [style*="background:#FFFBEB" i] {
  background: rgba(245, 158, 11, 0.2) !important;
  color: #FCD34D !important;
}

[data-theme="dark"] [style*="background: #fee2e2" i],
[data-theme="dark"] [style*="background:#fee2e2" i],
[data-theme="dark"] [style*="background: #FEE2E2" i],
[data-theme="dark"] [style*="background:#FEE2E2" i] {
  background: rgba(239, 68, 68, 0.2) !important;
  color: #FCA5A5 !important;
}

/* Border Adaptations */
[data-theme="dark"] [style*="border: 1px solid #E5E7EB" i],
[data-theme="dark"] [style*="border:1px solid #E5E7EB" i],
[data-theme="dark"] [style*="border: 1px solid #e5e7eb" i],
[data-theme="dark"] [style*="border:1px solid #e5e7eb" i],
[data-theme="dark"] [style*="border: 2px solid #e5e7eb" i],
[data-theme="dark"] [style*="border: 2px solid #E5E7EB" i],
[data-theme="dark"] [style*="border: 1px solid #D1D5DB" i],
[data-theme="dark"] [style*="border:1px solid #D1D5DB" i],
[data-theme="dark"] [style*="border: 1px solid #d1d5db" i],
[data-theme="dark"] [style*="border:1px solid #d1d5db" i],
[data-theme="dark"] [style*="border: 1px solid #F3F4F6" i],
[data-theme="dark"] [style*="border: 1px solid #f3f4f6" i],
[data-theme="dark"] [style*="border-top: 1px solid #F3F4F6" i],
[data-theme="dark"] [style*="border-top: 1px solid #f3f4f6" i],
[data-theme="dark"] [style*="border-top: 1px solid #E5E7EB" i],
[data-theme="dark"] [style*="border-top: 1px solid #e5e7eb" i],
[data-theme="dark"] [style*="border-bottom: 1px solid #F3F4F6" i],
[data-theme="dark"] [style*="border-bottom: 1px solid #f3f4f6" i],
[data-theme="dark"] [style*="border-bottom: 1px solid #E5E7EB" i],
[data-theme="dark"] [style*="border-bottom: 1px solid #e5e7eb" i],
[data-theme="dark"] [style*="border-bottom: 2px solid #E5E7EB" i],
[data-theme="dark"] [style*="border-bottom: 2px solid #e5e7eb" i] {
  border-color: var(--border-subtle) !important;
}

/* Reset & Base Elements */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-family: var(--font-sans);
  background-color: var(--bg-parchment);
  color: var(--text-primary);
  line-height: 1.6;
  scroll-behavior: smooth;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

main {
  flex: 1 0 auto;
}

img, svg {
  display: block;
  max-width: 100%;
}

a {
  color: var(--color-terracotta);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--color-terracotta-dark);
}

/* Devanagari Enhancement Classes */
.lang-mai, .devanagari-text {
  font-family: var(--font-devanagari);
  line-height: 1.7;
}

/* Script Typography Utilities (Mithilakshar / Tirhuta & Kaithi) */
.font-tirhuta, .tirhuta-font {
  font-family: var(--font-tirhuta) !important;
  font-synthesis: weight style;
}

.font-kaithi, .kaithi-font {
  font-family: var(--font-kaithi) !important;
  font-synthesis: weight style;
}

/* Grid & Layout Utilities */
.container {
  width: 100%;
  max-width: var(--container-max-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

.section {
  padding-top: 5rem;
  padding-bottom: 5rem;
}

.section-sm {
  padding-top: 3rem;
  padding-bottom: 3rem;
}

.section-header {
  text-align: center;
  max-width: 760px;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 3.5rem;
}

.section-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.85rem;
  font-size: 0.825rem;
  font-weight: 600;
  border-radius: var(--radius-full);
  background-color: var(--color-terracotta-light);
  color: var(--color-terracotta);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* Headings & Display Typography */
h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--text-primary);
  line-height: 1.3;
}

h1 {
  font-weight: 700;
  letter-spacing: -0.015em;
}

h2 {
  font-weight: 700;
  letter-spacing: -0.01em;
}

h3 {
  font-weight: 600;
}

.section-title {
  font-family: var(--font-display);
  font-size: 2.25rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.25;
  margin-bottom: 0.75rem;
  letter-spacing: -0.015em;
}

.section-subtitle {
  font-size: 1.125rem;
  color: var(--text-secondary);
}

/* Accessibility Focus Ring */
:focus-visible {
  outline: 2px solid var(--color-terracotta);
  outline-offset: 2px;
}

/* Responsive Grid */
.grid {
  display: grid;
  gap: 1.5rem;
}

.grid-cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (max-width: 1024px) {
  .grid-cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 640px) {
  .grid-cols-4, .grid-cols-3, .grid-cols-2 { grid-template-columns: 1fr; }
  .section { padding-top: 3.5rem; padding-bottom: 3.5rem; }
  .section-title { font-size: 1.85rem; }
}
