/*
 * Devbits: ef11 with an 8-bit accent.
 *
 * The page runs on ef11's components, themes and frame (base theme ef11,
 * ui_skins theme "light" as on erdfisch: beige content, Navy bands; the old
 * nf10 also had light content under a dark stage). This file only changes
 * the look of the devbits:
 * Share Tech fonts, square corners, pixel frames (nes.css) and the nerd sea
 * on the page title band. Unlayered, so it wins over ef11's @layer rules.
 *
 * Contrast (WCAG 2.2 AA) on Navy 80 (#1b2842, ef11 "dark"): text Beige 30
 * 13.3:1, tag badge Navy 80 on Rust 20 (#f38a31, accent) 5.9:1 (the old
 * theme had white on orange, 2.3:1), pixel frames Rust 20 5.9:1.
 */

:root {
  --font-sans: "Share Tech", ui-sans-serif, system-ui, sans-serif;
  --font-heading: "Share Tech Mono", ui-monospace, monospace;
  --font-mono: "Share Tech Mono", ui-monospace, monospace;
  /* Width of one "pixel" of the nes.css frames. */
  --nf-px: 4px;
}

/* Square corners everywhere: every theme sets its own shape tokens. */
:root,
[data-theme] {
  --radius-selector: 0;
  --radius-field: 0;
  --radius-box: 0;
}

/* Share Tech has one weight; synthetic bold smears it. */
:where(h1, h2, h3, h4, h5, h6, b, strong, .btn, .card-title) {
  font-weight: 400;
  font-synthesis: none;
}

:where(pre, code, kbd, samp) {
  font-family: var(--font-mono);
}

/*
 * Pixel frame: the nes.css corner trick, four box-shadows one pixel wide,
 * the corners stay open. Colour from --nf-frame.
 */
.btn,
.prose pre {
  box-shadow:
    0 var(--nf-px) var(--nf-frame, currentColor),
    0 calc(-1 * var(--nf-px)) var(--nf-frame, currentColor),
    var(--nf-px) 0 var(--nf-frame, currentColor),
    calc(-1 * var(--nf-px)) 0 var(--nf-frame, currentColor);
}

/* Buttons: the frame in the button's border colour replaces the border. */
.btn {
  --nf-frame: var(--btn-border, var(--btn-bg));
  border-width: 0;
  margin: var(--nf-px);
}

/* Code blocks: a dark terminal with a frame in the link colour. */
.prose pre {
  --nf-frame: var(--color-link);
  margin-inline: var(--nf-px);
}

/*
 * Code snippets (js/snippets.js): a dark nes.css container with the file name
 * as its title, a frame in the link colour and an 8-bit copy button.
 * Token colours on the terminal (#08152d): text 16.5:1, keyword Rust 20
 * 7.4:1, string 8.0:1, number 10.1:1, comment Cool Grey 30 5.6:1,
 * function 7.5:1.
 */
.nf-snippet {
  --nf-terminal: #08152d;
  margin-block: 2.5rem 1.5rem;
  margin-inline: 0;
  padding: 1.5rem 1rem 1rem;
  border-color: var(--color-link);
  background-color: var(--nf-terminal);
  color: #f8f3ed;

  &.with-title > .title {
    max-width: calc(100% - 1rem);
    overflow-wrap: anywhere;
    background-color: var(--nf-terminal);
    color: #f8f3ed;
    font-family: var(--font-mono);
    font-size: 0.875rem;
  }

  & pre {
    margin: 0;
    padding: 0;
    background: none;
    box-shadow: none;
    color: inherit;
    font-size: 0.875rem;
    line-height: 1.5rem;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
  }

  & code {
    padding: 0;
    background: none;
    color: inherit;
    font-weight: 400;
  }
}

.nf-snippet__copy.nes-btn {
  margin-top: 1rem;
  padding: 0.125rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.875rem;

  &:focus-visible {
    outline: 2px solid var(--color-link);
    outline-offset: 6px;
  }
}

.nf-snippet .token {
  &:is(.comment, .prolog, .doctype, .cdata) {
    color: #8190a9;
  }

  &:is(.keyword, .tag, .selector, .important, .atrule, .rule) {
    color: #f38a31;
  }

  &:is(.string, .char, .attr-value, .inserted, .url) {
    color: #9db803;
  }

  &:is(.number, .boolean, .constant, .variable, .property, .attr-name) {
    color: #e4be05;
  }

  &:is(.function, .class-name, .builtin) {
    color: #5fb3c1;
  }

  &.deleted {
    color: #e58fb7;
  }
}

