@import "stylesheet";

$text-indent: 0.5cm;
$img-padding: 0.2cm;

/*
 * Fonts
 */

@font-face {
  font-family: LocalGentium;
  src: url(theme(
      "theme.assetDirectory"
    ) + "/TypoPRO-GentiumBookBasic-Regular.ttf");
}

@font-face {
  font-family: LocalGentium;
  font-weight: bold;
  src: url(theme("theme.assetDirectory") + "/TypoPRO-GentiumBookBasic-Bold.ttf");
}

@font-face {
  font-family: LocalGentium;
  font-style: italic;
  src: url(theme(
      "theme.assetDirectory"
    ) + "/TypoPRO-GentiumBookBasic-Italic.ttf");
}

$base-font-family: "LocalGentium";

/*
 * General
 */

body {
  font-size: 12pt;
  font-family: $base-font-family;
  padding: 0;
  margin: 0;
}

.element-header {
  text-align: right;
  white-space: nowrap;
  height: 120pt;
  page-break-after: avoid;

  &.without-number {
    height: 100pt;
  }

  .prefix {
    display: none;
  }

  .text {
    font-size: 120pt;
    font-weight: bold;
    color: #eee;
  }
}

.element-title {
  text-align: left;
  font-size: 30pt;
  margin-top: -75pt;
  margin-bottom: 36pt;
  height: 70pt;
  page-break-after: avoid;

  &.without-number {
    margin-top: 10pt;
  }
}

/*
 * The WeasyPrint-specific rules for use with that application.
 */

@page {
  @top-center {
    font-family: $base-font-family;
    font-size: 9pt;
    font-style: italic;
    vertical-align: bottom;
    padding-bottom: 1em;
  }

  @bottom-center {
    font-family: $base-font-family;
    font-size: 9pt;
    font-style: italic;
    content: counter(page);
    vertical-align: top;
    padding-top: 1em;
  }

  size: 6in 9in;
  margin: 0.7in 0.4in;
}

@page :right {
  padding-left: 0.4in;

  @top-center {
    content: themeString("edition.title");
  }
}

@page :left {
  padding-right: 0.4in;

  @top-center {
    content: themeString("edition.author");
  }
}

@page :first {
  @top-center {
    content: "";
  }
}

@page chapter {
  @top-center {
    content: "";
  }
}

@page blank {
  @top-center {
    content: "";
  }
  @bottom-center {
    content: "";
  }
}

body {
  // We assume hyphenate will be done as a pipeline.
  hyphens: manual;
}

/*
 * WeasyPrint has a couple bugs when it comes to running headers and page
 * breaks. These elements are to control how they work.
 */

div.element-page-break {
  page-break-before: always;

  &.element-page-break-right {
    page: chapter;
    page-break-before: right;
  }

  &.element-page-break-left {
    page: chapter;
    page-break-before: left;
  }

  &.element-page-break-blank {
    page: blank;
  }

  &.element-page-break-legal {
    page: blank;
  }

  &.element-page-break-title,
  &.element-page-break-dedication {
    page: blank;
    page-break-before: right;
  }
}

div.element-page-pad-right {
  page-break-after: right;
}

/*
 * Page Specific
 */

div.cover {
  text-align: center;

  img {
    width: 80%;
  }
}

div.chapter,
div.appendix,
div.toc,
div.preface,
div.colophon {
  // Paragraphs are formatted like text.
  p {
    text-indent: $text-indent;
    padding: 0;
    margin: 0;
    text-align: justify;
  }

  p:first-of-type {
    text-indent: 0;
  }

  p.single-image {
    text-indent: 0;
    text-align: center;

    img.single-image {
      width: 80%;
    }
  }
}

h2,
h3 {
  font-family: $base-font-family;
  font-weight: normal;
}

/*
 * Title
 */

div.title {
  text-align: center;
  padding-top: 0.5in;

  .large {
    font-weight: bold;
    font-size: 60pt;
  }

  .medium {
    font-weight: bold;
    font-size: 36pt;
  }

  .author {
    margin-top: 1in;
    font-weight: normal;
    font-size: 36pt;
  }

  .publisher {
    margin-top: 2in;
    font-weight: normal;
    font-size: 12pt;
  }
}

/*
 * Legal
 */

div.legal {
  p {
    text-indent: 0;
    padding: 0 0 1em 0;
  }
}

/*
 * Dedication
 */

div.dedication {
  padding: 1in;
  text-align: center;

  p {
    text-indent: 0;
    padding: 0 0 1em 0;
  }
}

/*
 * License
 */

div#license {
  p {
    text-indent: 0;
  }
}

/*
 * HTML Elements
 */

a {
  // PDFs don't show links as blue.
  text-decoration: none;
  color: black;
}

/*
 * Paragraphs
 */

p {
  line-height: 1.2;
}

/*
 * Table of Contents
 */

p.toc-1 {
  font-family: $base-font-family;
  margin: 0 !important;
  padding: 0 0 6pt 0 !important;
  line-height: 1 !important;
  text-indent: 0 !important;
  text-align: left;
}

/*
 * Rules
 */

div.rule {
  color: #eee;
  page-break-after: avoid;
}

/**
 * Chapter Plates
 */

div.plate {
  margin-top: -0.5in;

  img {
    height: 5.8in;
  }
}
