/**
 * Monospace Web
 * Based on the work of Oskar Wickström
 * Licensed under the MIT License
 *
 * https://github.com/owickstrom/the-monospace-web
 */

@import url("https://fonts.cdnfonts.com/css/jetbrains-mono-2");

/* ==========================================================================
   Design Tokens
   ========================================================================== */

:root {
  --font-family: "JetBrains Mono", monospace;

  --font-size: 16px;
  --line-height: 1.2rem;

  --font-weight-normal: 500;
  --font-weight-medium: 600;
  --font-weight-bold: 800;

  --border-thickness: 2px;

  --text-color: #000;
  --text-color-alt: #666;
  --background-color: #fff;
  --background-color-alt: #eee;

  font-family: var(--font-family);
  font-size: var(--font-size);
  font-weight: var(--font-weight-normal);
  font-style: normal;
  font-variant-numeric: tabular-nums lining-nums;
  line-height: var(--line-height);
  font-optical-sizing: auto;
}

@media (prefers-color-scheme: dark) {
  :root {
    --text-color: #fff;
    --text-color-alt: #aaa;
    --background-color: #000;
    --background-color-alt: #111;
  }
}

/* ==========================================================================
   Reset / Base
   ========================================================================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  width: 100%;
  min-height: 100%;

  margin: 0;
  padding: 0;

  background: var(--background-color);
  color: var(--text-color);
}

body {
  position: relative;

  width: 100%;
  max-width: calc(min(80ch, round(down, 100%, 1ch)));

  margin: 0 auto;
  padding: var(--line-height) 2ch;

  overflow-x: hidden;

  background: var(--background-color);
  color: var(--text-color);

  line-height: var(--line-height);
}

/* ==========================================================================
   Typography
   ========================================================================== */

h1,
h2,
h3,
h4,
h5,
h6 {
  margin: 0 0 var(--line-height);

  font-weight: var(--font-weight-bold);
  line-height: var(--line-height);
}

h1 {
  margin-bottom: calc(var(--line-height) * 2);

  font-size: 2rem;
  line-height: calc(var(--line-height) * 2);
  text-transform: uppercase;
}

h2 {
  margin-top: calc(var(--line-height) * 2);

  font-size: 1rem;
  text-transform: uppercase;
}

h3,
h4,
h5,
h6 {
  margin-top: calc(var(--line-height) * 2);
}

p {
  margin: 0 0 var(--line-height);

  word-break: break-word;
  overflow-wrap: break-word;
  hyphens: auto;
}

strong {
  font-weight: var(--font-weight-bold);
}

em {
  font-style: italic;
}

sub {
  display: inline-block;
  position: relative;

  width: calc(1ch / 0.75);

  margin: 0;

  font-size: 0.75rem;
  line-height: 0;
  vertical-align: sub;
}

/* ==========================================================================
   Links
   ========================================================================== */

a {
  color: var(--text-color);
  text-decoration-thickness: var(--border-thickness);
}

a:link,
a:visited {
  color: var(--text-color);
}

/* ==========================================================================
   Header
   ========================================================================== */

.header {
  width: 100%;

  margin: 0 0 calc(var(--line-height) * 2);

  border-collapse: collapse;
}

.header h1 {
  margin: 0;
}

.header .subtitle {
  display: inline-block;
}

.header tr td:last-child {
  text-align: right;
}

/* ==========================================================================
   Navigation
   ========================================================================== */

nav {
  margin: 0 0 calc(var(--line-height) * 2);
}

nav h2 {
  margin-top: 0;
}

nav[aria-label="Form actions"] {
  display: flex;
  gap: 1ch;

  margin-bottom: var(--line-height);
}

/* ==========================================================================
   Sections
   ========================================================================== */

section {
  margin: 0;
}

section + section {
  margin-top: calc(var(--line-height) * 2);
}

/* ==========================================================================
   Horizontal Rule
   ========================================================================== */

hr {
  position: relative;

  display: block;

  height: var(--line-height);

  margin: calc(var(--line-height) * 1.5) 0;

  border: 0;
  color: var(--text-color);
}

hr::after {
  content: "";

  position: absolute;
  top: calc(var(--line-height) / 2 - var(--border-thickness));
  left: 0;

  width: 100%;
  height: 0;

  border-top: calc(var(--border-thickness) * 3) double var(--text-color);
}

