/* ==========================================================================
   Design tokens. Fonts, sizes and colors all live here.
   Dark is the default theme. Light overrides are in [data-theme="light"].
   ========================================================================== */
:root {
  /* Fonts. Backup pixel font: "DotGothic16" (see README). */
  --font-pixel: "Pixelify Sans", system-ui, sans-serif;
  --font-body: "Shantell Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;

  /* Pixel sizes. Keep these whole pixels so the pixel font stays crisp. */
  --pixel-nav: 14px;
  --pixel-card: 16px;
  --pixel-section: 18px;
  --pixel-title: 24px;
  --pixel-weight-title: 600;
  --pixel-weight-ui: 400;

  /* Body type. --body-line is the space between lines: lower is tighter. */
  --body-size: 17px;
  --body-line: 1.5;
  --body-word-spacing: normal;
  --body-weight-bold: 600;
  --card-text-size: 16px;
  --card-line: 1.45;
  --small-size: 14px;
  --footer-size: 15px;
  --tiny-size: 13px;

  /* Layout */
  --content-width: 720px;
  --gutter: 16px;
  --header-height: 60px;
  --logo-size: 32px;
  --photo-size: 160px;
  --switch-width: 36px;   /* theme switch, whole pixels only */
  --switch-height: 20px;
  --switch-knob: 12px;
  --card-radius: 14px;
  --menu-radius: 12px;
  --blur: 14px;

  /* Motion */
  --fade-in: 400ms;
  --menu-fade: 120ms;
  --menu-close-delay: 150ms; /* read by main.js */

  /* Colors, dark theme (default) */
  --color-bg: #000000;
  --color-text: #f2f2f2;
  --color-muted: #8a8a8a;
  --color-border: rgba(255, 255, 255, 0.10);
  --color-glass: rgba(255, 255, 255, 0.04);
  --color-header: rgba(0, 0, 0, 0.70);
  --color-menu: rgba(22, 22, 22, 0.80);
  --color-glow: rgba(255, 255, 255, 0.08);
  color-scheme: dark;
}

[data-theme="light"] {
  --color-bg: #ffffff;
  --color-text: #0d0d0d;
  --color-muted: #6b6b6b;
  --color-border: rgba(0, 0, 0, 0.10);
  --color-glass: rgba(0, 0, 0, 0.03);
  --color-header: rgba(255, 255, 255, 0.72);
  --color-menu: rgba(250, 250, 250, 0.84);
  --color-glow: rgba(0, 0, 0, 0.06);
  color-scheme: light;
}

@media (min-width: 761px) {
  :root { --gutter: 24px; }
}

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

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: clip; /* keeps the About page glow from causing sideways scroll */
}

body {
  margin: 0;
  background: var(--color-bg);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: var(--body-size);
  line-height: var(--body-line);
  word-spacing: var(--body-word-spacing);
  font-weight: 400;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

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

p { margin: 0 0 1.1em; }
p:last-child { margin-bottom: 0; }

a {
  color: inherit;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
}
a:hover { text-decoration-thickness: 2px; }

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  z-index: 50;
  padding: 8px 12px;
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: 8px;
}
.skip-link:focus { top: 12px; }

/* Pixel font. Only for name, nav, theme switch, titles, headings, card names. */
.pixel,
.page-title,
.section-title,
.card-name {
  font-family: var(--font-pixel);
  letter-spacing: 0;
  word-spacing: normal;
  font-style: normal;
  font-synthesis: none;
  line-height: 1.25;
}

/* ==========================================================================
   Header
   ========================================================================== */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid var(--color-border);
}

/* The frosted layer sits on a pseudo-element so the dropdown can blur too. */
.site-header::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background: var(--color-header);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
}

.header-inner {
  max-width: calc(var(--content-width) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 0 var(--gutter);
  height: var(--header-height);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-size: var(--pixel-card);
  font-weight: var(--pixel-weight-title);
}
.brand:hover { text-decoration: none; }
.brand:hover .brand-name { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 4px; }

.logo {
  width: var(--logo-size);
  height: var(--logo-size);
  flex: none;
  shape-rendering: crispEdges;
}

.nav-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  align-items: center;
  gap: 22px;
}
.nav-list > li {
  font-size: var(--pixel-nav);
  line-height: 1.25;
}

.nav-link,
.theme-toggle,
.menu-toggle,
.dropdown a {
  font-family: var(--font-pixel);
  font-size: var(--pixel-nav);
  font-weight: var(--pixel-weight-ui);
  letter-spacing: 0;
  word-spacing: normal;
  line-height: 1.25;
  color: var(--color-text);
}

