:root {
  color-scheme: light;
  --bg: #eef2f5;
  --panel: #ffffff;
  --panel-soft: #f6f8fb;
  --ink: #141821;
  --muted: #647084;
  --line: #d9e0e8;
  --line-strong: #a9b5c4;
  --accent: #0f6bff;
  --accent-dark: #074ec2;
  --danger: #c93636;
  --shadow: 0 18px 50px rgba(30, 41, 59, 0.14);
  --radius: 8px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(135deg, rgba(15, 107, 255, 0.08), transparent 34%),
    linear-gradient(315deg, rgba(12, 150, 120, 0.08), transparent 30%),
    var(--bg);
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: 7px;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(15, 107, 255, 0.28);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 390px;
  gap: 20px;
  min-height: 100vh;
  padding: 20px;
}

.plot-area {
  position: relative;
  min-height: calc(100vh - 40px);
  overflow: hidden;
  border: 1px solid rgba(169, 181, 196, 0.7);
  border-radius: var(--radius);
  background: #fbfcfe;
  box-shadow: var(--shadow);
}

#plotCanvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 560px;
  cursor: grab;
  touch-action: none;
}

#plotCanvas.is-dragging {
  cursor: grabbing;
}

.plot-toolbar {
  position: absolute;
  z-index: 2;
  top: 16px;
  right: 16px;
  display: flex;
  gap: 8px;
  padding: 6px;
  border: 1px solid rgba(217, 224, 232, 0.9);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.86);
  box-shadow: 0 10px 30px rgba(31, 41, 55, 0.14);
  backdrop-filter: blur(12px);
}

.tool-button {
  min-width: 40px;
  height: 38px;
  padding: 0 12px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
}

.tool-button:hover {
  background: #eef4ff;
}

.reset-button {
  min-width: 72px;
  font-weight: 650;
}

.plot-status {
  position: absolute;
  z-index: 2;
  left: 16px;
  bottom: 16px;
  padding: 8px 10px;
  border: 1px solid rgba(217, 224, 232, 0.85);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.88);
  color: #3f4a5c;
  font-size: 0.84rem;
  font-weight: 650;
  box-shadow: 0 8px 24px rgba(31, 41, 55, 0.12);
  backdrop-filter: blur(12px);
}

.control-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: calc(100vh - 40px);
  gap: 18px;
  padding: 22px;
  border: 1px solid rgba(217, 224, 232, 0.95);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.panel-header {
  display: grid;
  gap: 4px;
}

.eyebrow {
  margin: 0;
  color: var(--accent-dark);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.65rem, 1.35rem + 1vw, 2.25rem);
  line-height: 1.05;
}

h2 {
  font-size: 0.95rem;
  line-height: 1.2;
}

.add-form {
  display: grid;
  gap: 9px;
}

.add-form label {
  color: #30394a;
  font-size: 0.92rem;
  font-weight: 700;
}

.input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

input[type="text"] {
  min-width: 0;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
}

input[type="text"]::placeholder {
  color: #98a2b3;
}

.input-row button,
.function-actions button {
  height: 42px;
  padding: 0 14px;
  background: var(--accent);
  color: white;
  font-weight: 750;
}

.input-row button:hover,
.function-actions button:hover {
  background: var(--accent-dark);
}

.form-error,
.row-error {
  min-height: 18px;
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 650;
}

.functions-section {
  display: grid;
  gap: 10px;
  min-height: 0;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.section-heading span {
  min-width: 30px;
  height: 26px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: #445064;
  display: inline-grid;
  place-items: center;
  font-size: 0.82rem;
  font-weight: 800;
}

.function-list {
  display: grid;
  gap: 10px;
  overflow: auto;
  padding-right: 2px;
}

.function-item {
  display: grid;
  gap: 9px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel-soft);
}

.function-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.function-name {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
  color: #202838;
  font-weight: 800;
}

.color-dot {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  border-radius: 50%;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.92);
}

.switch-control {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #4a5568;
  font-size: 0.82rem;
  font-weight: 750;
  white-space: nowrap;
}

.switch-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-track {
  position: relative;
  width: 40px;
  height: 23px;
  flex: 0 0 auto;
  border: 1px solid #cbd5e1;
  border-radius: 999px;
  background: #e8edf4;
  transition:
    background 160ms ease,
    border-color 160ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 2px 6px rgba(31, 41, 55, 0.22);
  transition: transform 160ms ease;
}

.switch-control input:checked + .switch-track {
  border-color: var(--accent);
  background: var(--accent);
}

.switch-control input:checked + .switch-track::after {
  transform: translateX(17px);
}

.switch-control input:focus-visible + .switch-track {
  outline: 3px solid rgba(15, 107, 255, 0.28);
  outline-offset: 2px;
}

.switch-control input:disabled + .switch-track {
  opacity: 0.55;
}

.switch-control.is-disabled {
  color: #94a3b8;
  cursor: not-allowed;
}

.function-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 8px;
}

.derivative-expression {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 7px;
  background: #ffffff;
  color: #3f4a5c;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  font-weight: 650;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.derivative-expression.is-unavailable {
  color: #8a95a6;
  font-family: inherit;
}

.function-actions .delete-button {
  background: #fff1f1;
  color: #9f2727;
}

.function-actions .delete-button:hover {
  background: #ffe1e1;
}

.syntax-panel {
  display: grid;
  gap: 10px;
  margin-top: auto;
  padding-top: 4px;
}

.syntax-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.syntax-grid span {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  color: #526075;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  font-weight: 650;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .plot-area,
  .control-panel {
    min-height: auto;
  }

  #plotCanvas {
    min-height: 58vh;
  }

  .control-panel {
    order: -1;
  }
}

@media (max-width: 560px) {
  .app-shell {
    gap: 12px;
    padding: 12px;
  }

  .control-panel {
    padding: 16px;
  }

  .plot-toolbar {
    top: 10px;
    right: 10px;
  }

  .plot-status {
    left: 10px;
    bottom: 10px;
  }

  .input-row,
  .function-actions {
    grid-template-columns: 1fr;
  }

  .input-row button,
  .function-actions button {
    width: 100%;
  }
}
