/*
 * Monospace template
 * Based on "The Monospace Web" by Oskar Wickström (MIT License)
 * https://owickstrom.github.io/the-monospace-web/
 *
 * Everything sits on a character grid: 1ch wide, 1 line-height tall.
 * Keep widths in ch and vertical spacing in multiples of --line-height.
 */

@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,100..800;1,100..800&display=swap");

:root {
  --font-family: "JetBrains Mono", ui-monospace, monospace;
  --line-height: 1.2rem;
  --border-thickness: 2px;

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

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

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

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --text-color: #fff;
    --text-color-alt: #aaa;
    --background-color: #000;
    --background-color-alt: #111;
  }
}
:root[data-theme="dark"] {
  --text-color: #fff;
  --text-color-alt: #aaa;
  --background-color: #000;
  --background-color-alt: #111;
}

* {
  box-sizing: border-box;
}

html {
  display: flex;
  width: 100%;
  margin: 0;
  padding: 0;
  flex-direction: column;
  align-items: center;
  background: var(--background-color);
  color: var(--text-color);
}

body {
  position: relative;
  width: 100%;
  margin: 0;
  padding: var(--line-height) 2ch;
  max-width: calc(min(80ch, round(down, 100%, 1ch)));
  line-height: var(--line-height);
  overflow-x: hidden;
  background: var(--background-color);
}

@media screen and (max-width: 480px) {
  :root {
    font-size: 14px;
  }
  body {
    padding: var(--line-height) 1ch;
  }
}

/* ---------- Typography ---------- */

h1, h2, h3, h4, h5, h6 {
  font-weight: var(--font-weight-bold);
  margin: calc(var(--line-height) * 2) 0 var(--line-height);
  line-height: var(--line-height);
}

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

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

h3, h4, h5, h6 {
  font-size: 1rem;
}

p {
  margin: 0 0 var(--line-height);
  word-break: break-word;
  word-wrap: break-word;
  hyphens: auto;
}

/* Body text is justified; hyphenation keeps the word spacing even. */
p,
li,
blockquote {
  text-align: justify;
  hyphens: auto;
}

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

em {
  font-style: italic;
}

small, .muted {
  color: var(--text-color-alt);
  font-size: 1rem;
}

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

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

a:hover {
  background: var(--text-color);
  color: var(--background-color);
  text-decoration: none;
}

blockquote {
  margin: 0 0 var(--line-height);
  padding: 0 0 0 calc(2ch - var(--border-thickness));
  border-left: var(--border-thickness) solid var(--text-color);
  font-style: italic;
}

sub {
  position: relative;
  display: inline-block;
  margin: 0;
  vertical-align: sub;
  line-height: 0;
  width: calc(1ch / 0.75);
  font-size: 0.75rem;
}

hr {
  position: relative;
  display: block;
  height: var(--line-height);
  margin: calc(var(--line-height) * 1.5) 0;
  border: none;
  color: var(--text-color);
}

hr::after {
  display: block;
  content: "";
  position: absolute;
  top: calc(var(--line-height) / 2 - var(--border-thickness));
  left: 0;
  width: 100%;
  border-top: calc(var(--border-thickness) * 3) double var(--text-color);
  height: 0;
}

hr.thin::after {
  top: calc(var(--line-height) / 2 - var(--border-thickness) / 2);
  border-top: var(--border-thickness) solid var(--text-color);
}

/* ---------- Header table ---------- */

.header {
  margin-bottom: calc(var(--line-height) * 2);
}

.header h1 {
  margin: 0;
}

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

/* ---------- Navigation ---------- */

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

nav ul {
  display: flex;
  flex-wrap: wrap;
  gap: 0 2ch;
  list-style: none;
  padding: 0;
  margin: 0;
}

nav a {
  font-weight: var(--font-weight-medium);
  text-transform: uppercase;
  text-decoration: none;
}

nav a::before { content: "["; }
nav a::after { content: "]"; }

