@font-face {
  font-family: "Besley";
  font-stretch: 75% 100%;
  font-style: normal;
  font-weight: 400 900;
  src: url(/fonts/Besley-Variable.woff2) format(woff2) tech(variations);
}

@font-face {
  font-family: "Besley";
  font-stretch: 75% 100%;
  font-style: italic;
  font-weight: 400 900;
  src: url(/fonts/Besley-Italic-Variable.woff2) format(woff2) tech(variations);
}

:root {
  color-scheme: light dark;
  --base-light: oklch(0.98 0.015 215);
  --base-dark: oklch(0.35 0.035 215);
  --base-bg: light-dark(var(--base-light), var(--base-dark));
  --base-fg: light-dark(var(--base-dark), var(--base-light));
  --contrast-light: oklch(0.88 0.075 215);
  --contrast-dark: oklch(0.45 0.075 215);
  --contrast-bg: light-dark(var(--contrast-light), var(--contrast-dark));
  --contrast-fg: light-dark(var(--contrast-dark), var(--contrast-light));
  --font-text: "Besley", serif;
  --font-mono: monospace;

  --main-width: 538px;
  --side-width: 200px;
  --side-gap: 20px;

  counter-reset: side-note;

  accent-color: var(--contrast-fg);

  @media print {
    color-scheme: light;
    --base-light: white;
    --base-dark: black;
    --base-bg: light-dark(var(--base-light), var(--base-dark));
    --base-fg: light-dark(var(--base-dark), var(--base-light));
    --contrast-light: oklch(0.88 0 215);
    --contrast-dark: oklch(0.45 0 215);
  }
}

* {
  box-sizing: border-box;
}

body {
  background: var(--base-bg);
  color: var(--base-fg);
  font-family: var(--font-text);
}

header {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: center;
  width: 100%;

  nav {
    align-items: center;
    display: flex;
    gap: 8px;
    justify-content: center;
  }

  img {
    flex: 0 1 172px;
    max-height: 200px;
    min-width: 2em;
  }

  h1 {
    flex: 1 0 min-content;
    max-width: max-content;
  }
}

footer {
  align-items: center;
  display: flex;
  flex-direction: column;
  font-size: 0.8em;
  justify-content: center;
  margin: 20px auto 0;
  max-width: var(--main-width);
  width: 100%;

  > p {
    margin-top: 0;
  }
}

main,
article {
  margin: 0 auto;
  /* max-width: 472px; */
  max-width: var(--main-width);

  &.wide {
    max-width: 1170px;
  }
}

[role="note"] {
  float: right;
  clear: right;
  border-left: 0.7px dashed var(--base-fg);
  font-size: 0.8em;
  font-stretch: 95%;
  /* font-style: oblique; */
  margin-block: 1em;
  padding-left: 1em;
  width: 100%;
}

.footnote-marker {
  &::before {
    counter-increment: side-note;
    content: counter(side-note);
    font-variant-position: super;
    color: var(--contrast-fg);
  }

  & + [role="note"] {
    &::before {
      content: counter(side-note, decimal) "\2004·\2004";
      color: var(--contrast-fg);
    }
  }
}

[role="note"],
small {
  font-size: 0.8em;

  .equation {
    zoom: 0.8;
  }
}

[role="note"] small .equation {
  zoom: calc(0.8 * 0.8);
}

.badges,
.equation.block,
n-code,
pre {
  clear: right;
}

img {
  max-width: 100%;
}

.john {
  max-height: 90px;
  max-width: 100%;
  width: 728px;

  iframe {
    border: none;
    height: 100%;
    max-height: 90px;
    width: 100%;
  }
}

