@import url(codehilite-coffee.css);

:root {
  font-family: sans-serif;

  --color: #0088ff;

  --archival-color: #E39D5A;
  --code-color: #de2891;
  --coffee-color: #ee211d;
  --data-color: #18d211;
  --design-color: #d26b2a;
  --feature-color: #7f35ee;

  .archival, a[href*="#archival"] { --color: var(--archival-color); }
  .code, a[href*="#code"] { --color: var(--code-color); }
  .coffee, a[href*="#coffee"] { --color: var(--coffee-color); }
  .data, a[href*="#data"] { --color: var(--data-color); }
  .design, a[href*="#design"] { --color: var(--design-color); }
  .feature, a[href*="#feature"] { --color: var(--feature-color); }
}

body {
  margin: 25px;
  margin-bottom: 60px;

  &::before {
    content: "";
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: -1;

    background-color: #c9c9c9;
    background-image: url(/theme/img/5002.png);
    background-size: 125px;
  }

  > header,
  > main,
  > footer {
    max-width: 968px;
    margin-left: auto;
    margin-right: auto;

    background: white;
  }

  > header {
    padding: 20px 20px 10px 20px;

    background-color: black;
    background-image: url(/theme/img/5003.png);
    color: white;
    background-size: 125px;

    > nav ul {
      display: flex;
      padding: 0;
      margin-bottom: 10px;

      li {
        display: block;

        &:has(+ .right) {
          flex-grow: 1;
        }
      }

      li a {
        padding: 5px 20px;

        background: #272727;
        border: 1px solid var(--color);
        border-radius: 2px;

        &:where(li.active a) {
          background: var(--color);
          color: white;
        }
      }
    }
  }

  > footer {
    padding: 5px 20px 5px 20px;
    background-color: #f3f3f3;
  }

  > main {
    --content-padding: 20px;
    padding: var(--content-padding);

    contain: paint;

    article > header > :first-child {
      margin-top: 0;
    }
  }
}

a {
  color: var(--color);
  text-decoration: none;
  text-decoration-thickness: 0.0875em;

  &[href^="https://"], &[href^="http://"] {
    &:not(:where(
      [href^="https://hsmusic.wiki"],
      [href^="https://preview.hsmusic.wiki"],
      [href^="https://nebula.hsmusic.wiki"],
      [href^="https://discord.com"],
      [href^="https://github.com"],
      [href^="https://ko-fi.com"],
      .secret
    )) {
      text-decoration: underline;
      text-decoration-style: dotted;
    }
  }

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

  &.secret {
    color: inherit;
  }
}

img.cute {
  vertical-align: text-bottom;
  border-radius: 2px;
}