nav a[aria-current="page"] {
  background: var(--text-color);
  color: var(--background-color) !important;
}

/* ---------- Tables ---------- */

table {
  position: relative;
  top: calc(var(--line-height) / 2);
  width: calc(round(down, 100%, 1ch));
  border-collapse: collapse;
  margin: 0 0 calc(var(--line-height) * 2);
}

th, td {
  border: var(--border-thickness) solid var(--text-color);
  padding:
    calc((var(--line-height) / 2))
    calc(1ch - var(--border-thickness) / 2)
    calc((var(--line-height) / 2) - (var(--border-thickness)));
  line-height: var(--line-height);
  vertical-align: top;
  text-align: left;
}

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

th {
  font-weight: 700;
}

.width-min {
  width: 0%;
}

.width-auto {
  width: 100%;
}

/* ---------- Media ---------- */

img, video {
  display: block;
  width: 100%;
  object-fit: contain;
  overflow: hidden;
}

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

figure {
  margin: calc(var(--line-height) * 2) 3ch;
  overflow-x: auto;
  overflow-y: hidden;
}

figure pre {
  margin: 0;
}

figcaption {
  display: block;
  text-align: center;
  margin-top: var(--line-height);
  color: var(--text-color-alt);
}

/* ---------- Details ---------- */

details {
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) - var(--border-thickness)) 1ch;
  margin-bottom: var(--line-height);
}

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

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

details ::marker {
  display: inline-block;
  content: "▶ ";
  margin: 0;
}

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

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

/* ---------- Code ---------- */

pre {
  white-space: pre;
  overflow-x: auto;
  margin: var(--line-height) 0;
  overflow-y: hidden;
}

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

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

pre.box {
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) - var(--border-thickness)) calc(1ch - var(--border-thickness));
}

/* ---------- Lists ---------- */

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

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

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

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

ol li::before {
  content: counters(item, ".") ". ";
  counter-increment: item;
  font-weight: var(--font-weight-medium);
}

li {
  margin: 0;
  padding: 0;
}

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

/* Directory-style tree */

.tree, .tree ul {
  position: relative;
  padding-left: 0;
  list-style-type: none;
  line-height: var(--line-height);
}

.tree ul {
  margin: 0;
}

.tree ul li {
  position: relative;
  padding-left: 1.5ch;
  margin-left: 1.5ch;
  border-left: var(--border-thickness) solid var(--text-color);
}

.tree ul li::before {
  position: absolute;
  display: block;
  top: calc(var(--line-height) / 2);
  left: 0;
  content: "";
  width: 1ch;
  border-bottom: var(--border-thickness) solid var(--text-color);
}

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

.tree ul li:last-child::after {
  position: absolute;
  display: block;
  top: 0;
  left: 0;
  content: "";
  height: calc(var(--line-height) / 2);
  border-left: var(--border-thickness) solid var(--text-color);
}

/* Post index: date column + title */

.post-list {
  list-style: none;
  padding: 0;
}

.post-list li {
  display: flex;
  gap: 2ch;
}

.post-list time {
  flex: 0 0 auto;
  color: var(--text-color-alt);
}

/* ---------- Forms ---------- */

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

input, button, textarea, select {
  border: var(--border-thickness) solid var(--text-color);
  padding:
    calc(var(--line-height) / 2 - var(--border-thickness))
    calc(1ch - var(--border-thickness));
  margin: 0;
  font: inherit;
  font-weight: inherit;
  height: calc(var(--line-height) * 2);
  width: auto;
  overflow: visible;
  background: var(--background-color);
  color: var(--text-color);
  line-height: normal;
  border-radius: 0;
  -webkit-font-smoothing: inherit;
  -moz-osx-font-smoothing: inherit;
  -webkit-appearance: none;
  appearance: none;
}

textarea {
  display: block;
  width: calc(round(down, 100%, 1ch));
  height: calc(var(--line-height) * 6);
  line-height: var(--line-height);
  resize: vertical;
}

