:root {
  color-scheme: light;
  --bg: #eef3f8;
  --panel: rgba(255, 255, 255, 0.74);
  --panel-muted: rgba(247, 250, 253, 0.78);
  --panel-raised: rgba(255, 255, 255, 0.92);
  --text: #111827;
  --muted: #687385;
  --line: #d9e0e8;
  --line-strong: #b8c3cf;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8f0ff;
  --positive: #059669;
  --negative: #dc2626;
  --warning: #b45309;
  --glass: rgba(255, 255, 255, 0.7);
  --glass-strong: rgba(255, 255, 255, 0.86);
  --glass-line: rgba(105, 118, 138, 0.22);
  --mirror: rgba(255, 255, 255, 0.58);
  --mirror-top: rgba(255, 255, 255, 0.88);
  --mirror-shadow: 0 14px 48px rgba(15, 23, 42, 0.12);
  --hero-shadow: 0 24px 90px rgba(15, 23, 42, 0.15);
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --chart-bg: #ffffff;
  --chart-grid: #e4e9f0;
  --chart-text: #111827;
  --chart-muted: #687385;
  --chart-accent: #2563eb;
  --chart-positive: #059669;
  --chart-danger: #dc2626;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b0f14;
  --panel: rgba(17, 24, 33, 0.72);
  --panel-muted: rgba(21, 29, 39, 0.76);
  --panel-raised: rgba(23, 33, 45, 0.9);
  --text: #edf2f7;
  --muted: #8b98a8;
  --line: #243041;
  --line-strong: #344155;
  --accent: #60a5fa;
  --accent-hover: #93c5fd;
  --accent-soft: #12243d;
  --positive: #34d399;
  --negative: #f87171;
  --warning: #fbbf24;
  --glass: rgba(17, 24, 33, 0.58);
  --glass-strong: rgba(18, 27, 38, 0.76);
  --glass-line: rgba(174, 194, 219, 0.16);
  --mirror: rgba(18, 27, 38, 0.58);
  --mirror-top: rgba(255, 255, 255, 0.09);
  --mirror-shadow: 0 18px 56px rgba(0, 0, 0, 0.28);
  --hero-shadow: 0 28px 120px rgba(0, 0, 0, 0.36);
  --shadow: none;
  --chart-bg: #0f1620;
  --chart-grid: #263244;
  --chart-text: #edf2f7;
  --chart-muted: #8b98a8;
  --chart-accent: #60a5fa;
  --chart-positive: #34d399;
  --chart-danger: #f87171;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 18% -10%, rgba(52, 211, 153, 0.12), transparent 27rem),
    radial-gradient(circle at 92% 8%, rgba(96, 165, 250, 0.18), transparent 30rem),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  color: inherit;
}

.shell {
  display: grid;
  gap: 14px;
  min-height: 100vh;
  padding: 18px;
}

.tabs,
.panel,
.market-strip {
  border: 1px solid var(--glass-line);
  border-radius: 12px;
  background: var(--panel);
  box-shadow: var(--mirror-shadow);
  backdrop-filter: blur(20px) saturate(1.34);
  -webkit-backdrop-filter: blur(20px) saturate(1.34);
}

.hero-shell {
  position: relative;
  isolation: isolate;
  min-height: 382px;
  overflow: hidden;
  border: 1px solid var(--glass-line);
  border-radius: 24px;
  background: #0b111a;
  box-shadow: var(--hero-shadow);
}

.hero-image,
.hero-noise {
  position: absolute;
  inset: 0;
  z-index: -2;
}

.hero-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0.92;
}

.hero-noise {
  z-index: -1;
  background:
    linear-gradient(90deg, rgba(5, 8, 12, 0.82) 0%, rgba(5, 8, 12, 0.42) 42%, rgba(5, 8, 12, 0.22) 100%),
    radial-gradient(circle at 62% 32%, rgba(52, 211, 153, 0.18), transparent 20rem),
    radial-gradient(circle at 82% 72%, rgba(96, 165, 250, 0.22), transparent 24rem);
}

.hero-content {
  display: grid;
  gap: 28px;
  min-height: inherit;
  padding: 22px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 66px;
  border: 1px solid var(--glass-line);
  border-radius: 16px;
  padding: 12px 14px;
  background: var(--glass);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.12);
  backdrop-filter: blur(22px) saturate(1.5);
  -webkit-backdrop-filter: blur(22px) saturate(1.5);
}