/* Tags (ef11 tag_list): pixel badges after nes.css's nes-badge. */
.ef-tags :is(a, .ef-tag) {
  --nf-frame: var(--color-accent);
  margin: 0.25em 0.5em;
  padding: 0 0.25rem;
  border-radius: 0;
  background-color: var(--nf-frame);
  color: var(--color-accent-content);
  font-family: var(--font-mono);
  box-shadow:
    0 0.25em var(--nf-frame),
    0 -0.25em var(--nf-frame),
    0.5em 0 var(--nf-frame),
    -0.5em 0 var(--nf-frame);
}

.ef-tags a:is(:hover, :focus-visible) {
  --nf-frame: var(--color-heading);
  background-color: var(--nf-frame);
  color: var(--color-base-100);
}

/*
 * Filter box (ef11 .ef-filter, devbits.theme): square fields. Four columns
 * from md: search and Filtern in the first row; topic, difficulty, audience
 * and Zurücksetzen in the second.
 */
.ef-filter :is(.form-text, .form-select) {
  border-radius: 0;
}

/* The buttons' pixel frame sits in their margin: full width minus the frame. */
.ef-filter .form-submit {
  width: calc(100% - 2 * var(--nf-px));
}

/*
 * Zurücksetzen: the pixel frame replaces ef11's outline. By
 * data-drupal-selector as in ef11: after a Views AJAX update the id gets a
 * suffix (edit-reset--…).
 */
.ef-filter [data-drupal-selector="edit-reset"] {
  --nf-frame: var(--color-primary);
}

@media (width >= 48rem) {
  .ef-filter {
    grid-template-columns: repeat(3, minmax(0, 1fr)) auto;

    & .form-item-suche {
      grid-column: 1 / 4;
    }

    & [id^="edit-submit-"],
    & [data-drupal-selector="edit-reset"] {
      grid-column: 4;
    }

    & :is(.form-item-thema, .form-item-schwierigkeit, .form-item-zielgruppe),
    & [data-drupal-selector="edit-reset"] {
      grid-row: 2;
    }
  }
}

/* Cards: a pixel frame like nes.css's container, Rust 20 on hover. */
.card {
  --nf-frame: var(--color-base-300);
  margin: var(--nf-px);
}

.card,
a.card:is(:hover, :focus-visible) {
  box-shadow:
    0 var(--nf-px) var(--nf-frame),
    0 calc(-1 * var(--nf-px)) var(--nf-frame),
    var(--nf-px) 0 var(--nf-frame),
    calc(-1 * var(--nf-px)) 0 var(--nf-frame);
}

a.card:is(:hover, :focus-visible) {
  --nf-frame: var(--color-link);
}

/*
 * The nerd sea: a page title band (as slim as on the other landing pages)
 * all in pixel water, with the nerd ship bottom right. The water
 * (images/nerdwasser.webp) is cut from the old devbits sunset and tinted 65 %
 * towards Navy 80, so even its brightest pixel keeps 5.7:1 with the text
 * (Beige 30); no gradient needed. Like the header animations of ef11 the
 * ship plays each time the band comes into view (js/sea.js: is-playing): it
 * sails in in pixel steps and rocks twice. Only a band of its own (directly
 * in main): a title inside an area is just a heading block.
 */
main > .ef-title[data-theme="dark"] {
  --nf-ship: clamp(8rem, 16vw, 15rem);
  position: relative;
  isolation: isolate;
  overflow: hidden;
  background-image: url("../images/nerdwasser.webp");
  background-position: center bottom;
  background-size: cover;
  image-rendering: pixelated;

  &::before {
    content: "";
    position: absolute;
    right: max(1rem, 14vw);
    bottom: 0.75rem;
    z-index: -1;
    width: var(--nf-ship);
    aspect-ratio: 1;
    background: url("../images/nerdschiff.webp") center bottom / contain
      no-repeat;
    transform-origin: 50% 90%;
    pointer-events: none;
  }

  &.is-playing::before {
    animation:
      nf-sail 2.4s steps(16) both,
      nf-rock 1.2s steps(2) 2.4s 2;
  }
}

