:root {
  /* Color definitions */
  --color-blue: #050542;

  --color-green: #66e5bf;
  --color-green-negative: #991a40;
  --color-green-oklch: oklch(83.97% 0.126 170.74);
  --color-green-oklch-negative: oklch(44.95% 0.161 10.15);

  --color-purple: #a675f5;
  --color-purple-negative: #598a0a;
  --color-purple-oklch: oklch(66.85% 0.186 298.97);
  --color-purple-oklch-negative: oklch(57.63% 0.153 130.45);

  --color-white: #ffffff;
  --color-yellow: #fffc86;
  --color-yellow-negative: #000379;

  --color-archive: red;

  --gradient-angle: 42deg;

  /* Sizing definitions */
  --rounded: 0.5rem;
  --pilled: 2rem;
  --shadow: -0.15rem 0.15rem var(--color-text);
  --gap: clamp(1rem, calc(100vw / 24 * 0.5), 2rem);
  --nav-padding: 0.3em 0.4em; // try to use gap..
}

/* Light theme */
[data-theme='light'] {
  --color-text: var(--color-blue);

  --color-background: var(--color-white);
  --color-accent: var(--color-blue);
  --color-logo: var(--color-blue);

  --color-nav-text: var(--color-blue);
  --color-nav-background: var(--color-background);
  --color-nav-border: var(--color-blue);

  --color-active: var(--color-yellow);
  --color-active-text: var(--color-blue);
  --svg-filter: invert(4%) sepia(84%) saturate(7069%) hue-rotate(246deg) brightness(64%) contrast(105%);

  --gradient: linear-gradient(var(--gradient-angle), var(--color-purple) 0%, var(--color-green) 100%);

  @media (color-gamut: p3) {
    --gradient: linear-gradient(
      var(--gradient-angle) in oklch,
      var(--color-purple-oklch) 0%,
      var(--color-green-oklch) 100%
    );
  }

  body:not(:has(span.version.latest)) {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='600px' height='800px'><text x='0' y='500' text-anchor='middle' transform='rotate(-45)' fill='WhiteSmoke' font-family='Open Sans' font-size='200'>Archief</text></svg>");
    background-repeat: repeat-y;
    background-position: center;
  }
}
[data-theme='dark'] {
  --color-text: var(--color-white);
  --color-background: var(--color-blue);
  --color-accent: var(--color-white);
  --color-logo: var(--color-white);

  --color-nav-text: var(--color-white);
  --color-nav-background: var(--color-background);
  --color-nav-border: var(--color-white);

  --color-active: var(--color-yellow);
  --color-active-text: var(--color-blue);
  --svg-filter: invert(92%) sepia(93%) saturate(32%) hue-rotate(252deg) brightness(105%) contrast(100%);

  --gradient: linear-gradient(var(--gradient-angle), var(--color-purple-negative) 0%, var(--color-green-negative) 100%);

  @media (color-gamut: p3) {
    --gradient: linear-gradient(
      var(--gradient-angle) in oklch,
      var(--color-purple-oklch-negative) 0%,
      var(--color-green-oklch-negative) 100%
    );
  }

  body:not(:has(span.version.latest)) {
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='600px' height='800px'><text x='0' y='500' text-anchor='middle' transform='rotate(-45)' fill='MidnightBlue' font-family='Open Sans' font-size='200'>Archief</text></svg>");
    background-repeat: repeat-y;
    background-position: center;
  }
}

*,
*:before,
*:after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

.visually-hidden {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  width: 1px;
  height: 1px;
  overflow: hidden;
  position: absolute;
  white-space: nowrap;
}

html {
  height: 100%;
  scroll-behavior: smooth;

  @media (prefers-reduced-motion) {
    scroll-behavior: auto;
  }
}

body {
  background: var(--color-background);
  font-family: Open Sans, sans-serif;
  color: var(--color-text);
  min-height: 100vh;
  container-type: inline-size;
}

