/* MagnusL3D Gallery — minimal: 50% gray bg, white text. */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: #202020;
  color: #ffffff;
  font-family: 'JetBrains Mono', 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  letter-spacing: 0.01em;
  overflow-x: hidden;
}

img { display: block; max-width: 100%; user-select: none; -webkit-user-drag: none; }

::selection { background: #ffffff; color: #404040; }

/* ─── Page chrome ─────────────────────────────────────────────────────────── */
.ml-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: #202020;
}

.ml-header {
  position: sticky;
  top: 0;
  z-index: 1000;
  background: #202020;
}

.ml-header-row {
  width: 80%;
  margin: 0 auto;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 32px;
  padding: 20px 0 18px;
}

/* Bulge toggle on the far right — matches the Tweaks-panel toggle style */
.ml-bulge-toggle {
  position: relative;
  width: 32px;
  height: 18px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  transition: background 0.15s;
  cursor: pointer;
  padding: 0;
  justify-self: end;
  outline: none;
}
.ml-bulge-toggle:focus-visible {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.35);
}
.ml-bulge-toggle[data-on="1"] {
  background: #34c759;
}
.ml-bulge-toggle i {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}
.ml-bulge-toggle[data-on="1"] i {
  transform: translateX(14px);
}

.ml-logo {
  display: flex;
  align-items: baseline;
  gap: 8px;
  text-decoration: none;
  color: #ffffff;
}
.ml-logo-mark {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
}
.ml-logo-mark em { font-style: normal; }
.ml-logo-tag {
  font-size: 10px;
  letter-spacing: 0.18em;
  color: rgba(255, 255, 255, 0.55);
  text-transform: uppercase;
}

.ml-nav {
  display: flex;
  gap: 4px;
  justify-self: start;
}
.ml-nav-link {
  display: inline-block;
  padding: 6px 14px;
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.6);
  background: transparent;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  transition: color 0.12s, background 0.12s, border-color 0.12s;
}
.ml-nav-link:hover { color: #ffffff; }
.ml-nav-link.is-active {
  color: #404040;
  background: #ffffff;
  border-color: #ffffff;
}

/* ─── Album header ────────────────────────────────────────────────────────── */
.ml-album-head {
  width: 80%;
  margin: 0 auto;
  padding: 28px 0 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.15);
}
.ml-album-title {
  font-size: 56px;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 0.95;
  color: #ffffff;
}
.ml-album-title em { font-style: normal; }
.ml-album-sub {
  margin: 10px 0 0;
  font-size: 12px;
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 0.04em;
  max-width: 60ch;
}

/* ─── Gallery container ───────────────────────────────────────────────────── */
.ml-gallery-wrap {
  width: 80%;
  margin: 0 auto;
  padding: 0 0 28px;
}
.ml-gallery {
  position: relative;
  width: 100%;
}

/* ─── Tile ────────────────────────────────────────────────────────────────── */
.ml-tile {
  position: absolute;
  background: #6c6c6c;
  overflow: hidden;
  cursor: pointer;
  /* Per-tile vars updated per-frame by the rAF loop. */
  --zoom: 1;
  --ab: 0;
  --ab-ux: 0;
  --ab-uy: 0;
  --intensity: 0;
}

.ml-tile-img-wrap {
  position: absolute;
  /* Overshoot the tile by 2px in every direction. The parent .ml-tile has
     overflow: hidden, so this content is clipped to integer pixel bounds —
     adjacent tiles don't visibly overlap. The buffer absorbs subpixel
     rendering jitter from the `transform: scale(1)` always applied to
     .ml-tile-img (browsers route identity transforms through the same
     pipeline as real ones, which can shrink the rendered image by 1–2 device
     pixels at non-100% zoom). */
  inset: -2px;
  overflow: hidden;
  background: #6c6c6c;
  /* Pin the image to its own compositing layer so the transform pipeline
     produces a stable, integer-aligned render. */
  will-change: transform;
}

.ml-tile-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: translate(var(--pan-x, 0%), var(--pan-y, 0%)) scale(var(--zoom));
  transform-origin: var(--origin-x, 50%) var(--origin-y, 50%);
  will-change: transform;
  transition: opacity 0.18s, filter 0.32s;
}
/* Plain hover mode (Bulge off) — animate transform smoothly.
   Zoom OUT (default state, used when focus leaves) is twice as long as
   zoom IN, which is itself half-as-fast as the original 280ms. */
.ml-gallery.is-plain-hover .ml-tile-img {
  transition: transform 560ms cubic-bezier(.2,.7,.2,1), opacity 0.18s, filter 0.32s;
}
.ml-gallery.is-plain-hover .ml-tile.is-focused .ml-tile-img {
  transition: transform 1120ms cubic-bezier(.2,.7,.2,1), opacity 0.18s, filter 0.32s;
}

