/* ---- Reset & base ---- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #6f6f6f;
  --line: #cfcfcf;
  --accent: #5e5d5d;
  --gutter: clamp(1.5rem, 8vw, 8rem);
}

/* Dark palette, applied on explicit choice ... */
:root[data-theme="dark"] {
  --bg: #0e0e0e;
  --fg: #f2f2f2;
  --muted: #8f8f8f;
  --line: #3a3a3a;
}

/* ... or on the system setting when no explicit choice was made */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #0e0e0e;
    --fg: #f2f2f2;
    --muted: #8f8f8f;
  --line: #3a3a3a;
  }
}

html {
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  /* System fonts, same stack as the old site (no font file, nothing to load) */
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 1.0625rem;
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
}

a {
  color: inherit;
}

/* Animated links: a faint resting underline, and on hover a solid one sweeps in from the left.
   Drawn with backgrounds instead of ::after so it also works when a link wraps onto two lines. */
.link {
  --thick: 1px;
  text-decoration: none;
  padding-bottom: 0.12em;
  background:
    linear-gradient(currentColor, currentColor) 0 100% / 0 var(--thick) no-repeat,
    linear-gradient(var(--line), var(--line)) 0 100% / 100% var(--thick) no-repeat;
  transition: background-size 0.35s ease;
}

.link:hover {
  background-size: 100% var(--thick), 100% var(--thick);
}

@media (prefers-reduced-motion: reduce) {
  .link {
    transition: none;
  }
}

a:focus-visible,
button:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 4px;
}

/* ---- Header + theme toggle ---- */
.top {
  display: flex;
  justify-content: flex-end;
  padding: 1.5rem clamp(1.5rem, 6vw, 6rem);
}

.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 44px;
  padding: 0 0.875rem;
  border: 1.5px solid var(--fg);
  border-radius: 8px;
  background: transparent;
  color: var(--fg);
  font: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
}

.theme-toggle svg {
  width: 18px;
  height: 18px;
}

/* Icon + label mirror the active theme (light offers dark mode, dark offers light mode) */
.theme-toggle .icon-sun,
.theme-toggle .label-light {
  display: none;
}

:root[data-theme="dark"] .theme-toggle .icon-sun,
:root[data-theme="dark"] .theme-toggle .label-light {
  display: inline;
}

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

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) .theme-toggle .icon-sun,
  :root:not([data-theme]) .theme-toggle .label-light {
    display: inline;
  }

  :root:not([data-theme]) .theme-toggle .icon-moon,
  :root:not([data-theme]) .theme-toggle .label-dark {
    display: none;
  }
}

/* ---- Page ---- */
.page {
  flex: 1;
  padding: 0 var(--gutter);
}

/* ---- Hero ---- */
.hero {
  padding-top: clamp(2.5rem, 6vw, 5rem);
}

.tagline {
  font-size: 1.0625rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 1.5rem;
}

/* Shrink-wraps to the name so the divider tracks the name's width */
.title-block {
  width: fit-content;
  max-width: 100%;
}

