:root {
  color-scheme: light;
  --text: #111827;
  --muted: #64748b;
  --line: #dbe3ef;
  --panel: #ffffff;
  --band: #f7fafc;
  --blue: #2563eb;
  --teal: #14b8a6;
  --orange: #f97316;
  --red: #ef4444;
  --error-bg: #fef2f2;
  --error-text: #991b1b;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--text);
  background: #eef3f8;
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei",
    sans-serif;
}

.app-shell {
  width: min(1440px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.page-header {
  margin-bottom: 18px;
}

.page-header h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 760;
  letter-spacing: 0;
}

.page-header p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 18px;
}

.control-band,
.math-note,
.input-panel,
.error-box {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
}

.control-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  margin-bottom: 18px;
}

.slider-row {
  display: grid;
  grid-template-columns: auto minmax(180px, 560px) 42px;
  align-items: center;
  gap: 14px;
  width: 100%;
}

.slider-row label {
  font-weight: 650;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--blue);
}

output {
  font-variant-numeric: tabular-nums;
  color: var(--blue);
  font-weight: 700;
}

button {
  min-height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 18px;
  color: white;
  background: var(--blue);
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  background: #1d4ed8;
}

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

.error-box {
  margin-bottom: 18px;
  padding: 12px 14px;
  color: var(--error-text);
  background: var(--error-bg);
  border-color: #fecaca;
  font-weight: 650;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.chart-panel {
  min-width: 0;
}

.chart-panel h2,
.math-note h2 {
  margin: 0 0 10px;
  font-size: 22px;
}

.chart {
  width: 100%;
  height: 460px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.math-note {
  padding: 18px;
  margin-bottom: 18px;
}

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

.formula-grid p {
  margin: 0;
  line-height: 1.65;
}

code {
  padding: 2px 6px;
  border-radius: 4px;
  background: #edf2f7;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  white-space: normal;
  overflow-wrap: anywhere;
}

.explanation {
  margin-top: 14px;
  padding: 12px 14px;
  border-left: 4px solid var(--teal);
  background: var(--band);
}

.explanation p {
  margin: 6px 0;
}

.input-panel {
  padding: 18px;
}

#visualForm {
  display: grid;
  gap: 12px;
}

#visualForm > label,
.range-title {
  font-weight: 650;
}

.range-title {
  margin: 4px 0 0;
}

input[type="text"],
input[type="number"] {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 12px;
  color: var(--text);
  background: white;
  font: inherit;
}

input:focus {
  outline: 2px solid rgba(37, 99, 235, 0.22);
  border-color: var(--blue);
}

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

.range-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-weight: 650;
}

#visualForm button {
  width: fit-content;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 20px, 720px);
  }

  .control-band,
  .chart-grid,
  .formula-grid,
  .range-grid {
    grid-template-columns: 1fr;
  }

  .control-band {
    display: grid;
  }

  .slider-row {
    grid-template-columns: 1fr 42px;
  }

  .slider-row label {
    grid-column: 1 / -1;
  }

  .chart {
    height: 380px;
  }
}
