/**
 * The Natural Bridge — Translation Page
 * Paper Redesign: Phase 2 Slice 10 (2026-05-01)
 *
 * RULES:
 *   - Zero backdrop-filter / blur() anywhere in this file
 *   - Background: #100e0c dark onyx desk
 *   - Cover + section-headers: aged-manila (#f5f0e4) with 3px double border-bottom
 *   - Section bodies: white paper (#ffffff)
 *   - Hard-offset box-shadow — NO blur radius
 *   - Fonts: Michroma for all headings/labels, Spectral for body/content
 *   - Colour tokens: var(--ink-primary) navy, var(--ink-accent) blue
 */

/* ── BODY + DOCUMENT ─────────────────────────────────────────────────────── */

.tnb-body {
  /* Inherits --page-desk-wash from body[data-atmosphere] so cloud sky bleeds through */
  background: var(--page-desk-wash, #100e0c);
  min-height: 100vh;
  /* nav rail padding applied by navigation.js */
}

/* Scope body color reset so Spectral/Michroma render with ink tones on paper */
.tnb-body,
.tnb-body * {
  box-sizing: border-box;
}

.tnb-document {
  max-width: 900px;
  margin: 0 auto;
  padding: 2.5rem 1.5rem 5rem;
  color: #1a1a2e; /* ink-primary fallback */
}

/* ── DOCUMENT COVER (aged manila) ────────────────────────────────────────── */

.tnb-cover {
  background: #f5f0e4;
  border: 2px solid #1a1a2e;
  border-bottom: 3px double #1a1a2e;
  box-shadow: 8px 8px 0 #1a1a2e;
  padding: 2.5rem 2.5rem 2rem;
  margin-bottom: 2rem;
  color: #1a1a2e;
}

.tnb-cover-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  font-family: 'Michroma', monospace;
  font-size: 0.68rem;
  color: #666;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tnb-doc-number {
  font-weight: 400;
}

.tnb-cover-classification {
  font-weight: 400;
}

.tnb-cover-title {
  font-family: 'Michroma', monospace;
  font-size: clamp(1.5rem, 3.5vw, 2.25rem);
  color: #1a1a2e;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin: 0 0 0.4rem 0;
  font-weight: 400;
  line-height: 1.15;
}

.tnb-cover-subtitle {
  font-family: 'Spectral', serif;
  font-style: italic;
  font-size: 1rem;
  color: #555;
  margin: 0 0 1.75rem 0;
  letter-spacing: 0.04em;
}

/* 2×2 field table matching prophecy / archives pattern */
.tnb-cover-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border: 1px solid #1a1a2e;
}

.tnb-cover-field {
  padding: 0.7rem 1.1rem;
  border-right: 1px solid rgba(26, 26, 46, 0.25);
  border-bottom: 1px solid rgba(26, 26, 46, 0.18);
}

.tnb-cover-field:nth-child(even) {
  border-right: none;
}

.tnb-cover-field:nth-last-child(-n+2) {
  border-bottom: none;
}

.tcf-label {
  display: block;
  font-family: 'Michroma', monospace;
  font-size: 0.6rem;
  color: #777;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.tcf-value {
  display: block;
  font-family: 'Spectral', serif;
  font-size: 0.95rem;
  color: #1a1a2e;
  font-weight: 600;
}

/* Coverage line — populated by fetchCoverage() */
.tnb-coverage-line {
  font-family: 'Michroma', monospace;
  font-size: 0.68rem;
  color: #777;
  letter-spacing: 0.06em;
  margin: 1rem 0 0 0;
  padding-top: 0.85rem;
  border-top: 1px solid rgba(26, 26, 46, 0.15);
  min-height: 1.4em; /* reserve space so header doesn't jump */
}

/* ── SECTION WRAPPER ─────────────────────────────────────────────────────── */

.tnb-section {
  margin-bottom: 2rem;
  box-shadow: 6px 6px 0 #1a1a2e;
}