input[type="checkbox"],
input[type="radio"] {
  display: inline-grid;
  place-content: center;
  vertical-align: top;
  width: 2ch;
  height: var(--line-height);
  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%;
}

button:focus,
input:focus,
textarea:focus,
select:focus {
  --border-thickness: 3px;
  outline: none;
}

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

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

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

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);
}

label {
  display: block;
  width: calc(round(down, 100%, 1ch));
  height: auto;
  line-height: var(--line-height);
  font-weight: var(--font-weight-medium);
  margin: 0;
}

label input,
label textarea {
  width: 100%;
}

label.inline {
  display: inline;
  width: auto;
}

/* ---------- Grid ---------- */

.grid {
  display: flex;
  gap: 1ch;
  width: 100%;
  margin-bottom: var(--line-height);
}

.grid > *,
.grid > input {
  flex: 1 1 0;
  min-width: 0;
}

@media screen and (max-width: 480px) {
  .grid.stack-mobile {
    flex-direction: column;
    gap: var(--line-height);
  }
}

/* Bordered card on the grid */

.card {
  border: var(--border-thickness) solid var(--text-color);
  padding: calc(var(--line-height) - var(--border-thickness)) calc(1ch - var(--border-thickness));
}

.card h3 {
  margin-top: 0;
}

.card :last-child {
  margin-bottom: 0;
}

/* ---------- Footer ---------- */

footer {
  margin-top: calc(var(--line-height) * 2);
  color: var(--text-color-alt);
}

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

/* ---------- Debug grid ---------- */

.debug-toggle-label {
  text-align: right;
}

.debug .debug-grid {
  --color: color-mix(in srgb, var(--text-color) 10%, var(--background-color) 90%);
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 0;
  pointer-events: none;
  background-image:
    repeating-linear-gradient(var(--color) 0 1px, transparent 1px 100%),
    repeating-linear-gradient(90deg, var(--color) 0 1px, transparent 1px 100%);
  background-size: 1ch var(--line-height);
  margin: 0;
}

.debug .off-grid {
  background: rgba(255, 0, 0, 0.1);
}

/* ======================================================
 * Personal-site additions
 * ====================================================== */

/* Placeholder text you still need to fill in. Search the HTML for "todo". */
.todo {
  outline: var(--border-thickness) dashed var(--text-color-alt);
  outline-offset: -1px;
  color: var(--text-color-alt);
}

.center {
  text-align: center;
}

/* Two-column line: left label, right-aligned date/place */
.entry {
  display: flex;
  justify-content: space-between;
  gap: 2ch;
  margin: 0;
}

.entry > :last-child {
  text-align: right;
  white-space: nowrap;
}

.entry + ul {
  margin-top: 0;
}

/* Footnotes, for posts that cite authority */
sup {
  line-height: 0;
  font-size: 0.75rem;
}

sup a {
  text-decoration: none;
}

.footnotes {
  color: var(--text-color-alt);
}

.footnotes ol li::before {
  color: var(--text-color);
}

/* Legal disclaimer in the footer */
.disclaimer {
  color: var(--text-color-alt);
}

/* Print button on the résumé page */
.print-bar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: var(--line-height);
}

/* ---------- Print: the résumé page prints as a clean one-pager ---------- */

@media print {
  :root {
    --text-color: #000;
    --text-color-alt: #333;
    --background-color: #fff;
    font-size: 10pt;
  }

  @page {
    margin: 0.5in;
  }

  body {
    max-width: none;
    padding: 0;
  }

  nav,
  footer,
  .print-bar,
  .debug-grid,
  .no-print {
    display: none !important;
  }

  a:link,
  a:visited {
    text-decoration: none;
  }

  h2 {
    margin-top: var(--line-height);
  }

  .resume h1 {
    margin-bottom: 0;
  }

  .todo {
    outline: none;
  }
}
