/* ==================================================
   TRIANGLE SOLVER
   ================================================== */

.triangle-solver-body {
  display: grid;
  gap: .65rem;
  min-width: 0;
  padding: .7rem;
}

.triangle-orientation-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .45rem;
}

.triangle-orientation-tab {
  min-height: 3rem;
  padding: .35rem;
  color: var(--cnc-muted);
  background: #151a22;
  border: 1px solid var(--cnc-line);
  border-radius: .65rem;
  cursor: pointer;
}

.triangle-orientation-tab svg {
  display: block;
  width: 3rem;
  height: 2.2rem;
  margin: 0 auto;
}

.triangle-orientation-tab path:first-child {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linejoin: round;
}

.triangle-orientation-tab .right-mark {
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
}

.triangle-orientation-tab:hover,
.triangle-orientation-tab:focus-visible {
  color: var(--cnc-accent);
  border-color: var(--cnc-accent);
  outline: none;
}

.triangle-orientation-tab.is-active {
  color: #111;
  background: var(--cnc-accent);
  border-color: var(--cnc-accent-dark);
}

.triangle-stage {
  position: relative;
  min-height: 27rem;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(255, 212, 0, .055), transparent 55%),
    #151a22;
  border: 1px solid var(--cnc-line);
  border-radius: .9rem;
}

.triangle-diagram {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.triangle-leg,
.triangle-hypotenuse {
  vector-effect: non-scaling-stroke;
  stroke-linecap: round;
}

.triangle-leg {
  stroke: #f8fafc;
  stroke-width: 4;
}

.triangle-hypotenuse {
  stroke: var(--cnc-accent);
  stroke-width: 4;
}

.triangle-right-mark,
.triangle-angle-arc {
  fill: none;
  vector-effect: non-scaling-stroke;
}

.triangle-right-mark {
  stroke: var(--cnc-good);
  stroke-width: 2.5;
}

.triangle-angle-arc {
  stroke: var(--cnc-accent);
  stroke-width: 2.5;
}

.triangle-value {
  position: absolute;
  z-index: 2;
  display: grid;
  width: clamp(7rem, 16vw, 9rem);
  gap: .2rem;
  transform: translate(-50%, -50%);
}

.triangle-value span {
  color: var(--cnc-muted);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-align: center;
  text-transform: uppercase;
}

.triangle-value input {
  width: 100%;
  min-width: 0;
  padding: .5rem .55rem;
  color: #111;
  background: #f3f5f7;
  border: 2px solid #c9ced6;
  border-radius: .55rem;
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
}

.triangle-value input[type="number"] {
  appearance: textfield;
  -moz-appearance: textfield;
}

.triangle-value input[type="number"]::-webkit-outer-spin-button,
.triangle-value input[type="number"]::-webkit-inner-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.triangle-value input:focus {
  border-color: var(--cnc-accent);
  outline: 3px solid rgba(255, 212, 0, .2);
}

.triangle-value.is-known input {
  background: var(--cnc-accent);
  border-color: var(--cnc-accent-dark);
}

.triangle-value output {
  min-height: 1.05rem;
  color: var(--cnc-good);
  font-size: .72rem;
  font-weight: 800;
  text-align: center;
}

.triangle-value output::before {
  content: "Solved: ";
  color: var(--cnc-muted);
  font-weight: 700;
}

.triangle-value output:not(.is-solved)::before {
  content: "Value: ";
}

.triangle-fixed-angle {
  position: absolute;
  z-index: 2;
  transform: translate(-50%, -50%);
  padding: .18rem .35rem;
  color: var(--cnc-good);
  background: rgba(21, 26, 34, .82);
  border-radius: .3rem;
  font-size: .72rem;
  font-weight: 900;
  pointer-events: none;
}

.triangle-solver-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
}

.triangle-message {
  margin: 0;
  color: var(--cnc-muted);
  font-size: .9rem;
  font-weight: 700;
}

.triangle-message[data-state="solved"] {
  color: var(--cnc-good);
}

