.derivative-workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr);
  gap: 16px;
  align-items: stretch;
}

.derivative-input-panel,
.derivative-result-panel {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.derivative-result-panel .empty-state {
  flex: 1;
}

.derivative-field label {
  display: block;
  margin-bottom: 5px;
  color: var(--text-dim);
  font-size: 11px;
}

.plot-slider {
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: 640px;
  margin: 10px auto 0;
  padding: 8px 10px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--surface-2);
}

.plot-slider label {
  color: var(--text-dim);
  font-size: 11px;
  white-space: nowrap;
}

.x0-slider {
  flex: 1;
  min-width: 0;
  accent-color: var(--accent);
}

.slider-bound {
  color: var(--text-faint);
  font-family: var(--font-mono);
  font-size: 10px;
}

.x0-input {
  width: 64px;
  height: 28px;
  padding: 0 6px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  color: var(--accent);
  font-family: var(--font-mono);
  font-size: 12px;
  text-align: center;
}

.x0-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.x0-input:disabled,
.x0-slider:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.derivative-input {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface-2);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 15px;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.derivative-input::placeholder {
  color: var(--text-faint);
  opacity: 0.65;
}

.derivative-input:hover {
  border-color: var(--border);
  background: var(--surface-hover);
}

.derivative-input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

.function-keypad {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin-top: 8px;
}

.keypad-label {
  margin-right: 2px;
  color: var(--text-faint);
  font-size: 11px;
}

.keypad-button {
  min-width: 36px;
  height: 30px;
  padding: 0 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text-dim);
  font-family: var(--font-math);
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.keypad-button:hover {
  border-color: var(--accent-border);
  background: var(--surface-hover);
  color: var(--text);
}

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

.derivative-result-grid {
  display: grid;
  gap: 10px;
}

.derivative-result-card {
  padding: 13px;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: var(--surface-2);
}

.derivative-result-label {
  color: var(--text-faint);
  font-family: var(--font-math);
  font-size: 12px;
}

.derivative-expression {
  margin-top: 9px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 20px;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

.derivative-expression.is-derivative {
  color: var(--accent);
}

.derivative-tangent {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
}

.derivative-subhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}

.derivative-tangent-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.derivative-tangent-card {
  padding: 10px;
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  background: var(--surface-2);
}

.derivative-tangent-value {
  margin-top: 8px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 16px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.derivative-tangent-value.is-equation {
  color: var(--accent);
}

.help-static h3 {
  margin: 0 0 8px;
  color: var(--text-dim);
  font-size: 12px;
  font-weight: 600;
}

.derivative-plot-panel {
  margin-top: 16px;
}

.plot-wrap {
  position: relative;
  max-width: 640px;
  margin: 0 auto;
}

.function-plot {
  display: block;
  width: 100%;
  height: auto;
  overflow: hidden;
  border: 1px solid var(--border-soft);
  border-radius: 9px;
  background: var(--surface-2);
}

.plot-tangent-note {
  position: absolute;
  left: 9%;
  bottom: 12%;
  display: flex;
  align-items: baseline;
  gap: 7px;
  max-width: 48%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  box-shadow: var(--shadow);
  pointer-events: none;
}

.plot-tangent-note[hidden] {
  display: none;
}

.plot-tangent-note-label {
  flex: 0 0 auto;
  color: var(--warning);
  font-size: 10px;
  font-weight: 600;
}

.plot-tangent-note-equation {
  overflow: hidden;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.plot-grid-line {
  stroke: var(--border-soft);
  stroke-width: 1;
}

.plot-axis {
  stroke: var(--border);
  stroke-width: 1.4;
}

.plot-tick {
  fill: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
}

.plot-axis-label {
  fill: var(--text-dim);
  font-family: var(--font-math);
  font-size: 13px;
  font-style: italic;
}

.plot-curve {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.plot-tangent {
  stroke: var(--warning);
  stroke-width: 1.8;
  stroke-dasharray: 6 5;
}

.plot-point {
  fill: var(--warning);
  stroke: var(--surface);
  stroke-width: 2;
}

.plot-point-label {
  fill: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 10px;
}

.plot-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  max-width: 640px;
  margin: 9px auto 0;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-faint);
  font-size: 11px;
}

.legend-line {
  width: 18px;
  height: 2px;
  background: var(--accent);
}

.legend-tangent {
  width: 18px;
  border-top: 2px dashed var(--warning);
}

.legend-point {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--warning);
}

.derivative-note {
  margin: 14px 0 0;
  padding-top: 11px;
  border-top: 1px solid var(--border-soft);
  color: var(--text-faint);
  font-size: 11.5px;
  line-height: 1.7;
}

.derivative-result-panel .result-summary {
  margin-bottom: 0;
}

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

  .derivative-result-panel .empty-state {
    min-height: 210px;
  }
}

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

  .plot-slider {
    flex-wrap: wrap;
  }

  .slider-bound {
    order: 1;
  }

  .x0-input {
    order: 2;
  }

  .x0-slider {
    order: 3;
    flex-basis: 100%;
  }
}
