:root {
  --bg: #ffffff;
  --text: #111111;
  --muted: #666666;
  --accent: #111111;
  --border: #eaeaea;
  --link: #0645ad;
  --link-hover: #3366cc;
  --link-visited: #0b0080;
  --page-gutter: 0.25rem;
  --page-max: calc(1200px + 1in);
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  /* clip avoids creating a scroll container that breaks position: sticky */
  overflow-x: clip;
}

body {
  font-family: Georgia, "Times New Roman", Times, serif;
  color: var(--text);
  background: var(--bg);
  line-height: 1.6;
  overflow-x: clip;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ===== Navbar (desktop) ===== */
/* Horizontal inset matches .intro so brand + links sit on the
   content column's left/right edges (same max-width and gutter). */
.navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem max(
    var(--page-gutter),
    calc(50% - (var(--page-max) / 2) + var(--page-gutter))
  );
  border-bottom: 1px solid var(--border);
}

.nav-brand {
  font-size: 1.25rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.nav-back {
  display: inline-flex;
  align-items: baseline;
  gap: 0.4rem;
  font-size: 1.05rem;
  color: var(--muted);
  transition: color 0.15s ease;
}

.nav-back span {
  font-size: 1.2rem;
  line-height: 1;
}

.nav-back:hover {
  color: var(--accent);
}

.nav-links {
  position: relative;
  display: flex;
  gap: 2rem;
}

.nav-links a {
  color: var(--muted);
  font-size: 0.95rem;
  transition: color 0.15s ease;
  padding-bottom: 0.25rem;
}

.nav-links a:hover,
.nav-links a.active {
  color: var(--accent);
}

/* Sliding underline that tracks the active/hovered link. Positioned by JS
   (js/nav.js) via width + translateX; sits flush with the bottom of the row. */
.nav-indicator {
  position: absolute;
  left: 0;
  bottom: 0;
  width: 0;
  height: 2px;
  background: var(--accent);
  transform: translateX(0);
  transition: transform 0.28s ease, width 0.28s ease;
  pointer-events: none;
}

.nav-indicator.no-transition {
  transition: none;
}

/* Hamburger button — hidden on desktop */
.nav-toggle {
  display: none;
  flex-direction: column;
  gap: 5px;
  background: none;
  border: none;
  cursor: pointer;
  padding: 4px;
}

.nav-toggle span {
  display: block;
  width: 24px;
  height: 2px;
  background: var(--text);
}

/* ===== Mobile navbar ===== */
.mobile-menu {
  display: none;
  flex-direction: column;
  padding: 0.5rem var(--page-gutter) 1rem;
  border-bottom: 1px solid var(--border);
}

.mobile-menu a {
  padding: 0.75rem 0;
  color: var(--muted);
  border-top: 1px solid var(--border);
}

.mobile-menu a:hover,
.mobile-menu a.active {
  color: var(--accent);
}

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

/* ===== Intro / About ===== */
.intro {
  display: grid;
  grid-template-columns: 1fr 480px;
  grid-template-rows: auto 1fr;
  column-gap: 3rem;
  align-items: start;
  max-width: var(--page-max);
  margin: 4rem auto;
  padding: 0 var(--page-gutter);
}

/* Left column and infobox each span both rows and adopt the parent's
   row tracks as a subgrid, so the heading/title sit on row 1 and the
   body/image sit on row 2 — alignment by construction, no offsets. */
.intro-main {
  grid-column: 1;
  grid-row: 1 / 3;
  display: grid;
  grid-template-rows: subgrid;
}

.intro h1 {
  font-size: 1.9rem;
  line-height: 1.1;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.intro p {
  font-size: 1.1rem;
  color: var(--text);
}

.intro-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.25rem;
}

.btn {
  display: inline-block;
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.4rem 1rem;
  font-size: 0.95rem;
  text-align: center;
  color: var(--text);
  border: 1px solid var(--text);
  transition: color 0.25s ease, background 0.25s ease, border-color 0.25s ease;
}

.btn:hover {
  color: var(--bg);
  background: #0a0a0a;
  border-color: #0a0a0a;
}

.page-footer {
  margin-top: 3rem;
  padding: 1.5rem var(--page-gutter) 3rem;
  border-top: 1px solid var(--border);
}

.footer-icons {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.75rem;
}

.footer-icons a {
  display: inline-flex;
  color: var(--muted);
  transition: color 0.15s ease;
}

.footer-icons a:hover {
  color: var(--accent);
}

.footer-icons svg {
  display: block;
  width: 1.35rem;
  height: 1.35rem;
}

.intro-quote {
  margin: 1.25rem 0 0;
  padding-left: 1.25rem;
  border-left: 3px solid #2b2b2b;
}

.intro-quote p {
  font-size: 0.95rem;
  font-style: italic;
  line-height: 1.5;
  letter-spacing: 0.01em;
  color: #2b2b2b;
}

.intro-body {
  display: flex;
  flex-direction: column;
}

/* ===== Wikipedia-style infobox ===== */
.infobox {
  grid-column: 2;
  grid-row: 1 / 3;
  display: grid;
  grid-template-rows: subgrid;
  font-size: 0.85rem;
  line-height: 1.4;
}

.infobox-title {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  line-height: 1;
  padding: 0.75rem;
  border: 1px solid var(--border);
  border-bottom: none;
  background: #f8f9fa;
}

.infobox-body {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.infobox-panel {
  border: 1px solid var(--border);
  border-top: none;
  background: #f8f9fa;
}

.infobox-image {
  display: block;
  width: 100%;
  height: 390px;
  object-fit: cover;
}

.infobox-caption {
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  padding: 0.4rem 0.75rem 0.6rem;
}

.infobox-table {
  width: 100%;
  border-collapse: collapse;
}

.infobox-table th,
.infobox-table td {
  text-align: left;
  vertical-align: top;
  padding: 0.35rem 0;
  border-top: 1px solid var(--border);
}

.infobox-table th {
  font-weight: 700;
  padding-left: 0.75rem;
  padding-right: 0.75rem;
  white-space: nowrap;
}

.infobox-table td {
  padding-right: 0.75rem;
}

/* ===== Contact ===== */
.contact {
  margin-top: 2rem;
}

.contact h2 {
  font-size: 1.4rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.contact p {
  margin-bottom: 1rem;
}

.contact-list {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 1.5rem;
  row-gap: 0.5rem;
}

.contact-list dt {
  font-weight: 700;
  color: var(--muted);
}

.contact-list dd {
  margin: 0;
}

.contact-list a {
  color: var(--link);
  transition: color 0.15s ease;
}

.contact-list a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

.contact-list a:visited {
  color: var(--link-visited);
}

@media (max-width: 640px) {
  .intro {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    text-align: left;
    padding: 0 var(--page-gutter);
    margin: 2rem auto;
  }

  /* Flatten the wrappers so About text, picture and contact
     become direct grid items that can be individually reordered. */
  .intro-main,
  .intro-body {
    display: contents;
  }

  .intro h1,
  .intro-body > p,
  .intro-actions {
    order: 1;
    min-width: 0;
  }

  .infobox {
    grid-column: 1;
    grid-row: auto;
    display: block;
    order: 2;
    margin-top: 4.5rem;
    min-width: 0;
  }

  .infobox-body {
    display: flex;
    flex-direction: column;
    height: auto;
  }

  .infobox-image {
    height: 280px;
  }

  .contact {
    order: 3;
    margin-top: 4.5rem;
  }

  .intro-actions {
    justify-content: flex-start;
  }

  .intro-actions .btn {
    flex: 1 1 calc(33.333% - 0.35rem);
    padding: 0.4rem 0.5rem;
    font-size: 0.9rem;
  }

  .contact-list {
    display: block;
  }

  .contact-list dt {
    margin-top: 0.75rem;
  }

  .contact-list dt:first-child {
    margin-top: 0;
  }

  .contact-list dd {
    overflow-wrap: anywhere;
  }
}

/* ===== Projects / Experience layout ===== */
/* Same content column as .intro / navbar (page-max + gutter). */
.projects,
.experience {
  max-width: var(--page-max);
  margin: 4rem auto;
  padding: 0 var(--page-gutter);
}

/* Wikipedia-style contents box. Full-width above the reading column by
   default; on wide screens it becomes a sticky left rail inside the
   same page-max column as the navbar. */
.toc {
  border: 1px solid var(--border);
  background: #f8f9fa;
  font-size: 0.9rem;
  line-height: 1.45;
  width: 100%;
  max-width: 100%;
  margin: 0 0 2rem;
  box-sizing: border-box;
}

@media (min-width: 1200px) {
  .projects {
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
    column-gap: 3rem;
  }

  .toc {
    width: 220px;
    max-width: 220px;
    margin: 0;
    position: sticky;
    top: 1.5rem;
    align-self: start;
  }
}

.toc-toggle {
  display: block;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: none;
  border-bottom: 1px solid var(--border);
  background: #eaecf0;
  font: inherit;
  font-weight: 700;
  color: inherit;
  cursor: pointer;
  text-align: center;
}

.toc.collapsed .toc-toggle {
  border-bottom: none;
}

.toc-panel {
  overflow: hidden;
}

.toc.collapsed .toc-panel {
  display: none;
}

.toc-list {
  list-style: none;
  padding: 0.75rem 1rem 1rem;
  margin: 0;
}

.toc-list > li + li {
  margin-top: 0.75rem;
}

.toc-list ul {
  list-style: none;
  padding: 0.35rem 0 0 1rem;
  margin: 0;
}

.toc-list ul li + li {
  margin-top: 0.25rem;
}

.toc-list a {
  color: var(--link);
  transition: color 0.15s ease;
}

.toc-list a:hover {
  color: var(--link-hover);
  text-decoration: underline;
}

.toc-list a:visited {
  color: var(--link-visited);
}

.projects-main,
.experience-main {
  min-width: 0;
}

.page-heading {
  font-size: 2.75rem;
  line-height: 1.1;
  font-weight: 400;
  letter-spacing: -0.02em;
  margin-bottom: 2.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.project,
.project-section,
.experience-entry,
.experience-section {
  scroll-margin-top: 1.5rem;
}

.project + .project,
.experience-entry + .experience-entry {
  margin-top: 4.5rem;
  padding-top: 3rem;
  border-top: 1px solid var(--border);
}

.page-heading + .experience-entry {
  margin-top: 0;
}

.project-title,
.experience-title {
  font-size: 1.9rem;
  line-height: 1.1;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-bottom: 1.5rem;
  padding-bottom: 0.5rem;
  border-bottom: 1px solid var(--border);
}

.project-section + .project-section,
.experience-section + .experience-section {
  margin-top: 4rem;
}

.project-section h2,
.experience-section h3 {
  font-size: 1.4rem;
  font-weight: 400;
  letter-spacing: -0.01em;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.project-section p,
.experience-section p {
  font-size: 1.05rem;
  margin-bottom: 1rem;
}

.project-meta,
.experience-meta {
  color: var(--muted);
  font-size: 0.95rem;
}

.experience-title + .experience-meta {
  margin: -0.75rem 0 1.5rem;
}

.project-media {
  margin: 1.25rem 0 0;
}

.project-media-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  aspect-ratio: 4 / 3;
  min-height: 480px;
  border: 1px solid var(--border);
  background: #f8f9fa;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
  padding: 1.5rem;
  box-sizing: border-box;
}

.project-media img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid var(--border);
}

.project-media figcaption {
  margin-top: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
  text-align: center;
}

/* Process timeline: 01 ───── 02 ───── 03 ───── 04
   Numbers occupy content columns; hairlines sit in the gutters. */
.process-steps {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr auto 1fr auto 1fr auto 1fr;
  align-items: start;
  margin: 1.25rem 0 1.5rem;
  padding: 0;
}

.process-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.4rem;
}

.process-rule {
  align-self: start;
  width: 1.5rem;
  margin-top: 0.75rem;
  border-top: 1px solid var(--text);
}

.process-num {
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.process-label {
  font-size: 0.9rem;
  color: var(--muted);
}

@media (max-width: 640px) {
  .projects,
  .experience {
    padding: 0 var(--page-gutter);
    margin: 2rem auto;
  }

  .project,
  .project-section,
  .experience-entry,
  .experience-section {
    scroll-margin-top: 5.5rem;
  }

  .process-steps {
    grid-template-columns: 1fr auto 1fr;
    row-gap: 1.25rem;
  }

  /* Hide the connector between Prototype (end of row 1)
     and Problem (start of row 2). */
  .process-steps .process-rule:nth-child(4) {
    display: none;
  }

  .project-media-placeholder {
    min-height: 320px;
    aspect-ratio: 1 / 1;
  }
}

/* ===== Floating mobile dock ===== */
.mobile-dock {
  display: none;
}

@media (max-width: 640px) {
  .navbar,
  .mobile-menu {
    display: none;
  }

  body {
    padding-top: 5rem;
  }

  .mobile-dock {
    display: flex;
    position: fixed;
    left: 50%;
    top: 1.25rem;
    transform: translateX(-50%);
    z-index: 100;
    gap: 0.25rem;
    padding: 0.35rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 999px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
    transition: transform 0.3s ease, opacity 0.3s ease;
  }

  .mobile-dock.hidden {
    transform: translate(-50%, -150%);
    opacity: 0;
    pointer-events: none;
  }

  /* Sliding black pill behind the active/tapped dock link. */
  .dock-indicator {
    position: absolute;
    top: 0.35rem;
    left: 0;
    height: calc(100% - 0.7rem);
    width: 0;
    background: var(--accent);
    border-radius: 999px;
    transform: translateX(0);
    transition: transform 0.3s ease, width 0.3s ease;
    pointer-events: none;
    z-index: 0;
  }

  .dock-indicator.no-transition {
    transition: none;
  }

  .mobile-dock a {
    position: relative;
    z-index: 1;
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    color: var(--muted);
    border-radius: 999px;
    transition: color 0.2s ease;
  }

  .mobile-dock a.active {
    color: var(--bg);
  }
}
