@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: 540px;
  --side-width: 200px;
  --side-gap: 20px;

  counter-reset: side-note;

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

  @media print {
    --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;
}

@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;
    }
  }

  .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));
  }
}

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,
.badges,
.equation.block {
  margin-block: 0.5em;
}

hgroup {
  h1 {
    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)
    )::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 1fr;

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

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

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

.badges {
  display: grid;
  font-stretch: 85%;
  font-weight: 500;
  gap: 2px;
  grid: auto-flow 31px / repeat(auto-fill, 88px);

  a {
    align-items: center;
    display: flex;
    justify-content: center;
  }
}

.badge:not(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;
  text-shadow: 1px 1px #ffffff7e;
  width: 88px;
  word-break: break-word;

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

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

.badges img,
.badge img,
img.badge {
  display: block;
  image-rendering: pixelated;
  max-height: 31px;
  max-width: 88px;

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

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

  & > .badge {
    height: unset;
  }
}

#nowplaying {
  align-items: center;
  display: flex;
  gap: 8px;
  justify-content: center;
  margin: 16px auto;
  max-width: 540px;

  & > a {
    border: 1px solid var(--base-fg);
    color: inherit;
    display: grid;
    grid: 13px 17px / 34px auto;
    gap: 4px;
    max-width: 100%;
    overflow: hidden;
    padding: 2px;
    text-decoration: none;
    text-wrap: nowrap;
    min-width: 200px;
    max-width: 100%;

    img {
      grid-row: span 2;
    }

    span {
      align-self: end;
      font-size: 9px;
      font-stretch: 85%;
      line-height: 9px;
      padding-right: 4px;
    }

    span + span {
      align-self: start;
      font-size: 13px;
      font-stretch: 100%;
      line-height: 13px;
    }
  }
}