.brand,
.run-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand h1,
.panel-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 21px;
  line-height: 1.1;
}

.brand p,
.panel-heading span,
.metric-card span,
.progress-copy span,
.market-strip span {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.health-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--warning);
  box-shadow: 0 0 0 5px rgba(251, 191, 36, 0.12);
}

.health-dot.online {
  background: var(--positive);
  box-shadow: 0 0 0 5px rgba(52, 211, 153, 0.13);
}

.hero-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(340px, 0.58fr);
  gap: 24px;
  align-items: stretch;
}

.hero-copy {
  align-self: end;
  max-width: 760px;
  padding: 14px 0 10px;
}

.hero-kicker {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  padding: 0 11px;
  color: rgba(237, 242, 247, 0.84);
  background: rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(18px) saturate(1.45);
  -webkit-backdrop-filter: blur(18px) saturate(1.45);
  font-size: 12px;
  font-weight: 760;
}

.hero-copy h2 {
  max-width: 780px;
  margin: 14px 0 0;
  color: #f8fafc;
  font-size: clamp(34px, 4.4vw, 58px);
  line-height: 1;
  letter-spacing: 0;
}

.hero-copy p {
  max-width: 660px;
  margin: 18px 0 0;
  color: rgba(237, 242, 247, 0.78);
  font-size: 16px;
  line-height: 1.55;
}

.hero-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 22px;
}

.glass-chip {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  padding: 0 12px;
  color: rgba(248, 250, 252, 0.9);
  background: rgba(255, 255, 255, 0.09);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(18px) saturate(1.45);
  -webkit-backdrop-filter: blur(18px) saturate(1.45);
  font-size: 12px;
  font-weight: 760;
}

.mirror-console {
  align-self: end;
  display: grid;
  gap: 14px;
  min-height: 286px;
  border: 1px solid var(--glass-line);
  border-radius: 22px;
  padding: 16px;
  color: rgba(248, 250, 252, 0.92);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.16), rgba(255, 255, 255, 0.045)),
    rgba(11, 18, 28, 0.42);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.18),
    inset 0 -1px 0 rgba(255, 255, 255, 0.05),
    0 24px 70px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(26px) saturate(1.55);
  -webkit-backdrop-filter: blur(26px) saturate(1.55);
}

.console-topline,
.console-rows article {
  border: 1px solid var(--glass-line);
  border-radius: 14px;
  background: rgba(8, 13, 20, 0.28);
}

.console-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 0 12px;
}

.console-topline span,
.console-rows span {
  color: rgba(237, 242, 247, 0.66);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.console-topline strong {
  color: var(--positive);
  font-size: 13px;
}

.console-chart {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  align-items: end;
  gap: 7px;
  min-height: 86px;
  border: 1px solid var(--glass-line);
  border-radius: 16px;
  padding: 14px;
  background:
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.05) 1px, transparent 1px),
    rgba(8, 13, 20, 0.22);
  background-size: 100% 22px, 44px 100%, auto;
}

.console-chart span {
  height: var(--height);
  min-height: 18px;
  border-radius: 999px 999px 4px 4px;
  background: linear-gradient(180deg, rgba(96, 165, 250, 0.95), rgba(52, 211, 153, 0.42));
  box-shadow: 0 10px 24px rgba(96, 165, 250, 0.2);
}

.console-rows {
  display: grid;
  gap: 8px;
}

.console-rows article {
  display: grid;
  grid-template-columns: 92px 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
}

.console-rows strong {
  font-size: 13px;
}

.console-rows em {
  color: rgba(237, 242, 247, 0.58);
  font-size: 12px;
  font-style: normal;
  white-space: nowrap;
}

.market-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  overflow: hidden;
  padding: 0;
  background: var(--glass-strong);
  backdrop-filter: blur(20px) saturate(1.35);
  -webkit-backdrop-filter: blur(20px) saturate(1.35);
}

.market-strip article {
  min-width: 0;
  padding: 12px 14px;
  border-right: 1px solid var(--glass-line);
}

.market-strip article:last-child {
  border-right: 0;
}

