/* ---------- Tokens ---------- */
:root {
  --bg: #fbfaf7;
  --surface: #f6f3ee;
  --text: #171411;
  --text-muted: #6e6660;
  --text-faint: #9d9489;
  --hairline: #ebe6dd;
  --hairline-strong: #dad3c8;
  --accent: #171411;
  --accent-on: #fbfaf7;
  --accent-hue: #a86a3a;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.02);
  --curve-color: rgba(23, 20, 17, 0.15);
  --radius: 6px;
  --radius-lg: 12px;
  --sidebar-w: clamp(320px, 26vw, 460px);
  --pad-x: clamp(24px, 3.5vw, 96px);
  --pad-y: clamp(32px, 3.5vw, 72px);
  --gap-col: clamp(40px, 5vw, 104px);
  --gap-projects: clamp(48px, 5vw, 88px);

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-serif: "Instrument Serif", "Times New Roman", serif;

  --t-fast: 120ms ease;
  --t-med: 220ms cubic-bezier(0.2, 0.6, 0.2, 1);
}

html[data-theme="dark"] {
  --bg: #1c1a17;
  --surface: #231f1a;
  --text: #f1eee8;
  --text-muted: #a9a39a;
  --text-faint: #6f6961;
  --hairline: #2c2a26;
  --hairline-strong: #3a3631;
  --accent: #f1eee8;
  --accent-on: #1c1a17;
  --accent-hue: #c98a52;
  --shadow: 0 1px 0 rgba(255, 255, 255, 0.02);
  --curve-color: rgba(241, 238, 232, 0.12);
}

@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] {
    --bg: #1c1a17;
    --surface: #231f1a;
    --text: #f1eee8;
    --text-muted: #a9a39a;
    --text-faint: #6f6961;
    --hairline: #2c2a26;
    --hairline-strong: #3a3631;
    --accent: #f1eee8;
    --accent-on: #1c1a17;
    --accent-hue: #c98a52;
    --shadow: 0 1px 0 rgba(255, 255, 255, 0.02);
    --curve-color: rgba(241, 238, 232, 0.12);
  }
}

/* ---------- Reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; text-rendering: optimizeLegibility; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  font-weight: 400;
  letter-spacing: -0.005em;
  position: relative;
  transition: background-color var(--t-med), color var(--t-med);
}

/* ---------- Background curves ---------- */
.bg-curves {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
  color: var(--curve-color);
  transition: color var(--t-med);
}
.bg-curve {
  position: absolute;
  width: 88vmin;
  height: 88vmin;
  max-width: 1100px;
  max-height: 1100px;
  transform-origin: var(--bg-origin, center);
  transform: translate3d(var(--bg-px, 0px), var(--bg-py, 0px), 0) scale(var(--bg-scale, 1));
  will-change: transform;
}
.bg-curve-tr { top: 0; right: 0; --bg-origin: 100% 0%; }
.bg-curve-bl { bottom: 0; left: 0; --bg-origin: 0% 100%; }

@media (prefers-reduced-motion: reduce) {
  .bg-curve { transform: none; }
}

.layout,
.project-page { position: relative; z-index: 1; }
img, video { display: block; max-width: 100%; height: auto; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
ul, ol, dl { margin: 0; padding: 0; list-style: none; }
h1, h2, h3, p { margin: 0; }

/* Selection */
::selection { background: var(--text); color: var(--bg); }

/* Keyboard focus ring — applied only on actual keyboard focus, not click */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent-hue);
  outline-offset: 3px;
  border-radius: 2px;
}
a:focus-visible,
button:focus-visible {
  outline-offset: 4px;
}

/* ---------- Layout ---------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: var(--gap-col);
  width: 100%;
  margin: 0;
  padding: var(--pad-y) var(--pad-x);
  min-height: 100vh;
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 48px;
  }
}

/* ---------- Sidebar ---------- */
.sidebar {
  position: relative;
}
.sidebar-inner {
  position: sticky;
  top: var(--pad-y);
  display: flex;
  flex-direction: column;
  gap: 32px;
  max-height: calc(100vh - (var(--pad-y) * 2));
  padding-right: 8px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline-strong) transparent;
}
.sidebar-inner::-webkit-scrollbar { width: 6px; }
.sidebar-inner::-webkit-scrollbar-thumb { background: var(--hairline-strong); border-radius: 3px; }
.sidebar-inner::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .sidebar-inner {
    position: static;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
}

