@font-face {
  font-family: Cairo;
  src: url("/fonts/cairo-variable.woff2") format("woff2");
  font-weight: 200 1000;
  font-style: normal;
  font-display: swap;
}

:root {
  color-scheme: dark;
  --bg: #0b0d12;
  --card: #141821;
  --inset: #1b202b;
  --line: #272d3a;
  --text: #eef1f6;
  --muted: #9aa3b2;
  --faint: #6f7888;
  --up: #34d399;
  --up-soft: rgba(52, 211, 153, .13);
  --down: #f87171;
  --down-soft: rgba(248, 113, 113, .13);
  --accent: #7cb7ff;
  --accent-soft: rgba(124, 183, 255, .13);
  --warn: #fbbf24;
  --warn-soft: rgba(251, 191, 36, .12);
  --radius: 16px;
  --gap: 14px;
}
@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --bg: #f3f5f9;
    --card: #ffffff;
    --inset: #f0f3f8;
    --line: #dde3ec;
    --text: #131722;
    --muted: #586174;
    --faint: #8490a3;
    --up: #0b8f61;
    --up-soft: rgba(11, 143, 97, .11);
    --down: #d23b48;
    --down-soft: rgba(210, 59, 72, .10);
    --accent: #2563eb;
    --accent-soft: rgba(37, 99, 235, .10);
    --warn: #a86a08;
    --warn-soft: rgba(168, 106, 8, .11);
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Cairo, "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  padding-bottom: env(safe-area-inset-bottom);
}
h1, h2, p, dl, dd, ul { margin: 0; padding: 0; }
ul { list-style: none; }
button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
small { font-size: 12.5px; color: var(--muted); font-weight: 500; }
b, strong { font-weight: 700; }
[hidden] { display: none !important; }
[dir="ltr"] { unicode-bidi: isolate; }
.muted { color: var(--muted); font-size: 12.5px; }
.up { color: var(--up); }
.down { color: var(--down); }
time, .num, dd, #price { font-variant-numeric: tabular-nums; }

/* ---------- top bar ---------- */
.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand > div { display: grid; line-height: 1.25; }
.brand b { font-size: 16px; font-weight: 800; }
.brand small { font-size: 10.5px; letter-spacing: .04em; color: var(--faint); }
.logo {
  width: 36px; height: 36px; flex: none; display: grid; place-items: center;
  border-radius: 11px; background: var(--accent-soft); color: var(--accent);
}
.logo svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linejoin: round; stroke-linecap: round; }
.quote { margin-inline-start: auto; display: grid; justify-items: end; line-height: 1.2; }
.quote small { font-size: 11px; }
.quote-line { display: flex; align-items: baseline; gap: 6px; direction: ltr; }
#price { font-size: 22px; font-weight: 800; letter-spacing: -.01em; }
#price.frozen { color: var(--muted); }
.tick { font-size: 13px; font-weight: 800; width: 12px; text-align: center; }
.tick.up { color: var(--up); }
.tick.down { color: var(--down); }
.conn {
  display: inline-flex; align-items: center; gap: 7px; flex: none;
  padding: 5px 11px; border-radius: 999px;
  background: var(--inset); border: 1px solid var(--line);
  font-size: 12.5px; font-weight: 700; color: var(--muted);
}
.conn i { width: 8px; height: 8px; border-radius: 50%; background: var(--faint); }
.conn[data-state="live"] { color: var(--up); }
.conn[data-state="live"] i { background: var(--up); box-shadow: 0 0 0 4px var(--up-soft); }
.conn[data-state="stale"] { color: var(--warn); }
.conn[data-state="stale"] i { background: var(--warn); }
.conn[data-state="down"] { color: var(--down); }
.conn[data-state="down"] i { background: var(--down); }

.banner {
  margin: 12px 16px 0; padding: 10px 14px; border-radius: 12px;
  background: var(--warn-soft); color: var(--warn);
  border: 1px solid color-mix(in srgb, var(--warn) 35%, transparent);
  font-size: 13.5px; font-weight: 600;
}