/*
 * Below 64rem the text runs across the ship (from 64rem the text column ends
 * before it): there it sails darkened to 40 % (images/nerdschiff-dunkel.webp),
 * so the text keeps 5.2:1 on its sails as well. A file, not a CSS filter:
 * filters may darken in linear RGB.
 */
@media (width < 64rem) {
  main > .ef-title[data-theme="dark"]::before {
    background-image: url("../images/nerdschiff-dunkel.webp");
  }
}

@keyframes nf-sail {
  from {
    translate: 60vw 0;
  }

  to {
    translate: 0 0;
  }
}

@keyframes nf-rock {
  50% {
    rotate: -2deg;
    translate: 0 -3px;
  }
}

/*
 * Devbit page: ef11:stage with box like a blog article, but without an
 * image. The nerd sea and the ship take the place of the blurred article
 * image; the box gets a pixel frame in Rust 20.
 */
main > .ef-stage--box:not(:has(.ef-stage__bg)) {
  background-image:
    url("../images/nerdschiff.webp"), url("../images/nerdsee.webp");
  background-repeat: no-repeat;
  background-position:
    right max(1rem, 8vw) bottom 0,
    center bottom;
  background-size:
    auto 80%,
    cover;

  & .ef-stage__content {
    --nf-frame: var(--color-accent);
    margin: var(--nf-px);
    box-shadow:
      0 var(--nf-px) var(--nf-frame),
      0 calc(-1 * var(--nf-px)) var(--nf-frame),
      var(--nf-px) 0 var(--nf-frame),
      calc(-1 * var(--nf-px)) 0 var(--nf-frame);
  }
}

/* Konami code easter egg (js/nerdfisch.js): fish swim over the page. */
.nf-aquarium {
  position: fixed;
  inset: 0;
  z-index: 100;
  overflow: hidden;
  background-color: rgb(8 21 45 / 0.85);
  pointer-events: none;
}

.nf-fish {
  position: absolute;
  left: 0;
  width: 145px;
  height: 145px;
  background-repeat: no-repeat;
  background-size: 290px 145px;
  image-rendering: pixelated;
  /* Two frames per sprite: the tail flaps. */
  animation:
    nf-swim var(--nf-swim, 20s) linear var(--nf-delay, 0s) infinite,
    nf-flap 0.4s steps(1) infinite;
}

.nf-fish--angel {
  background-image: url("../images/fish/angel.png");
}

.nf-fish--butterfly {
  background-image: url("../images/fish/butterfly.png");
}

.nf-fish--flounder {
  background-image: url("../images/fish/flounder.png");
}

.nf-fish--guppy {
  background-image: url("../images/fish/guppy.png");
}

.nf-fish--jelly {
  background-image: url("../images/fish/jelly.png");
}

.nf-fish--minnow {
  background-image: url("../images/fish/minnow.png");
}

.nf-fish--red {
  background-image: url("../images/fish/red.png");
}

.nf-fish--seahorse {
  background-image: url("../images/fish/seahorse.png");
}

.nf-fish--striped {
  background-image: url("../images/fish/striped.png");
}

.nf-fish--rtl {
  animation-direction: reverse, normal;
  scale: -1 1;
}

@keyframes nf-swim {
  from {
    translate: -160px 0;
  }

  to {
    translate: 100vw 0;
  }
}

@keyframes nf-flap {
  50% {
    background-position: -145px 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .nf-fish {
    animation: none;
    translate: var(--nf-x, 50vw) 0;
  }
}

/* Klaro buttons get the pixel frame of the other buttons (tokens from ef11). */
body .klaro .cm-btn {
  --nf-frame: var(--color-primary);
  border-width: 0;
  box-shadow:
    0 var(--nf-px) var(--nf-frame),
    0 calc(-1 * var(--nf-px)) var(--nf-frame),
    var(--nf-px) 0 var(--nf-frame),
    calc(-1 * var(--nf-px)) 0 var(--nf-frame);
}

/*
 * Table of contents: ef11 marks the section in view bold, but Share Tech has
 * one weight and the Navy step is too small to see. Here it gets a pixel bar
 * in the link colour in front, like the pixel frames; the text stays dark
 * (Rust on Beige 30 would be 4.4:1).
 */
.ef-toc__list a[aria-current] {
  box-shadow: inset var(--nf-px) 0 0 var(--color-link);
  text-decoration-color: currentColor;
}
