.container {
  margin-right: auto;
  margin-left: auto;
  --width: min(calc(100vw - 16px), 1600px);
}

.card {
  position: relative;
  padding: 13px 0;
  margin-bottom: 20px;
  border-radius: 6px;
}

.container > *:not(.google-auto-placed) {
  padding-left: max(calc((100% - var(--width)) / 2 + 8px), env(safe-area-inset-left));
  padding-right: max(calc((100% - var(--width)) / 2 + 8px), env(safe-area-inset-right));
}

/* Text */
p, figure > figcaption {
  margin: 0 0 0.8em;
  word-wrap: break-word;
}

a {
  color: var(--a);
  -webkit-tap-highlight-color: var(--temperature);
  text-decoration: none;

  &:hover:not(.nounderline), &:focus:not(.nounderline) {
    text-decoration: underline;
  }
}

.smallcaps {
  font-variant: small-caps;
}

.allcaps {
  text-transform: uppercase;
}

/* Used for wrap points */
.wrapspan {
  display: inline-block;
}

kbd {
  font-family: unset;
  font-weight: 200;
  margin: 0 2px;
}

samp {
  margin: 0 2px;
}

output {
  font-style: italic;
  margin: 0 2px;
}

hr {
  border: 0;
  height: 0;
  border-top: 1px solid rgba(0, 0, 0, 0.1);
  border-bottom: 1px solid rgba(255, 255, 255, 0.3);

  &.wp-block-separator {
    border-width: 8px;
  }
}

/* Headings */
h2 {
  font-size: 1.75em;
  font-weight: 700;
  color: var(--dg);
  line-height: 1.1;
  margin-top: 8px;
  margin-bottom: 1rem;

  [itemprop="articleBody"] & {
    margin-top: 2rem;
  }
}

h3 {
  font-size: 1.4em;
  margin-top: 1rem;
  margin-bottom: 0.8rem;
  color: var(--dg);
}

h4 {
  font-size: 1.1em;
  margin: 6px 0;
}

h1.inline, h2.inline, h3.inline, h4.inline {
  display: inline;
}

.heading-caption {
  display: block;
  color: var(--g);
}

.h3-caption {
  font-size: 0.8em;
}

.heading-gradient {
  font-weight: bold;
  background: -webkit-linear-gradient(-45deg, var(--from), var(--to));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  color: black;
}

/* Lists */
ul {
  list-style-type: square;
}

.card p, .card figure > figcaption, .card li {
  line-height: 1.7;
}

.card li {
  padding-bottom: 4px;
}

.ul-primary > li {
  font-size: 18px;

  > a {
    display: inline-block;
    margin-bottom: 4px;
  }
}

@media (min-width: 992px) {
  .ul-primary li {
    display: flex;
  }
  .ul-primary > li {
    padding-bottom: 10px;
    padding-top: 10px;
    border-bottom: .05em solid lightgray;
  }
}

/* Posts */
ul.posts {
  list-style: none;
  margin: 0;
  padding: 0;

  li {
    border-bottom: 1px solid #dddddd;
    padding-bottom: 10px;
    padding-top: 10px;
    overflow: hidden;
  }
}

/* Content */
blockquote.wp-block-quote {
  margin-left: 0;
  margin-right: 0;
  padding: 8px 8px 8px 16px;
  border-left: 4px solid #ffeb8e;

  @media (min-width: 992px) {
    margin-left: -20px;
  }

  &.large {
    margin: 8px 0;
    font-size: 1.2em;
    text-align: center;

    q {
      display: block;
      font-size: 1.2em;
    }
  }
}

.borderless-width, .borderless-width.alignfull {
  @media (min-width: 768px) {
    margin: 0 calc((-100vw + var(--width)) / 2);
  }
}

/* Images */
.posts-image {
  max-width: 300px;
  max-height: 100px;

  @media (min-width: 992px) {
    float: left;
    width: 300px;
    height: 125px;
    max-height: none;
    overflow: hidden;
  }

  img {
    max-width: 100%;
    max-height: 100%;

    @media (min-width: 992px) {
      width: 100%;
      max-height: initial;
    }
  }
}

.right-image {
  display: block;
  text-align: center;

  @media (min-width: 992px) {
    float: right;
  }
}

figure {
  margin: 0 0 8px 0;
}

