/* Matephis Plot Styling */

/* Container */
.matephis-plot-container {
  display: flex;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
  -webkit-user-select: none;
  cursor: default;
  /* Explicit default cursor to stop inheritance */

  flex-direction: column;
  align-items: center;
  margin: .25rem 0 20px 0; /* Add bottom margin for toolbar (I NEED TO FIGURE THIS OUT) */
  max-width: 70%;
  width: 100%;
}

.matephis-plot-container.bordered {
  border: 1px solid var(--border-color, #e1e1e1);
}

/* Modifiers */
.matephis-plot-container.align-center {
  margin-left: auto;
  margin-right: auto;
}

.matephis-plot-container.align-left {
  margin-left: 0;
  margin-right: auto;
}

/* Stage */
.matephis-plot-stage {
  position: relative;
  width: 100%;
}

/* SVG */
.matephis-plot-svg {
  background: transparent;
  max-width: 100%;
  width: 100%;
  height: auto;
  font-family: var(--font-plot, monospace);
  display: block;
  user-select: none;
  -webkit-user-select: none;
}

/* Fix for mobile pinch: ensure touches pass through lines/text to the SVG handler */
.matephis-plot-svg * {
  pointer-events: none;
}

.matephis-plot-svg.interactive {
  cursor: default;
}

.matephis-plot-svg.static {
  cursor: zoom-in;
}

/* Error */
.matephis-plot-error {
  color: red;
  border: 1px solid red;
  padding: 5px;
}

/* Derivative Plot */
.matephis-derivative-plot {
  width: 100%;
  max-width: 100%;
  margin: 15px auto 0 auto;
  border-top: 1px dashed #eee;
  padding-top: 15px;
  display: flex;
  flex-direction: column;
  align-items: center;
}

/* Derivative Plot internal instance should be tighter */
.matephis-derivative-plot .matephis-plot-container {
  margin: 0 !important;
  max-width: 100% !important;
  width: 100% !important;
}

.matephis-derivative-title {
  font-family: var(--font-plot, sans-serif);
  font-size: 0.9rem;
  font-weight: bold;
  color: #666;
  margin-bottom: 10px;
  text-align: center;
}

/* Controls (Sliders) */
.matephis-plot-controls {
  width: 100%;
  max-width: 600px;
  padding: 12px 16px;
  background: #fff;
  border-top: 1px solid #f0f0f0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
}

.matephis-slider-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-family: var(--font-plot, monospace);
  font-size: 0.85rem;
}

.matephis-slider-row.slider-bordered {
  border: 1px solid var(--border-color, #e1e1e1);
  padding: 6px 0px 6px 12px;
  margin-bottom: 4px;
}

.matephis-slider-label-group {
  min-width: 80px;
  white-space: nowrap;
  text-align: left;
  display: flex;
  align-items: center;
}

.matephis-slider-label {
  font-weight: bold;
}

.matephis-slider-val {
  min-width: 4ch;
  text-align: left;
  color: var(--accent, #B01A00);
  font-weight: bold;
  margin-left: 8px;
}

.matephis-slider-min,
.matephis-slider-max {
  font-size: 0.8em;
  color: #999;
  min-width: 40px;
  display: inline-block;
}

.matephis-slider-min {
  margin-right: 8px;
  text-align: right;
}

.matephis-slider-max {
  margin-left: 8px;
  text-align: left;
}

.matephis-slider-row input[type=range] {
  -webkit-appearance: none;
  appearance: none;
  flex-grow: 1;
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  outline: none;
  cursor: default;
}

.matephis-slider-row input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 6px;
  height: 6px;
  background: var(--accent, #B01A00);
  border: none;
  border-radius: 50%;
  box-shadow: 0 0 0 6px rgba(176, 26, 0, 0.2);
  cursor: pointer;
  transition: all 0.1s ease-in-out;
  margin-top: 0;
}

.matephis-slider-row input[type=range]::-webkit-slider-thumb:hover {
  outline: 6px solid #b01a00;
}

.matephis-slider-row input[type=range]::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: none;
  background: var(--accent, #B01A00);
  cursor: pointer;
  transition: transform 0.1s;
}

.matephis-slider-row input[type=range]::-moz-range-thumb:hover {
  transform: scale(1.2);
}

/* Toolbar (Below Plot) */
.matephis-plot-toolbar {
  display: flex;
  justify-content: center;
  align-items: center; /* Fix vertical alignment */
  gap: 8px;
  width: 100%;
  z-index: 10;
  cursor: default;
  /* Toolbar background should be default */
}

.matephis-plot-btn {
  background: #f0f0f0;
  border: none;
  border-radius: 0;
  width: 32px;
  height: 32px;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 !important;
  margin: 0 !important;
  line-height: normal !important;
  cursor: pointer;
  user-select: none;
  box-sizing: border-box !important;
}

.matephis-plot-btn:not(.active):hover {
  background: #e0e0e0;
}

.matephis-plot-btn:active {
  background: #d0d0d0;
}

.matephis-plot-btn.active {
  background: var(--accent, #B01A00);
}

.matephis-plot-btn.active img,
.matephis-plot-btn.active svg {
  opacity: 1;
  filter: brightness(0) invert(1); /* Make white */
}

.matephis-plot-separator {
  width: 1px;
  height: 24px;
  background: #ddd;
  margin: 4px 4px;
}

.matephis-plot-btn img,
.matephis-plot-btn svg {
  opacity: 0.6;
  pointer-events: none;
  /* Let clicks pass to button */
  margin: 0 !important;
  padding: 0 !important;
  display: block !important;
  width: 20px !important;
  height: 20px !important;
  min-width: 20px !important;
  min-height: 20px !important;
  max-width: 20px !important;
  max-height: 20px !important;
  flex-shrink: 0 !important;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  background: none !important;
  color: inherit; /* Allow fill="currentColor" to work */
}

.matephis-plot-btn:hover img,
.matephis-plot-btn:hover svg {
  opacity: 0.9;
}

@media (max-width: 768px) {
  .matephis-plot-container {
    max-width: 90%;
    width: 90%;
  }
}

.matephis-plot-container.interactive {
  touch-action: none;
}

/* SVG Text - Force Font Family */
.matephis-plot-text {
  font-family: var(--font-plot, 'Space Mono', monospace) !important;
}

/* Captions for plots */
.matephis-plot + pre + p:has(> em:only-child) {
  text-align: left;
  font-size: 0.85rem;
  color: #888;
  font-family: var(--font);
  font-style: normal;
  margin-top: var(--space-xs);
  margin-bottom: var(--space-lg);
  margin-left: var(--space-sm);
  margin-right: var(--space-sm);
}

.matephis-plot:has(.matephis-plot-container.align-center)+pre+p:has(> em:only-child) {
  text-align: center;
  padding: 0 var(--space-lg) 0 var(--space-lg);
}

/* Utility to forcibly hide elements */
.matephis-hidden {
  display: none !important;
}

/* Animation Controls */
.matephis-plot-play-btn {
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.7;
  transition: opacity 0.2s;
  min-width: 24px;
}
.matephis-plot-play-btn:hover {
  opacity: 1;
}
.matephis-plot-play-btn img,
.matephis-plot-play-btn svg {
  width: 20px;
  height: 20px;
  pointer-events: none;
  color: #1f1f1f;
}
