:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page-plane: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --good: #0ca30c;
  --good-text: #006300;
  --critical: #d03b3b;
  --shadow: 0 1px 2px rgba(11, 11, 11, 0.04), 0 8px 24px rgba(11, 11, 11, 0.05);
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page-plane: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --series-1: #3987e5;
    --series-2: #d95926;
    --good: #0ca30c;
    --good-text: #0ca30c;
    --critical: #e66767;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --surface-1: #1a1a19;
  --page-plane: #0d0d0d;
  --text-primary: #ffffff;
  --text-secondary: #c3c2b7;
  --text-muted: #898781;
  --gridline: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --series-1: #3987e5;
  --series-2: #d95926;
  --good: #0ca30c;
  --good-text: #0ca30c;
  --critical: #e66767;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

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

.page {
  max-width: 980px;
  margin: 0 auto;
  padding: 24px 20px 64px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.brand h1 {
  font-size: 1.6rem;
  margin: 0 0 4px;
}

.tagline {
  margin: 0;
  color: var(--text-secondary);
  max-width: 60ch;
}

.theme-toggle {
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.85rem;
  cursor: pointer;
  flex-shrink: 0;
}

.theme-toggle:hover {
  border-color: var(--axis);
}

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 20px 20px 24px;
  margin-bottom: 20px;
}

.card h2 {
  font-size: 1.15rem;
  margin: 0 0 4px;
}

.card .section-desc {
  color: var(--text-secondary);
  margin: 0 0 16px;
  max-width: 68ch;
}

.intro p {
  margin: 0;
  color: var(--text-secondary);
  max-width: 72ch;
}

.formula {
  display: inline-flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 10px 0 0;
  font-size: 0.92rem;
}

.formula code {
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 2px 8px;
  color: var(--text-primary);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.field-label {
  font-size: 0.8rem;
  color: var(--text-secondary);
  display: block;
  margin-bottom: 4px;
}

input[type="text"],
input[type="number"] {
  font: inherit;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--axis);
  background: var(--surface-1);
  color: var(--text-primary);
  width: 100%;
}

input[type="text"]:focus,
input[type="number"]:focus {
  outline: 2px solid var(--series-1);
  outline-offset: 1px;
}

.btn {
  font: inherit;
  padding: 9px 16px;
  border-radius: 8px;
  border: 1px solid var(--series-1);
  background: var(--series-1);
  color: #fff;
  cursor: pointer;
  font-weight: 600;
}

.btn:hover {
  filter: brightness(1.05);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-ghost {
  background: transparent;
  color: var(--text-primary);
  border-color: var(--axis);
  font-weight: 500;
}

.btn-preset {
  font: inherit;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.85rem;
}

.btn-preset:hover {
  border-color: var(--axis);
  color: var(--text-primary);
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 12px;
  margin: 18px 0;
}

.stat-tile {
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
}

.stat-tile .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.stat-tile .value {
  font-size: 1.4rem;
  font-weight: 600;
  font-variant-numeric: proportional-nums;
  word-break: break-word;
}

.stat-tile .value.small {
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.chart-figure {
  display: flex;
  flex-direction: column;
  margin: 6px 0 4px;
}

.chart-body {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.axis-title-y {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  padding: 4px 0;
}

.axis-title-x {
  flex: 0 0 auto;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 6px;
}

.chart-wrap {
  position: relative;
  width: 100%;
  height: 260px;
  flex: 1 1 auto;
  min-width: 0;
}

.chart-wrap canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.fullscreen-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 6;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  opacity: 0.8;
}

.fullscreen-btn:hover {
  opacity: 1;
  border-color: var(--axis);
  color: var(--text-primary);
}

.chart-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.chart-modal[hidden] {
  display: none;
}

.chart-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(11, 11, 11, 0.6);
}

.chart-modal-panel {
  position: relative;
  width: min(1100px, 94vw);
  height: min(720px, 88vh);
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 28px 24px 20px;
  display: flex;
  flex-direction: column;
}

.chart-modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 2;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-1);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 15px;
}

