:root {
  --bg: #05070b;
  --bg-2: #0a0f17;
  --panel: rgba(10, 15, 23, 0.78);
  --panel-strong: rgba(14, 20, 32, 0.90);
  --panel-soft: rgba(255, 255, 255, 0.035);
  --border: rgba(122, 167, 255, 0.16);
  --border-strong: rgba(122, 167, 255, 0.28);
  --text: #edf4ff;
  --muted: #97a8c0;
  --muted-2: #6f7f96;
  --accent: #63a8ff;
  --accent-2: #49f2ff;
  --accent-3: #9a7dff;
  --good: #57d68d;
  --danger: #ff7a70;
  --warning: #f4c66a;
  --shadow-lg: 0 26px 90px rgba(0, 0, 0, 0.42);
  --shadow-md: 0 16px 38px rgba(0, 0, 0, 0.24);
  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
  --radius-sm: 12px;
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  color: var(--text);
  font-family:
    Inter,
    ui-sans-serif,
    system-ui,
    -apple-system,
    BlinkMacSystemFont,
    "Segoe UI",
    sans-serif;
  background:
    radial-gradient(circle at top left, rgba(99, 168, 255, 0.10), transparent 28%),
    radial-gradient(circle at top right, rgba(73, 242, 255, 0.08), transparent 22%),
    linear-gradient(180deg, #06090e 0%, #04060a 100%);
  overflow-x: hidden;
}

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

.app-bg {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
}

.bg-orb {
  position: absolute;
  border-radius: 999px;
  filter: blur(80px);
  opacity: 0.28;
}

.orb-1 {
  width: 420px;
  height: 420px;
  top: -120px;
  left: -60px;
  background: rgba(99, 168, 255, 0.28);
}

.orb-2 {
  width: 340px;
  height: 340px;
  top: 80px;
  right: -60px;
  background: rgba(73, 242, 255, 0.18);
}

.bg-grid {
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 42px 42px;
  mask-image: linear-gradient(180deg, rgba(255,255,255,0.35), transparent 75%);
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 26px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  background: rgba(4, 7, 11, 0.68);
  backdrop-filter: blur(22px) saturate(150%);
}

.header-left,
.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-chip {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  font-size: 15px;
  font-weight: 900;
  letter-spacing: -0.04em;
  color: white;
  border: 1px solid rgba(99, 168, 255, 0.35);
  background:
    linear-gradient(135deg, rgba(99, 168, 255, 0.30), rgba(73, 242, 255, 0.10)),
    rgba(255,255,255,0.04);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.10),
    0 0 30px rgba(99, 168, 255, 0.20);
}

.brand-copy h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.045em;
}

.brand-copy p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.header-badge,
.status-pill,
.viz-tag {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 34px;
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status-pill::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--warning);
  box-shadow: 0 0 16px rgba(244, 198, 106, 0.8);
}

.status-pill.ok {
  color: #c8fadb;
  border-color: rgba(87, 214, 141, 0.22);
  background: rgba(87, 214, 141, 0.10);
}

.status-pill.ok::before {
  background: var(--good);
  box-shadow: 0 0 16px rgba(87, 214, 141, 0.85);
}

.status-pill.bad {
  color: #ffd1cd;
  border-color: rgba(255, 122, 112, 0.24);
  background: rgba(255, 122, 112, 0.09);
}

.status-pill.bad::before {
  background: var(--danger);
  box-shadow: 0 0 16px rgba(255, 122, 112, 0.85);
}

.layout {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: 330px minmax(560px, 1fr) 360px;
  gap: 20px;
  padding: 20px;
  align-items: start;
}

.panel,
.viz-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.015)),
    var(--panel);
  backdrop-filter: blur(18px) saturate(145%);
  box-shadow: var(--shadow-lg);
}

.panel {
  padding: 18px;
}

.setup-panel,
.results-panel {
  position: sticky;
  top: 94px;
  max-height: calc(100vh - 110px);
  overflow: auto;
}

