/* Embeddable widget styles (spec: ROADMAP.md § A-bis).
 *
 * Served twice: linked normally on our own event page, and inlined into
 * /embed/v1/... where it lands in a stranger's stylesheet. That is why every
 * selector is namespaced `.ipd-*` and nothing here styles a bare element -
 * a rule on `table` or `svg` would reach into the host page.
 *
 * Light DOM on purpose. Shadow DOM would isolate styling for free, but links
 * inside a shadow root are not reliably crawled and the inbound links are the
 * whole point of the embed. So: namespace hard, inherit little, and set every
 * property that matters rather than relying on the host's defaults.
 *
 * Colours come from inpedana's own tokens so the widget looks native here and
 * recognisable elsewhere. The categorical pair (magenta identity vs blue) and
 * the diverging pair (blue vs red) were checked for colour-blind separation;
 * magenta and red never appear in the same widget because they are
 * indistinguishable to a deutan reader (ΔE 7.3) and hard even with full colour
 * vision (ΔE 8.4).
 */

/* Montserrat, self-hosted.
 *
 * Deliberately NOT named "Montserrat": inpedana's own pages already define
 * that family from Google Fonts, and a second @font-face for the same name
 * would compete with it and risk a duplicate download on our own site. Naming
 * it separately and putting it *after* Montserrat in the stack means our page
 * uses the copy it already has, while a third-party page - where "Montserrat"
 * resolves to nothing and is skipped - falls through to this one.
 *
 * Self-hosted rather than linked from Google: an embed that pulled fonts from
 * fonts.gstatic.com would put a third-party request on a partner's page, which
 * is theirs to consent to, not ours to add. Montserrat is SIL OFL, so hosting
 * it ourselves is fine. unicode-range splits the subsets so a page of Italian
 * names never downloads latin-ext.
 */
