/* ==========================================================================
   IQ Xchange — live rate board
   Self-hosted fonts, no external requests. Logical properties keep the whole
   layout working in both RTL (Arabic) and LTR (English).
   ========================================================================== */

@font-face {
  font-family: "Manrope";
  src: url("fonts/manrope-latin.woff2") format("woff2");
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Inter";
  src: url("fonts/inter-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Noto Kufi Arabic";
  src: url("fonts/noto-kufi-arabic.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --bg: #131313;
  --panel: #201f1f;
  --panel-2: #2a2a2a;
  --panel-3: #353534;
  --line: #4f4632;
  --gold: #f6c500;
  --gold-soft: #ffe5a0;
  --text: #e5e2e1;
  --muted: #d4c5ab;
  --down: #ffb4ab;
  --up: #7ee0a0;

  --font-head: "Manrope", "Noto Kufi Arabic", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-body: "Inter", "Noto Kufi Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;

  --radius: 14px;
  --pad: clamp(1.1rem, 2.2vw, 1.9rem);
  --gap: clamp(0.9rem, 1.6vw, 1.5rem);
  --ticker-h: 68px;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, p, ul, li { margin: 0; padding: 0; }
ul { list-style: none; }
a { color: inherit; }

/* several blocks are toggled from JS — keep `hidden` authoritative */
[hidden] { display: none !important; }

.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;
}

/* ------------------------------------------------------------------ topbar */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0 clamp(1rem, 3vw, 3rem);
  min-height: 84px;
  background: #131313;
  border-bottom: 1px solid rgba(79, 70, 50, 0.35);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  text-decoration: none;
  font-family: var(--font-head);
  text-transform: uppercase;
}

.brand-mark {
  background: var(--gold);
  color: #131313;
  font-weight: 800;
  font-size: 1.35rem;
  line-height: 1;
  padding: 0.35rem 0.5rem;
  border-radius: 8px;
  letter-spacing: -0.02em;
}

.brand-name {
  color: var(--text);
  font-weight: 700;
  font-size: 1.4rem;
  letter-spacing: -0.04em;
}

.topbar-tools {
  display: flex;
  align-items: center;
  gap: clamp(0.6rem, 1.6vw, 1.4rem);
}

.live-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.4rem 0.8rem;
  border-radius: 10px;
  background: var(--panel-3);
  border: 1px solid rgba(79, 70, 50, 0.45);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-soft);
  white-space: nowrap;
}

.live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 0 0 rgba(246, 197, 0, 0.5);
  animation: pulse 2.4s ease-out infinite;
}

.live-pill[data-state="offline"] { color: var(--down); }
.live-pill[data-state="offline"] .live-dot { background: var(--down); animation: none; }
.live-pill[data-state="degraded"] { color: var(--muted); }
.live-pill[data-state="degraded"] .live-dot { background: var(--muted); animation: none; }

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(246, 197, 0, 0.45); }
  70% { box-shadow: 0 0 0 9px rgba(246, 197, 0, 0); }
  100% { box-shadow: 0 0 0 0 rgba(246, 197, 0, 0); }
}

.clock {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text);
}

.clock svg { color: var(--gold-soft); opacity: 0.8; }

.clock time {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: clamp(1.1rem, 1.8vw, 1.4rem);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid rgba(79, 70, 50, 0.6);
  border-radius: 10px;
  overflow: hidden;
}

.lang-switch button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font-body);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.45rem 0.8rem;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.lang-switch button:hover { color: var(--gold-soft); }

.lang-switch button.is-active {
  background: var(--gold);
  color: #131313;
}

.lang-switch button:focus-visible {
  outline: 2px solid var(--gold-soft);
  outline-offset: -2px;
}

/* -------------------------------------------------------------------- page */
.page {
  flex: 1;
  padding: clamp(1.2rem, 2.6vw, 2.4rem) clamp(1rem, 3vw, 3rem);
  display: flex;
  flex-direction: column;
  gap: clamp(1rem, 2vw, 1.8rem);
  background: var(--panel);
}

.page-head { display: flex; flex-direction: column; gap: 0.35rem; }

.kicker {
  color: var(--muted);
  font-size: clamp(0.72rem, 1.1vw, 0.9rem);
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0.75;
}

.page-title {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: clamp(1.9rem, 3.4vw, 2.9rem);
  line-height: 1.1;
  letter-spacing: -0.03em;
  color: #fff;
}

