/* ---------- fonts ---------- */
@font-face {
  font-family: 'EB Garamond';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/eb-garamond-latin-400-normal.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'EB Garamond';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/eb-garamond-latin-400-italic.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: 'EB Garamond';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/eb-garamond-latin-ext-400-normal.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: 'EB Garamond';
  font-style: italic;
  font-weight: 400;
  font-display: swap;
  src: url('../fonts/eb-garamond-latin-ext-400-italic.woff2') format('woff2');
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- tokens ---------- */
:root {
  --bg: #000;
  --fg: #ededed;
  --muted: #8c8c8c;
  --faint: #3a3a3a;
  --ink: #ece7dc; /* the loader's drawing ink: a warm bone white */
  --serif: 'EB Garamond', 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  color-scheme: dark;
}

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

html {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  position: relative;
  margin: 0;
  background: var(--bg);
}

::selection {
  background: var(--fg);
  color: var(--bg);
}

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.18em;
  text-decoration-color: var(--muted);
  transition: text-decoration-color 0.2s, color 0.2s;
}
a:hover {
  text-decoration-color: currentColor;
}
:focus-visible {
  outline: 1px dashed var(--fg);
  outline-offset: 3px;
}
main:focus {
  outline: none;
}

/* ---------- page: one narrow column, centred when short (after nel.ag) ---------- */
#page {
  position: relative;
  z-index: 1;
  width: min(31rem, 100% - 32px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: 5.5rem 0 6rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  transition: opacity 0.18s ease;
}
#page.leaving,
#page.entering {
  opacity: 0;
}

header {
  margin-bottom: 1.6rem;
}
.name {
  font-style: italic;
  text-decoration: none;
}
header nav {
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1.1rem;
  margin-top: 0.15rem;
  font-size: 0.9rem;
}
header nav a {
  color: var(--muted);
  text-decoration: none;
}
header nav a:hover,
header nav a[aria-current] {
  color: var(--fg);
}
header nav a[aria-current] {
  text-decoration: underline;
  text-decoration-color: var(--muted);
}

/* ---------- content (markdown) ---------- */
main > :first-child {
  margin-top: 0;
}
main h1,
main h2,
main h3 {
  font-size: 1rem;
  font-weight: 400;
  line-height: 1.35;
}
main h1 {
  font-style: italic;
  margin: 0 0 1rem;
}
main h2 {
  color: var(--muted);
  font-style: italic;
  margin: 1.8rem 0 0.4rem;
}
main h3 {
  margin: 1.4rem 0 0.3rem;
}
main p {
  margin: 0 0 0.9rem;
}
main ul,
main ol {
  margin: 0 0 0.9rem;
  padding-left: 1.1rem;
}
main li {
  margin: 0.15rem 0;
}
main li::marker {
  color: var(--muted);
}
main blockquote {
  margin: 1.2rem 0;
  padding-left: 1rem;
  border-left: 1px solid var(--faint);
  color: var(--muted);
}
main hr {
  border: 0;
  border-top: 1px solid var(--faint);
  margin: 1.8rem 0;
}
main img {
  max-width: 100%;
  height: auto;
}
main code {
  font-size: 0.85em;
}
main strong {
  font-weight: 600;
  background: linear-gradient(100deg, #178f86, #0e6b67, #5cc9bd, #1f9e93, #178f86);
  background-size: 250% 100%;
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  -webkit-text-fill-color: transparent;
  animation: shimmer 6s ease-in-out infinite;
}

@keyframes shimmer {
  0%,
  100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

/* ---------- folded sections: hidden until their link is clicked (folds.js) ---------- */
.js .fold {
  display: none;
}
.js .fold.open {
  display: block;
  animation: unfold 0.35s ease;
}
@keyframes unfold {
  from {
    opacity: 0;
    transform: translateY(-4px);
  }
}
main a[aria-expanded='true'] {
  text-decoration-color: currentColor;
}

/* ---------- writings: the list of posts, and each post's date ---------- */
.posts {
  list-style: none;
  margin: 0;
  padding: 0;
}
.posts li {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 1rem;
  margin: 0 0 0.35rem;
}
.posts time,
.post-date {
  color: var(--muted);
  font-size: 0.85rem;
  white-space: nowrap;
}
.post-date {
  margin: -0.6rem 0 1.4rem;
  font-style: italic;
}

/* ---------- habit tracker (habits.js) ---------- */
.habits {
  margin: 1.8rem 0 1rem;
}
.habits-scroll {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
}
.habits-scroll::-webkit-scrollbar {
  display: none;
}
.habits-grid {
  display: block;
  flex: none;
  margin-left: auto; /* today stays at the right edge even when there's room to spare */
}
.habits-cursor {
  fill: none;
  stroke: var(--fg);
  stroke-opacity: 0.6;
  pointer-events: none;
}
.habits.editing .habits-grid {
  cursor: pointer;
}
.habits-info {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  height: 1.35em; /* a long name's second line hangs into the space below instead of pushing it */
  margin-top: 0.4rem;
  font-size: 0.78rem;
  font-style: italic;
  line-height: 1.35;
  color: var(--muted);
}
.habits.editing .habits-info {
  height: auto;
  min-height: 1.35em;
}
.habits-info span:last-child {
  flex: none;
  white-space: nowrap;
}
.habits-edit,
.habits-login {
  margin: 0.2rem 0 0;
  font-size: 0.78rem;
  color: var(--muted);
}
.habits-edit button,
.habits-login button {
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font: inherit;
  text-decoration: underline;
  text-decoration-color: var(--faint);
  cursor: pointer;
}
.habits-login input {
  width: 14rem;
  max-width: 55%;
  margin-right: 0.5rem;
  padding: 0.1rem 0;
  border: 0;
  border-bottom: 1px solid var(--faint);
  background: none;
  color: var(--fg);
  font: inherit;
}

/* ---------- collage: covers, posters, and portraits behind the links (collage.js) ---------- */
#collage {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.18s ease;
}
#collage.shown {
  opacity: 1;
  transition-duration: 1.2s;
}
body:has(#page.leaving) #collage {
  opacity: 0;
  transition-duration: 0.18s;
}
#collage img {
  position: absolute;
  display: block;
  height: auto;
  opacity: 0.14;
  filter: grayscale(1);
  transform: translate(-50%, -50%);
  user-select: none;
}