[itemprop="articleBody"] figure > figcaption:not(.post-info) {
  text-align: center;
  font-size: 0.8em;
  color: var(--g);
}

@media (min-width: 992px) {
  div.posts-info {
    margin-left: 320px;
  }
  /* Inline toc table of contents */
  .card.toc {
    float: right;
    z-index: 5;
    margin: -5px -5px 20px 20px;
  }
}

/* Table of contents */
.lwptoc_title {
  text-transform: uppercase;
  font-size: 0.7em;
  color: grey;
  font-weight: unset;
}

.lwptoc_item {
  margin-top: 4px;
}

.lwptoc_items > .lwptoc_itemWrap {
  display: flex;
  flex-wrap: wrap;

  @media (min-width: 1600px) {
    display: unset;
  }

  > .lwptoc_item {
    margin-right: 32px;

    @media (min-width: 1600px) {
      margin-right: unset;
    }
  }
}

.lwptoc_items > .lwptoc_itemWrap > .lwptoc_item {
  margin-top: 8px;
}

.lwptoc_items > .lwptoc_itemWrap > .lwptoc_item .lwptoc_itemWrap .lwptoc_item {
  font-size: 0.9em;
}

.lwptoc_itemWrap .lwptoc_itemWrap {
  margin-left: 16px;
}

/* Item number alignment */
a.lwptoc_item {
  display: flex;
}

.lwptoc_item_number {
  margin-right: 4px;
  font-weight: 500;
}

/* Series */
.series-list {
  display: flex;
  align-items: center;
  flex-wrap: wrap;

  @media (min-width: 1600px) {
    display: unset;
  }

  > * {
    flex-basis: 50%;
    flex-grow: 1;
  }

  p, figure > figcaption {
    margin: 0 0 0.4em;
    line-height: 1.6;

    &:not(.series-title) {
      font-size: 0.9em;
    }
  }

  ol {
    margin: 0;
    font-size: 0.9em;
  }
}

.series-title {
  font-size: 1.1em;

  &::before {
    content: "Post Series";
    text-transform: uppercase;
    display: block;
    font-size: 0.7em;
    color: grey;
  }
}

span[itemprop="datePublished"] {
  color: var(--g);
}

div.posts-info {
  margin-top: 10px;
}

/* Category */
.category-image {
  width: 500px;
  max-width: 100%;
  display: block;
  margin: 10px auto 10px;
}

.card-categories .flex-post.box-aside {
  padding: 5px;
  background: #fbfbfb;
}

/* Post */
.post-header {
  @media (min-width: 992px) {
    --width: min(calc(100vw - 64px), 1600px);
  }

  &, a {
    color: white;
  }

  h1 {
    font-size: 2.6rem;
    margin-bottom: 10px;
    margin-top: 10px;
    font-weight: 800;
  }

  span[itemprop="datePublished"] {
    color: #aaa;
  }

  .flex-image {
    margin: 0 -16px;

    @media (min-width: 768px) {
      margin: 0;
    }
  }

  .wp-post-image {
    margin: 0 auto;
    width: 100%;
    max-width: 480px;
    aspect-ratio: 464 / 200;
  }

  > .flex-post {
    margin: 0 !important;
    padding: 0 0 0.2em !important;

    @media (min-width: 992px) {
      padding: 0 !important;

      > [itemprop="description"] {
        max-width: calc(100% - 120px);
      }

      > .post-info > .post-meta {
        margin: 0 0 -0.2em;
      }
    }
  }
}

/* Ensure if the image is shorter than the post title,
 * there is padding between the info and bottom of background */
.post-info {
  flex-grow: 1;
  flex-basis: 320px;

  @media (min-width: 992px) {
    display: flex;
    flex-direction: column;
  }

  .post-header & {
    align-items: flex-start !important;
  }

  > .post-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;

    .page-header & {
      order: -1;
    }

    > span:not(:first-child) {
      padding-left: 6px;
    }

    &:last-child .page & {
      float: right;
      margin-top: -1em;
      margin-bottom: -100%;
    }
  }

  > [itemprop="description"] {
    line-height: 1.7;
  }
}

img.post-header-image {
  max-width: 100%;
  max-height: 200px;

  @media (min-width: 992px) {
    max-height: 150px;
    max-width: 500px;
    padding-left: 1em;
  }
}

