/* The Bike Cave — Real Range Calculator
   Skinned to thebikecave.com: white cards on light grey, a near-black inset
   panel for the answer, yellow pills with a glow on the live one.

   Type is inherited from the host page on purpose, so the widget takes on
   whatever the bike page is already set in. Set --tr-body to pin it. */

.tbc-range {
  /* Each token falls back to a sensible standalone value, but picks up the
     host page's own variable when the page defines one. On thebikecave.com
     that means the widget inherits the site palette with no page-level CSS. */
  --tr-card: var(--card, #ffffff);
  --tr-sunk: var(--card-soft, #f2f2f2);
  --tr-ink: var(--ink, #121212);
  --tr-muted: var(--ink-soft, #6e6e73);
  --tr-line: var(--line, #e7e7e7);
  --tr-rail: var(--line, #e4e4e4);

  --tr-dark: #161618;
  --tr-dark-soft: #27272b;
  --tr-dark-line: #313136;
  --tr-dark-ink: #f5f4f1;
  --tr-dark-muted: #9c9ca3;

  --tr-accent: var(--yellow, #ffc61a);
  --tr-accent-hot: #ff9d3d;
  --tr-accent-ink: var(--yellow-deep, #8a6100);
  --tr-on-accent: #131313;
  --tr-glow: 0 0 18px rgba(247, 198, 62, .55);
  --tr-glow-soft: 0 0 10px rgba(247, 198, 62, .38);

  --tr-radius: var(--radius-lg, 24px);
  --tr-panel-radius: var(--radius-md, 20px);
  --tr-pad: 16px;
  --tr-sticky-top: 0px;    /* raise this to clear a sticky site header */
  --tr-body: inherit;
  --tr-display: inherit;   /* set this to the page's heading face */

  box-sizing: border-box;
  position: relative;
  isolation: isolate;
  background: var(--tr-card);
  color: var(--tr-ink);
  font-family: var(--tr-body);
  line-height: 1.45;
  border-radius: var(--tr-radius);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05), 0 14px 36px -20px rgba(0, 0, 0, .35);
  max-width: 900px;
  margin: 32px auto;
  overflow: clip;
}

/* the yellow-to-orange progress hairline the site runs across the top */
.tbc-range::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  height: 3px;
  width: 100%;
  z-index: 1;
  background: linear-gradient(90deg, var(--tr-accent), var(--tr-accent-hot) 45%, transparent 92%);
}

/* the soft yellow corner wash off the homepage cards */
.tbc-range::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 62%;
  height: 220px;
  z-index: -1;
  pointer-events: none;
  background: radial-gradient(120% 100% at 100% 0%, rgba(247, 198, 62, .20), transparent 68%);
}

@media (min-width: 760px) {
  .tbc-range { --tr-pad: 22px; }
}
/* Very narrow phones. Specificity is deliberate: the base tile rules live
   further down the file and would otherwise win on source order. */
@media (max-width: 359px) {
  .tbc-range .tbc-range__stat { padding: 9px 7px; }
  .tbc-range .tbc-range__stat .n { font-size: 14px; }
  /* the label cannot fit on one line down here, so let it wrap — the grid
     keeps all three tiles the same height either way */
  .tbc-range .tbc-range__stat .l { font-size: 8.5px; letter-spacing: .03em; white-space: normal; }
}

/* Dark tokens, applied for all three states the page can be in: the system
   setting with nothing stamped, a theme stamped on the document, and a theme
   stamped on the widget itself. A closer light stamp always wins. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .tbc-range:not([data-theme="light"]) {
      --tr-card: #1a1a1c;
      --tr-sunk: #232327;
      --tr-ink: #f4f3f0;
      --tr-muted: #9a9aa1;
      --tr-line: #2c2c30;
      --tr-rail: #313136;
      --tr-dark: #0f0f11;
      --tr-dark-soft: #27272c;
      --tr-dark-line: #34343a;
      --tr-accent-ink: #f7c63e;
  }
}
:root[data-theme="dark"] .tbc-range:not([data-theme="light"]) {
    --tr-card: #1a1a1c;
    --tr-sunk: #232327;
    --tr-ink: #f4f3f0;
    --tr-muted: #9a9aa1;
    --tr-line: #2c2c30;
    --tr-rail: #313136;
    --tr-dark: #0f0f11;
    --tr-dark-soft: #27272c;
    --tr-dark-line: #34343a;
    --tr-accent-ink: #f7c63e;
}
.tbc-range[data-theme="dark"] {
    --tr-card: #1a1a1c;
    --tr-sunk: #232327;
    --tr-ink: #f4f3f0;
    --tr-muted: #9a9aa1;
    --tr-line: #2c2c30;
    --tr-rail: #313136;
    --tr-dark: #0f0f11;
    --tr-dark-soft: #27272c;
    --tr-dark-line: #34343a;
    --tr-accent-ink: #f7c63e;
}

.tbc-range *,
.tbc-range *::before,
.tbc-range *::after { box-sizing: border-box; }

/* ---------- header ---------- */

.tbc-range__head {
  position: relative;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
  padding: calc(var(--tr-pad) + 6px) var(--tr-pad) 4px;
}
.tbc-range__head-main { flex: 1 1 220px; min-width: 0; }
.tbc-range__eyebrow {
  display: flex;
  align-items: center;
  gap: 11px;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--tr-ink);
}
.tbc-range__chip {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border-radius: 13px;
  background: var(--tr-accent);
  color: var(--tr-on-accent);
  box-shadow: var(--tr-glow);
}
.tbc-range__chip svg { width: 19px; height: 19px; display: block; }
.tbc-range__title {
  font-family: var(--tr-display);
  font-size: clamp(21px, 4.6vw, 27px);
  font-weight: 800;
  letter-spacing: -.02em;
  line-height: 1.15;
  text-wrap: balance;
  margin: 13px 0 0;
}
.tbc-range__sub {
  font-size: 14px;
  color: var(--tr-muted);
  margin: 6px 0 0;
  max-width: 46ch;
}

.tbc-range__units {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  border-radius: 999px;
  background: var(--tr-sunk);
}
.tbc-range__units button {
  appearance: none;
  border: 0;
  background: none;
  color: var(--tr-muted);
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .09em;
  text-transform: uppercase;
  padding: 6px 13px;
  border-radius: 999px;
  cursor: pointer;
  min-height: 30px;
}
.tbc-range__units button[aria-pressed="true"] {
  background: var(--tr-accent);
  color: var(--tr-on-accent);
  box-shadow: var(--tr-glow-soft);
}
.tbc-range__units button:focus-visible { outline: 2px solid var(--tr-ink); outline-offset: 1px; }

/* ---------- layout ---------- */

.tbc-range__body {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 14px var(--tr-pad) var(--tr-pad);
}

/* Phone: the answer panel pins to the top of the card, full bleed, so the
   number keeps updating in front of you while your thumb is on a control
   further down. Stats and small print are allowed to scroll away. */
@media (max-width: 759px) {
  .tbc-range .tbc-range__key {
    order: -1;
    position: sticky;
    top: var(--tr-sticky-top);
    z-index: 3;
    margin: -14px calc(var(--tr-pad) * -1) 0;
    border-radius: 0;
    box-shadow: 0 12px 20px -14px rgba(0, 0, 0, .7);
  }
  .tbc-range .tbc-range__controls { order: 0; }
  .tbc-range .tbc-range__extras { order: 1; }
}

@media (min-width: 760px) {
  .tbc-range__body {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    grid-template-areas: "controls key" "controls extras";
    column-gap: 24px;
    row-gap: 16px;
  }
  .tbc-range__controls { grid-area: controls; }
  .tbc-range__key { grid-area: key; }
  .tbc-range__extras { grid-area: extras; }
}

/* ---------- controls ---------- */

.tbc-range__field { margin: 0 0 18px; border: 0; padding: 0; min-width: 0; }
.tbc-range__field:last-child { margin-bottom: 0; }

.tbc-range__label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .13em;
  text-transform: uppercase;
  color: var(--tr-muted);
  padding: 0;
  margin: 0 0 9px;
  width: 100%;
}
/* the editable watt-hour figure, styled to sit in the label row like a value */
.tbc-range__num {
  font-family: var(--tr-display);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -.01em;
  color: var(--tr-ink);
  text-transform: none;
}
.tbc-range__num input {
  width: 4.6em;
  text-align: right;
  font: inherit;
  color: inherit;
  background: var(--tr-sunk);
  border: 0;
  border-radius: 9px;
  padding: 4px 9px;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}
.tbc-range__num input::-webkit-outer-spin-button,
.tbc-range__num input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.tbc-range__num input:focus-visible { outline: 2px solid var(--tr-ink); outline-offset: 1px; }

/* the unit suffix doubles as the switch between watt hours and amp hours */
.tbc-range__whah {
  display: inline-flex;
  gap: 1px;
  padding: 2px;
  border-radius: 999px;
  background: var(--tr-sunk);
  align-self: center;
}
.tbc-range__whah button {
  appearance: none;
  border: 0;
  background: none;
  font: inherit;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: .04em;
  color: var(--tr-muted);
  padding: 4px 9px;
  min-height: 26px;
  border-radius: 999px;
  cursor: pointer;
}
.tbc-range__whah button[aria-pressed="true"] {
  background: var(--tr-accent);
  color: var(--tr-on-accent);
  box-shadow: var(--tr-glow-soft);
}
.tbc-range__whah button:focus-visible { outline: 2px solid var(--tr-ink); outline-offset: 1px; }

.tbc-range__value {
  font-family: var(--tr-display);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -.01em;
  color: var(--tr-ink);
  font-variant-numeric: tabular-nums;
  text-transform: none;
}

/* the filled part of the track is painted from JS, same gradient as the top rule */
.tbc-range input[type="range"] {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  height: 6px;
  border-radius: 999px;
  background: var(--tr-rail);
  cursor: pointer;
  display: block;
  margin: 0;
}
.tbc-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 26px;
  height: 26px;
  margin-top: 0;
  border-radius: 50%;
  background: var(--tr-accent);
  border: 4px solid var(--tr-card);
  box-shadow: var(--tr-glow-soft);
}
.tbc-range input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--tr-accent);
  border: 4px solid var(--tr-card);
  box-shadow: var(--tr-glow-soft);
}
.tbc-range input[type="range"]:focus-visible { outline: 2px solid var(--tr-ink); outline-offset: 4px; }