.chart-modal-close:hover {
  color: var(--text-primary);
  border-color: var(--axis);
}

.chart-modal-slot {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
}

.chart-modal-slot .chart-figure {
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
}

.chart-modal-slot .chart-body {
  flex: 1 1 auto;
  min-height: 0;
}

.chart-modal-slot .chart-wrap {
  height: 100%;
}

.chart-modal-slot .axis-title-y,
.chart-modal-slot .axis-title-x {
  font-size: 0.85rem;
}

.chart-modal-slot .fullscreen-btn {
  display: none;
}

.tooltip {
  position: absolute;
  transform: translate(-50%, calc(-100% - 10px));
  background: var(--text-primary);
  color: var(--surface-1);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  pointer-events: none;
  white-space: nowrap;
  box-shadow: var(--shadow);
  z-index: 5;
}

.tooltip .tooltip-value {
  font-weight: 700;
}

.tooltip .tooltip-label {
  opacity: 0.75;
}

.chart-controls {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 4px;
}

.toggle-chip {
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--page-plane);
  color: var(--text-secondary);
  cursor: pointer;
}

.toggle-chip[aria-pressed="true"] {
  background: var(--series-1);
  color: #fff;
  border-color: var(--series-1);
}

details.sequence-list {
  margin-top: 10px;
}

details.sequence-list summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.sequence-values {
  font-variant-numeric: tabular-nums;
  font-size: 0.82rem;
  color: var(--text-secondary);
  background: var(--page-plane);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 8px;
  max-height: 200px;
  overflow: auto;
  word-break: break-all;
}

.error-text {
  color: var(--critical);
  font-size: 0.85rem;
  margin: 6px 0 0;
  min-height: 1.2em;
}

.server-settings {
  margin: 6px 0 10px;
}

.server-settings summary {
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 0.82rem;
}

.server-settings summary:hover {
  color: var(--text-primary);
}

.server-settings-form {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: flex-end;
  margin-top: 10px;
}

.server-settings-hint {
  color: var(--text-muted);
  font-size: 0.78rem;
  margin: 8px 0 0;
  max-width: 60ch;
}

.progress-track {
  height: 8px;
  border-radius: 999px;
  background: var(--gridline);
  overflow: hidden;
  margin: 14px 0 4px;
}

.progress-fill {
  height: 100%;
  background: var(--series-1);
  width: 0%;
  transition: width 0.15s linear;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 0.9rem;
  margin: 14px 0;
  border: 1px solid var(--border);
}

.banner.good {
  background: color-mix(in srgb, var(--good) 12%, var(--surface-1));
  color: var(--good-text);
}

.banner.critical {
  background: color-mix(in srgb, var(--critical) 12%, var(--surface-1));
  color: var(--critical);
}

.banner-icon {
  font-size: 1.1rem;
}

.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin: 18px 0 10px;
}

.tab-btn {
  font: inherit;
  padding: 8px 14px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  font-size: 0.88rem;
}

.tab-btn[aria-selected="true"] {
  color: var(--text-primary);
  border-bottom-color: var(--series-1);
  font-weight: 600;
}

table.records {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

table.records th,
table.records td {
  text-align: right;
  padding: 7px 10px;
  border-bottom: 1px solid var(--gridline);
  font-variant-numeric: tabular-nums;
}

table.records th:first-child,
table.records td:first-child {
  text-align: left;
  font-variant-numeric: normal;
}

table.records th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.footnote {
  color: var(--text-muted);
  font-size: 0.82rem;
  max-width: 72ch;
  margin: 8px auto 0;
}

.legend-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.legend-swatch {
  width: 14px;
  height: 2px;
  background: var(--series-1);
  display: inline-block;
  border-radius: 2px;
}

@media (max-width: 560px) {
  .topbar {
    flex-direction: column;
  }
  .stat-row {
    grid-template-columns: repeat(2, 1fr);
  }
}
