/* ─── Reset ──────────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* ─── Typography ─────────────────────────────────────────────────────────── */

:root {
  --font-mono: "JetBrains Mono", "Courier New", monospace;
  --font-sans: "Inter", system-ui, sans-serif;

  --color-bg:   #f5f5f5;
  --color-fg:   #1a1a1a;
  --color-mute: #888888;

  --pad: 24px;
  --gap: 16px;
}

/* ─── Body ───────────────────────────────────────────────────────────────── */

html, body {
  height: 100%;
  overscroll-behavior: none;
}

body {
  background: var(--color-bg);
  color: var(--color-fg);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  text-transform: lowercase;

  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100dvh;
  padding: var(--pad) var(--pad) var(--pad) calc(var(--pad) + 32px);
  gap: var(--pad);
}

/* ─── Language Switcher (fixed left-center, rotated) ─────────────────────── */

.lang-switcher {
  position: fixed;
  left: calc(var(--pad) * 3 / 4);
  top: 50%;
  transform: translateY(-50%) rotate(180deg);
  writing-mode: vertical-rL;
  text-orientation: mixed;
  z-index: 100;
  display: flex;
  flex-direction: row;
  gap: 8px;
}

.lang-btn {
  background: none;
  border: none;
  color: var(--color-mute);
  font-family: var(--font-mono);
  font-size: 13px;
  cursor: pointer;
  transition: color 0.15s;
  text-transform: lowercase;
  padding: 0;
}

.lang-btn:hover,
.lang-btn.active {
  color: var(--color-fg);
}

.lang-btn.active {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ─── Header ─────────────────────────────────────────────────────────────── */

header {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  align-items: start;
  gap: var(--gap);
}

.header-name {
  font-weight: 700;
  letter-spacing: 0.02em;
}

.header-email-col {
  display: flex;
  justify-content: center;
}

.header-email {
  color: var(--color-mute);
}

.header-nav {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  border-left: 1px solid var(--color-fg);
  padding-left: 20px;
  width: fit-content;
  margin-left: auto;
}

/* ─── Navigation links ───────────────────────────────────────────────────── */

a {
  color: inherit;
  text-decoration: none;
}

.nav-link {
  color: var(--color-mute);
  transition: color 0.15s;
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--font-mono);
  font-size: 13px;
  text-transform: lowercase;
  padding: 0;
}

.nav-link:hover,
.nav-link.active {
  color: var(--color-fg);
}

