:root {
  color-scheme: light dark;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #f9fafb;
  --surface-muted: #eef2f4;
  --text: #16202a;
  --muted: #5f6f7d;
  --border: #d8e0e7;
  --border-strong: #b9c7d2;
  --accent: #0f8f8c;
  --accent-strong: #0b6f6d;
  --accent-soft: #d9f3f1;
  --accent-glow: rgba(15, 143, 140, 0.18);
  --warn: #b65c00;
  --line: #2b8cbe;
  --success: #2d7c44;
  --header-bg: rgba(255, 255, 255, 0.92);
  --slot-bg: rgba(255, 255, 255, 0.88);
  --slot-border: rgba(255, 255, 255, 0.42);
  --trace-top: #5ecfc8;
  --trace-fill: rgba(43, 140, 190, 0.38);
  --shadow: 0 18px 50px rgba(22, 32, 42, 0.08);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111417;
    --surface: #1a1f24;
    --surface-strong: #20262c;
    --surface-muted: #15191d;
    --text: #edf2f5;
    --muted: #9ba9b4;
    --border: #303940;
    --border-strong: #46535d;
    --accent: #45c7be;
    --accent-strong: #70d8d0;
    --accent-soft: #123a39;
    --accent-glow: rgba(69, 199, 190, 0.2);
    --warn: #ffb45f;
    --line: #63b7df;
    --success: #70ca86;
    --header-bg: rgba(26, 31, 36, 0.94);
    --slot-bg: rgba(26, 31, 36, 0.88);
    --slot-border: rgba(255, 255, 255, 0.12);
    --trace-top: #70d8d0;
    --trace-fill: rgba(99, 183, 223, 0.34);
    --shadow: 0 20px 60px rgba(0, 0, 0, 0.24);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, var(--surface-strong) 0, var(--bg) 18rem);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--accent-strong);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

button,
input {
  font: inherit;
}

button {
  min-height: 2.5rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 0.55rem 0.85rem;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
}

button:not(:disabled):hover {
  border-color: var(--accent);
  color: var(--accent-strong);
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--accent-soft);
  outline-offset: 2px;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input {
  width: 100%;
  min-height: 2.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.48rem 0.65rem;
  background: var(--surface);
  color: var(--text);
}

input[type="checkbox"] {
  width: 1rem;
  min-height: 1rem;
  margin: 0;
  accent-color: var(--accent);
}

label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
  text-transform: uppercase;
}

.app-header {
  border-bottom: 1px solid var(--border);
  background: var(--header-bg);
}

.header-inner,
.app-main {
  width: min(1220px, calc(100% - 2rem));
  margin: 0 auto;
}

.header-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1.5rem;
  align-items: end;
  padding: 1.5rem 0;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent-strong);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 0.25rem;
  font-size: clamp(1.9rem, 3vw, 3rem);
  line-height: 1.06;
  letter-spacing: 0;
}

.header-copy {
  max-width: 48rem;
  margin-bottom: 0;
  color: var(--muted);
}

.header-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 0.5rem;
}

.header-links a {
  display: inline-flex;
  min-height: 2.25rem;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.4rem 0.8rem;
  background: var(--surface);
  color: var(--text);
  font-weight: 650;
  white-space: nowrap;
}

.app-main {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(0, 1fr);
  gap: 1.25rem;
  padding: 1.25rem 0 2rem;
}

.sidebar,
.workspace {
  display: grid;
  gap: 1rem;
  align-content: start;
}

.panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.panel-header {
  display: flex;
  gap: 1rem;
  align-items: start;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  padding: 1rem 1rem 0.85rem;
  background: var(--surface-strong);
}

.panel-title {
  margin: 0;
  font-size: 1rem;
  line-height: 1.25;
}

