/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */

/* Avoid adding ID selector rules in this style sheet, since they could
 * inadvertently match elements in the article content. */

:root {
  --gray-theme-background: var(--color-gray-30);
  --light-theme-background: #fff;
  --light-theme-foreground: rgb(21, 20, 26);
  --dark-theme-background: rgb(28, 27, 34);
  --dark-theme-foreground: rgb(251, 251, 254);
  --body-padding: 64px;
  --font-size: 12;
  --content-width: 22em;
  --line-height: 1.6em;
  --text-alignment: start;
  --word-spacing: 0;
  --letter-spacing: 0;
  --font-weight: normal;
  --font-family: sans-serif;
  --block-img-margin-left: unset;
  --block-img-margin-right: unset;
}

body {
  --main-background: var(--light-theme-background);
  --main-foreground: var(--light-theme-foreground);
  --primary-color: rgb(0, 97, 224);
  --toolbar-border: var(--color-black-alpha-20);
  --toolbar-transparent-border: transparent;
  --toolbar-button-background: transparent;
  --toolbar-button-background-hover: rgba(207, 207, 216, 0.66);
  --toolbar-button-foreground-hover: var(--icon-fill);
  --toolbar-button-background-active: rgb(207, 207, 216);
  --toolbar-button-foreground-active: var(--primary-color);
  --toolbar-button-border: transparent;
  --toolbar-button-border-hover: var(--toolbar-button-border);
  --toolbar-button-border-active: var(--toolbar-button-border);
  --tooltip-background: var(--toolbar-button-background-active);
  --tooltip-foreground: var(--icon-fill);
  --tooltip-border: transparent;
  --popup-background: #fff;
  --popup-foreground: var(--main-foreground);
  --popup-border: rgba(0, 0, 0, 0.12);
  --popup-line: var(--gray-theme-background);
  --popup-shadow: rgba(49, 49, 49, 0.3);
  --popup-button-background: rgba(207, 207, 216, 0.33);
  --popup-button-foreground: var(--main-foreground);
  --popup-button-selected-foreground: var(--color-gray-0);
  --popup-button-background-hover: var(--toolbar-button-background-hover);
  --popup-button-foreground-hover: var(--main-foreground);
  --popup-button-background-active: var(--toolbar-button-background-active);
  --popup-button-border: rgba(0, 0, 0, 0.2);
  --selected-background: rgba(0, 97, 224, 0.3);
  --outline-focus-color: var(--primary-color);
  --icon-fill: rgb(91, 91, 102);
  --icon-disabled-fill: rgba(91, 91, 102, 0.4);
  --text-selected-background: var(--selected-background);
  --text-selected-foreground: inherit;
  --link-foreground: var(--primary-color);
  --link-selected-background: var(--selected-background);
  --link-selected-foreground: #333;
  --visited-link-foreground: #b5007f;
  --custom-theme-background: var(--color-white);
  --custom-theme-foreground: var(--color-gray-100);
  --custom-theme-unvisited-links: var(--color-blue-50);
  --custom-theme-visited-links: #321c64;
  --custom-theme-selection-highlight: #ffffcc;
  /* light colours */
}

body.light {
  color-scheme: light;
}

body.sepia {
  color-scheme: light;
  --main-background: rgb(244, 236, 216);
  --main-foreground: rgb(91, 70, 54);
  --toolbar-border: var(--main-foreground);
  --icon-fill: var(--main-foreground);
  --icon-disabled-fill: rgba(91, 70, 54, 0.4);
}

body.gray {
  color-scheme: light;
  --main-background: var(--gray-theme-background);
  --main-foreground: var(--light-theme-foreground);
  --toolbar-border: var(--main-foreground);
  --icon-fill: var(--main-foreground);
}

