/* ── Self-hosted Noto fonts – WOFF2 subsets (no Google Fonts, 0 third-party) ─ */
/* Sizes: NotoSans-R 33 KB, -B 32 KB, Nastaliq 144 KB, Naskh 52 KB, Devang 57 KB.
   unicode-range ensures browsers only download a font when characters in its
   script range are actually needed; tab labels use system-ui and don't trigger
   the heavy downloads on pages in other languages. */

@font-face {
  font-family: 'Noto Sans';
  src: url('/public/fonts/NotoSans-Regular.woff2') format('woff2'),
       url('/public/fonts/NotoSans-Regular.ttf')   format('truetype');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Noto Sans';
  src: url('/public/fonts/NotoSans-Bold.woff2') format('woff2'),
       url('/public/fonts/NotoSans-Bold.ttf')   format('truetype');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Noto Nastaliq Urdu';
  src: url('/public/fonts/NotoNastaliqUrdu-Regular.woff2') format('woff2'),
       url('/public/fonts/NotoNastaliqUrdu-Regular.ttf')   format('truetype');
  font-weight: 400; font-display: swap;
  unicode-range: U+0600-U+06FF, U+0750-U+077F, U+08A0-U+08FF,
                 U+FB50-U+FDFF, U+FE70-U+FEFF;
}
@font-face {
  font-family: 'Noto Naskh Arabic';
  src: url('/public/fonts/NotoNaskhArabic-Regular.woff2') format('woff2'),
       url('/public/fonts/NotoNaskhArabic-Regular.ttf')   format('truetype');
  font-weight: 400; font-display: swap;
  unicode-range: U+0600-U+06FF, U+0750-U+077F, U+FB50-U+FDFF, U+FE70-U+FEFF;
}
@font-face {
  font-family: 'Noto Sans Devanagari';
  src: url('/public/fonts/NotoSansDevanagari-Regular.woff2') format('woff2'),
       url('/public/fonts/NotoSansDevanagari-Regular.ttf')   format('truetype');
  font-weight: 400; font-display: swap;
  unicode-range: U+0900-U+097F, U+0980-U+09FF;
}

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

:root {
  --bg:        #0f172a;
  --bg-card:   #1e293b;
  --bg-hover:  #273549;
  --border:    #334155;
  --text:      #f1f5f9;
  --text-muted:#94a3b8;
  --accent:    #3b82f6;
  --accent-hov:#2563eb;
  --badge-bg:  #1d4ed8;
  --badge-txt: #bfdbfe;
  --radius:    12px;
  --radius-sm: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,.45);

  /* Language font stacks – Japanese uses system fonts (broad device support) */
  --font-en: 'Noto Sans', system-ui, sans-serif;
  --font-ur: 'Noto Nastaliq Urdu', serif;
  --font-hi: 'Noto Sans Devanagari', 'Noto Sans', sans-serif;
  --font-ar: 'Noto Naskh Arabic', 'Noto Sans', sans-serif;
  --font-de: 'Noto Sans', system-ui, sans-serif;
  --font-es: 'Noto Sans', system-ui, sans-serif;
  --font-ja: 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', 'Meiryo', 'Yu Gothic',
             'Noto Sans CJK JP', system-ui, sans-serif;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-en);
  min-height: 100dvh;
  overflow-x: hidden;
}

[lang=ur], [lang=ur] * { font-family: var(--font-ur); }
[lang=hi], [lang=hi] * { font-family: var(--font-hi); }
[lang=ar], [lang=ar] * { font-family: var(--font-ar); }
[lang=ja], [lang=ja] * { font-family: var(--font-ja); }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; max-width: 100%; }

