/* Colors are tokens, redefined for dark mode; js/app.js reads them to theme the plot. */
:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --text: #1b1f24;
  --muted: #5b6470;
  --border: #dde1e6;
  --grid: #e3e6ea;
  --accent: #1f6f7d;
  --accent-text: #ffffff;
  --fit: #b42318;
  --track: #d5dae0;
  --radius: 12px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1216;
    --surface: #171b21;
    --text: #e6e9ed;
    --muted: #9aa3ae;
    --border: #2a3039;
    --grid: #2a3039;
    --accent: #5cc2d1;
    --accent-text: #0b1316;
    --fit: #ff7a6b;
    --track: #343b45;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #0f1216;
  --surface: #171b21;
  --text: #e6e9ed;
  --muted: #9aa3ae;
  --border: #2a3039;
  --grid: #2a3039;
  --accent: #5cc2d1;
  --accent-text: #0b1316;
  --fit: #ff7a6b;
  --track: #343b45;
  --shadow: none;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

a {
  color: var(--accent);
}

h1,
h2 {
  line-height: 1.2;
  letter-spacing: -0.01em;
}

h2 {
  font-size: 1.05rem;
  margin: 0 0 0.5rem;
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
  margin: 0 0 0.75rem;
}

/* Page frame */

.page-header,
.layout,
.notes,
.page-footer {
  max-width: 1320px;
  margin: 0 auto;
  padding-left: 16px;
  padding-right: 16px;
}

.page-header {
  padding-top: 2rem;
  padding-bottom: 1.25rem;
}

.page-header h1 {
  font-size: clamp(1.6rem, 1.2rem + 1.5vw, 2.2rem);
  margin: 0 0 0.5rem;
}

.lede {
  max-width: 68ch;
  margin: 0;
  color: var(--muted);
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 16px;
  align-items: start;
}

@media (max-width: 960px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
}

/* Plot */

.plot-card,
.panel,
.notes > section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.plot-card {
  padding: 8px;
  position: sticky;
  top: 16px;
}

@media (max-width: 960px) {
  .plot-card {
    position: static;
  }
}

@media (max-width: 600px) {
  .plot {
    height: auto;
    aspect-ratio: 1 / 1;
    min-height: 320px;
  }
}

.plot {
  width: 100%;
  height: min(72vh, 680px);
  min-height: 360px;
}

.plot-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 8px 4px;
}

.plot-hint {
  margin: 0;
  font-size: 0.8rem;
  color: var(--muted);
}

/* Side panel */

.panel {
  padding: 16px;
}

.readout {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.stat {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.stat-label {
  font-weight: 600;
}

.stat-value {
  font-size: 2rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  color: var(--fit);
}

.stat-note {
  margin: 0.25rem 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.controls fieldset {
  border: 0;
  margin: 0;
  padding: 8px 0 4px;
}

.controls legend {
  font-size: 0.75rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  padding: 0;
  margin-bottom: 2px;
}

.control {
  display: grid;
  grid-template-columns: 6.25rem minmax(0, 1fr) 4.75rem;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
}

.control label {
  font-size: 0.9rem;
  white-space: nowrap;
}

.control .unit {
  display: block;
  font-size: 0.72rem;
  color: var(--muted);
  line-height: 1.1;
}

.control input[type="text"] {
  width: 100%;
  font: inherit;
  font-size: 0.85rem;
  font-family: var(--mono);
  text-align: right;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 3px 6px;
}

.control input[type="text"]:hover {
  border-color: var(--border);
}

.control input[type="text"]:focus {
  outline: none;
  border-color: var(--accent);
}

.control input[type="text"][aria-invalid="true"] {
  border-color: var(--fit);
}

/* Range input, styled the same in WebKit and Firefox, with a thumb big enough for a finger. */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 28px;
  margin: 0;
  background: transparent;
  cursor: pointer;
  touch-action: pan-y;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--accent) var(--fill, 50%), var(--track) var(--fill, 50%));
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: var(--track);
}

input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.2);
}

input[type="range"]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--surface);
  border: 2px solid var(--accent);
}

input[type="range"]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.button {
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
}

.button-small {
  font-size: 0.8rem;
  padding: 4px 10px;
}

.button-quiet {
  background: transparent;
  color: var(--accent);
}

.button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.defaults-note {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 10px 0 0;
}

.derived {
  margin-top: 16px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.derived-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
  margin: 0;
  font-size: 0.875rem;
}

.derived-list dt {
  font-weight: 600;
  white-space: nowrap;
}

.derived-list dd {
  margin: 0;
  color: var(--muted);
}

.derived-list .value {
  color: var(--text);
  font-family: var(--mono);
  font-size: 0.85rem;
}

/* Notes below the plot */

.notes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr));
  gap: 16px;
  margin-top: 16px;
}

.notes > section {
  padding: 16px 20px;
}

.notes p,
.notes li {
  max-width: 70ch;
}

.notes ul,
.notes ol {
  padding-left: 1.25rem;
}

.equations li {
  margin-bottom: 0.75rem;
}

.eq-name {
  font-weight: 600;
}

/* A wide equation scrolls sideways on a narrow screen; the padding keeps tall parts from triggering a vertical scrollbar. */
math[display="block"] {
  margin: 0.25rem 0;
  padding: 0.35rem 0;
  font-size: 1.05rem;
  overflow-x: auto;
  overflow-y: hidden;
}

.glossary {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 14px;
  margin: 0;
  font-size: 0.9rem;
}

.glossary dt {
  font-weight: 600;
  white-space: nowrap;
}

.glossary dd {
  margin: 0;
}

.page-footer {
  padding-top: 1.5rem;
  padding-bottom: 2rem;
  font-size: 0.85rem;
  color: var(--muted);
}