body.dark,
body.contrast {
  color-scheme: dark;
  --toolbar-button-background-hover: rgb(82, 82, 94);
  --toolbar-button-background-active: rgb(91, 91, 102);
  --popup-background: rgb(66, 65, 77);
  --popup-button-border: rgba(255, 255, 255, 0.2);
  --popup-line: rgba(249, 249, 250, 0.1);
  --popup-button-background: rgb(43, 42, 51);
  --icon-disabled-fill: rgba(251, 251, 254, 0.4);
  --link-selected-foreground: #fff;
  --visited-link-foreground: #e675fd;
  --selected-background: rgba(0, 221, 255, 0.3);
  --popup-button-selected-foreground: var(--color-gray-100);
  /* dark colours */

  .moz-reader-block-img {
    filter: brightness(0.8) contrast(1.2);
  }
}

body.dark {
  --main-background: var(--dark-theme-background);
  --main-foreground: var(--dark-theme-foreground);
  --primary-color: rgb(0, 221, 255);
  --toolbar-border: var(--color-white-alpha-20);
  --icon-fill: rgb(251, 251, 254);
}

body.contrast {
  --main-background: #000000;
  --main-foreground: #fff;
  --primary-color: #d6b4fd;
  --link-color: #8080ff;
  --link-color-hover: #d6b4fd;
  --toolbar-border: #ffee32;
  --icon-fill: #ffee32;
}

body.custom {
  color-scheme: light;
  --main-background: var(--custom-theme-background);
  --main-foreground: var(--custom-theme-foreground);
  --link-foreground: var(--custom-theme-unvisited-links);
  --visited-link-foreground: var(--custom-theme-visited-links);
  --popup-foreground: var(--light-theme-foreground);
  --popup-button-foreground: var(--light-theme-foreground);
  --popup-button-foreground-hover: var(--light-theme-foreground);
  --tooltip-foreground: var(--light-theme-foreground);
  --toolbar-border: var(--main-foreground);
  --icon-fill: var(--main-foreground);
  --icon-disabled-fill: rgba(91, 91, 102, 0.4);
}

body.hcm {
  --main-background: Canvas;
  --main-foreground: CanvasText;
  --primary-color: SelectedItem;
  --toolbar-border: CanvasText;
  /* We need a true transparent but in HCM this would compute to an actual color,
     so select the page's background color instead: */
  --toolbar-transparent-border: Canvas;
  --toolbar-button-background: ButtonFace;
  --toolbar-button-background-hover: SelectedItem;
  --toolbar-button-foreground-hover: SelectedItemText;
  --toolbar-button-background-active: SelectedItemText;
  --toolbar-button-foreground-active: SelectedItem;
  --toolbar-button-border: ButtonText;
  --toolbar-button-border-hover: SelectedItemText;
  --toolbar-button-border-active: SelectedItem;
  --tooltip-background: Canvas;
  --tooltip-foreground: CanvasText;
  --tooltip-border: CanvasText;
  --popup-background: Canvas;
  --popup-foreground: CanvasText;
  --popup-border: CanvasText;
  --popup-line: CanvasText;
  --popup-button-background: ButtonFace;
  --popup-button-foreground: ButtonText;
  --popup-button-background-hover: ButtonFace;
  --popup-button-foreground-hover: SelectedItem;
  --popup-button-background-active: ButtonFace;
  --popup-button-border: ButtonText;
  --link-color-hover: SelectedItem;
  --selected-background: Canvas;
  --outline-focus-color: CanvasText;
  --icon-fill: ButtonText;
  --icon-disabled-fill: GrayText;
  --text-selected-background: SelectedItem;
  --text-selected-foreground: SelectedItemText;
  --popup-button-selected-foreground: SelectedItemText;
  --link-foreground: LinkText;
  --link-selected-background: SelectedItem;
  --link-selected-foreground: SelectedItemText;
  --visited-link-foreground: VisitedText;
}

body.hcm .colors-dropdown {
  /* Hide entire colors menu when HCM is on. */
  display: none;
}

