:root {
  color-scheme: light;
  --page_bg: #f5f7f4;
  --panel_bg: #ffffff;
  --panel_alt: #eef3ee;
  --text: #17211c;
  --muted: #5d6b62;
  --border: #cbd8cf;
  --accent: #0f766e;
  --accent_dark: #0b534e;
  --warning: #b45309;
  --danger: #b91c1c;
  --incoming: #f5c542;
  --emitted: #e4572e;
  --cool: #2563eb;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--page_bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.app_header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--panel_bg);
}

.app_header h1 {
  margin: 0 0 4px;
  font-size: 1.25rem;
  line-height: 1.2;
}

.app_header p {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.playback_bar {
  display: flex;
  align-items: end;
  gap: 10px;
  flex-wrap: wrap;
}

.app_shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(420px, 1fr) minmax(360px, 520px);
  gap: 14px;
  padding: 14px;
  min-height: calc(100vh - 74px);
}

.controls_panel,
.stage_panel,
.plots_panel {
  min-width: 0;
}

.controls_panel {
  overflow: auto;
  max-height: calc(100vh - 102px);
  padding-right: 4px;
}

.control_group,
.stage_panel,
.plot_block {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--panel_bg);
}

.control_group {
  padding: 12px;
  margin-bottom: 12px;
}

.control_group h2,
.plot_block h2 {
  margin: 0 0 10px;
  font-size: 0.92rem;
  line-height: 1.2;
}

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

label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.25;
}

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

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
}

input,
select {
  height: 34px;
  padding: 4px 8px;
}

textarea {
  min-height: 94px;
  padding: 8px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.78rem;
  line-height: 1.35;
}

button {
  border: 1px solid var(--accent_dark);
  border-radius: 6px;
  background: var(--accent);
  color: white;
  min-height: 34px;
  padding: 6px 12px;
  cursor: pointer;
}

button.secondary {
  background: #fff;
  color: var(--accent_dark);
}

button:hover {
  background: var(--accent_dark);
}

.project_link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border: 1px solid #24292f;
  border-radius: 6px;
  padding: 6px 12px;
  background: #24292f;
  color: #fff;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
}

.project_link:hover {
  background: #3b434c;
  border-color: #3b434c;
}

.github_mark {
  flex: 0 0 auto;
  fill: currentColor;
}

details {
  margin-top: 12px;
}

summary {
  cursor: pointer;
  color: var(--accent_dark);
  font-weight: 650;
  font-size: 0.84rem;
}

.small_note {
  margin: 8px 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.inline_toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.inline_toggle input {
  width: auto;
  height: auto;
}

.mini_plot {
  display: block;
  width: 100%;
  height: 110px;
  margin: 8px 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fbfcfb;
  overflow: hidden;
}

.validation_messages {
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.validation_messages.error {
  color: var(--danger);
}

.validation_messages.warn {
  color: var(--warning);
}

.stage_panel {
  display: grid;
  grid-template-rows: auto minmax(320px, 1fr);
  gap: 12px;
  padding: 12px;
  min-height: 560px;
}

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

.readout_grid div {
  min-width: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel_alt);
  padding: 8px;
}

.readout_grid span {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
}

.readout_grid strong {
  display: block;
  margin-top: 2px;
  font-size: 0.95rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.slab_canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 360px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: linear-gradient(#0c1118, #0a0e14);
}

.plots_panel {
  display: grid;
  grid-template-rows: repeat(3, minmax(200px, 1fr));
  gap: 12px;
}

.plot_block {
  min-height: 220px;
  padding: 12px;
}

.plot_block .plot_host {
  display: block;
  width: 100%;
  height: calc(100% - 28px);
  min-height: 170px;
  overflow: hidden;
}

.u-legend {
  font-size: 0.72rem;
}

@media (max-width: 1200px) {
  .app_shell {
    grid-template-columns: minmax(300px, 380px) minmax(420px, 1fr);
  }

  .plots_panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    grid-template-rows: none;
  }
}

@media (max-width: 820px) {
  .app_header {
    align-items: flex-start;
    flex-direction: column;
  }

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

  .controls_panel {
    max-height: none;
    order: 2;
  }

  .stage_panel {
    order: 1;
    min-height: 520px;
  }

  .plots_panel {
    order: 3;
    grid-template-columns: 1fr;
  }

  .readout_grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

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

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