.identity {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.availability {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 11px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  width: max-content;
  max-width: 100%;
  align-self: flex-start;
}
.availability-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent-hue);
  flex-shrink: 0;
  position: relative;
  animation: availability-pulse 2.4s ease-in-out infinite;
}
.availability-dot::after {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 999px;
  background: var(--accent-hue);
  opacity: 0.25;
  animation: availability-halo 2.4s ease-in-out infinite;
}
.availability-label { white-space: nowrap; }
@keyframes availability-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
@keyframes availability-halo {
  0%, 100% { transform: scale(0.6); opacity: 0; }
  50% { transform: scale(1.1); opacity: 0.18; }
}

.identity .name {
  font-family: var(--font-serif);
  font-size: clamp(40px, 4.6vw, 60px);
  font-weight: 400;
  line-height: 0.98;
  letter-spacing: -0.015em;
  text-wrap: balance;
  margin: 0;
}
.identity .role {
  margin: 0;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0.005em;
  display: flex;
  align-items: baseline;
  gap: 12px;
}
.identity .role::before {
  content: "";
  display: inline-block;
  width: 22px;
  height: 1px;
  background: var(--text-faint);
  flex-shrink: 0;
  transform: translateY(-4px);
}

/* Hero entrance — staggered fade-up */
@keyframes hero-enter {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
.availability,
.identity .name,
.identity .role,
.bio,
.details,
.links {
  animation: hero-enter 700ms cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.availability      { animation-delay:  80ms; }
.identity .name    { animation-delay: 180ms; }
.identity .role    { animation-delay: 300ms; }
.bio               { animation-delay: 420ms; }
.details           { animation-delay: 540ms; }
.links             { animation-delay: 660ms; }

@media (prefers-reduced-motion: reduce) {
  .availability,
  .identity .name,
  .identity .role,
  .bio,
  .details,
  .links { animation: none; }
  .availability-dot,
  .availability-dot::after { animation: none; }
}

.bio {
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
  max-width: 44ch;
}
.bio p + p { margin-top: 0.9em; }

.details dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 16px;
  row-gap: 8px;
  font-size: 13px;
}
.details dt {
  color: var(--text-faint);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 11px;
  font-weight: 500;
  padding-top: 2px;
}
.details dd {
  color: var(--text);
  margin: 0;
  font-size: 13px;
}

.links ul {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.links a {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
  font-size: 14px;
  color: var(--text);
  border-bottom: 1px solid var(--hairline);
  transition: color var(--t-fast), padding var(--t-fast);
}
.links li:last-child a { border-bottom: 0; }
.links a::after {
  content: "↗";
  color: var(--text-faint);
  font-size: 12px;
  transition: transform var(--t-fast), color var(--t-fast);
}
.links a:hover { color: var(--text); }
.links a:hover::after { transform: translate(2px, -2px); color: var(--accent-hue); }

.sidebar-spacer { flex: 1; min-height: 16px; }

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 24px;
  border-top: 1px solid var(--hairline);
}

.cta {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 18px;
  background: var(--accent);
  color: var(--accent-on);
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  letter-spacing: 0.01em;
  transition: transform var(--t-fast), opacity var(--t-fast);
}
.cta::after {
  content: "→";
  transition: transform var(--t-med);
}
.cta:hover { opacity: 0.9; }
.cta:hover::after { transform: translateX(3px); }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  align-self: flex-start;
  padding: 6px 8px;
  margin-left: -8px;
  border-radius: var(--radius);
  color: var(--text-muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  transition: color var(--t-fast), background-color var(--t-fast);
}
.theme-toggle:hover { color: var(--text); }
.theme-toggle-track {
  position: relative;
  width: 28px;
  height: 16px;
  background: var(--hairline-strong);
  border-radius: 999px;
  transition: background-color var(--t-med);
}
.theme-toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 12px;
  height: 12px;
  background: var(--bg);
  border-radius: 999px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
  transition: transform var(--t-med), background-color var(--t-med);
}
html[data-theme="dark"] .theme-toggle-thumb,
html[data-theme="auto"] .theme-toggle-thumb { /* fallback under prefers-dark handled below */ }
html[data-theme="dark"] .theme-toggle-track .theme-toggle-thumb { transform: translateX(12px); }
@media (prefers-color-scheme: dark) {
  html[data-theme="auto"] .theme-toggle-track .theme-toggle-thumb { transform: translateX(6px); opacity: 0.6; }
}

