:root {
  --bg: #070b14;
  --surface: #0f172a;
  --surface-2: #162138;
  --surface-3: #1d2b48;
  --border: rgba(148, 163, 184, 0.2);
  --text: #f8fafc;
  --muted: #94a3b8;
  --cyan: #22d3ee;
  --green: #22c55e;
  --amber: #f59e0b;
  --red: #f43f5e;
  --purple: #a855f7;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  max-width: 100%;
  overflow-x: hidden;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: radial-gradient(circle at top right, #11203d 0%, var(--bg) 52%);
  color: var(--text);
  line-height: 1.45;
}

.hidden { display: none !important; }
.mono-sm { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; color: var(--muted); }
.muted-sm { color: var(--muted); font-size: 13px; margin: 4px 0 0; }
.muted-xs { color: var(--muted); font-size: 12px; }
.text-green { color: var(--green); }
.text-red { color: var(--red); }
.text-cyan { color: var(--cyan); }
.mt-sm { margin-top: 10px; }
.mt-md { margin-top: 16px; }
.sep { border: 0; border-top: 1px solid var(--border); margin: 16px 0; }

.kill-banner {
  background: linear-gradient(90deg, #9f1239, #be123c);
  color: #fff;
  padding: 10px 18px;
  font-size: 13px;
  text-align: center;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  background: rgba(15, 23, 42, 0.92);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.brand-wrap { display: flex; align-items: center; gap: 12px; }
.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--cyan), #3b82f6);
  color: #04101f;
  font-weight: 900;
  font-size: 13px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.brand-title { font-size: 17px; font-weight: 800; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--muted); }

.topbar-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.role-picker-wrap {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.micro-label { font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }

select, input, textarea {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
  max-width: 100%;
}
select:focus, input:focus, textarea:focus {
  outline: 2px solid rgba(34, 211, 238, 0.45);
  border-color: var(--cyan);
}

.mode-toggle {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 2px;
}
.toggle-btn {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 6px 10px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.toggle-btn.active {
  background: rgba(34, 211, 238, 0.18);
  color: var(--cyan);
}

.shell {
  max-width: 1420px;
  margin: 0 auto;
  padding: 16px 18px 40px;
}

.radar-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}
.radar-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
}
.radar-l2 { border-color: rgba(34, 211, 238, 0.35); background: linear-gradient(180deg, rgba(34, 211, 238, 0.08), var(--surface)); }
.radar-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.radar-val { font-size: 16px; font-weight: 800; margin: 4px 0; display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.radar-sub { font-size: 11.5px; color: var(--muted); }

.role-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  margin-bottom: 14px;
}
.role-desc-wrap { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; min-width: 0; }
.role-badge {
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  color: #04101f;
  background: var(--cyan);
}
.role-desc { font-size: 12.5px; color: var(--muted); }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab-btn {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 7px 12px;
  font-size: 12.5px;
  font-weight: 700;
  cursor: pointer;
}
.tab-btn.active {
  background: rgba(34, 211, 238, 0.16);
  border-color: var(--cyan);
  color: var(--text);
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.preset-bar {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.preset-btn {
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, transform 0.12s;
}
.preset-btn:hover { border-color: rgba(34, 211, 238, 0.5); }
.preset-btn.active {
  border-color: var(--cyan);
  background: linear-gradient(180deg, rgba(34, 211, 238, 0.14), var(--surface));
}
.preset-btn.preset-danger.active {
  border-color: var(--red);
  background: linear-gradient(180deg, rgba(244, 63, 94, 0.16), var(--surface));
}
.preset-name { font-size: 13px; font-weight: 800; margin-top: 4px; }
.preset-cat { font-size: 11px; color: var(--muted); }

.studio-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}
.col-main, .col-side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  min-width: 0;
}
.card h2 { font-size: 16px; margin: 0 0 4px; }
.card h3 { font-size: 14px; margin: 0 0 8px; }
.card-head {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}
.kpi {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.kpi-label { font-size: 11px; color: var(--muted); }
.kpi strong { font-size: 17px; }

.liq-badge {
  padding: 5px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}
.liq-zero { background: rgba(34, 197, 94, 0.16); color: #86efac; border: 1px solid rgba(34, 197, 94, 0.4); }
.liq-capped { background: rgba(34, 211, 238, 0.16); color: #67e8f9; border: 1px solid rgba(34, 211, 238, 0.4); }
.liq-danger { background: rgba(244, 63, 94, 0.2); color: #fda4af; border: 1px solid rgba(244, 63, 94, 0.5); }

.chart-wrap {
  background: #0a1020;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
  margin-bottom: 12px;
}
.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 6px;
}
.sim-readout { margin-left: auto; color: var(--text); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }
.dot-t2 { background: #22c55e; }
.dot-t1 { background: #f59e0b; }
.dot-sim { background: #22d3ee; }
#payoffSvg { width: 100%; height: auto; display: block; }

.sliders-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.slider-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.slider-top { display: flex; justify-content: space-between; font-size: 12px; gap: 6px; }
.slider-box input[type="range"] { width: 100%; padding: 0; accent-color: var(--cyan); }

.scenarios-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.scenario-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-size: 12px;
}
.scenario-card strong { display: block; margin-bottom: 4px; font-size: 12.5px; }

.callout {
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
}
.callout-info {
  background: rgba(56, 189, 248, 0.1);
  border: 1px solid rgba(56, 189, 248, 0.3);
  color: #e0f2fe;
}
.callout-warn {
  background: rgba(245, 158, 11, 0.12);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fef3c7;
}
.callout-danger {
  background: rgba(244, 63, 94, 0.15);
  border: 1px solid rgba(244, 63, 94, 0.45);
  color: #ffe4e6;
}
.callout-ok {
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: #dcfce7;
}

.pro-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 10px;
  background: rgba(168, 85, 247, 0.08);
  border: 1px solid rgba(168, 85, 247, 0.3);
}
.greeks-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.greeks-row div {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  font-size: 12px;
}

.table-scroll { overflow-x: auto; max-width: 100%; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12.5px;
}
.data-table th, .data-table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.data-table th { color: var(--muted); font-size: 11px; text-transform: uppercase; }

.pill {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.pill-cyan { background: rgba(34, 211, 238, 0.16); color: #67e8f9; }
.pill-green { background: rgba(34, 197, 94, 0.16); color: #86efac; }
.pill-amber { background: rgba(245, 158, 11, 0.16); color: #fcd34d; }
.pill-red { background: rgba(244, 63, 94, 0.18); color: #fda4af; }
.pill-purple { background: rgba(168, 85, 247, 0.18); color: #d8b4fe; }

.btn {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  color: var(--text);
  background: var(--surface-3);
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; }
.btn-primary { background: linear-gradient(135deg, #06b6d4, #2563eb); color: #fff; }
.btn-secondary { background: var(--surface-3); border-color: var(--border); }
.btn-success { background: linear-gradient(135deg, #16a34a, #15803d); color: #fff; }
.btn-danger { background: linear-gradient(135deg, #e11d48, #be123c); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted); }

.split-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.cards-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 10px; }
.form-stack, .stack-sm, .btn-stack { display: flex; flex-direction: column; gap: 10px; }
.form-stack label, .form-grid label, .field-stack { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.check-row { flex-direction: row !important; align-items: center; gap: 8px !important; color: var(--text) !important; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.inline-field { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); }

.mini-result {
  margin-top: 10px;
  padding: 10px;
  border-radius: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 12.5px;
}

.l3-box {
  font-size: 12.5px;
  white-space: pre-wrap;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
}

.item-card {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 11px 12px;
  font-size: 12.5px;
}

#marginResult {
  min-height: 98px;
}
.is-loading {
  opacity: 0.6;
  transition: opacity 0.15s;
}

@media (max-width: 1100px) {
  .radar-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .preset-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .studio-grid, .split-2, .cards-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; }
  .shell { padding: 12px 10px 32px; }
  .radar-strip, .kpi-grid, .sliders-grid, .scenarios-grid, .form-grid, .greeks-row, .preset-bar {
    grid-template-columns: minmax(0, 1fr);
  }
  .sim-readout { margin-left: 0; }
  .topbar-controls { width: 100%; justify-content: space-between; }
  .role-picker-wrap { width: 100%; }
  .role-picker-wrap select { width: 100%; }
}