.triangle-message[data-state="error"] {
  color: var(--cnc-danger);
}

.triangle-clear {
  flex: 0 0 auto;
  padding: .45rem .8rem;
  color: var(--cnc-text);
  background: #303a49;
  border: 1px solid var(--cnc-line);
  border-radius: .55rem;
  cursor: pointer;
  font-weight: 800;
}

.triangle-clear:hover,
.triangle-clear:focus-visible {
  color: #111;
  background: var(--cnc-accent);
  border-color: var(--cnc-accent-dark);
  outline: none;
}

.triangle-more {
  overflow: hidden;
  background: #151a22;
  border: 1px solid var(--cnc-line);
  border-radius: .75rem;
}

.triangle-more summary {
  padding: .65rem .8rem;
  color: var(--cnc-accent);
  cursor: pointer;
  font-size: .82rem;
  font-weight: 900;
  letter-spacing: .08em;
  list-style-position: inside;
}

.triangle-more-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: .55rem;
  padding: 0 .7rem .7rem;
}

.triangle-more-result {
  display: grid;
  gap: .2rem;
  min-width: 0;
  padding: .55rem;
  background: var(--cnc-panel-2);
  border: 1px solid var(--cnc-line);
  border-radius: .55rem;
}

.triangle-more-result span {
  color: var(--cnc-muted);
  font-size: .7rem;
  font-weight: 800;
  letter-spacing: .05em;
  text-transform: uppercase;
}

.triangle-more-result strong {
  overflow-wrap: anywhere;
  font-size: 1rem;
}

/* Triangle Solver: compact, no-scroll desktop presentation. */

@media (min-width: 801px) {
  #triangle-solver-modal {
    padding: .75rem;
  }

  #triangle-solver-modal .triangle-solver-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(1040px, calc(100vw - 1.5rem));
    height: min(790px, calc(100vh - 1.5rem));
    max-height: calc(100vh - 1.5rem);
    overflow: hidden;
  }

  #triangle-solver-modal .triangle-solver-header {
    position: relative;
    padding: .75rem 1rem;
  }

  #triangle-solver-modal .triangle-solver-header h2 {
    font-size: 2.15rem;
    line-height: 1;
  }

  #triangle-solver-modal .triangle-solver-body {
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    min-height: 0;
    overflow: hidden;
    padding: .65rem;
  }

  #triangle-solver-modal .triangle-orientation-tabs {
    width: min(430px, 100%);
    margin: 0 auto;
  }

  #triangle-solver-modal .triangle-orientation-tab {
    min-height: 2.55rem;
  }

  #triangle-solver-modal .triangle-orientation-tab svg {
    width: 2.7rem;
    height: 1.85rem;
  }

  #triangle-solver-modal .triangle-stage {
    min-height: 0;
    height: 100%;
  }

  #triangle-solver-modal .triangle-value {
    width: 8.5rem;
  }

  #triangle-solver-modal .triangle-more-grid {
    grid-template-columns: repeat(7, minmax(0, 1fr));
  }

  #triangle-solver-modal .triangle-more-result {
    padding: .45rem;
  }

  #triangle-solver-modal .triangle-more-result strong {
    font-size: .9rem;
  }
}

@media (max-width: 800px) {
  #triangle-solver-modal .triangle-solver-panel {
    overflow: auto;
  }

  .triangle-stage {
    min-height: 30rem;
  }

  .triangle-value {
    width: 7rem;
  }
}


/* ==================================================
   TRIANGLE SOLVER — IMAGE-BASED LAYOUT
   ================================================== */

.triangle-orientation-tab img {
  display: block;
  width: 3rem;
  height: 2.2rem;
  margin: 0 auto;
  object-fit: contain;
}

.triangle-visual-shell {
  position: relative;
  min-height: 34rem;
  overflow: hidden;
  background:
    radial-gradient(circle at center, rgba(255, 212, 0, .055), transparent 58%),
    #151a22;
  border: 1px solid var(--cnc-line);
  border-radius: .9rem;
}

