:root {
  --text: rgba(32, 32, 32, 0.88);
  --muted: rgba(32, 32, 32, 0.5);
  --soft: rgba(32, 32, 32, 0.65);
  --card: #f4f4f4;
  --bg: #fff;
  --sidebar: 355px;
  --gap: 24px;
  --radius: 40px;
  --pad: 40px;
  /* Strong ease-out for UI interactions */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  /* Gentle ease-in-out for on-screen movement */
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11";
}

a { color: inherit; text-decoration: none; }
img, video { display: block; max-width: 100%; }
p { margin: 0; }
ul { margin: 0; padding: 0; }

/* ---------- Layout ---------- */

.layout {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: var(--pad);
}

.brand__name { font-size: 22px; line-height: 1.3; }
.brand__role { font-size: 17px; color: var(--muted); margin-top: 8px; }

.nav {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 30px;
}

.nav a { color: var(--muted); transition: color 0.2s; }
.nav a:hover,
.nav a[aria-current="page"] { color: var(--text); }

.sidebar__bottom { margin-top: auto; }

/* ---------- "Show all projects" ---------- */

.all-projects {
  display: grid;
  grid-template-rows: 0fr;
  /* Collapse only after the items have faded out */
  transition: grid-template-rows 0s 0.15s;
}
.all-projects > ul { overflow: hidden; list-style: none; }
.sidebar.is-open .all-projects { grid-template-rows: 1fr; transition-delay: 0s; }

.all-projects li {
  line-height: 1.2;
  padding-bottom: 18px;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  /* Exit: fast, all at once */
  transition: opacity 0.15s var(--ease-out), transform 0.15s var(--ease-out), visibility 0.15s;
}
.sidebar.is-open .all-projects li {
  opacity: 1;
  visibility: visible;
  transform: none;
  /* Enter: stagger upwards from the toggle */
  transition-duration: 0.3s;
}
.sidebar.is-open .all-projects li:nth-last-child(2) { transition-delay: 30ms; }
.sidebar.is-open .all-projects li:nth-last-child(3) { transition-delay: 60ms; }
.sidebar.is-open .all-projects li:nth-last-child(4) { transition-delay: 90ms; }
.sidebar.is-open .all-projects li:nth-last-child(5) { transition-delay: 120ms; }
.sidebar.is-open .all-projects li:nth-last-child(6) { transition-delay: 150ms; }
.all-projects li:last-child { padding-bottom: 36px; }
.all-projects a { display: inline-block; transition: color 0.2s; }
.all-projects a:hover { color: var(--muted); }
.all-projects .meta { margin-top: 8px; }

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: var(--muted);
  cursor: pointer;
  transform-origin: left center;
  transition: color 0.2s ease, transform 0.16s var(--ease-out);
}
.toggle:hover,
.sidebar.is-open .toggle { color: var(--text); }
.toggle:active { transform: scale(0.97); }

/* Eyes: open by default, blink twice on hover, closed while the list is open */
.eyes {
  position: relative;
  flex: none;
  width: 16px;
  height: 22px;
  color: var(--muted);
  transition: color 0.2s;
}
.toggle:hover .eyes { color: var(--text); }
.sidebar.is-open .eyes { color: var(--muted); }

.eyes__open {
  position: absolute;
  top: 5px;
  left: 0;
  display: flex;
  gap: 5px;
}
.eyes__open i {
  width: 5px;
  height: 12px;
  border-radius: 25px;
  background: currentColor;
}

.eyes__closed {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: visible;
  opacity: 0;
}

@media (hover: hover) and (pointer: fine) {
  .toggle:hover .eyes__open { animation: eyes-open 0.4s linear; }
  .toggle:hover .eyes__closed { animation: eyes-closed 0.4s linear; }
}
.sidebar.is-open .eyes__open { opacity: 0; animation: none; }
.sidebar.is-open .eyes__closed { opacity: 1; animation: none; }