.tbc-range__slider-wrap { padding: 10px 0 2px; }   /* thumb needs room to breathe */

.tbc-range__ends {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--tr-muted);
  font-variant-numeric: tabular-nums;
  margin-top: 6px;
}

/* pills — radios wearing the site's buttons */
.tbc-range__choices {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 8px;
}
.tbc-range__choices--wrap { grid-auto-flow: row; grid-auto-columns: auto; }
.tbc-range__choice { position: relative; display: block; min-width: 0; }
.tbc-range__choice input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}
.tbc-range__choice span {
  display: block;
  text-align: center;
  padding: 9px 8px;
  min-height: 44px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  color: var(--tr-ink);
  background: var(--tr-sunk);
  cursor: pointer;
  transition: background .14s ease, box-shadow .14s ease, color .14s ease;
}
.tbc-range__choice small {
  display: block;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--tr-muted);
  margin-top: 1px;
}
.tbc-range__choice input:checked + span {
  background: var(--tr-accent);
  color: var(--tr-on-accent);
  box-shadow: var(--tr-glow-soft);
}
.tbc-range__choice input:checked + span small { color: rgba(19, 19, 19, .68); }
.tbc-range__choice input:focus-visible + span { outline: 2px solid var(--tr-ink); outline-offset: 2px; }
@media (hover: hover) {
  .tbc-range__choice input:not(:checked) + span:hover { background: var(--tr-rail); }
}

