/* Vazirmatn is SIL OFL and self-hosted (a CDN would be unreliable here).
   IRANYekan / IRANSans are proprietary, so they are only *referenced* -- used
   when the visitor already has them installed, never shipped by us. Drop
   licensed .woff2 files into /fonts and add @font-face rules to enable them. */
@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-400.woff2") format("woff2");
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-500.woff2") format("woff2");
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: "Vazirmatn";
  src: url("/fonts/Vazirmatn-700.woff2") format("woff2");
  font-weight: 700; font-style: normal; font-display: swap;
}

:root {
  --font-fa: "IRANYekanX", "IRANYekan", "IRANSans", "Vazirmatn",
             Tahoma, "Segoe UI", system-ui, -apple-system, sans-serif;
  --bg: #0d0f14;
  --panel: #151922;
  --panel-2: #1b2029;
  --line: #262c38;
  --text: #e8eaf0;
  --muted: #8b93a5;
  --gold: #d4af37;
  --gold-soft: rgba(212, 175, 55, .12);
  --up: #2ecc71;
  --down: #ff5f56;
  --radius: 14px;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f7fa;
    --panel: #ffffff;
    --panel-2: #f2f4f8;
    --line: #e3e7ee;
    --text: #161a22;
    --muted: #666f80;
    --gold-soft: rgba(212, 175, 55, .16);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-fa);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.wrap { width: min(1180px, 100% - 2rem); margin-inline: auto; }

/* ---------- header ---------- */
.topbar {
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--panel) 85%, transparent);
  position: sticky; top: 0; z-index: 10;
  backdrop-filter: blur(8px);
}
.topbar .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; padding: .85rem 0; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: .6rem; }
.brand h1 { font-size: 1.35rem; margin: 0; letter-spacing: .5px; }
.brand .dot {
  width: 12px; height: 12px; border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #f5d76e, var(--gold));
  box-shadow: 0 0 0 4px var(--gold-soft);
}
.brandLogo {
  flex: none;
  width: clamp(34px, 8vw, 48px);
  height: auto;
  display: block;
  filter: drop-shadow(0 1px 1px rgba(0, 0, 0, .3));
}
.tag { color: var(--muted); font-size: .82rem; }
.meta { display: flex; align-items: center; gap: .75rem; font-size: .82rem; color: var(--muted); }

.unit {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 999px; padding: .3rem .8rem; cursor: pointer; font: inherit; font-size: .8rem;
}
.unit:hover { border-color: var(--gold); }

.status { display: inline-flex; align-items: center; gap: .4rem; }
.pulse {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
  box-shadow: 0 0 0 0 currentColor;
}
.status.live .pulse { background: var(--up); animation: pulse 2s infinite; }
.status.stale .pulse { background: var(--down); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(46, 204, 113, .5); }
  70% { box-shadow: 0 0 0 7px rgba(46, 204, 113, 0); }
  100% { box-shadow: 0 0 0 0 rgba(46, 204, 113, 0); }
}
@media (prefers-reduced-motion: reduce) { .status.live .pulse { animation: none; } }

/* ---------- chart ---------- */
.chartCard {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem; margin: 1.4rem 0;
  min-width: 0;
}
.chartHead {
  display: flex; justify-content: space-between; align-items: flex-start;
  gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem;
}
.chartHead > div:first-child { min-width: 0; }
.chartHead h2 { margin: 0; font-size: 1.05rem; }
.sub { margin: .15rem 0 0; color: var(--muted); font-size: .85rem; }

.ranges { display: flex; gap: .3rem; flex-wrap: wrap; }
.ranges button {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  border-radius: 999px; padding: .3rem .7rem; cursor: pointer; font: inherit; font-size: .78rem;
}
.ranges button:hover { color: var(--text); }
.ranges button.on { background: var(--gold-soft); border-color: var(--gold); color: var(--gold); }

/* Chart.js sizes the canvas from this box, so it must have a resolved width and
   height. `min-width: 0` keeps it from being pinned to the canvas's intrinsic
   300px if it ever ends up inside a flex/grid parent. */
.canvasBox {
  position: relative;
  width: 100%;
  min-width: 0;
  height: clamp(240px, 34vw, 360px);
}
.canvasBox > canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

.empty { text-align: center; color: var(--muted); padding: 1.5rem 0; font-size: .9rem; }
.hidden { display: none; }

/* ---------- tabs ---------- */
.tabs {
  display: flex; gap: .35rem; margin: 1.4rem 0 0;
  border-bottom: 1px solid var(--line);
}
.tabs button {
  background: none; border: 0; border-bottom: 2px solid transparent;
  color: var(--muted); font: inherit; font-size: .95rem; font-weight: 500;
  padding: .6rem 1rem; cursor: pointer; margin-bottom: -1px;
}
.tabs button:hover { color: var(--text); }
.tabs button.on { color: var(--gold); border-bottom-color: var(--gold); }

