/* ==========================================================================
   Design tokens
   Values taken from the Figma design. Change a colour here and it changes
   everywhere on the site.
   ========================================================================== */

:root {
  /* Colours */
  --color-parchment: #ffffff;   /* page background */
  --color-ink: #1c1b18;         /* headings, emphasis */
  --color-ink-light: #4a4843;   /* body copy */
  --color-ink-faint: #9b9890;   /* dates, meta, numbers */
  --color-accent: #3a5a6e;      /* links, active nav */
  --color-accent-light: #e8eef2;/* formula blocks */
  --color-rule: #dedad4;        /* borders, dividers */

  /* Type */
  --font-sans: 'Barlow', system-ui, -apple-system, sans-serif;

  /* Layout */
  --measure: 42rem;             /* max content width (714px at 17px root) */
  --gutter: 1.25rem;            /* side padding, mobile */
  --gutter-lg: 1.5rem;          /* side padding, >= 640px */
}

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

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

html {
  font-size: 17px;
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background-color: var(--color-parchment);
  color: var(--color-ink);
  font-family: var(--font-sans);
  font-weight: 400;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

img {
  max-width: 100%;
  display: block;
}

a {
  color: inherit;
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 3px;
  border-radius: 2px;
}

/* Skip link — visible only when focused by keyboard */
.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  padding: 0.5rem 1rem;
  background: var(--color-parchment);
  color: var(--color-accent);
  font-size: 0.875rem;
}

.skip-link:focus {
  left: var(--gutter);
  top: 0.5rem;
}

/* Scrollbar */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--color-rule); border-radius: 2px; }

/* ==========================================================================
   Layout
   ========================================================================== */

.wrap {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: var(--gutter);
  width: 100%;
}

.page {
  padding-top: 2.5rem;
  padding-bottom: 2rem;
}

main {
  flex: 1;
}

@media (min-width: 640px) {
  .wrap { padding-inline: var(--gutter-lg); }
  .page { padding-top: 4rem; }
}

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

.site-header {
  position: relative;
  z-index: 50;
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding-block: 1rem;
}

.nav-desktop {
  display: none;
  gap: 4rem;
}

.nav-link {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.025em;
  color: var(--color-ink-light);
  transition: color 150ms ease;
}

.nav-link:hover {
  color: var(--color-ink);
}

.nav-link[aria-current='page'] {
  color: var(--color-accent);
}

/* Hamburger */
.nav-toggle {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
  padding: 0.25rem;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--color-ink);
}

.nav-toggle span {
  display: block;
  width: 1.25rem;
  height: 1px;
  background: currentColor;
  transition: transform 200ms ease, opacity 200ms ease;
  transform-origin: center;
}

.nav-toggle[aria-expanded='true'] span:nth-child(1) {
  transform: translateY(4.5px) rotate(45deg);
}

.nav-toggle[aria-expanded='true'] span:nth-child(2) {
  opacity: 0;
}

.nav-toggle[aria-expanded='true'] span:nth-child(3) {
  transform: translateY(-4.5px) rotate(-45deg);
}

/* Mobile drawer */
.nav-mobile {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--color-parchment);
}

.nav-mobile[data-open='true'] {
  display: block;
}

.nav-mobile .wrap {
  display: flex;
  flex-direction: column;
  /* The drawer sits inside .site-header, so reset the centring that
     `.site-header .wrap` applies to the desktop bar. */
  align-items: stretch;
  justify-content: flex-start;
  gap: 1.25rem;
  padding-block: 1.5rem;
}

.nav-mobile .nav-link {
  font-weight: 400;
}

@media (min-width: 640px) {
  .site-header .wrap { padding-block: 1.25rem; }
  .nav-desktop { display: flex; }
  .nav-toggle { display: none; }
  .nav-mobile { display: none !important; }
}

/* ==========================================================================
   Footer
   ========================================================================== */

.site-footer {
  margin-top: 4rem;
}

.site-footer .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-block: 1.5rem;
}

.site-footer .copyright,
.site-footer a {
  font-size: 0.75rem;
  color: var(--color-ink-faint);
}

.site-footer a {
  transition: color 150ms ease;
}

.site-footer a:hover {
  color: var(--color-ink);
}

.site-footer .socials {
  display: flex;
  gap: 1.25rem;
}

@media (min-width: 640px) {
  .site-footer { margin-top: 6rem; }
  .site-footer .wrap { padding-block: 2rem; }
}

/* ==========================================================================
   Shared: page heading and intro paragraph
   ========================================================================== */

.intro {
  color: var(--color-ink-light);
  font-size: 0.875rem;
  line-height: 1.7;
  margin: 0 0 2rem;
}

@media (min-width: 640px) {
  .intro {
    font-size: 1rem;
    margin-bottom: 2.5rem;
  }
}

/* ==========================================================================
   Notes index
   ========================================================================== */

.note-list {
  display: flex;
  flex-direction: column;
  gap: 2rem;
}

.note-card time {
  display: block;
  font-size: 0.75rem;
  color: var(--color-ink-faint);
  letter-spacing: 0.025em;
  margin-bottom: 0.5rem;
}

.note-card h2 {
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--color-ink);
  margin: 0 0 0.5rem;
}

.note-card h2 a {
  transition: color 150ms ease;
}

.note-card:hover h2 a,
.note-card h2 a:hover {
  color: var(--color-accent);
}

.note-card .preview {
  color: var(--color-ink-light);
  font-size: 0.875rem;
  line-height: 1.6;
  margin: 0 0 0.75rem;
}

.note-card .meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.read-more {
  font-size: 0.75rem;
  color: var(--color-accent);
  flex-shrink: 0;
  text-underline-offset: 4px;
}

