/* ==========================================================================
   Tokens
   ========================================================================== */
:root {
  --bg: #141311;
  --surface: #1b1917;
  --surface-alt: #221f1b;
  --line: #34302a;
  --text: #ede8dd;
  --text-muted: #8f887a;
  --accent: #c7a159;
  --accent-soft: rgba(199, 161, 89, 0.35);
  --scrim: rgba(10, 9, 8, 0.97);

  --font-display: "Meiryo", "メイリオ", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  --font-ui: "Meiryo", "メイリオ", "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;

  --gap: 6px;
  --ease: cubic-bezier(0.65, 0, 0.35, 1);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  overflow-x: hidden; /* belt-and-suspenders: never let a hairline rounding
                          overflow anywhere on the page create a horizontal
                          scrollbar / shove content around on mobile */
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  -webkit-font-smoothing: antialiased;
}

body.viewer-open { overflow: hidden; height: 100%; }

img { display: block; }

button {
  font-family: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0;
}

:focus-visible {
  outline: 1px solid var(--accent);
  outline-offset: 3px;
}

/* ==========================================================================
   Header
   ========================================================================== */
.site-header {
  display: flex;
  align-items: baseline;
  gap: 18px;
  padding: 14px 24px;
  border-bottom: 1px solid var(--line);
}

.site-header__title {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 200;
  font-size: clamp(17px, 2.2vw, 22px);
  letter-spacing: 0.04em;
  color: var(--text);
  flex: 1;
}

.site-header__pixiv {
  font-size: 12px;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  text-decoration: none;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  transition: color 0.2s;
}
.site-header__pixiv:hover { color: var(--accent); }

/* ==========================================================================
   Masonry gallery (justified rows)
   ========================================================================== */
.gallery {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  padding: var(--gap);
  overflow-x: hidden;
}

/* Each row is built by JS with the exact items it should contain, so it
   never needs to wrap — this avoids relying on the browser to make its own
   (rounding-sensitive) line-break decision, which is what could push an
   item onto the next line and leave a gap on the right. */
.gallery-row {
  display: flex;
  flex-wrap: nowrap;
  gap: var(--gap);
}

.gallery-item {
  position: relative;
  overflow: hidden;
  background: var(--surface);
  flex: 0 0 auto;
  min-width: 0;
}

.gallery-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.5s var(--ease), filter 0.4s var(--ease);
}

.gallery-item__label {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85), 0 0 12px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.3s var(--ease), transform 0.3s var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@media (hover: hover) and (pointer: fine) {
  .gallery-item:hover img { transform: scale(1.035); filter: brightness(0.92); }
  .gallery-item:hover .gallery-item__label { opacity: 1; transform: translateY(0); }
}

.diff-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(10, 9, 8, 0.6);
  border: 1px solid rgba(237, 232, 221, 0.25);
  color: var(--text);
  font-size: 11px;
  letter-spacing: 0.03em;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(2px);
}

.empty-message {
  padding: 60px 28px;
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  line-height: 1.9;
}

.empty-message code {
  color: var(--accent);
  background: var(--surface);
  padding: 2px 8px;
  border: 1px solid var(--line);
}

/* ==========================================================================
   Viewer
   ========================================================================== */
.viewer {
  position: fixed;
  inset: 0;
  z-index: 1000;
}

.viewer__scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
}

.viewer-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  touch-action: none;
}

.slide {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* Nav buttons (left/right/up/down) are now allowed to sit on top of the
     image — only the title/close row (top) and the always-visible
     thumbnail strip (bottom) actually need to stay clear of the image, so
     padding is trimmed to just that: title/close clearance on top, and a
     hairline gap above the thumbnail strip on the bottom. Left/right are 0
     so the image runs edge-to-edge. */
  padding: 60px 0 90px;
  transition: transform 0.4s var(--ease);
  will-change: transform;
}

.slide img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.slide.from-right { transform: translateX(100%); }
.slide.from-left   { transform: translateX(-100%); }
.slide.from-down   { transform: translateY(100%); }
.slide.from-up     { transform: translateY(-100%); }
.slide.to-left     { transform: translateX(-100%); }
.slide.to-right    { transform: translateX(100%); }
.slide.to-up       { transform: translateY(-100%); }
.slide.to-down     { transform: translateY(100%); }
.slide.settled,
.slide.current      { transform: translate(0, 0); }
.slide.no-anim      { transition: none; }

