/* ==========================================================================
   Yeh-Chaia Shared Multi-Language Switcher, Popover & Multi-Script Typography
   ========================================================================== */

.lang-switcher {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(148, 163, 184, 0.2);
  border-radius: 20px;
  padding: 2px 3px;
}

.lang-btn {
  background: transparent;
  border: none;
  color: #cbd5e1;
  padding: 3px 9px;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.28rem;
  line-height: 1.25;
  white-space: nowrap;
  font-family: inherit;
  transition: background-color 0.15s, color 0.15s;
}

.lang-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.08);
}

.lang-btn.active {
  background: var(--primary, #f59e0b);
  color: #111827;
  font-weight: 700;
}

.lang-btn:focus-visible {
  outline: 2px solid var(--accent, #fbbf24);
  outline-offset: 2px;
}

.lang-sep {
  width: 1px;
  height: 12px;
  background: rgba(148, 163, 184, 0.28);
  margin: 0 1px;
  flex-shrink: 0;
}

.lang-more-btn {
  padding: 3px 8px;
}

.lang-more-btn[aria-expanded="true"]:not(.active) {
  background: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.lang-globe-icon,
.lang-chevron {
  flex-shrink: 0;
  display: block;
  transition: transform 0.15s;
}

.lang-more-btn[aria-expanded="true"] .lang-chevron {
  transform: rotate(180deg);
}

.lang-more-label[hidden] {
  display: none;
}

/* Popover fallback guard for browsers/polyfills lacking :popover-open */
@supports not selector(:popover-open) {
  .lang-popover:not(.\:popover-open) {
    display: none;
  }
}

.lang-popover {
  background: #0f172a;
  color: #f1f5f9;
  border: 1px solid #334155;
  border-radius: var(--radius-lg, 12px);
  padding: 0.35rem;
  min-inline-size: 196px;
  max-inline-size: min(260px, calc(100vw - 16px));
  max-block-size: min(360px, calc(100vh - 24px));
  overflow-y: auto;
  box-shadow: 0 16px 28px -6px rgb(0 0 0 / 0.65), 0 6px 12px -4px rgb(0 0 0 / 0.5);
  z-index: 1000;
}

.lang-popover:is(:popover-open, .\:popover-open) {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

@supports (position-area: block-end) {
  .lang-popover {
    inset: auto;
    margin: 0;
    margin-block-start: 6px;
    position-area: block-end span-inline-start;
    position-try-fallbacks: flip-inline, flip-block, flip-block flip-inline;
  }
}

@supports not (position-area: block-end) {
  .lang-popover {
    position: fixed;
    inset: auto;
    margin: 0;
  }
}

.lang-option {
  width: 100%;
  background: transparent;
  border: none;
  border-radius: var(--radius-md, 8px);
  padding: 0.45rem 0.6rem;
  color: #e2e8f0;
  font: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  text-align: start;
  transition: background-color 0.12s, color 0.12s;
}

.lang-option:hover {
  background: #1e293b;
  color: #ffffff;
}

.lang-option:focus-visible {
  outline: 2px solid var(--accent, #fbbf24);
  outline-offset: -2px;
}

.lang-option.active {
  background: rgba(245, 158, 11, 0.14);
  color: var(--accent, #fbbf24);
  font-weight: 700;
}

.lang-option-check {
  inline-size: 1rem;
  flex: none;
  text-align: center;
  color: var(--accent, #fbbf24);
  font-weight: 800;
}

.lang-option-endonym {
  flex: 1;
  min-inline-size: 0;
}

.lang-option-code {
  margin-inline-start: auto;
  font-family: monospace;
  font-size: 0.7rem;
  font-weight: 600;
  color: #94a3b8;
  text-transform: uppercase;
}

/* Multi-Script Typography Tuning */
html[data-script="latin"] body {
  font-size-adjust: from-font;
  letter-spacing: -0.005em;
  line-height: 1.55;
}

html[data-script="latin"] h1,
html[data-script="latin"] h2,
html[data-script="latin"] h3,
html[data-script="latin"] .spec-table thead th {
  text-wrap: balance;
}

html[data-script="latin"] .duty-callout,
html[data-script="latin"] .spec-disclaimer,
html[data-script="latin"] .spec-table tbody td,
html[data-script="latin"] .policy-card p,
html[data-script="latin"] .policy-list li {
  text-wrap: pretty;
}

html[data-script="tall"] body {
  line-height: 1.72;
}

.print-only-timestamp {
  display: none;
}

@media print {
  .lang-popover {
    display: none !important;
  }

  .print-only-timestamp {
    display: block !important;
    max-width: 1100px;
    margin: 0.55rem auto 0;
    padding-top: 0.45rem;
    border-top: 1px solid #334155;
    font-size: 0.72rem;
    color: #64748b;
    text-align: right;
    font-variant-numeric: tabular-nums;
  }
}