@media (width >= 800px) {
  article:has([role="note"]:not(.inline-note)) {
    /* grid-template-columns: var(--main-width) var(--side-width);
    column-gap: var(--side-gap); */
    max-width: calc(var(--main-width) + var(--side-gap) + var(--side-width));
    padding-left: 0px;
    padding-right: calc(var(--side-gap) + var(--side-width));

    [role="note"]:not(.inline-note) {
      width: var(--side-width);
      margin: 0;
      margin-right: calc(0px - var(--side-gap) - var(--side-width));
      border: none;
      margin-bottom: var(--side-gap);
      text-wrap-style: balance;

      &.wide {
        width: calc(2 * var(--side-width));
      }
    }

    .john {
      max-width: calc(var(--main-width) + var(--side-gap) + var(--side-width));
      margin-right: calc(0px - var(--side-gap) - var(--side-width));
    }
  }

  .badges,
  .equation.block,
  n-code,
  pre {
    clear: none;
  }
}

@media (width >= 1020px) {
  article:has([role="note"]:not(.inline-note)) {
    /* grid-template-columns: var(--main-width) var(--side-width);
    column-gap: var(--side-gap); */
    max-width: calc(var(--main-width) + 2 * var(--side-gap) + 2 * var(--side-width));
    padding-left: calc(var(--side-gap) + var(--side-width));
    padding-right: calc(var(--side-gap) + var(--side-width));

    &.wide {
      max-width: calc(90px + var(--main-width) + 2 * var(--side-gap) + 2 * var(--side-width));
    }
  }
}

@media (width >= 1200px) {
  article:has([role="note"]:not(.inline-note)) {
    &.wide {
      max-width: calc(180px + var(--main-width) + 2 * var(--side-gap) + 2 * var(--side-width));
    }
  }
}

h1,
h2,
h3 {
  font-stretch: 85%;
  font-weight: 800;
  line-height: 1;
  margin: 1em 0 0.25em;
}

h1 {
  font-size: 2em;
}

h2 {
  font-size: 1.5em;
}

h3 {
  font-size: 1em;
}

h4 {
  font-size: 1em;
  font-weight: 500;
  font-variant-caps: small-caps;
  line-height: 1;
  margin: 1em 0 0.25em;
}

h5,
h6 {
  display: inline;
  font-variant-caps: small-caps;
  line-height: 1;
  margin: 1em 0 0.25em;
}

p,
ul,
ol,
pre,
hr,
n-code,
figure,
.badges,
.equation.block {
  margin-block: 0.5em;
  margin-inline: 0;
}

hgroup {
  h1 {
    margin-bottom: 0;
  }

  .subtitle {
    font-size: unset;
    font-stretch: 85%;
  }

  p:not(:last-child) {
    margin-bottom: 0;
  }

  p {
    margin-top: 0;
    font-size: 0.8em;
  }
}

code,
n-code,
pre {
  background: var(--contrast-bg);
  font-family: var(--font-mono);
  padding: 2px;
}

n-code,
pre {
  display: block;
  font-size: 0.8em;
  max-width: 100%;
  position: relative;
  white-space: pre;

  & > code {
    display: block;
    overflow-x: auto;
  }

  & > button {
    background: oklch(from var(--base-fg) l c h / 50%);
    border: none;
    color: var(--contrast-bg);
    font-family: var(--font-text);
    font-size: 0.8rem;
    font-stretch: 75%;
    font-weight: 600;
    padding: 0 2px;
    position: absolute;
    right: 2px;
    width: 42px;

    /* 540px + 2 * 46px */
    @media (min-width: 632px) {
      color: var(--base-bg);
      right: calc(-44px);
      top: 0px;
    }
  }

  code,
  pre {
    background: none;
    padding: 0;
  }
}

pre {
  overflow-x: auto;
}

embed {
  display: block;
  min-height: 200px;
  width: 100%;
}

hr {
  border: none;
  border-bottom: 0.7px dashed var(--base-fg);
}

.equation.block {
  display: block;
  margin-inline: auto;
}

a {
  color: var(--contrast-fg);
  text-decoration: none;

  &:hover {
    text-decoration: underline;
  }

  &[href^="http"]:not(.badge, .no-arrow):not([href*="nleanba.ch"]):not(:has(img:only-child))::after,
  &.arrow::after {
    /* color: var(--base-fg); */
    content: "☛";
    padding-inline: 2px;
    font-size: 0.8em;
    vertical-align: super;
  }

  @media (prefers-contrast: more) {
    text-decoration: underline;
  }
  @media print {
    text-decoration: underline;
  }
}