.triangle-reference-box {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(58%, 31rem);
  aspect-ratio: 1 / 1;
  transform: translate(-50%, -50%);
}

.triangle-reference-image {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  pointer-events: none;
}

.triangle-data-point {
  position: absolute;
  z-index: 3;
  width: 8.2rem;
  transform: translate(-50%, -50%);
}

.triangle-data-point--hypotenuse {
  left: 50%;
  top: 50%;
  width: 8.6rem;
}

.triangle-value {
  position: static;
  width: 100%;
  transform: none;
}

.triangle-value__label {
  display: block;
  margin-bottom: .22rem;
  color: var(--cnc-muted);
  font-size: .72rem;
  font-weight: 800;
  letter-spacing: .06em;
  text-align: center;
  text-transform: uppercase;
}

.triangle-value input {
  width: 100%;
  min-width: 0;
  padding: .48rem .5rem;
  color: #111;
  background: #f3f5f7;
  border: 2px solid #c9ced6;
  border-radius: .55rem;
  font-size: 1rem;
  font-weight: 800;
  text-align: center;
}

.triangle-data-point.is-known .triangle-value input {
  background: var(--cnc-accent);
  border-color: var(--cnc-accent-dark);
}

.triangle-value__solved {
  display: block;
  min-height: 1.05rem;
  margin-top: .18rem;
  color: var(--cnc-good);
  font-size: .72rem;
  font-weight: 800;
  text-align: center;
}

.triangle-value__solved.is-entered {
  color: var(--cnc-muted);
}

.triangle-value__solved.is-calculated {
  color: var(--cnc-good);
}

/* Side data points */

.triangle-data-point[data-slot="left"] {
  left: 8%;
  top: 50%;
}

.triangle-data-point[data-slot="right"] {
  left: 92%;
  top: 50%;
}

.triangle-data-point[data-slot="top"] {
  left: 50%;
  top: 10%;
}

.triangle-data-point[data-slot="bottom"] {
  left: 50%;
  top: 90%;
}

/* Acute-angle data points */

.triangle-data-point[data-slot="top-left"] {
  left: 10%;
  top: 12%;
}

.triangle-data-point[data-slot="top-right"] {
  left: 90%;
  top: 12%;
}

.triangle-data-point[data-slot="bottom-left"] {
  left: 10%;
  top: 88%;
}

.triangle-data-point[data-slot="bottom-right"] {
  left: 90%;
  top: 88%;
}

/* Hypotenuse stays inside the image box */

.triangle-data-point[data-slot="center"] {
  left: 50%;
  top: 50%;
}


/*
  Hypotenuse c occupies the open quadrant of the reference image.
  Positions are mirrored from the image boundaries, not eyeballed
  against the diagonal. The control remains INSIDE .triangle-reference-box.
*/

.triangle-data-point[data-slot="inside-top-left"] {
  left: 0;
  top: 0;
  right: auto;
  bottom: auto;
  transform: none;
}

.triangle-data-point[data-slot="inside-top-right"] {
  left: auto;
  top: 0;
  right: 0;
  bottom: auto;
  transform: none;
}

.triangle-data-point[data-slot="inside-bottom-right"] {
  left: auto;
  top: auto;
  right: 0;
  bottom: 0;
  transform: none;
}

.triangle-data-point[data-slot="inside-bottom-left"] {
  left: 0;
  top: auto;
  right: auto;
  bottom: 0;
  transform: none;
}

.triangle-data-point--hypotenuse .triangle-value {
  padding: .4rem;
  background: rgba(21, 26, 34, .88);
  border: 1px solid rgba(56, 68, 84, .9);
  border-radius: .65rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
}

/* ==================================================
   TRIANGLE SOLVER — DESKTOP
   ================================================== */