/* ---------- the answer panel ---------- */

.tbc-range__key {
  background: var(--tr-dark);
  color: var(--tr-dark-ink);
  border-radius: var(--tr-panel-radius);
  padding: 20px;
}
.tbc-range__answer { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.tbc-range__big {
  font-family: var(--tr-display);
  font-size: clamp(46px, 13vw, 62px);
  font-weight: 800;
  line-height: .92;
  letter-spacing: -.035em;
  font-variant-numeric: tabular-nums;
  color: var(--tr-accent);
}
.tbc-range__unit {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--tr-dark-muted);
}
.tbc-range__window {
  font-size: 13px;
  color: var(--tr-dark-muted);
  margin: 8px 0 0;
}
.tbc-range__window b { color: var(--tr-dark-ink); font-variant-numeric: tabular-nums; }

.tbc-range__scale { margin: 22px 0 0; }
.tbc-range__track {
  position: relative;
  height: 18px;
  background: var(--tr-dark-soft);
  border-radius: 999px;
}
/* everything up to the low end is range you will get whatever the day does */
.tbc-range__reach {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  border-radius: 999px 0 0 999px;
  background: rgba(247, 198, 62, .18);
  transition: width .18s ease;
}
/* the window itself */
.tbc-range__band {
  position: absolute;
  top: 0;
  bottom: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--tr-accent-hot), var(--tr-accent));
  box-shadow: var(--tr-glow-soft);
  min-width: 6px;
  transition: left .18s ease, width .18s ease;
}
.tbc-range__ticks {
  position: relative;
  height: 16px;
  margin-top: 6px;
  font-size: 10.5px;
  color: var(--tr-dark-muted);
  font-variant-numeric: tabular-nums;
}
.tbc-range__tick { position: absolute; top: 0; transform: translateX(-50%); white-space: nowrap; }
.tbc-range__tick:first-child { transform: none; }
.tbc-range__tick:last-child { transform: translateX(-100%); }