/* touch screens: a pictured link tapped once (its picture is lit; the next tap opens it) */
main a.armed {
  text-decoration-color: currentColor;
}

/* ---------- footer: the external links ---------- */
footer {
  margin-top: 1.6rem;
}
.links {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.2rem 1rem;
  font-size: 0.9rem;
}
.links a {
  color: var(--muted);
}
.links a:hover {
  color: var(--fg);
}

/* ---------- loader: the procession (first page of a visit only) ---------- */
#loader {
  display: none;
}
.loading #loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  place-content: center; /* the drawing and the name line below it sit together in the middle */
  background: var(--bg);
  transition: opacity 0.8s ease;
}
.loading #loader.done {
  opacity: 0;
  pointer-events: none;
}
.loading body {
  overflow: hidden;
}
#loader svg {
  width: min(94vw, 1080px);
  height: auto;
  overflow: visible;
}
#loader .species {
  height: 1.4em; /* kept even when empty, so nothing shifts when a name appears */
  margin: 1.1rem 0 0;
  font: italic 1.15rem/1.4 var(--serif);
  color: var(--ink);
  opacity: 0;
  transition: opacity 0.25s ease;
}
#loader .species.shown {
  opacity: 0.85;
}

/* ---------- sound: playing / not playing, bottom right ---------- */
#sound {
  position: fixed;
  right: 16px;
  bottom: 12px;
  z-index: 50;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.1rem;
  border: 0;
  background: none;
  color: var(--muted);
  font: italic 0.8rem/1 var(--serif);
  cursor: pointer;
  transition: color 0.2s;
}
#sound[hidden] {
  display: none;
}
#sound:hover,
#sound.playing {
  color: var(--fg);
}
#sound .bars {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 11px;
}
#sound .bars i {
  width: 2px;
  height: 100%;
  background: currentColor;
  transform-origin: bottom;
  transform: scaleY(0.18);
  transition: transform 0.4s ease;
}
#sound.playing .bars i {
  animation: bar 1.1s ease-in-out infinite alternate;
}
#sound.playing .bars i:nth-child(2) {
  animation-duration: 0.8s;
  animation-delay: -0.3s;
}
#sound.playing .bars i:nth-child(3) {
  animation-duration: 1.3s;
  animation-delay: -0.7s;
}
#sound.playing .bars i:nth-child(4) {
  animation-duration: 0.95s;
  animation-delay: -0.2s;
}
@keyframes bar {
  from {
    transform: scaleY(0.25);
  }
  to {
    transform: scaleY(1);
  }
}

/* ---------- "click" tag under the cursor, until the first click (after jia.build) ---------- */
#click-tag {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 300;
  pointer-events: none;
  font: italic 0.8rem/1 var(--serif);
  letter-spacing: 0.02em;
  color: var(--fg);
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.55), 0 0 22px rgba(255, 255, 255, 0.25);
  white-space: nowrap;
  opacity: 0;
  transition: opacity 0.3s ease;
}
#click-tag.shown {
  opacity: 1;
}

/* ---------- torch: the fire carried by the cursor ---------- */
#torch {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 200;
  pointer-events: none;
  mix-blend-mode: screen;
}

/* ---------- motion preferences ---------- */
@media (prefers-reduced-motion: reduce) {
  #page {
    transition: none;
  }
  #sound.playing .bars i {
    animation: none;
    transform: scaleY(0.7);
  }
  .js .fold.open {
    animation: none;
  }
  main strong {
    animation: none;
    background-position: 30% 50%;
  }
}

@media (max-width: 480px) {
  html {
    font-size: 18px;
  }
  #page {
    padding: 4rem 0 5rem;
  }
}