.market-strip strong {
  display: block;
  margin-top: 5px;
  overflow: hidden;
  color: var(--text);
  font-size: 13px;
  font-weight: 750;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.primary-button,
.preset-button,
.tab-button,
.actions a,
.icon-button,
.template-chip,
.inline-button {
  min-height: 36px;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button {
  min-width: 104px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  color: #ffffff;
  background: linear-gradient(180deg, #78adff, var(--accent));
  box-shadow: 0 12px 30px rgba(37, 99, 235, 0.32);
}

.primary-button:hover {
  border-color: var(--accent-hover);
  background: var(--accent-hover);
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.62;
}

.icon-button,
.preset-button,
.actions a,
.template-chip,
.inline-button {
  border: 1px solid var(--glass-line);
  color: var(--text);
  background: var(--mirror);
  box-shadow: inset 0 1px 0 var(--mirror-top);
  backdrop-filter: blur(16px) saturate(1.25);
  -webkit-backdrop-filter: blur(16px) saturate(1.25);
}

.icon-button {
  min-width: 62px;
  padding: 0 12px;
  background: var(--glass);
  backdrop-filter: blur(16px) saturate(1.35);
  -webkit-backdrop-filter: blur(16px) saturate(1.35);
}

.icon-button:hover,
.preset-button:hover,
.actions a:hover,
.template-chip:hover,
.inline-button:hover {
  border-color: var(--line-strong);
  background: var(--panel-raised);
}

.inline-button {
  min-height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.inline-button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.hidden {
  display: none !important;
}

.saved-backtest-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.saved-backtest-copy {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.saved-backtest-copy span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

.saved-backtest-copy strong {
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.saved-backtest-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.status-badge {
  border: 1px solid var(--glass-line);
  border-radius: 999px;
  padding: 7px 11px;
  color: var(--muted);
  background: var(--mirror);
  box-shadow: inset 0 1px 0 var(--mirror-top);
  font-size: 12px;
  font-weight: 750;
}

.status-badge.running {
  color: var(--warning);
}

.status-badge.succeeded {
  color: var(--positive);
}

.status-badge.failed {
  color: var(--negative);
}

.tabs {
  display: flex;
  gap: 2px;
  overflow-x: auto;
  padding: 6px;
}

.tab-button {
  border: 1px solid transparent;
  padding: 0 12px;
  color: var(--muted);
  background: transparent;
  white-space: nowrap;
}

.tab-button:hover {
  color: var(--text);
  background: var(--mirror);
}

.tab-button.active {
  border-color: var(--glass-line);
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(96, 165, 250, 0.16), rgba(96, 165, 250, 0.08)),
    var(--mirror);
  box-shadow: inset 0 1px 0 var(--mirror-top);
}

.content-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(286px, 336px);
  gap: 12px;
  align-items: start;
}

.workspace {
  min-width: 0;
}

.tab-panel {
  display: none;
  gap: 12px;
}

.tab-panel.active {
  display: grid;
}

.side-rail {
  position: sticky;
  top: 14px;
  display: grid;
  gap: 12px;
}

.panel {
  padding: 14px;
}

.panel-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  font-size: 15px;
  font-weight: 760;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.field-grid.compact {
  grid-template-columns: repeat(2, minmax(0, 180px));
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--glass-line);
  border-radius: 8px;
  padding: 8px 10px;
  color: var(--text);
  background: var(--mirror);
  box-shadow: inset 0 1px 0 var(--mirror-top);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
}

textarea {
  min-height: 140px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid rgba(96, 165, 250, 0.22);
  border-color: var(--accent);
}

.preset-row,
.actions,
.builder-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.preset-row {
  margin-bottom: 12px;
}

.preset-button {
  padding: 0 11px;
}

.builder-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(260px, 0.9fr);
  gap: 14px;
}

.builder-actions {
  align-items: center;
  margin-top: 12px;
}

.inline-status,
.empty-note {
  color: var(--muted);
  font-size: 12px;
}

.block-palette,
.compare-selector,
.library-grid {
  display: grid;
  gap: 8px;
}

.template-chip,
.check-row,
.library-card,
.builder-dropzone {
  border: 1px solid var(--glass-line);
  border-radius: 8px;
  background: var(--mirror);
  box-shadow: inset 0 1px 0 var(--mirror-top);
}

.template-chip {
  min-height: 36px;
  padding: 0 10px;
  text-align: left;
}

.builder-dropzone {
  display: grid;
  gap: 8px;
  min-height: 112px;
  margin-top: 12px;
  padding: 14px;
  border-style: dashed;
}

.builder-dropzone.dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.builder-dropzone strong,
.library-card strong {
  font-size: 14px;
}

.builder-dropzone span,
.library-card span {
  color: var(--muted);
  font-size: 12px;
}

.library-card {
  display: grid;
  gap: 5px;
  padding: 10px;
}

.check-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 9px;
  padding: 9px 10px;
  text-transform: none;
}

.check-row label {
  display: flex;
  align-items: center;
  gap: 9px;
}

.check-row input {
  width: auto;
  min-height: auto;
  accent-color: var(--accent);
}

.check-row span {
  margin: 0;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  text-transform: none;
}

.selected-row {
  outline: 1px solid rgba(96, 165, 250, 0.46);
  background:
    linear-gradient(180deg, rgba(96, 165, 250, 0.14), rgba(96, 165, 250, 0.055)),
    var(--mirror);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric-card strong {
  display: block;
  margin-top: 7px;
  color: var(--text);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 22px;
  font-weight: 760;
  letter-spacing: 0;
}

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

.chart-panel,
.table-panel {
  min-width: 0;
}

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

canvas {
  display: block;
  width: 100%;
  height: 320px;
  border: 1px solid var(--glass-line);
  border-radius: 10px;
  background: var(--chart-bg);
  box-shadow: inset 0 1px 0 var(--mirror-top);
}

.progress-copy {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.progress-copy strong {
  white-space: nowrap;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  font-weight: 650;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--mirror);
  box-shadow: inset 0 1px 0 var(--mirror-top);
}

.progress-bar {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), var(--positive));
  transition: width 180ms ease;
}