/* Chromatic aberration on neighbours within falloff radius.
   Position + opacity driven by per-tile CSS vars updated by the rAF loop. */
.ml-tile-img--ab {
  pointer-events: none;
  mix-blend-mode: screen;
  will-change: transform, opacity;
  opacity: calc(var(--ab) * 0.55);
}
.ml-tile-img--ab-r {
  filter: contrast(1.1) saturate(1.2) hue-rotate(-15deg) brightness(1.1);
  transform:
    translate(var(--pan-x, 0%), var(--pan-y, 0%))
    scale(var(--zoom))
    translate(
      calc(var(--ab-ux) * -6px * var(--ab)),
      calc(var(--ab-uy) * -6px * var(--ab))
    );
}
.ml-tile-img--ab-b {
  filter: contrast(1.1) saturate(1.2) hue-rotate(25deg) brightness(1.1);
  transform:
    translate(var(--pan-x, 0%), var(--pan-y, 0%))
    scale(var(--zoom))
    translate(
      calc(var(--ab-ux) * 6px * var(--ab)),
      calc(var(--ab-uy) * 6px * var(--ab))
    );
}

.ml-tile.is-focused .ml-tile-img {
  filter: brightness(1.04);
}

.ml-tile.is-dimmed .ml-tile-img {
  filter: saturate(0.6) brightness(0.8);
}

/* Play badge — overlaid on video tiles in the grid. */
.ml-play-badge {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.55);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  padding-left: 4px; /* nudge the ▶ glyph optically into the circle's center */
  pointer-events: none;
  z-index: 4;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}

/* Metadata block — bottom of focused tile */
.ml-meta {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 12px;
  background: linear-gradient(0deg, rgba(0,0,0,0.7), rgba(0,0,0,0.0));
  color: #ffffff;
  z-index: 6;
  font-size: 10px;
  letter-spacing: 0.04em;
  pointer-events: none;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px 14px;
  animation: ml-meta-in 0.22s ease-out 0.05s backwards;
}
@keyframes ml-meta-in {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}
.ml-meta-row { display: flex; gap: 6px; align-items: baseline; }
.ml-meta-key {
  color: rgba(255, 255, 255, 0.7);
  letter-spacing: 0.16em;
  font-size: 9px;
  width: 32px;
  flex-shrink: 0;
}
.ml-meta-val {
  color: #ffffff;
  font-variant-numeric: tabular-nums;
}

/* ─── Lightbox ────────────────────────────────────────────────────────────── */
.ml-lb {
  position: fixed;
  inset: 0;
  z-index: 2000;
  background: rgba(60, 60, 60, 0.96);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  animation: ml-lb-fade 0.18s ease-out;
}
@keyframes ml-lb-fade { from { opacity: 0; } to { opacity: 1; } }

.ml-lb-grid {
  display: grid;
  grid-template-rows: 1fr;
  height: 100%;
  width: 100%;
}

.ml-lb-stage {
  /* No flex/grid sizing — image controls its own size and the imgwrap is
     absolutely centered. Avoids the parent-height-transfer pitfall that was
     letting tall images escape the viewport. */
  position: relative;
  height: 100%;
  width: 100%;
  overflow: visible;
}
.ml-lb-imgwrap {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  display: block;
  line-height: 0;
}
.ml-lb-img {
  /* Hard viewport-minus-gap caps. Always fits with 40px on every side and
     then some, regardless of how the parents are sized. dvh handles the
     mobile-chrome case where 100vh overshoots the visible viewport. */
  display: block;
  max-width:  calc(100vw - 80px);
  max-height: calc(100vh - 80px);
  max-height: calc(100dvh - 80px);
  width:  auto;
  height: auto;
  object-fit: contain;
  box-shadow: 0 30px 100px rgba(0,0,0,0.4);
  animation: ml-lb-img-in 0.22s cubic-bezier(.2,.7,.2,1) both;
  transform-origin: center center;
}
@keyframes ml-lb-img-in {
  from { opacity: 0; transform: scale(0.6); }
  to   { opacity: 1; transform: scale(1); }
}
.ml-lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.18);
  font-size: 36px;
  line-height: 1;
  cursor: pointer;
  z-index: 10;
  font-family: inherit;
  padding: 0;
  transition: color 0.15s;
}
.ml-lb-nav:hover:not(:disabled) {
  color: #ffffff;
}
.ml-lb-nav:disabled { opacity: 0.15; cursor: not-allowed; }
.ml-lb-nav--l { left: -52px; }
.ml-lb-nav--r { right: -52px; }
.ml-lb-x--float {
  position: absolute;
  top: -36px;
  right: 0;
  z-index: 20;
  margin: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  background: transparent;
  border: 0;
  color: rgba(255, 255, 255, 0.18);
  cursor: pointer;
  letter-spacing: 0;
  transition: color 0.15s;
}
.ml-lb-x--float:hover {
  color: #ffffff;
  border-color: transparent;
}