@font-face {
  font-family: 'Montserrat Inpedana';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: local('Montserrat'),
       url('https://inpedana.com/static/fonts/montserrat-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA,
                 U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122,
                 U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'Montserrat Inpedana';
  font-style: normal;
  font-weight: 400 700;
  font-display: swap;
  src: local('Montserrat'),
       url('https://inpedana.com/static/fonts/montserrat-latin-ext.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF,
                 U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF,
                 U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* Tokens copied verbatim from inpedana's styles.css :root, so the widget is
   the same surface, ink and accent as the rest of the site - not an
   approximation of them. Single theme on purpose: inpedana declares no
   prefers-color-scheme block at all, so there is no dark palette to match.
   The widget paints its own background either way, which is what lets a cream
   card sit legibly on a dark host page. */
.ipd-w {
  --ipd-bg: #F6F4EE;              /* --c-bg */
  --ipd-rule: #DCD8CC;            /* --c-border */
  --ipd-rule-strong: #B8B5A8;     /* --c-border-strong */
  --ipd-ink: #1A2418;             /* --c-text */
  --ipd-ink-2: #5A655A;           /* --c-text-muted */
  --ipd-ink-3: #8E978D;           /* --c-text-faint */
  --ipd-forest: #3E5C42;          /* --c-primary */
  --ipd-accent: #E63E81;          /* --c-accent */
  --ipd-accent-soft: rgba(230, 62, 129, .10);   /* --c-accent-soft */

  /* Series colours. Validated for colour-blind separation against this exact
     surface (#F6F4EE): magenta/blue pass all gates, blue/red pass all gates,
     and magenta/red are never drawn together - they are indistinguishable to a
     deutan reader and hard even with full colour vision. */
  --ipd-gain: #2a78d6;
  --ipd-loss: #e34948;
  --ipd-mute: #B8B5A8;
  --ipd-s1: #cde2fb; --ipd-s2: #9ec5f4; --ipd-s3: #6da7ec;
  --ipd-s4: #3987e5; --ipd-s5: #256abf; --ipd-s6: #184f95;

  --ipd-font: 'Montserrat', 'Montserrat Inpedana', -apple-system,
              BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;

  box-sizing: border-box;
  background: var(--ipd-bg);
  border: 1px solid var(--ipd-rule);
  border-radius: 8px;             /* --radius */
  padding: 18px 18px 14px;
  margin: 0 0 18px;
  color: var(--ipd-ink);
  font-family: var(--ipd-font);
  font-size: 14px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
  max-width: 100%;
  overflow: hidden;
}
.ipd-w *, .ipd-w *::before, .ipd-w *::after { box-sizing: border-box; }

/* Defensive reset. The host page styles bare elements - a test host putting
   `svg { border: 2px dashed blue }` and `td { padding: 20px }` on everything
   showed both bleeding straight through - and those rules reach into our light
   DOM. Neutralise the properties we care about on the elements we actually
   render, then let the rules below set them back. Scoped to `.ipd-w`, so the
   host's own page is never touched.

   `:where()` is load-bearing: it contributes zero specificity, so this rule
   weighs exactly `.ipd-w` (0,1,0). That still outranks any host rule on a bare
   element (0,0,1), but loses every tie to our own component classes further
   down. Written as a plain `.ipd-w div` list (0,1,1) it would outrank
   `.ipd-tile` (0,1,0) and silently strip the padding off our own tiles. */
.ipd-w :where(svg, table, td, th, tr, thead, tbody, div, p, span, a, b, i) {
  /* `font: inherit` in one line covers family, size, weight, style and
     line-height - the host's `td { font-size: 20px }` was inflating our table
     because a direct rule on `td` beats inheritance from `.ipd-w`. */
  font: inherit;
  color: inherit;
  text-align: inherit;
  vertical-align: baseline;
  text-decoration: none;
  border: 0;
  margin: 0;
  padding: 0;
  outline: 0;
  width: auto;
  height: auto;
  float: none;
  text-shadow: none;
  box-shadow: none;
  text-transform: none;
  letter-spacing: normal;
  background-image: none;
}
.ipd-w svg { max-width: 100%; }

.ipd-w__head { margin: 0 0 12px; }
.ipd-w__title {
  margin: 0; font-size: 15px; font-weight: 700;
  letter-spacing: -.01em; color: var(--ipd-ink); line-height: 1.3;
}
.ipd-w__sub { margin: 2px 0 0; font-size: 12px; color: var(--ipd-ink-3); }

.ipd-w__foot {
  margin-top: 12px; padding-top: 9px; border-top: 1px solid var(--ipd-rule);
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  font-size: 11px; color: var(--ipd-ink-3);
}
.ipd-w__foot a.ipd-src {
  color: var(--ipd-accent); text-decoration: none; font-weight: 600;
}
.ipd-w__foot a.ipd-src:hover { text-decoration: underline; }

.ipd-scroll { overflow-x: auto; max-width: 100%; }

/* stat tiles */
.ipd-tiles {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1px; background: var(--ipd-rule);
  border: 1px solid var(--ipd-rule); border-radius: 4px; overflow: hidden;
}
.ipd-tile { background: var(--ipd-bg); padding: 13px 15px; }
.ipd-tile__v {
  display: block; font-size: 28px; font-weight: 700;
  letter-spacing: -.03em; line-height: 1.05; color: var(--ipd-ink);
}
.ipd-tile__v--acc { color: var(--ipd-accent); }
.ipd-tile__k { display: block; font-size: 11px; color: var(--ipd-ink-3); margin-top: 2px; }
.ipd-tile__s { display: block; font-size: 11px; color: var(--ipd-ink-2); }

/* table */
.ipd-w table.ipd-t { border-collapse: collapse; width: 100%; font-size: 13px; min-width: 520px; }
.ipd-w table.ipd-t th {
  font-size: 10px; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ipd-ink-3); font-weight: 700; text-align: right;
  padding: 0 8px 7px; border-bottom: 1px solid var(--ipd-rule); white-space: nowrap;
  background: none;
}
.ipd-w table.ipd-t th.ipd-l, .ipd-w table.ipd-t td.ipd-l { text-align: left; }
.ipd-w table.ipd-t td {
  padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--ipd-rule);
  white-space: nowrap; color: var(--ipd-ink); background: none;
}
.ipd-w table.ipd-t tr:last-child td { border-bottom: 0; }
.ipd-w table.ipd-t tr.ipd-home td { background: var(--ipd-accent-soft); }
.ipd-w table.ipd-t td a {
  color: var(--ipd-ink); text-decoration: none; font-weight: 600;
  border-bottom: 1px solid var(--ipd-mute);
}
.ipd-w table.ipd-t td a:hover { color: var(--ipd-accent); border-color: var(--ipd-accent); }
.ipd-w table.ipd-t td b { font-weight: 700; }
.ipd-rk { color: var(--ipd-ink-3); font-size: 12px; }
.ipd-cc { font-size: 11px; color: var(--ipd-ink-3); }
.ipd-best { color: var(--ipd-accent); font-weight: 700; }

/* charts */
.ipd-w svg { display: block; max-width: 100%; height: auto; }
.ipd-w svg text { font-family: var(--ipd-font); }
.ipd-grid { stroke: var(--ipd-rule); stroke-width: 1; }
.ipd-ax { font-size: 10px; fill: var(--ipd-ink-3); }
.ipd-lb { font-size: 11px; fill: var(--ipd-ink); }
.ipd-lb2 { font-size: 10px; fill: var(--ipd-ink-3); }
.ipd-hit { fill: transparent; cursor: pointer; }

.ipd-legend {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
  font-size: 11px; color: var(--ipd-ink-2); margin: 0 0 10px;
}
.ipd-legend span { display: inline-flex; align-items: center; gap: 6px; }
.ipd-legend i { width: 18px; height: 3px; border-radius: 2px; display: inline-block; }
.ipd-legend i.ipd-sq { width: 11px; height: 11px; border-radius: 3px; }

.ipd-note { margin: 8px 0 0; font-size: 11px; color: var(--ipd-ink-3); }

/* tooltip - appended to <body>, so it carries its own colours */
.ipd-tip {
  position: fixed; z-index: 2147483000; pointer-events: none; opacity: 0;
  /* Appended to <body>, outside .ipd-w, so it cannot read the tokens -
     these are the same --c-text / --c-bg values, written out. */
  transition: opacity .1s; background: #1A2418; color: #F6F4EE;
  font-family: var(--ipd-font, system-ui, sans-serif); font-size: 11.5px;
  line-height: 1.45; padding: 7px 10px; border-radius: 7px; max-width: 240px;
  box-shadow: 0 4px 14px rgba(0, 0, 0, .22);
}
.ipd-tip b { color: #fff; font-weight: 700; }
.ipd-tip .ipd-k { opacity: .72; }

.ipd-w a:focus-visible, .ipd-w [tabindex]:focus-visible {
  outline: 2px solid var(--ipd-accent); outline-offset: 2px;
}
@media (prefers-reduced-motion: reduce) { .ipd-tip { transition: none; } }

/* Finals: one ranking per apparatus. Two columns where there is room, one on a
   narrow host - a finals event has two apparatus (groups) or four
   (individuals), so the grid has to cope with both. */
.ipd-finals {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 16px;
}
.ipd-final__h {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ipd-forest);
}
.ipd-w table.ipd-t--tight { min-width: 0; font-size: 12.5px; }
.ipd-w table.ipd-t--tight td { padding: 5px 6px; }
.ipd-w table.ipd-t tr.ipd-first td { background: var(--ipd-accent-soft); }
.ipd-w table.ipd-t tr.ipd-first td b { color: var(--ipd-accent); }
