:root {
  color-scheme: light dark;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background-color: Canvas;
  color: CanvasText;
}

body {
  margin: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 1.5rem 1rem 3rem;
}

header h1 {
  margin-bottom: 0.25rem;
}

header p {
  margin-top: 0;
  color: color-mix(in srgb, currentColor 70%, transparent);
}

.top-panels {
  margin-top: 1.5rem;
  display: grid;
  gap: 1.25rem;
}

@media (min-width: 900px) {
  .top-panels {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

.panel {
  padding: 1rem;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
  background: color-mix(in srgb, currentColor 6%, transparent);
}

.controls-panel {
  display: grid;
  gap: 0.75rem;
}

.data-preview {
  display: grid;
  gap: 0.75rem;
}

.preview-actions {
  margin-top: 0.75rem;
  display: flex;
  justify-content: flex-end;
}

#viewRawButton {
  background-color: #2ca02c;
}

.table-container {
  max-height: 240px;
  overflow-y: auto;
  border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
  border-radius: 8px;
  background: color-mix(in srgb, currentColor 4%, transparent);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

thead {
  position: sticky;
  top: 0;
  background: color-mix(in srgb, currentColor 15%, transparent);
}

th,
td {
  padding: 0.4rem 0.6rem;
  border-bottom: 1px solid color-mix(in srgb, currentColor 12%, transparent);
  white-space: nowrap;
}

tbody tr:nth-child(even) {
  background: color-mix(in srgb, currentColor 6%, transparent);
}

.control-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.control-group input {
  padding: 0.4rem;
  border-radius: 6px;
  border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
}

button {
  padding: 0.6rem 1rem;
  border-radius: 999px;
  border: none;
  background-color: #1f77b4;
  color: white;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s ease;
}

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

.plots {
  margin-top: 2rem;
  display: grid;
  gap: 1.5rem;
}

.plot-card {
  padding: 1rem;
  border-radius: 12px;
  border: 1px solid color-mix(in srgb, currentColor 20%, transparent);
  background: color-mix(in srgb, currentColor 6%, transparent);
}

.plot {
  width: 100%;
  height: 260px;
}

.download {
  margin-top: 2.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#fitSummary {
  margin: 0;
  font-size: 0.95rem;
  color: color-mix(in srgb, currentColor 75%, transparent);
}

.equations {
  margin-top: 2rem;
  display: grid;
  gap: 1rem;
}

.equations-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

#equationsToggle {
  border: none;
  background: color-mix(in srgb, currentColor 10%, transparent);
  color: currentColor;
  font-size: 1.1rem;
  padding: 0.2rem 0.75rem;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease;
}

#equationsToggle:hover {
  background: color-mix(in srgb, currentColor 18%, transparent);
}

.equations.collapsed #equationsToggle {
  transform: rotate(-90deg);
}

#helpButton {
  background-color: #9467bd;
}

#equationsContent p {
  margin: 0.25rem 0;
  line-height: 1.5;
}

#equationsContent .math-block {
  margin: 0.75rem 0;
}

.equations.collapsed .equations-body {
  display: none;
}

.equations.collapsed {
  gap: 0.25rem;
  padding-bottom: 0.5rem;
  padding-top: 0.75rem;
}

#helpModal[hidden] {
  display: none;
}

#helpModal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
}

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

.modal-content {
  position: relative;
  z-index: 1;
  max-width: 640px;
  width: min(92vw, 640px);
  max-height: 80vh;
  overflow-y: auto;
  background: Canvas;
  color: CanvasText;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
}

.modal-content header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin-bottom: 0.75rem;
}

#closeHelpButton {
  background: transparent;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: currentColor;
}

.modal-body {
  font-size: 0.95rem;
  line-height: 1.6;
}

.modal-body ol {
  padding-left: 1.25rem;
  margin: 0.5rem 0 1rem;
}