/* Main Layout */
body {
  display: grid;
  gap: var(--gap);
  grid-template-rows: min-content auto min-content;
  grid-template-areas:
    'header'
    'main'
    'footer';

  @media (min-width: 35rem) {
    & {
      grid-template-columns: 10rem auto;
      grid-template-areas:
        'header header'
        'main main'
        '. footer';
    }
  }

  @media (min-width: 42rem) {
    & {
      grid-template-columns: 15rem auto;
    }
  }

  /* Block placement */
  & header {
    grid-area: header;
    position: sticky;
    top: 0;
  }

  & main {
    position: relative;
    grid-area: main;

    & > nav {
      grid-area: subnav;
      display: none;
    }

    & > article {
      grid-area: article;
      padding-right: var(--gap);
    }

    @media (min-width: 35rem) {
      & {
        display: grid;
        grid-template-columns: subgrid;
        grid-template-areas: 'subnav article';
      }
      & > nav.subnav {
        display: block;
      }
    }
  }

  & footer {
    grid-area: footer;
  }
}

/* Logo, main nav and settings (header) */
header {
  display: flex;
  position: relative;
  justify-content: space-between;
  gap: var(--gap);
  padding: var(--gap);
  background: var(--color-background);
  z-index: 98;

  /* Version */
  span.version {
    position: absolute;
    bottom: 0;
    font-size: 0.7rem;
    cursor: normal;
  }
  /* Logo and page-title */
  & a {
    text-decoration: none;
    color: currentColor;

    & h1 {
      position: relative;
      margin: 0;
      padding: 0;
      font-size: 1rem;
      white-space: nowrap;

      & abbr {
        text-decoration: none;

        & span {
          position: relative;
          display: inline-block;
          background-color: var(--color-background);
          background-image: var(--gradient);
          padding: 0.3em 0.4em;
          border: 1px solid var(--color-text);
          border-radius: var(--rounded);
          box-shadow: var(--shadow);
          z-index: 1;
        }
      }
    }
  }

  /* Breadcrumb / dropdown */
  & nav {
    flex-grow: 1;

    & ul {
      list-style: none;
      margin: 0;
      padding: 0;
      display: grid;
    }

    & > ul {
      display: flex;
      width: 100%;
      justify-content: flex-start;

      & > li {
        &.delimiter {
          padding: var(--nav-padding);
        }

        & .dropdown__title {
          display: flex;
          flex-flow: row nowrap;
          padding: var(--nav-padding);
          border: 0;
          border-radius: var(--rounded);
          color: var(--color-nav-text);
          background: var(--color-nav-background);
          font-size: 1rem;
          font-family: inherit;

          & span {
            display: block;
            text-align: left;
            overflow: hidden;
            min-width: 0;
            text-overflow: ellipsis;
            height: 1lh;
            text-wrap: nowrap;
          }

          &#paragraph-button {
            & span {
              text-wrap: wrap;
            }
          }
        }
      }
    }
  }

  & .dropdown {
    position: relative;

    & .dropdown__menu {
      background: var(--color-nav-background);
      border: 1px solid var(--color-nav-border);
      border-radius: var(--rounded);
      box-shadow: var(--shadow);
      padding: var(--nav-padding);
      min-width: 100%;

      /* Centered below button */
      position: absolute;
      top: 100%;
      left: 50%;
      transform: translateX(-50%);

      /* Hide by default */
      transform: rotateX(-90deg) translateX(-50%);
      transform-origin: top center;
      opacity: 0.3;
      transition: 200ms all 120ms ease-out;
      z-index: 99;

      & a {
        display: block;
        padding: var(--nav-padding);
        text-decoration: none;
        color: var(--color-text);

        &:hover {
          text-decoration: underline;
        }
      }
    }

    &:hover,
    &:focus-within {
      .dropdown__menu {
        opacity: 1;
        transform: rotateX(0) translateX(-50%);
        visibility: visible;
      }
    }

    & .dropdown__title {
      display: inline-flex;
      align-items: center;

      &:after {
        content: '';
        border: 0.25rem solid transparent;
        border-top-color: var(--color-text);
        opacity: 0.45;
        margin-left: 0.25rem;
        transform: translateY(0.25em);
      }
    }
  }

  /* Settings panel */
  .settings {
    display: none;
  }
  @media (min-width: 32rem) {
    .settings {
      display: grid;
      gap: calc(var(--gap) / 4);
      place-items: center;
      grid-auto-flow: column;

      & button {
        position: relative;
        width: 2.5rem;
        background: var(--color-background);
        border: 1px solid var(--color-text);
        border-radius: var(--pilled);
        cursor: pointer;
        touch-action: manipulation;
        -webkit-tap-highlight-color: transparent;
        outline-offset: 5px;

        & span {
          position: absolute;
          display: block;
          text-align: center;
          width: 100%;
          font-size: 0.5rem;
          bottom: -0.8rem;
          color: var(--color-text);
        }

        &:before {
          content: '';
          display: grid;
          place-content: center;
          width: 1rem;
          height: 1rem;
          margin: 0.2rem;
          color: var(--color-background);
          font-size: 0.6rem;

          background: var(--color-text);
          border: 1px solid var(--color-text);
          border-radius: var(--pilled);
          float: left;
        }
      }
      & [aria-label='dark'] {
        &:before {
          content: 'D';
          float: left;
        }
      }
      & [aria-label='light'] {
        background: var(--color-active);

        &:before {
          content: 'L';
          float: right;
        }
      }
      & [aria-label='false'] {
        &:before {
          content: '';
          float: left;
        }
      }
      & [aria-label='true'] {
        background: var(--color-active);

        &:before {
          content: '1';
          float: right;
        }
      }

      & :disabled {
        opacity: 0.4;
        cursor: not-allowed;

        &:before {
        }
      }
    }
  }
}

