/* bergmandavid.com
   A pond at noon (light) and a pond at night (dark). Everything is drawn
   with one monospace family; the koi are the only color. */

:root {
  --mono: "Spline Sans Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;
  --adv: 0.6;
  --gutter: clamp(20px, 5vw, 40px);

  --bg: #e6e9e3;
  --ink: #1e2622;
  --muted: #5d6762;
  --faint: #a4ada7;
  --rule: rgba(30, 38, 34, 0.14);
  --accent: #ad4824;
  --select: rgba(173, 72, 36, 0.16);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0f1715;
  --ink: #d5dbd2;
  --muted: #7f8c86;
  --faint: #3d4a45;
  --rule: rgba(213, 219, 210, 0.11);
  --accent: #e2794a;
  --select: rgba(226, 121, 74, 0.22);
  color-scheme: dark;
}

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

html {
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100svh;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--mono);
  font-size: 13.5px;
  font-weight: 400;
  line-height: 1.8;
  letter-spacing: -0.01em;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  transition: background-color 400ms ease, color 400ms ease;
}

::selection {
  background: var(--select);
}

p {
  margin: 0;
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  transition: color 160ms ease, text-decoration-color 160ms ease;
}

a:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

:focus-visible {
  outline: 1px dashed var(--accent);
  outline-offset: 4px;
  border-radius: 1px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* ------------------------------------------------------------- navigation */

.nav {
  position: absolute;
  z-index: 20;
  top: 18px;
  left: 50%;
  display: flex;
  align-items: center;
  gap: 4px;
  transform: translateX(-50%);
  font-size: 12.5px;
  view-transition-name: nav;
}

.nav a,
.nav button {
  padding: 6px 11px;
  color: var(--muted);
  text-decoration: none;
}

.nav a:hover,
.nav button:hover {
  color: var(--ink);
}

.nav a[aria-current="page"] {
  position: relative;
  color: var(--ink);
}

/* The current page sits on a small ripple. */
.nav a[aria-current="page"]::after {
  content: "~";
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  color: var(--accent);
  font-size: 12px;
  line-height: 1;
}

.theme-toggle {
  display: grid;
  place-items: center;
  margin: 0 0 0 4px;
  border: 0;
  background: none;
  font: inherit;
  cursor: pointer;
}

.theme-toggle svg {
  display: block;
  width: 15px;
  height: 15px;
}

.theme-toggle .moon,
:root[data-theme="dark"] .theme-toggle .sun {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .moon {
  display: block;
}

/* --------------------------------------------------------------- the pond */

.pond-canvas {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: manipulation;
  cursor: crosshair;
}

.pond-hud {
  position: fixed;
  z-index: 20;
  top: 24px;
  right: var(--gutter);
  display: grid;
  grid-template-columns: auto auto;
  column-gap: 12px;
  font-size: 11.5px;
  line-height: 1.6;
  color: var(--muted);
  pointer-events: none;
  font-variant-numeric: tabular-nums;
}

.pond-hud dd {
  margin: 0;
  color: var(--ink);
  text-align: right;
}

.pond-hud button {
  pointer-events: auto;
  text-decoration-color: var(--faint);
}

.pond-hud dt {
  margin: 0;
}

.koi-label {
  position: fixed;
  z-index: 15;
  top: 0;
  left: 0;
  font-size: 11.5px;
  line-height: 1.5;
  color: var(--ink);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transition: opacity 240ms ease;
}

.koi-label.is-visible {
  opacity: 1;
}

.koi-label span {
  display: block;
  color: var(--muted);
}

.home {
  position: relative;
  z-index: 1;
  display: grid;
  align-content: end;
  min-height: 100svh;
  padding: 120px var(--gutter) max(14vh, 64px) clamp(24px, 14vw, 232px);
  pointer-events: none;
}

.intro {
  position: relative;
  max-width: 54ch;
  pointer-events: auto;
}

.couplet {
  min-height: calc(2 * 1.8em);
  margin-bottom: 30px;
  color: var(--muted);
  white-space: pre-line;
}

.caret {
  display: inline-block;
  width: 0.58em;
  height: 1.08em;
  margin-left: 2px;
  vertical-align: -0.18em;
  background: currentColor;
  opacity: 0.85;
}

.is-resting .caret {
  animation: blink 1.15s steps(1) infinite;
}

@keyframes blink {
  50% {
    opacity: 0;
  }
}

.bio p + p {
  margin-top: 2px;
}

.links {
  margin-top: 22px;
  color: var(--muted);
}

.links a {
  color: var(--muted);
}

.links a:hover {
  color: var(--accent);
}

/* ------------------------------------------------------------ inner pages */

.page {
  width: min(100% - 2 * var(--gutter), 760px);
  margin: clamp(96px, 16vh, 148px) auto 112px;
}

.page-head {
  margin-bottom: 64px;
}

.page-head .couplet {
  min-height: 1.8em;
  margin: 0 0 6px;
  color: var(--ink);
  font: inherit;
}

.page-head p {
  color: var(--muted);
}

.page-sub {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 24px;
}

.text-button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-decoration-color: var(--faint);
  text-decoration-thickness: 1px;
  text-underline-offset: 4px;
  cursor: pointer;
}

.text-button:hover {
  color: var(--accent);
  text-decoration-color: currentColor;
}

/* --------------------------------------------------------------- projects */

.plate {
  margin: 0 0 88px;
}

.drawing {
  display: grid;
  justify-items: center;
  padding: clamp(18px, 6%, 44px) clamp(10px, 3%, 24px);
  border: 1px solid var(--rule);
  border-bottom: 0;
  container-type: inline-size;
  overflow: hidden;
}

.drawing.is-interactive {
  cursor: pointer;
}

/* Ink and accent layers sit in the same cell, so they always align. */
.drawing pre {
  grid-area: 1 / 1;
  margin: 0;
  font-family: var(--mono);
  font-size: min(12.5px, calc(100cqi / (var(--cols, 64) * var(--adv)) - 0.1px));
  line-height: 1.3;
  letter-spacing: 0;
  color: var(--ink);
  white-space: pre;
  user-select: none;
}

.drawing pre + pre {
  color: var(--accent);
}

.title-block {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  border: 1px solid var(--rule);
  font-size: 12px;
  line-height: 1.5;
}

.title-block > * {
  padding: 9px 14px;
}

.title-block > * + * {
  border-left: 1px solid var(--rule);
  color: var(--muted);
}

.title-block h2 {
  margin: 0;
  font-size: inherit;
  font-weight: 500;
}

.plate-notes {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 6px 24px;
  margin-top: 14px;
}

.plate-notes p {
  max-width: 58ch;
}

.plate-notes .plate-links {
  color: var(--muted);
}

/* ----------------------------------------------------------------- photos */

.photos {
  columns: 2;
  column-gap: 32px;
}

.photo {
  break-inside: avoid;
  margin: 0 0 40px;
}

.photo-frame {
  position: relative;
  display: block;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  cursor: crosshair;
}

.photo-frame img {
  display: block;
  width: 100%;
  height: auto;
}

/* Until its characters are drawn, keep the photo itself out of sight. */
.js .photo-frame:not(.is-ready) img {
  visibility: hidden;
}

.photo-frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.photo figcaption {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  font-size: 12px;
  color: var(--muted);
}

/* ------------------------------------------------------------------- blog */

.stillwater {
  display: grid;
  place-items: center;
  min-height: 100svh;
  padding: 96px var(--gutter) 64px;
}

.stillwater-scene {
  width: min(100%, 720px);
}

.stillwater canvas {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  cursor: crosshair;
}

.stillwater .couplet {
  min-height: 1.8em;
  margin: 18px 0 0;
  color: var(--muted);
  font: inherit;
  text-align: center;
}

/* -------------------------------------------------------------------- 404 */

.empty-water {
  text-align: center;
}

.empty-water .ring {
  display: inline-block;
  margin: 0 0 36px;
  color: var(--muted);
  font: inherit;
  line-height: 1.25;
  text-align: left;
  animation: drift 7s ease-in-out infinite;
}

.empty-water h1 {
  margin: 0 0 4px;
  font: inherit;
  font-weight: 500;
}

.empty-water p {
  color: var(--muted);
}

@keyframes drift {
  50% {
    opacity: 0.45;
    transform: scale(1.04);
  }
}

/* ------------------------------------------------------------- transitions */

@view-transition {
  navigation: auto;
}

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 320ms;
}

/* ----------------------------------------------------------------- mobile */

@media (max-width: 640px) {
  body {
    font-size: 13px;
  }

  .nav {
    top: 12px;
    font-size: 12px;
  }

  .nav a,
  .nav button {
    padding: 6px 7px;
  }

  .pond-hud {
    top: auto;
    bottom: 16px;
    left: var(--gutter);
    grid-template-columns: repeat(3, auto auto);
    justify-content: start;
    column-gap: 8px;
  }

  .pond-hud dd {
    margin-right: 14px;
  }

  .home {
    padding-left: var(--gutter);
    padding-bottom: 64px;
  }

  .photos {
    columns: 1;
  }

  .stillwater canvas {
    aspect-ratio: 4 / 3;
  }

  .title-block {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .title-block > :last-child {
    grid-column: 1 / -1;
    border-left: 0;
    border-top: 1px solid var(--rule);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition: none !important;
    animation: none !important;
  }

  @view-transition {
    navigation: none;
  }
}