/* ---------- layout ---------- */
.grid {
  display: grid; gap: var(--gap);
  grid-template-columns: minmax(0, 1fr);
  max-width: 1240px; margin: 0 auto; padding: 14px 16px 8px;
}
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; min-width: 0;
}
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 12px; }
.card-head h2 { font-size: 16px; font-weight: 800; }
.note { margin-top: 12px; font-size: 12.5px; color: var(--muted); line-height: 1.7; }

@media (min-width: 920px) {
  .grid { grid-template-columns: repeat(12, minmax(0, 1fr)); padding-top: 18px; --gap: 16px; }
  .trade { grid-column: span 5; }
  .chart-card { grid-column: span 7; }
  .engine, .perf { grid-column: span 6; }
  .log { grid-column: span 12; }
  .card { padding: 20px; }
}

/* ---------- trade card ---------- */
.trade { position: relative; overflow: hidden; display: flex; flex-direction: column; }
.trade::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px; background: var(--line);
}
.trade[data-tone="up"]::before { background: var(--up); }
.trade[data-tone="down"]::before { background: var(--down); }
.trade[data-tone="up"] { background: linear-gradient(180deg, var(--up-soft), transparent 55%), var(--card); }
.trade[data-tone="down"] { background: linear-gradient(180deg, var(--down-soft), transparent 55%), var(--card); }
.kicker { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 700; color: var(--muted); }
.pulse { width: 9px; height: 9px; border-radius: 50%; background: currentColor; animation: pulse 1.6s ease-in-out infinite; }
.trade[data-tone="up"] .kicker { color: var(--up); }
.trade[data-tone="down"] .kicker { color: var(--down); }
@keyframes pulse { 50% { opacity: .25; } }
.trade-open, .trade-idle { display: flex; flex-direction: column; gap: 14px; flex: 1; }
.trade-head { display: flex; align-items: center; justify-content: space-between; }
.pill {
  padding: 3px 12px; border-radius: 999px; background: var(--inset); border: 1px solid var(--line);
  font-size: 13px; font-weight: 700;
}
.trade-dir { display: flex; align-items: center; gap: 12px; }
.dir-icon {
  width: 54px; height: 54px; flex: none; border-radius: 15px; display: grid; place-items: center;
  font-size: 24px; line-height: 1; background: var(--inset);
}
.trade[data-tone="up"] .dir-icon { background: var(--up); color: #04130d; }
.trade[data-tone="down"] .dir-icon { background: var(--down); color: #1a0506; }
.trade-dir h1 { font-size: 40px; font-weight: 900; line-height: 1.1; }
.trade[data-tone="up"] .trade-dir h1 { color: var(--up); }
.trade[data-tone="down"] .trade-dir h1 { color: var(--down); }
.conf { margin-inline-start: auto; display: grid; justify-items: end; line-height: 1.2; }
.conf b { font-size: 26px; font-weight: 800; }
.countdown { background: var(--inset); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: grid; gap: 9px; }
.count-main { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.count-main b { font-size: 34px; font-weight: 800; letter-spacing: .01em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 999px; background: var(--line); overflow: hidden; direction: ltr; }
.bar i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .9s linear; }
.count-ends { display: flex; justify-content: space-between; gap: 10px; font-size: 13px; color: var(--muted); }
.count-ends b { color: var(--text); font-variant-numeric: tabular-nums; }
.facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.facts > div, .idle-row > div, .tiles > div, .mini-facts > div {
  background: var(--inset); border-radius: 12px; padding: 9px 11px; display: grid; gap: 1px; min-width: 0;
}
dt { font-size: 12px; color: var(--muted); }
dd { font-size: 16.5px; font-weight: 700; }
.standing { font-size: 14px; font-weight: 700; color: var(--muted); margin-top: auto; }
.standing[data-tone="win"] { color: var(--up); }
.standing[data-tone="loss"] { color: var(--down); }

.trade-idle h1 { font-size: 26px; font-weight: 800; line-height: 1.35; }
.idle-reason { color: var(--muted); font-size: 14px; min-height: 1.6em; }
.idle-row { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.idle-row b { font-size: 16.5px; }
.last-trade { border-top: 1px solid var(--line); padding-top: 12px; margin-top: auto; display: grid; gap: 6px; }
.last-line { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; font-size: 13.5px; font-variant-numeric: tabular-nums; }

.tag, .result {
  display: inline-flex; align-items: center; gap: 5px; padding: 1px 10px; border-radius: 999px;
  font-size: 12.5px; font-weight: 700; white-space: nowrap; background: var(--inset); color: var(--muted);
}
.tag[data-tone="up"], .result[data-tone="win"] { background: var(--up-soft); color: var(--up); }
.tag[data-tone="down"], .result[data-tone="loss"] { background: var(--down-soft); color: var(--down); }
.result[data-tone="open"] { background: var(--accent-soft); color: var(--accent); }

/* ---------- chart ---------- */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--inset); border: 1px solid var(--line); border-radius: 11px; }
.seg button { border: 0; background: transparent; padding: 3px 13px; border-radius: 8px; font-size: 13px; font-weight: 700; color: var(--muted); min-height: 30px; }
.seg button[aria-pressed="true"] { background: var(--card); color: var(--text); box-shadow: 0 0 0 1px var(--line); }
.chart-wrap { position: relative; height: 300px; }
#chart { display: block; width: 100%; height: 100%; direction: ltr; touch-action: pan-y; }
#chart text { font-family: Cairo, Arial, sans-serif; font-size: 10.5px; fill: var(--muted); font-variant-numeric: tabular-nums; }
.empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 14px; pointer-events: none; }
.tip {
  position: absolute; top: 6px; left: 8px; pointer-events: none; white-space: pre;
  background: var(--inset); border: 1px solid var(--line); border-radius: 10px; padding: 6px 10px;
  font-size: 11.5px; line-height: 1.55; font-variant-numeric: tabular-nums; color: var(--text);
}
.legend { display: flex; flex-wrap: wrap; gap: 6px 16px; margin-top: 10px; font-size: 12.5px; color: var(--muted); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.lg { width: 10px; height: 10px; border-radius: 3px; }
.lg-open { background: var(--accent); }
.lg-win { background: var(--up); }
.lg-loss { background: var(--down); }
@media (min-width: 920px) { .chart-wrap { height: 360px; } }

/* ---------- engine ---------- */
.gauge { display: grid; gap: 6px; }
.gauge-top { display: flex; align-items: baseline; justify-content: space-between; }
.lean { font-size: 20px; font-weight: 800; }
.lean[data-tone="up"] { color: var(--up); }
.lean[data-tone="down"] { color: var(--down); }
.gauge-top b { font-size: 28px; font-weight: 800; }
.meter, .ratebar { position: relative; height: 12px; border-radius: 999px; background: var(--inset); border: 1px solid var(--line); }
.meter i, .ratebar i { position: absolute; inset: 0 auto 0 0; width: 0; border-radius: inherit; background: var(--faint); transition: width .5s ease; }
.meter i[data-tone="up"] { background: var(--up); }
.meter i[data-tone="down"] { background: var(--down); }
.mark { position: absolute; top: -5px; bottom: -5px; width: 2px; margin-left: -1px; background: var(--text); border-radius: 2px; }
.meter-scale, .ratebar-scale, .dv-scale {
  display: flex; justify-content: space-between; font-size: 11.5px; color: var(--faint); position: relative;
}
.meter-scale span:nth-child(2), .ratebar-scale span:nth-child(2) { position: absolute; transform: translateX(-50%); color: var(--muted); white-space: nowrap; font-weight: 600; }
.factors { display: grid; gap: 13px; margin-top: 16px; }
.f-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 4px; }
.f-head b { font-size: 14.5px; }
.f-head span { font-size: 13.5px; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); }
.f-head span[data-tone="up"] { color: var(--up); }
.f-head span[data-tone="down"] { color: var(--down); }
.dv { position: relative; height: 8px; border-radius: 999px; background: var(--inset); border: 1px solid var(--line); margin-bottom: 3px; }
.dv::after { content: ""; position: absolute; left: 50%; top: -3px; bottom: -3px; width: 2px; margin-left: -1px; background: var(--faint); border-radius: 2px; }
.dv i { position: absolute; top: 0; bottom: 0; left: 50%; width: 0; border-radius: 999px; background: var(--faint); transition: left .5s ease, width .5s ease; }
.dv i[data-tone="up"] { background: var(--up); }
.dv i[data-tone="down"] { background: var(--down); }
.dv-scale { margin-top: 8px; }
.mini-facts { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; margin-top: 14px; }
.mini-facts b { font-size: 15.5px; }
.history { margin-top: 14px; }
.h-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 6px; }
.sent-dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); margin-inline-end: 5px; }
#spark { display: block; width: 100%; height: 64px; direction: ltr; }