/* ---------- sentiment ---------- */
.badge {
  border-radius: 999px; padding: .35rem .85rem; font-size: .82rem; font-weight: 700;
  border: 1px solid currentColor;
}
.badge.up { color: var(--up); background: rgba(46,204,113,.1); }
.badge.down { color: var(--down); background: rgba(255,95,86,.1); }
.badge.flat, .badge.mixed { color: var(--muted); background: var(--panel-2); }

.gauge { margin: .4rem 0 1.1rem; }
.gaugeBar {
  display: flex; height: 10px; border-radius: 999px; overflow: hidden;
  background: var(--panel-2); border: 1px solid var(--line);
}
.gaugeBar span { display: block; height: 100%; transition: width .4s; }
#gBull { background: var(--up); }
#gNeut { background: var(--muted); opacity: .45; }
#gBear { background: var(--down); }
.gaugeKey {
  display: flex; gap: 1.2rem; flex-wrap: wrap;
  margin-top: .55rem; color: var(--muted); font-size: .82rem;
}
.gaugeKey b { color: var(--text); font-variant-numeric: tabular-nums; }
.k { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-inline-end: .3rem; }
.k.up { background: var(--up); } .k.down { background: var(--down); }
.k.flat { background: var(--muted); opacity: .45; }

.summary { margin: 0 0 1rem; line-height: 2; }
.subhead { font-size: .85rem; color: var(--muted); margin: 1.2rem 0 .6rem; font-weight: 600; }

