/* DECODE — calculator */

.calc {
  padding-block: var(--space-6) var(--space-8);
  align-items: start;
}

/* ---------- Controls ---------- */
.calc__controls {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

/* Hints are filled after load; reserve a line so nothing below them shifts. */
.calc__controls .field__hint {
  min-height: 1.45em;
}

.calc__custom {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding-left: var(--space-4);
  border-left: 2px solid var(--hairline-strong);
}

.calc__custom[hidden] {
  display: none;
}

.calc__actions {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding-top: var(--space-2);
}

.calc__actions-note {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink-2);
}

.slider__tick--off {
  text-decoration: line-through;
  text-decoration-color: var(--ink-2);
}

/* ---------- Readouts ---------- */
.calc__readouts {
  position: sticky;
  top: calc(var(--header-height) + var(--space-5));
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
}

.calc__summary,
.calc__details {
  display: flex;
  flex-direction: column;
  gap: var(--space-5);
}

.calc__verdict {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.verdict__icon path {
  display: none;
}

/* The reason is written by script before the data arrives and again after.
   On narrow screens it runs to two lines, so two are reserved from the start. */
@media (max-width: 720px) {
  .calc__verdict .verdict__reason {
    min-height: 3.1em;
  }
}

.verdict--fits path[data-icon="fits"],
.verdict--tight path[data-icon="tight"],
.verdict--wont-fit path[data-icon="wont-fit"],
.verdict--unknown path[data-icon="unknown"] {
  display: block;
}

/* ---------- Memory bar ---------- */
.calc__bar-wrap {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
}

.calc__bar-track {
  padding-right: 22%; /* room for the overflow segment to run past the frame */
}

.calc__bar {
  position: relative;
  display: flex;
  height: 32px;
  width: 100%;
  background: var(--panel-2);
  border-radius: var(--radius-panel);
}

/* Right edge of the frame: the machine's memory. Marked so overflow reads as past it. */
.calc__bar::after {
  content: "";
  position: absolute;
  right: -1px;
  top: -6px;
  bottom: -6px;
  border-right: 1px solid var(--ink);
  pointer-events: none;
}

.calc__bar-segment {
  flex: 0 0 auto;
  width: 0;
  height: 100%;
  position: relative;
}

.calc__bar-segment + .calc__bar-segment {
  box-shadow: inset 1px 0 0 var(--panel-0);
}

.calc__bar-segment--weights { background: var(--weights); }
.calc__bar-segment--cache { background: var(--cache); }
.calc__bar-segment--overhead { background: var(--overhead); }

/* Free memory is the empty part of the room: tinted, with a solid baseline. */
.calc__bar-segment--free {
  background:
    linear-gradient(to top, var(--room) 0 2px, transparent 2px),
    color-mix(in srgb, var(--room) 22%, var(--panel-2));
}

.calc__bar-segment--overflow {
  background: var(--fail);
  z-index: 1;
}

.calc__bar-segment--overflow::after {
  content: "";
  position: absolute;
  right: 0;
  top: 0;
  bottom: 0;
  width: 12px;
  background: linear-gradient(to right, transparent, var(--panel-0));
}

.calc__bar-segment--overflow[data-capped="true"]::after {
  width: 24px;
}

.calc__bar-scale {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-2);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--step--1);
  color: var(--ink-3);
}

/* ---------- Token stream: the door ---------- */
.calc__stream {
  position: relative;
  height: 56px;
  border-top: 1px solid var(--hairline);
  border-bottom: 1px solid var(--hairline);
  overflow: hidden;
}

/* The door frame at the left edge: tokens come out of it. */
.calc__stream::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 2px;
  background: var(--ink);
}

/* ---------- Speed readouts ---------- */
.calc__speed .readout__value {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
}

.readout--hidden .readout__value {
  color: var(--ink-3);
}

/* ---------- Compare ---------- */
.calc__compare[hidden] {
  display: none;
}