/* Aged-manila section header with double-rule border — the signature pattern */
.tnb-section-header {
  background: #f5f0e4;
  border: 2px solid #1a1a2e;
  border-bottom: 3px double #1a1a2e;
  padding: 0.85rem 1.5rem;
}

.tnb-section-title {
  font-family: 'Michroma', monospace;
  font-size: 0.78rem;
  color: #1a1a2e;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  margin: 0;
  font-weight: 400;
}

/* White paper body */
.tnb-section-body {
  background: #ffffff;
  border: 2px solid #1a1a2e;
  border-top: none;
  padding: 1.75rem 1.75rem 2rem;
  color: #1a1a2e;
}

.tnb-section-intro {
  font-family: 'Spectral', serif;
  font-size: 0.95rem;
  color: #555;
  line-height: 1.7;
  margin: 0 0 1.5rem 0;
}

/* ── HORIZON TABS ────────────────────────────────────────────────────────── */

/* Override any .horizon-tabs rules from components.css / prophecy.css */
.tnb-body .horizon-tabs {
  display: flex;
  gap: 0;
  margin-bottom: 1.5rem;
  border: 2px solid #1a1a2e;
  background: none;
  padding: 0;
  border-radius: 0;
  /* reset any backdrop-filter that components.css might set */
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.tnb-body .horizon-tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.3rem;
  flex: 1;
  padding: 0.75rem 0.4rem;
  background: #f5f0e4;
  border: none;
  border-right: 1px solid rgba(26, 26, 46, 0.25);
  cursor: pointer;
  transition: background 0.12s;
  font-family: 'Michroma', monospace;
  color: #666;
  border-radius: 0;
}

.tnb-body .horizon-tab:last-child {
  border-right: none;
}

.tnb-body .horizon-tab:hover {
  background: #ede8d8;
  color: #1a1a2e;
}

.tnb-body .horizon-tab.active {
  background: #1a1a2e;
  color: #f5f0e4;
}

.tnb-body .tab-icon {
  font-size: 1.2rem;
}