/* ---------- Work column ---------- */
.work {
  display: flex;
  flex-direction: column;
  gap: 28px;
  min-width: 0;
}
.work-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--hairline);
}
.work-eyebrow {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
}
.work-year {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-faint);
  font-feature-settings: "tnum" 1;
}

/* Filter chips — beveled rectangles (octagonal corners via clip-path).
   Click toggles a tag; OR semantics across multiple chips. */
.project-filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: clamp(28px, 3vw, 44px);
}
.filter-chip {
  --bevel: 6px;
  position: relative;
  padding: 10px 16px;
  background: var(--surface);
  color: var(--text-muted);
  border: 0;
  font-family: inherit;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  clip-path: polygon(
    var(--bevel) 0,
    calc(100% - var(--bevel)) 0,
    100% var(--bevel),
    100% calc(100% - var(--bevel)),
    calc(100% - var(--bevel)) 100%,
    var(--bevel) 100%,
    0 calc(100% - var(--bevel)),
    0 var(--bevel)
  );
  transition: background-color var(--t-fast), color var(--t-fast);
}
.filter-chip:hover {
  background: var(--hairline-strong);
  color: var(--text);
}
.filter-chip.is-active {
  background: var(--text);
  color: var(--bg);
}
.filter-chip:focus-visible {
  /* clip-path eats outlines, so use bg colour change for focus instead */
  background: var(--accent-hue);
  color: var(--bg);
  outline: none;
}
.filter-chip-count {
  margin-left: 8px;
  opacity: 0.5;
  font-feature-settings: "tnum" 1;
  font-size: 11px;
  letter-spacing: 0;
}
.filter-chip.is-active .filter-chip-count { opacity: 0.65; }

/* Project hidden by current filter — display:none collapses the multi-column flow. */
.project.is-hidden { display: none; }

/* Column-flow stacking (CSS multi-column).
   Projects pack top-to-bottom in column 1, then column 2 — so a tall card in
   one column doesn't leave a void next to a short card. Trade-off: reading
   order is vertical-first (01 → 02 → 03 in column 1, then 04+ in column 2). */
.projects {
  column-count: 1;
  column-gap: 0;
}
@media (min-width: 1200px) {
  .projects {
    column-count: 2;
    column-gap: clamp(32px, 3vw, 56px);
  }
}
.projects > .project {
  break-inside: avoid;
  -webkit-column-break-inside: avoid;
  page-break-inside: avoid;
  margin-bottom: var(--gap-projects);
}
.projects > .project:last-child { margin-bottom: 0; }
.loading {
  padding: 80px 0;
  text-align: center;
  color: var(--text-faint);
  font-size: 13px;
  letter-spacing: 0.04em;
}

.project {
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.project-media-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.project-media {
  position: relative;
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--hairline);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.project-media img,
.project-media video {
  display: block;
  max-width: 100%;
  height: auto;
  transition: transform 600ms cubic-bezier(0.2, 0.6, 0.2, 1);
}
/* Empty/placeholder cards keep a 16:9 frame so the grid stays consistent. */
.project-media:not(:has(img)):not(:has(video)) {
  aspect-ratio: 16 / 9;
}
a.project-link { cursor: pointer; }
a.project-link:hover .project-media img,
a.project-link:hover .project-media video { transform: scale(1.015); }

.project-media-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  color: var(--text-faint);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
  padding: 32px;
}
.project-media-placeholder code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--hairline);
  padding: 2px 6px;
  border-radius: 4px;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text-muted);
}

