/* ==========================================================================
   calculator.css — the tool itself
   Requires tokens.css + base.css (+ layout.css for page context).

   PRINCIPLE
   --------------------------------------------------------------------------
   The result display is the hero of every page. A visitor arrives from a
   search result, needs one number, and leaves. On a 375x667 phone the H1,
   the inputs and the answer must all be visible without scrolling — so the
   calculator is deliberately compact and the answer is deliberately huge.

   The result panel is rendered on first paint with its default/prefilled
   value, at its final height. It is never empty-then-filled: an empty state
   that later grows is a layout shift and also a worse product.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. THE CARD
   -------------------------------------------------------------------------- */
.calc {
  background-color: var(--surface);
  border: var(--bw) solid var(--border);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-md);
  overflow: hidden; /* keeps the result panel's corners inside the card */
}

.calc__form {
  display: grid;
  gap: var(--sp-4);
  padding: var(--sp-4);
}

@media (min-width: 40em) {
  .calc__form {
    gap: var(--sp-5);
    padding: var(--sp-6);
  }
}

/* ANSWER-FIRST
   For permutation and answer pages ("30 days from today") the answer IS the
   page: it is what the search snippet promised and what the visitor came for.
   Those pages render {{ result_panel(...) }} BEFORE the <form> in the tool
   partial — real DOM order, not a CSS reorder, so reading order and focus
   order stay honest. This class only fixes the border seam. */
.calc--answer-first .result {
  border-top: 0;
  border-bottom: var(--bw) solid var(--result-border);
}

.calc__legend,
.calc__heading {
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--text-subtle);
  padding: 0;
}

.calc fieldset {
  border: 0;
  padding: 0;
  margin: 0;
  display: grid;
  gap: var(--sp-4);
  min-width: 0;
}

/* --- input rows ---------------------------------------------------------- */
.calc__row {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--sp-4);
}

@media (min-width: 30em) {
  .calc__row--2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .calc__row--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  /* value + unit selector, e.g. [ 180 ][ cm ] */
  .calc__row--value-unit {
    grid-template-columns: minmax(0, 1fr) 9rem;
    gap: var(--sp-2);
  }
}

/* Number with a trailing static unit inside the field. */
.input-affix {
  position: relative;
  display: flex;
  align-items: center;
}

.input-affix input {
  padding-right: 3.25rem;
}

.input-affix__suffix {
  position: absolute;
  right: var(--sp-3);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--text-subtle);
  pointer-events: none;
  user-select: none;
}

/* Stepper for small integer inputs (days, reps, credits). */
.stepper {
  display: grid;
  grid-template-columns: 2.875rem minmax(0, 1fr) 2.875rem;
  gap: var(--sp-2);
  align-items: stretch;
}

.stepper input {
  text-align: center;
  font-weight: var(--fw-semibold);
  font-size: var(--fs-lg);
}

.stepper__btn {
  display: grid;
  place-items: center;
  min-height: 2.875rem;
  background-color: var(--surface-2);
  border: var(--bw) solid var(--border-input);
  border-radius: var(--r-md);
  color: var(--text-strong);
  font-size: var(--fs-xl);
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.stepper__btn:hover {
  background-color: var(--surface-sunken);
  border-color: var(--border-strong);
}

/* --- actions -------------------------------------------------------------
   Calculators recompute live on input, so the submit button is a fallback for
   keyboard/no-JS and is not the primary interaction. Reset sits beside it. */
.calc__actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-3);
  align-items: center;
}

.calc__actions .btn--primary {
  flex: 1 1 12rem;
}

/* Repeatable rows (GPA courses, weighted assignments). */
.calc__rows {
  display: grid;
  gap: var(--sp-3);
}

.calc__rows-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 6rem 2.75rem;
  gap: var(--sp-2);
  align-items: end;
}

.calc__rows-item .field .label {
  /* labels only on the first row; the rest use aria-label */
  margin-bottom: 0;
}

