/*
 * Public ranking embed (docs/EMBED.md). Colours and font come from custom
 * properties the server sets from validated query parameters; these fallbacks
 * match the default theme.
 */
:root {
  --embed-bg: #ffffff;
  --embed-text: #1a1a1a;
  --embed-link: #2e7d32;
  --embed-focus: #2e7d32;
  --embed-accent: #2e7d32;
  --embed-header: #0f2a44;
  --embed-header-text: #ffffff;
  --embed-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --embed-row-bg: var(--embed-bg);
  --embed-line: color-mix(in srgb, var(--embed-text) 22%, var(--embed-row-bg));
  --embed-stripe: color-mix(in srgb, var(--embed-text) 5%, var(--embed-row-bg));
  --embed-heading-font: var(--embed-font);
  --embed-size: 16px;
  --embed-heading-size: 22px;
  --embed-heading-weight: 700;
  --embed-heading-transform: none;
  --embed-pad-y: 8px;
  --embed-pad-x: 10px;
}

* { box-sizing: border-box; }

html, body.embed-body {
  margin: 0;
  background: var(--embed-bg);
  color: var(--embed-text);
  font-family: var(--embed-font);
  line-height: 1.45;
}

/* Base text size from the style (14–20px); everything else is in rem, so it scales with it. */
html { font-size: var(--embed-size); }
body.embed-body { font-size: 1rem; }

.embed {
  padding: 12px 16px 16px;
  max-width: 100%;
}

.embed-header h1 {
  margin: 0 0 4px;
  padding-bottom: 6px;
  border-bottom: 3px solid var(--embed-accent);
  font-family: var(--embed-heading-font);
  font-size: var(--embed-heading-size);
  font-weight: var(--embed-heading-weight);
  text-transform: var(--embed-heading-transform);
  line-height: 1.25;
}

.embed-meta,
.embed-note,
.embed-footer,
.embed-message {
  margin: 8px 0;
  font-size: 1rem;
}

.embed-footer { font-size: 0.95rem; }

a { color: var(--embed-link); text-underline-offset: 2px; }

a:focus-visible,
button:focus-visible,
select:focus-visible,
input:focus-visible,
.embed-table-wrap:focus-visible {
  outline: 3px solid var(--embed-focus);
  outline-offset: 2px;
}

.embed-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 24px;
  margin: 12px 0;
}

.embed-switcher,
.embed-history { flex: 1 1 16rem; min-width: 0; }

.embed-switcher label,
.embed-history label {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
}

.embed-search { flex: 1 1 16rem; min-width: 0; }
.embed-search[hidden] { display: none; }
.embed-search label {
  display: block;
  margin-bottom: 4px;
  font-weight: 600;
}
.embed-search input {
  box-sizing: border-box;
  width: 100%;
  min-height: 44px;
  padding: 8px 10px;
  font: inherit;
  color: var(--embed-text);
  background: var(--embed-bg);
  border: 1px solid var(--embed-text);
  border-radius: 6px;
}
.embed-search-status { margin: 6px 0 0; min-height: 1.4em; }
.embed-table tr[hidden] { display: none; }

.embed-switcher-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.embed-switcher select,
.embed-history input,
.embed-switcher button,
.embed-history button {
  min-height: 44px;
  font: inherit;
  border-radius: 6px;
  border: 1px solid var(--embed-text);
}

.embed-switcher select,
.embed-history input {
  flex: 1 1 10rem;
  min-width: 0;
  max-width: 100%;
  padding: 0 8px;
  background: var(--embed-bg);
  color: var(--embed-text);
}

.embed-switcher button,
.embed-history button {
  min-width: 44px;
  padding: 0 16px;
  background: var(--embed-header);
  color: var(--embed-header-text);
  border-color: var(--embed-header-text);
  font-weight: 600;
  cursor: pointer;
}

.embed-table-wrap {
  /* Contains the absolutely positioned .embed-sr text in off-screen columns, so only this box scrolls. */
  position: relative;
  max-width: 100%;
  overflow-x: auto;
  /*
   * Never a vertical scroller: the iframe grows to the page height (web/embed.js posts it), so only a
   * genuinely wide table scrolls, sideways. overflow-x:auto alone would make overflow-y auto too, and
   * a few pixels of overflow (focus outlines, hidden text) gave the table its own vertical scrollbar.
   */
  overflow-y: hidden;
  margin: 12px 0;
  border: 1px solid var(--embed-line);
  border-radius: 6px;
}