.calc__pins {
  list-style: none;
  padding: 0;
  margin: 0;
}

.calc__pin {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2) var(--space-4);
  padding-block: var(--space-4);
}

.calc__pin + .calc__pin {
  border-top: 1px solid var(--hairline);
}

.calc__pin-title {
  font-size: var(--step-0);
  color: var(--ink);
}

.calc__pin-title .num {
  color: var(--ink-2);
}

.calc__pin-bar {
  grid-column: 1 / -1;
}

.calc__pin-bar .calc__bar {
  height: 16px;
}

.calc__pin-bar .calc__bar::after {
  top: -4px;
  bottom: -4px;
}

.calc__pin-meta {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-5);
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-size: var(--step--1);
  color: var(--ink-2);
}

.calc__pin-meta .verdict {
  font-size: var(--step--1);
  font-weight: 500;
}

.calc__pin-meta .num {
  color: var(--ink);
}

.calc__compare-actions {
  padding-top: var(--space-3);
}

/* ---------- Suggestions ---------- */
.calc__suggestions[hidden] {
  display: none;
}

.calc__fixes {
  list-style: none;
  padding: 0;
  margin: 0;
}

.calc__fix {
  display: grid;
  grid-template-columns: minmax(180px, auto) 1fr;
  gap: var(--space-2) var(--space-4);
  align-items: start;
  padding-block: var(--space-3);
}

.calc__fix + .calc__fix {
  border-top: 1px solid var(--hairline);
}

.calc__fix-delta {
  font-size: var(--step-0);
  color: var(--ink-2);
  padding-top: 0.35em;
}

.calc__fix-result {
  font-family: var(--font-mono);
  font-size: var(--step--1);
  color: var(--ink);
  margin-left: var(--space-2);
}

.calc__disclaimer {
  font-size: var(--step--1);
  color: var(--ink-3);
  max-width: 60ch;
}

/* ---------- Mobile: readouts stick above the controls ---------- */
@media (max-width: 960px) {
  .calc {
    row-gap: var(--space-5);
  }

  .calc__readouts {
    display: contents;
  }

  .calc__summary,
  .calc__details {
    grid-column: 1 / -1;
  }

  .calc__summary {
    order: -1;
    position: sticky;
    top: var(--header-height);
    z-index: 5;
    gap: var(--space-3);
    margin-inline: calc(-1 * var(--margin));
    padding: var(--space-3) var(--margin) var(--space-4);
    background: var(--panel-0);
    border-bottom: 1px solid var(--hairline);
  }

  .calc__summary .rule {
    display: none;
  }

  .calc__summary .verdict--lg {
    font-size: var(--step-3);
  }

  .calc__summary .verdict__reason {
    font-size: var(--step--1);
  }

  .calc__summary .notice {
    display: none;
  }

  .calc__bar {
    height: 22px;
  }

  .calc__bar-track {
    padding-right: 18%;
  }

  .calc__bar-wrap {
    gap: var(--space-2);
  }

  .calc__bar-scale {
    display: none;
  }

  .calc__summary .legend {
    gap: var(--space-2) var(--space-4);
    font-size: 0.75rem;
  }

  .calc__speed .readout--lg .readout__value {
    font-size: var(--step-3);
  }

  .calc__speed {
    grid-template-columns: 1fr 1fr;
    gap: var(--space-4);
  }

  .calc__speed .readout__note {
    display: none;
  }

  .calc__stream {
    display: none;
  }

  .calc__controls {
    order: 0;
  }

  .calc__details {
    order: 1;
  }

  .calc__fix {
    grid-template-columns: 1fr;
  }

  .calc__details .readout-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) and (max-height: 700px) {
  /* Short phones: keep the sticky strip small */
  .calc__summary .verdict__reason {
    display: none;
  }
}

/* ---------- Print ---------- */
@media print {
  .calc__readouts {
    position: static;
  }

  .calc__actions {
    display: none;
  }
}
