.project-detail-page {
  --project-accent: #8c0c0c;
  --project-ink: #242321;
  --project-muted: #66645e;
  --project-line: #d8d5ce;
  --project-panel: #ffffff;
  --project-surface: #f5f6f3;
  padding: clamp(6px, 1.5vw, 16px) 0 56px;
}

.project-content {
  max-width: 1120px;
  margin: 0 auto;
}

.back-link {
  display: inline-flex;
  align-items: center;
  margin: 0 0 22px;
  color: var(--project-accent);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.86rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-decoration: none;
  text-transform: uppercase;
}

.back-link:hover {
  text-decoration: underline;
}

.project-mobile-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 22px;
}

.project-mobile-actions .back-link {
  margin: 0;
}

.project-details-button {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 12px;
  color: var(--project-accent);
  background: var(--project-surface);
  border: 1px solid var(--project-line);
  border-radius: 999px;
  cursor: pointer;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.project-details-button:focus-visible,
.project-drawer-close:focus-visible,
.project-drawer-backdrop:focus-visible {
  outline: 2px solid var(--project-accent);
  outline-offset: 3px;
}

/* MARK: Detail shell + rails */
.project-shell {
  max-width: 1120px;
  margin: 0 auto;
}

.project-main {
  container-type: inline-size;
  min-width: 0;
}

.project-rail {
  display: none;
}

.project-content :is(h2, h3) {
  scroll-margin-top: calc(var(--header-height, 64px) + 16px);
}

@media (min-width: 1120px) {
  .main-content:has(.project-detail-page) {
    max-width: 1320px;
  }

  .project-shell {
    display: grid;
    grid-template-columns: 200px minmax(0, 1fr) 210px;
    gap: clamp(24px, 3vw, 44px);
    align-items: start;
    max-width: 1320px;
  }

  .project-main {
    grid-column: 2;
  }

  .project-rail {
    display: block;
    position: fixed;
    top: calc(var(--current-header-height, var(--header-height, 64px)) + 8px);
    width: 210px;
    max-height: calc(100vh - var(--current-header-height, var(--header-height, 64px)) - 18px);
    overflow-y: auto;
    font-family: Arial, Helvetica, sans-serif;
  }

  .project-rail--left {
    left: max(20px, calc((100vw - 1320px) / 2));
    width: 200px;
  }

  .project-rail--right {
    right: max(20px, calc((100vw - 1320px) / 2));
  }

  .back-link--mobile {
    display: none;
  }

  .project-mobile-actions {
    display: none;
  }
}

.rail-back {
  display: inline-block;
  margin-bottom: 14px;
  color: var(--project-accent);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  text-decoration: none;
}

.rail-back:hover {
  text-decoration: underline;
}

.rail-project-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--project-line);
}

.rail-project-list a {
  display: block;
  padding: 7px 0;
  border-bottom: 1px solid var(--project-line);
  color: var(--project-muted);
  font-size: 0.84rem;
  line-height: 1.3;
  text-decoration: none;
  transition: color 0.15s ease;
}

.rail-project-list a:hover {
  color: var(--project-accent);
}

.rail-project-list a.is-active {
  color: var(--project-accent);
  font-weight: 700;
}

.rail-card {
  padding: 14px 16px;
  background: var(--project-surface);
  border: 1px solid var(--project-line);
  border-radius: 8px;
}

.rail-card + .rail-card {
  margin-top: 12px;
}

.rail-card-label {
  margin: 0 0 3px;
  color: var(--project-muted);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rail-card-label:not(:first-child) {
  margin-top: 12px;
}

.rail-card-value {
  margin: 0;
  color: var(--project-ink);
  font-size: 0.94rem;
  line-height: 1.4;
}

.rail-link-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
}

.rail-link-list a {
  color: var(--project-accent);
  font-size: 0.84rem;
  font-weight: 700;
  text-decoration: none;
}

.rail-link-list a:hover {
  text-decoration: underline;
}

.rail-outline {
  margin-top: 20px;
}

