* {
  box-sizing: border-box;
}

:root {
  --main-color: #111111;
  --overlay-color: #9fc5ff4d;

  --border-strong: color-mix(in srgb, var(--main-color) 50%, transparent);
  --border-medium: color-mix(in srgb, var(--main-color) 40%, transparent);
  --border-soft: color-mix(in srgb, var(--main-color) 30%, transparent);
  --surface-hover: color-mix(in srgb, #f5f5f5 10%, transparent);
  --surface-hover-soft: color-mix(in srgb, #f5f5f5 7%, transparent);
  --interactive-duration: 0.18s;
  --interactive-ease: ease;
  --focus-ring: color-mix(in srgb, var(--main-color) 45%, transparent);

  --project-main-col: 280px;
  --project-links-col: 240px;
  --project-tags-col: 300px;
}

body.dark {
  --main-color: #f5f5f5;
  --overlay-color: #071a33b3;
  --border-strong: color-mix(in srgb, var(--main-color) 58%, transparent);
  --border-medium: color-mix(in srgb, var(--main-color) 48%, transparent);
  --border-soft: color-mix(in srgb, var(--main-color) 38%, transparent);
  background: linear-gradient(to bottom, #285596 0%, #000103 100%) fixed;
}

body {
  margin: 0;
  font-family: system-ui, sans-serif;
  background: linear-gradient(to bottom, #6898de 0%, #fafafa 100%) fixed;
  color: var(--main-color);
}

a,
button {
  transition:
    color var(--interactive-duration) var(--interactive-ease),
    border-color var(--interactive-duration) var(--interactive-ease),
    background-color var(--interactive-duration) var(--interactive-ease),
    opacity var(--interactive-duration) var(--interactive-ease),
    text-decoration-color var(--interactive-duration) var(--interactive-ease);
}

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

h1 {
  font-family: Georgia, serif;
  text-align: center;
}

.intro {
  width: min(550px, 100%);
  margin: 0.85rem auto 0;
  line-height: 1.6;
  text-align: center;
  opacity: 0.78;
  font-size: clamp(0.95rem, 1.6vw, 1.03rem);
}

.page {
  width: min(1100px, 92%);
  margin: 0 auto;
  padding: 2rem 0 5rem;
}

.site-header {
  margin-bottom: 2.5rem;
}

.header-top {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 2.5rem;
  font-size: 0.875rem;
}

.note,
.socials a {
  margin: 0;
  opacity: 0.6;
}

.note a {
  color: inherit;
}

.note a:hover {
  text-decoration: underline;
}

footer {
  margin-top: 5rem;
  text-align: center;
  font-size: 0.875rem;
}

.footer-row {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 1rem;
}

.footer-note {
  justify-self: center;
}

.footer-pages {
  justify-self: end;
}

.socials {
  display: flex;
  gap: 0.875rem;
  flex-wrap: wrap;
  align-items: center;
}

.socials a,
.project-links a {
  color: inherit;
  text-decoration: none;
}

.socials a:hover {
  opacity: 1;
  text-decoration: underline;
}

.socials a[aria-current="page"] {
  opacity: 1;
  text-decoration: underline;
  text-underline-offset: 0.12em;
}

.theme-toggle,
.menu-toggle {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 999px;
  background: transparent;
  color: inherit;
  padding: 0.25rem;
  margin: 0;
  line-height: 1;
  cursor: pointer;
  opacity: 0.6;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.theme-toggle:hover,
.menu-toggle:hover {
  opacity: 1;
  border-color: var(--border-soft);
  background-color: var(--surface-hover-soft);
}

.theme-toggle-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.utility-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  color: currentColor;
  stroke-width: 2;
  vertical-align: middle;
}

.icon-sun {
  display: none;
}

body.dark .icon-moon {
  display: none;
}

body.dark .icon-sun {
  display: inline;
}

.mobile-controls,
.mobile-menu {
  display: none;
}

h1 {
  font-size: clamp(1.6rem, 4vw, 2rem);
}

.featured {
  margin-top: 0;
  margin-bottom: 5rem;
}

.archive {
  margin-top: 4rem;
}

.section-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
  margin-bottom: 1.5rem;
}

.section-header h2 {
  order: 1;
}

.section-header .section-label {
  order: 2;
  margin-left: auto;
}

.section-label {
  margin: 0;
  opacity: 0.6;
  font-size: 0.875rem;
}

.section-header h2 {
  margin: 0;
  font-family: Georgia, serif;
  font-size: clamp(1.1rem, 2vw, 1.35rem);
  font-weight: 400;
}

.featured-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1.5rem;
}

.featured-project {
  display: grid;
  gap: 1rem;
  align-content: start;
  padding: 1.25rem 0 1.5rem;
  border-top: 1px solid var(--border-soft);
}

.featured-thumbnail {
  width: 100%;
  height: auto;
  aspect-ratio: 16 / 9;
  border: 1px solid var(--border-strong);
  background: #ddd;
  object-fit: cover;
  display: block;
}

.featured-content {
  display: grid;
  gap: 0.875rem;
}

.featured-meta {
  display: grid;
  grid-template-columns: 1fr;
  align-items: flex-start;
  gap: 0.75rem;
}

.featured-project .project-links,
.featured-project .project-tags {
  grid-area: auto;
  min-width: 0;
  align-self: start;
  margin-top: 0;
  margin-bottom: 0;
}

.featured-project .project-links {
  justify-content: flex-start;
  justify-self: start;
}

.featured-project .project-tags {
  justify-content: flex-start;
  justify-self: start;
  margin-left: 0;
}

.featured-copy {
  display: grid;
  gap: 0.45rem;
}

.featured-description {
  width: 100%;
  margin: 0;
}

.featured-project h3 {
  margin: 0;
  font-size: clamp(1rem, 1.4vw, 1.1rem);
  font-weight: 500;
  margin-bottom: 0.2rem;
}

.featured-description {
  opacity: 0.75;
  line-height: 1.5;
  font-size: 0.95rem;
}

.projects {
  border-top: 1px solid var(--border-soft);
  overflow: visible;
}

.project {
  display: grid;
  grid-template-columns:
    124px minmax(0, var(--project-main-col)) minmax(0, var(--project-links-col))
    minmax(0, 1fr);
  grid-template-areas: "thumb main links tags";
  gap: 1rem;
  align-items: start;
  padding: 1rem 0;
  border-bottom: 1px solid var(--border-soft);
  overflow: visible;
}

.thumbnail {
  grid-area: thumb;
  width: 124px;
  height: 70px;
  border: 1px solid var(--border-strong);
  background: #ddd;
  object-fit: cover;
  display: block;
}

.project-main {
  grid-area: main;
  min-width: 0;
  margin-top: 0.5rem;
  margin-bottom: auto;
}

.project h2 {
  margin: 0 0 1rem;
  font-size: clamp(0.95rem, 1.2vw, 1rem);
}

.subtitle {
  margin: 0;
  text-transform: uppercase;
  opacity: 0.7;
  font-size: clamp(0.85rem, 1vw, 0.938rem);
}

.project-links {
  grid-area: links;
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: start;
  justify-self: stretch;
  min-width: 0;
  margin-top: auto;
  margin-bottom: auto;
}

.project-links a {
  display: inline-flex;
  gap: 0.4rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border-medium);
  border-radius: 999px;
  font-size: clamp(0.875rem, 0.8vw, 0.9375rem);
}

.project-links a:hover {
  background-color: var(--surface-hover);
  transform: scale(1.01);
}

.link-icon {
  width: 16px;
  height: 16px;
  flex: 0 0 16px;
  color: currentColor;
  stroke-width: 2;
  vertical-align: middle;
}

.project-tags {
  grid-area: tags;
  display: flex;
  gap: 0.625rem;
  flex-wrap: wrap;
  justify-content: end;
  justify-self: end;
  min-width: 0;
  margin-top: auto;
  margin-bottom: auto;
}

.project-tags span {
  border: 1px solid var(--border-soft);
  padding: 0.35rem 0.6rem;
  opacity: 0.8;
  font-size: clamp(0.813rem, 1.2vw, 0.875rem);
}

/* ─── Tablet ────────────────────────────────────────────
   Two-column layout:
     Left  — thumbnail + project text, side by side, spanning both rows
     Right — project links (top) and project tags (bottom), both right-aligned
   ─────────────────────────────────────────────────────────────────────── */
@media (max-width: 880px) {
  .featured-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.25rem;
  }

  .project {
    grid-template-columns: 124px 1fr auto;
    grid-template-rows: auto auto;
    grid-template-areas:
      "thumb main links"
      "thumb main tags";
    gap: 0.5rem 1rem;
  }

  .project-main {
    align-self: start;
  }

  .project-links {
    justify-self: end;
    justify-content: flex-end;
    align-self: end;
  }

  .project-tags {
    justify-self: end;
    justify-content: flex-end;
    align-self: start;
  }
}