.setup-panel::-webkit-scrollbar,
.results-panel::-webkit-scrollbar {
  width: 8px;
}

.setup-panel::-webkit-scrollbar-thumb,
.results-panel::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 999px;
}

.section-kicker {
  margin-bottom: 8px;
  color: var(--accent-2);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.panel-heading {
  margin-bottom: 16px;
}

.panel-heading h2,
.workspace-top h2 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.045em;
}

.panel-heading p,
.workspace-top p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.module {
  margin-bottom: 14px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: var(--radius-lg);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.015)),
    rgba(255,255,255,0.02);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.04);
}

.module:last-of-type {
  margin-bottom: 0;
}

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

.module-head h3 {
  margin: 0;
  font-size: 15px;
  letter-spacing: -0.025em;
}

.module-head span {
  color: var(--muted-2);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.field {
  display: block;
}

.field.full + .field.full {
  margin-top: 12px;
}

.field span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 12px;
}

.two-col:first-child {
  margin-top: 0;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid rgba(122, 167, 255, 0.14);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.01)),
    rgba(5, 8, 13, 0.78);
  outline: none;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(99, 168, 255, 0.48);
  box-shadow:
    0 0 0 3px rgba(99, 168, 255, 0.10),
    0 0 22px rgba(99, 168, 255, 0.10);
  background: rgba(8, 12, 18, 0.94);
}

input[type="range"] {
  min-height: 26px;
  padding: 0;
  border: 0;
  box-shadow: none;
  background: transparent;
  accent-color: var(--accent-2);
}

.slider-card {
  padding: 12px 12px 10px;
  border: 1px solid rgba(255,255,255,0.05);
  border-radius: var(--radius-md);
  background: rgba(255,255,255,0.02);
}

.slider-card + .slider-card {
  margin-top: 10px;
}

.slider-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 10px;
}

.slider-meta span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.slider-meta strong {
  font-size: 14px;
  color: var(--text);
}

.button-stack {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.btn {
  width: 100%;
  min-height: 46px;
  border: 0;
  border-radius: 15px;
  cursor: pointer;
  font-weight: 900;
  letter-spacing: -0.015em;
  transition:
    transform 120ms ease,
    filter 120ms ease,
    box-shadow 120ms ease,
    opacity 120ms ease;
}

.btn:hover {
  transform: translateY(-1px);
  filter: brightness(1.05);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.64;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  color: #04111d;
  background: linear-gradient(135deg, #8be0ff 0%, #63a8ff 50%, #7e87ff 100%);
  box-shadow: 0 18px 40px rgba(99, 168, 255, 0.24);
}

.btn-secondary {
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
  background: rgba(255,255,255,0.06);
}

.btn-danger {
  color: #ffd0cb;
  border: 1px solid rgba(255, 122, 112, 0.24);
  background: rgba(255, 122, 112, 0.10);
}

.compact {
  min-height: 40px;
  margin-top: 10px;
}

.message-box {
  min-height: 18px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.message-box.error {
  color: #ffd0cb;
}

.message-box.ok {
  color: #c8fadb;
}

.workspace {
  min-width: 0;
}

.workspace-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 20px;
  padding: 6px 4px 16px;
}

.workspace-top p {
  max-width: 430px;
  text-align: right;
}

.viz-grid {
  display: grid;
  gap: 18px;
}

.viz-card {
  overflow: hidden;
}

.viz-head {
  display: flex;
  justify-content: space-between;
  align-items: start;
  gap: 18px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.viz-head h3 {
  margin: 0;
  font-size: 16px;
  letter-spacing: -0.025em;
}

.viz-head p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.viz-tag {
  color: #dff7ff;
  border-color: rgba(73, 242, 255, 0.20);
  background: rgba(73, 242, 255, 0.08);
}

.plot-shell {
  position: relative;
  height: 410px;
  padding: 22px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 45%, rgba(99, 168, 255, 0.08), transparent 30%),
    linear-gradient(180deg, rgba(8,12,18,0.92), rgba(4,7,12,0.98));
}

.plot-frame {
  position: absolute;
  inset: 14px;
  border: 1px solid rgba(99, 168, 255, 0.12);
  border-radius: 18px;
  pointer-events: none;
  box-shadow:
    inset 0 0 0 1px rgba(255,255,255,0.03),
    0 0 30px rgba(99, 168, 255, 0.05);
}

.plot-frame::before,
.plot-frame::after {
  content: "";
  position: absolute;
  border-color: rgba(73, 242, 255, 0.35);
  border-style: solid;
  width: 16px;
  height: 16px;
}

.plot-frame::before {
  top: 10px;
  left: 10px;
  border-width: 1px 0 0 1px;
}

.plot-frame::after {
  right: 10px;
  bottom: 10px;
  border-width: 0 1px 1px 0;
}

.plot {
  position: absolute;
  inset: 0;
  z-index: 1;
}

.car-overlay {
  position: absolute;
  inset: 22px;
  width: calc(100% - 44px);
  height: calc(100% - 44px);
  z-index: 3;
  pointer-events: none;
  filter: drop-shadow(0 16px 26px rgba(0, 0, 0, 0.40));
}

.metrics-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.metric {
  min-height: 88px;
  padding: 13px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,0.06);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.05), rgba(255,255,255,0.015)),
    rgba(255,255,255,0.02);
  box-shadow: var(--shadow-md);
}

