@mixin page-top-style() {
  content: '';
  margin-bottom: 4mm;
}

@media screen {
  body {
    margin: auto 4rem;
    padding-bottom: 4rem;
  }
  article {
    margin: 0 auto;
    max-width: 60rem;
  }
  section {
    clear: both;
  }

  figure {
    max-width: 50rem;
  }

  .footnote {
    vertical-align: super;
    background-color: rgba(214, 255, 0, 0.4);
    margin: 0 0.1rem;
    line-height: 0;

    a {
      word-break: break-all;
    }
  }

  a[data-ref='sec'],
  a[data-ref='subsec'],
  a[data-ref='fig'],
  a[data-ref='tbl'],
  a[data-ref='cite'] {
    color: $color_red;
    background-color: rgba(255, 0, 0, 0.3);
  }
  a[data-ref='sec']::before {
    content: '§ XXX';
  }
  a[data-ref='subsec']::before {
    content: '§ XXX.XXX';
  }
  a[data-ref='fig']::before {
    content: 'Fig. XXX';
    :root:lang(ja) & {
      content: '図 XXX';
    }
  }
  a[data-ref='tbl']::before {
    content: 'Table XXX';
    :root:lang(ja) & {
      content: '表 XXX';
    }
  }
  a[data-ref='cite']::before {
    content: '[XXX]';
  }
}

@media print {
  :root {
    widows: 3;
    orphans: 3;
    hyphens: auto;
    font-size: 100%;
  }

  h1,
  h2,
  h3,
  h4,
  h5,
  h6 {
    break-after: avoid;
  }

  tr,
  th,
  td {
    break-inside: avoid;
  }

  .footnote {
    float: footnote;
    text-align: left;
  }
}

@page {
  size: $page-width $page-height;
  margin-top: $page-margin-top;
  margin-bottom: $page-margin-bottom - 6mm;

  @top-left-corner {
    @include page-top-style();
    margin-top: -$page-bleed;
    margin-left: -$page-bleed;
  }
  @top-center {
    @include page-top-style();
    margin-top: -$page-bleed;
    margin-left: -1mm;
    margin-right: -1mm;
    padding-left: 1mm;
    padding-right: 1mm;
  }
  @top-right-corner {
    @include page-top-style();
    margin-top: -$page-bleed;
    margin-right: -$page-bleed;
  }

  @bottom-left-corner {
    content: '';
    margin-top: -8mm;
    margin-bottom: -$page-bleed;
    margin-left: -$page-bleed;
    background-color: $color_white;
    z-index: 1000;
  }
  @bottom-right-corner {
    content: '';
    margin-top: -8mm;
    margin-bottom: -$page-bleed;
    margin-right: -$page-bleed;
    background-color: $color_white;
    z-index: 1000;
  }
}

@page :left {
  font-family: $font-family;
  margin-left: $page-margin-outer;
  margin-right: $page-margin-inner;

  @top-center {
    content: env(pub-title);
    font-size: 75%;
    text-align: left;
    padding: 12mm 2mm 0 2mm;
  }
  @bottom-left {
    content: counter(page);
    margin-top: 15mm;
    margin-bottom: -$page-bleed;
    padding: 0 2mm 15mm 2mm;
  }
}

@page :right {
  font-family: $font-family;
  margin-left: $page-margin-inner;
  margin-right: $page-margin-outer;

  @top-center {
    content: env(doc-title);
    font-size: 75%;
    text-align: right;
    padding: 12mm 2mm 0 2mm;
  }
  @bottom-right {
    content: counter(page);
    margin-top: 15mm;
    margin-bottom: -$page-bleed;
    padding: 0 2mm 15mm 2mm;
  }
}
