:root,
:root[data-theme="day"] {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --field-bg: #fbfcfd;
  --ink: #172026;
  --code-ink: #22303a;
  --muted: #66727c;
  --line: #dbe2e8;
  --control-border: #cbd5dc;
  --accent: #006d77;
  --accent-strong: #00535b;
  --accent-soft: #eef8f9;
  --accent-line: #bddade;
  --on-accent: #ffffff;
  --warning: #a44b00;
  --header-bg: rgba(255, 255, 255, 0.88);
  --status-error-border: #f0c8ad;
  --status-error-bg: #fff6ef;
  --focus-ring: rgba(0, 109, 119, 0.22);
  --quote-line: #bddade;
  --chart-bg: #ffffff;
  --chart-grid: #dce4ea;
  --chart-label: #66727c;
  --chart-line: #172026;
  --chart-frame: #006d77;
  --shadow: 0 18px 42px rgba(23, 32, 38, 0.08);
}

:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #0f1315;
  --surface: #171d20;
  --surface-soft: #111719;
  --field-bg: #12181b;
  --ink: #ecf2f3;
  --code-ink: #d8e4e7;
  --muted: #9caaae;
  --line: #2c373b;
  --control-border: #39464b;
  --accent: #66c7cf;
  --accent-strong: #8fdee4;
  --accent-soft: #10272b;
  --accent-line: #315d63;
  --on-accent: #081315;
  --warning: #ffb36e;
  --header-bg: rgba(15, 19, 21, 0.92);
  --status-error-border: #815338;
  --status-error-bg: #271b15;
  --focus-ring: rgba(102, 199, 207, 0.26);
  --quote-line: #315d63;
  --chart-bg: #101719;
  --chart-grid: #2d4045;
  --chart-label: #a6b5b9;
  --chart-line: #ecf2f3;
  --chart-frame: #66c7cf;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

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

body,
.app-header,
.panel,
input,
select,
textarea,
button,
canvas,
.json-block {
  transition:
    background-color 160ms ease,
    border-color 160ms ease,
    color 160ms ease,
    box-shadow 160ms ease;
}

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

.app-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  padding: 28px clamp(18px, 4vw, 48px) 18px;
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
}

.header-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 4vw, 44px);
  line-height: 1.08;
}

h2 {
  margin-bottom: 0;
  font-size: 18px;
}

