.guided-math {
  --guided-selected: #166534;
  --guided-selected-text: #fff;
  --guided-hour: #165e39;
  --guided-minute: #1e40af;
}

.dark .guided-math {
  --guided-selected: #91d9a9;
  --guided-selected-text: #102519;
  --guided-hour: #91d9a9;
  --guided-minute: #9cc0ff;
}

.dark .calculator-page:has(.guided-math) :is(.related-content, .calculator-sources) a {
  color: #a7c7ff;
}

.guided-math [hidden] { display: none; }

.calculator-page--standard .guided-math .guided-math-field,
.guided-math-results > div {
  display: grid;
  grid-template-columns: minmax(8rem, 1fr) minmax(0, 1.4fr);
  align-items: center;
  gap: 0.35rem 1rem;
}

.calculator-page--standard .guided-math .calc-label { white-space: normal; }

.calculator-page--standard .guided-math .guided-math-field :is(.calc-input, .calc-select) {
  box-sizing: border-box;
  width: 100%;
  min-width: 0;
}

.guided-math-examples,
.calculator-page--standard .guided-math .calc-actions {
  display: grid;
  width: 100%;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.5rem;
}

.guided-math-examples button {
  min-height: 44px;
  white-space: normal;
}

.guided-math:is([data-guided-math="trapezoid"], [data-guided-math="great-circle"]) .guided-math-examples .btn-clear {
  text-transform: none;
}

.guided-field-groups {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr));
  gap: 1rem;
  margin: 1rem 0;
}

.guided-field-groups fieldset {
  min-inline-size: 0;
  margin: 0;
  padding: .75rem;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
}

.dark .guided-field-groups fieldset {
  border-color: #64748b;
}

.guided-field-groups legend {
  padding-inline: .4rem;
  font-weight: 700;
}

.guided-math:has([data-field-layout="stacked"]) .guided-field-groups {
  grid-template-columns: minmax(0, 1fr);
  gap: .75rem;
}

.guided-math [data-field-layout="stacked"] > fieldset:not([hidden]) {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  align-items: end;
  gap: .75rem 1rem;
}

.calculator-page--standard .guided-math:has([data-field-layout="stacked"]) fieldset > .guided-math-field {
  grid-template-columns: minmax(0, 1fr);
  gap: .3rem;
  margin: 0;
}

.guided-math [data-field-layout="stacked"] .guided-math-measure {
  grid-template-columns: minmax(0, 1fr) minmax(6rem, .32fr);
}

@media (min-width: 601px) {
  .guided-math [data-field-layout="stacked"] > fieldset:not([hidden]) {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .guided-math [data-field-layout="stacked"] > fieldset >
    .guided-math-field:nth-child(odd of .guided-math-field:not([hidden])):nth-last-child(1 of .guided-math-field:not([hidden])) {
    grid-column: 1 / -1;
  }
}

.guided-coordinate-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, .85fr);
  align-items: end;
  gap: .5rem;
}

.calculator-page--standard .guided-math .guided-coordinate-row .guided-math-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
}

.guided-formula-disclosure summary {
  display: list-item;
  min-height: 44px;
  padding-block: .65rem;
  cursor: pointer;
}

.calculator-page--standard .guided-math .guided-math-examples .btn-clear[aria-pressed="true"] {
  border-color: var(--guided-selected);
  background: var(--guided-selected);
  color: var(--guided-selected-text);
}

.calculator-page--standard .guided-math .guided-math-formula {
  box-sizing: border-box;
  display: flex;
  width: 100%;
  flex-direction: column;
  margin-top: 1.25rem;
  padding: 1.25rem 1rem;
  gap: 0.75rem;
  font-style: normal;
}

.guided-math-formula > math { font-size: clamp(1.25rem, 3.5vw, 1.65rem); }