.nav-link.active {
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* ─── Main Content ───────────────────────────────────────────────────────── */

main {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

main:not(.projects-main) {
  overflow-y: auto;
  scrollbar-width: none;
}
main:not(.projects-main)::-webkit-scrollbar {
  display: none;
}

/* ─── Footer ─────────────────────────────────────────────────────────────── */

footer {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  align-items: flex-end;
  gap: var(--gap);
  color: var(--color-mute);
}

.footer-motto {
  color: var(--color-fg);
  font-weight: 700;
}

.footer-copyright {
  text-align: right;
  white-space: nowrap;
}

.unix-time {
  font-variant-numeric: tabular-nums;
  cursor: default;
}

/* ─── Projects scroll page ───────────────────────────────────────────────── */

main.projects-main {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  cursor: grab;
}

main.projects-main:active {
  cursor: grabbing;
}

.projects-outer {
  overscroll-behavior: contain;
  box-sizing: border-box;
  scrollbar-width: none;
  flex-direction: column;
  gap: 20px;
  padding-block: 25vh;
  padding-right: var(--pad);
  padding-left: 0;
  display: flex;
  position: absolute;
  inset: 0;
  overflow: hidden scroll;
  -webkit-overflow-scrolling: touch;
  touch-action: none;
  scroll-padding: 0;
}

.projects-outer::-webkit-scrollbar { display: none; }

.project-track {
  scroll-snap-align: center;
  scroll-snap-stop: always;
  height: 35vh;
  scroll-padding-right: calc(100% - var(--pad) * 3 - 35vh * 4 / 3);
  overscroll-behavior-x: contain;
  touch-action: none;
  scrollbar-width: none;
  flex-direction: row;
  flex-shrink: 0;
  align-items: stretch;
  transition: opacity 0.4s, height 0.35s;
  display: flex;
  overflow-x: scroll;
  -webkit-overflow-scrolling: touch;
}

.project-track::-webkit-scrollbar { display: none; }

.project-track:not(.is-active) {
  opacity: 0.35;
  overflow-x: hidden;
}

.project-track.is-active { opacity: 1; }

.project-track:not(.is-active) .project-panel-main-meta,
.project-track:not(.is-active) .project-panel-gallery,
.project-track:not(.is-active) .project-panel-detail { display: none; }

.project-track:not(.is-active) .project-panel-main {
  flex: none;
  will-change: transform;
}

/* On mobile, inactive cover panels match the active one's proportions */
@media (max-width: 600px) {
  .project-track:not(.is-active) .project-panel-main {
    flex: 0 0 88%;
  }
}

.project-panel-main {
  align-items: stretch;
  gap: var(--pad);
  scroll-snap-align: start;
  padding: var(--pad) var(--pad) var(--pad) 0;
  flex-direction: row;
  flex: 0 0 100%;
  display: flex;
}

.project-panel-main-img { flex-shrink: 0; overflow: hidden; }

.project-cover-img {
  aspect-ratio: 4 / 3;
  object-fit: cover;
  width: auto;
  height: 100%;
  display: block;
}

.project-panel-main-meta { flex: 1; overflow: hidden; }

.pmj {
  font-family: var(--font-mono), monospace;
  color: var(--color-fg);
  font-size: 13px;
  line-height: 1.8;
}

.pmj-brace { color: var(--color-mute); }
.pmj-row { word-break: break-word; padding-left: 1.5em; }
.pmj-key, .pmj-sep { color: var(--color-mute); }
.pmj-title { color: var(--color-fg); font-weight: 700; }

.project-panel-gallery {
  scroll-snap-align: end;
  padding: var(--pad) 0 var(--pad) var(--pad);
  flex: none;
  height: 100%;
  align-items: center;
  justify-content: center;
  display: flex;
  cursor: pointer;
}

.project-gallery-img {
  height: calc(35vh - 2 * var(--pad));
  object-fit: contain;
  width: auto;
  max-width: 85vw;
  display: block;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

.project-panel-detail {
  padding: var(--pad);
  scroll-snap-align: start;
  flex-direction: column;
  flex: 0 0 calc(min(80vw, 900px) + 2 * var(--pad));
  gap: 24px;
  display: flex;
  overflow-y: auto;
}

/* ─── Detail overlay ─────────────────────────────────────────────────────── */

.detail-overlay {
  position: absolute;
  inset: var(--pad);
  z-index: 10;
  pointer-events: none;
  will-change: transform;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.detail-overlay-content {
  pointer-events: auto;
  background: var(--color-bg);
  width: min(80vw, 900px);
  height: 100%;
  padding: var(--pad);
  flex-direction: column;
  gap: 24px;
  font-size: 12px;
  display: flex;
  overflow-y: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.detail-overlay-content::-webkit-scrollbar { display: none; }

.project-details-text {
  color: var(--color-mute);
  line-height: 1.7;
}

.project-detail-link {
  color: var(--color-fg);
  text-underline-offset: 3px;
  text-decoration: underline;
}

.project-credits {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.project-credit {
  display: flex;
  gap: var(--gap);
}

.project-credit-role {
  color: var(--color-mute);
  min-width: 180px;
}

/* ─── About page ─────────────────────────────────────────────────────────── */

.about-content {
  max-width: 720px;
  display: flex;
  flex-direction: column;
  gap: var(--pad);
}

.about-title {
  font-size: 3em;
  font-weight: 700;
  line-height: 1.15;
  margin: 0;
}

.about-content h2.about-title {
  margin-top: var(--pad);
}

.about-body {
  color: var(--color-mute);
  line-height: 1.7;
  margin: 0;
}

/* ─── Us page ────────────────────────────────────────────────────────────── */

@media (min-width: 601px) {
  main.us-main {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    scrollbar-width: none;
  }

  main.us-main::-webkit-scrollbar { display: none; }

  .us-outer {
    display: flex;
    flex-direction: row;
    gap: calc(var(--pad) * 2);
    align-items: flex-start;
    justify-content: flex-start;
    padding: var(--pad) var(--pad) var(--pad) 0;
  }

  .us-track {
    flex: 0 0 25%;
    display: flex;
    flex-direction: column;
    gap: var(--pad);
    min-width: 180px;
  }

  .us-panel-photo {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .us-panel-intro {
    color: var(--color-mute);
  }

  .us-photo {
    width: 15vw;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    display: block;
  }

  .us-name {
    font-size: 1.4em;
    font-weight: 700;
    line-height: 1.2;
  }

  .us-intro-text {
    color: var(--color-mute);
    line-height: 1.7;
    font-size: 12px;
  }
}

/* ─── Mobile meta panels (hidden on desktop) ─────────────────────────────── */

.project-panel-mini-meta { display: none; }
.project-panel-fullmeta  { display: none; }

/* ─── Responsive ─────────────────────────────────────────────────────────── */

@media (max-width: 600px) {
  header {
    grid-template-rows: auto 1fr;
    grid-template-columns: 1fr auto;
  }
  .header-email-col {
    grid-area: 2 / 1;
    justify-content: flex-start;
    align-self: end;
  }
  .header-nav { grid-area: 1 / 2 / 3; }
  footer { flex-direction: column; align-items: flex-start; gap: 2px; }
  .footer-copyright { text-align: left; white-space: normal; }

  /* ── Mobile projects layout: JS controls all touch ─────────────────────── */

  /* Block native touch scroll so JS momentum handlers can take over */
  main.projects-main { touch-action: none; }
  .projects-outer { touch-action: none; }
  .project-track { touch-action: none; }

  /* ── Mobile projects layout: center-snap ────────────────────────────────── */

  /* Outer: JS handles snapping; padding lets neighbours peek */
  .projects-outer {
    scroll-snap-type: none;
    padding-block: 28vh;
    scroll-padding-top: 0;
    gap: 8px;
  }

  /* Tracks on mobile portrait, no horizontal snap — free scroll with gap */
  .project-track {
    height: 32vh;
    scroll-snap-type: none;
    scroll-snap-align: center;
    scroll-snap-stop: always;
    scroll-margin-top: 0;
    scroll-margin-bottom: 0;
    gap: 6px;
  }

  .project-panel-main {
    flex: 0 0 88%;
  }

  /* Gallery panels: auto-size to image content with ~10% screen padding */
  .project-panel-gallery {
    flex: 0 0 auto;
    padding: 0 5vw;
  }

  /* Gallery images: fill the track height */
  .project-gallery-img {
    height: calc(32vh - 4 * var(--pad));
    max-width: 92vw;
  }

  /* Main panel: stack image above mini-meta, centered vertically */
  .project-panel-main {
    flex-direction: column;
    padding: var(--pad) var(--pad) 0 calc(var(--pad) + 20px);
    gap: 8px;
    align-items: stretch;
    justify-content: center;
  }

  /* Image fills most of the track but leaves room for title+year */
  .project-panel-main-img {
    width: 100%;
    flex: 0 1 auto;
    min-height: 0;
    max-height: calc(32vh - 70px - 2 * var(--pad));
    overflow: hidden;
  }

  .project-cover-img {
    width: 100%;
    height: 100%;
    aspect-ratio: unset;
    object-fit: cover;
  }

  /* Desktop full meta: hidden on mobile */
  .desktop-meta { display: none; }

  /* Mini meta (title + year): always visible below image */
  .project-panel-mini-meta {
    display: block;
    flex-shrink: 0;
    padding-bottom: var(--pad);
    overflow: hidden;
  }

  /* Ensure mini-meta keys (title, year) have same indentation */
  .project-panel-mini-meta .pmj-row {
    padding-left: 0;
  }

  /* Mini meta layout: brace and content divs aligned horizontally */
  .project-panel-mini-meta .pmj {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0;
  }

  .project-panel-mini-meta .pmj-brace-open {
    padding-left: 0;
    line-height: 1.8;
    flex-shrink: 0;
    margin-right: 0.5em;
    color: var(--color-mute);
  }

  .project-panel-mini-meta .pmj-content-mini {
    line-height: 1.8;
    flex: 1;
  }

  .project-panel-mini-meta .pmj-content-mini .pmj-row:last-child .pmj-brace {
    margin-left: 0.5em;
  }

  /* Full-meta panel: shown as next horizontal snap panel */
  .project-panel-fullmeta {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: flex-start;
    flex: 0 0 100%;
    padding: var(--pad) var(--pad) var(--pad) calc(var(--pad) + 20px);
    scroll-snap-align: start;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* ── Mobile us layout ────────────────────────────────────────────────────── */

  main.us-main {
    flex: 1;
    min-height: 0;
    position: relative;
    overflow: hidden;
    touch-action: none;
  }

  .us-outer {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden scroll;
    -webkit-overflow-scrolling: touch;
    scroll-snap-type: none;
    padding-block: 25vh;
    gap: 4px;
    touch-action: none;
    scrollbar-width: none;
  }

  .us-outer::-webkit-scrollbar { display: none; }

  .us-track {
    flex: 0 0 35vh;
    display: flex;
    flex-direction: row;
    width: 100%;
    height: 35vh;
    flex-shrink: 0;
    overflow-x: scroll;
    -webkit-overflow-scrolling: touch;
    touch-action: none;
    scrollbar-width: none;
    align-items: stretch;
    transition: opacity 0.4s;
    gap: 0;
  }

  .us-track::-webkit-scrollbar { display: none; }

  .us-track:not(.is-active) {
    opacity: 0.35;
    overflow-x: hidden;
  }

  .us-track.is-active { opacity: 1; }

  .us-track:not(.is-active) .us-panel-photo {
    flex: 0 0 88%;
    will-change: transform;
  }

  .us-panel-photo {
    flex: 0 0 88%;
    display: flex;
    flex-direction: column;
    padding: var(--pad) var(--pad) 0 calc(var(--pad) + 20px);
    gap: 8px;
    align-items: stretch;
    min-width: 0;
  }

  .us-photo {
    flex: none;
    width: 100%;
    max-height: 20vh;
    object-fit: cover;
  }

  .us-name {
    font-size: 1em;
    font-weight: 700;
    flex-shrink: 0;
    padding-bottom: var(--pad);
  }

  .us-panel-intro {
    flex: 0 0 88%;
    display: flex;
    flex-direction: column;
    padding: var(--pad) var(--pad) var(--pad) calc(var(--pad) + 20px);
    overflow-y: scroll;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .us-panel-intro::-webkit-scrollbar { display: none; }

  .us-intro-text {
    font-size: 0.95em;
    line-height: 1.6;
    margin: 0;
    color: var(--color-mute);
  }
}

/* ─── Lightbox ─────────────────────────────────────────────────────────── */

.img-lightbox {
  display: none;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  inset: 0; /* modern shorthand, same as above */
  width: 100%;
  height: 100%;
  z-index: 1000;
  background: rgba(0, 0, 0, 0.92);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  touch-action: none;
  cursor: zoom-out;
  overflow: hidden;
}

.img-lightbox.is-open {
  display: flex;
}

.img-lightbox-img {
  max-width: 100%;
  max-height: calc(100vh - 3em); /* dvh fallback */
  max-height: calc(100dvh - 3em);
  object-fit: contain;
  display: block;
  flex-shrink: 0;
}

.img-lightbox-caption {
  position: absolute;
  bottom: 1.5em;
  left: 50%;
  transform: translateX(-50%);
  max-width: 90%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 12px;
  border-radius: 4px;
  background: rgba(120, 120, 120, 0.45);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  font-family: var(--font-mono);
  font-size: 12px;
  color: rgba(255, 255, 255, 0.9);
  text-transform: lowercase;
  pointer-events: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ─── DEBUG: Visual layout indicators (temporary) ──────────────────────── */
/* Add ?debug=1 to URL to enable */

body.debug-layout .projects-outer {
  border: 3px solid red !important;
  background: rgba(255, 0, 0, 0.05) !important;
}

body.debug-layout .project-track {
  border: 2px solid blue !important;
  background: rgba(0, 0, 255, 0.05) !important;
}

body.debug-layout .project-panel-main {
  border: 1px solid green !important;
}

body.debug-layout .detail-overlay {
  border: 2px solid purple !important;
}

.project-credits {
  border-top: 1px solid var(--color-mute);
  padding-top: 1rem;
  font-size: 12px;
}

.credits-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.back-link {
  display: inline-block;
  color: var(--color-mute);
  margin-bottom: 1rem;
  transition: color 0.15s;
}

.back-link:hover {
  color: var(--color-fg);
}

/* ─── Matrix Loading Animation ───────────────────────────────────────────── */

.matrix-loader {
  background: var(--color-bg);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: auto;
}

.matrix-loader.fade-out {
  pointer-events: none;
}

.matrix-char {
  position: absolute;
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--color-mute);
  opacity: 0;
  animation: matrixFade 2s ease-in-out forwards;
  user-select: none;
  pointer-events: none;
}

@keyframes matrixFade {
  0% {
    opacity: 0;
  }
  50% {
    opacity: 0.6;
  }
  100% {
    opacity: 0;
  }
}

.matrix-loader.fade-out {
  animation: matrixLoaderFade 0.6s ease-out forwards;
  pointer-events: none;
}

@keyframes matrixLoaderFade {
  0% {
    opacity: 1;
  }
  100% {
    opacity: 0;
    pointer-events: none;
  }
}

/* ─── Carpentry Start Page Animation ──────────────────────────────────────── */

@keyframes carpentryAppear {
  0%   { opacity: 0; }
  20%  { opacity: 1; }
  70%  { opacity: 0.6; }
  100% { opacity: 0; }
}

.carpentry-animation {
  background: var(--color-bg);
}

.carpentry-char {
  /* styling handled inline */
}
