:root {
  --bg: #FAFAF8;
  --ink: #0A0A0A;
  --muted: #6E6E69;
  --line: #BDBDB7;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --gutter: 20px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); }
body {
  font-family: 'Inter Tight', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  font-weight: 300;
  font-size: 15px;
  line-height: 1.3;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
h1 { font: inherit; margin: 0; }
ol { list-style: none; margin: 0; padding: 0; }
img, video, picture { display: block; }
button { appearance: none; background: none; border: 0; padding: 0; margin: 0; font: inherit; color: inherit; cursor: pointer; }
:focus-visible { outline: 1px solid var(--ink); outline-offset: 4px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.num { font-variant-numeric: tabular-nums; }
.ul { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 5px; text-decoration-color: var(--muted); }

/* Hairline: a 1px line scaled to half height */
.hair-top { position: relative; }
.hair-top::before {
  content: ''; position: absolute; left: 0; right: 0; top: 0;
  height: 1px; background: var(--line);
  transform: scaleY(.5); transform-origin: top;
}

@keyframes fadeUp { from { opacity: 0; transform: translateY(28px); } to { opacity: 1; transform: none; } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes drawLine { from { transform: scale(0, .5); } to { transform: scale(1, .5); } }

/* ================= Shell (phone first) ================= */
.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  min-height: 560px;
  overflow: hidden;
}

.rail {
  flex: none;
  position: relative;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: max(16px, env(safe-area-inset-top)) var(--gutter) 12px;
  background: var(--bg);
}
.id { display: flex; flex-direction: column; gap: 4px; }
.name { min-height: 24px; display: flex; align-items: center; white-space: nowrap; }
.rail-work, .rail-foot { display: none; }

.mnav { display: flex; gap: 16px; }
.mnav-link { position: relative; min-height: 24px; padding: 0 4px; display: flex; align-items: center; }
.mnav-link::after {
  content: '';
  position: absolute; left: 4px; right: 4px; bottom: -1px;
  height: 1px; background: var(--muted);
  transform: scaleY(.5);
  transition: transform .9s var(--ease), background .5s var(--ease);
}
.mnav-link.is-on::after { background: var(--ink); transform: scaleY(2); }

.pane { position: relative; flex: 1; min-height: 0; min-width: 0; }
.view {
  position: absolute; inset: 0;
  display: none;
  flex-direction: column;
  background: var(--bg);
}
.view.is-active { display: flex; animation: fadeIn .7s var(--ease) both; }

/* ---------- Home slideshow ---------- */
.slides { position: absolute; inset: 0; }
.slide {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px var(--gutter) 72px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 1.8s var(--ease);
}
.slide.is-on { opacity: 1; pointer-events: auto; }
.slide picture { display: contents; }
.slide img, .slide video {
  max-width: 100%; max-height: 100%;
  width: auto; height: auto;
  object-fit: contain;
  transform: scale(1.04);
  transition: transform 6s var(--ease);
}
.slide.is-on img, .slide.is-on video { transform: none; }
.caption {
  position: absolute; left: var(--gutter); right: var(--gutter);
  bottom: max(24px, env(safe-area-inset-bottom));
  margin: 0;
  display: flex; gap: 16px;
  pointer-events: none;
}

/* ---------- Work list (phone only) ---------- */
.list-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 8px var(--gutter) 32px; }
.row a { display: flex; align-items: center; min-height: 48px; }
.row span { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 5px; text-decoration-color: var(--muted); }
.view-list.is-active .row { animation: fadeUp .9s var(--ease) both; }

/* ---------- Project ---------- */
.p-head, .c-head {
  flex: none;
  height: 64px;
  padding: 0 var(--gutter);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.c-head { justify-content: flex-end; }
.p-title { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
#project-no { color: var(--muted); }
.close { min-width: 48px; min-height: 48px; display: flex; align-items: center; justify-content: flex-end; }
.close path { stroke: var(--ink); stroke-width: 1; fill: none; }
.p-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 0 var(--gutter); }
.p-media { display: flex; flex-direction: column; gap: 16px; }
.m img, .m video { width: 100%; height: auto; background: #F0F0EC; }
.m.reveal { opacity: 0; transform: translateY(28px); transition: opacity 1.2s var(--ease), transform 1.2s var(--ease); }
.m.reveal.in { opacity: 1; transform: none; }
.p-next {
  display: flex; flex-direction: column; gap: 6px;
  margin-top: 16px;
  padding: 28px 0 40px;
}
.p-next-name { font-size: 36px; letter-spacing: -0.045em; line-height: 1.05; }
.p-foot {
  flex: none;
  height: calc(64px + env(safe-area-inset-bottom));
  padding: 0 var(--gutter) env(safe-area-inset-bottom);
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--bg);
}
.p-foot a { min-height: 48px; display: flex; align-items: center; }
.pf-prev, .pf-next { min-width: 80px; }
.pf-next { justify-content: flex-end; text-align: right; }
.pf-d { display: none; }

/* ---------- Contact ---------- */
.view-contact .c-head { display: none; }
.c-body { flex: 1; min-height: 0; padding: 0 var(--gutter); display: flex; flex-direction: column; justify-content: center; }
.email {
  position: relative;
  align-self: flex-start;
  max-width: 100%;
  font-size: 30px; letter-spacing: -0.05em; line-height: 1.1;
  word-break: break-word;
  padding-bottom: 12px;
}
.view-contact.is-active .email { animation: fadeUp 1.2s var(--ease) .1s both; }
.email-line {
  position: absolute; left: 0; right: 0; bottom: 0;
  height: 1px; background: var(--ink);
  transform-origin: left center;
  transform: scale(1, .4);
}
.view-contact.is-active .email-line { animation: drawLine 1.6s var(--ease) .6s both; }

.noscript { position: fixed; left: 20px; right: 20px; bottom: 20px; margin: 0; }

/* ================= Desktop: A3 Split ================= */
@media (min-width: 900px) {
  :root { --gutter: 40px; }
  .app { flex-direction: row; min-height: 640px; }

  /* Left rail, always on screen */
  .rail {
    flex: 0 0 340px;
    height: 100%;
    flex-direction: column;
    justify-content: flex-start;
    gap: 28px;
    padding: 28px 24px 24px 32px;
  }
  .rail::after {
    content: ''; position: absolute; top: 0; bottom: 0; right: 0;
    width: 1px; background: var(--line);
    transform: scaleX(.5); transform-origin: right;
  }
  .mnav { display: none; }
  .rail-work { display: flex; flex-direction: column; flex: 1; min-height: 0; width: 100%; overflow-y: auto; }
  .rail-label { padding-bottom: 6px; color: var(--ink); }
  .rail-foot .mark { color: var(--ink); }
  .rail-foot { display: block; width: 100%; }

  /* List and Contact links with the sliding marker */
  .mark {
    position: relative;
    display: flex; align-items: center;
    padding: 6px 0;
    color: var(--muted);
    transition: color .5s var(--ease);
  }
  .mark-line {
    position: absolute; left: 0; top: 50%;
    width: 18px; height: 1px;
    background: var(--ink);
    transform-origin: left center;
    transform: scale(0, .5);
    transition: transform .9s var(--ease);
  }
  .mark-text { display: block; transition: transform .9s var(--ease); }
  .mark:hover, .mark:focus-visible { color: var(--ink); }
  .mark:hover .mark-line, .mark:focus-visible .mark-line { transform: scale(.45, .5); }
  .mark:hover .mark-text, .mark:focus-visible .mark-text { transform: translateX(14px); }
  .mark.is-on { color: var(--ink); }
  .mark.is-on .mark-line { transform: scale(1, .5); }
  .mark.is-on .mark-text { transform: translateX(30px); }
  .mark:focus-visible { outline-offset: 2px; }

  /* Right pane */
  .view-list { display: none !important; }
  .slide { padding: 40px 40px 88px; }
  .caption { left: 40px; bottom: 32px; }

  .p-head, .c-head { height: 72px; }
  .p-title { gap: 20px; }
  #project-no { color: var(--ink); }
  .close { min-width: 44px; min-height: 44px; }
  .p-media { gap: 24px; }
  .p-next { margin-top: 16px; padding: 40px 0 16px; gap: 8px; margin-bottom: 40px; }
  .p-next-name { font-size: 80px; letter-spacing: -0.045em; line-height: 1; }
  .p-foot { height: 80px; padding: 0 40px; gap: 24px; }
  .pf-m, .pf-all { display: none !important; }
  .pf-d { display: block; }
  .p-foot .pf-prev, .p-foot .pf-next { flex-direction: column; align-items: flex-start; justify-content: center; gap: 4px; min-height: 44px; }
  .p-foot .pf-next { align-items: flex-end; }
  .pf-name { font-size: 20px; letter-spacing: -0.02em; }

  .view-contact .c-head { display: flex; }
  .c-body { justify-content: flex-end; padding: 0 40px 56px; }
  .email { font-size: 80px; letter-spacing: -0.05em; line-height: 1; padding-bottom: 0; }
  .email-line { bottom: -8px; transform: scale(0, .4); transition: transform 1s var(--ease); }
  .view-contact.is-active .email-line { animation: none; }
  .email:hover .email-line, .email:focus-visible .email-line { transform: scale(1, .4); }
}

@media (min-width: 900px) and (max-width: 1180px) {
  .email { font-size: 56px; }
  .p-next-name { font-size: 56px; }
}

@media (hover: hover) {
  .name { transition: color .5s var(--ease); }
  .name:hover { color: var(--muted); }
}

/* Bottom of each project: names drift towards where they lead, labels darken */
.pf-name, .p-next-name { transition: transform .9s var(--ease); }
.p-next .small, .pf-d.small { transition: color .5s var(--ease); }
.ul { transition: text-decoration-color .5s var(--ease); }
@media (hover: hover) {
  .p-next:hover .p-next-name, .p-next:focus-visible .p-next-name { transform: translateX(16px); }
  .pf-next:hover .pf-name, .pf-next:focus-visible .pf-name { transform: translateX(8px); }
  .pf-prev:hover .pf-name, .pf-prev:focus-visible .pf-name { transform: translateX(-8px); }
  .p-next:hover .small, .pf-prev:hover .pf-d.small, .pf-next:hover .pf-d.small { color: var(--ink); }
  .p-foot a:hover .ul, .p-foot a.ul:hover { text-decoration-color: var(--ink); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .slide img, .slide video { transform: none; }
  .m.reveal { opacity: 1; transform: none; }
}