.rail-outline-title {
  margin: 0 0 8px;
  color: var(--project-muted);
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.rail-outline ul {
  list-style: none;
  margin: 0;
  padding: 0;
  border-left: 2px solid var(--project-line);
}

.rail-outline a {
  display: block;
  margin-left: -2px;
  padding: 5px 0 5px 12px;
  border-left: 2px solid transparent;
  color: var(--project-muted);
  font-size: 0.84rem;
  line-height: 1.3;
  text-decoration: none;
}

.rail-outline li.lvl-3 a {
  padding-left: 24px;
  font-size: 0.8rem;
}

.rail-outline a:hover {
  color: var(--project-accent);
}

.rail-outline a.is-active {
  color: var(--project-accent);
  border-left-color: var(--project-accent);
}

.project-drawer {
  display: none;
}

body.project-drawer-open {
  overflow: hidden;
}

@media (max-width: 1119px) {
  .project-drawer {
    position: fixed;
    inset: 0;
    z-index: 10020;
    display: block;
    visibility: hidden;
    pointer-events: none;
  }

  .project-drawer.is-open {
    visibility: visible;
    pointer-events: auto;
  }

  .project-drawer-backdrop {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    padding: 0;
    background: rgba(0, 0, 0, 0.48);
    border: 0;
    opacity: 0;
    cursor: pointer;
    transition: opacity 0.18s ease;
  }

  .project-drawer.is-open .project-drawer-backdrop {
    opacity: 1;
  }

  .project-drawer-sheet {
    position: absolute;
    right: 0;
    bottom: 0;
    left: 0;
    max-height: min(78vh, 620px);
    padding: 14px 16px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto;
    color: var(--project-ink);
    background: var(--project-panel);
    border: 1px solid var(--project-line);
    border-width: 1px 0 0;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -16px 40px rgba(0, 0, 0, 0.28);
    transform: translateY(100%);
    transition: transform 0.2s ease;
  }

  .project-drawer.is-open .project-drawer-sheet {
    transform: translateY(0);
  }

  .project-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
  }

  .project-drawer-header h2 {
    margin: 0;
    color: var(--project-ink);
    font-size: 1rem;
    line-height: 1.2;
  }

  .project-drawer-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    color: var(--project-muted);
    background: transparent;
    border: 1px solid var(--project-line);
    border-radius: 999px;
    cursor: pointer;
    font-size: 1.45rem;
    line-height: 1;
  }

  .project-drawer .rail-outline {
    margin-top: 14px;
  }
}

.project-header {
  max-width: 820px;
  margin-bottom: clamp(22px, 4vw, 36px);
}

.project-kicker {
  color: #5d6d62;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  line-height: 1.2;
  margin: 0 0 8px;
  text-transform: uppercase;
}

.project-title {
  color: var(--project-ink);
  font-size: clamp(1.55rem, 2.35vw, 2.05rem);
  font-weight: 600;
  line-height: 1.12;
  margin: 0;
}

.project-subtitle {
  color: var(--project-muted);
  font-size: clamp(1.04rem, 1.8vw, 1.22rem);
  line-height: 1.5;
  max-width: 680px;
  margin: 16px 0 0;
}

.project-layout {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(0, 1.35fr);
  gap: clamp(20px, 4vw, 44px);
  align-items: start;
}

.project-layout.full {
  grid-template-columns: 1fr;
}

.project-figure {
  margin: 0;
  padding: 12px;
  background:
    linear-gradient(135deg, rgba(140, 12, 12, 0.07), transparent 42%),
    var(--project-surface);
  border: 1px solid var(--project-line);
  border-radius: 8px;
}

.project-figure img {
  display: block;
  width: 100%;
  height: auto;
  object-fit: contain;
  max-height: clamp(260px, 48vh, 560px);
  border-radius: 6px;
}

.project-figure figcaption {
  color: var(--project-muted);
  margin-top: 10px;
  font-size: 0.9rem;
  line-height: 1.35;
}

.project-body,
.project-more {
  color: var(--project-ink);
  font-size: 1.04rem;
  line-height: 1.75;
}

.project-body {
  padding-top: 0;
}

.project-body > *:first-child {
  margin-top: 0;
}

.project-body p:first-child {
  font-size: 1.1rem;
  line-height: 1.68;
}

.project-body img,
.project-more img {
  max-width: 100%;
  height: auto;
}

.project-more {
  max-width: 860px;
  margin-top: clamp(30px, 5vw, 56px);
}

.project-more h2,
.project-more h3,
.project-body h2,
.project-body h3 {
  color: var(--project-ink);
  line-height: 1.2;
  margin-top: 1.6em;
}

.project-more table,
.project-body table {
  width: 100%;
  border-collapse: collapse;
  margin: 18px 0 24px;
  font-size: 0.96rem;
}