article {
  line-height: 1.6;

  &:is(#top > h2 ~ *) {
    &:not(:last-child) {
      margin-bottom: 1.5em;
    }

    footer {
      display: none;
    }
  }

  blockquote {
    margin-left: 15px;
    padding-left: 25px;
    border-left: 1px dotted;
  }

  code:not(:where(pre code)) {
    padding: 2px 3px;
    background-color: color-mix(in srgb, var(--color), 85% #00000003);
    border: 1px solid color-mix(in srgb, var(--color), 70% #00000002);
    border-radius: 3px;
  }

  details {
    padding-left: 15px;
    padding-right: 15px;
    border-left: 3px dotted #ccc8;
    border-right: 3px dotted #ccc8;

    &[open] {
      padding-bottom: 15px;

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

    summary {
      margin-left: -25px;
      margin-right: -25px;

      --cue-font-scale: 0.80;
      --pale: #f0eca7;
      --dim: color-mix(in hsl, var(--pale), 15% black);

      background:
        linear-gradient(to right,
          var(--pale),
          var(--pale) calc(5px + var(--cue-font-scale) * 82ch),
          var(--dim) calc(5px + var(--cue-font-scale) * 84ch));

      span {
        display: inline-block;
        vertical-align: top;
        max-width: calc(var(--cue-font-scale) * 80ch - 15px);
      }

      border: 3px solid var(--dim);
      border-radius: 4px;
      padding: 5px 5px 5px 8px;
      cursor: default;

      &::after {
        content: "click to expand";
        margin-right: 5px;
        font-style: oblique;
        font-size: calc(var(--cue-font-scale) * 1em);
        display: block;
        max-width: 80ch;
        text-align: right;
      }

      &:is(details[open] > summary)::after {
        content: "click to collapse";
      }
    }
  }

  figure {
    margin-top: 2em;
    margin-bottom: 2em;

    img, video {
      background: #c0c0c0;
      display: block;
      margin-left: auto;
      margin-right: auto;
      margin-bottom: 1em;
      max-width: 100%;
      max-height: 80vh;
      box-shadow: 0 1px 3px 1px #3336;
      width: auto;
      height: auto;

      &:is(figure.squish *) {
        max-width: max(min(100%, 400px), 75%);
        max-height: 60vh;
      }
    }

    figcaption {
      text-align: center;
      font-style: oblique;
    }
  }

  li {
    /* baseline, paragraphs will space further */
    margin-bottom: 0.25em;
  }

  pre {
    line-height: 1.3;
    white-space: pre-wrap;
    border: 4px inset #ccce !important;
    padding: 12px 8px;

    background: #191615;
    color: #ddd0c0;

    &:has(code.scroll) {
      white-space: pre;

      /* would be nice to use
       * scrollbar-gutter: stable
       * here, but it doesn't work
       * for overflow-x lmao
       *
       * https://stackoverflow.com/questions/
       * 77502434/#comment140186491_77580453
       */
      overflow-x: scroll;

      &::-webkit-scrollbar {
        background: #191615;
        border-top: 1px solid currentColor;
      }

      &::-webkit-scrollbar-thumb {
        transition: background 0.2s;
        background: currentColor;
        padding: 4px;
        border-radius: 10px;
        background-clip: content-box;
      }
    }
  }

  .toc {
    font-weight: 800;

    /* for rss/atom summaries, where the
     * list items are rendered inline
     */
    li i { display: none; }

    li a {
      text-decoration-thickness: 0.08em;
    }

    li::before {
      --pale: color-mix(in srgb, var(--color), 65% #ffffff);
      --shine: color-mix(in srgb, var(--color), 75% white);

      background: var(--pale);
      padding: 3px 7px;
      margin-right: 7px;
      border-bottom-right-radius: 5px;
      border-top-left-radius: 5px;
    }

    li:has(a:hover)::before {
      background:
        linear-gradient(45deg,
          var(--pale) var(--shine2),
          var(--shine) calc(var(--shine2) + 1%),
          var(--shine) var(--shine1),
          var(--pale) calc(var(--shine1) + 1%));

      animation: label-shine 0.35s linear forwards;
    }

    li:has(a[href*="#archival"])::before {
      content: "archival"; --color: var(--archival-color);
    }

    li:has(a[href*="#code"])::before {
      content: "code"; --color: var(--code-color);
    }

    li:has(a[href*="#coffee"])::before {
      content: "coffee"; --color: var(--coffee-color);
    }

    li:has(a[href*="#data"])::before {
      content: "data"; --color: var(--data-color);
    }

    li:has(a[href*="#design"])::before {
      content: "design"; --color: var(--design-color);
    }

    li:has(a[href*="#feature"])::before {
      content: "feature"; --color: var(--feature-color);
    }
  }

  h3 {
    margin-left: calc(-1 * var(--content-padding));
    margin-right: calc(-1 * var(--content-padding));
    padding-left: calc(0.5 * var(--content-padding));
    padding-right: calc(1.5 * var(--content-padding));
    padding-top: 6px;
    padding-bottom: 4px;
    margin-top: 1.75em;
    scroll-margin-top: 0.75em;

    position: sticky;
    top: 0;
    z-index: 3;
    background: #fffc;
    box-shadow: 0 3px 4px #fff3;
    border-bottom: 2px solid #22222238;
    backdrop-filter:
      contrast(0.9) brightness(1.4) contrast(0.2) brightness(2.0) saturate(1.4) blur(6px);

    &::before {
      background: color-mix(in srgb, var(--color), 65% #ffffff);
      padding: 5px 10px;
      margin-right: 10px;
      border-bottom-right-radius: 5px;
      border-top-left-radius: 5px;
    }

    &.archival::before { content: "archival"; }
    &.code::before { content: "code"; }
    &.coffee::before { content: "coffee"; }
    &.data::before { content: "data"; }
    &.design::before { content: "design"; }
    &.feature::before { content: "feature"; }
  }

  h3 { font-size: 1.17em; }
  h3 { margin-bottom: 0;  }
  h3 + * { margin-top: 1.17em; }

  footer {
    line-height: 1.2;
    p { margin: 0; }

    &::before {
      content: "";
      display: block;
      width: 14ch;
      height: 2px;
      margin-bottom: 1em;
      margin-top: 3em;
      background: #c7c7c7;
    }

    address {
      font-style: normal;
    }
  }
}

#top {
  --letter-margin: 30px;
  --letter-padding: 10px;

  > h2 {
    margin-top: 0.5em;

    font-weight: normal;
    font-size: 1em;

    padding: 0 20px 5px;

    text-transform: lowercase;

    border-bottom: 1px solid var(--color);
    margin-bottom: 1.5em;

    &:where(li.active a) {
      background: var(--color);
      color: white;
    }
  }
}

@property --shine1 {
  syntax: '<percentage>';
  initial-value: 0%;
  inherits: false;
}

@property --shine2 {
  syntax: '<percentage>';
  initial-value: 0%;
  inherits: false;
}

@keyframes label-shine {
  from {
    --shine1: 0%;
    --shine2: 0%;
  }

  20% {
    --shine2: 0%;
  }

  80% {
    --shine1: 100%;
  }

  100% {
    --shine1: 100%;
    --shine2: 100%;
  }
}