@media (min-width: 801px) {

  #triangle-solver-modal {
    padding: .75rem;
  }

  #triangle-solver-modal .triangle-solver-panel {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    width: min(1040px, calc(100vw - 1.5rem));
    height: min(790px, calc(100vh - 1.5rem));
    max-height: calc(100vh - 1.5rem);
    overflow: hidden;
  }

  #triangle-solver-modal .triangle-solver-header {
    position: relative;
    padding: .75rem 1rem;
  }

  #triangle-solver-modal .triangle-solver-header h2 {
    font-size: 2.15rem;
    line-height: 1;
  }

  #triangle-solver-modal .triangle-solver-body {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: .55rem;
    min-height: 0;
    overflow: hidden;
    padding: .65rem;
  }

  #triangle-solver-modal .triangle-orientation-tabs {
    width: min(470px, 100%);
    margin: 0 auto;
  }

  #triangle-solver-modal .triangle-orientation-tab {
    min-height: 3rem;
    padding: .25rem;
  }

  #triangle-solver-modal .triangle-orientation-tab img {
    width: 3.35rem;
    height: 2.55rem;
  }

  #triangle-solver-modal .triangle-visual-shell {
    min-height: 0;
    height: 100%;
  }

  #triangle-solver-modal .triangle-reference-box {
    width: min(56%, 30rem);
  }

  #triangle-solver-modal .triangle-data-point {
    width: 8rem;
  }

  #triangle-solver-modal .triangle-data-point--hypotenuse {
    width: 8.5rem;
  }

  #triangle-solver-modal .triangle-more-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  #triangle-solver-modal .triangle-more-result {
    padding: .45rem;
  }

  #triangle-solver-modal .triangle-more-result strong {
    font-size: .9rem;
  }
}

/* ==================================================
   TRIANGLE SOLVER — MOBILE
   ================================================== */

@media (max-width: 800px) {

  #triangle-solver-modal .triangle-solver-panel {
    overflow: auto;
  }

  .triangle-solver-body {
    gap: .6rem;
  }

  .triangle-orientation-tab img {
    width: 2.5rem;
    height: 1.9rem;
  }

  .triangle-visual-shell {
    min-height: 34rem;
  }

  .triangle-reference-box {
    width: min(56%, 18rem);
  }

  .triangle-data-point {
    width: 6.6rem;
  }

  .triangle-data-point--hypotenuse {
    width: 7rem;
  }

  .triangle-data-point[data-slot="left"] {
    left: 12%;
  }

  .triangle-data-point[data-slot="right"] {
    left: 88%;
  }

  .triangle-data-point[data-slot="top-left"] {
    left: 14%;
    top: 13%;
  }

  .triangle-data-point[data-slot="top-right"] {
    left: 86%;
    top: 13%;
  }

  .triangle-data-point[data-slot="bottom-left"] {
    left: 14%;
    top: 87%;
  }

  .triangle-data-point[data-slot="bottom-right"] {
    left: 86%;
    top: 87%;
  }
}


/* ==================================================
   TRIANGLE SOLVER — IMAGE-EDGE ANCHORS V3
   All primary controls are children of .triangle-reference-box.
   This makes every control position relative to the actual image edges.
   ================================================== */

.triangle-reference-box {
  --triangle-control-gap: 1rem;
  overflow: visible;
}

/* Reset the earlier shell-percentage positioning. */
.triangle-reference-box > .triangle-data-point {
  position: absolute;
  z-index: 4;
  width: 8.2rem;
  margin: 0;
}

/* --------------------------------------------------
   Side controls
   One outside edge + midpoint alignment.
   -------------------------------------------------- */

.triangle-reference-box > .triangle-data-point[data-slot="outside-left-center"] {
  top: 50%;
  right: calc(100% + var(--triangle-control-gap));
  bottom: auto;
  left: auto;
  transform: translateY(-50%);
}

.triangle-reference-box > .triangle-data-point[data-slot="outside-right-center"] {
  top: 50%;
  left: calc(100% + var(--triangle-control-gap));
  right: auto;
  bottom: auto;
  transform: translateY(-50%);
}

