/* ============================================
   GALLERY · 帳簿 — Builds Ledger
   Scoped chrome for /gallery. Pairs with commission.css for the
   shared sub-page editorial scaffold (sp-top / sp-section /
   sp-shead / sp-foot). Only the grid + card styles are
   gallery-specific.
   ============================================ */

.page-gallery {
  background: var(--bone);
  color: var(--sumi);
}

/* HERO — restrained sp-shead variant. The .sp-shead pattern already
   ships from commission.css; gallery just nudges the lede width and
   keeps the giant kanji as the page mark (帳 = "ledger"). */
.gallery-hero {
  border-bottom: 0.5px solid var(--rule-soft);
}
.gallery-hero__lede {
  max-width: 56ch;
}

/* GRID — 3 → 2 → 1 columns. Uses --s-* tokens defined globally
   in styles.css :root. */
.gallery-grid-section {
  padding-top: var(--s-48);
  padding-bottom: var(--s-96);
}
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--s-32);
  max-width: var(--content-max);
  margin: 0 auto;
}
@media (max-width: 1024px) {
  .gallery-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 640px) {
  .gallery-grid { grid-template-columns: 1fr; }
}

/* CARD — paper bg + hairline border, lifts on hover. Same visual
   weight as .sp-base cards on /commission so /gallery reads as
   part of the same atelier. */
.gallery-card {
  display: flex;
  flex-direction: column;
  gap: var(--s-12);
  padding: var(--s-24);
  background: var(--paper, #faf4e6);
  border: 0.5px solid var(--rule-soft);
  border-radius: 3px;
  transition:
    border-color 200ms ease,
    transform 200ms ease,
    box-shadow 200ms ease;
}
.gallery-card:hover {
  border-color: rgba(20, 17, 13, 0.18);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}

/* THUMB — 16:9 frame, mirrors the home /works grid so /gallery feels
   visually consistent. Default scale 1.5 compensates for transparent
   padding in the mostly-square source PNGs in /assets/pics-stripped/.
   Override per-card via the `--card-scale` CSS variable on the <img>
   inline style (e.g. landscape PNGs like gengar.png should use
   scale: 1 so the wider image isn't side-cropped). Values otherwise
   match .work__media in styles.css. */
.gallery-card__thumb {
  position: relative;
  aspect-ratio: 16 / 9;
  background: var(--paper, #faf4e6);
  border: 0.5px solid var(--rule-soft);
  border-radius: 2px;
  overflow: hidden;
}
.gallery-card__thumb img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  transform: scale(var(--card-scale, 1.5));
  transform-origin: center;
  display: block;
}
.gallery-card__placeholder {
  width: 40%;
  height: 40%;
  opacity: 0.35;
  filter: grayscale(0.2);
  user-select: none;
  pointer-events: none;
}

/* META — mono caps year only (build numbers removed). */
.gallery-card__meta {
  display: flex;
  align-items: baseline;
  margin-top: var(--s-8);
}
.gallery-card__year {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--akane);
  font-weight: 500;
  font-variant-numeric: lining-nums tabular-nums;
}

/* NAME — mincho italic for the rare named builds (Suzaku, Hinata,
   Kintsugi …). Omitted entirely when `name` is null — visual rhythm
   stays clean either way. */
.gallery-card__name {
  font-family: var(--display);
  font-style: italic;
  font-weight: 700;
  font-size: clamp(24px, 2.4vw, 32px);
  line-height: 1.05;
  letter-spacing: -0.018em;
  margin: 0;
  color: var(--sumi);
}

/* CHASSIS — model name, mincho italic, slightly smaller. */
.gallery-card__chassis {
  font-family: var(--display);
  font-style: italic;
  font-weight: 500;
  font-size: 18px;
  line-height: 1.25;
  margin: 0;
  color: var(--sumi);
}

/* CASE — descriptive subtitle (colourway, mod tags …). Source Serif
   italic, sumi-soft so it reads as secondary. */
.gallery-card__case {
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  line-height: 1.4;
  margin: 0;
  color: var(--sumi-soft);
}

/* When there's no `name`, pull the chassis up so the card spacing
   stays even and cards in the same row align across the grid. */
.gallery-card__name + .gallery-card__chassis {
  margin-top: calc(var(--s-4) * -1);
}

/* =====================================================================
   CLICKABLE CARD — the gallery card is now a <button> that opens the
   lightbox. Reset native button chrome so the existing card styling
   still wins, and add a subtle hover lift + akane focus ring.
   ===================================================================== */