.header img.page-header-image {
  position: absolute;
  width: 24vw;
  margin-top: -3.8vw;
  opacity: 0.5;
  z-index: -1;

  @media (min-width: 992px) {
    position: unset;
    width: 128px;
    float: left;
    margin: 0 1em -32px 0;
    opacity: unset;
  }
}

@media (min-width: 992px) {
  ul.ul-primary-compressed {
    padding: 0 10px;
  }
}

ul.ul-primary-compressed li {
  padding: 3px 0;
  border-bottom: none;
}

ul.ul-primary-compressed-inline li {
  display: inline-block;
  margin-right: 50px;
}

/* Icons */
img[src^="/r/icon/"] {
  height: 1em !important;
  margin-right: 0.2em;
}

[itemprop="articleBody"] img:not(.inline),
[itemprop="articleBody"] video:not(.inline) {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 8px auto;
}

[itemprop="articleBody"] p img, [itemprop="articleBody"] figure > figcaption img {
  display: inline !important;
}

img.inline.inline-super {
  width: 16px;
  vertical-align: super;
  transform: translateX(-2px);
}

.card.card-sideimage > img:first-of-type {
  max-width: 80%;
  margin: 0 auto;
}

@media (min-width: 992px) {
  .card.card-sideimage {
    overflow: hidden;
  }
  .card.card-sideimage > img:first-of-type {
    float: left;
    padding-right: 20px;
  }
}

.card img {
  max-width: 100%;
  height: auto;
}

/* Boxes */
.box-aside {
  background: #f2f2f2;
  border: 1px solid #e3e3e3;

  .flex-image img {
    margin: 10px auto 10px;
    display: block;
  }
}

.box-note {
  background-color: #fff8dc;
  border: 1px solid #e0dcbf;
}

@media (min-width: 992px) {
  .box-toc {
    float: right;
    margin-left: 20px;
    margin-top: 20px;
  }
}

.box-toc ul, .box-toc li {
  padding: 0 !important;
  margin: 0;
}

.box-toc li {
  font-size: 0.9em;
}

@media (max-width: 992px) {
  .box-toc ul {
    margin-left: 15px;
  }
  .ad-inline + .box-note, .ad-inline + .box-aside {
    margin-top: 10px;
  }
}