.triangle-reference-box > .triangle-data-point[data-slot="outside-top-center"] {
  left: 50%;
  bottom: calc(100% + var(--triangle-control-gap));
  top: auto;
  right: auto;
  transform: translateX(-50%);
}

.triangle-reference-box > .triangle-data-point[data-slot="outside-bottom-center"] {
  left: 50%;
  top: calc(100% + var(--triangle-control-gap));
  right: auto;
  bottom: auto;
  transform: translateX(-50%);
}

/* --------------------------------------------------
   Acute-angle controls
   Horizontal outside edge + top/bottom image-edge anchor.

   Example, orientation 1:
   Angle A = left of image, bottoms aligned.
   Angle B = right of image, tops aligned.
   -------------------------------------------------- */

.triangle-reference-box > .triangle-data-point[data-slot="outside-left-top"] {
  right: calc(100% + var(--triangle-control-gap));
  top: 0;
  left: auto;
  bottom: auto;
  transform: none;
}

.triangle-reference-box > .triangle-data-point[data-slot="outside-left-bottom"] {
  right: calc(100% + var(--triangle-control-gap));
  bottom: 0;
  left: auto;
  top: auto;
  transform: none;
}

.triangle-reference-box > .triangle-data-point[data-slot="outside-right-top"] {
  left: calc(100% + var(--triangle-control-gap));
  top: 0;
  right: auto;
  bottom: auto;
  transform: none;
}

.triangle-reference-box > .triangle-data-point[data-slot="outside-right-bottom"] {
  left: calc(100% + var(--triangle-control-gap));
  bottom: 0;
  right: auto;
  top: auto;
  transform: none;
}

/* --------------------------------------------------
   Hypotenuse c
   Lives in the open quadrant INSIDE the image.
   Same image-edge anchoring, mirrored per orientation.
   -------------------------------------------------- */

.triangle-reference-box > .triangle-data-point--hypotenuse[data-slot="inside-top-left"] {
  top: 0;
  left: 0;
  right: auto;
  bottom: auto;
  transform: none;
}

.triangle-reference-box > .triangle-data-point--hypotenuse[data-slot="inside-top-right"] {
  top: 0;
  right: 0;
  left: auto;
  bottom: auto;
  transform: none;
}

.triangle-reference-box > .triangle-data-point--hypotenuse[data-slot="inside-bottom-right"] {
  right: 0;
  bottom: 0;
  left: auto;
  top: auto;
  transform: none;
}

.triangle-reference-box > .triangle-data-point--hypotenuse[data-slot="inside-bottom-left"] {
  left: 0;
  bottom: 0;
  right: auto;
  top: auto;
  transform: none;
}

/* The bottom side control deliberately sits a little farther away
   than the other controls so it clears the image's b label cleanly. */
.triangle-reference-box > .triangle-data-point[data-slot="outside-bottom-center"] {
  top: calc(100% + var(--triangle-control-gap) + .35rem);
}

/* Keep top-side spacing visually symmetric if Side b flips upward. */
.triangle-reference-box > .triangle-data-point[data-slot="outside-top-center"] {
  bottom: calc(100% + var(--triangle-control-gap) + .35rem);
}

@media (min-width: 801px) {
  #triangle-solver-modal .triangle-reference-box {
    --triangle-control-gap: .85rem;
  }
}

@media (max-width: 800px) {
  #triangle-solver-modal .triangle-reference-box {
    --triangle-control-gap: .55rem;
  }

  .triangle-reference-box > .triangle-data-point {
    width: 6.6rem;
  }

  .triangle-reference-box > .triangle-data-point--hypotenuse {
    width: 7rem;
  }
}


@media (min-width: 801px) {
  #triangle-solver-modal .triangle-reference-box {
    --triangle-control-gap: .85rem;

    top: 50%;

    /*
      Reserve vertical room for the top/bottom controls.
      The image stays square and centered.
    */
    width: auto;
    height: calc(100% - 11rem);
    max-height: 30rem;
    aspect-ratio: 1 / 1;

    transform: translate(-50%, -50%);
  }
}