.name {
  font-size: clamp(3.5rem, 12vw, 9.5rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 0.95;
}

.name .accent {
  color: var(--accent);
  /* On load, the color eases in from the normal text color to the accent */
  animation: accent-color 0.75s ease 0.5s both;
}

@keyframes accent-color {
  from {
    color: var(--fg);
  }

  to {
    color: var(--accent);
  }
}

.rule {
  border: 0;
  height: 2px;
  width: 100%;
  background: var(--fg);
  margin: 2rem 0;
}

/* ---- Hero load sequence (the page's one entrance moment) ----
   Tagline and name fade in, the line draws itself from left to right, then the links appear. */
.hero .tagline,
.hero .name,
.hero .links {
  animation: hero-fade 0.5s ease both;
}

.hero .name {
  animation-delay: 0.1s;
}

.hero .links {
  animation-delay: 0.85s;
}

.hero .rule {
  transform-origin: left;
  animation: rule-draw 0.7s cubic-bezier(0.65, 0, 0.35, 1) 0.3s both;
}

@keyframes hero-fade {
  from {
    opacity: 0;
  }
}

@keyframes rule-draw {
  from {
    transform: scaleX(0);
  }
}

/* The rest of the page continues the same sequence, top to bottom, in one pass on load */
.built h2,
.repos article,
.other h2,
.projects > div,
.footer {
  animation: hero-fade 0.5s ease both;
}

.built h2 { animation-delay: 1s; }
.repos article:nth-child(1) { animation-delay: 1.1s; }
.repos article:nth-child(2) { animation-delay: 1.2s; }
.other h2 { animation-delay: 1.35s; }
.projects > div:nth-child(1) { animation-delay: 1.45s; }
.projects > div:nth-child(2) { animation-delay: 1.5s; }
.projects > div:nth-child(3) { animation-delay: 1.55s; }
.projects > div:nth-child(4) { animation-delay: 1.6s; }
.footer { animation-delay: 1.7s; }

@media (prefers-reduced-motion: reduce) {
  .name .accent,
  .hero .tagline,
  .hero .name,
  .hero .links,
  .hero .rule,
  .built h2,
  .repos article,
  .other h2,
  .projects > div,
  .footer {
    animation: none;
  }
}

.links {
  display: flex;
  gap: 1.5rem;
}

.links a {
  font-weight: 500;
}

/* ---- Sections ---- */
.built,
.other {
  max-width: 760px;
  padding-top: 6rem;
}

.other {
  padding-bottom: 6rem;
}

h2 {
  font-size: 1.875rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  /* Tight to its own content so heading and items read as one group */
  margin-bottom: 1.5rem;
}

/* ---- Things I've built ---- */
.repos {
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

.repo-name {
  font-size: clamp(1.5rem, 4vw, 2.125rem);
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.15;
  overflow-wrap: anywhere;
  --thick: 2px;
}

.repo-desc {
  margin-top: 0.625rem;
  font-size: 1.1875rem;
  max-width: 52ch;
}

.repo-meta {
  margin-top: 0.375rem;
  font-size: 0.9375rem;
  color: var(--muted);
}
/* ---- Other projects ---- */
.projects {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: 2rem 3.5rem;
}

.projects h3 {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.015em;
}

.projects p {
  margin-top: 0.25rem;
  line-height: 1.55;
}

/* ---- Footer ---- */
.footer {
  display: flex;
  gap: 1.5rem;
  padding: 0 var(--gutter) 3rem;
  font-size: 0.875rem;
  color: var(--muted);
}

/* ---- 404 ---- */
.page-404 {
  padding-bottom: 6rem;
}

/* ---- Theme switch: circle reveal (driven by main.js via View Transitions) ---- */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}

/* The circle does the animating; the usual color fade would only muddy it */
.theme-switching body {
  transition: none;
}

/* ---- Wide screens: "Other projects" moves next to "Things I've built" ----
   From laptop width up. Between 1200 and ~1900 px, gutters, gaps and type scale with the window,
   so both columns fit on a laptop and reach the normal sizes on Full HD.
   To revert, delete this block (the .work wrapper in index.html is harmless). */
@media (min-width: 1200px) {
  :root {
    --gutter: clamp(2.5rem, 10vw - 4rem, 8rem);
  }

  .work {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    gap: clamp(3rem, 5vw, 5rem);
    max-width: 1280px;
    /* Bottom space belongs to the row, not to one column, so the longer column can't touch the footer */
    padding-bottom: 6rem;
  }

  .built,
  .other {
    max-width: none;
    padding-bottom: 0;
  }

  h2 {
    font-size: clamp(1.5rem, 0.5rem + 1.5vw, 1.875rem);
  }

  .repo-name {
    font-size: clamp(1.5rem, 0.25rem + 2vw, 2.125rem);
  }

  /* Keep the 2x2 grid of the narrow layout, just tighter */
  .projects {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.75rem clamp(2rem, 2.5vw, 2.5rem);
  }

  .projects h3 {
    font-size: clamp(1.0625rem, 0.5rem + 0.9vw, 1.25rem);
  }

  .projects p {
    font-size: clamp(0.9375rem, 0.5rem + 0.6vw, 1.0625rem);
  }
}

/* Wide but short windows (laptops): shrink the hero by height, so both columns show up without scrolling */
@media (min-width: 1200px) and (max-height: 900px) {
  .hero {
    padding-top: 1.5rem;
  }

  .name {
    font-size: clamp(3.5rem, 14vh, 9.5rem);
  }

  .rule {
    margin: 1.5rem 0;
  }

  .built,
  .other {
    padding-top: 3.5rem;
  }

  .work {
    padding-bottom: 3.5rem;
  }
}