.gallery-card--clickable {
  cursor: pointer;
  background: var(--paper, #faf4e6);
  border: 0.5px solid var(--rule-soft);
  padding: var(--s-24);
  text-align: left;
  width: 100%;
  color: inherit;
  font: inherit;
  display: flex;
  flex-direction: column;
  gap: var(--s-12);
  border-radius: 3px;
  transition:
    border-color 200ms ease,
    transform 200ms ease,
    box-shadow 200ms ease;
}
.gallery-card--clickable:hover {
  border-color: rgba(20, 17, 13, 0.18);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}
.gallery-card--clickable:focus-visible {
  outline: 1.5px solid var(--akane);
  outline-offset: 4px;
}

/* =====================================================================
   LINKED CARD — the card is a <div> with TWO actions:
   (1) thumb is a <button> that opens the lightbox
   (2) "Read the story →" link to /builds/{slug}
   Inherits .gallery-card base styles; just resets the inner button.
   ===================================================================== */
.gallery-card--linked {
  background: var(--paper, #faf4e6);
  border: 0.5px solid var(--rule-soft);
  padding: var(--s-24);
  display: flex;
  flex-direction: column;
  gap: var(--s-12);
  border-radius: 3px;
  transition: border-color 200ms ease, transform 200ms ease, box-shadow 200ms ease;
}
.gallery-card--linked:hover {
  border-color: rgba(20, 17, 13, 0.18);
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.06);
}
.gallery-card__open {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
  display: block;
  width: 100%;
}
.gallery-card__open:focus-visible {
  outline: 1.5px solid var(--akane);
  outline-offset: 4px;
}
.gallery-card__no {
  font-family: var(--display);
  font-style: italic;
  font-weight: 700;
  color: var(--sumi);
  text-transform: none;
  letter-spacing: -0.005em;
  font-feature-settings: "onum" 1;
}
.gallery-card__sep {
  color: var(--rule);
  margin: 0 6px;
}
.gallery-card__story {
  margin-top: 8px;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--akane);
  text-decoration: none;
  align-self: flex-start;
  border-bottom: 1px solid transparent;
  padding-bottom: 1px;
  transition: border-color 0.2s ease;
}
.gallery-card__story:hover {
  border-bottom-color: var(--akane);
}
.gallery-card__story:focus-visible {
  outline: 1.5px solid var(--akane);
  outline-offset: 3px;
}

/* =====================================================================
   LIGHTBOX — full-screen modal opened by clicking any card. Closes on
   backdrop click, × button, or Escape. ‹ › arrows cycle builds (also
   ArrowLeft / ArrowRight keys). Body scroll is locked while open.
   ===================================================================== */
.gallery-lightbox {
  position: fixed;
  inset: 0;
  background: rgba(20, 17, 13, 0.92);
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: var(--s-32);
  animation: gallery-lightbox-fade-in 0.2s ease;
}
@keyframes gallery-lightbox-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

.gallery-lightbox__inner {
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: var(--s-32);
  max-width: min(1400px, 100%);
  max-height: 90vh;
  align-items: center;
}
@media (max-width: 768px) {
  .gallery-lightbox__inner {
    grid-template-columns: 1fr;
    grid-template-rows: 1fr auto;
    gap: var(--s-16);
    max-height: 95vh;
  }
}

.gallery-lightbox__img {
  max-width: 100%;
  max-height: 90vh;
  object-fit: contain;
  background: var(--paper);
  border-radius: 4px;
  display: block;
  margin: 0 auto;
}

.gallery-lightbox__caption {
  color: var(--bone);
  font-family: var(--serif);
}
.gallery-lightbox__name {
  font-family: var(--serif);
  font-style: italic;
  font-size: clamp(1.5rem, 3vw, 2.5rem);
  margin: 0 0 var(--s-12);
  color: var(--bone);
}
.gallery-lightbox__chassis {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--akane);
  margin: 0 0 var(--s-12);
}
.gallery-lightbox__detail {
  font-family: var(--serif);
  font-style: italic;
  font-size: 1rem;
  color: rgba(239, 231, 214, 0.85);
  margin: 0 0 var(--s-16);
}
.gallery-lightbox__year {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: rgba(239, 231, 214, 0.6);
  margin: 0;
}

.gallery-lightbox__close {
  position: absolute;
  top: var(--s-16);
  right: var(--s-16);
  width: 44px;
  height: 44px;
  background: none;
  border: 1px solid rgba(239, 231, 214, 0.4);
  border-radius: 50%;
  color: var(--bone);
  font-size: 24px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.gallery-lightbox__close:hover {
  background: var(--akane);
  border-color: var(--akane);
}

.gallery-lightbox__nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 56px;
  height: 56px;
  background: none;
  border: 1px solid rgba(239, 231, 214, 0.3);
  border-radius: 50%;
  color: var(--bone);
  font-size: 32px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s ease, border-color 0.2s ease;
}
.gallery-lightbox__nav:hover {
  background: var(--akane);
  border-color: var(--akane);
}
.gallery-lightbox__nav--prev { left: var(--s-24); }
.gallery-lightbox__nav--next { right: var(--s-24); }

@media (max-width: 640px) {
  .gallery-lightbox__nav {
    width: 44px;
    height: 44px;
    font-size: 24px;
  }
  .gallery-lightbox__nav--prev { left: var(--s-12); }
  .gallery-lightbox__nav--next { right: var(--s-12); }
}