/* ==========================================================================
   Tables
   ========================================================================== */

table {
  position: relative;
  top: calc(var(--line-height) / 2);

  width: calc(round(down, 100%, 1ch));

  margin: 0 0 calc(var(--line-height) * 2);

  border-collapse: collapse;
}

th,
td {
  padding: calc(var(--line-height) / 2) calc(1ch - var(--border-thickness) / 2)
    calc(var(--line-height) / 2 - var(--border-thickness));

  border: var(--border-thickness) solid var(--text-color);

  line-height: var(--line-height);
  text-align: left;
  vertical-align: top;
}

table tbody tr:first-child > * {
  padding-top: calc(var(--line-height) / 2 - var(--border-thickness));
}

th {
  font-weight: var(--font-weight-bold);
}

.width-min {
  width: 0%;
}

.width-auto {
  width: 100%;
}

/* ==========================================================================
   Details
   ========================================================================== */

details {
  margin: 0 0 var(--line-height);
  padding: calc(var(--line-height) - var(--border-thickness)) 1ch;

  border: var(--border-thickness) solid var(--text-color);
}

summary {
  font-weight: var(--font-weight-medium);
  cursor: pointer;
}

details[open] summary {
  margin-bottom: var(--line-height);
}

details ::marker {
  content: "▶";
}

details[open] ::marker {
  content: "▼";
}

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

/* ==========================================================================
   Lists
   ========================================================================== */

ul,
ol {
  margin: 0 0 var(--line-height);
  padding: 0;
}

ul {
  padding-left: 2ch;
  list-style-type: square;
}

ol {
  list-style: none;
  counter-reset: item;
}

ol li::before {
  content: counters(item, ".") ". ";

  counter-increment: item;

  font-weight: var(--font-weight-medium);
}

ol ol,
ul ol,
ol ul,
ul ul {
  margin: 0;
  padding-left: 3ch;
}

li {
  margin: 0;
  padding: 0;
}

li::marker {
  line-height: 0;
}

/* ==========================================================================
   Tree
   ========================================================================== */

.tree,
.tree ul {
  position: relative;

  margin: 0;
  padding-left: 0;

  list-style: none;
  line-height: var(--line-height);
}

.tree ul li {
  position: relative;

  margin-left: 1.5ch;
  padding-left: 1.5ch;

  border-left: var(--border-thickness) solid var(--text-color);
}

.tree ul li::before {
  content: "";

  position: absolute;
  top: calc(var(--line-height) / 2);
  left: 0;

  width: 1ch;

  border-bottom: var(--border-thickness) solid var(--text-color);
}

.tree ul li:last-child {
  border-left: 0;
}

.tree ul li:last-child::after {
  content: "";

  position: absolute;
  top: 0;
  left: 0;

  height: calc(var(--line-height) / 2);

  border-left: var(--border-thickness) solid var(--text-color);
}

/* ==========================================================================
   Code / Preformatted Content
   ========================================================================== */

pre,
code {
  font-family: var(--font-family);
}

code {
  font-weight: var(--font-weight-medium);
}

pre {
  margin: var(--line-height) 0;

  overflow-x: auto;
  overflow-y: hidden;

  white-space: pre;
}

figure pre {
  margin: 0;
}

figure {
  margin: calc(var(--line-height) * 2) 3ch;

  overflow-x: auto;
  overflow-y: hidden;
}

figcaption {
  display: block;

  margin-top: var(--line-height);

  font-style: italic;
}

/* ==========================================================================
   Media
   ========================================================================== */

img,
video {
  display: block;

  width: 100%;

  object-fit: contain;
  overflow: hidden;
}

img {
  color: var(--text-color-alt);
  font-style: italic;
}

/* ==========================================================================
   Forms
   ========================================================================== */

input,
button,
textarea {
  width: auto;
  height: calc(var(--line-height) * 2);

  margin: 0;
  padding: calc(var(--line-height) / 2 - var(--border-thickness))
    calc(1ch - var(--border-thickness));

  border: var(--border-thickness) solid var(--text-color);

  background: var(--background-color);
  color: var(--text-color);

  font: inherit;
  font-weight: inherit;
  line-height: normal;

  overflow: visible;

  -webkit-appearance: none;
  -webkit-font-smoothing: inherit;
  -moz-osx-font-smoothing: inherit;
}