.project-meta {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding-top: 4px;
}
.project-title {
  font-family: var(--font-serif);
  font-size: clamp(20px, 2vw, 24px);
  font-weight: 400;
  letter-spacing: -0.005em;
  color: var(--text);
}
a.project-link .project-title {
  background-image: linear-gradient(currentColor, currentColor);
  background-size: 0% 1px;
  background-position: 0 100%;
  background-repeat: no-repeat;
  transition: background-size 350ms cubic-bezier(0.2, 0.6, 0.2, 1);
}
a.project-link:hover .project-title { background-size: 100% 1px; }

.project-index {
  font-size: 11px;
  letter-spacing: 0.1em;
  color: var(--text-faint);
  font-feature-settings: "tnum" 1;
}
.project-description {
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.6;
  max-width: 70ch;
}

/* ---------- Work footer ---------- */
.work-footer {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}
.work-footer .dot { opacity: 0.6; }

/* ---------- Project detail page ---------- */
.project-page {
  width: 100%;
  min-height: 100vh;
  padding: var(--pad-y) var(--pad-x);
  display: flex;
  flex-direction: column;
  gap: clamp(40px, 4vw, 72px);
}

.project-page-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--hairline);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--text-muted);
  font-size: 13px;
  letter-spacing: 0.04em;
  font-weight: 500;
  transition: color var(--t-fast), gap var(--t-fast);
}
.back-link:hover { color: var(--text); gap: 14px; }
.back-arrow {
  display: inline-block;
  transition: transform var(--t-med);
}
.back-link:hover .back-arrow { transform: translateX(-3px); }

.project-detail {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  gap: var(--gap-col);
  align-items: start;
  width: 100%;
}
@media (max-width: 900px) {
  .project-detail {
    grid-template-columns: 1fr;
    gap: 40px;
  }
}

.project-sidebar { position: relative; }
.project-sidebar-inner {
  position: sticky;
  top: var(--pad-y);
  display: flex;
  flex-direction: column;
  gap: 28px;
  max-height: calc(100vh - (var(--pad-y) * 2));
  overflow-y: auto;
  padding-right: 8px;
  scrollbar-width: thin;
  scrollbar-color: var(--hairline-strong) transparent;
}
.project-sidebar-inner::-webkit-scrollbar { width: 6px; }
.project-sidebar-inner::-webkit-scrollbar-thumb { background: var(--hairline-strong); border-radius: 3px; }
.project-sidebar-inner::-webkit-scrollbar-track { background: transparent; }

@media (max-width: 900px) {
  .project-sidebar-inner {
    position: static;
    max-height: none;
    overflow: visible;
    padding-right: 0;
  }
}

.project-sidebar-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.project-detail-eyebrow {
  font-size: 12px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
}
.project-detail-title {
  font-family: var(--font-serif);
  font-size: clamp(36px, 4vw, 56px);
  font-weight: 400;
  line-height: 1.05;
  letter-spacing: -0.01em;
  color: var(--text);
}

.project-media-column { min-width: 0; }

.project-detail-media {
  display: flex;
  flex-direction: column;
  gap: clamp(20px, 2vw, 32px);
}
/* On the detail page, show media at its natural aspect — don't crop. */
.project-detail-media .project-media {
  aspect-ratio: auto;
  background: var(--surface);
}
.project-detail-media .project-media img,
.project-detail-media .project-media video {
  width: 100%;
  height: auto;
  object-fit: contain;
  transform: none !important;
}

.project-detail-description-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-top: 22px;
  border-top: 1px solid var(--hairline);
}
.project-detail-description-label {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--text-faint);
  font-weight: 500;
  margin: 0;
}
.project-detail-description {
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
}
.project-detail-description p + p { margin-top: 0.9em; }

.project-page-footer {
  margin-top: auto;
  padding-top: 24px;
  border-top: 1px solid var(--hairline);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-faint);
  letter-spacing: 0.04em;
}
.project-page-footer .back-link { font-size: 12px; }
.project-page-footer .copy { font-feature-settings: "tnum" 1; }

/* Project detail page: keep theme toggle compact in the top nav */
.project-page-nav .theme-toggle { margin-left: 0; }

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
  a.project-link:hover .project-media img,
  a.project-link:hover .project-media video { transform: none; }
}