body {
  margin: 0;
  padding: var(--body-padding);
  background-color: var(--main-background);
  color: var(--main-foreground);
}

body.loaded {
  transition:
    color 0.4s,
    background-color 0.4s;
}

*::selection {
  background-color: var(--text-selected-background);
  color: var(--text-selected-foreground);
}

a {
  border-radius: var(--border-radius-xsmall);
}

a::selection {
  background-color: var(--link-selected-background);
  color: var(--link-selected-foreground);
}

a:focus-visible {
  outline: 2px solid var(--outline-focus-color);
  outline-offset: 1px;
}

body {
  font-family: var(--font-family);
}

body.sans-serif {
  font-family: sans-serif;
}

body.serif {
  font-family: serif;
}

/* Override some controls and content styles based on color scheme */

blockquote {
  border-inline-start: 2px solid var(--main-foreground) !important;
}

/* Loading/error message */

.reader-message {
  margin-top: 40px;
  display: none;
  text-align: center;
  width: 100%;
  font-size: 0.9em;
}

/* Detector element to see if we're at the top of the doc or not. */
.top-anchor {
  position: absolute;
  top: 0;
  width: 0;
  height: 5px;
  pointer-events: none;
}

/* Header */

.header {
  text-align: start;
  display: none;
}

.domain {
  font-size: 0.9em;
  line-height: 1.48em;
  padding-bottom: 4px;
  font-family: sans-serif;
  text-decoration: underline var(--main-foreground) !important;
  color: var(--link-foreground);
}

.header > h1 {
  font-size: 1.6em;
  line-height: 1.25em;
  width: 100%;
  margin: 30px 0;
  padding: 0;
}

.header > .credits {
  font-size: 0.9em;
  line-height: 1.48em;
  margin: 0 0 10px;
  padding: 0;
  font-style: italic;
}

.header > .meta-data {
  font-size: 0.65em;
  margin: 0 0 15px;
}

.reader-estimated-time {
  text-align: match-parent;
}

/* Controls toolbar */

.toolbar-container {
  position: sticky;
  z-index: 2;
  top: 32px;
  height: 0; /* take up no space, so body is at the top. */

  /* As a stick container, we're positioned relative to the body. Move us to
   * the edge of the viewport using margins, and take the width of
   * the body padding into account for calculating our width.
   */
  margin-inline-start: calc(-1 * var(--body-padding));
  width: max(var(--body-padding), calc((100% - var(--content-width)) / 2 + var(--body-padding)));
  font-size: var(--font-size); /* Needed to ensure `em` units match, is reset for .reader-controls */
}

.toolbar {
  padding-block: 16px;
  border: 1px solid var(--toolbar-border);
  border-radius: var(--border-radius-small);
  box-shadow: var(--box-shadow-level-4);

  width: 32px; /* basic width, without padding/border */

  /* padding should be 16px, except if there's not enough space for that, in
   * which case use half the available space for padding (=25% on each side).
   * The 34px here is the width + borders. We use a variable because we need
   * to know this size for the margin calculation.
   */
  --inline-padding: min(16px, calc(25% - 0.25 * 34px));
  padding-inline: var(--inline-padding);

  /* Keep a maximum of 96px distance to the body, but center once the margin
   * gets too small. We need to set the start margin, however...
   * To center, we'd want 50% of the container, but we'd subtract half our
   * own width (16px) and half the border (1px) and the inline padding.
   * When the other margin would be 96px, we want 100% - 96px - the complete
   * width of the actual toolbar (34px + 2 * padding)
   */
  margin-inline-start: max(calc(50% - 17px - var(--inline-padding)), calc(100% - 96px - 34px - 2 * var(--inline-padding)));

  font-family: system-ui;
  list-style: none;
  user-select: none;

  /* Set focus outlines to the primary color without having to specify it
   * per each element. */
  accent-color: var(--primary-color);
}