.panel-kicker {
  margin: 0.2rem 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.panel-body {
  padding: 1rem;
}

.control-stack {
  display: grid;
  gap: 1rem;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
}

.primary-action {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
  font-weight: 750;
}

.primary-action:not(:disabled):hover {
  border-color: var(--accent-strong);
  background: var(--accent-strong);
  color: #ffffff;
}

.field-group {
  display: grid;
  gap: 0.5rem;
}

.checkbox-field {
  display: flex;
  gap: 0.55rem;
  align-items: center;
  margin: 0;
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 650;
  text-transform: none;
}

.file-note {
  margin: -0.2rem 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.runtime-log,
.event-log {
  margin: 0;
  overflow: auto;
  border-radius: 6px;
  padding: 0.85rem;
  background: var(--surface-muted);
  color: var(--text);
  font: 0.88rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
}

.runtime-log {
  min-height: 9rem;
  max-height: 18rem;
}

.event-log {
  min-height: 18rem;
  max-height: min(42rem, calc(100vh - 10rem));
}

.visualization-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 1rem;
}

.visual-panel {
  grid-column: span 3;
}

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

.visual-panel-wide > .panel-header {
  display: grid;
  grid-template-columns: minmax(12rem, 0.35fr) minmax(0, 1fr);
  align-items: end;
}

#graph-controls {
  display: grid;
  grid-template-columns: repeat(6, minmax(5.75rem, 1fr));
  gap: 0.65rem;
  align-items: end;
  width: 100%;
}

#graph-controls label {
  margin: 0;
}

#graph-controls .control-field {
  display: grid;
  gap: 0.35rem;
}

#float-graph {
  display: block;
  width: 100%;
  height: clamp(320px, 42vh, 470px);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-muted);
}

#constellation-graph {
  display: block;
  width: 100%;
  height: clamp(280px, 32vh, 380px);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-muted);
}

#spectrum-graph {
  display: block;
  width: 100%;
  height: clamp(280px, 32vh, 380px);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-muted);
}

#waterfall-graph {
  display: block;
  width: 100%;
  height: clamp(280px, 32vh, 380px);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  background: var(--surface-muted);
}

.plot-surface {
  position: relative;
  min-height: 18rem;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  overflow: hidden;
  background:
    linear-gradient(var(--border) 1px, transparent 1px),
    linear-gradient(90deg, var(--border) 1px, transparent 1px),
    var(--surface-muted);
  background-size: 44px 44px;
}

.plot-surface::after {
  position: absolute;
  inset: 0;
  border: 1px solid var(--slot-border);
  content: "";
  pointer-events: none;
}

.constellation-points {
  position: absolute;
  inset: 1rem;
}

.constellation-points span {
  position: absolute;
  left: var(--x);
  top: var(--y);
  width: 0.72rem;
  height: 0.72rem;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 0 0.34rem var(--accent-glow);
  transform: translate(-50%, -50%);
}

.spectrum-trace {
  position: absolute;
  inset: auto 1rem 1.4rem;
  height: 45%;
  clip-path: polygon(
    0 75%, 6% 58%, 13% 64%, 18% 39%, 24% 60%, 30% 47%,
    36% 63%, 42% 23%, 48% 61%, 54% 51%, 60% 66%, 68% 42%,
    76% 68%, 84% 34%, 91% 62%, 100% 49%, 100% 100%, 0 100%
  );
  background: linear-gradient(
    180deg,
    var(--trace-top) 0%,
    var(--trace-fill) 100%
  );
  opacity: 0.78;
}

.slot-label {
  position: absolute;
  left: 1rem;
  top: 1rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.24rem 0.55rem;
  background: var(--slot-bg);
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 750;
}

@media (max-width: 940px) {
  .header-inner,
  .app-main {
    width: min(100% - 1.25rem, 1220px);
  }

  .header-inner,
  .app-main {
    grid-template-columns: 1fr;
  }

  .header-links {
    justify-content: flex-start;
  }

  .visual-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  body {
    font-size: 14px;
  }

  .panel-header {
    display: block;
  }

  #graph-controls {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .visual-panel-wide > .panel-header > #graph-controls {
    margin-top: 1rem;
  }

  #graph-controls button {
    width: 100%;
  }

  #float-graph,
  .plot-surface {
    min-height: 16rem;
    height: 16rem;
  }
}
