/* ==========================================================================
   Marathon XC Invitational - printable results (lib/print.js)
   US Letter or A4, 0.5in margins. On screen: white paper sheets under a
   sticky toolbar. In print: running footer with "Page N of M" from @page
   margin boxes (the footer text itself is set per document in a <style>).
   Ink-light: the three-colour season stripe is the only colour flourish, and
   every tint still reads in greyscale.
   ========================================================================== */

:root {
  color-scheme: light;
  --ink: #111a15;
  --ink-2: #2f3934;
  --muted: #5d6862;
  --faint: #89938e;
  --line: #cfd6d2;
  --hair: #e3e8e5;
  --zebra: #edf1ee;
  --brand: #34190a;
  --accent: #c2470f;
  --pine: #2d8752;
  --gold: #e5a82e;
  --orange: #e0621f;
  --maple: #b9301f;
  --display: "Barlow Condensed", "Arial Narrow", "Roboto Condensed", Arial, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* ------------------------------------------------------------------ page */

@page {
  margin: 0.5in;
  /* An (invisible) top margin box stops Chromium drawing its own date/title
     header when "Headers and footers" is left on in the print dialog; the
     bottom boxes already replace its footer. */
  @top-center { content: ""; }
  @bottom-left {
    font-family: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 6.75pt;
    line-height: 1.45;
    color: #6b746f;
    white-space: pre-wrap;
    vertical-align: top;
    padding-top: 5pt;
    border-top: 0.5pt solid #c9d0cc;
  }
  @bottom-right {
    width: 1.1in;
    white-space: nowrap;
    content: "Page " counter(page) " of " counter(pages);
    font-family: system-ui, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 7.5pt;
    font-weight: 600;
    color: #4a544f;
    vertical-align: top;
    text-align: right;
    padding-top: 5pt;
    border-top: 0.5pt solid #c9d0cc;
  }
}

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

html {
  -webkit-print-color-adjust: exact;
  print-color-adjust: exact;
}

body {
  margin: 0;
  background: #fff;
  color: var(--ink);
  font-family: var(--body);
  font-size: 9pt;
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3, p { margin: 0; }

.muted { color: var(--muted); }
.dot { color: var(--faint); padding: 0 0.15em; }

/* ------------------------------------------------------------------ title block */

.tblock {
  margin-bottom: 14pt;
  break-inside: avoid;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10pt;
}

.brand-mark {
  width: 0.55in;
  height: 0.55in;
  flex: none;
  display: block;
}

.brand-name {
  font-family: var(--display);
  font-weight: 700;
  font-size: 13.5pt;
  line-height: 1.05;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  color: var(--brand);
}

.brand-facts {
  margin-top: 2pt;
  font-size: 8.5pt;
  color: var(--muted);
}

.stripe {
  display: flex;
  gap: 2pt;
  height: 3pt;
  margin: 9pt 0 12pt;
}
.stripe i { flex: 1; display: block; }
.stripe i:nth-child(1) { background: var(--gold); }
.stripe i:nth-child(2) { background: var(--orange); }
.stripe i:nth-child(3) { background: var(--maple); }
.stripe i:nth-child(4) { display: none; } /* the stripe has no green quarter */

.kicker {
  font-family: var(--display);
  font-weight: 600;
  font-size: 8pt;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1pt;
}

.doc-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 27pt;
  line-height: 1;
  letter-spacing: 0.005em;
  color: var(--ink);
}

.doc-meta {
  margin-top: 5pt;
  font-size: 9.5pt;
  color: var(--ink-2);
}

.doc-notes {
  margin-top: 5pt;
  font-size: 8.5pt;
  color: var(--muted);
  font-style: italic;
}

/* ------------------------------------------------------------------ section headings */

.part { margin-top: 16pt; }
.tblock + .part,
.tblock + .contents,
.tblock + .sp-summary { margin-top: 0; }

.part-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 13pt;
  line-height: 1.1;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--ink);
  margin-bottom: 5pt;
  break-after: avoid;
}

.part-sub {
  color: var(--muted);
  font-weight: 600;
}
.part-sub::before { content: "\2014\00a0"; color: var(--faint); }

.sub {
  font-family: var(--display);
  font-weight: 600;
  font-size: 8.5pt;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 8pt 0 3pt;
  break-after: avoid;
}

.table-note {
  margin-top: 4pt;
  font-size: 7.5pt;
  color: var(--muted);
}

.empty {
  padding: 18pt 0;
  color: var(--muted);
  font-style: italic;
}