@media (prefers-reduced-motion: no-preference) {
  .toolbar {
    transition-property: border-color, box-shadow;
    transition-duration: 250ms;
  }

  .toolbar .toolbar-button {
    transition-property: opacity;
    transition-duration: 250ms;
  }

  .toolbar-container.scrolled > .toolbar:not(:hover, :focus-within) {
    border-color: var(--toolbar-transparent-border);
    box-shadow: 0 2px 8px transparent;
  }

  .toolbar-container.scrolled > .toolbar:not(:hover, :focus-within) > .reader-controls:not(.dropdown-open) .toolbar-button {
    opacity: var(--opacity-deemphasized);
  }

  .toolbar-container.transition-location {
    transition-duration: 250ms;
    transition-property: width;
  }
}

.toolbar-container.overlaps .toolbar-button {
  opacity: 0.1;
}

.dropdown-open .toolbar {
  border-color: var(--toolbar-transparent-border);
  box-shadow: 0 2px 8px transparent;
}

.reader-controls {
  /* We use `em`s above this node to get it to the right size. However,
   * the UI inside the toolbar should use a fixed, smaller size. */
  font-size: 11px;
}

button {
  -moz-context-properties: fill;
  color: var(--main-foreground);
  fill: var(--icon-fill);
}

button:disabled {
  /* !important to override other uses of `fill` where the specificity there is greater. */
  fill: var(--icon-disabled-fill) !important;
}

.toolbar-button {
  position: relative;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--toolbar-button-border);
  border-radius: var(--border-radius-small);
  margin: 4px 0;
  background-color: var(--toolbar-button-background);
  background-size: 16px 16px;
  background-position: center;
  background-repeat: no-repeat;
}

.toolbar-button:hover {
  background-color: var(--toolbar-button-background-hover);
  border-color: var(--toolbar-button-border-hover);
  fill: var(--toolbar-button-foreground-hover);
}

.open .toolbar-button,
.toolbar-button:hover:active {
  background-color: var(--toolbar-button-background-active);
  color: var(--toolbar-button-foreground-active);
  border-color: var(--toolbar-button-border-active);
  fill: var(--toolbar-button-foreground-active);
}

.toolbar-button:focus-visible {
  outline: 2px solid var(--outline-focus-color);
  outline-offset: 2px;
}

.hover-label {
  position: relative;
  inset-inline-start: 36px;
  line-height: 16px;
  white-space: pre; /* make sure we don't wrap */
  background-color: var(--tooltip-background);
  color: var(--tooltip-foreground);
  padding: 4px 8px;
  border: 1px solid var(--tooltip-border);
  border-radius: var(--border-radius-xsmall);
  visibility: hidden;
  pointer-events: none;
  /* Put above .dropdown .dropdown-popup, which has z-index: 1000. */
  z-index: 1001;
}

/* Show the hover tooltip on non-dropdown buttons. */
.toolbar-button:not(.dropdown-toggle):hover > .hover-label,
.toolbar-button:not(.dropdown-toggle):focus-visible > .hover-label,
/* Show the hover tooltip for dropdown buttons unless its dropdown is open. */
:not(.open) > li > .dropdown-toggle:hover > .hover-label,
:not(.open) > li > .dropdown-toggle:focus-visible > .hover-label {
  visibility: visible;
}

.dropdown {
  text-align: center;
  list-style: none;
  margin: 0;
  padding: 0;
  position: relative;
}

.dropdown li {
  margin: 0;
  padding: 0;
}

/* Popup */

.dropdown .dropdown-popup {
  text-align: start;
  position: absolute;
  inset-inline-start: 32px;
  z-index: 1000;
  background-color: var(--popup-background);
  visibility: hidden;
  border-radius: var(--border-radius-small);
  border: 1px solid var(--popup-border);
  box-shadow: 0 0 10px 0 var(--popup-shadow);
  top: var(--space-xsmall);

  h2 {
    font-size: var(--font-size-large);
    font-weight: var(--font-weight-heading);
    color: var(--popup-foreground);
    margin-block: var(--space-small);
  }

  hr {
    width: 100%;
    display: inline-block;
    margin-block: var(--space-small);
    border: none;
    border-top: 1px solid var(--popup-line);
  }
}

