/* =====================================================================================
   Pit Wall buttons: v4, the "selection frame" family (docs/BUTTONS.md; the company site,
   MRS_WEBSITE_V2 docs/BUTTONS.md, is the master spec).

   A flat rectangle with no radius, set in the mono font (uppercase, spaced) like a HUD label, with
   four small bracket marks on its corners. On hover and keyboard focus the frame "locks on": the
   marks move outward, the fill lightens, and the thin line-arrow grows with its head snapping in.
   Colours come from the --brand-* block in brand-tokens.css (via --accent, --text, --panel-hi).
   Selectors carry `html body` so they win over the app's older button rules. web/js/buttons.js
   adds the classes (and the arrow) to the app's labelled action buttons.
   ===================================================================================== */

:root {
  --btn-heat: #ff5a1f;
  --btn-graphite: var(--panel-hi); /* primary fill: the lightest panel step, lighter than the page and the cards */
  --btn-line: 2px; /* arrow weight, as the MENU icon */
  --btn-dur: 0.5s;
  --btn-ease: var(--ease);
  --btn-gap: 0.85rem;
  --btn-rule-w: 2.1rem;
  --btn-inset: 2px; /* drawn shape inside the 44px hit area */
  --btn-snap: cubic-bezier(0.34, 1.56, 0.64, 1);
  --btn-edge-w: 1px;
  --btn-mark: 7px; /* bracket arm length */
  --btn-mark-w: 2px; /* bracket thickness */
  --btn-mark-out: 0px; /* how far the brackets sit outside the corners at rest */
  --btn-mark-out-on: 3px; /* ... and when locked on */
}

html body .btn {
  --btn-ink: var(--text);
  --btn-fill: var(--btn-graphite);
  --btn-fill-on: color-mix(in srgb, var(--btn-graphite), var(--text) 8%);
  --btn-edge: color-mix(in srgb, var(--text) 14%, transparent);
  --btn-base: var(--accent); /* primary: a signal edge along the bottom */
  --btn-marks: var(--accent);
  --btn-marks-on: var(--accent);
  --btn-rule: var(--accent);
  --btn-rest: 0.5;
  --btn-out: var(--btn-mark-out);
  position: relative;
  isolation: isolate;
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--btn-gap);
  min-width: 2.75rem;
  min-height: 2.75rem;
  padding: 0 1.05rem;
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--btn-ink);
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.7rem;
  line-height: 1.2;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
  transition: color var(--btn-dur) var(--btn-ease);
}

/* The rectangle: fill, hairline and (primary) the signal edge along the bottom. */
html body .btn::before {
  content: "";
  position: absolute;
  inset: var(--btn-inset) 0;
  z-index: -1;
  background: var(--btn-fill);
  box-shadow:
    inset 0 0 0 var(--btn-edge-w) var(--btn-edge),
    inset 0 -2px 0 var(--btn-base);
  transition: background-color var(--btn-dur) var(--btn-ease), box-shadow var(--btn-dur) var(--btn-ease);
}

/* The four corner brackets: eight thin bars as background layers on one pseudo-element that sits
   --btn-out outside the rectangle. Moving --btn-out is the "lock on". */
html body .btn::after {
  content: "";
  position: absolute;
  inset: calc(var(--btn-inset) - var(--btn-out)) calc(var(--btn-out) * -1);
  z-index: -1;
  pointer-events: none;
  background:
    linear-gradient(var(--btn-marks), var(--btn-marks)) left top / var(--btn-mark) var(--btn-mark-w),
    linear-gradient(var(--btn-marks), var(--btn-marks)) left top / var(--btn-mark-w) var(--btn-mark),
    linear-gradient(var(--btn-marks), var(--btn-marks)) right top / var(--btn-mark) var(--btn-mark-w),
    linear-gradient(var(--btn-marks), var(--btn-marks)) right top / var(--btn-mark-w) var(--btn-mark),
    linear-gradient(var(--btn-marks), var(--btn-marks)) left bottom / var(--btn-mark) var(--btn-mark-w),
    linear-gradient(var(--btn-marks), var(--btn-marks)) left bottom / var(--btn-mark-w) var(--btn-mark),
    linear-gradient(var(--btn-marks), var(--btn-marks)) right bottom / var(--btn-mark) var(--btn-mark-w),
    linear-gradient(var(--btn-marks), var(--btn-marks)) right bottom / var(--btn-mark-w) var(--btn-mark);
  background-repeat: no-repeat;
  transition: inset var(--btn-dur) var(--btn-ease);
}