/* Wijzigingen (changes) invisible */
[data-changes='false'] {
  & del {
    display: none;
  }
  & h2,
  & h3,
  & h4,
  & h5,
  & h6,
  & li {
    &:has(del) {
      display: none;
    }
  }
}

/* Discussies (discussion) invisible */
[data-discussion='false'] {
  section:has(.icon-discussion) {
    border-right-color: transparent;
  }
  & a.discussion-link {
    display: none;
  }
  section aside {
    display: none;
  }
}

/* Subnav / table of contents (in main) */
nav.subnav {
  position: sticky;
  top: calc(var(--gap) * 5);
  height: fit-content;
  max-height: calc(100vh - (var(--gap) * 6));
  padding-left: calc(var(--gap) / 2);
  font-size: 0.9rem;
  overflow: auto;

  & ol {
    list-style: none;
  }
  & li {
    line-height: 1.2rem;

    & a {
      display: block;
      text-decoration: none;

      &:hover,
      &:focus-within {
        text-decoration: underline;
      }
      &.active {
        background: var(--color-active);
        color: var(--color-active-text);
      }
    }
  }

  & .toc-link {
    display: block;
    width: 100%;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    padding: var(--nav-padding);
    text-decoration: none;
  }
  & .toc-link-h2 {
    margin-top: 1em;
  }
  & .toc-link-h3 {
    margin-top: 0.5em;
  }
  & .toc-link-h2,
  & .toc-link-h3 {
    font-weight: bold;
  }
  & .toc-level-4 {
    font-size: 0.9em;
  }

  & .toc-level-4 li a {
    position: relative;
    padding-left: 1.5rem;
  }
  & .toc-level-4 a::before {
    content: '~';
    position: absolute;
    top: 0.25rem;
    left: 0.5rem;
  }
}