.actions a {
  padding: 9px 11px;
  text-decoration: none;
  font-size: 12px;
}

.warnings {
  display: grid;
  gap: 8px;
}

.warning {
  border-left: 3px solid var(--warning);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
  background: var(--mirror);
  font-size: 12px;
}

.plot-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.plot-grid a {
  display: grid;
  gap: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 12px;
  font-weight: 700;
}

.plot-grid img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid var(--glass-line);
  border-radius: 10px;
  background: var(--mirror);
}

.table-scroll {
  overflow-x: auto;
  border: 1px solid var(--glass-line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

th,
td {
  border-bottom: 1px solid var(--glass-line);
  padding: 10px 8px;
  text-align: right;
  white-space: nowrap;
}

tbody tr:hover {
  background: var(--panel-muted);
}

th:first-child,
td:first-child {
  text-align: left;
}

th {
  position: sticky;
  top: 0;
  color: var(--muted);
  background: var(--panel-raised);
  font-size: 11px;
  font-weight: 760;
  text-transform: uppercase;
}

td {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

@media (max-width: 1120px) {
  .content-grid {
    grid-template-columns: 1fr;
  }

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

  .mirror-console {
    min-height: 238px;
  }

  .side-rail {
    position: static;
  }

  .metric-grid,
  .chart-grid,
  .plot-grid,
  .builder-grid,
  .market-strip {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 720px) {
  .shell {
    padding: 10px;
  }

  .hero-shell {
    min-height: auto;
    border-radius: 16px;
  }

  .hero-content {
    gap: 24px;
    padding: 12px;
  }

  .app-header,
  .run-actions,
  .panel-heading,
  .progress-copy,
  .saved-backtest-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .brand,
  .run-actions {
    width: 100%;
  }

  .hero-copy h2 {
    font-size: 34px;
    line-height: 1.02;
  }

  .hero-copy p {
    font-size: 14px;
  }

  .console-rows article {
    grid-template-columns: 1fr;
    gap: 3px;
    padding: 10px 12px;
  }

  .console-rows em {
    white-space: normal;
  }

  .field-grid,
  .field-grid.compact,
  .metric-grid,
  .chart-grid,
  .plot-grid,
  .builder-grid,
  .market-strip {
    grid-template-columns: 1fr;
  }

  .primary-button,
  .icon-button,
  .saved-backtest-actions,
  .saved-backtest-actions .inline-button {
    width: 100%;
  }
}