.embed-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  background: var(--embed-row-bg);
}

/* Cell padding follows the style's table density (compact 8px 10px, comfortable 12px 14px). */
.embed-table th,
.embed-table td {
  padding: var(--embed-pad-y) var(--embed-pad-x);
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--embed-line);
}

/* Table borders: rows (default) draws lines between rows; grid outlines every cell; none draws no lines. */
.embed-borders-grid .embed-table-wrap { border: 0; border-radius: 0; }
.embed-borders-grid .embed-table > thead > tr > th,
.embed-borders-grid .embed-table > tbody > tr > th,
.embed-borders-grid .embed-table > tbody > tr > td { border: 1px solid var(--embed-line); }
.embed-borders-none .embed-table-wrap { border: 0; }
.embed-borders-none .embed-table > thead > tr > th,
.embed-borders-none .embed-table > tbody > tr > th,
.embed-borders-none .embed-table > tbody > tr > td { border: 0; }

.embed-table thead th {
  background: var(--embed-header);
  color: var(--embed-header-text);
  vertical-align: bottom;
  font-weight: 700;
}

.embed-table tbody th { font-weight: 600; }

.embed-table tbody tr.embed-row-alt { background: var(--embed-stripe); }

.embed-table tbody tr:last-child th,
.embed-table tbody tr:last-child td { border-bottom: 0; }

.embed-borders-grid .embed-table > tbody > tr:last-child > th,
.embed-borders-grid .embed-table > tbody > tr:last-child > td { border-bottom: 1px solid var(--embed-line); }

.embed-table .embed-num { text-align: right; white-space: nowrap; }
.embed-table .embed-age { white-space: nowrap; }

.embed-table .embed-ranks { font-weight: 700; }

.embed-table thead .embed-event {
  /* One line per heading: a wrapped long event name made the header row very tall on phones. */
  min-width: 8rem;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.95rem;
}

.embed-event-label,
.embed-event-date { display: block; }

.embed-event-date { font-weight: 400; }

.embed-index {
  margin: 12px 0;
  padding: 0;
  list-style: none;
}

.embed-index li { margin: 0; }

.embed-index a {
  display: block;
  min-height: 44px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--embed-line);
}

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

.embed-history-links {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 16px;
  margin: 6px 0 0;
}

.embed-history-links a {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
}

.embed-as-at {
  margin: 8px 0;
  padding: 8px 12px;
  border-left: 4px solid var(--embed-accent);
  background: var(--embed-stripe);
}

/* Player name that expands their results (web/embed.js). */
.embed-player {
  display: inline-flex;
  align-items: flex-start;
  gap: 6px;
  /* The cell's own padding is part of the 44px target, so the button never overflows its row. */
  min-height: 44px;
  /* Matches the cell padding (the table density), so the button never overflows its row. */
  margin: calc(-1 * var(--embed-pad-y)) 0;
  padding: var(--embed-pad-y) 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  font-weight: 600;
  text-align: left;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  cursor: pointer;
}

.embed-chevron::before {
  content: "▸";
  display: inline-block;
  width: 0.8em;
}

.embed-player[aria-expanded="true"] .embed-chevron::before { content: "▾"; }

.embed-detail td {
  padding-top: 4px;
  padding-bottom: 12px;
}

.embed-results {
  /* Stay readable at the left of a wide, scrolled table (event columns on). */
  position: sticky;
  left: 10px;
  /* Fits the visible width (page padding, cell padding and border), so Points never hides off to the side. */
  width: min(36rem, calc(100vw - 64px));
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

.embed-table .embed-results th,
.embed-table .embed-results td {
  padding: 6px 10px;
  border-bottom: 1px solid var(--embed-line);
  background: transparent;
  color: inherit;
}

.embed-table .embed-results thead th {
  background: transparent;
  color: inherit;
  font-weight: 700;
  border-bottom: 2px solid var(--embed-line);
}

.embed-table .embed-results tbody th { font-weight: 600; }

.embed-table .embed-results tbody tr:last-child th,
.embed-table .embed-results tbody tr:last-child td { border-bottom: 0; }

.embed-adjustment-column { display: block; font-weight: 400; }

.embed-results-note,
.embed-results-empty { margin: 6px 0 0; }