.calc__rows-remove {
  display: grid;
  place-items: center;
  min-height: 2.875rem;
  border: var(--bw) solid var(--border);
  border-radius: var(--r-md);
  color: var(--text-subtle);
  background-color: var(--surface);
  cursor: pointer;
}

.calc__rows-remove:hover {
  color: var(--err);
  border-color: var(--err);
}

/* --------------------------------------------------------------------------
   2. THE RESULT DISPLAY — the hero
   -------------------------------------------------------------------------- */
.result {
  position: relative;
  padding: var(--sp-5) var(--sp-4);
  background: linear-gradient(
    160deg,
    var(--result-bg) 0%,
    var(--result-bg-2) 100%
  );
  border-top: var(--bw) solid var(--result-border);
  color: var(--result-text);
  box-shadow: inset 0 1px 0 color-mix(in srgb, #fff 12%, transparent);
}

@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .result {
    background: var(--result-bg);
  }
}

@media (min-width: 40em) {
  .result {
    padding: var(--sp-8) var(--sp-6) var(--sp-6);
  }
}

/* Standalone result card (used on cluster/answer pages without a form). */
.result-card {
  border-radius: var(--r-xl);
  border: var(--bw) solid var(--result-border);
  box-shadow: var(--shadow-result);
  overflow: hidden;
}

.result__label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--result-text-muted);
  margin-bottom: var(--sp-2);
}

/* THE NUMBER. Tabular figures so a live-updating value never reflows.
   line-height is tight because at 60px a normal line-height wastes the
   vertical budget we need to keep this above the fold. */
.result__value {
  display: block;
  font-family: var(--font-num);
  font-size: var(--fs-result);
  font-weight: var(--fw-bold);
  line-height: 1.05;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  color: var(--result-text);
  overflow-wrap: anywhere;
  text-wrap: balance;
}

/* Long textual answers ("Saturday, 17 September 2026") get the smaller ramp
   so they stay on two lines at most on a 375px screen. */
.result__value--text {
  font-size: var(--fs-result-sm);
  letter-spacing: var(--tracking-tight);
  line-height: 1.15;
}

.result__unit {
  font-size: 0.44em;
  font-weight: var(--fw-semibold);
  letter-spacing: var(--tracking-normal);
  color: var(--result-text-muted);
  margin-left: 0.25em;
}

.result__sub {
  margin-top: var(--sp-3);
  font-size: var(--fs-base);
  color: var(--result-text-muted);
  font-variant-numeric: tabular-nums;
}

/* Value change flash — a 1-frame confirmation that recalculation happened.
   Colour only, no size/position change, so it can never cause CLS. */
@keyframes result-flash {
  from {
    opacity: 0.35;
  }
  to {
    opacity: 1;
  }
}

.result__value[data-flash="1"] {
  animation: result-flash 180ms var(--ease);
}

/* --- secondary results ---------------------------------------------------
   e.g. TDEE -> cut / maintain / bulk targets; date -> weeks, business days.
   Reserved as a fixed-column grid so the count changing does not reflow the
   page height on desktop. */
.result__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--sp-3);
  margin-top: var(--sp-5);
  padding-top: var(--sp-5);
  border-top: var(--bw) solid
    color-mix(in srgb, var(--result-text) 18%, transparent);
}

@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .result__grid {
    border-top-color: var(--result-border);
  }
}

@media (min-width: 34em) {
  .result__grid--3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
  .result__grid--4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.result-stat {
  min-width: 0;
}

.result-stat__label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: var(--fw-medium);
  color: var(--result-text-muted);
  letter-spacing: var(--tracking-wide);
  margin-bottom: 0.15rem;
}

.result-stat__value {
  display: block;
  font-size: var(--fs-xl);
  font-weight: var(--fw-semibold);
  line-height: var(--lh-tight);
  font-variant-numeric: tabular-nums;
  color: var(--result-text);
  overflow-wrap: anywhere;
}

.result-stat--emphasis .result-stat__value {
  font-size: var(--fs-2xl);
}