.open > .dropdown-popup {
  visibility: visible;
}

.radio-button {
  /* We visually hide these, but we keep them around so they can be focused
   * and changed by interacting with them via the label, or the keyboard, or
   * assistive technology.
   */
  opacity: 0;
  pointer-events: none;
  position: absolute;
}

.radiorow,
.buttonrow {
  display: flex;
  align-content: center;
  justify-content: center;
}

.buttonrow > button {
  background-repeat: no-repeat;
  background-position: center;
  fill: var(--popup-button-foreground);
}

.buttonrow > button:enabled:hover {
  background-color: var(--popup-button-background-hover);
  fill: var(--popup-button-foreground-hover);
}

.buttonrow > button:enabled:hover:active {
  background-color: var(--popup-button-background-active);
}

.buttonrow > button:enabled:focus-visible {
  outline: 2px solid var(--outline-focus-color);
  outline-offset: -2px;
}

.radiorow > label {
  position: relative;
  box-sizing: border-box;
  border: 2px solid var(--popup-button-border);
}

.radiorow > label[checked] {
  border: 2px solid var(--link-selected-foreground);
}

.radiorow > label:hover {
  background-color: var(--popup-button-background-hover);
  color: var(--popup-button-foreground-hover);
}

.radiorow > input[type="radio"]:focus-visible + label {
  outline: 2px solid var(--primary-color);
  outline-offset: var(--focus-outline-offset);
  z-index: 1;
}

body.hcm .color-scheme-buttons {
  /* Disallow selecting themes when HCM is on. */
  display: none;
}

.color-scheme-buttons > label {
  padding: 12px;
  height: 34px;
  font-size: 12px;
  /* Center the labels horizontally as well as vertically */
  display: inline-flex;
  align-items: center;
  justify-content: center;
  /* We want 10px between items, but there's no margin collapsing in flexbox. */
  margin: 10px 5px;
  border-radius: var(--border-radius-xsmall);
  border-color: var(--popup-border);
}

/* Improved text and layout menu popup */

#text-layout-controls {
  display: flex;
  flex-direction: column;
  width: 340px;
  padding: var(--space-small) var(--space-large);
  max-height: calc(100vh - 7em);
  overflow-y: auto;
  font-size: 15px;
  color: var(--popup-foreground);
}

#text-size-controls {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-block: var(--space-small);
}

.text-size-buttons {
  gap: var(--space-medium);
}

.text-size-buttons > button {
  height: var(--size-item-large);
  width: var(--size-item-large);
  border: 1px solid transparent;
  border-radius: var(--border-radius-small);
  background-color: var(--popup-button-background);

  &.text-size-minus-button {
    background-image: url("chrome://global/skin/icons/minus.svg");
  }

  &.text-size-plus-button {
    background-image: url("chrome://global/skin/icons/plus.svg");
  }

  body.hcm & {
    border-color: var(--popup-button-border);

    &:hover {
      border-color: SelectedItem;

      &:active {
        border-color: ButtonText;
      }
    }
  }
}

#font-controls {
  display: flex;
  justify-content: space-between;
  gap: var(--space-medium);
  padding-block: var(--space-small);
}

