/* ===== Design tokens (quant / trading terminal aesthetic — cool slate + amber accent) ===== */
:root, [data-theme="light"] {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #fafbfc;
  --surface-offset: #eef0f4;
  --border: #d9dde3;
  --divider: #e5e8ed;
  --text: #0f172a;
  --text-muted: #52607a;
  --text-faint: #94a1b5;
  --accent: #b45309;         /* amber — CTA */
  --accent-hover: #92400e;
  --accent-highlight: #fef3c7;
  --pos: #059669;            /* green */
  --pos-soft: rgba(5,150,105,0.12);
  --neg: #dc2626;            /* red */
  --neg-soft: rgba(220,38,38,0.12);
  --blue: #2563eb;
  --purple: #7c3aed;
  --shadow-sm: 0 1px 2px rgba(15,23,42,0.06);
  --shadow-md: 0 4px 12px rgba(15,23,42,0.08);

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;

  --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  --transition: 160ms cubic-bezier(0.16, 1, 0.3, 1);
}

[data-theme="dark"] {
  --bg: #0b0f17;
  --surface: #131923;
  --surface-2: #171e2a;
  --surface-offset: #1c2432;
  --border: #263041;
  --divider: #1c2434;
  --text: #e6ebf4;
  --text-muted: #8a96ab;
  --text-faint: #566277;
  --accent: #f59e0b;
  --accent-hover: #fbbf24;
  --accent-highlight: rgba(245,158,11,0.15);
  --pos: #10b981;
  --pos-soft: rgba(16,185,129,0.18);
  --neg: #ef4444;
  --neg-soft: rgba(239,68,68,0.18);
  --blue: #60a5fa;
  --purple: #a78bfa;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.5);
}

/* Reset */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }
body {
  min-height: 100dvh;
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}
button { cursor: pointer; background: none; border: none; font: inherit; color: inherit; }
input, select { font: inherit; color: inherit; }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 18px; font-weight: 600; letter-spacing: -0.01em; }
h2 { font-size: 15px; font-weight: 600; letter-spacing: -0.005em; text-transform: uppercase; color: var(--text-muted); }
h3 { font-size: 14px; font-weight: 600; }
.sub { font-size: 12px; color: var(--text-muted); }
.hint { font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); }

/* Topbar */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; gap: 12px; align-items: center; color: var(--accent); }
.brand h1 { color: var(--text); }
.brand .sub { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
#theme-toggle {
  padding: 8px; border-radius: var(--radius-md); color: var(--text-muted);
  transition: background var(--transition), color var(--transition);
}
#theme-toggle:hover { background: var(--surface-offset); color: var(--text); }

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 320px minmax(0,1fr);
  gap: 20px;
  padding: 20px;
  max-width: 1600px;
  margin: 0 auto;
}
@media (max-width: 1024px) {
  .layout { grid-template-columns: 1fr; }
}

/* Panels */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 16px;
}
.panel-hd { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.panel-hd h3 { margin-bottom: 2px; }

/* Controls */
.controls { position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 96px); overflow-y: auto; }
.controls h2 { margin-bottom: 14px; }
fieldset { border: none; padding: 12px 0; border-top: 1px solid var(--divider); }
fieldset:first-of-type { border-top: none; padding-top: 4px; }
legend {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--accent); font-weight: 600; padding-bottom: 8px;
}
label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-muted);
  margin-bottom: 10px;
}
label.row { flex-direction: row; align-items: center; gap: 8px; }
label.row input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
label > span:first-child { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.val { font-family: var(--font-mono); color: var(--text); font-size: 12px; font-weight: 500; }
input[type=number], input[type=text] {
  background: var(--surface-offset);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  color: var(--text);
  font-family: var(--font-mono);
  transition: border-color var(--transition), background var(--transition);
}
input[type=number]:focus, input[type=text]:focus {
  outline: none; border-color: var(--accent); background: var(--surface);
}
input[type=range] {
  width: 100%; height: 4px; background: var(--surface-offset);
  border-radius: 2px; appearance: none; -webkit-appearance: none;
}
input[type=range]::-webkit-slider-thumb {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px; background: var(--accent);
  border-radius: 50%; cursor: pointer; border: 2px solid var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
input[type=range]::-moz-range-thumb {
  width: 16px; height: 16px; background: var(--accent);
  border-radius: 50%; cursor: pointer; border: 2px solid var(--surface);
}

.run {
  width: 100%; margin-top: 12px;
  padding: 12px; background: var(--accent); color: white;
  border-radius: var(--radius-md); font-weight: 600; font-size: 14px;
  transition: background var(--transition), transform var(--transition);
}
.run:hover { background: var(--accent-hover); }
.run:active { transform: scale(0.98); }
.run:disabled { opacity: 0.5; cursor: wait; }
.status { margin-top: 8px; font-size: 12px; color: var(--text-muted); text-align: center; min-height: 18px; font-family: var(--font-mono); }

/* Results */
.results { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* KPIs */
.kpi-grid {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px;
}
@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 600px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 12px 14px;
}
.kpi-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 500; }
.kpi-value {
  font-family: var(--font-mono); font-size: 20px; font-weight: 600;
  color: var(--text); margin-top: 4px; letter-spacing: -0.02em;
}
.kpi-value.pos { color: var(--pos); }
.kpi-value.neg { color: var(--neg); }

/* Charts */
.chart-wrap { position: relative; height: 320px; }

/* Buy & hold comparison row */
.bh-row {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px;
  margin-bottom: 12px;
}
@media (max-width: 900px) { .bh-row { grid-template-columns: repeat(2, 1fr); } }
.bh-cell {
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-md); padding: 10px 12px;
}
.bh-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); font-weight: 500; }
.bh-value { font-family: var(--font-mono); font-size: 17px; font-weight: 600; color: var(--text); margin-top: 3px; letter-spacing: -0.02em; }
.bh-value.pos { color: var(--pos); }
.bh-value.neg { color: var(--neg); }

/* Table */
.table-wrap { overflow-x: auto; max-height: 400px; overflow-y: auto; }
table { width: 100%; border-collapse: collapse; font-family: var(--font-mono); font-size: 12px; }
th, td { padding: 8px 10px; text-align: right; border-bottom: 1px solid var(--divider); }
th:first-child, td:first-child { text-align: left; }
th {
  position: sticky; top: 0; background: var(--surface-2);
  font-weight: 600; color: var(--text-muted); text-transform: uppercase;
  font-size: 11px; letter-spacing: 0.04em;
}
td.pos { color: var(--pos); }
td.neg { color: var(--neg); }
tr.state-put td:nth-child(2) { color: var(--blue); }
tr.state-call td:nth-child(2) { color: var(--purple); }
tr.state-anchor td:nth-child(2) { color: var(--accent); }
.path-picker { flex-direction: row; align-items: center; gap: 8px; margin: 0; }

/* Footer */
footer { padding: 20px 24px 40px; color: var(--text-muted); font-size: 12px; max-width: 1600px; margin: 0 auto; }
footer p { max-width: 900px; }