.page-note {
  color: var(--muted);
  font-size: clamp(0.78rem, 1.1vw, 0.9rem);
  opacity: 0.72;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: baseline;
}

.page-note-sep { opacity: 0.45; }
.updated { font-variant-numeric: tabular-nums; }

.feed-note {
  margin-top: 0.6rem;
  padding-inline-start: 0.7rem;
  border-inline-start: 2px solid rgba(246, 197, 0, 0.45);
  color: var(--gold-soft);
  font-size: clamp(0.74rem, 1vw, 0.84rem);
  opacity: 0.85;
}

/* -------------------------------------------------------------------- grid */
.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: var(--gap);
  align-items: stretch;
}

.card {
  grid-column: span 4;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: var(--pad);
  background: var(--panel-2);
  border: 1px solid rgba(79, 70, 50, 0.22);
  border-radius: var(--radius);
  overflow: hidden;
  min-height: 190px;
}

.card-hero {
  grid-row: span 2;
  grid-column: span 4;
  background:
    linear-gradient(150deg, rgba(255, 224, 139, 0.1) 0%, rgba(241, 193, 0, 0) 55%),
    var(--panel-3);
  border-bottom: 4px solid var(--gold);
  justify-content: space-between;
}

.card-official {
  background: var(--panel);
  border-color: rgba(79, 70, 50, 0.35);
}

.card-list { justify-content: flex-start; gap: 0.7rem; }

.card-ghost {
  position: absolute;
  inset-block-end: -3rem;
  inset-inline-end: -3rem;
  width: 15rem;
  height: 15rem;
  color: var(--gold);
  opacity: 0.06;
  pointer-events: none;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.8rem;
}

.card-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: clamp(1.35rem, 2vw, 1.75rem);
  line-height: 1.15;
  color: #fff;
  letter-spacing: -0.02em;
}

.card-title-lg { font-size: clamp(1.7rem, 2.6vw, 2.3rem); font-weight: 800; }

.card-tag {
  display: inline-block;
  margin-top: 0.35rem;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  background: rgba(246, 197, 0, 0.12);
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.card-official .card-tag {
  background: rgba(212, 197, 171, 0.1);
  color: var(--muted);
}

.tier-badge {
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--muted);
  border: 1px solid rgba(79, 70, 50, 0.6);
  border-radius: 6px;
  padding: 0.2rem 0.4rem;
  white-space: nowrap;
  opacity: 0.85;
}

.tier-badge[data-tier="LOCAL"] {
  color: #131313;
  background: var(--gold);
  border-color: var(--gold);
}

.card-body { display: flex; flex-direction: column; gap: 0.15rem; }

.value {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: clamp(2.4rem, 4.4vw, 3.5rem);
  line-height: 1;
  letter-spacing: -0.035em;
  color: var(--gold);
  font-variant-numeric: tabular-nums;
}

.value-xl {
  font-size: clamp(3.4rem, 7vw, 5.6rem);
  margin-block: 0.35rem;
}

.value-unit {
  color: var(--muted);
  font-size: clamp(0.8rem, 1.15vw, 0.95rem);
  opacity: 0.75;
}

.card-quote {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  background: rgba(19, 19, 19, 0.55);
  border: 1px solid rgba(246, 197, 0, 0.28);
  font-size: 0.78rem;
  color: var(--muted);
}

.quote-label {
  margin-inline-end: auto;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  opacity: 0.75;
}

.quote-value {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: clamp(1rem, 1.6vw, 1.25rem);
  color: var(--gold-soft);
  font-variant-numeric: tabular-nums;
}

.quote-markup {
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  opacity: 0.7;
}

.card-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.6rem;
  margin-top: auto;
  font-size: 0.78rem;
  color: var(--muted);
}

.card-foot-muted { opacity: 0.6; }
.note { font-size: 0.72rem; }

.delta {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  opacity: 0.8;
}

.delta.is-up { color: var(--up); opacity: 1; }
.delta.is-down { color: var(--down); opacity: 1; }

.asof { font-variant-numeric: tabular-nums; opacity: 0.65; }

/* number change feedback — only the changed digits animate */
@keyframes flash-up {
  0% { color: var(--up); transform: translateY(-1px); }
  100% { color: var(--gold); transform: none; }
}

@keyframes flash-down {
  0% { color: var(--down); transform: translateY(1px); }
  100% { color: var(--gold); transform: none; }
}

