:root {
  --bg: #101419;
  --panel: #161c23;
  --panel-2: #1d2530;
  --text: #e7edf6;
  --muted: #8d9aac;
  --line: rgba(145, 158, 180, 0.18);
  --good: #22c55e;
  --warn: #f59e0b;
  --bad: #ef4444;
  --accent: #38bdf8;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: var(--bg);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

body.risk-on {
  --regime: var(--good);
}

body.neutral {
  --regime: var(--accent);
}

body.caution {
  --regime: var(--warn);
}

body.risk-off {
  --regime: var(--bad);
}

.topbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  align-items: flex-start;
  gap: 20px;
  padding: 22px clamp(16px, 3vw, 34px);
  border-bottom: 1px solid var(--line);
  background: #0d1117;
  position: sticky;
  top: 0;
  z-index: 2;
}

.top-actions {
  display: flex;
  grid-column: 1 / -1;
  align-items: flex-start;
  gap: 12px;
  flex-wrap: wrap;
  justify-content: space-between;
  min-width: 0;
  width: 100%;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-start;
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111820;
  max-width: none;
  flex: 1 1 760px;
  overflow: visible;
}

.tab-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 0 11px;
  border-radius: 6px;
  color: #b8c4d4;
  font-size: 12px;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.tab-link.active {
  background: var(--accent);
  color: #051018;
}

.tab-hidden {
  display: none !important;
}

.eyebrow,
.label,
.signal-head p,
.section-title p,
.note,
.timestamp {
  color: var(--muted);
}

.eyebrow,
.label {
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(28px, 3.5vw, 48px);
  line-height: 1;
  color: var(--regime);
}

.timestamp {
  font-size: 13px;
  white-space: nowrap;
}

.layout {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: clamp(16px, 3vw, 34px);
}

.hero-panel,
.signal-card,
.chart-box,
.table-wrap,
.backtest-panel,
.global-hero,
.errors {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.global-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 22px;
  padding: clamp(18px, 3vw, 30px);
  margin-bottom: 16px;
}

.global-hero h2 {
  margin-bottom: 8px;
  font-size: clamp(24px, 3vw, 38px);
}

.global-hero strong {
  font-size: clamp(42px, 7vw, 76px);
  line-height: 1;
}

.global-hero.supportive strong,
.global-hero.supportive h2 {
  color: var(--good);
}

.global-hero.caution strong,
.global-hero.caution h2 {
  color: var(--warn);
}

.global-hero.danger strong,
.global-hero.danger h2 {
  color: var(--bad);
}

.global-grid {
  grid-template-columns: repeat(5, minmax(180px, 1fr));
}

.pressure-meter span {
  background: linear-gradient(90deg, var(--good), var(--warn), var(--bad));
}

.global-bias-table {
  margin-top: 14px;
}

.hero-panel {
  display: grid;
  grid-template-columns: minmax(0, 1.3fr) minmax(320px, 0.8fr);
  gap: 24px;
  padding: clamp(18px, 3vw, 30px);
  margin-bottom: 22px;
}

.score-wrap {
  display: flex;
  align-items: center;
  gap: clamp(18px, 3vw, 34px);
}

.score-ring {
  width: clamp(132px, 18vw, 190px);
  aspect-ratio: 1;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(var(--regime) calc(var(--score) * 1%), rgba(255,255,255,.08) 0);
  position: relative;
}

.score-ring::after {
  content: "";
  position: absolute;
  inset: 13px;
  border-radius: 50%;
  background: var(--panel);
}

.score-ring span {
  position: relative;
  z-index: 1;
  font-size: clamp(34px, 5vw, 58px);
  font-weight: 800;
}

.hero-panel h2 {
  margin-bottom: 10px;
  font-size: clamp(25px, 3vw, 42px);
}

.playbook {
  max-width: 760px;
  color: #c5cedb;
  font-size: 17px;
  line-height: 1.55;
}

.summary-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.summary-columns h3,
.chart-box h3 {
  font-size: 15px;
  margin-bottom: 12px;
}

.mini-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 14px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.mini-row span {
  min-width: 220px;
}

.mini-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mini-row strong {
  color: var(--good);
}

.mini-row.danger strong {
  color: var(--warn);
}

