/* Canonical (i) tooltip — pair with app/templates/includes/info_hint.html.
   CSS-only hover + focus-visible. */

.info-hint {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  margin-left: 6px;
  vertical-align: middle;
  cursor: help;
  outline: none;
  isolation: isolate;
  flex-shrink: 0;
}

/* Canonical (i) — gray/white circle, italic serif "i" (the distinctive info glyph). */
.info-hint-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.08);
  color: var(--kl-mut, #97999F);
  font-size: 11px;
  font-weight: 700;
  font-style: italic;
  font-family: Georgia, "Times New Roman", serif;
  line-height: 1;
  user-select: none;
  transition: background 120ms ease, color 120ms ease;
}

.info-hint:hover .info-hint-icon,
.info-hint:focus-visible .info-hint-icon {
  background: rgba(255, 255, 255, 0.12);
  color: var(--kl-ink, #F7F7F8);
}

.info-hint:hover,
.info-hint:focus-visible {
  z-index: 20000;
}

.info-hint:focus-visible {
  /* Was a blue halo. The shell defines --kl-focus-ring; a per-component ring would be a
     second, off-catalog focus style on the one control that appears on every page. */
  box-shadow: var(--kl-focus-ring, 0 0 0 2px #0A0A0C, 0 0 0 4px #F2F2F4);
  border-radius: 50%;
}

/* Overlay surface, neutral border — the same panel colour as every menu and sheet. */
.info-hint-bubble {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  min-width: 220px;
  max-width: min(360px, calc(100vw - 32px));
  padding: 14px;
  background: var(--kl-overlay, #23252A);
  color: var(--kl-ink-2, #C9CACF);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  font-size: 11px;
  line-height: 1.6;
  text-align: left;
  font-style: normal;
  font-weight: 400;
  font-family: inherit;
  white-space: normal;
  word-wrap: break-word;
  max-height: min(360px, 60vh);
  overflow-y: auto;
  overscroll-behavior: contain;
  opacity: 0;
  pointer-events: none;
  transition: opacity 140ms ease, transform 140ms ease;
  z-index: 20001;
}

.info-hint-bubble strong {
  display: block;
  margin-bottom: 6px;
  color: var(--kl-ink, #F7F7F8);
  font-weight: 600;
}

.info-hint-body {
  display: block;
  color: var(--kl-ink-2, #C9CACF);
}

/* Multi-item bodies (migrated from technical.html .info-tooltip-item). */
.info-hint-item + .info-hint-item {
  margin-top: 10px;
}
.info-hint-item strong {
  display: block;
  margin-bottom: 6px;
  color: var(--kl-ink, #F7F7F8);
  font-weight: 600;
}

/* Rich body_html: headings, paragraphs, inline code (migrated from backtester's
   .race-info-tooltip / .bt-info-tip). A <p> wrapper keeps its own <strong> inline —
   the bare-strong title rule above only blocks direct-child / info-hint-item strongs. */
.info-hint-bubble h4 {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 600;
  color: var(--kl-ink, #F7F7F8);
}
.info-hint-bubble h4:not(:first-child) {
  margin-top: 12px;
}
.info-hint-bubble p {
  margin: 0 0 6px;
}
.info-hint-bubble p:last-child {
  margin-bottom: 0;
}
.info-hint-bubble p strong {
  display: inline;
  margin: 0;
}
.info-hint-bubble code {
  background: rgba(255, 255, 255, 0.08);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.85em;
  color: var(--kl-ink, #F7F7F8);
}

.info-hint:hover .info-hint-bubble,
.info-hint:focus-visible .info-hint-bubble {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.info-hint-bubble::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  border: 6px solid transparent;
  border-top-color: var(--kl-overlay, #23252A);
}

/* ── JS-assisted absolute placement (app/static/js/info_hint.js) ──
   Stays position:absolute so it is immune to ancestor transform / backdrop-filter
   (which break position:fixed). Classes flip the bubble below / anchor it sideways
   when a centered, upward bubble would clip against the viewport. */
.info-hint.info-hint-below .info-hint-bubble {
  bottom: auto;
  top: calc(100% + 8px);
}
.info-hint.info-hint-below .info-hint-bubble::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: var(--kl-overlay, #23252A);
}
.info-hint.info-hint-align-right .info-hint-bubble {
  left: auto;
  right: 0;
  transform: translateX(0) translateY(4px);
}
.info-hint.info-hint-align-left .info-hint-bubble {
  left: 0;
  right: auto;
  transform: translateX(0) translateY(4px);
}
.info-hint.info-hint-align-right:hover .info-hint-bubble,
.info-hint.info-hint-align-right:focus-visible .info-hint-bubble,
.info-hint.info-hint-align-left:hover .info-hint-bubble,
.info-hint.info-hint-align-left:focus-visible .info-hint-bubble {
  transform: translateX(0) translateY(0);
}
.info-hint.info-hint-align-right .info-hint-bubble::after {
  left: auto;
  right: 5px;
  transform: none;
}
.info-hint.info-hint-align-left .info-hint-bubble::after {
  left: 5px;
  transform: none;
}

/* ── Portaled bubble (app/static/js/info_hint.js moves it to <body>) ──
   Rendered fixed and above the sticky header, and interactive so the user can move
   onto it and scroll long content. JS sets left/top and --info-hint-arrow. */
.info-hint-bubble.info-hint-bubble--portal {
  position: fixed !important;
  left: 0;
  top: 0;
  right: auto;
  bottom: auto;
  margin: 0;
  transform: none !important;
  opacity: 0;
  pointer-events: none;
  z-index: 2147483600;
  transition: opacity 120ms ease;
}
.info-hint-bubble.info-hint-bubble--portal.info-hint-bubble--show {
  opacity: 1;
  pointer-events: auto;
}
.info-hint-bubble.info-hint-bubble--portal::after {
  top: 100%;
  bottom: auto;
  left: var(--info-hint-arrow, 50%);
  right: auto;
  transform: translateX(-50%);
  border-top-color: var(--kl-overlay, #23252A);
  border-bottom-color: transparent;
}
.info-hint-bubble.info-hint-bubble--portal.info-hint-bubble--below::after {
  top: auto;
  bottom: 100%;
  border-top-color: transparent;
  border-bottom-color: var(--kl-overlay, #23252A);
}

/* NOTE: the legacy .info-hint-floating rules (position:fixed bubble driven by page-local
   JS) were removed — position:fixed resolves against any ancestor with backdrop-filter/
   transform (CSS containing-block rule), which misplaced/clipped bubbles inside blurred
   cards (the screener bug). The class is now inert; the shared portal script
   (js/info_hint.js, loaded globally via includes/app_sidebar.html) owns floating
   placement by portaling the bubble to <body>. */

@media (max-width: 480px) {
  .info-hint-bubble {
    min-width: 180px;
    max-width: calc(100vw - 32px);
    font-size: 11px;
  }
}

/* ── Phones: the resting (un-portaled) bubble must not lay out past the viewport ──
   The CSS-only bubble is centred on its icon (left:50% + translateX(-50%)). On a narrow
   screen any hint sitting near the right edge — e.g. #info-hint-arena-fair-join — extends
   past the viewport, where the shell's html{overflow-x:clip} clips it: unreachable, and it
   registers as page-level horizontal overflow. Pin it to the viewport gutters instead.
   js/info_hint.js still owns real placement (it portals the bubble to <body> and adds
   .info-hint-bubble--portal), so this governs only the resting / no-JS state.

   MEASURED: this only half-works on its own. `position:fixed` resolves against the nearest
   ancestor with backdrop-filter/transform (the CSS containing-block rule this file already
   warns about above), so on /technical/ the bubble lands at left:29..346 — inside the blurred
   .chart-card, not the viewport — and inside a translated carousel slide (value.html) it lands
   at left:-129, off the screen entirely. It is therefore kept only as the no-JS fallback
   (best effort). Whenever js/info_hint.js is live — html.info-hint-js, i.e. always in practice
   — the resting bubble is instead collapsed to an sr-only 1x1 box: it cannot overflow from any
   containing block, it stays in the a11y tree for aria-describedby, and the only bubble a
   phone ever shows is the portaled one, which <body> hosts and the script clamps. */
@media (max-width: 600px) {
  html:not(.info-hint-js) .info-hint-bubble:not(.info-hint-bubble--portal) {
    position: fixed;
    left: 12px;
    right: 12px;
    top: auto;
    bottom: 12px;
    width: auto;
    min-width: 0;
    max-width: none;
    transform: none;
  }
  /* The arrow points at an anchor this bubble is no longer attached to. */
  html:not(.info-hint-js) .info-hint-bubble:not(.info-hint-bubble--portal)::after {
    display: none;
  }

  /* Enhancer live: the resting bubble is never the one you see — take it out of the layout
     (1x1, no padding/border, clipped) so it contributes zero overflow wherever it sits. */
  html.info-hint-js .info-hint-bubble:not(.info-hint-bubble--portal) {
    position: absolute;
    left: 0;
    right: auto;
    top: 0;
    bottom: auto;
    width: 1px;
    height: 1px;
    min-width: 0;
    max-width: none;
    padding: 0;
    border: 0;
    overflow: hidden;
    clip-path: inset(50%);
    transform: none;
  }
  html.info-hint-js .info-hint-bubble:not(.info-hint-bubble--portal)::after {
    display: none;
  }

  /* The portaled bubble spans the viewport gutters instead of being centred on its icon:
     js/info_hint.js writes left:12px, this adds the matching right gutter with width:auto,
     so no content width can push it off either edge. Its ::after arrow still points at the
     trigger via --info-hint-arrow. */
  .info-hint-bubble.info-hint-bubble--portal {
    right: 12px;
    width: auto;
    min-width: 0;
    max-width: none;
  }

  /* Thumb-sized hit area for the 16px trigger. A centred 36px pseudo-element leaves the
     glyph's size and the surrounding layout untouched, and stays 36px (not 56px) on the
     pages that already grow .card-header .info-hint to 36/40px. */
  .info-hint::before {
    content: "";
    position: absolute;
    top: 50%;
    left: 50%;
    width: 36px;
    height: 36px;
    transform: translate(-50%, -50%);
    border-radius: 50%;
  }
}