html body .btn:not(:disabled):not([aria-disabled="true"]):hover,
html body .btn:not(:disabled):not([aria-disabled="true"]):focus-visible {
  --btn-out: var(--btn-mark-out-on);
  --btn-marks: var(--btn-marks-on);
}

html body .btn:not(:disabled):not([aria-disabled="true"]):hover::before,
html body .btn:not(:disabled):not([aria-disabled="true"]):focus-visible::before {
  background: var(--btn-fill-on);
}

/* Secondary: no fill, a low-opacity hairline, grey brackets that go cyan when locked on. */
html body .btn-secondary {
  --btn-fill: transparent;
  --btn-fill-on: color-mix(in srgb, var(--text) 7%, transparent);
  --btn-edge: color-mix(in srgb, var(--text) 26%, transparent);
  --btn-base: transparent;
  --btn-marks: color-mix(in srgb, var(--text) 55%, transparent);
  --btn-marks-on: var(--accent);
  --btn-rule: var(--text);
  --btn-rule-on: var(--accent);
}

html body .btn-secondary:not(:disabled):not([aria-disabled="true"]):hover,
html body .btn-secondary:not(:disabled):not([aria-disabled="true"]):focus-visible {
  --btn-rule: var(--btn-rule-on);
}

/* Danger (a modifier on secondary): heat-orange text, hairline, brackets and arrow. */
html body .btn-danger {
  --btn-ink: var(--btn-heat);
  --btn-edge: color-mix(in srgb, var(--btn-heat) 50%, transparent);
  --btn-fill-on: color-mix(in srgb, var(--btn-heat) 12%, transparent);
  --btn-marks: color-mix(in srgb, var(--btn-heat) 70%, transparent);
  --btn-marks-on: var(--btn-heat);
  --btn-rule: var(--btn-heat);
  --btn-rule-on: var(--btn-heat);
}

/* Pressed: one pixel down, a shade darker. */
html body .btn:not(:disabled):not([aria-disabled="true"]):active {
  transform: translateY(1px);
}

html body .btn:not(:disabled):not([aria-disabled="true"]):active::before {
  filter: brightness(0.88);
}

/* Small: forms and admin. On a touch screen the hit area grows to 44px while the drawn frame stays
   small (--btn-inset). */
html body .btn-sm {
  --btn-gap: 0.55rem;
  --btn-rule-w: 1.5rem;
  --btn-inset: 0px;
  --btn-mark: 5px;
  min-height: 1.875rem;
  padding: 0 0.75rem;
  font-size: 0.66rem;
}

@media (pointer: coarse) {
  html body .btn-sm {
    --btn-inset: 0.4375rem;
    min-height: 2.75rem;
  }
}

/* Large: the closing call to action. */
html body .btn-lg {
  --btn-gap: 1.25rem;
  --btn-line: 3px;
  --btn-rule-w: clamp(3rem, 6vw, 5rem);
  --btn-inset: 0px;
  --btn-mark: 12px;
  --btn-mark-w: 3px;
  --btn-mark-out-on: 5px;
  min-height: 3.85rem;
  padding: 0 clamp(1.25rem, 2.6vw, 2.1rem);
  font-size: clamp(0.95rem, 1.8vw, 1.45rem);
  line-height: 1.05;
  white-space: nowrap;
}