.metric .label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  line-height: 1.25;
}

.metric .value {
  margin-top: 10px;
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.05em;
  color: var(--text);
}

#runHistory {
  height: 190px;
}

#runHistory,
#compareA,
#compareB {
  width: 100%;
}

#runHistory option,
#compareA option,
#compareB option {
  padding: 8px;
}

.comparison-box {
  min-height: 108px;
  margin-top: 12px;
  padding: 13px;
  border: 1px solid rgba(122, 167, 255, 0.14);
  border-radius: 15px;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(255,255,255,0.035), rgba(255,255,255,0.01)),
    rgba(5, 8, 13, 0.76);
  line-height: 1.55;
  font-size: 13px;
}

.comparison-box strong {
  color: #e3f5ff;
}

textarea {
  height: 245px;
  margin-top: 10px;
  resize: vertical;
  line-height: 1.5;
  color: #ddebff;
  font-family:
    ui-monospace,
    SFMono-Regular,
    Menlo,
    Monaco,
    Consolas,
    "Liberation Mono",
    monospace;
  font-size: 12px;
}

@media (max-width: 1320px) {
  .layout {
    grid-template-columns: 320px minmax(520px, 1fr);
  }

  .results-panel {
    grid-column: 1 / -1;
    position: static;
    max-height: none;
  }

  .results-panel {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
  }

  .results-panel > .section-kicker,
  .results-panel > .panel-heading {
    grid-column: 1 / -1;
  }
}

@media (max-width: 980px) {
  .app-header {
    flex-direction: column;
    align-items: flex-start;
    padding: 16px;
  }

  .header-right {
    width: 100%;
    justify-content: space-between;
  }

  .layout {
    grid-template-columns: 1fr;
    padding: 12px;
  }

  .setup-panel,
  .results-panel {
    position: static;
    max-height: none;
  }

  .results-panel {
    display: block;
  }

  .workspace-top {
    display: block;
  }

  .workspace-top p {
    margin-top: 8px;
    max-width: none;
    text-align: left;
  }

  .plot-shell {
    height: 350px;
    padding: 16px;
  }

  .car-overlay {
    inset: 16px;
    width: calc(100% - 32px);
    height: calc(100% - 32px);
  }
}

@media (max-width: 620px) {
  .two-col,
  .metrics-grid {
    grid-template-columns: 1fr;
  }

  .brand-copy p,
  .header-badge {
    display: none;
  }

  .plot-shell {
    height: 300px;
    padding: 12px;
  }

  .car-overlay {
    inset: 12px;
    width: calc(100% - 24px);
    height: calc(100% - 24px);
  }

  .plot-frame {
    inset: 8px;
  }
}