input {
  width: calc(round(down, 100%, 1ch));
}

input[type="checkbox"],
input[type="radio"] {
  display: inline-grid;
  place-content: center;

  width: 2ch;
  height: var(--line-height);

  vertical-align: top;

  cursor: pointer;
}

input[type="checkbox"]:checked::before,
input[type="radio"]:checked::before {
  content: "";

  width: 1ch;
  height: calc(var(--line-height) / 2);

  background: var(--text-color);
}

input[type="radio"],
input[type="radio"]::before {
  border-radius: 100%;
}

textarea {
  min-height: calc(var(--line-height) * 4);
  resize: vertical;
}

label {
  display: block;

  width: calc(round(down, 100%, 1ch));

  margin: 0;

  font-weight: var(--font-weight-medium);
  line-height: var(--line-height);
}

label input {
  width: 100%;
}

::placeholder {
  color: var(--text-color-alt);
  opacity: 1;
}

button {
  text-transform: uppercase;
  font-weight: var(--font-weight-medium);
  cursor: pointer;
}

button:hover {
  background: var(--background-color-alt);
}

button:active {
  transform: translate(2px, 2px);
}

button:focus,
input:focus,
textarea:focus {
  --border-thickness: 3px;

  outline: none;
}

button::-moz-focus-inner {
  padding: 0;
  border: 0;
}

/* ==========================================================================
   Grid
   ========================================================================== */

.grid {
  --grid-cells: 0;

  display: flex;
  gap: 1ch;

  width: calc(
    round(down, 100%, (1ch * var(--grid-cells)) - (1ch * var(--grid-cells) - 1))
  );

  margin: 0 0 var(--line-height);
}

.grid > *,
.grid > input {
  flex: 0 0
    calc(
      round(
        down,
        (100% - (1ch * (var(--grid-cells) - 1))) / var(--grid-cells),
        1ch
      )
    );
}

.grid:has(> :last-child:nth-child(1)) {
  --grid-cells: 1;
}

.grid:has(> :last-child:nth-child(2)) {
  --grid-cells: 2;
}

.grid:has(> :last-child:nth-child(3)) {
  --grid-cells: 3;
}

.grid:has(> :last-child:nth-child(4)) {
  --grid-cells: 4;
}

.grid:has(> :last-child:nth-child(5)) {
  --grid-cells: 5;
}

.grid:has(> :last-child:nth-child(6)) {
  --grid-cells: 6;
}

.grid:has(> :last-child:nth-child(7)) {
  --grid-cells: 7;
}

.grid:has(> :last-child:nth-child(8)) {
  --grid-cells: 8;
}

.grid:has(> :last-child:nth-child(9)) {
  --grid-cells: 9;
}

/* ==========================================================================
   Focus / Accessibility
   ========================================================================== */

:focus-visible {
  outline: var(--border-thickness) solid var(--text-color);
  outline-offset: 2px;
}

/* ==========================================================================
   Scrollbars
   ========================================================================== */

::-webkit-scrollbar {
  height: var(--line-height);
}

/* ==========================================================================
   Debug
   ========================================================================== */

.debug .debug-grid {
  --debug-color: color-mix(
    in srgb,
    var(--text-color) 10%,
    var(--background-color) 90%
  );

  position: absolute;
  inset: 0;
  z-index: -1;

  margin: 0;

  background-image:
    repeating-linear-gradient(var(--debug-color) 0 1px, transparent 1px 100%),
    repeating-linear-gradient(
      90deg,
      var(--debug-color) 0 1px,
      transparent 1px 100%
    );

  background-size: 1ch var(--line-height);
}

.debug .off-grid {
  background: rgb(255 0 0 / 10%);
}

.debug-toggle-label {
  display: block;

  margin: 0 0 calc(var(--line-height) * 2);

  text-align: right;
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media screen and (max-width: 480px) {
  :root {
    --font-size: 14px;
  }

  body {
    padding-right: 1ch;
    padding-left: 1ch;
  }

  figure {
    margin-right: 1ch;
    margin-left: 1ch;
  }
}
