:root {
  color-scheme: light dark;

  --fg: light-dark(#20242d, #eceff4);
  --fg-alt: light-dark(#4e5564, #b1b6bd);
  --bg: light-dark(#fdfbf8, #252a33);
  --bg-alt: light-dark(#ebebe8, #2f3540);
  --primary: light-dark(#0056a8, #5fd7ff);
  --error: light-dark(#a41d2b, #eca2a9);

  --st: rgb(255, 127, 127);
  --at: rgb(255, 191, 127);
  --bt: rgb(255, 223, 127);
  --ct: rgb(255, 255, 127);
  --dt: rgb(191, 255, 127);
}

/** global defaults */

/*
 * font from https://fonts.google.com rather
 * than https://github.com/rsms/inter because fonts are wonderfully compressed
 */
@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url(/fonts/inter-v18.woff2) format("woff2");
  unicode-range:
    U+0000-00FF,
    U+0131,
    U+0152-0153,
    U+02BB-02BC,
    U+02C6,
    U+02DA,
    U+02DC,
    U+0304,
    U+0308,
    U+0329,
    U+2000-206F,
    U+2074,
    U+20AC,
    U+2122,
    U+2191,
    U+2193,
    U+2212,
    U+2215,
    U+FEFF,
    U+FFFD;
}

/*
 * font from https://www.jetbrains.com/lp/mono/
 */
@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 100;
  font-display: swap;
  src: url(/fonts/JetBrainsMono-Regular.woff2) format("woff2");
}

@media print {
  /* do not print */
  .dnp {
    display: none !important;
  }
}
@page {
  size: auto;
  margin: 0.5in;
}

*:focus-visible {
  outline: 2px solid #5097f5;
}

body {
  max-width: 900px;
  margin: 1rem auto;
  padding: 0 0.8rem;
  font-family: Inter, Sans-serif;
  background: var(--bg);
  color: var(--fg);
}
article {
  word-break: break-word;
}
code, pre {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.9rem;
  border-radius: 8px;
}
code {
  background: var(--bg-alt);
  padding: 0.1rem 0.3rem;
}

mark {
  background: light-dark(#ffd145, #4d4d66);
  color: var(--fg);
}

h1 {
  font-size: 2.369rem;
}
h2 {
  font-size: 1.777rem;
}
h3 {
  font-size: 1.333rem;
}
h4, h5, h6 {
  font-size: 1rem;
}
figcaption, small, sup, sub {
  font-size: 0.75rem;
}

h2 a, h3 a, h4 a, h5 a, h6 a {
  color: inherit;
  text-decoration: none;
}

h2[id] a:hover::after,
h3[id] a:hover::after,
h4[id] a:hover::after,
h5[id] a:hover::after,
h6[id] a:hover::after {
  color: var(--primary);
  content: " §";
}

blockquote, h1, h2, h3, h4, h5, h6, ol, p, pre, ul {
  margin: 1rem 0;
}
li ol, li ul {
  margin: 0;
}
li {
  margin: 0.3rem 0;
}
article, header, footer, section {
  margin: 3rem 0;
}
small {
  display: block;
  margin: 0.75rem 0;
}

details.showmore {
  summary {
    display: block;
    cursor: pointer;
    color: var(--primary);
    text-decoration: underline;
    visibility: hidden;
  }
  summary:hover {
    text-decoration: none;
  }
  summary::before {
    visibility: visible;
    content: "Show more";
  }
  &[open] summary::before {
    content: "Show less";
  }
}

summary {
  cursor: pointer;
}

ol {
  padding-left: 1.3rem;
}
ul {
  padding-left: 1rem;
}

a {
  color: var(--primary);
  text-decoration: underline;
}
a:focus,
a:hover {
  text-decoration: none;
}

dfn {
  color: var(--primary);
  font-style: normal;
  font-weight: 700;
}
s, s * {
  color: var(--fg-alt);
}
aside, blockquote {
  font-style: italic;
  padding: 0 1rem;
  color: var(--fg-alt);
}
aside {
  border-left: 0.25rem solid var(--bg-alt);
}

figure {
  margin: 1rem;
}

audio,
img,
video,
wc-yt-video {
  margin: 0 auto;
  max-width: 100%;
  border-radius: 8px;
}
audio,
img,
video {
  border: 1px solid light-dark(var(--fg), transparent);
  display: block;
}
audio {
  /* border radius doesn't work properly with audio */
  border-radius: 0;
  width: 100%;
}
img {
  background: var(--bg-alt);
}
img::after {
  content: " (image)";
}

pre:has(code) {
  border: 1px solid #2e3440;
  background: var(--bg-alt);
}
pre > code {
  display: inline-block;
  padding: 1rem;
  min-width: calc(100% - 2rem);
}

table {
  border-collapse: collapse;
}
th,
td {
  padding: 0.4rem;
  border-width: 1px;
  border-style: solid;
  border-color: var(--fg-alt);
}
td ul {
  margin: 0;
}

hr {
  color: var(--bg-alt);
}

.footnote-ref a {
  text-decoration: none;
}
.footnote-ref a:hover {
  text-decoration: underline;
}
ol.footnotes-list {
  padding-left: 1rem;

  * {
    font-size: 0.75rem;
    margin: 0.75rem 0;
  }
}

/** components */

header .title {
  color: inherit;
  text-decoration: none;
  font-weight: 700;
}
header nav, nav.pagination {
  margin: 3rem 0;

  ol {
    list-style-type: none;
    padding: 0;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.7rem;

    li {
      margin: 0;
    }

    a {
      color: inherit;
    }
  }
}

.pagination ol {
  justify-content: center;
}

.thoughtsingle {
  position: relative;
}
.thoughtsingle img {
  max-height: 600px;
}
.thoughtsingle pre {
  overflow-x: auto;
}

aside.spoiler {
  margin: 1rem 0;
  color: var(--error);
  border-color: var(--error);
  font-style: normal;
}

a.sourceref {
  display: block;
  margin: 0.25rem 0 0.25rem auto;
  width: fit-content;
  color: var(--fg-alt);
  font-size: 0.75rem;
  font-style: italic;
}

.meta {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}
.meta ul, .meta li {
  margin: 0;
}
.meta ul {
  list-style-type: none;
  display: contents;
}
dl {
  display: grid;
  grid-template-columns: 1fr 1fr;
  width: fit-content;
}
dt::after {
  content: ":";
}
dd {
  margin-left: 1rem;
}

table.fwidth {
  width: 100%;
}

.articlelist, .streamlist {
  list-style-type: none;
  padding: 0;

  a {
    color: inherit;
    display: flex;
    flex-direction: column;
    gap: 4px;
  }

  p {
    margin: 0;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
  }
}

.articlelist > li {
  margin: 1.5rem 0;

  a {
    font-size: 1.333rem;
  }
}

.streamlist {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  counter-reset: stream;

  &.count p:first-of-type::before {
    counter-increment: stream;
    content: counter(stream) ". ";
  }

  li {
    width: 270px;
  }

  img {
    aspect-ratio: 16/9;
  }
}
@media (max-aspect-ratio: 1/1) {
  .streamlist {
    justify-content: space-around;

    li {
      width: 350px;
    }
  }
}

.recsingle > ol {
  padding: 0;
  list-style-type: none;
}
.recsingle > ol > li {
  margin: 1rem 0;
}
ol.top {
  list-style-type: decimal;
  padding-left: 1rem;
}

.st,
.at,
.bt,
.ct,
.dt {
  position: relative;
  padding-left: 1rem;
}
.st::before,
.at::before,
.bt::before,
.ct::before,
.dt::before {
  position: absolute;
  top: 0;
  left: 0;
  height: 100%;
  width: 0.5rem;
  content: "";
  /* permanently --fg */
  border: 1px solid #20242d;
}
.st::before {
  background: var(--st);
}
.at::before {
  background: var(--at);
}
.bt::before {
  background: var(--bt);
}
.ct::before {
  background: var(--ct);
}
.dt::before {
  background: var(--dt);
}

.tweet {
  max-width: 600px;
  margin: 0 auto;
  padding: 0 1rem;
  border: 1px solid var(--fg-alt);
  border-radius: 8px;
  font-size: 0.9rem;
  font-family: "JetBrains Mono", monospace;

  & > * {
    margin: 1rem 0;
  }

  & > div:first-child {
    position: relative;
    margin-left: 56px;

    &::first-line {
      font-weight: 700;
    }

    &::before {
      content: "";
      position: absolute;
      left: -56px;
      height: 40px;
      width: 40px;
      background: var(--bg-alt);
      border: 1px solid var(--fg-alt);
      border-radius: 50%;
    }
  }

  & > div:last-child {
    &, & a {
      color: var(--fg-alt);
    }
  }
}

/** common style groups (used in articles) */

.imggroup {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.imggroup img {
  margin: 0;
}

[data-tier] {
  /* permanently --fg */
  color: #20242d;
  text-align: center;
}
[data-tier]::after {
  content: attr(data-tier);
  font-size: 3rem;
  font-weight: 700;
}
[data-tier="S"] {
  background: var(--st);
}
[data-tier="A"] {
  background: var(--at);
}
[data-tier="B"] {
  background: var(--bt);
}
[data-tier="C"] {
  background: var(--ct);
}
[data-tier="D"] {
  background: var(--dt);
}

.badge {
  display: grid;
  margin: 1rem 0;
  width: 50px;
  padding: 0.5rem;
  text-decoration: none;
  /* permanently --fg */
  border: 2px solid #20242d;
}
@media screen and (min-width: 1100px) {
  .badge {
    position: sticky;
    top: 1rem;
    float: right;
    margin-right: -85px;
  }
}

/** web components */

wc-timestamp button {
  color: var(--primary);
  font-size: inherit;
  padding: 0;
  background: none;
  border: none;
  text-align: left;
  vertical-align: top;
  cursor: pointer;
  text-decoration: underline;
}
wc-timestamp button:focus,
wc-timestamp button:hover {
  text-decoration: none;
}
wc-timestamp::after {
  content: " (" attr(data-t) ")";
}

/** plugins */

/* auto_toc */

#toc > ol ol {
  list-style-type: lower-alpha;
}
@media screen and (min-width: 1400px) {
  #toc {
    position: sticky;
    top: 0;
    float: left;
    margin-left: -250px;
    width: 234px;
    padding: 8px;
    font-size: 0.9em;
  }
  #toc h2 {
    margin-top: 0;
    font-size: 1.5em;
  }
}

/* codeHighlight */

pre code {
  color: light-dark(#2e3440, #d8dee9);
}
.lang-attr {
  color: light-dark(#0f5e5c, #8fbcbb);
}
.lang-built_in {
  color: light-dark(#077295, #8fbcbb);
}
.lang-comment {
  color: light-dark(#66676c, #999fac);
}
.lang-keyword, .lang-tag, .lang-type {
  color: light-dark(#27598a, #81a1c1);
}
.lang-literal, .lang-number {
  color: light-dark(#823373, #b48ead);
}
.lang-string {
  color: light-dark(#33600c, #a3be8c);
}
.lang-section {
  color: light-dark(#753569, #e7b8de);
}
.lang-meta {
  color: light-dark(#27598a, #5e81ac);
}
.lang-addition, pre code ins {
  text-decoration: none;
  color: light-dark(#2e3440, #a3be8c);
  background-color: light-dark(#a3be8cc0, transparent);
}
.lang-deletion, pre code del {
  text-decoration: none;
  color: light-dark(#2e3440, #ffaeb7);
  background-color: light-dark(#bf616a80, transparent);
}