.project-more th,
.project-more td,
.project-body th,
.project-body td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--project-line);
  text-align: left;
  vertical-align: top;
}

.project-more th,
.project-body th {
  color: var(--project-ink);
  background: var(--project-surface);
  font-family: Arial, Helvetica, sans-serif;
  font-size: 0.82rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.md-figure {
  margin: 1.2rem 0;
}

.md-figure img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
}

.md-figure figcaption {
  color: var(--project-muted);
  margin-top: 0.45rem;
  font-size: 0.9rem;
  line-height: 1.35;
}

.project-section-title {
  color: var(--project-ink);
  font-size: 1.4rem;
  line-height: 1.2;
  margin: clamp(30px, 5vw, 48px) 0 0.6em;
}

.gallery {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 16px;
  margin-top: clamp(28px, 5vw, 48px);
}

.project-section-title + .gallery {
  margin-top: 0;
}

.gallery figure {
  margin: 0;
}

.gallery .thumb {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  overflow: hidden;
  background: var(--project-surface);
  border: 1px solid var(--project-line);
  border-radius: 8px;
  cursor: zoom-in;
}

.gallery .thumb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.gallery figcaption {
  color: var(--project-muted);
  margin-top: 0.5rem;
  font-size: 0.88rem;
  line-height: 1.35;
}

.gallery.single {
  display: block;
  margin: clamp(28px, 5vw, 48px) auto;
}

.gallery.single figure {
  max-width: clamp(520px, 75vw, 960px);
  margin: 0 auto;
}

.gallery.single .thumb {
  aspect-ratio: auto;
  overflow: visible;
}

.gallery.single .thumb img {
  position: static;
  width: 100%;
  height: auto;
  object-fit: contain;
  max-height: clamp(280px, 60vh, 720px);
  border-radius: 8px;
}

.gallery.single figcaption {
  text-align: center;
}

#imgLightbox{
  position:fixed;
  inset:0;
  display:none;
  align-items:center;
  justify-content:center;
  background:rgba(0,0,0,.8);
  z-index:2000;
  cursor:zoom-out;
}
#imgLightbox.show{display:flex}
#imgLightbox figure{
  margin:0;
  text-align:center;
  position:relative;
  max-width:90%;
  max-height:90%;
}
#imgLightbox img{
  max-width:100%;
  max-height:100%;
  border-radius:8px;
  box-shadow:0 6px 24px rgba(0,0,0,.25);
}
#imgLightbox figcaption{
  position:absolute;
  bottom:0;
  left:0;
  width:100%;
  padding:.5rem;
  box-sizing:border-box;
  background:rgba(0,0,0,.6);
  color:#fff;
}
#imgLightbox .nav{
  position:absolute;
  top:50%;
  transform:translateY(-50%);
  background:none;
  border:none;
  color:#fff;
  font-size:2rem;
  cursor:pointer;
  padding:.25rem .5rem;
  z-index:1;
}
#imgLightbox .nav.prev{left:1rem}
#imgLightbox .nav.next{right:1rem}

html.dark-mode .project-detail-page {
  --project-ink: #f0eee8;
  --project-muted: #c9c3b8;
  --project-line: #46423a;
  --project-panel: #262624;
  --project-surface: #1f211f;
  --project-accent: #e88f8f;
}

html.dark-mode .project-kicker {
  color: #b9cbbd;
}

html.dark-mode .rail-project-list a,
html.dark-mode .rail-outline a {
  color: var(--project-muted);
}

html.dark-mode .rail-back,
html.dark-mode .rail-project-list a:hover,
html.dark-mode .rail-project-list a.is-active,
html.dark-mode .rail-outline a:hover,
html.dark-mode .rail-outline a.is-active {
  color: var(--project-accent);
}

@media (max-width: 900px) {
  .project-figure img {
    max-height: none;
  }
}

@media (max-width: 680px) {
  .project-detail-page {
    padding-top: 8px;
  }

  .project-body,
  .project-more {
    font-size: 1rem;
  }

  .project-more table,
  .project-body table {
    display: block;
    overflow-x: auto;
  }
}

/* Collapse hero/body split when the content column itself is narrow
   (e.g. when the desktop rails are present), regardless of viewport. */
@container (max-width: 640px) {
  .project-layout {
    grid-template-columns: 1fr;
  }
}