.nav-link {
  text-decoration: none;
  text-underline-offset: 6px;
  text-decoration-thickness: 1px;
}
.nav-link:hover,
.nav-link[aria-current="page"],
body[data-page="about"] .nav-link[data-nav="about"],
body[data-page="portfolio"] .nav-link[data-nav="portfolio"],
body[data-page="writing"] .nav-link[data-nav="writing"],
body[data-page="resources"] .nav-link[data-nav="resources"] {
  text-decoration: underline;
  text-decoration-thickness: 1px;
}

.theme-toggle,
.menu-toggle {
  appearance: none;
  background: none;
  border: 0;
  padding: 0;
  margin: 0;
  cursor: pointer;
  text-decoration: none;
}
.theme-toggle:hover,
.menu-toggle:hover { text-decoration: underline; text-underline-offset: 6px; }

/* Theme switch: a pixel-style track with a square knob.
   Off (dark): knob left, outlined track. On (light): knob right, filled track.
   Position comes from data-theme, so it's correct before main.js runs. */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}
.theme-toggle:hover { text-decoration: none; }

.theme-text {
  /* Visible only in the phone menu (see mobile styles) */
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

.switch-track {
  --notch: 2px;
  position: relative;
  display: block;
  width: var(--switch-width);
  height: var(--switch-height);
  border: 2px solid var(--color-muted);
  background: transparent;
  /* Cut the corners in 2px steps so it reads as pixel art */
  clip-path: polygon(
    var(--notch) 0, calc(100% - var(--notch)) 0,
    calc(100% - var(--notch)) var(--notch), 100% var(--notch),
    100% calc(100% - var(--notch)), calc(100% - var(--notch)) calc(100% - var(--notch)),
    calc(100% - var(--notch)) 100%, var(--notch) 100%,
    var(--notch) calc(100% - var(--notch)), 0 calc(100% - var(--notch)),
    0 var(--notch), var(--notch) var(--notch)
  );
}
.switch-knob {
  position: absolute;
  top: 2px;
  left: 2px;
  width: var(--switch-knob);
  height: var(--switch-knob);
  background: var(--color-text);
}
.theme-toggle:hover .switch-track { border-color: var(--color-text); }

[data-theme="light"] .switch-track {
  background: var(--color-text);
  border-color: var(--color-text);
}
[data-theme="light"] .switch-knob {
  left: auto;
  right: 2px;
  background: var(--color-bg);
}

.menu-toggle { display: none; }

/* Resources dropdown */
.has-menu { position: relative; }

.dropdown {
  list-style: none;
  margin: 0;
  padding: 6px;
  position: absolute;
  top: calc(100% + 14px);
  left: -14px;
  min-width: 156px;
  background: var(--color-menu);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
  border: 1px solid var(--color-border);
  border-radius: var(--menu-radius);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--menu-fade) linear, visibility 0s linear var(--menu-fade);
}

/* Invisible bridge across the gap so the pointer can travel to the menu. */
.dropdown::before {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  top: -16px;
  height: 16px;
}

.has-menu.is-open .dropdown {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--menu-fade) linear, visibility 0s;
}

.dropdown a {
  display: block;
  padding: 7px 10px;
  border-radius: 8px;
  text-decoration: none;
}
.dropdown a:hover { text-decoration: underline; text-underline-offset: 5px; }

/* ==========================================================================
   Mobile navigation
   ========================================================================== */
@media (max-width: 760px) {
  .menu-toggle { display: block; }

  .site-nav {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    padding: 4px var(--gutter) 12px;
    background: var(--color-menu);
    -webkit-backdrop-filter: blur(var(--blur));
    backdrop-filter: blur(var(--blur));
    border-bottom: 1px solid var(--color-border);
  }
  .site-header.menu-open .site-nav { display: block; }

  .nav-list {
    flex-direction: column;
    align-items: stretch;
    gap: 0;
  }

  .nav-link,
  .site-nav .theme-toggle {
    display: block;
    padding: 12px 0;
  }

  .site-nav .theme-toggle {
    display: flex;
    width: 100%;
    justify-content: space-between;
    margin-top: 4px;
    border-top: 1px solid var(--color-border);
    padding-top: 14px;
  }
  .site-nav .theme-text {
    position: static;
    width: auto;
    height: auto;
    overflow: visible;
    clip: auto;
  }

  .dropdown {
    position: static;
    min-width: 0;
    padding: 0 0 6px 16px;
    background: none;
    -webkit-backdrop-filter: none;
    backdrop-filter: none;
    border: 0;
    border-radius: 0;
    display: none;
    opacity: 1;
    visibility: visible;
    transition: none;
  }
  .dropdown::before { display: none; }
  .has-menu.is-open .dropdown { display: block; }
  .dropdown a { padding: 10px 0; }
}

