/* ============================================================
   PRJ.JPN — Japan project styles
   ------------------------------------------------------------
   Scoped to /projects/japan/. Does NOT depend on the main
   site's /assets/css/base.css. Shared across the project
   index and the three chapter pages (Tokyo / Kyoto / Osaka).

   Sections:
     1. Theme         — palette using light-dark()
     2. Reset         — element defaults
     3. Top bar       — back link + breadcrumb
     4. Title block   — PRJ.JPN headline + subtitle
     5. TOC           — chapter list on the index
     6. Chapter       — city page layout
     7. Chapter intro — map + text above gallery
     8. Japan map     — inline SVG, region/city activation
     9. Gallery       — grid + side-scroller (paginated)
    10. Lightbox      — fullscreen viewer (native <dialog>)
    11. Footer
    12. Mobile        — tightening for <540px
   ============================================================ */


/* ---------- 1. Theme ---------------------------------------- */
:root {
  color-scheme: light dark;

  --paper:      light-dark(#f4f1ea, #0f0e0c);
  --paper-soft: light-dark(#ece8de, #191815);
  --ink:        light-dark(#181818, #ece7da);
  --ink-soft:   light-dark(#6e6a62, #8c8678);
  --rule:       light-dark(#d8d2c4, #2a2723);

  /* Hi no Maru — the red of the Japanese flag (JIS spec ~#BC002D).
     Slightly brightened in dark mode for visibility. */
  --hi-no-maru: light-dark(#bc002d, #dc143c);
}


/* ---------- 2. Reset ---------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font-family: "Cormorant Garamond", "Hiragino Mincho ProN",
               "Yu Mincho", Georgia, serif;
  font-size: 19px;
  line-height: 1.7;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

a   { color: inherit; text-decoration: none; }
img { display: block; max-width: 100%; }

/* The single red dot — reusable wherever PRJ.JPN appears inline. */
.dot-jp { color: var(--hi-no-maru); }


/* ---------- 3. Top bar -------------------------------------- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem 2rem;
  font-family: "Futura", "Jost", -apple-system, sans-serif;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.topbar a {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 2px;
  transition: color 200ms, border-color 200ms;
}
.topbar a:hover {
  color: var(--hi-no-maru);
  border-bottom-color: var(--hi-no-maru);
}


/* ---------- 4. Title block ---------------------------------- */
.title-block {
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 4rem 2rem 3rem;
}

.prj-title {
  font-family: "Futura", "Jost", -apple-system, sans-serif;
  font-weight: 700;
  font-size: clamp(4.5rem, 13vw, 10rem);
  letter-spacing: -0.01em;
  line-height: 0.95;
  color: var(--ink);
  margin: 0;
}
.prj-title__dot { color: var(--hi-no-maru); }

.prj-subtitle {
  font-family: "Cormorant Garamond", serif;
  font-style: italic;
  font-weight: 400;
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  line-height: 1.4;
  color: var(--ink-soft);
  margin: 1.5rem 0 0;
  max-width: 28rem;
}


/* ---------- 5. TOC (chapter list) --------------------------- */
.toc {
  max-width: 900px;
  width: 100%;
  margin: 3rem auto 0;
  padding: 0 2rem 4rem;
}

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

.toc__item { border-bottom: 1px solid var(--rule); }

.toc__item a {
  display: grid;
  grid-template-columns: 80px 1fr auto;
  gap: 2rem;
  align-items: baseline;
  padding: 2rem 0;
  transition: color 200ms;
}
.toc__item a:hover,
.toc__item a:hover .toc__stats,
.toc__item a:hover .toc__stat-num { color: var(--hi-no-maru); }

.toc__num {
  font-family: "Futura", "Jost", sans-serif;
  font-weight: 500;
  font-size: 0.8rem;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
}

.toc__name {
  font-family: "Futura", "Jost", sans-serif;
  font-weight: 700;
  font-size: clamp(1.75rem, 4vw, 2.75rem);
  text-transform: uppercase;
  letter-spacing: 0.01em;
  line-height: 1;
}

/* Stats — frame count, word count, and date for each chapter.
   Bold numerals against tracked-out uppercase labels;
   the whole block tints to hi-no-maru on row hover. */
.toc__stats {
  display: inline-flex;
  align-items: baseline;
  flex-wrap: wrap;
  column-gap: 0.6rem;
  row-gap: 0.25rem;
  font-family: "Futura", "Jost", sans-serif;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
  transition: color 200ms;
}
.toc__stat {
  display: inline-flex;
  align-items: baseline;
  gap: 0.3rem;
}
.toc__stat-num {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--ink);
  transition: color 200ms;
}
.toc__sep {
  color: var(--ink-soft);
  opacity: 0.45;
}

@media (max-width: 640px) {
  .toc__item a {
    grid-template-columns: 50px 1fr;
    gap: 1rem;
    padding: 1.5rem 0;
  }
  .toc__stats { grid-column: 2 / -1; }
}


/* ---------- 6. Chapter (city page) -------------------------- */
.chapter {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
}

.chapter__eyebrow {
  font-family: "Futura", "Jost", sans-serif;
  font-weight: 500;
  font-size: 0.75rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--ink-soft);
  margin: 0 0 1rem;
}

.chapter__title {
  font-family: "Futura", "Jost", sans-serif;
  font-weight: 700;
  font-size: clamp(4rem, 12vw, 8rem);
  letter-spacing: -0.01em;
  line-height: 0.95;
  text-transform: uppercase;
  color: var(--ink);
  margin: 0 0 2rem;
}

.chapter__nav {
  display: flex;
  justify-content: space-between;
  margin-top: 3rem;
  font-family: "Futura", "Jost", sans-serif;
  font-size: 0.8rem;
  font-weight: 500;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.chapter__nav a {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 2px;
  transition: color 200ms, border-color 200ms;
}
.chapter__nav a:hover {
  color: var(--hi-no-maru);
  border-bottom-color: var(--hi-no-maru);
}


/* ---------- 7. Chapter intro (map + text above gallery) ----- */
.chapter__intro {
  display: grid;
  gap: 1.75rem;
  margin: 1.5rem 0 2.5rem;
}

@media (min-width: 720px) {
  .chapter__intro {
    grid-template-columns: 220px 1fr;
    gap: 3rem;
    align-items: start;
  }
}

.chapter__intro-text {
  font-family: "Cormorant Garamond", serif;
  font-size: 1.1rem;
  line-height: 1.6;
  color: var(--ink);
}
.chapter__intro-text p      { margin: 0 0 0.85rem; }
.chapter__intro-text p:last-child { margin-bottom: 0; }
.chapter__intro-text em     { color: var(--ink-soft); }


/* Chapter notes — long-form prose under the gallery. A narrower
   measure keeps the line length readable for the essay-style
   passages on each city page. */
.chapter__notes {
  max-width: 38rem;
  font-family: "Cormorant Garamond", "Hiragino Mincho ProN",
               "Yu Mincho", Georgia, serif;
  font-size: 1.1rem;
  line-height: 1.75;
  color: light-dark(#000, #fff);
  counter-reset: note;
}
.chapter__notes p {
  position: relative;
  padding-left: 3rem;
  margin: 0 0 1.5rem;
  counter-increment: note;
}
.chapter__notes p:last-child { margin-bottom: 0; }
.chapter__notes p::before {
  content: counter(note, decimal-leading-zero);
  position: absolute;
  left: 0;
  bottom: 0;
  font-family: "Futura", "Jost", sans-serif;
  font-weight: 500;
  font-size: 0.75rem;
  letter-spacing: 0.25em;
  color: var(--ink-soft);
  line-height: 1;
}


/* Prologue block on the PRJ.JPN landing page — centered like the
   title-block and toc above it. The inner .chapter__notes keeps
   the same serif rhythm and numbered paragraphs as the city pages. */
.prj-prologue {
  max-width: 900px;
  width: 100%;
  margin: 3rem auto 0;
  padding: 0 2rem 2rem;
}
.prj-prologue .chapter__notes { margin-left: auto; margin-right: auto; }
@media (max-width: 540px) {
  .prj-prologue { padding: 0 1.25rem 2rem; }
}


/* ---------- 8. Japan map (inline SVG injected by JS) -------- */
.japan-map {
  display: block;
  width: 100%;
  max-width: 240px;
  margin: 0 auto;
}
.japan-map svg { width: 100%; height: auto; }

.japan-map .island {
  fill: var(--paper-soft);
  stroke: var(--ink-soft);
  stroke-width: 0.6;
  stroke-linejoin: round;
}

/* Region overlays — only the active region becomes visible. */
.japan-map .region { fill: var(--hi-no-maru); opacity: 0; }

.japan-map .city__dot {
  fill: var(--ink-soft);
}
.japan-map .city__label {
  font-family: "Futura", "Jost", sans-serif;
  font-size: 7px;
  font-weight: 500;
  letter-spacing: 0.12em;
  fill: var(--ink-soft);
  text-transform: uppercase;
}

/* Activation rules driven by body[data-city]. */
body[data-city="tokyo"]  .japan-map .region--kanto  { opacity: 0.18; }
body[data-city="kyoto"]  .japan-map .region--kansai,
body[data-city="osaka"]  .japan-map .region--kansai { opacity: 0.18; }

body[data-city="tokyo"] .japan-map #city-tokyo .city__dot,
body[data-city="kyoto"] .japan-map #city-kyoto .city__dot,
body[data-city="osaka"] .japan-map #city-osaka .city__dot {
  fill: var(--hi-no-maru);
  r: 3.5;
}
body[data-city="tokyo"] .japan-map #city-tokyo .city__label,
body[data-city="kyoto"] .japan-map #city-kyoto .city__label,
body[data-city="osaka"] .japan-map #city-osaka .city__label {
  fill: var(--ink);
  font-weight: 700;
}


/* ---------- 9. Gallery -------------------------------------- */
/*
   Modes ([data-mode] on .gallery):
     "grid"   — responsive flowing CSS Grid. Frames are 2:3
                portrait (the camera's native 3:2 ratio, rotated):
                  • mobile  (<560px):    2 columns
                  • desktop (>=560px):   3 columns
                Portrait items are narrower per-cell, so we can
                pack two side-by-side even on phones without the
                images looking cramped.
     "scroll" — one item per viewport, paginated horizontally.
                Arrows advance one image at a time. On wider
                screens the frame is centred and capped in width
                so a 2:3 portrait stays fully visible without
                running off the bottom of the viewport.

   Arrows live in the toolbar and only appear in scroll mode —
   grid mode just scrolls vertically with the rest of the page.
*/

.gallery { margin: 2rem 0 2.5rem; }

/* Toolbar */
.gallery__toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
  font-family: "Futura", "Jost", sans-serif;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.gallery__controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Arrows (toolbar pager) */
.gallery__pager {
  display: none;
  align-items: center;
  gap: 2px;
}
.gallery[data-mode="scroll"] .gallery__pager { display: inline-flex; }

.gallery__arrow {
  appearance: none;
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 100px;
  width: 30px;
  height: 30px;
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 150ms, border-color 150ms;
}
.gallery__arrow:hover:not(:disabled) {
  color: var(--ink);
  border-color: var(--ink-soft);
}
.gallery__arrow:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}
.gallery__arrow svg { width: 12px; height: 12px; display: block; }
.gallery__arrow:focus-visible {
  outline: 2px solid var(--hi-no-maru);
  outline-offset: 2px;
}

/* Mode toggle (segmented control) */
.gallery__modes {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border: 1px solid var(--rule);
  border-radius: 100px;
  background: var(--paper);
}
.gallery__mode {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 6px 10px;
  border-radius: 100px;
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 150ms, background 150ms;
}
.gallery__mode:hover { color: var(--ink); }
.gallery__mode[aria-pressed="true"] {
  color: var(--ink);
  background: var(--paper-soft);
}
.gallery__mode svg { width: 16px; height: 16px; display: block; }
.gallery__mode:focus-visible {
  outline: 2px solid var(--hi-no-maru);
  outline-offset: 2px;
}

/* ----- Grid mode: responsive flowing grid -----
   Items keep their natural 2:3 portrait ratio. Two columns even
   on phones (a single full-bleed portrait runs much too tall),
   stepping up to three from 560px onward. */
.gallery[data-mode="grid"] .gallery__items {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.75rem;
}
@media (min-width: 560px) {
  .gallery[data-mode="grid"] .gallery__items {
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
  }
}

/* ----- Side-scroller mode (one image at a time) ----- */
.gallery[data-mode="scroll"] .gallery__items {
  display: flex;
  gap: 0;
  overflow-x: auto;
  overflow-y: hidden;
  scroll-snap-type: x mandatory;
  scroll-behavior: smooth;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.gallery[data-mode="scroll"] .gallery__items::-webkit-scrollbar { display: none; }

.gallery[data-mode="scroll"] .gallery__item {
  flex: 0 0 100%;
  scroll-snap-align: start;
  display: flex;
  justify-content: center;
}

/* On wider screens, cap the portrait frame width so a 2:3 image
   stays fully visible without forcing the viewport to scroll.
   Mobile keeps the frame at 100% — a tall portrait filling the
   phone screen reads as the intended "one image at a time". */
@media (min-width: 720px) {
  .gallery[data-mode="scroll"] .gallery__frame {
    max-width: min(100%, calc(70vh * 2 / 3));
  }
}

/* Items */
.gallery__item { margin: 0; padding: 0; }

/* Frame (now a button so it's natively focusable / clickable) */
.gallery__frame {
  appearance: none;
  position: relative;
  display: block;
  width: 100%;
  aspect-ratio: 2 / 3;
  background: var(--paper-soft);
  border: 1px solid var(--rule);
  padding: 0;
  margin: 0;
  cursor: pointer;
  overflow: hidden;
  color: inherit;
  transition: border-color 200ms;
  font: inherit;
}
.gallery__frame:hover { border-color: var(--ink-soft); }
.gallery__frame:focus-visible {
  outline: 2px solid var(--hi-no-maru);
  outline-offset: 2px;
}
.gallery__frame::before {
  content: attr(data-num);
  position: absolute;
  top: 0.6rem;
  left: 0.7rem;
  font-family: "Futura", "Jost", sans-serif;
  font-size: 0.65rem;
  font-weight: 500;
  letter-spacing: 0.2em;
  color: var(--ink-soft);
  pointer-events: none;
}
.gallery__frame img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}


/* ---------- 10. Lightbox (native <dialog>) ------------------ */
.lightbox {
  /* Reset native dialog defaults */
  padding: 0;
  border: 0;
  margin: 0;
  width: 100vw;
  height: 100vh;
  max-width: none;
  max-height: none;
  background: #0a0a0a;
  color: #f2efe8;
}

/* Show as flex when open; hide entirely when closed */
.lightbox[open] {
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox::backdrop { background: #0a0a0a; }

.lightbox__figure {
  margin: 0;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 4rem 1rem 2rem;
}

.lightbox__media {
  display: flex;
  align-items: center;
  justify-content: center;
  max-width: 100%;
  max-height: 100%;
}

.lightbox__img {
  max-width: min(95vw, 1400px);
  max-height: 80vh;
  object-fit: contain;
  display: block;
}

.lightbox__placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  /* Portrait placeholder: drive layout from height so the frame
     never exceeds the viewport. Width follows from aspect-ratio. */
  height: min(80vh, 900px);
  aspect-ratio: 2 / 3;
  max-width: 85vw;
  background: #1a1815;
  border: 1px solid #2a2723;
  color: #6e6a62;
  font-family: "Futura", "Jost", sans-serif;
  font-size: clamp(2rem, 6vw, 4rem);
  font-weight: 500;
  letter-spacing: 0.25em;
}

/* The class-level display rules above override the UA [hidden]
   declaration, so re-assert it for the toggled lightbox media. */
.lightbox__img[hidden],
.lightbox__placeholder[hidden] { display: none; }

.lightbox__caption {
  font-family: "Futura", "Jost", sans-serif;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: #a8a59e;
}

/* Lightbox controls */
.lightbox__close,
.lightbox__arrow {
  appearance: none;
  position: absolute;
  background: transparent;
  border: 1px solid rgba(255, 255, 255, 0.25);
  border-radius: 100px;
  color: #f2efe8;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: color 150ms, border-color 150ms, background 150ms;
}
.lightbox__close:hover,
.lightbox__arrow:hover:not(:disabled) {
  color: #fff;
  border-color: var(--hi-no-maru);
}
.lightbox__arrow:disabled { opacity: 0.25; cursor: not-allowed; }
.lightbox__close:focus-visible,
.lightbox__arrow:focus-visible {
  outline: 2px solid var(--hi-no-maru);
  outline-offset: 2px;
}

/* Position uses max(margin, env(safe-area-inset)) so the controls
   clear iPhone notches/home indicators while still keeping a
   generous default gap from the edges. */
.lightbox__close {
  top:   max(1.75rem, env(safe-area-inset-top));
  right: max(1.75rem, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  font-size: 1.5rem;
  line-height: 1;
}

.lightbox__arrow {
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
}
.lightbox__arrow svg { width: 20px; height: 20px; }
.lightbox__arrow--prev { left:  max(1.75rem, env(safe-area-inset-left)); }
.lightbox__arrow--next { right: max(1.75rem, env(safe-area-inset-right)); }

@media (max-width: 540px) {
  .lightbox__arrow      { width: 40px; height: 40px; }
  .lightbox__arrow--prev { left:  max(1.25rem, env(safe-area-inset-left)); }
  .lightbox__arrow--next { right: max(1.25rem, env(safe-area-inset-right)); }
  .lightbox__close {
    top:   max(1.25rem, env(safe-area-inset-top));
    right: max(1.25rem, env(safe-area-inset-right));
    width: 40px;
    height: 40px;
  }
}


/* ---------- 11. Footer -------------------------------------- */
.site-footer {
  margin-top: auto;
  padding: 2.5rem 2rem 3rem;
  border-top: 1px solid var(--rule);
  text-align: center;
  font-family: "Futura", "Jost", sans-serif;
  font-weight: 500;
  font-size: 0.7rem;
  letter-spacing: 0.25em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.site-footer a {
  border-bottom: 1px solid var(--rule);
  padding-bottom: 2px;
  transition: color 200ms, border-color 200ms;
}
.site-footer a:hover {
  color: var(--hi-no-maru);
  border-bottom-color: var(--hi-no-maru);
}


/* ---------- 12. Mobile (tightens horizontal padding) -------- */
@media (max-width: 540px) {
  .topbar       { padding: 1.25rem 1.25rem; gap: 1rem; }
  .title-block  { padding: 3rem 1.25rem 2rem; }
  .toc          { padding: 0 1.25rem 3rem; }
  .chapter      { padding: 1.5rem 1.25rem 3rem; }
  .site-footer  { padding: 2rem 1.25rem 2.5rem; }

  /* Slightly smaller display sizes on the tiniest screens */
  .prj-title       { font-size: clamp(3.5rem, 16vw, 5.5rem); }
  .chapter__title  { font-size: clamp(3rem, 14vw, 4.5rem); }
}