.dropdown-selector {
  display: flex;
  flex-direction: column;
  flex: 1;
  max-width: 50%;
  gap: var(--space-xsmall);

  > select {
    appearance: none;
    min-height: var(--button-min-height);
    border: 1px solid transparent;
    border-radius: var(--border-radius-small);
    background-color: var(--popup-button-background);
    color: var(--popup-button-foreground);
    font-size: inherit;
    font-weight: var(--font-weight-semibold);
    padding-inline: var(--space-large) var(--space-xxlarge);
    text-overflow: ellipsis;
    background-image: url("chrome://global/skin/icons/arrow-down.svg");
    background-position: right var(--space-medium) center;
    background-repeat: no-repeat;
    -moz-context-properties: fill;
    fill: currentColor;

    &:hover,
    &:focus-visible {
      background-color: var(--popup-button-background-hover);
      color: var(--popup-button-foreground-hover);

      &:active {
        background-color: var(--popup-button-background-active);
      }
    }

    body.hcm & {
      border-color: var(--popup-button-border);

      &:hover {
        border-color: SelectedItem;
      }

      &:hover:active {
        border-color: ButtonText;
      }
    }

    /* Selector chevron should appear on the left for RTL. */
    &:dir(rtl) {
      background-position-x: left var(--space-medium);
    }
  }
}

.accordion-header {
  list-style: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;

  .chevron-icon {
    background-image: url("chrome://global/skin/icons/arrow-down.svg");
    background-position: center;
    background-repeat: no-repeat;
    -moz-context-properties: fill;
    fill: currentColor;
    height: var(--size-item-large);
    width: var(--size-item-large);
    border: 1px solid transparent;
    border-radius: var(--border-radius-small);

    #about-reader-advanced-layout[open] & {
      background-image: url("chrome://global/skin/icons/arrow-up.svg");
    }

    body.hcm & {
      color: ButtonText;
      border-color: var(--popup-button-border);

      &:hover {
        color: SelectedItem;
        border-color: SelectedItem;
      }

      &:hover:active {
        border-color: ButtonText;
      }
    }
  }
}

.slider-container {
  padding-block: var(--space-small);
}

label[for="text-alignment-buttons"] {
  display: block;
  padding-block-start: var(--space-small);
}

.text-alignment-buttons {
  gap: var(--space-xxsmall);
  padding-block: var(--space-small);

  > label {
    display: flex;
    flex: 1;
    min-height: var(--button-min-height);
    background-repeat: no-repeat;
    background-position: center;
    background-color: var(--popup-button-background);
    -moz-context-properties: fill;
    fill: currentColor;
    border: none;

    /* border radius does not target class because button order
     * can be opposite in RTL */
    &:first-of-type {
      border-start-start-radius: var(--border-radius-small);
      border-end-start-radius: var(--border-radius-small);
    }

    &:last-of-type {
      border-start-end-radius: var(--border-radius-small);
      border-end-end-radius: var(--border-radius-small);
    }

    &.left-align-button {
      background-image: url("chrome://global/skin/reader/align-left-20.svg");
    }

    &.center-align-button {
      background-image: url("chrome://global/skin/reader/align-center-20.svg");
    }

    &.right-align-button {
      background-image: url("chrome://global/skin/reader/align-right-20.svg");
    }

    &.justify-align-button {
      background-image: url("chrome://global/skin/reader/align-justify-20.svg");
    }

    &[checked] {
      background-color: var(--primary-color);
      border: none;
      color: var(--popup-button-selected-foreground);
    }

    body.hcm & {
      border: 1px solid var(--popup-button-border);

      &:hover:not([checked]) {
        border-color: SelectedItem;
      }

      &:hover:active:not([checked]) {
        border-color: ButtonText;
      }
    }
  }
}

/* Colors menu popup */

#color-controls {
  padding-block: var(--space-small);
  width: 400px;
}

#about-reader-colors-menu-header {
  margin-inline: var(--space-large) 0;
}

button-group {
  display: flex;
  font-size: var(--font-size-small);
  padding-block: var(--space-small);
}

button[is="named-deck-button"] {
  background: none;
  color: var(--popup-button-foreground);
  border: 1px var(--popup-button-border);
  border-style: solid none;
  padding: var(--space-small);
  flex-basis: 50%;

  &[selected] {
    color: var(--primary-color);
    border-top: 2px solid var(--primary-color);
  }
}