h3 {
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.status {
  min-width: 112px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.status.is-error {
  border-color: var(--status-error-border);
  color: var(--warning);
  background: var(--status-error-bg);
}

.status.is-working {
  color: var(--accent);
}

.shell {
  display: grid;
  grid-template-columns: minmax(240px, 0.9fr) minmax(240px, 0.9fr) minmax(360px, 1.4fr);
  align-items: start;
  gap: 18px;
  padding: 20px clamp(18px, 4vw, 48px) 42px;
}

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

.controls-panel,
.infer-panel,
.coefficients-panel,
.inferred-panel,
.chart-panel,
.inference-response-panel {
  padding: 18px;
}

.controls-panel {
  grid-column: 1;
  grid-row: 1;
}

.coefficients-panel {
  grid-column: 2;
  grid-row: 1;
}

.chart-panel {
  grid-column: 3;
  grid-row: 1;
}

.infer-panel {
  grid-column: 1;
  grid-row: 2;
}

.inferred-panel {
  grid-column: 2;
  grid-row: 2;
}

.inference-response-panel {
  grid-column: 3;
  grid-row: 2;
}

.about-panel {
  display: flex;
  grid-column: 1 / -1;
  grid-row: 3;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px;
  color: var(--ink);
}

.about-panel .eyebrow {
  margin-bottom: 7px;
  color: var(--accent);
}

.about-copy {
  min-width: 0;
}

.about-copy h2 {
  margin-bottom: 14px;
  font-size: 20px;
  line-height: 1.25;
}

.about-quote {
  display: grid;
  gap: 6px;
  max-width: 760px;
  margin: 0;
  border-left: 3px solid var(--quote-line);
  padding-left: 14px;
  color: var(--ink);
}

.about-quote p {
  margin-bottom: 0;
  line-height: 1.55;
}

.about-quote cite {
  color: var(--muted);
  font-size: 14px;
  font-style: normal;
}

.social-links {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

.social-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid var(--accent-line);
  border-radius: 6px;
  color: var(--accent);
  background: var(--accent-soft);
  text-decoration: none;
}

.social-link:hover,
.social-link:focus-visible {
  color: var(--on-accent);
  border-color: var(--accent);
  background: var(--accent);
}

.social-link:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

.social-link svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.social-link img {
  display: block;
  width: 22px;
  height: 22px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.title-with-mode {
  display: flex;
  min-width: 0;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.mode-toggle {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  min-width: max-content;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 2px;
  background: var(--surface-soft);
}

.mode-toggle legend {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.mode-toggle label {
  display: block;
  min-width: auto;
}

.mode-toggle input {
  position: absolute;
  width: 1px;
  height: 1px;
  min-height: 0;
  opacity: 0;
}

.mode-toggle span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 36px;
  min-height: 28px;
  border-radius: 4px;
  padding: 0 9px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.mode-toggle input:checked + span {
  color: var(--on-accent);
  background: var(--accent);
}

.mode-toggle input:focus-visible + span {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

.theme-toggle span {
  min-width: 56px;
}

.button-group {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.points-control {
  display: flex;
  align-items: center;
  gap: 8px;
  width: auto;
}

.points-control span {
  white-space: nowrap;
}

.points-control input {
  width: 96px;
  min-height: 34px;
}

.form-grid,
.infer-grid {
  display: grid;
  gap: 14px;
}

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

label {
  display: grid;
  gap: 7px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  min-height: 40px;
  border: 1px solid var(--control-border);
  border-radius: 6px;
  color: var(--ink);
  background: var(--field-bg);
  accent-color: var(--accent);
}

input,
select {
  padding: 0 10px;
}

textarea {
  resize: vertical;
  padding: 10px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 1px;
}

button {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  font-weight: 800;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.primary-button {
  color: var(--on-accent);
  background: var(--accent);
}

.primary-button:hover:not(:disabled) {
  background: var(--accent-strong);
}

.ghost-button {
  color: var(--accent);
  border-color: var(--accent-line);
  background: var(--accent-soft);
}

.chart-wrap {
  position: relative;
  width: 100%;
  min-height: 360px;
}

canvas {
  display: block;
  width: 100%;
  height: clamp(300px, 34vh, 420px);
  min-height: 340px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--chart-bg);
}

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

.coeff-list {
  margin: 0;
  padding-left: 0;
  list-style: none;
  color: var(--ink);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.7;
  overflow-wrap: anywhere;
}

.json-block {
  max-height: 230px;
  margin: 16px 0 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  color: var(--code-ink);
  background: var(--surface-soft);
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

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

.summary-list div {
  min-width: 0;
  border-bottom: 1px solid var(--line);
  padding-bottom: 8px;
}

.summary-list dt {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.summary-list dd {
  margin: 3px 0 0;
  overflow-wrap: anywhere;
  font-family: "Cascadia Mono", Consolas, monospace;
  font-size: 13px;
}

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

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

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

  .controls-panel,
  .coefficients-panel,
  .chart-panel,
  .infer-panel,
  .inferred-panel,
  .inference-response-panel,
  .about-panel {
    grid-column: auto;
    grid-row: auto;
  }

  .controls-panel {
    order: 1;
  }

  .coefficients-panel {
    order: 2;
  }

  .chart-panel {
    order: 3;
  }

  .infer-panel {
    order: 4;
  }

  .inferred-panel {
    order: 5;
  }

  .inference-response-panel {
    order: 6;
  }

  .about-panel {
    order: 7;
  }
}

@media (max-width: 560px) {
  .form-grid,
  .coeff-columns,
  .infer-grid,
  .summary-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 10px;
  }

  .shell {
    gap: 14px;
    padding-inline: 12px;
  }

  .controls-panel,
  .infer-panel,
  .coefficients-panel,
  .inferred-panel,
  .chart-panel,
  .inference-response-panel {
    padding: 14px;
  }

  .section-title {
    align-items: stretch;
    flex-direction: column;
  }

  .button-group {
    flex-direction: column;
  }

  .points-control {
    width: 100%;
  }

  .points-control input {
    flex: 1;
    width: auto;
  }

  button {
    width: 100%;
  }

  .about-panel {
    align-items: flex-start;
    flex-direction: column;
    padding: 20px;
  }

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