.value.is-flash-up { animation: flash-up 900ms ease-out; }
.value.is-flash-down { animation: flash-down 900ms ease-out; }

/* ------------------------------------------------------------------- lists */
.card-list-title {
  font-family: var(--font-head);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.card-list-sub {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  opacity: 0.6;
  font-family: var(--font-body);
  font-weight: 600;
}

.rate-list { display: flex; flex-direction: column; }

.rate-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding-block: 0.62rem;
  border-bottom: 1px solid rgba(79, 70, 50, 0.2);
}

.rate-list li:last-child { border-bottom: 0; }

.row-name {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: clamp(1rem, 1.4vw, 1.2rem);
  color: #fff;
  letter-spacing: -0.01em;
}

.rate-list-cur .row-name {
  font-family: var(--font-body);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.row-right {
  display: inline-flex;
  align-items: baseline;
  gap: 0.6rem;
}

.row-value {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: clamp(1.15rem, 1.8vw, 1.5rem);
  color: var(--gold);
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.rate-list-cur .row-value { font-size: clamp(1rem, 1.5vw, 1.2rem); }

.row-badge {
  font-size: 0.58rem;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: var(--muted);
  opacity: 0.55;
  min-width: 2.6rem;
  text-align: end;
}

.row-badge[data-tier="LOCAL"] { color: var(--gold); opacity: 0.9; }

.disclaimer {
  color: var(--muted);
  font-size: 0.74rem;
  opacity: 0.5;
  text-align: center;
  padding-block-end: 0.2rem;
}

/* ------------------------------------------------------------------ ticker */
.ticker {
  display: flex;
  align-items: stretch;
  min-height: var(--ticker-h);
  background: rgba(19, 19, 19, 0.94);
  border-top: 1px solid rgba(246, 197, 0, 0.18);
  box-shadow: 0 -10px 40px rgba(246, 197, 0, 0.05);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

.ticker-label {
  display: inline-flex;
  align-items: center;
  gap: 0.55rem;
  padding-inline: clamp(1rem, 2.4vw, 2.4rem) 1.2rem;
  color: var(--gold);
  font-family: var(--font-head);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  white-space: nowrap;
  background: var(--bg);
  z-index: 1;
}

.ticker-label svg { flex: none; }

.ticker-view { flex: 1; overflow: hidden; display: flex; align-items: center; }

.ticker-track {
  display: inline-flex;
  align-items: center;
  gap: 3rem;
  white-space: nowrap;
  will-change: transform;
  animation: marquee var(--marquee-duration, 60s) linear infinite;
}

.ticker:hover .ticker-track,
.ticker-track:focus-within { animation-play-state: paused; }

@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(-50%); }
}

[dir="rtl"] .ticker-track { animation-name: marquee-rtl; }

@keyframes marquee-rtl {
  from { transform: translateX(0); }
  to { transform: translateX(50%); }
}

.ticker-item {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.95rem;
  color: var(--text);
  text-decoration: none;
}

.ticker-item::after {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--gold);
  opacity: 0.35;
  margin-inline-start: 1rem;
}

.ticker-src {
  color: var(--gold);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  white-space: nowrap;
}

.ticker-text { white-space: nowrap; }

a.ticker-item:hover .ticker-text { color: var(--gold-soft); }

/* -------------------------------------------------------------- responsive */
@media (max-width: 1080px) {
  .card,
  .card-hero { grid-column: span 6; }
  .card-hero { grid-row: auto; }
}

@media (max-width: 720px) {
  .topbar {
    flex-wrap: wrap;
    min-height: auto;
    padding-block: 0.7rem;
    gap: 0.6rem;
  }
  .brand-name { font-size: 1.15rem; }
  .brand-mark { font-size: 1.1rem; }
  .topbar-tools { gap: 0.5rem; }
  .clock time { font-size: 1rem; }
  .live-pill { font-size: 0.62rem; padding: 0.3rem 0.55rem; }
  .card, .card-hero { grid-column: span 12; }
  .value-xl { font-size: clamp(2.9rem, 15vw, 4rem); }
  .ticker { min-height: 58px; }
  .ticker-label { font-size: 0.66rem; padding-inline: 0.9rem; }
  .ticker-item { font-size: 0.85rem; }
}

@media (prefers-reduced-motion: reduce) {
  .ticker-track { animation: none !important; }
  .live-dot { animation: none; }
  .value.is-flash-up,
  .value.is-flash-down { animation: none; }
}