.signals-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(180px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.signal-card {
  padding: 16px;
  min-height: 205px;
}

.signal-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.signal-head p {
  margin-bottom: 4px;
  font-size: 11px;
  text-transform: uppercase;
  font-weight: 700;
}

.signal-head h3 {
  font-size: 16px;
  margin-bottom: 0;
}

.badge {
  max-width: 112px;
  padding: 5px 8px;
  border-radius: 999px;
  background: rgba(56, 189, 248, 0.13);
  color: #b9e9ff;
  font-size: 11px;
  font-weight: 700;
  text-align: center;
}

.signal-value {
  margin: 18px 0 12px;
}

.signal-value strong {
  font-size: 31px;
}

.signal-value span {
  color: var(--muted);
  margin-left: 4px;
}

.meter {
  height: 7px;
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--bad), var(--warn), var(--good));
}

.note {
  margin: 12px 0 0;
  font-size: 13px;
  line-height: 1.4;
}

.section-title {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 20px;
  margin: 12px 0 14px;
}

.section-title h2 {
  margin-bottom: 0;
  font-size: 24px;
}

.section-title p {
  max-width: 660px;
  margin-bottom: 0;
  line-height: 1.45;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.backtest-section {
  margin-bottom: 28px;
}

.backtest-panel {
  padding: 16px;
}

.control-grid {
  display: grid;
  grid-template-columns: 1.4fr 1.2fr 0.9fr 0.7fr auto;
  gap: 12px;
  align-items: end;
}

.vintage-control-grid {
  grid-template-columns: 1fr .9fr .9fr .9fr auto;
}

.control-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.control-grid select,
.control-grid input {
  width: 100%;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #0f141b;
  color: var(--text);
  padding: 0 11px;
  font-size: 14px;
}

.control-grid button {
  height: 42px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: #051018;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
}

.backtest-status {
  margin: 14px 0;
  min-height: 22px;
  color: #b9e9ff;
  font-size: 13px;
}

.backtest-status.error {
  color: #fecaca;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(8, minmax(110px, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.stats-grid div {
  min-height: 76px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111820;
  padding: 12px;
}

.stats-grid span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.stats-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 22px;
  color: var(--text);
}

.backtest-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.rules-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.rules-strip span {
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #0f141b;
  color: #cdd6e4;
  padding: 8px 11px;
  font-size: 12px;
}

.trade-plan-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 14px;
}

.trade-plan-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.plan-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.plan-panel h3 {
  margin-bottom: 12px;
  font-size: 15px;
}

.plan-panel strong {
  display: block;
  margin-bottom: 10px;
  font-size: 24px;
  color: var(--accent);
}

.plan-panel p {
  color: #cdd6e4;
  line-height: 1.45;
  margin-bottom: 8px;
}

.chart-box {
  padding: 16px 14px 10px;
}

.chart-fallback {
  display: grid;
  place-items: center;
  min-height: 260px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
  padding: 18px;
}

.chart-box.wide {
  grid-column: 1 / -1;
}

.table-wrap {
  overflow-x: auto;
}

.options-table-wrap {
  margin-top: 14px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: #b8c4d4;
  background: var(--panel-2);
  position: sticky;
  top: 0;
}

td {
  color: #dce4ef;
}

code {
  color: #8bdcff;
  font-family: "Cascadia Mono", Consolas, monospace;
}

.errors {
  margin-top: 18px;
  padding: 16px;
  border-color: rgba(245, 158, 11, 0.5);
}

.errors p {
  color: #facc15;
  margin-bottom: 4px;
}

@media (max-width: 1180px) {
  .signals-grid {
    grid-template-columns: repeat(3, minmax(180px, 1fr));
  }

  .hero-panel {
    grid-template-columns: 1fr;
  }

  .global-grid {
    grid-template-columns: repeat(2, minmax(180px, 1fr));
  }

  .control-grid,
  .vintage-control-grid,
  .trade-plan-grid,
  .trade-plan-grid.two,
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .topbar,
  .top-actions,
  .global-hero,
  .score-wrap,
  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .tabs {
    width: 100%;
    max-width: 100%;
  }

  .tab-link {
    flex: 0 0 auto;
  }

  .timestamp {
    white-space: normal;
  }

  .signals-grid,
  .global-grid,
  .chart-grid,
  .backtest-grid,
  .trade-plan-grid,
  .trade-plan-grid.two,
  .control-grid,
  .vintage-control-grid,
  .stats-grid,
  .summary-columns {
    grid-template-columns: 1fr;
  }

  .signal-card {
    min-height: auto;
  }
}