/* Footer */
footer {
  grid-area: footer;
  margin-top: calc(var(--gap) * 3);

  & h2 {
    /* Same as main > h5 */
    line-height: 1.1;
    font-size: 1.777rem;
  }

  & a.github {
    display: inline-block;
    margin: var(--gap) 0;
    padding: var(--nav-padding);
    border-radius: var(--rounded);
    border: 1px solid var(--color-text);
    text-decoration: none;
    box-shadow: var(--shadow);

    &:hover {
      color: var(--color-blue);
      background: var(--color-yellow);
    }
  }

  & p.copy {
    margin-bottom: var(--gap);
  }
}

/* DOCUMENT TEXT ITEMS */

/* Section headings specific styling */
section {
  position: relative;
  border-right-width: 1px;
  border-right-style: solid;
  border-right-color: transparent;
  max-width: 34rem;

  & h2 {
    margin-bottom: 0.5em;
  }

  & h2,
  & h3,
  & h4,
  & h5,
  & h6 {
    text-wrap: balance;
    scroll-margin-top: calc(var(--gap) * 4);

    & a:first-of-type {
      text-decoration: none;

      &:hover,
      &:focus {
        text-decoration: underline;
      }
      &:after {
        content: '';
        display: inline-block;
        margin-left: 0;
        width: 0.6em;
        height: 0.6em;
        line-height: 1em;
        background-repeat: none;
        background-size: contain;
        background-image: url('../img/link.svg');
        filter: var(--svg-filter);
        position: absolute;
        left: -1.25rem;
        top: 0.35em;
        right: auto;
      }
    }

    /* Discussions (if visible) */
    & a.discussion-link {
      position: absolute;
      top: -0.2rem;
      right: -0.7rem;
      line-height: 1.2rem;

      & .icon {
        display: inline-block;
        width: 1.2rem;
        height: 1.2rem;
        background: var(--color-background);
        border-radius: var(--rounded);

        &::before {
          display: block;
          content: '';
          width: 100%;
          height: 100%;
          background-repeat: none;
          background-size: contain;
          filter: var(--svg-filter);
        }
      }
      & .icon-discussion::before {
        background-image: url('../img/message-exclamation.svg');
      }
      & .icon-new-discussion::before {
        background-image: url('../img/message-plus.svg');
      }
    }
  }
  &:has(.icon-discussion) {
    border-right-color: var(--color-text);
  }
  &:has(.icon-discussion:hover),
  &:has(.icon-discussion:focus),
  &:has(.icon-new-discussion:hover),
  &:has(.icon-new-discussion:focus) {
    background: var(--color-active);
    color: var(--color-active-text);
    border-right-color: var(--color-active-text);

    & a:after {
      filter: none !important;
    }
  }
}

@container (max-width: 540px) {
  section *:first-child a:first-of-type:after {
    left: auto;
    right: -0.75rem;
    width: 0.5em;
    height: 0.5em;
    top: 1.65rem;
  }
}

/* Discussion content */
section aside.discussion {
  position: relative;
  font-size: 0.9rem;
  margin: var(--gap) 0;
  padding: var(--nav-padding);
  border-radius: var(--rounded);
  background: #c2c2c2c2;

  & span {
    display: block;
    clear: both;
    &:first-of-type {
      font-weight: bold;
      &:before {
        content: 'Discussie gestart door ';
      }
    }
    &:last-of-type {
      text-align: right;
    }
  }
  /* large screens? */
  @media (min-width: 52rem) {
    /* float: right; */
    /* clear: right; */
    /* margin-left: calc(100% + var(--gap)); */
    /* top: 0; */

    /* max-width: 100%; */
  }
}

main section:first-of-type {
  & p {
    font-size: 1.1rem;
    font-weight: 600;
    & + p {
      font-size: 1rem;
      font-weight: 400;
    }
  }
}

section {
  padding: 0 calc(var(--gap) / 2);

  & p {
    line-height: 1.5;
  }
}

section + section {
  & > h2,
  & > h3 {
    margin-top: 0.75em;
  }

  & > h4,
  & > h5,
  & > h6 {
    margin-top: 1em;
  }
}