div[name="customtheme"] {
  padding-inline: var(--space-large);
}

.custom-colors-selection {
  display: flex;
  flex-direction: column;
  gap: var(--space-small);
  padding: var(--space-small) 0;
  list-style-type: none;
  font-size: 15px;
  color: var(--popup-button-foreground);
}

.color-scheme-buttons {
  flex-wrap: wrap;
  padding-block: var(--space-xsmall) var(--space-small);
}

.color-scheme-buttons > label {
  height: var(--size-item-xlarge);
  width: calc(50% - 21px);
  font-size: 15px;
  color: var(--popup-button-foreground);
  border: 1px solid var(--popup-button-border);
  border-radius: var(--border-radius-small);
  /* Center content vertically and justify left horizontally */
  display: inline-flex;
  align-items: center;
  justify-content: start;
  margin: var(--space-xsmall);
}

.color-scheme-buttons > label:before {
  content: "";
  display: inline-block;
  width: 24px;
  height: 24px;
  border-radius: var(--border-radius-circle);
  outline: 1px solid var(--popup-button-border);
  margin-inline: var(--space-medium);
}

.color-scheme-buttons {
  .auto-button:before {
    background: linear-gradient(to right, var(--light-theme-background) 50%, var(--dark-theme-background) 50%);
  }

  .light-button:before {
    background-color: var(--light-theme-background);
  }

  .dark-button:before {
    background-color: var(--dark-theme-background);
  }

  .sepia-button:before {
    background-color: #f4ecd8;
  }

  .contrast-button:before {
    background-color: black;
  }

  .gray-button:before {
    background-color: var(--gray-theme-background);
  }
}

.reset-button {
  background: none;
  border: none;
  color: var(--link-color);
  text-decoration: underline;
  font-size: 15px;
  padding-block: var(--space-small);
  cursor: pointer;

  &.text-layout-reset-button {
    float: inline-end;
  }

  &:hover {
    color: var(--link-color-hover);

    &:active {
      color: var(--link-color-active);
    }
  }
}

/* Toolbar icons */

.close-button {
  background-image: url("chrome://global/skin/icons/close.svg");
}

.text-layout-button {
  background-image: url("chrome://global/skin/reader/RM-Type-Controls-24x24.svg");
}

.colors-button {
  background-image: url("chrome://mozapps/skin/extensions/category-themes.svg");
}

@media print {
  .toolbar {
    display: none !important;
  }
}

/* Article content */

/* Note that any class names from the original article that we want to match on
 * must be added to CLASSES_TO_PRESERVE in ReaderMode.sys.mjs, so that
 * Readability.js doesn't strip them out */

/* Variables in .container are for user customization and should not be replaced with design tokens */
.container {
  margin: 0 auto;
  font-size: var(--font-size);
  max-width: var(--content-width);
  line-height: var(--line-height);
  text-align: var(--text-alignment);
  word-spacing: var(--word-spacing);
  letter-spacing: var(--letter-spacing);
  /* stylelint-disable-next-line stylelint-plugin-mozilla/use-font-weight-tokens */
  font-weight: var(--font-weight);

  .header {
    text-align: var(--text-alignment);
  }
}

pre {
  font-family: monospace;

  .plain-text-doc & {
    font-family: inherit;
  }
}

.moz-reader-content {
  display: none;
  font-size: 1em;
}

@media print {
  .moz-reader-content p,
  .moz-reader-content code,
  .moz-reader-content pre,
  .moz-reader-content blockquote,
  .moz-reader-content ul,
  .moz-reader-content ol,
  .moz-reader-content li,
  .moz-reader-content figure,
  .moz-reader-content .wp-caption {
    margin: 0 0 10px !important;
    padding: 0 !important;
  }
}

.moz-reader-content h1,
.moz-reader-content h2,
.moz-reader-content h3 {
  font-weight: var(--font-weight-bold);
}