.themes { display: grid; gap: .55rem; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.theme {
  background: var(--panel-2); border: 1px solid var(--line);
  border-radius: 10px; padding: .7rem .8rem;
  border-inline-start: 3px solid var(--muted);
}
.theme.up { border-inline-start-color: var(--up); }
.theme.down { border-inline-start-color: var(--down); }
.theme h4 { margin: 0 0 .25rem; font-size: .9rem; }
.theme p { margin: 0; color: var(--muted); font-size: .8rem; line-height: 1.8; }
.theme .cnt { float: left; color: var(--muted); font-size: .75rem; }

.claims { list-style: none; padding: 0; margin: 0; display: grid; gap: .45rem; }
.claims li {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: .6rem .75rem; font-size: .86rem; display: flex; gap: .6rem; align-items: flex-start;
}
.cred { flex: 0 0 auto; font-size: .72rem; border-radius: 999px; padding: .1rem .5rem; border: 1px solid currentColor; }
.cred.low { color: var(--down); } .cred.medium { color: var(--gold); } .cred.high { color: var(--up); }

/* ---------- comments ---------- */
.comments { display: grid; gap: .6rem; }
.cmt { background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: .7rem .85rem; }
.cmt .meta {
  display: flex; gap: .6rem; align-items: center; flex-wrap: wrap;
  color: var(--muted); font-size: .76rem; margin-bottom: .35rem;
}
.cmt .who { color: var(--gold); font-weight: 600; }
.cmt .body { font-size: .9rem; line-height: 1.95; overflow-wrap: anywhere; }

.moreBtn {
  width: 100%; margin-top: .8rem; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem; cursor: pointer; font: inherit;
  font-size: .85rem;
}
.moreBtn:hover { border-color: var(--gold); color: var(--gold); }
.moreBtn[disabled] { opacity: .5; cursor: default; }

.note {
  margin: .9rem 0 0; padding-top: .8rem; border-top: 1px solid var(--line);
  color: var(--muted); font-size: .82rem; line-height: 1.9;
}
.note a { color: var(--gold); }
.note code {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: .1rem .4rem; font-size: .8rem; direction: ltr; display: inline-block;
}
#compareSub b { font-weight: 700; }

/* ---------- rate cards ---------- */
.group { margin: 1.6rem 0; }
.group h3 {
  font-size: .9rem; color: var(--muted); font-weight: 600;
  margin: 0 0 .7rem; display: flex; align-items: center; gap: .5rem;
}
.group h3::after { content: ""; flex: 1; height: 1px; background: var(--line); }

.grid { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: .85rem .95rem; cursor: pointer; text-align: right;
  font: inherit; color: inherit; width: 100%;
  transition: border-color .15s, transform .15s;
}
.card:hover { border-color: var(--gold); transform: translateY(-2px); }
.card.active { border-color: var(--gold); background: var(--gold-soft); }
.card .name { color: var(--muted); font-size: .8rem; }
.card .val { font-size: 1.2rem; font-weight: 700; font-variant-numeric: tabular-nums; margin-top: .2rem; }
.card .unit { font-size: .72rem; color: var(--muted); margin-inline-start: .25rem; font-weight: 400; }
.card .chg { font-size: .76rem; margin-top: .2rem; font-variant-numeric: tabular-nums; }
.chg.up { color: var(--up); }
.chg.down { color: var(--down); }
.chg.flat { color: var(--muted); }

.foot {
  display: flex; justify-content: space-between; align-items: center;
  color: var(--muted); font-size: .8rem; padding: 1.5rem 0; border-top: 1px solid var(--line); margin-top: 2rem;
}
.foot a { color: var(--gold); text-decoration: none; }

/* ---------- prediction game ---------- */
.predScore { text-align: left; display: flex; flex-direction: column; gap: .15rem; }
.predScore .who { color: var(--gold); font-weight: 700; }
.predScore .sc { color: var(--muted); font-size: .82rem; font-variant-numeric: tabular-nums; }

.priceNow {
  text-align: center; background: var(--panel-2); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem; margin: .6rem 0 1rem;
}
.priceNow .lbl { color: var(--muted); font-size: .85rem; }
.priceVal { margin-top: .35rem; }
.priceVal b { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.priceVal .unit { color: var(--muted); font-size: .85rem; margin-inline-start: .35rem; }

.predQ { text-align: center; font-size: 1rem; margin: .2rem 0 1rem; }

.guessBtns { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.guess {
  border: 1px solid currentColor; border-radius: 12px; padding: 1rem;
  font: inherit; font-size: 1.1rem; font-weight: 700; cursor: pointer;
  transition: transform .12s, filter .12s;
}
.guess:hover:not([disabled]) { transform: translateY(-2px); filter: brightness(1.1); }
.guess.up { color: #fff; background: var(--up); border-color: var(--up); }
.guess.down { color: #fff; background: var(--down); border-color: var(--down); }
.guess[disabled] { opacity: .45; cursor: default; }
.guess.chosen { outline: 3px solid var(--gold); outline-offset: 2px; opacity: 1; }

.predMsg {
  margin: 1rem 0 0; padding: .7rem .85rem; border-radius: 10px; font-size: .88rem;
  background: var(--panel-2); border: 1px solid var(--line); text-align: center;
}
.predMsg.on { border-color: var(--gold); color: var(--gold); }
.predMsg.err { border-color: var(--down); color: var(--down); }

.predLast {
  margin: 1rem 0 0; padding: .6rem .85rem; border-radius: 10px; font-size: .84rem;
  border: 1px solid var(--line); text-align: center; font-variant-numeric: tabular-nums;
}
.predLast.up { border-inline-start: 3px solid var(--up); }
.predLast.down { border-inline-start: 3px solid var(--down); }

#predCrowd { margin-top: 1.4rem; }
#cUp { background: var(--up); }
#cDown { background: var(--down); }
.gaugeKey .muted { color: var(--muted); }

/* auth (mobile → OTP → name) */
.authStep { display: flex; flex-direction: column; gap: .55rem; max-width: 340px; }
.fLbl { color: var(--muted); font-size: .85rem; }
.fInput {
  background: var(--panel-2); border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: .7rem .85rem; font: inherit; font-size: 1rem;
}
.fInput:focus { outline: none; border-color: var(--gold); }
#codeInput { letter-spacing: .5em; text-align: center; }
.fBtn {
  background: var(--gold); color: #1a1400; border: 0; border-radius: 10px;
  padding: .7rem; font: inherit; font-weight: 700; cursor: pointer;
}
.fBtn:hover { filter: brightness(1.05); }
.fBtn[disabled] { opacity: .5; cursor: default; }
.fLink {
  background: none; border: 0; color: var(--muted); font: inherit; font-size: .82rem;
  cursor: pointer; text-decoration: underline; padding: 0;
}
.fLink:hover { color: var(--gold); }
.authMsg { margin: .8rem 0 0; font-size: .85rem; color: var(--muted); }
.authMsg.err { color: var(--down); }

/* leaderboard */
.lbWrap { overflow-x: auto; }
table.lb { width: 100%; border-collapse: collapse; font-size: .9rem; }
table.lb th, table.lb td { padding: .6rem .7rem; text-align: right; }
table.lb th { color: var(--muted); font-weight: 600; font-size: .82rem; border-bottom: 1px solid var(--line); }
table.lb td { border-bottom: 1px solid var(--line); }
table.lb td.rank, table.lb td.score { font-variant-numeric: tabular-nums; }
table.lb td.score { color: var(--gold); font-weight: 700; }
table.lb tr.meRow td { background: var(--gold-soft); }

/* ---------- responsive ---------- */
@media (max-width: 760px) {
  .chartCard { padding: .85rem; border-radius: 12px; }
  .chartHead { gap: .6rem; }
  .chartHead h2 { font-size: .98rem; }
  .sub { font-size: .78rem; }

  /* Six range buttons don't fit; scroll them instead of wrapping to two rows. */
  .ranges {
    flex-wrap: nowrap;
    overflow-x: auto;
    scrollbar-width: none;
    margin-inline: -.85rem;
    padding-inline: .85rem;
    width: calc(100% + 1.7rem);
  }
  .ranges::-webkit-scrollbar { display: none; }
  .ranges button { flex: 0 0 auto; }

  .grid { grid-template-columns: repeat(auto-fill, minmax(145px, 1fr)); gap: .55rem; }
  .card { padding: .7rem .75rem; }
  .card .val { font-size: 1.05rem; }
}

@media (max-width: 420px) {
  .tag { display: none; }
  .brand h1 { font-size: 1.15rem; }
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .canvasBox { height: 250px; }
}
