:root,
.viz-root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline-axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --marker-fill: #2a78d6;
  --chart-axis: #e3a3a3;
  --chart-grid: #f2d6d6;
  --chart-coord-text: #c76a6a;
  --chart-edge: var(--text-muted);
  --accent: #2a78d6;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme='light'])),
  :root:where(:not([data-theme='light'])) .viz-root {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline-axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --marker-fill: #3987e5;
    --chart-axis: #a15c5c;
    --chart-grid: #4a3232;
    --chart-coord-text: #e0a3a3;
    --accent: #3987e5;
  }
}

:root[data-theme='dark'],
:root[data-theme='dark'] .viz-root {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --baseline-axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --marker-fill: #3987e5;
  --chart-axis: #a15c5c;
  --chart-grid: #4a3232;
  --chart-coord-text: #e0a3a3;
  --accent: #3987e5;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--page-plane);
  color: var(--text-primary);
}

header {
  display: flex;
  align-items: baseline;
  gap: 12px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-1);
}

header h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 600;
}

header p {
  margin: 0;
  color: var(--text-secondary);
  font-size: 13px;
}

.header-links {
  display: flex;
  gap: 16px;
  margin-left: 16px;
  font-size: 13px;
}

.header-links a {
  color: var(--text-secondary);
  text-decoration: none;
}

.header-links a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.theme-toggle {
  margin-left: auto;
}

.site-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-muted);
  font-size: 10;
}

.site-footer p {
  margin: 10;
}

.site-footer a {
  color: var(--text-muted);
}

.layout {
  display: flex;
  align-items: flex-start;
  gap: 0;
  min-height: calc(100vh - 57px);
}

aside {
  width: 320px;
  flex: 0 0 320px;
  padding: 20px;
  background: var(--surface-1);
  border-right: 1px solid var(--border);
  height: calc(100vh - 57px);
  overflow-y: auto;
  position: sticky;
  top: 57px;
}

section.control-group {
  margin-bottom: 22px;
}

section.control-group h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin: 0 0 10px;
  font-weight: 600;
}

.field {
  margin-bottom: 12px;
}

.field label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 4px;
  gap: 8px;
}

.field .row-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-primary);
  margin-bottom: 8px;
}

.field .row-checkbox label {
  margin: 0;
}

.field output {
  font-variant-numeric: tabular-nums;
  color: var(--text-muted);
  font-size: 12px;
}

select,
input[type='text'],
input[type='number'],
input[type='file'] {
  width: 100%;
  padding: 7px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-size: 13px;
}

input[type='range'] {
  width: 100%;
}

textarea {
  width: 100%;
  padding: 7px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  font-family: ui-monospace, SFMono-Regular, Consolas, 'Liberation Mono', Menlo, monospace;
  font-size: 12px;
  line-height: 1.4;
  resize: vertical;
}

textarea + .button-row {
  margin-top: 8px;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  padding: 8px 10px;
  font-size: 13px;
}

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

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

.button-row {
  display: flex;
  gap: 8px;
}

.button-row button {
  flex: 1;
}

main {
  flex: 1;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.chart-frame {
  width: 100%;
  max-width: 980px;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}

.chart-frame svg {
  width: 100%;
  height: auto;
  display: block;
}

.chart-empty {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-secondary);
}

.stats-bar {
  width: 100%;
  max-width: 980px;
  display: flex;
  gap: 18px;
  padding: 10px 4px 0;
  font-size: 12px;
  color: var(--text-secondary);
  flex-wrap: wrap;
}

.stats-bar strong {
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.error-banner {
  width: 100%;
  max-width: 980px;
  background: rgba(211, 59, 59, 0.1);
  border: 1px solid #d03b3b;
  color: #d03b3b;
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 12px;
}

.hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

@media (max-width: 860px) {
  .layout {
    flex-direction: column;
  }
  aside {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
}