.moz-reader-content h1 {
  font-size: 1.6em;
  line-height: 1.25em;
}

.moz-reader-content h2 {
  font-size: 1.2em;
  line-height: 1.51em;
}

.moz-reader-content h3 {
  font-size: 1em;
  line-height: 1.66em;
}

.moz-reader-content a:link {
  text-decoration: underline;
  font-weight: normal;
}

.moz-reader-content a:link,
.moz-reader-content a:link:hover,
.moz-reader-content a:link:active {
  color: var(--link-foreground);
}

.moz-reader-content a:visited {
  color: var(--visited-link-foreground);
}

.moz-reader-content * {
  max-width: 100%;
  height: auto;
}

.moz-reader-content p,
.moz-reader-content p,
.moz-reader-content code,
.moz-reader-content pre,
.moz-reader-content blockquote,
.moz-reader-content ul,
.moz-reader-content ol,
.moz-reader-content li,
.moz-reader-content figure,
.moz-reader-content .wp-caption {
  margin: -10px -10px calc(8px + var(--line-height) * 0.4);
  padding: 10px;
  border-radius: var(--border-radius-small);
}

.moz-reader-content li {
  margin-bottom: 0;
}

.moz-reader-content li > ul,
.moz-reader-content li > ol {
  margin-bottom: -10px;
}

.moz-reader-content p > img:only-child,
.moz-reader-content p > a:only-child > img:only-child,
.moz-reader-content .wp-caption img,
.moz-reader-content figure img {
  display: block;
}

.moz-reader-content img[moz-reader-center] {
  margin-inline: auto;
}

/* Align non-centered images with the text. Margins are unset unless the user makes a text alignment selection. */
/* Does not use logical properties because the margins are tied to text alignment and not text direction. */
.moz-reader-content img:not([moz-reader-center]) {
  margin-left: var(--block-img-margin-left);
  margin-right: var(--block-img-margin-right);
}

.moz-reader-content .caption,
.moz-reader-content .wp-caption-text,
.moz-reader-content figcaption {
  font-size: 0.9em;
  line-height: 1.48em;
  font-style: italic;
}

.moz-reader-content pre {
  white-space: pre-wrap;
}

.moz-reader-content blockquote {
  padding: 0;
  padding-inline-start: 16px;
}

.moz-reader-content ul,
.moz-reader-content ol {
  padding: 0;
}

.moz-reader-content ul {
  padding-inline-start: 30px;
  list-style: disc;
}

.moz-reader-content ol {
  padding-inline-start: 30px;
}

table,
th,
td {
  border: 1px solid currentColor;
  border-collapse: collapse;
  padding: 6px;
  vertical-align: top;
}

table {
  margin: 5px;
}

/* Visually hide (but don't display: none) screen reader elements */
.moz-reader-content .visually-hidden,
.moz-reader-content .visuallyhidden,
.moz-reader-content .sr-only {
  display: inline-block;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  border-width: 0;
}

/* Hide elements with common "hidden" class names */
.moz-reader-content .hidden,
.moz-reader-content .invisible {
  display: none;
}

/* Enforce wordpress and similar emoji/smileys aren't sized to be full-width,
 * see bug 1399616 for context. */
.moz-reader-content img.wp-smiley,
.moz-reader-content img.emoji {
  display: inline-block;
  border-width: 0;
  /* height: auto is implied from `.moz-reader-content *` rule. */
  width: 1em;
  margin: 0 0.07em;
  padding: 0;
}

.reader-show-element {
  display: initial;
}

/* Provide extra spacing for images that may be aided with accompanying element such as <figcaption> */
.moz-reader-block-img:not(:last-child) {
  margin-block-end: 12px;
}

.moz-reader-wide-table {
  overflow-x: auto;
  display: block;
}

pre code {
  background-color: var(--main-background);
  border: 1px solid var(--main-foreground);
  display: block;
  overflow: auto;
}