/* ==========================================================================
   Main content
   ========================================================================== */
main {
  flex: 1;
  width: 100%;
  max-width: calc(var(--content-width) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 56px var(--gutter) 88px;
  animation: fade-in var(--fade-in) ease-out both;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@media (min-width: 761px) {
  main { padding-top: 80px; padding-bottom: 112px; }
}

.page-title {
  font-size: var(--pixel-title);
  font-weight: var(--pixel-weight-title);
  margin: 0 0 20px;
}

.section-title {
  font-size: var(--pixel-section);
  font-weight: var(--pixel-weight-title);
  margin: 0 0 16px;
}

.intro { margin-bottom: 40px; }

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

/* About page */
.profile {
  position: relative;
  isolation: isolate;
  margin-bottom: 36px;
  width: var(--photo-size);
}

/* The one faint glow behind the photo. About page only. */
.profile::before {
  content: "";
  position: absolute;
  z-index: -1;
  left: 50%;
  top: 50%;
  /* 720px, but never wider than fits on screen to the right of the photo,
     or phones zoom the page out. */
  width: min(720px, calc(2 * (100vw - var(--gutter) - var(--photo-size) / 2)));
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  background: radial-gradient(circle closest-side, var(--color-glow), transparent);
  pointer-events: none;
}

.avatar {
  position: relative;
  width: var(--photo-size);
  height: var(--photo-size);
  border-radius: 50%;
  border: 1px solid var(--color-border);
  overflow: hidden;
  display: grid;
  place-items: center;
  background: var(--color-bg);
}
.avatar-initials {
  font-family: var(--font-pixel);
  font-size: var(--pixel-title);
  font-weight: var(--pixel-weight-title);
  color: var(--color-muted);
}
.avatar img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.bio { max-width: 640px; }

/* Cards (Portfolio and Resources only) */
.card-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
@media (min-width: 640px) {
  .card-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.card {
  display: flex;
  flex-direction: column;
  padding: 20px 20px 18px;
  background: var(--color-glass);
  -webkit-backdrop-filter: blur(var(--blur));
  backdrop-filter: blur(var(--blur));
  border: 1px solid var(--color-border);
  border-radius: var(--card-radius);
  font-size: var(--card-text-size);
  line-height: var(--card-line);
}
.card-name {
  font-size: var(--pixel-card);
  font-weight: var(--pixel-weight-title);
  margin: 0 0 4px;
}
.card-status {
  font-size: var(--small-size);
  color: var(--color-muted);
  margin: 0 0 12px;
}
.card-desc { margin: 0 0 12px; }
.card-tools {
  font-size: var(--small-size);
  color: var(--color-muted);
  margin: auto 0 0;
}
.card-link {
  align-self: flex-start;
  margin-top: 10px;
  font-size: var(--small-size);
}

/* Writing list */
.post-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--color-border);
}
.post-list li {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 24px;
  padding: 14px 0;
  border-bottom: 1px solid var(--color-border);
}
.post-date {
  color: var(--color-muted);
  font-size: var(--small-size);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Resources */
.resource-section {
  margin-top: 48px;
  scroll-margin-top: calc(var(--header-height) + 24px);
}
.empty-note { color: var(--color-muted); }

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
  border-top: 1px solid var(--color-border);
}
.footer-inner {
  max-width: calc(var(--content-width) + var(--gutter) * 2);
  margin: 0 auto;
  padding: 28px var(--gutter) 36px;
  font-size: var(--footer-size);
  line-height: 1.3;
}
/* Socials: an even grid, label on top, handle in gray below. */
.footer-links {
  list-style: none;
  margin: 0 0 28px;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px 24px;
}
@media (min-width: 640px) {
  .footer-links { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
.footer-links a {
  display: flex;
  flex-direction: column;
  gap: 2px;
  text-decoration: none;
}
.footer-label {
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 3px;
  align-self: flex-start;
}
.footer-links a:hover .footer-label { text-decoration-thickness: 2px; }
.footer-links .handle {
  color: var(--color-muted);
  font-size: var(--small-size);
  overflow-wrap: anywhere;
}
.copyright {
  margin: 0;
  font-size: var(--tiny-size);
  color: var(--color-muted);
}

/* ==========================================================================
   Reduced motion
   ========================================================================== */
@media (prefers-reduced-motion: reduce) {
  main { animation: none; }
  .dropdown,
  .has-menu.is-open .dropdown { transition: none; }
}