/* ── Header ──────────────────────────────────────────────────────────────── */
.site-header {
  background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%);
  padding: .9rem 1.25rem;
  position: sticky; top: 0; z-index: 100;
  box-shadow: 0 2px 12px rgba(0,0,0,.4);
}
.header-inner {
  max-width: 72rem; margin: 0 auto;
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
}
.site-title { font-size: 1.15rem; font-weight: 700; color: #fff; display: flex; align-items: center; gap: .4rem; }
.globe { font-size: 1.3rem; }
.header-meta { font-size: .8rem; color: #bfdbfe; white-space: nowrap; }

/* ── Language tabs ───────────────────────────────────────────────────────── */
.lang-tabs {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.lang-tabs::-webkit-scrollbar { display: none; }
.lang-tab {
  padding: .75rem 1.1rem;
  font-size: .9rem; font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
  min-height: 44px; min-width: 44px;
  display: flex; align-items: center;
  flex-shrink: 0;
  /* Use system-ui for tab labels so they do NOT trigger heavy script font downloads */
  font-family: system-ui, sans-serif !important;
}
.lang-tab:hover { color: var(--text); text-decoration: none; }
.lang-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Toolbar ─────────────────────────────────────────────────────────────── */
.toolbar { background: var(--bg-card); border-bottom: 1px solid var(--border); padding: .6rem 1.25rem; }
.toolbar-inner {
  max-width: 72rem; margin: 0 auto;
  display: flex; align-items: center; gap: .75rem; flex-wrap: wrap;
}
.archive-label { font-size: .8rem; color: var(--text-muted); }
.archive-picker {
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: .35rem .6rem; font-size: .85rem;
  min-height: 44px; cursor: pointer;
}
.archive-picker:focus { outline: 2px solid var(--accent); }

.share-btns { display: flex; gap: .5rem; margin-left: auto; }
.btn-share {
  background: var(--bg); border: 1px solid var(--border); color: var(--text-muted);
  border-radius: var(--radius-sm); padding: .35rem .75rem; font-size: .8rem;
  min-height: 44px; min-width: 44px;
  display: flex; align-items: center;
  transition: color .15s, border-color .15s;
}
.btn-share:hover { color: var(--text); border-color: var(--accent); text-decoration: none; }

/* ── Board ───────────────────────────────────────────────────────────────── */
.board { max-width: 72rem; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.empty-state { color: var(--text-muted); padding: 3rem 0; text-align: center; }
.small-wiki-note { font-size: .85rem; color: var(--text-muted); margin-bottom: 1rem; font-style: italic; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  cursor: pointer;
  transition: background .15s, transform .12s, box-shadow .12s;
  position: relative;
}
.card:hover, .card:focus-visible {
  background: var(--bg-hover); transform: translateY(-2px); box-shadow: var(--shadow);
  outline: none;
}
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Hero */
.card-hero {
  display: grid; grid-template-columns: 240px 1fr;
  margin-bottom: 1.25rem; min-height: 220px;
}
@media (max-width: 580px) { .card-hero { grid-template-columns: 1fr; } }
[dir=rtl] .card-hero { grid-template-columns: 1fr 240px; }
@media (max-width: 580px) { [dir=rtl] .card-hero { grid-template-columns: 1fr; } }

/* Thumbnails */
.card-thumb { background: #1a2744; aspect-ratio: 4/3; overflow: hidden; }
.card-hero .card-thumb { aspect-ratio: auto; min-height: 220px; }
.card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb-placeholder {
  width: 100%; height: 100%; min-height: 120px;
  background: #1a2744;
  position: relative;
}
/* CSS-only vector placeholder: two diagonal lines + inner rectangle.
   No emoji, no canvas, no JS required for the initial render. */
.thumb-placeholder::before,
.thumb-placeholder::after {
  content: '';
  position: absolute;
  inset: 0;
}
.thumb-placeholder::before {
  background:
    linear-gradient(to bottom right, transparent calc(50% - .5px), #334155 calc(50% - .5px), #334155 calc(50% + .5px), transparent calc(50% + .5px)),
    linear-gradient(to bottom left,  transparent calc(50% - .5px), #334155 calc(50% - .5px), #334155 calc(50% + .5px), transparent calc(50% + .5px));
}
.thumb-placeholder::after {
  border: 1.5px solid #475569;
  margin: 28% 30%;
}
/* When img fails, the parent .card-thumb gets is-error class via JS */
.card-thumb.is-error img { display: none; }
.card-thumb.is-error .thumb-placeholder-auto {
  width: 100%; height: 100%; min-height: 120px;
  background: #1a2744; position: relative;
  display: block;
}

/* Card body */
.card-body { padding: .9rem 1rem; display: flex; flex-direction: column; gap: .45rem; }
.card-hero .card-body { padding: 1.1rem 1.25rem; gap: .6rem; }

/* Badge – always LTR */
.badge {
  display: inline-flex; align-items: center; gap: .15em;
  background: var(--badge-bg); color: var(--badge-txt);
  font-size: .75rem; font-weight: 700;
  padding: .2rem .55rem; border-radius: 99px;
  letter-spacing: .02em; width: fit-content;
  unicode-bidi: isolate; direction: ltr;
}

/* Views */
.card-views { font-size: .78rem; color: var(--text-muted); unicode-bidi: isolate; }

/* Why note */
.why-note { font-size: .8rem; color: #7dd3fc; font-style: italic; line-height: 1.4; }
.card-grid-item .why-note {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Sparkline */
.sparkline { width: 70px; height: 24px; flex-shrink: 0; }
.card-hero .sparkline { width: 100px; height: 32px; }
.sparkline-line { fill: none; stroke: var(--accent); stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sparkline-area { fill: rgba(59,130,246,.18); }

/* Titles */
.card-title { font-size: .95rem; font-weight: 700; color: var(--text); line-height: 1.3; }
.card-hero .card-title { font-size: 1.3rem; }

/* Grid */
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 1rem; }
@media (max-width: 480px) { .card-grid { grid-template-columns: 1fr 1fr; gap: .65rem; } }
.card-grid-item .card-thumb { aspect-ratio: 16/9; }
.card-grid-item .card-body { padding: .7rem .8rem; gap: .3rem; }
.card-grid-item .card-title { font-size: .88rem; }

/* ── Detail overlay ──────────────────────────────────────────────────────── */
.detail-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.7); z-index: 200;
  display: flex; align-items: flex-end; justify-content: center;
  backdrop-filter: blur(3px);
}
.detail-overlay[hidden] { display: none; }
.detail-panel {
  background: var(--bg-card); border-radius: var(--radius) var(--radius) 0 0;
  width: 100%; max-width: 680px; max-height: 90dvh;
  overflow-y: auto; padding: 1.5rem 1.5rem 2rem;
  position: relative; box-shadow: 0 -8px 40px rgba(0,0,0,.5);
  animation: slideUp .22s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
@media (min-width: 680px) {
  .detail-overlay { align-items: center; }
  .detail-panel { border-radius: var(--radius); max-height: 85dvh; }
}
.detail-close {
  position: absolute; top: .9rem; right: .9rem;
  background: var(--border); border: none; color: var(--text);
  font-size: 1.3rem; border-radius: 50%; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  min-width: 44px; min-height: 44px;
  transition: background .15s;
}
[dir=rtl] .detail-close { right: auto; left: .9rem; }
.detail-close:hover { background: var(--accent); }
.detail-thumb { width: 100%; max-height: 260px; object-fit: cover; border-radius: var(--radius-sm); margin-bottom: 1rem; }
.detail-content { display: flex; flex-direction: column; gap: .6rem; }
.detail-title { font-size: 1.2rem; font-weight: 700; line-height: 1.3; }
.detail-summary { font-size: .9rem; color: var(--text-muted); line-height: 1.6; }
.image-credit { font-size: .72rem; color: var(--text-muted); opacity: .75; }
.detail-link {
  display: inline-flex; align-items: center;
  background: var(--accent); color: #fff; padding: .55rem 1.1rem;
  border-radius: var(--radius-sm); font-weight: 600; font-size: .9rem;
  min-height: 44px; transition: background .15s;
}
.detail-link:hover { background: var(--accent-hov); text-decoration: none; }
.chart-wrap { background: var(--bg); border-radius: var(--radius-sm); padding: .75rem; }
#detail-chart { width: 100%; height: auto; }
.chart-line { fill: none; stroke: var(--accent); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.chart-area { fill: rgba(59,130,246,.15); }
.chart-dot  { fill: var(--accent); }
.chart-label { font-size: 10px; fill: var(--text-muted); }

/* ── Footer ──────────────────────────────────────────────────────────────── */
.site-footer {
  background: var(--bg-card); border-top: 1px solid var(--border);
  padding: 1.5rem 1.25rem; text-align: center;
  font-size: .78rem; color: var(--text-muted); line-height: 1.7;
}
.site-footer a { color: var(--text-muted); min-height: 44px; display: inline-flex; align-items: center; }
.site-footer a:hover { color: var(--accent); }

/* ── Error page ──────────────────────────────────────────────────────────── */
.error-wrap {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; min-height: 60dvh;
  padding: 3rem 1.5rem; text-align: center; gap: 1rem;
}
.error-msg { font-size: 1.2rem; font-weight: 700; color: #f1f5f9; }
.error-sub  { color: var(--text-muted); }