/* ------------------------------------------------------------------ tables */

table.results {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

table.results thead { display: table-header-group; }

table.results th {
  font-family: var(--display);
  font-weight: 600;
  font-size: 7.75pt;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  text-align: left;
  padding: 2pt 4pt 2.5pt;
  border-bottom: 0.9pt solid var(--ink);
  white-space: nowrap;
  overflow: hidden;
}

table.results td {
  padding: 1.3pt 4pt;
  line-height: 1.25;
  vertical-align: baseline;
  overflow-wrap: break-word;
  border-bottom: 0.4pt solid var(--hair);
}

table.results tr { break-inside: avoid; page-break-inside: avoid; }
table.results tbody tr:nth-child(even) td { background: var(--zebra); }
table.results tbody:last-child tr:last-child td { border-bottom: 0.9pt solid var(--line); }
table.results tbody.lead,
table.results tbody.tail { break-inside: avoid; page-break-inside: avoid; }

/* column widths (table-layout: fixed). In the individual results name and
   school get content-sized shares and the leftover width is spread over
   every column, so the row reads evenly instead of across one wide gap. */
.w-pl { width: 3.2em; }
.w-gr { width: 2.5em; }
.w-time { width: 4.8em; }
.w-tm { width: 3.6em; }
.w-bib { width: 3.6em; }
.ind .w-name { width: 29%; }
.ind .w-school { width: 27%; }

.c-pl, .c-gr, .c-tm, .c-score, .c-count, .c-num { text-align: center !important; }
.c-time, .c-bib, .c-avg, .c-split { text-align: right !important; }

td.c-name { font-weight: 600; color: var(--ink); }
td.c-pl, td.c-time, td.c-disp, td.c-gap, td.c-score { white-space: nowrap; }
td.c-school { color: var(--ink-2); }
td.c-time { color: var(--ink); }
td.c-tm, td.c-bib { color: var(--muted); }
td.c-gr { color: var(--ink-2); }

/* place marker: places 1-3 look exactly like every other place */
.pl {
  display: inline-block;
  min-width: 1.6em;
  text-align: center;
  font-weight: 600;
}

/* DNF / DNS / DQ rows at the end */
tr.is-status td { color: var(--muted); }
tr.is-status td.c-name { font-weight: 500; }
tr.first-status td { border-top: 0.9pt solid var(--line); }
.st {
  font-family: var(--display);
  font-weight: 700;
  font-size: 8pt;
  letter-spacing: 0.06em;
  color: var(--ink-2);
}

/* ------------------------------------------------------------------ team scores */

.tsec { margin-top: 18pt; }
.tsec:first-child { margin-top: 0; }
.part-individual + .part-teams { margin-top: 18pt; }

.tsec-head {
  break-inside: avoid;
  break-after: avoid;
}
.tsec-top.keep { break-inside: avoid; }
.tsec-head .part-title { margin-bottom: 1pt; }

.tsec-meta {
  font-size: 8.5pt;
  color: var(--muted);
  margin-bottom: 2pt;
}

.standings .w-tpl { width: 3.2em; }
.standings .w-score { width: 4em; }
.standings .w-places { width: 12em; }
.standings .w-disp { width: 7em; }
.standings .w-avg { width: 4.4em; }
.standings .w-split { width: 5.6em; }
.standings .w-total { width: 5.4em; }
.standings td.c-team { font-weight: 600; }
.standings td.c-score { font-weight: 700; font-size: 9.5pt; }
/* Ranked by combined time: Total is the deciding figure, Score is secondary. */
.standings .c-total { text-align: right !important; }
.standings td.c-total { font-weight: 700; font-size: 9.5pt; white-space: nowrap; }
.standings.by-time td.c-score { font-weight: 400; font-size: 9pt; color: var(--ink-2); }
.standings td.c-places { letter-spacing: 0.02em; color: var(--ink-2); white-space: nowrap; }
.standings td.c-disp { color: var(--muted); }
.standings td.c-avg, .standings td.c-split { color: var(--ink-2); }

.sub-detail { margin-top: 10pt; }

.teams {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 20pt;
  row-gap: 10pt;
}

.team {
  break-inside: avoid;
  page-break-inside: avoid;
  border-top: 1.2pt solid var(--ink);
  padding-top: 3pt;
  min-width: 0;
}

.team-head {
  display: flex;
  align-items: baseline;
  gap: 5pt;
  padding-bottom: 2.5pt;
  border-bottom: 0.5pt solid var(--line);
}
.team-head .pl {
  font-family: var(--display);
  font-size: 10pt;
  min-width: 1.75em;
  flex: none;
}
.team-name {
  flex: 1;
  min-width: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: 11pt;
  line-height: 1.1;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  overflow-wrap: break-word;
}
.team-score {
  flex: none;
  font-family: var(--display);
  font-weight: 700;
  font-size: 12pt;
  line-height: 1;
}
.team-score small {
  font-size: 7pt;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.team-runners {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 8.5pt;
}
.team-runners td {
  padding: 1pt 3pt;
  border-bottom: 0.4pt solid var(--hair);
  vertical-align: baseline;
  overflow-wrap: break-word;
}
.team-runners .r-pl { width: 3.5em; text-align: right; padding-right: 6pt; font-weight: 600; white-space: nowrap; }
.team-runners .r-g { width: 1.8em; text-align: center; color: var(--muted); font-size: 7.5pt; }
.team-runners .r-time { width: 4em; text-align: right; }
.team-runners tr.disp td { color: var(--muted); }
.team-runners tr.disp .r-pl { font-weight: 400; }

/* Displacer places "(43)": the closing paren takes no width, so the digits
   line up with the scorers' places above. */
.pp::before { content: "("; }
.pp::after { content: ")"; display: inline-block; width: 0; }

.team-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 2pt 11pt;
  padding-top: 2.5pt;
  font-size: 7.5pt;
  color: var(--muted);
}
.team-foot b { font-weight: 600; color: var(--ink-2); }

/* The scoring key: a footnote right under the first standings table. */
.legend {
  margin-top: 4pt;
  font-size: 7.25pt;
  line-height: 1.4;
  color: var(--muted);
  break-inside: avoid;
}
.legend b { color: var(--ink-2); }
.teams-solo .legend { margin-top: 0; padding-top: 4pt; align-self: start; }

/* ------------------------------------------------------------------ meet cover */

.toc .w-num { width: 2.6em; }
.toc .w-group { width: 7em; }
.toc .w-count { width: 5.5em; }
.toc td { padding-top: 3.5pt; padding-bottom: 3.5pt; font-size: 9.5pt; }
.toc td.c-race { font-weight: 600; }
.toc td.c-num, .toc td.c-group { color: var(--muted); }

.champions { margin-top: 22pt; break-inside: avoid; }
.champs .w-race { width: 28%; }
.champs .w-time { width: 5em; }
.champs .w-team { width: 22%; }
.champs .w-pts { width: 3.6em; }
.champs td { padding-top: 3pt; padding-bottom: 3pt; }
.champs td.c-race { font-weight: 600; }
.champs td b { font-weight: 600; }
.champs .c-pts { text-align: right !important; }
.champs td.c-pts { font-weight: 700; }

/* ------------------------------------------------------------------ coach packet */

.sp-sum .w-teamres { width: 9.5em; }
.sp-sum .w-count { width: 5em; }
.sp-sum .w-top { width: 42%; }
.sp-sum td.c-race { font-weight: 600; }

/* Short sections never split; long ones keep the heading with their first
   rows (tbody.lead) and then break with a repeated table header. */
.sp-race { margin-top: 18pt; }
.sp-race.keep { break-inside: avoid; }
.sp-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 2pt 12pt;
  border-bottom: 1.2pt solid var(--ink);
  padding-bottom: 2pt;
  break-after: avoid;
}
.sp-title {
  font-family: var(--display);
  font-weight: 700;
  font-size: 14pt;
  line-height: 1.1;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.sp-meta { font-size: 8pt; color: var(--muted); }

.sp-lines {
  list-style: none;
  margin: 5pt 0 5pt;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 2pt 16pt;
  font-size: 9.5pt;
  break-after: avoid;
}
.sp-lines .lbl { color: var(--muted); }
.sp-runners { margin-top: 2pt; }
.sp-runners .w-name { width: 32%; }
.sp-runners.no-role .w-name { width: auto; }
.sp-runners .w-gap { width: 5.4em; }
.sp-runners .w-tm { width: 4.4em; }
.sp-runners .w-role { width: auto; }
.sp-runners td.c-gap { text-align: right; color: var(--muted); }
.sp-runners th.c-gap { text-align: right; }
.sp-runners .c-role { padding-left: 14pt; }
.sp-runners td.c-role { color: var(--ink-2); }
.sp-runners td.c-role.is-disp { color: var(--muted); }
.sp-runners tr.disp td { color: var(--muted); }

/* ------------------------------------------------------------------ screen */

.pbar { display: none; }

@media screen {
  html { background: #dfe4e1; }
  body { background: #dfe4e1; font-size: 9pt; }

  .pbar {
    display: block;
    position: sticky;
    top: 0;
    z-index: 10;
    background: var(--brand);
    color: #fff;
    font-family: var(--body);
    box-shadow: 0 2px 10px rgba(40, 22, 10, 0.22);
  }
  .pbar::after {
    content: "";
    display: block;
    height: 3px;
    background: linear-gradient(90deg, var(--pine) 0 25%, var(--gold) 25% 50%, var(--orange) 50% 75%, var(--maple) 75% 100%);
  }
  .pbar-in {
    max-width: calc(8.5in + 32px);
    margin: 0 auto;
    padding: 10px 16px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 10px 16px;
  }
  .pbar-back {
    color: #fff;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    white-space: nowrap;
    padding: 6px 0;
  }
  .pbar-back:hover, .pbar-back:focus-visible { text-decoration: underline; }
  .pbar-label {
    flex: 1;
    min-width: 0;
    font-family: var(--display);
    font-weight: 600;
    font-size: 15px;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: #b4c5bb;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .seg {
    display: inline-flex;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 9px;
    padding: 3px;
    gap: 2px;
  }
  .seg a {
    color: #dbe6df;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    padding: 6px 13px;
    border-radius: 7px;
    text-align: center;
  }
  .seg a:hover { background: rgba(255, 255, 255, 0.12); color: #fff; }
  .seg a.on { background: #fff; color: var(--brand); }
  .pbar-print {
    appearance: none;
    border: 0;
    border-radius: 9px;
    background: var(--accent);
    color: #fff;
    font: 600 14px/1 var(--body);
    padding: 11px 16px;
    cursor: pointer;
    white-space: nowrap;
  }
  .pbar-print:hover { background: #a83c0b; }
  .pbar a:focus-visible, .pbar-print:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

  .sheets { padding: 28px 16px 56px; }
  .sheet {
    background: #fff;
    max-width: 8.5in;
    min-height: 4in;
    margin: 0 auto 28px;
    padding: 0.5in;
    border-radius: 2px;
    box-shadow: 0 1px 2px rgba(40, 22, 10, 0.08), 0 10px 30px rgba(40, 22, 10, 0.14);
  }

  @media (max-width: 700px) {
    .pbar-label { display: none; }
    .pbar-back { order: 1; }
    .pbar-print { order: 2; margin-left: auto; }
    .seg { order: 3; flex: 1 1 100%; }
    .seg a { flex: 1; padding: 7px 6px; }
    .sheets { padding: 14px 8px 32px; }
    .sheet { padding: 22px 14px 28px; margin-bottom: 14px; }
    body { font-size: 8pt; }
    .doc-title { font-size: 22pt; }
    .brand-mark { width: 40px; height: 40px; }
    .teams { grid-template-columns: 1fr; }
    table.results td, table.results th { padding-left: 2.5pt; padding-right: 2.5pt; }
    .ind .w-bib, .ind .c-bib { display: none; }
    .standings .w-places { width: 10.5em; }
    .standings td.c-places { letter-spacing: 0; }
    .w-pl, .standings .w-tpl { width: 2.6em; }
    .w-time { width: 4.3em; }
    .w-tm, .sp-runners .w-tm { width: 3em; }
    /* name and school share the rest about equally (names are bold, so a bit more) */
    .ind .w-name { width: 33%; }
    .ind .w-school { width: auto; }
    td.c-name, td.c-school { hyphens: manual; overflow-wrap: anywhere; }
    .standings .w-score { width: 3em; }
    .standings .w-total { width: 4.6em; }
    .sp-runners .w-name, .sp-runners.no-role .w-name { width: auto; }
    .sp-runners .w-role, .sp-runners .c-role { display: none; }
    .standings .w-avg, .standings .c-avg, .sp-sum .w-top, .sp-sum .c-top { display: none; }
    .champs .w-time, .champs .c-time { display: none; }
    .champs .w-race { width: 34%; }
    .champs .w-team { width: 28%; }
  }
}

/* ------------------------------------------------------------------ print */

@media print {
  html, body { background: #fff; }
  .pbar { display: none !important; }
  .sheets { padding: 0; }
  .sheet { break-before: page; }
  .sheet:first-child { break-before: auto; }
  a { color: inherit; text-decoration: none; }
}
