/* SPDX-License-Identifier: MIT */
/* Light/dark toggle button and dark theme (loaded after custom.css). */

/* ---- Theme toggle ---- */
#theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.4em;
  padding: 0.15rem 0.6rem;
  font: inherit;
  font-size: 1.2rem;
  color: inherit;
  background: none;
  border: 1px solid currentColor;
  border-radius: 999px;
  cursor: pointer;
}
#theme-toggle:hover,
#theme-toggle:focus-visible {
  background-color: var(--highlight-weak);
}

/* ---- Theme variables ---- */
:root {
  --theme-bg: #ffffff;
  --theme-outer: #ececec;
  --theme-text: #111;
  --theme-border: #999;
}
html[data-theme="dark"] {
  --theme-bg: #0b0b0b;
  --theme-outer: #151515;
  --theme-text: #ddd;
  --theme-border: #3a3a3a;
  color-scheme: dark;
}
/* Follow the OS preference when no choice has been made (works without JS) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --theme-bg: #0b0b0b;
    --theme-outer: #151515;
    --theme-text: #ddd;
    --theme-border: #3a3a3a;
    color-scheme: dark;
  }
}

/* Page background around the column; body is the "paper" on top of it */
html {
  background-color: var(--theme-outer);
}
body {
  background-color: var(--theme-bg);
  color: var(--theme-text);
}
code,
pre {
  color: var(--theme-text);
}

/* Tufte paints its link underline with a hardcoded background colour;
   repaint it with the theme background so it works in both themes. */
a:link {
  background-image: linear-gradient(var(--theme-bg), var(--theme-bg)),
    linear-gradient(var(--theme-bg), var(--theme-bg)),
    linear-gradient(currentColor, currentColor);
  text-shadow: .03em 0em var(--theme-bg),-.03em 0em var(--theme-bg),0em .03em var(--theme-bg),0em -.03em var(--theme-bg),.06em 0em var(--theme-bg),-.06em 0em var(--theme-bg),.09em 0em var(--theme-bg),-.09em 0em var(--theme-bg),.12em 0em var(--theme-bg),-.12em 0em var(--theme-bg),.15em 0em var(--theme-bg),-.15em 0em var(--theme-bg);
}
header nav a {
  text-decoration: none;
}

/* Page-like column: visible vertical borders at the margins on wide screens */
@media (min-width: 900px) {
  body {
    box-sizing: border-box;
    min-height: 100vh;
    /* extra room between the border and the text; max-width grows to match */
    padding: 0 4.5rem;
    max-width: 80rem;
    border-left: 1px solid var(--theme-border);
    border-right: 1px solid var(--theme-border);
  }
}

/* Header: nav on the left, credits and theme toggle on the right.
   On narrow screens the credits drop to their own row below, and the toggle
   stays on the nav's row. */
header {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  column-gap: 1rem;
  padding-top: 2.1rem;
}
/* Tufted gives the links a top margin that throws off vertical centring; the
   space lives in the header padding instead. */
header nav a,
header nav a:link,
header nav a:visited { margin-top: 0; }
header > nav { grid-column: 1; grid-row: 1; flex-wrap: wrap; row-gap: 0; }
header nav a { white-space: nowrap; }
#made-with {
  grid-column: 2;
  grid-row: 1;
  font-size: 1.1rem;
  opacity: 0.7;
}
#theme-toggle { grid-column: 3; grid-row: 1; }

@media (max-width: 640px) {
  header { grid-template-columns: 1fr auto; row-gap: 0.4rem; }
  #theme-toggle { grid-column: 2; }
  #made-with { grid-column: 1 / -1; grid-row: 2; text-align: right; }
  /* Keep the nav on a single line: the font scales with the viewport (capped
     at its desktop size) and the link spacing shrinks with it. */
  header > nav { flex-wrap: nowrap; gap: 0.2em; }
  header nav a,
  header nav a:link,
  header nav a:visited {
    font-size: min(1.5rem, calc(6vw - 8px));
    padding: 0.2em 0.3em;
  }
  /* Link-icon links are nowrap, which pushes long ones (like the home page's
     "Open source" row) past the right edge; let them wrap on phones. */
  td a,
  td a:link,
  td a:visited { white-space: normal !important; }
}

/* 404 page: the cookie and its two buttons */
.lost {
  text-align: center;
}
.lost .cookie {
  display: block;
  margin: 0 auto 1rem;
  width: 9rem;
  height: 9rem;
  transition: opacity 0.35s ease;
}
.lost .cookie.gone {
  opacity: 0; /* keeps its space, so the text below doesn't jump */
}
.lost-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 1.5rem;
}
.btn,
a.btn,
a.btn:link,
a.btn:visited {
  display: inline-block;
  padding: 0.3rem 1.2rem;
  font: inherit;
  font-size: 1.4rem;
  line-height: 1.6;
  color: inherit;
  background: none;
  background-image: none;
  text-shadow: none;
  text-decoration: none;
  border: 1px solid currentColor;
  border-radius: 999px;
  cursor: pointer;
}
.btn:hover:not(:disabled),
.btn:focus-visible {
  background-color: var(--highlight-weak);
}
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