button {
  &:hover {
    filter: opacity(85%) contrast(75%);
  }
}

.index {
  list-style: none;
  padding-inline: 0;

  li {
    display: grid;
    grid-template: auto / auto auto 1fr;

    &:not(:has(.date)) {
      list-style: "– " inside;
      display: list-item;
    }

    .date {
      color: inherit;
      font-stretch: 85%;
      font-variant-numeric: tabular-nums;
      /* text-decoration: none; */
    }

    .subtitle {
      font-size: 0.8em;
      font-stretch: 85%;
      margin-left: 0.8em;
    }

    & > .date:first-child::after {
      content: "–";
      margin-inline: 4px;
      text-decoration: none;
    }
  }
}

.navrow {
  ul {
    display: flex;
    flex-flow: row wrap;
    gap: 2px 0px;
    list-style: none;
    margin: 0;
    padding: 0;

    a:not(:has(img)) {
      border: 1px solid var(--base-dark);
      border-radius: 0 8px 8px 0;
      color: var(--base-dark);
      display: block;
      font-size: 14px;
      font-stretch: 85%;
      height: 31px;
      line-height: 21px;
      padding: 3px 10px 3px 7px;
      border-image: url(/img/badge-border.png) 6 fill / 6px stretch;
    }

    * {
      display: block;
      flex: 0 0 auto;
    }
  }
}

.badges {
  display: grid;
  font-stretch: 85%;
  font-weight: 500;
  gap: 2px;
  grid: auto-flow 31px / repeat(auto-fill, 88px);
  margin-inline: auto;
  width: calc(round(down, calc(100% + 2px), 90px) - 2px);

  a {
    align-items: center;
    display: flex;
    font-size: 11px;
    line-height: 11px;
    justify-content: center;
    word-break: break-word;
  }

  form {
    display: grid;
    grid-template-columns: 1fr auto;

    input,
    button {
      min-width: unset;
      width: unset;
    }

    label {
      display: none;
    }
  }
}

.image-grid {
  display: grid;
  gap: 8px;
  grid: auto-flow dense 100px / repeat(auto-fill, 100px);

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

.badge:not(img):not(:has(img)) {
  align-items: center;
  background: #cccccc border-box;
  border: 2px solid;
  border-color: #ffffff7e #0000007e #0000007e #ffffff7e;
  color: black;
  display: flex;
  font-size: 11px;
  font-weight: 600;
  height: 31px;
  justify-content: center;
  line-height: 11px;
  text-align: center;
  text-decoration: none;
  width: 88px;
  word-break: break-word;

  &:active {
    border-color: #0000007e #ffffff7e #ffffff7e #0000007e;
  }
}

.badges img,
.badge img,
img.badge {
  /*display: block;*/
  max-height: 31px;
  max-width: 88px;
  vertical-align: middle;
}

.badges *,
.badge {
  &[title] {
    position: relative;

    &:hover::after,
    &:focus::after {
      color: var(--contrast-fg);
      content: attr(title);
      background: var(--contrast-bg);
      pointer-events: none;
      border: 1px solid var(--contrast-fg);
      font-size: 0.8rem;
      font-weight: normal;
      position: absolute;
      top: 100%;
      z-index: 10;
      width: max-content;
      word-wrap: break-word;
      max-width: 200px;
      padding: 4px;
      line-height: normal;
    }
  }
}

/* only use pixelated rendering on integer zoom */
@media (resolution: 1x),
  (resolution: 2x),
  (resolution: 3x),
  (resolution: 4x),
  (min-resolution: 4x),
  (min-resolution: 2x) and (pointer: coarse) {
  .bg,
  .badges,
  .navrow,
  .badge,
  #nowplaying {
    image-rendering: pixelated;
  }

  img[src$="svg"] {
    image-rendering: initial;
  }
}

.double-badge {
  display: grid;
  grid-template-rows: 1fr 1fr;

  & > .badge {
    height: unset;
  }
}