/* 150ms open → 85ms closed → 80ms open → 85ms closed → open */
@keyframes eyes-open {
  0%, 37.4% { opacity: 1; }
  37.5%, 58.7% { opacity: 0; }
  58.8%, 78.7% { opacity: 1; }
  78.8%, 99.9% { opacity: 0; }
  100% { opacity: 1; }
}
@keyframes eyes-closed {
  0%, 37.4% { opacity: 0; }
  37.5%, 58.7% { opacity: 1; }
  58.8%, 78.7% { opacity: 0; }
  78.8%, 99.9% { opacity: 1; }
  100% { opacity: 0; }
}

.arrow {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-left: 4px;
  vertical-align: 1px;
}

/* ---------- Main ---------- */

.main {
  min-width: 0;
  padding: var(--pad) var(--pad) var(--pad) 40px;
}

/* ---------- Cards ---------- */

.card {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  background: var(--card);
  aspect-ratio: 3 / 2;
  /* Safari: keep rounded corners while children animate */
  isolation: isolate;
}

.card > img,
.card > video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card--top > img,
.card--top > video { object-position: top; }
.card--bottom > img { object-position: bottom; }
.card--face > img { object-position: 50% 46%; }
/* Pushes thin black edges baked into the file outside the card */
.card--trim > video { transform: scale(1.012); }
.card--contain > img { object-fit: contain; padding: 24px; }
.card--zoom > img { transform: scale(1.7); }
.card--dark { background: radial-gradient(120% 90% at 50% 100%, #6b221c 0%, #2a1311 55%, #140d0c 100%); }
.card--dark > img { object-fit: contain; padding: 12% 6%; }

.card--nda {
  display: grid;
  place-items: center;
  color: var(--muted);
}

/* ---------- Home: project rows ---------- */

.projects { display: flex; flex-direction: column; gap: var(--gap); }

.project {
  display: flex;
  gap: var(--gap);
  height: 400px;
}

.project__info {
  flex: 0 0 0;
  margin-right: calc(var(--gap) * -1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  opacity: 0;
  /* Exit */
  transition: flex-basis 0.35s var(--ease-in-out), margin 0.35s var(--ease-in-out), opacity 0.2s ease;
}
.project__info > * { width: 235px; }
.project__info > div > * { width: auto; }

.project__title { display: inline-block; font-size: 17px; transition: color 0.2s; }
.project__title:hover { color: var(--muted); }
.project__meta { color: var(--muted); margin-top: 4px; }
.project__desc { color: var(--muted); }

.project .card {
  flex: 1 1 0;
  aspect-ratio: auto;
  height: 100%;
  min-width: 0;
}

@media (hover: hover) and (pointer: fine) {
  .project:hover .project__info {
    flex-basis: 235px;
    margin-right: 0;
    opacity: 1;
    /* Enter: text fades in while the panel opens */
    transition-duration: 0.45s, 0.45s, 0.3s;
    transition-delay: 0s, 0s, 0.1s;
  }
}

/* ---------- Case study ---------- */

.back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  transition: color 0.2s;
}
.back:hover { color: var(--muted); }
.back svg { width: 12px; height: 12px; }

.case-head { margin-top: 40px; }
.case-head h1 { font-size: 22px; font-weight: 400; margin: 0; line-height: 1.3; }
.case-head p { margin-top: 6px; }
.case-head a { color: var(--muted); transition: color 0.2s; }
.case-head a:hover { color: var(--text); }

.prose { max-width: 800px; }
.prose h2 {
  font-size: 22px;
  font-weight: 500;
  line-height: 1.3;
  margin: 72px 0 20px;
}
.prose p + p,
.prose p + ul,
.prose ul + p { margin-top: 20px; }
.prose p + ul.tight { margin-top: 0; }
.prose ul { padding-left: 32px; }
.prose li::marker { font-size: 0.8em; }

/* Award name with a tooltip */
.tip {
  position: relative;
  color: var(--muted);
  text-decoration: underline;
  cursor: pointer;
  outline: none;
  transition: color 0.2s;
}
.tip:hover,
.tip:focus-visible { color: var(--text); }

.tip__bubble {
  position: absolute;
  top: calc(100% + 8px);
  left: 50%;
  z-index: 10;
  width: 296px;
  max-width: calc(100vw - 32px);
  padding: 12px;
  border-radius: 16px;
  background: #393939;
  color: #fff;
  font-size: 13px;
  font-weight: 400;
  line-height: 1.45;
  transform: translateX(-50%) scale(0.97);
  transform-origin: top center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  /* Exit: fast */
  transition: opacity 0.1s var(--ease-out), transform 0.1s var(--ease-out), visibility 0.1s;
}
.tip:hover .tip__bubble,
.tip:focus-visible .tip__bubble {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%);
  /* Enter */
  transition-duration: 0.15s;
}
/* Touch screens: open on tap */
@media (hover: none) {
  .tip:focus { color: var(--text); }
  .tip:focus .tip__bubble { opacity: 1; visibility: visible; transform: translateX(-50%); transition-duration: 0.15s; }
}

.section { margin-top: 72px; }
.section__title { font-size: 17px; }
.section__sub { color: var(--muted); margin-top: 4px; }

.pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--gap);
  margin-top: 28px;
}