/* close */
.viewer-close {
  position: absolute;
  top: 10px; /* aligned with the title plate's line rather than the viewer edge */
  right: 20px;
  z-index: 20;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  font-weight: 300;
  color: var(--text);
  opacity: 0.75;
  transition: opacity 0.2s, transform 0.2s;
}
.viewer-close:hover { opacity: 1; transform: rotate(90deg); }

/* nav buttons */
.nav-btn {
  position: absolute;
  z-index: 20;
  width: 46px;
  height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text);
  opacity: 0.55;
  transition: opacity 0.2s, transform 0.2s;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn:hover { opacity: 1; }
.nav-btn.is-disabled { opacity: 0.15; pointer-events: none; }
.nav-btn.is-hidden { display: none; }

.nav-btn--left  { left: 8px; top: calc(50% - 15px); transform: translateY(-50%); }
.nav-btn--right { right: 8px; top: calc(50% - 15px); transform: translateY(-50%); }
.nav-btn--left:hover  { transform: translateY(-50%) translateX(-3px); }
.nav-btn--right:hover { transform: translateY(-50%) translateX(3px); }

.nav-btn--up   { top: 60px; left: 50%; transform: translateX(-50%); }
.nav-btn--down { bottom: 90px; left: 50%; transform: translateX(-50%); }
.nav-btn--up:hover   { transform: translateX(-50%) translateY(-3px); }
.nav-btn--down:hover { transform: translateX(-50%) translateY(3px); }

/* gallery plate — signature label (top-left, clear of the always-visible thumbnail strip) */
.viewer-plate {
  position: absolute;
  left: 24px;
  top: 20px;
  z-index: 15;
  display: flex;
  align-items: baseline;
  gap: 12px;
  max-width: 55vw;
  padding-left: 14px;
  border-left: 1px solid var(--accent-soft);
  transition: opacity 0.25s var(--ease);
}
.viewer-plate.is-fading { opacity: 0; }

.viewer-plate__title {
  font-family: var(--font-display);
  font-size: 17px;
  letter-spacing: 0.05em;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viewer-plate__diff {
  font-size: 11px;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* thumbnail strip — always visible filmstrip at the bottom */
.thumb-strip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 18;
  background: linear-gradient(to top, rgba(10, 9, 8, 0.9), rgba(10, 9, 8, 0));
  padding: 16px 16px 12px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}
.thumb-strip::-webkit-scrollbar { display: none; }

.thumb-track {
  display: flex;
  gap: 6px;
  width: max-content;
}

.thumb-item {
  position: relative;
  flex: 0 0 auto;
  height: 58px;
  overflow: hidden;
  opacity: 0.5;
  border: 1px solid transparent;
  transition: opacity 0.2s, border-color 0.2s;
}
.thumb-item img { height: 100%; width: auto; display: block; }
.thumb-item:hover { opacity: 0.85; }
.thumb-item.is-active {
  opacity: 1;
  border-color: var(--accent);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 640px) {
  .site-header { padding: 10px 16px; gap: 10px; }
  /* nav-up stays pulled down from the top edge so it still clears the
     title plate (a UI-to-UI collision, unaffected by the "buttons may sit
     over the image" relaxation below). Everything else is trimmed to the
     practical minimum: buttons overlapping the image is fine, so only the
     title/close row and the thumbnail strip actually need clearance. */
  .slide { padding: 60px 0 72px; }
  .nav-btn--left  { left: 2px; top: calc(50% - 6px); }
  .nav-btn--right { right: 2px; top: calc(50% - 6px); }
  .nav-btn--up    { top: 58px; }
  .nav-btn--down  { bottom: 74px; }
  .viewer-close   { top: 8px; }
  .viewer-plate   { left: 14px; top: 14px; max-width: 65vw; }
  .viewer-plate__title { font-size: 15px; }
  .thumb-strip { padding: 12px 12px 10px; }
  .thumb-item { height: 46px; }
}

@media (prefers-reduced-motion: reduce) {
  .slide, .thumb-strip, .gallery-item img, .gallery-item::after,
  .gallery-item__label, .viewer-plate, .nav-btn, .viewer-close {
    transition-duration: 0.001ms !important;
  }
}