/* ---------- performance ---------- */
.rate { display: flex; align-items: flex-end; justify-content: space-between; gap: 10px; margin-bottom: 10px; }
.rate > div { display: grid; line-height: 1.15; }
.rate b { font-size: 44px; font-weight: 900; letter-spacing: -.01em; }
.verdict { padding: 4px 12px; border-radius: 999px; font-size: 13px; font-weight: 700; background: var(--inset); color: var(--muted); }
.verdict[data-tone="good"] { background: var(--up-soft); color: var(--up); }
.verdict[data-tone="bad"] { background: var(--down-soft); color: var(--down); }
.ratebar i[data-tone="good"] { background: var(--up); }
.ratebar i[data-tone="bad"] { background: var(--down); }
.ratebar-scale { margin-top: 6px; }
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; margin-top: 18px; }
.tiles b { font-size: 19px; font-weight: 800; }
@media (max-width: 420px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

table { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
th { text-align: right; font-size: 12px; font-weight: 600; color: var(--muted); padding: 7px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 8px; border-bottom: 1px solid var(--line); font-size: 13.5px; white-space: nowrap; text-align: right; }
tbody tr:last-child td { border-bottom: 0; }
.split { margin-top: 14px; }
.split td:last-child, .split th:last-child { text-align: left; font-weight: 700; }

/* ---------- log ---------- */
.table-wrap { overflow-x: auto; margin: 0 -8px; }
.trades td { vertical-align: middle; }
.trades .when small { display: block; font-size: 11px; color: var(--faint); }
.trades .prices { direction: ltr; text-align: right; }
.empty-cell { text-align: center; color: var(--muted); padding: 22px 8px; }
.ghost {
  display: block; width: 100%; margin-top: 10px; padding: 9px; border-radius: 12px;
  background: var(--inset); border: 1px solid var(--line); font-weight: 700; font-size: 13.5px; color: var(--muted);
}
@media (max-width: 520px) { .col-conf { display: none; } td, th { padding-inline: 6px; } }

/* ---------- footer ---------- */
.foot { max-width: 1240px; margin: 0 auto; padding: 14px 18px 28px; color: var(--muted); font-size: 12.5px; display: grid; gap: 4px; }
.foot b { color: var(--text); }
.caution { color: var(--warn); font-weight: 600; }
details { margin-top: 8px; }
summary { cursor: pointer; font-weight: 700; padding: 4px 0; width: fit-content; }
pre { margin: 8px 0 0; padding: 12px; max-height: 320px; overflow: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; font-size: 11.5px; line-height: 1.55; text-align: left; }

@media (max-width: 420px) {
  .top { gap: 8px; padding-inline: 12px; }
  .brand small { display: none; }
  #price { font-size: 19px; }
  .grid { padding-inline: 12px; }
  .card { padding: 14px; }
  .trade-dir h1 { font-size: 34px; }
  .count-main b { font-size: 30px; }
  dd, .idle-row b { font-size: 15px; }
}
@media (prefers-reduced-motion: reduce) {
  .pulse { animation: none; }
  .bar i, .meter i, .ratebar i, .dv i { transition: none; }
}
