:root {
  --max-body-width: 48rem;
}

html {
  height: 100%;
  line-height: 1.4;
}

h1,
h2,
h3 {
  line-height: 1.15;
}

body {
  display: flex;
  flex-direction: column;
  width: calc(100% - 1rem);
  max-width: var(--max-body-width);
  min-height: 100%;
  margin: 0 auto;
  overflow-wrap: break-word;
}

main {
  flex-grow: 1;
}

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

table {
  display: block;
  overflow-x: auto;
}

pre {
  padding: 1rem;

  /* stylelint-disable declaration-no-important -- Prism hack */
  margin-top: 1rem !important;
  margin-bottom: 1rem !important;
  /* stylelint-enable */
  overflow-x: auto;
  line-height: 1.15;
}

code {
  padding: 0.25rem;
}

pre code {
  padding: unset;
}

kbd {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.5rem;
  max-width: calc(100% - 0.1rem * 2);
  min-height: 1.5rem;
  padding: 0 0.25rem;
  margin: 0 0.1rem;
  overflow: hidden;
}

kbd kbd {
  min-width: unset;
  min-height: unset;
  padding: 0;
  margin: 0;
}

kbd kbd:not(:first-child) {
  padding-left: 0.25rem;
}

kbd kbd:not(:last-child) {
  padding-right: 0.25rem;
}

iframe {
  width: 100%;
  border: none;
}

dialog {
  max-height: calc(100% - 1rem);
  overflow-y: auto;
  border: none;
}

audio,
video,
embed,
object {
  width: 100%;
}

[type="range"],
meter,
progress {
  display: block;
  width: 100%;
  height: 2.25rem;
}

[type="color"] {
  height: 2.25rem;
  vertical-align: top;
}

td,
th,
details,
button,
[type="button"],
[type="reset"],
[type="submit"] {
  padding: 0.5rem;
}

input:not([type]),
[type="email"],
[type="hidden"],
[type="number"],
[type="password"],
[type="search"],
[type="tel"],
[type="text"],
[type="url"] {
  display: block;
  width: 100%;
  height: 2.25rem;
  padding: 0.5rem;
}

[type="file"] {
  display: block;
  width: 100%;
  height: 2.25rem;

  /* Works in Chrome (but poorly), doesn't work in Firefox */
  padding-top: 0.35rem;
}

[type="date"],
[type="datetime-local"],
[type="time"],
[type="month"],
[type="week"] {
  display: block;
  width: 100%;
  height: 2.25rem;

  /* 0.4rem is a hack for mobile Chrome */
  padding: 0.4rem 0.5rem;
}

output {
  display: block;
  width: 100%;
}

textarea {
  display: block;
  width: 100%;
  min-height: 8em;
  padding: 0.5rem;
}

select {
  display: block;
  width: 100%;
  min-height: 2.25rem;

  /* "padding: 0.5rem;" messes up the height of selects */
  padding: 0.45rem 0.5rem;
}

summary {
  padding: 0.5rem;
  margin: -0.5rem;
}

[type="image"] {
  vertical-align: bottom;
}

fieldset {
  padding: 0.75rem;
}

label > [type="color"] {
  margin-left: 0.25rem;
}

label {
  display: flex;
  flex-wrap: wrap;
  column-gap: 0.25rem;
  align-items: center;
  width: 100%;
  margin-top: 1rem;
}

legend + label {
  margin-top: 0;
}

[type="checkbox"] + label,
[type="radio"] + label {
  display: inline-flex;
  width: unset;
  vertical-align: text-bottom;
}

/* stylelint-disable-next-line plugin/stylelint-group-selectors -- conflicts
with no-descending-specificity */
blockquote > p:first-child,
fieldset > label:first-child {
  margin-top: 0;
}

label > [type="checkbox"],
label > [type="radio"] {
  min-height: 1rem;
}

blockquote {
  padding: 1rem 2rem;
  margin-right: 0;
  margin-left: 0;
}

blockquote > p:last-child {
  margin-bottom: 0;
}

footer {
  margin-top: 1rem;
}

figure > figcaption,
body > header {
  text-align: center;
}

body > footer {
  padding-bottom: 1rem;
  text-align: center;
}

figure {
  margin-right: 0;
  margin-left: 0;
  text-align: center;
}

figure > * {
  text-align: initial;
}

dt,
[aria-current="page"],
[aria-current="step"],
[aria-current="location"],
[aria-current="date"],
[aria-current="time"],
[aria-current="true"] {
  font-weight: bold;
}

dd {
  margin-bottom: 1rem;
}

li {
  margin-top: 0.5rem;
  margin-bottom: 0.5rem;
}

picture {
  position: relative;
  left: calc(-50vw + 50%);
  display: block;
  width: 100vw;
  max-height: 100vh;
  text-align: center;
}

/* highlight.js hack */
.hljs {
  /* stylelint-disable-next-line declaration-no-important -- highlight.js hack */
  padding: 1rem !important;
  margin: -1rem;
}

@media (width <= 50rem) {
  table {
    width: calc(100% + 1rem);
    margin-left: -0.5rem;
  }

  video {
    width: calc(100% + 1rem);
    max-height: 100vh;
    margin-left: -0.5rem;
  }

  pre {
    width: calc(100% + 1rem);

    /* stylelint-disable declaration-no-important -- Prism hack */
    padding-right: 0.5rem !important;
    padding-left: 0.5rem !important;
    margin-left: -0.5rem !important;
    /* stylelint-enable */
  }

  /* highlight.js hack */
  .hljs {
    /* stylelint-disable declaration-no-important -- highlight.js hack */
    padding-right: 0.5rem !important;
    padding-left: 0.5rem !important;
    /* stylelint-enable */

    margin: -1rem -0.5rem;
  }
}