html body .btn:disabled,
html body .btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Focus: the site's signal outline, set out beyond the locked-on brackets. */
html body .btn:focus-visible {
  outline: 2px solid var(--btn-focus, var(--accent));
  outline-offset: 8px;
  border-radius: 0;
}

/* Forced colours (Windows contrast themes) drop the fill and the box-shadow hairline: draw the frame
   as a real border in the system button colour so every button keeps a visible edge. */
@media (forced-colors: active) {
  html body .btn::before {
    border: 1px solid ButtonText;
  }

  html body .btn:focus-visible {
    outline-color: Highlight;
  }
}

/* The arrow: the MENU's line, in a fixed-width track so growing it never moves the layout. */
html body .btn-rule {
  position: relative;
  display: block;
  flex: none;
  width: var(--btn-rule-w);
  height: var(--btn-line);
  transition: transform 0.12s var(--btn-ease);
}

html body .btn-rule::before {
  content: "";
  position: absolute;
  inset: 0;
  background: var(--btn-rule);
  transform: scaleX(var(--btn-rest));
  transform-origin: left center;
  transition: transform var(--btn-dur) var(--btn-ease), background-color var(--btn-dur) var(--btn-ease);
}

/* The arrow head, two thin lines, drawn when the line is full. */
html body .btn-rule::after {
  content: "";
  position: absolute;
  right: 0.12em;
  top: calc(50% - 0.3em);
  width: 0.6em;
  height: 0.6em;
  border-top: var(--btn-line) solid var(--btn-rule);
  border-right: var(--btn-line) solid var(--btn-rule);
  transform: rotate(45deg) scale(0.6);
  opacity: 0;
  transition: opacity 0.15s var(--btn-ease), transform 0.35s var(--btn-snap);
}

html body .btn:not(:disabled):not([aria-disabled="true"]):hover .btn-rule::before,
html body .btn:not(:disabled):not([aria-disabled="true"]):focus-visible .btn-rule::before {
  transform: scaleX(1);
}

html body .btn:not(:disabled):not([aria-disabled="true"]):hover .btn-rule::after,
html body .btn:not(:disabled):not([aria-disabled="true"]):focus-visible .btn-rule::after {
  opacity: 1;
  transform: rotate(45deg) scale(1);
}

/* Pressed: the arrow darts forward. */
html body .btn:not(:disabled):not([aria-disabled="true"]):active .btn-rule {
  transform: translateX(0.3rem);
}

@media (prefers-reduced-motion: reduce) {
  html body .btn,
  html body .btn::before,
  html body .btn::after,
  html body .btn-rule,
  html body .btn-rule::before,
  html body .btn-rule::after {
    transition: none;
  }

  html body .btn:active,
  html body .btn:active .btn-rule {
    transform: none;
  }
}

/* Icon-only: a square hit area, no arrow, the glyph or drawing inside. */
html body .btn-icon {
  justify-content: center;
  padding: 0 0.6rem;
  min-width: 2.75rem;
  font-size: 0.95rem;
  letter-spacing: 0;
  text-transform: none;
}

html body .btn-icon .btn-rule {
  display: none;
}

/* Dense app: type a little larger than the website's small size. */
html body .btn-sm {
  font-size: 0.7rem;
}

/* Pit Wall: the app's older button rules paint a fill, border and shadow on every button, and
   again on hover; the family draws its own shape, so those are switched off for it. */
html body button.btn,
html body button.btn:is(:hover, :focus, :active, :disabled) {
  background: none;
  border: 0;
  box-shadow: none;
  border-radius: 0;
  color: var(--btn-ink);
}

/* A connected toggle (live timing, telemetry) keeps its green "on" state: green fill, white text,
   white brackets and arrow. */
html body .btn.connected-active {
  --btn-fill: #15803d;
  --btn-fill-on: #166534;
  --btn-ink: #fff;
  --btn-base: var(--green-dim);
  --btn-marks: var(--green-dim);
  --btn-marks-on: #fff;
  --btn-rule: #fff;
}