.read-more:hover {
  text-decoration: underline;
}

@media (min-width: 640px) {
  .note-list { gap: 2.5rem; }
  .note-card h2 { font-size: 1.125rem; }
}

/* Tags */
.tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.tag {
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--color-ink-faint);
  padding: 0.125rem 0.5rem;
  border: 1px solid var(--color-rule);
  border-radius: 999px;
}

/* ==========================================================================
   Note detail
   ========================================================================== */

.back-link {
  display: block;
  font-size: 0.75rem;
  color: var(--color-ink-faint);
  margin-bottom: 2rem;
  transition: color 150ms ease;
}

.back-link:hover {
  color: var(--color-ink);
}

.note-header time {
  display: block;
  font-size: 0.75rem;
  color: var(--color-ink-faint);
  letter-spacing: 0.025em;
  margin-bottom: 0.75rem;
}

.note-header h1 {
  font-size: 1.125rem;
  font-weight: 500;
  line-height: 1.375;
  color: var(--color-ink);
  margin: 0 0 1.5rem;
}

.note-footer {
  margin-top: 2.5rem;
}

@media (min-width: 640px) {
  .back-link { margin-bottom: 2.5rem; }
  .note-header time { margin-bottom: 1rem; }
  .note-header h1 {
    font-size: 1.25rem;
    margin-bottom: 2rem;
  }
  .note-footer { margin-top: 3rem; }
}

/* ==========================================================================
   Prose — the generated body of a note or the about page
   ========================================================================== */

.prose {
  color: var(--color-ink-light);
  font-size: 0.875rem;
  line-height: 1.85;
}

/* Reset the browser's default block margins, then space siblings evenly.
   Both selectors have the same specificity, so the later one wins for
   everything after the first child. */
.prose > * {
  margin: 0;
}

.prose > * + * {
  margin-top: 1rem;
}

.prose strong {
  font-weight: 600;
  color: var(--color-ink);
}

.prose em {
  font-style: italic;
}

.prose a {
  color: var(--color-accent);
  text-decoration: underline;
  text-underline-offset: 4px;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--color-rule);
  transition: text-decoration-color 150ms ease;
}

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

/* Headings inside prose */
.prose h2 {
  font-size: 1.0625rem;
  font-weight: 500;
  line-height: 1.4;
  color: var(--color-ink);
  margin: 2.5rem 0 0;
}

.prose h3 {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--color-ink);
  margin: 2rem 0 0;
}

.prose h2 + *,
.prose h3 + * {
  margin-top: 0.75rem;
}

/* Lists */
.prose ul,
.prose ol {
  margin: 1rem 0 0;
  padding-left: 1.25rem;
}

.prose li {
  margin-top: 0.375rem;
}

.prose li::marker {
  color: var(--color-ink-faint);
}

.prose ul > li::marker {
  font-size: 0.8em;
}

/* Pull quotes */
.prose blockquote {
  margin: 1.5rem 0 0;
  padding-left: 1.125rem;
  border-left: 2px solid var(--color-rule);
  color: var(--color-ink);
  font-style: italic;
}

.prose blockquote p {
  margin: 0;
}

/* Formula blocks — authored as ```formula fenced blocks in markdown */
.prose .formula {
  margin: 1.5rem 0 0;
  padding: 0.875rem 1rem;
  background: var(--color-accent-light);
  border-radius: 3px;
  color: var(--color-ink);
  font-size: 0.875rem;
  line-height: 1.9;
  text-align: center;
  font-variant-numeric: tabular-nums;
  overflow-wrap: break-word;
}

.prose hr {
  margin: 2.5rem 0 0;
  border: 0;
  border-top: 1px solid var(--color-rule);
}

@media (min-width: 640px) {
  .prose {
    font-size: 1.0625rem;
  }

  .prose > * + * {
    margin-top: 1.25rem;
  }

  .prose h2 { font-size: 1.1875rem; }
  .prose h3 { font-size: 1.0625rem; }
  .prose .formula { font-size: 1rem; }
}

/* ==========================================================================
   Quotes page
   ========================================================================== */

.quote-list {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.quote-item {
  display: flex;
  gap: 1.25rem;
  align-items: baseline;
  margin: 0;
}

.quote-item .num {
  font-size: 0.75rem;
  color: var(--color-ink-faint);
  flex-shrink: 0;
  width: 1.25rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.quote-item blockquote {
  margin: 0;
  font-size: 0.875rem;
  line-height: 1.7;
  color: var(--color-ink);
}

@media (min-width: 640px) {
  .quote-list { gap: 2.5rem; }
  .quote-item blockquote { font-size: 1rem; }
}

/* ==========================================================================
   Whoami page
   ========================================================================== */

.about-head {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  align-items: flex-start;
  margin-bottom: 2rem;
}

.about-photo {
  width: 100%;
  aspect-ratio: 3 / 4;
  max-height: 400px;
  flex-shrink: 0;
  overflow: hidden;
  border-radius: 3px;
  background: var(--color-rule);
}

.about-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 50% 30%;
}

@media (min-width: 640px) {
  .about-head {
    flex-direction: row;
    gap: 2.5rem;
    margin-bottom: 2.5rem;
  }

  .about-photo { width: 13rem; }
}

/* ==========================================================================
   404
   ========================================================================== */

.notfound p {
  color: var(--color-ink-faint);
  font-size: 0.9375rem;
}

.notfound a {
  display: inline-block;
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--color-accent);
}

.notfound a:hover {
  text-decoration: underline;
  text-underline-offset: 4px;
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }

  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