/* ─── Mobile stacked layout ───────────────────────────────────
   Single-column stack per project.  All four pieces read top-to-bottom:
   thumbnail → text → links → tags.  Projects keep the same divider lines
   as desktop.  Header nav stacks here too.
   ─────────────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  .page {
    padding: 0 0 5rem;
  }

  .header-top {
    margin-bottom: 1rem;
  }

  .header-top .note,
  .header-top .socials {
    display: none;
  }

  .mobile-controls {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
  }

  .mobile-controls .header-button {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 42px;
  }

  .mobile-controls .utility-icon {
    width: 19px;
    height: 19px;
    flex: 0 0 19px;
  }

  .mobile-controls .header-button:hover {
    opacity: 1;
    border-color: var(--border-soft);
    background-color: var(--surface-hover-soft);
  }

  .mobile-controls .header-button:active {
    opacity: 0.8;
  }

  .mobile-menu {
    display: none;
    flex-direction: column;
    gap: 0.75rem;
    margin: 0 0 1.25rem;
    padding: 0.875rem 0;
    border-top: 1px solid var(--border-soft);
    border-bottom: 1px solid var(--border-soft);
  }

  .mobile-menu.is-open {
    display: flex;
  }

  .mobile-menu a,
  .mobile-menu-note {
    color: inherit;
    text-decoration: none;
    font-size: 0.875rem;
    opacity: 0.6;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border-soft);
  }

  .mobile-menu a:hover {
    opacity: 1;
    text-decoration: underline;
  }

  .mobile-menu :last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .projects {
    border-top: 1px solid var(--border-medium);
  }

  .featured {
    margin-top: 0;
    margin-bottom: 3.5rem;
  }

  .intro {
    margin-top: 0.7rem;
    font-size: 0.95rem;
    line-height: 1.55;
  }

  .archive {
    margin-top: 2.75rem;
  }

  .section-header {
    flex-direction: row;
    align-items: baseline;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
  }

  .section-label,
  .section-header h2 {
    min-width: 0;
  }

  .featured-project {
    gap: 0.875rem;
    padding: 1.1rem 0 1.5rem;
  }

  .featured-grid {
    grid-template-columns: 1fr;
  }

  .featured-meta {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .featured-project .project-tags {
    justify-content: flex-start;
    justify-self: start;
    margin-left: 0;
  }

  .featured-description {
    max-width: none;
    font-size: 0.9rem;
  }

  .project {
    border-bottom: 1px solid var(--border-medium);
  }

  .project {
    grid-template-columns: 1fr;
    grid-template-areas:
      "thumb"
      "main"
      "links"
      "tags";
    gap: 0.625rem;
    padding: 1.25rem 0;
    padding-bottom: 3rem;
  }

  .thumbnail {
    width: 100%;
    height: auto;
    aspect-ratio: 16 / 9;
  }

  .project-main {
    gap: 1rem;
  }

  .project h2 {
    margin: 0 0 0.35rem;
  }

  .project-links {
    justify-content: flex-start;
    justify-self: start;
    gap: 0.5rem;
  }

  .project-tags {
    justify-content: flex-start;
    justify-self: start;
  }

  .footer-row {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 0.75rem;
  }

  .footer-pages {
    justify-self: center;
  }
}