/* --------------------------------------------------------------------------
   3. COPY TO CLIPBOARD
   Sits top-right of the result panel on wide screens, full-width under the
   value on a phone (where the corner is a thumb-hostile target).
   -------------------------------------------------------------------------- */
.result__tools {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
}

.copy-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 2.5rem;
  padding: var(--sp-2) var(--sp-4);
  background-color: color-mix(in srgb, var(--result-text) 12%, transparent);
  border: var(--bw) solid
    color-mix(in srgb, var(--result-text) 28%, transparent);
  border-radius: var(--r-pill);
  color: var(--result-text);
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}

@supports not (color: color-mix(in srgb, red 50%, blue)) {
  .copy-btn {
    background-color: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.3);
  }
}

.copy-btn:hover {
  background-color: color-mix(in srgb, var(--result-text) 22%, transparent);
}

.copy-btn svg {
  width: 1rem;
  height: 1rem;
  flex: none;
}

/* Both labels ship in the DOM at the same width band so the swap on success
   does not resize the button. */
.copy-btn__done {
  display: none;
}

.copy-btn[data-copied="true"] .copy-btn__done {
  display: inline;
}

.copy-btn[data-copied="true"] .copy-btn__idle {
  display: none;
}

.copy-btn[data-copied="true"] .icon-copy {
  display: none;
}

.copy-btn .icon-check {
  display: none;
}

.copy-btn[data-copied="true"] .icon-check {
  display: block;
}

@media (min-width: 40em) {
  .result--has-corner-copy .result__tools {
    position: absolute;
    top: var(--sp-5);
    right: var(--sp-5);
    margin-top: 0;
  }
  .result--has-corner-copy .result__label,
  .result--has-corner-copy .result__value {
    padding-right: 9rem;
  }
}

/* --------------------------------------------------------------------------
   4. STATES
   -------------------------------------------------------------------------- */
.result[data-state="error"] {
  background: var(--surface-sunken);
  color: var(--text);
  border-top-color: var(--err);
}

.result[data-state="error"] .result__value {
  font-size: var(--fs-xl);
  color: var(--err);
  font-weight: var(--fw-semibold);
}

.result[data-state="error"] .result__label,
.result[data-state="error"] .result__sub {
  color: var(--text-muted);
}

.result[data-state="error"] .result__tools {
  display: none;
}

/* No-JS: the form still submits nowhere useful, so say so plainly rather
   than showing a dead calculator. */
.no-js-note {
  display: none;
}

.no-js .no-js-note {
  display: block;
  margin: var(--sp-4) var(--sp-5);
  padding: var(--sp-4);
  border: var(--bw) solid var(--warn);
  border-radius: var(--r-md);
  color: var(--text);
  font-size: var(--fs-sm);
}

/* --------------------------------------------------------------------------
   5. ANCILLARY TOOL PIECES
   -------------------------------------------------------------------------- */
/* Quick-jump links under the tool: "7 days · 14 days · 30 days · 90 days".
   These are real internal links to permutation pages, not JS shortcuts. */
.quick-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  margin-top: var(--sp-4);
  padding: 0;
  list-style: none;
}

.quick-links a {
  display: inline-block;
  padding: var(--sp-2) var(--sp-3);
  background-color: var(--accent-soft);
  border: var(--bw) solid var(--accent-soft-border);
  border-radius: var(--r-pill);
  color: var(--accent);
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  text-decoration: none;
  white-space: nowrap;
}

.quick-links a:hover {
  border-color: var(--accent-line);
}

/* Breakdown / working-out, shown under the result for trust. */
.calc__breakdown {
  padding: var(--sp-4) var(--sp-5);
  border-top: var(--bw) solid var(--border);
  background-color: var(--surface-2);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}

.calc__breakdown dl {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: var(--sp-2) var(--sp-4);
  margin: 0;
}

.calc__breakdown dt {
  color: var(--text-muted);
}

.calc__breakdown dd {
  margin: 0;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: var(--text-strong);
  font-weight: var(--fw-medium);
}

/* Live-region announcements for screen readers; visually hidden. */
.result__announce {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}