/* ---------- stats, speed strip, small print ---------- */

.tbc-range__extras { display: flex; flex-direction: column; gap: 14px; }

.tbc-range__stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 20px 0 0;
  padding-top: 18px;
  border-top: 1px solid var(--tr-dark-line);
}
.tbc-range__stat {
  background: var(--tr-dark-soft);
  border-radius: 15px;
  padding: 10px 12px;
}
.tbc-range__stat .n {
  font-family: var(--tr-display);
  display: block;
  font-size: 19px;
  white-space: nowrap;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.tbc-range__stat .l {
  display: block;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--tr-dark-muted);
  margin-top: 2px;
  white-space: nowrap;   /* three tiles of equal height beats a tidy label */
}

.tbc-range__curve-head {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--tr-muted);
  margin-bottom: 7px;
}
.tbc-range__curve-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.tbc-range__curve-cell {
  background: var(--tr-sunk);
  border-radius: 15px;
  padding: 8px 6px;
  text-align: center;
}
.tbc-range__curve-cell.is-here {
  background: var(--tr-accent);
  box-shadow: var(--tr-glow-soft);
}
.tbc-range__curve-cell .v {
  font-family: var(--tr-display);
  display: block;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}
.tbc-range__curve-cell .k {
  display: block;
  font-size: 10px;
  color: var(--tr-muted);
  font-variant-numeric: tabular-nums;
}
.tbc-range__curve-cell.is-here .v { color: var(--tr-on-accent); }
.tbc-range__curve-cell.is-here .k { color: rgba(19, 19, 19, .68); }

.tbc-range__note {
  font-size: 11.5px;
  color: var(--tr-muted);
  margin: 0;
}

.tbc-range__foot {
  border-top: 1px solid var(--tr-line);
  padding: 13px var(--tr-pad);
  font-size: 11.5px;
  color: var(--tr-muted);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.tbc-range__reset {
  appearance: none;
  border: 0;
  background: var(--tr-sunk);
  border-radius: 999px;
  padding: 7px 15px;
  font: inherit;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--tr-ink);
  cursor: pointer;
  min-height: 32px;
}
@media (hover: hover) { .tbc-range__reset:hover { background: var(--tr-rail); } }
.tbc-range__reset:focus-visible { outline: 2px solid var(--tr-ink); outline-offset: 2px; }

.tbc-range__sr {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

@media (prefers-reduced-motion: reduce) {
  .tbc-range * { transition: none !important; }
}