main a,
footer a {
  color: currentColor;
  white-space: inherit;

  &:not(.discussion-link) {
    &[href^='http://']:after,
    &[href^='https://']:after,
    &[href$='.pdf']:after,
    &[href$='.doc']:after,
    &[href$='.zip']:after,
    &[href$='.rar']:after,
    &[href$='.tar']:after {
      content: '';
      margin: 0 0 -0.1em 0.1em;
      display: inline-block;
      line-height: 1em;
      font-size: 0.8em;
      width: 1em;
      height: 1em;
      background: url('../img/link-external.svg') no-repeat 100% 0;
      background-size: contain;
      filter: var(--svg-filter);
    }
    &[href^='http://']:after,
    &[href^='https://']:after
    {
      background: url('../img/link-external.svg') no-repeat 100% 0;
    }
    &[href$='.pdf']:after,
    &[href$='.doc']:after {
      background: url('../img/file-text.svg') no-repeat 100% 0;
    }
    &[href$='.zip']:after,
    &[href$='.rar']:after,
    &[href$='.tar']:after {
      background: url('../img/file-zip.svg') no-repeat 100% 0;
    }
  }
}

h1,
h2,
h3,
h4,
h5,
h6 {
  & + p,
  & + ul,
  & + ol,
  & + blockquote,
  & + table {
    margin-top: 1em;
  }
}

blockquote {
  position: relative;
  margin-left: 1em;

  &::before {
    position: absolute;
    inset: 0.2em 0 0.2em -1em;
    background: currentColor;
    content: '';
    width: 0.3em;
    border-radius: 2px;
    opacity: 0.3;
  }
}

p,
blockquote,
ul,
ol,
table {
  & + h1,
  & + h2,
  & + h3,
  & + h4,
  & + h5,
  & + h6,
  & + p,
  & + ul,
  & + ol,
  & + blockquote,
  & + table {
    margin-top: 1em;
  }
}

h2,
h3,
h4,
h5,
h6 {
  line-height: 1em;
  font-weight: bold;
  overflow-wrap: break-word;
}

h2 {
  font-size: 3rem;
  letter-spacing: -0.04em;
}

h3 {
  font-size: 2.5rem;
  line-height: 1.1;
  letter-spacing: -0.04em;
}

h4 {
  font-size: 2rem;
  line-height: 1.1;
  letter-spacing: -0.04em;
}

h5 {
  line-height: 1.1;
  font-size: 1.777rem;
}

h6 {
  line-height: 1.1;
  font-size: 1.333rem;
}

small,
sup,
sub {
  font-size: 0.75rem;
}

blockquote {
  margin-left: 1rem;
  font-style: italic;
}

img {
  border-radius: var(--rounded);
  max-width: 100%;
}
article {
  & ul {
    list-style: disc;
    padding-left: 1rem;

    & li + li {
      margin-top: 0.4em;
    }
  }

  & ol {
    list-style: decimal;
    padding-left: 1rem;

    & li + li {
      margin-top: 0.4em;
    }
  }
}

pre {
  padding: var(--gap);
}

table {
  margin-bottom: 1rem;
}

table,
tbody,
th,
td,
tr,
caption {
  display: block;
  text-align: left;
}

tr,
caption {
  margin-bottom: 0.625em;
}

caption {
  display: block;
  font-size: 0.75em;
  font-style: italic;
}

thead {
  display: block;
  border: none;
  clip: rect(0 0 0 0);
  height: 1px;
  margin: -1px;
  overflow: hidden;
  padding: 0;
  position: absolute;
  width: 1px;
}

tbody {
  border: 1px solid var(--color-accent);
  padding: var(--nav-padding);
}

sup {
}

sub {
}

section.footnotes p {
  display: inline;
}

img {
  border-radius: var(--rounded);
  max-width: 100%;
}