/* Pieces */
@media (min-width: 1600px) {
  .box-aside-right, .alignright, .lwptoc, .box-aside-left, .alignleft {
    position: absolute;
    width: max-content;
    max-width: calc((100vw - var(--width)) / 2 - 128px);

    &, & * {
      transition: none;
    }

    h3:first-child {
      margin: -4px 0 4px 0;
    }
  }

  .box-aside-left, .alignleft {
    right: calc((100% - var(--width)) / 2 + 8px + var(--width) + 64px);

    &::before {
      display: block;
      content: "";
      position: absolute;
      left: 0;
      right: 0;
      z-index: -1;
      background-color: #f8fafa;
      top: 0;
      bottom: 0;
      background-image: linear-gradient(#f8fafa, color-mix(in srgb, black 2%, #f8fafa));
      top: 0;
      bottom: 0;
    }

    &::before {
      background-color: #f8fafa;
      top: -16px;
      right: -16px;
      bottom: -16px;
      left: -16px;
    }
  }

  .box-aside-right, .alignright, .lwptoc {
    left: calc((100% - var(--width)) / 2 + 8px + var(--width) + 64px);

    &::before {
      display: block;
      content: "";
      position: absolute;
      left: 0;
      right: 0;
      z-index: -1;
      background-color: #f8fafa;
      top: 0;
      bottom: 0;
      background-image: linear-gradient(#f8fafa, color-mix(in srgb, black 2%, #f8fafa));
      top: 0;
      bottom: 0;
    }

    &::before {
      background-color: #f8fafa;
      top: -16px;
      right: -16px;
      bottom: -16px;
      left: -16px;
    }
  }

  .lwptoc {
    top: 16px;
  }

  .alignwide + .lwptoc {
    --width: 904px;
  }
}

.piece-blue {
  &::before {
    display: block;
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    z-index: -1;
    background-color: #d1edff;
    top: -8px;
    bottom: -8px;
    transform: skewY(2deg) translateY(var(--shift));
    background-image: linear-gradient(#d1edff, color-mix(in srgb, black 2%, #d1edff));
    width: 100%;
  }

  position: relative;

  &::after {
    display: block;
    content: " ";
    clear: both;
  }
}

.piece-yellow {
  &::before {
    display: block;
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    z-index: -1;
    background-color: #fbeB9a;
    top: -8px;
    bottom: -8px;
    transform: skewY(2deg) translateY(var(--shift));
    background-image: linear-gradient(#fbeB9a, color-mix(in srgb, black 2%, #fbeB9a));
    width: 100%;
  }

  position: relative;

  &::after {
    display: block;
    content: " ";
    clear: both;
  }
}

/* Highlights */
.note {
  background-color: #fff8dc;
  box-shadow: 0 0 0 4px #fff8dc;
}

.highlight-yellow {
  --hl: #FFFCE8;
  background-color: var(--hl);
  box-shadow: 0 0 0 4px var(--hl);
  padding-left: 2px;
  padding-right: 2px;
  margin-left: 2px;
  margin-right: 2px;

  @media (prefers-color-scheme: dark) {
    --hl: rgba(181, 157.3913043478, 0, 0.52);
  }
}

.highlight-grey {
  --hl: #f2f2f2;
  background-color: var(--hl);
  box-shadow: 0 0 0 4px var(--hl);
  padding-left: 2px;
  padding-right: 2px;
  margin-left: 2px;
  margin-right: 2px;

  @media (prefers-color-scheme: dark) {
    --hl: rgba(89, 89, 89, 0.52);
  }
}

.highlight-blue {
  --hl: #ddfcff;
  background-color: var(--hl);
  box-shadow: 0 0 0 4px var(--hl);
  padding-left: 2px;
  padding-right: 2px;
  margin-left: 2px;
  margin-right: 2px;

  @media (prefers-color-scheme: dark) {
    --hl: rgba(0, 155, 170, 0.52);
  }
}

.highlight-red {
  --hl: #FDF0F0;
  background-color: var(--hl);
  box-shadow: 0 0 0 4px var(--hl);
  padding-left: 2px;
  padding-right: 2px;
  margin-left: 2px;
  margin-right: 2px;

  @media (prefers-color-scheme: dark) {
    --hl: rgba(165, 22, 22, 0.52);
  }
}

.highlight-purple {
  --hl: #F0F0FE;
  background-color: var(--hl);
  box-shadow: 0 0 0 4px var(--hl);
  padding-left: 2px;
  padding-right: 2px;
  margin-left: 2px;
  margin-right: 2px;

  @media (prefers-color-scheme: dark) {
    --hl: rgba(11.75, 11.75, 176.25, 0.52);
  }
}

.highlight-green {
  --hl: #EAFEE7;
  background-color: var(--hl);
  box-shadow: 0 0 0 4px var(--hl);
  padding-left: 2px;
  padding-right: 2px;
  margin-left: 2px;
  margin-right: 2px;

  @media (prefers-color-scheme: dark) {
    --hl: rgba(28.64, 171.84, 7.16, 0.52);
  }
}

del.del-replace {
  text-decoration-color: var(--g);
  -webkit-text-decoration-color: var(--g);
  text-decoration-thickness: 3px;
  -webkit-text-decoration-thickness: 3px;

  &::after {
    content: attr(data-del-replace);
    position: absolute;
    transform: translateX(-70%) translateY(-70%) rotate(4deg);
  }
}

.intention, .intention-error {
  text-decoration: underline;
  text-decoration-style: wavy;
  -webkit-text-decoration-style: wavy;
  text-decoration-color: #FEBE05;
  -webkit-text-decoration-color: #FEBE05;
}

.intention-error {
  text-decoration-color: #FE0402;
  -webkit-text-decoration-color: #FE0402;
}

.badge-yellow,
.badge-blue, .badged-updated::after, .flex-post-is-sticky > .post-info > h2::after,
.badge-green, .badged-new::after, .flex-post-is-new > .post-info > h2::after {
  border-radius: 20px;
  padding: 0.25em 0.8em;
  font-size: 0.9em;
}

.badge-green, .badged-new::after, .flex-post-is-new > .post-info > h2::after {
  background-color: #e4f3c5;
  color: #4f8a32;
}

.badge-blue, .badged-updated::after, .flex-post-is-sticky > .post-info > h2::after {
  background-color: #ECF4FD;
  color: #5D7A9C;
}

.badge-yellow {
  background-color: #f1e5bc;
  color: #9a7909;
}

.badged-new::after, .flex-post-is-new > .post-info > h2::after {
  content: "NEW";
  display: inline-block;
  font-size: 0.7em;
}

.badged-updated::after, .flex-post-is-sticky > .post-info > h2::after {
  content: "UPDATED";
  display: inline-block;
  font-size: 0.7em;
}

* ~ [class*="badge"] {
  margin-left: 8px;
}

.bracketed::after, .bracketed::before {
  font-size: 1.2em;
  color: darkgrey;
}

.bracketed::before {
  content: "[";
}

.bracketed::after {
  content: "]";
}

.cool {
  --temperature: #5E81AC;
  --temperature-a: rgba(94, 129, 172, 0.45);
}

.warm {
  --temperature: #EBCB8B;
  --temperature-a: rgba(235, 203, 139, 0.45);
}

.hot {
  --temperature: #D08770;
  --temperature-a: rgba(208, 135, 112, 0.45);
}

.supernova {
  --temperature: #BF616A;
  --temperature-a: rgba(191, 97, 106, 0.45);
}

/* Post info */
div.box-aside.inline, div.box-note.inline {
  padding: 5px;
}

div.flex-post-info {
  display: flex;
  flex-wrap: wrap;
}

div.flex-post-info > * {
  flex-basis: 200px;
  flex-grow: 1;
}

div.flex-post-info > ul {
  margin: 0;
}

/* Resource indicator for resource posts */
.flex-post.resource h2 a:before {
  content: "resource";
  display: block;
  color: grey;
  font-size: .6em;
  margin: -8px 0 6px 0;
}

dl.definitions dt {
  display: inline;
  font-weight: bold;
}

dl.definitions dd {
  margin-bottom: 8px;
}

/* Video card */
video {
  display: block;
  margin: 0 auto;
}

.card-video {
  padding-bottom: 50%;
}

iframe.video, .card-video video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

/* Image card */
.card-image {
  padding: 0;

  img {
    display: block;
    width: 100%;
    border-radius: 6px 6px 0 0;

    ~ p, ~ figcaption {
      background: #fafafa;
      margin: 0;
      padding: 8px;
      border-top: .5px solid #e1e1e1;
      line-height: 1.4;
      border-radius: 0 0 6px 6px;
      background-clip: padding-box;

      &::after {
        content: "\00a9 George Garside, contact before use";
        display: block;
        text-align: right;
        font-size: .8em;
        color: grey;
      }
    }
  }
}

.flex-post > .post-info > h2::before {
  display: block;
  color: var(--g);
  font-size: 0.5em;
  text-transform: uppercase;
  margin-bottom: 0.7em;
}

/* Interpost navigation */
.interpost {
  display: flex;
  flex-direction: column;
  border-top: 4px solid var(--lg);
  line-height: 1.4;
  contain: content;

  > figure {
    > .flex-image {
      max-width: 320px;
    }

    img {
      max-width: 100%;
    }
  }

  > .flex-post:first-child > .post-info > h2::before {
    content: "Next Post";

    @media (min-width: 768px) {
      text-align: right;
    }
  }

  > .flex-post:last-child > .post-info > h2::before {
    content: "Previous Post";
    text-align: unset;
  }
}

.post-nav-links {
  display: flex;
  align-items: center;
  gap: 8px;

  .post-page-numbers {
    padding: .5rem .75rem;
    border: 1px solid #dee2e6;
    border-radius: 6px;

    &.current {
      background: var(--lg);
      font-weight: bold;
    }

    &:last-child {
      margin-left: auto;
      border: 3px solid;
    }
  }
}

/* Maths */
.maths-fbox {
  --maths-colour: var(--dg);
  color: var(--maths-colour);
  border: 2px solid var(--maths-colour);
  padding: 2px 4px;
}

.maths-shift {
  --maths-colour: rgb(170, 136, 0);
}

.maths-alpha {
  --maths-colour: maroon;
}

/* Code */
pre, code {
  word-wrap: break-word;
}

pre {
  word-wrap: normal;
  overflow-x: scroll;
}
