/* Polar-scope formula — scoped so it does not collide with the site chrome. */

.math-stage {
  --panel: rgba(8, 8, 10, 0.88);
  --math-line: #222228;
  --math-text: #f2f2f6;
  --math-muted: #8a8a96;
  --c0: #6cf0ff;
  --c1: #ff3d7a;
  --pad: 18px;
  position: relative;
  flex: 1;
  min-height: 0;
  background: #000;
  color: var(--math-text);
  font: 13px/1.45 "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
  overflow: hidden;
}

.math-stage * {
  box-sizing: border-box;
}

.math-stage #view {
  display: block;
  width: 100%;
  height: 100%;
  background: #000;
  touch-action: none;
  cursor: grab;
}

.math-stage #view:active {
  cursor: grabbing;
}

.math-stage .panel {
  position: absolute;
  top: 16px;
  left: 16px;
  bottom: 16px;
  width: 312px;
  overflow: auto;
  padding: var(--pad);
  background: var(--panel);
  border: 1px solid var(--math-line);
  border-left: 3px solid transparent;
  border-image: linear-gradient(to bottom, var(--c0), var(--c1)) 1;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: var(--math-text);
  z-index: 2;
}

.math-stage .panel-head {
  margin-bottom: 18px;
}

.math-stage .kicker {
  margin: 0 0 10px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--math-muted);
}

.math-stage .formula {
  display: flex;
  align-items: center;
  gap: 10px;
}

.math-stage .fname {
  font-size: 22px;
  font-style: italic;
  font-weight: 500;
}

.math-stage .fargs,
.math-stage .eq {
  font-style: italic;
  color: #c8c8d0;
}

.math-stage .eq {
  margin-left: 6px;
}

.math-stage .mat {
  display: flex;
  align-items: stretch;
  gap: 6px;
}

.math-stage .br {
  width: 8px;
  border: 1.5px solid #d8d8e0;
}

.math-stage .br.left {
  border-right: 0;
  border-radius: 6px 0 0 6px;
}

.math-stage .br.right {
  border-left: 0;
  border-radius: 0 6px 6px 0;
}

.math-stage .rows {
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 3px;
  font-family: "Cambria Math", "Times New Roman", ui-serif, serif;
  font-size: 13px;
  white-space: nowrap;
}

.math-stage .frac {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  line-height: 1.15;
}

.math-stage .frac .num {
  border-bottom: 1px solid #d0d0d8;
  padding: 0 4px 1px;
}

.math-stage .frac .den {
  padding: 1px 4px 0;
}

.math-stage .rep {
  text-decoration: overline;
}

.math-stage .note {
  margin: 8px 0 0;
  color: var(--math-muted);
  font-size: 11px;
}

.math-stage section + section,
.math-stage .advanced {
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--math-line);
}

.math-stage h2,
.math-stage summary {
  margin: 0 0 10px;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--math-muted);
}

.math-stage .ctrl {
  display: block;
  margin-bottom: 10px;
}

.math-stage .ctrl-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 5px;
  color: #c4c4cc;
}

.math-stage .ctrl-head output,
.math-stage code {
  font-family: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, monospace;
  font-size: 11px;
  color: var(--math-text);
}

.math-stage input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 3px;
  border-radius: 2px;
  background: #2a2a32;
  outline: none;
}

.math-stage input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  cursor: pointer;
}

.math-stage input[type="range"]::-moz-range-thumb {
  width: 13px;
  height: 13px;
  border-radius: 50%;
  background: #fff;
  border: 0;
  cursor: pointer;
}

.math-stage .btn-row {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.math-stage .btn {
  flex: 1;
  height: 32px;
  border: 1px solid #2e2e36;
  background: #111114;
  color: var(--math-text);
  font: inherit;
  letter-spacing: 0.04em;
  cursor: pointer;
  padding: 0;
}

.math-stage .btn:hover {
  border-color: #4a4a56;
  opacity: 1;
  background: #111114;
}

.math-stage .btn.primary {
  background: #f4f4f8;
  color: #111;
  border-color: #f4f4f8;
}

.math-stage .btn.primary:hover {
  background: #fff;
  color: #111;
}

.math-stage .colors .swatches {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.math-stage .colors .swatches.three {
  grid-template-columns: 1fr 1fr 1fr;
}

.math-stage .colors .swatches.three .swatch {
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
}

.math-stage .colors .swatches.three input[type="color"] {
  width: 100%;
  height: 40px;
}

.math-stage .swatch {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
}

.math-stage .swatch span {
  display: block;
  color: #c4c4cc;
}

.math-stage .swatch code {
  display: block;
  margin-top: 2px;
  color: var(--math-muted);
}

.math-stage input[type="color"] {
  -webkit-appearance: none;
  appearance: none;
  width: 52px;
  height: 52px;
  padding: 0;
  border: 1px solid #33333a;
  background: none;
  cursor: pointer;
}

.math-stage input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.math-stage input[type="color"]::-webkit-color-swatch {
  border: 0;
}

.math-stage input[type="color"]::-moz-color-swatch {
  border: 0;
}

.math-stage .checks {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px 10px;
}

.math-stage .check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #c4c4cc;
  cursor: pointer;
}

.math-stage .check input {
  accent-color: var(--c0);
}

.math-stage .advanced summary {
  cursor: pointer;
  list-style: none;
}

.math-stage .advanced summary::-webkit-details-marker {
  display: none;
}

.math-stage .advanced[open] summary {
  margin-bottom: 12px;
}

.math-stage .hint {
  position: absolute;
  left: auto;
  right: 72px;
  bottom: 28px;
  margin: 0;
  color: #4a4a54;
  font-size: 11px;
  letter-spacing: 0.08em;
  pointer-events: none;
}

.math-stage .toggle {
  display: none;
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 3;
  height: 32px;
  padding: 0 12px;
  border: 1px solid #2e2e36;
  background: #0a0a0c;
  color: var(--math-text);
  font: inherit;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
}

.math-stage .panel.hidden {
  display: none;
}

@media (max-width: 720px) {
  .math-stage .toggle {
    display: block;
  }

  .math-stage .hint {
    display: none;
  }

  .math-stage .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    max-height: 48%;
    border-left: 0;
    border-image: none;
    border-top: 3px solid transparent;
    border-image: linear-gradient(to right, var(--c0), var(--c1)) 1;
  }
}