.calculator-page--standard .guided-math .guided-math-formula ul {
  box-sizing: border-box;
  width: fit-content;
  max-width: 100%;
  margin: 0 auto;
  padding-inline-start: 1.15em;
  list-style: disc outside;
  text-align: start;
}

.guided-math .guided-math-results { margin: 0; }

.guided-math .guided-math-results :is(dt, dd) {
  margin: 0;
  overflow-wrap: anywhere;
}

.guided-math .guided-math-results dd {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.guided-math .guided-math-results .guided-math-equation {
  min-width: 0;
  overflow-x: auto;
}

.guided-math-equation:focus-visible {
  outline: 2px solid currentColor;
  outline-offset: 2px;
}

.guided-math .guided-math-table {
  margin-top: 1rem;
  overflow: auto;
}

.calculator-page--standard .guided-math .guided-math-table :is(th, td) {
  text-align: center;
  vertical-align: middle;
  overflow-wrap: anywhere;
}

.guided-math-table caption { font-weight: 700; }

.guided-math-measure {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(4.5rem, 0.55fr);
  gap: 0.5rem;
  width: 100%;
}

.guided-math [data-share-url] {
  opacity: 0.8;
}

.guided-math-details {
  margin-top: 1.25rem;
}

.guided-math-details li {
  margin-bottom: 1rem;
}

.guided-math-details li p {
  margin-bottom: 0.35rem;
}

.guided-math-step-equation {
  overflow: auto;
  text-align: start;
}

.calculator-page--standard .guided-math .guided-math-share {
  grid-template-columns: 1fr;
  margin-top: 1rem;
}

.guided-math [data-share-url] {
  width: 100%;
}

.guided-math-visual {
  margin: 1.5rem 0 0;
  text-align: center;
}

.guided-math-visual canvas {
  display: block;
  width: min(100%, 43rem);
  height: auto;
  margin: 0 auto;
}

.guided-math-visual figcaption {
  margin-top: 0.4rem;
}

.guided-math-triangle {
  overflow: auto;
  text-align: center;
}

.calculator-page--standard .guided-math .guided-math-triangle ol {
  display: grid;
  justify-items: center;
  width: max-content;
  min-width: 100%;
  list-style: none;
  margin: 0 auto;
  padding: 0;
}

.calculator-page--standard .guided-math .guided-math-triangle li {
  display: flex;
  gap: 0.6rem;
  align-items: center;
  margin: 0.3rem 0;
  padding: 0;
}

.guided-math-triangle li span {
  border: 1px solid currentColor;
  border-radius: 0.25rem;
  min-width: 2rem;
  padding: 0.18rem 0.35rem;
}

.guided-clock {
  position: relative;
  width: min(12rem, 100%);
  aspect-ratio: 1;
  margin: 1.5rem auto 0;
  border: 2px solid currentColor;
  border-radius: 50%;
  color: inherit;
}

.guided-clock > span {
  position: absolute;
  font-weight: 700;
}

.guided-clock-north { top: 4%; left: 50%; transform: translateX(-50%); }
.guided-clock-east { top: 50%; right: 6%; transform: translateY(-50%); }
.guided-clock-south { bottom: 4%; left: 50%; transform: translateX(-50%); }
.guided-clock-west { top: 50%; left: 6%; transform: translateY(-50%); }

.guided-clock-hour,
.guided-clock-minute {
  bottom: 50%;
  left: calc(50% - 2px);
  width: 4px;
  border-radius: 4px;
  transform-origin: bottom center;
}

.guided-clock-hour { height: 25%; background: var(--guided-hour); transform: rotate(var(--hour-hand)); }
.guided-clock-minute { height: 36%; background: var(--guided-minute); transform: rotate(var(--minute-hand)); }

@media (max-width: 600px) {
  .calculator-page--standard .guided-math .guided-math-field,
  .guided-math-results > div { grid-template-columns: 1fr; }

  .guided-math-results > div + div { margin-top: 0.65rem; }
}
