body {
  font-family: Arial, Helvetica, sans-serif;
  font-size: 10pt;
  background: #fff;
  color: #000;
}

.title {
  font-family: Verdana;
}

p {
  text-align: justify;
  text-rendering: optimizeLegibility;
  text-wrap: pretty;
  overflow-wrap: break-word;
  hyphens: auto;
  orphans: 2;
  widows: 2;
}

h1 {
  text-wrap: balance;
  line-height: 1.4;
}

emu-note p,
emu-table td p {
  text-align: left;
  hyphens: manual;
  overflow: hidden;
}

emu-table td,
emu-table th {
  overflow-wrap: break-word;
}

emu-table table {
  table-layout: auto;
  width: 100%;
}

emu-figure img {
  max-width: 100%;
  height: auto;
}

#spec-container {
  max-width: none;
}

#toc a,
#toc var {
  color: #000;
}

#toc a[href] {
  background: #fff;
  padding-right: 0.5em;
}
#toc a[href]::after {
  content: /* leader(dotted) */ target-counter(attr(href), page);
  float: right;
  padding-left: 0.5em;
  background: #fff;
}
/* NOTE: hacks because Paged.js doesn't support leader() in content directives */
#toc ol {
  overflow-x: hidden;
}
#toc ol li:before {
  float: left;
  width: 0;
  white-space: nowrap;
  content: '. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . '
    '. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . '
    '. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .';
}

/* skip the Introduction since it's before the first emu-clause (and therefore doesn't have a proper page number) */
#toc > ol > li:first-child {
  display: none;
}

#toc > ol > li {
  margin-top: 1ex;
}

#toc,
#spec-container > emu-intro,
#spec-container > emu-annex {
  break-before: recto;
  break-after: always;
}

/* according to Ecma guidelines, we're actually not supposed to break before every clause (only the first), but Paged.js fails if we do that */
/* so instead, just break before any of the clauses that have sub-clauses */
#spec-container > emu-clause:has(emu-clause:not([example])) {
  break-before: always;
}

#spec-container > emu-clause:first-of-type {
  break-before: recto;
}

emu-note,
emu-note p,
emu-table tr,
emu-table th,
emu-table td,
emu-alg li,
pre,
h1,
#metadata-block {
  break-inside: avoid;
}

emu-table thead,
h1,
figcaption,
emu-alg > ol > li:first-child {
  break-after: avoid;
}

emu-grammar + emu-alg,
figcaption + emu-table,
figcaption + span[id] + emu-table,
emu-alg > ol > li:last-child {
  break-before: avoid;
}

a[data-print-href]::after {
  content: ' <' attr(href) '>';
  color: initial;
}

emu-table thead {
  display: table-header-group;
}
emu-table tfoot {
  display: table-footer-group;
}

@page {
  size: A4;
}

@page {
  @top-center {
    content: url(./ecma-header.png);
  }
}
@page :first {
  @top-center {
    content: none;
  }
}

:root {
  --page-number-style: decimal;
}

#toc {
  page: toc;
}
@page toc {
  --page-number-style: lower-roman;
}
emu-intro {
  page: intro;
}
@page intro {
  --page-number-style: lower-roman;
}

#toc {
  counter-reset: page 1;
}
#spec-container > emu-clause:first-of-type {
  counter-reset: page 1;
}

@page :left {
  @bottom-left {
    content: counter(page, var(--page-number-style));
  }
}
@page :right {
  @bottom-right {
    content: counter(page, var(--page-number-style));
  }
}

@page :first {
  @bottom-left {
    content: '';
  }
  @bottom-right {
    content: '';
  }
}