.tnb-body .tab-label {
  font-size: 0.6rem;
  font-weight: 400;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ── TRANSLATION DISPLAY ─────────────────────────────────────────────────── */

.translation-display {
  min-height: 180px;
  background: #fafafa;
  border: 1px solid rgba(26, 26, 46, 0.15);
  padding: 1.5rem;
  color: #1a1a2e;
}

/* ── Classes injected by translation-panel.js ── */

/* April 23 fix: renamed from .translation-content to avoid component collision */
.nb-display-content {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.source-prophecy-section {
  padding-bottom: 1.25rem;
  border-bottom: 2px solid rgba(26, 26, 46, 0.12);
}

.source-prophecy-section .source-label {
  display: block;
  font-family: 'Michroma', monospace;
  font-size: 0.65rem;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 0.5rem;
}

.source-prophecy-section .source-text {
  font-family: 'Spectral', serif;
  font-style: italic;
  font-size: 0.95rem;
  color: #555;
  line-height: 1.7;
  margin: 0;
}

.translated-prophecy-section {
  /* empty — content styled by children */
}

.translated-prophecy-section .translated-text {
  font-family: 'Spectral', serif;
  font-size: 1.1rem;
  line-height: 1.85;
  color: #1a1a2e;
  margin: 0 0 1rem 0;
}

.translation-meta {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding-top: 1rem;
  border-top: 1px solid rgba(26, 26, 46, 0.1);
}

.meta-row {
  display: flex;
  gap: 0.75rem;
  font-family: 'Spectral', serif;
  font-size: 0.82rem;
}

.meta-label {
  color: #777;
  font-style: italic;
  min-width: 90px;
  flex-shrink: 0;
}

.meta-value {
  color: #1a1a2e;
  font-weight: 600;
}

.cultural-notes-list {
  list-style: none;
  padding: 0;
  margin: 0.75rem 0 0 0;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.cultural-notes-list li {
  font-family: 'Spectral', serif;
  font-size: 0.88rem;
  color: #1a1a2e;
  padding: 0.4rem 0.7rem;
  border-left: 3px solid #1a3a6b;
  line-height: 1.55;
  background: rgba(26, 58, 107, 0.04);
}

/* ── LANGUAGE GRID ───────────────────────────────────────────────────────── */

.tnb-body .language-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 0;
  border: 2px solid #1a1a2e;
}

.tnb-body .language-btn {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.8rem 0.85rem;
  background: #f5f0e4;
  border: none;
  border-right: 1px solid rgba(26, 26, 46, 0.2);
  border-bottom: 1px solid rgba(26, 26, 46, 0.15);
  cursor: pointer;
  transition: background 0.12s;
  font-family: 'Spectral', serif;
  color: #1a1a2e;
  text-align: left;
  border-radius: 0;
}

/* Remove right border from every 5th (last in row) */
.tnb-body .language-btn:nth-child(5n) {
  border-right: none;
}

/* Remove bottom border from last row (items 6–10) */
.tnb-body .language-btn:nth-child(n+6) {
  border-bottom: none;
}

.tnb-body .language-btn:hover {
  background: #ede8d8;
}

.tnb-body .language-btn.active {
  background: #1a3a6b;
  color: #f5f0e4;
}

/* Unavailable language — applied by JS when coverage shows missing cell */
.tnb-body .language-btn.lang-unavailable {
  opacity: 0.45;
  cursor: not-allowed;
}

.tnb-body .lang-flag {
  font-size: 1.2rem;
  flex-shrink: 0;
  line-height: 1;
}

.tnb-body .lang-name {
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* ── STATS GRID ──────────────────────────────────────────────────────────── */

.tnb-body .stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  border: 2px solid #1a1a2e;
}

.tnb-body .stat-card {
  padding: 1.25rem 1rem;
  border-right: 1px solid rgba(26, 26, 46, 0.18);
  text-align: center;
  /* Ink-accent top border — the paper card signature */
  border-top: 3px solid #1a3a6b;
  background: #ffffff;
}

.tnb-body .stat-card:last-child {
  border-right: none;
}

.tnb-body .stat-value {
  font-family: 'Michroma', monospace;
  font-size: 1rem;
  color: #1a1a2e;
  font-weight: 400;
  margin-bottom: 0.4rem;
  word-break: break-word;
  line-height: 1.3;
}

.tnb-body .stat-label {
  font-family: 'Spectral', serif;
  font-size: 0.75rem;
  color: #777;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

/* ── LOADING STATE (inside translation-display) ──────────────────────────── */

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 3rem 1rem;
  gap: 1rem;
  color: #777;
  font-family: 'Spectral', serif;
  font-style: italic;
  font-size: 0.9rem;
}

.loading-state .spinner {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(26, 26, 46, 0.15);
  border-top-color: #1a1a2e;
  border-radius: 50%;
  animation: tnb-spin 1s linear infinite;
  flex-shrink: 0;
}

@keyframes tnb-spin {
  to { transform: rotate(360deg); }
}

/* ── CULTURAL NOTES (COLLAPSIBLE SECTION) ────────────────────────────────── */

/* The section itself uses .tnb-section but overrides the header as a button */
.cultural-notes-section {
  /* inherits from .tnb-section above */
}

.cultural-notes-toggle {
  display: block;
  width: 100%;
  background: #f5f0e4;
  border: 2px solid #1a1a2e;
  border-bottom: none;
  padding: 0.85rem 1.5rem;
  font-family: 'Michroma', monospace;
  font-size: 0.72rem;
  color: #1a1a2e;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
  border-radius: 0;
}

.cultural-notes-toggle:hover {
  background: #ede8d8;
}

.cultural-notes-content {
  background: #ffffff;
  border: 2px solid #1a1a2e;
  border-top: none;
  padding: 1.5rem 1.75rem;
  color: #1a1a2e;
  font-family: 'Spectral', serif;
  font-size: 0.92rem;
  line-height: 1.7;
}

/* ── LOADING OVERLAY (full-page blocking) ────────────────────────────────── */

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(16, 14, 12, 0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 10000;
  /* NO backdrop-filter */
}

.loading-content {
  text-align: center;
  padding: 2rem;
}

/* Overlay spinner (larger than inline) */
.loading-overlay .spinner {
  width: 48px;
  height: 48px;
  border: 3px solid rgba(245, 240, 228, 0.2);
  border-top-color: #f5f0e4;
  border-radius: 50%;
  animation: tnb-spin 1s linear infinite;
  margin: 0 auto 1.25rem;
}

.loading-message {
  font-family: 'Michroma', monospace;
  font-size: 0.82rem;
  color: #f5f0e4;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  animation: tnb-pulse 2s ease-in-out infinite;
}

@keyframes tnb-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* ── RESPONSIVE ──────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
  .tnb-document {
    padding: 1.25rem 0.75rem 3.5rem;
  }

  .tnb-cover {
    padding: 1.5rem 1.25rem 1.25rem;
    box-shadow: 5px 5px 0 #1a1a2e;
  }

  .tnb-cover-title {
    font-size: 1.4rem;
  }

  /* Stack cover fields to single column on mobile */
  .tnb-cover-fields {
    grid-template-columns: 1fr;
  }

  .tnb-cover-field {
    border-right: none;
    border-bottom: 1px solid rgba(26, 26, 46, 0.15);
  }

  .tnb-cover-field:last-child {
    border-bottom: none;
  }

  .tnb-section {
    box-shadow: 4px 4px 0 #1a1a2e;
  }

  .tnb-section-body {
    padding: 1.25rem 1rem 1.5rem;
  }

  /* Horizon tabs wrap on mobile */
  .tnb-body .horizon-tabs {
    flex-wrap: wrap;
  }

  .tnb-body .horizon-tab {
    flex: 1 1 30%;
    border-bottom: 1px solid rgba(26, 26, 46, 0.2);
    min-width: 80px;
  }

  /* Language grid: 2 columns on mobile */
  .tnb-body .language-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  /* Reset 5n right-border rule for 2-col layout */
  .tnb-body .language-btn:nth-child(5n) {
    border-right: 1px solid rgba(26, 26, 46, 0.2);
  }

  /* Apply 2-col right-border removal */
  .tnb-body .language-btn:nth-child(2n) {
    border-right: none;
  }

  /* Reset last-row bottom-border for 5-col (rows 6-10) */
  .tnb-body .language-btn:nth-child(n+6) {
    border-bottom: 1px solid rgba(26, 26, 46, 0.15);
  }

  /* Last row in 2-col = items 9–10 */
  .tnb-body .language-btn:nth-child(n+9) {
    border-bottom: none;
  }

  /* Stats: 2 columns */
  .tnb-body .stats-grid {
    grid-template-columns: 1fr 1fr;
  }

  .tnb-body .stat-card:nth-child(2n) {
    border-right: none;
  }

  .tnb-body .stat-card:nth-child(n+3) {
    border-top: 1px solid rgba(26, 26, 46, 0.15);
  }
}

@media (max-width: 480px) {
  .tnb-cover-title {
    font-size: 1.2rem;
  }

  /* Single column language grid on small phones */
  .tnb-body .language-grid {
    grid-template-columns: 1fr;
  }

  .tnb-body .language-btn {
    border-right: none;
    border-bottom: 1px solid rgba(26, 26, 46, 0.15);
  }

  .tnb-body .language-btn:last-child {
    border-bottom: none;
  }

  /* Reset all nth-child overrides for 1-col */
  .tnb-body .language-btn:nth-child(2n),
  .tnb-body .language-btn:nth-child(5n) {
    border-right: none;
  }

  .tnb-body .language-btn:nth-child(n+9),
  .tnb-body .language-btn:nth-child(n+6) {
    border-bottom: 1px solid rgba(26, 26, 46, 0.15);
  }

  /* 1 column stats on very small screens */
  .tnb-body .stats-grid {
    grid-template-columns: 1fr;
  }

  .tnb-body .stat-card {
    border-right: none;
    border-bottom: 1px solid rgba(26, 26, 46, 0.12);
  }

  .tnb-body .stat-card:last-child {
    border-bottom: none;
  }
}