.duo {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 24px 24px 0;
}
.duo img { width: 100%; height: auto; border-radius: 16px 16px 0 0; }

/* ---------- About ---------- */

.page-title { font-size: 22px; font-weight: 400; margin: 0 0 20px; line-height: 1.3; }

.about-intro { max-width: 800px; }
.about-intro p + p { margin-top: 20px; }

.photos { margin-top: 28px; }

.experience { margin-top: 64px; max-width: 1000px; }
.job { margin-top: 28px; }
.job__head { display: flex; justify-content: space-between; gap: 16px; }
.job__desc { color: var(--muted); font-style: italic; max-width: 680px; margin-top: 8px; }
.job__role { margin-top: 8px; }
.job__role span { color: var(--muted); }
.job ul { color: var(--muted); max-width: 680px; margin-top: 20px; padding-left: 32px; }
.job li::marker { font-size: 0.8em; }
.job li b { color: var(--soft); font-weight: 600; }
.job a { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Connect ---------- */

.connect-intro { max-width: 800px; }
.contacts {
  display: grid;
  grid-template-columns: 128px auto;
  gap: 16px 0;
  margin-top: 56px;
  justify-content: start;
}
.contacts dt { color: var(--muted); }
.contacts dd { margin: 0; }
.contacts a { color: var(--muted); transition: color 0.2s; }
.contacts a:hover { color: var(--text); }

/* ---------- 404 ---------- */

.notfound p + p { margin-top: 12px; }
.notfound a { text-decoration: underline; text-underline-offset: 3px; }

/* ---------- Tablet & mobile ---------- */

@media (max-width: 1100px) {
  :root { --sidebar: 260px; }
  .project { height: 320px; }
}

@media (max-width: 809px) {
  :root { --pad: 20px; --radius: 28px; --gap: 16px; }

  body { font-size: 16px; }

  .layout { display: block; }

  .sidebar {
    position: static;
    height: auto;
    padding: 28px var(--pad) 0;
  }

  .nav { flex-direction: row; gap: 24px; margin-top: 24px; }

  .sidebar__bottom { display: none; }

  .main { padding: 32px var(--pad) 48px; }

  .projects { gap: 48px; }

  .project { flex-direction: column; height: auto; gap: 12px; }
  .project__info {
    flex: none;
    margin: 0 0 8px;
    opacity: 1;
    overflow: visible;
  }
  .project__info > * { width: auto; }
  .project__desc { margin-top: 8px; }
  .project .card { flex: none; height: auto; aspect-ratio: 5 / 4; }

  .pair { grid-template-columns: 1fr; gap: 12px; }

  .prose h2 { font-size: 20px; margin-top: 56px; }
  .section { margin-top: 56px; }

  .job__head { flex-direction: column; gap: 0; }
  .job__head span:last-child { color: var(--muted); }

  .contacts { grid-template-columns: 96px auto; }
}

/* Reduced motion: keep color and opacity fades, drop movement and blinking */
@media (prefers-reduced-motion: reduce) {
  .toggle:active { transform: none; }
  .toggle:hover .eyes__open,
  .toggle:hover .eyes__closed { animation: none; }
  .all-projects li { transform: none; transition-delay: 0s !important; }
  .project__info { transition: opacity 0.2s ease; }
  .tip__bubble,
  .tip:hover .tip__bubble,
  .tip:focus-visible .tip__bubble { transform: translateX(-50%); }
}
