/* 
  Global layout: brutalist canvas, full-viewport, no scrollbars.
  Typography: JetBrains Mono, light weights (default — overridable via config).
  Design tokens: all visual properties as CSS variables for runtime theming.
*/

*,
*::before,
*::after {
  box-sizing: border-box;
}

/* ── Design Tokens ─────────────────────────────────────────────────────────── */

:root {
  --bg-colour:          #f7f5f0;
  --text-colour:        #ffff00;
  --ui-text-size:       18px;
  --font-family:        "JetBrains Mono", "Cascadia Code", "Source Code Pro", Menlo, Monaco, "Courier New", monospace;

  /* Theme gradient (used by bg-gradient-static and bg-gradient-animated) */
  --bg-from:            #f7f5f0;
  --bg-to:              #e0e0e0;

  /* Noise/grain overlay */
  --noise-opacity:      0;

  /* Image shadows */
  --shadow-enabled:     1;   /* set to 0 via body.no-shadow */
  --shadow-blur:        30px;
  --shadow-color:       rgba(0, 0, 0, 0.06);

  /* Duotone image filter */
  --duotone-hue:        200deg;
  --duotone-sat:        2;

  /* Zone layout spacing */
  --zone-edge:          32px;
  --zone-mid-y:         50%;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--bg-colour);
  color: var(--text-colour, #111111);
  font-family: var(--font-family);
  font-weight: var(--font-weight, 400);
  font-stretch: var(--font-stretch, 100%);
  text-transform: var(--text-transform, uppercase);
  font-size: var(--ui-text-size, 18px);
  font-size-adjust: from-font;
}

body {
  -webkit-font-smoothing: antialiased;
}

/* Reset for semantic elements */
figure {
  margin: 0;
  padding: 0;
}

/* Fixed navigation bar */

.nav {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 64px;
  padding: 0 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1000;
  pointer-events: none; /* Container ignores events, children re-enable */
  mix-blend-mode: var(--text-blend-mode, normal);
  background: transparent;
  color: inherit;
  text-transform: var(--text-transform, uppercase);
}

.nav-left {
  letter-spacing: 0.08em;
  text-transform: var(--text-transform, uppercase);
  font-size: var(--ui-text-size, 18px);
  pointer-events: auto; /* Re-enable for the brand/name if needed, or keep it none */
  display: flex;
  align-items: center;
  gap: 8px;
}

a.nav-left {
  color: inherit;
  text-decoration: none;
}

a.zone-title-module:hover .nav-title-text {
  text-decoration: underline;
}

.site-logo {
  display: flex;
  align-items: center;
  justify-content: center;
}
.site-logo svg {
  display: block;
}

/* Nav right — shared base for all injected items */

.nav-right {
  display: flex;
  align-items: center;
  gap: 0;
  pointer-events: none; /* container pass-through; children re-enable */
}

/* Base style for every nav interactive element (buttons + links) */
.nav-btn {
  display: inline;
  background: transparent;
  border: none;
  color: inherit;
  font-family: inherit;
  font-size: var(--ui-text-size, 18px);
  font-weight: inherit;
  font-stretch: inherit;
  text-transform: var(--text-transform, uppercase);
  letter-spacing: 0.08em;
  text-decoration: none;
  padding: 0;
  cursor: pointer;
  pointer-events: auto;
  white-space: nowrap;
}

.nav-btn:hover {
  text-decoration: underline;
}


/* Global Module Wrapper (separates brackets from clickable links) */
.module-wrapper {
  display: inline-flex;
  align-items: baseline;
  pointer-events: none;
}
.module-wrapper > * {
  pointer-events: auto;
}
.module-prefix, .module-suffix {
  pointer-events: none;
  user-select: none;
  white-space: pre;
}

/* Separator pipe between nav items */
.nav-sep {
  font-size: var(--ui-text-size, 18px);
  letter-spacing: 0.04em;
  pointer-events: none;
  user-select: none;
}

/* Strikethrough = category is hidden / toggled off */
.nav-btn.is-struck {
  text-decoration: line-through;
}

.nav-btn.is-struck:hover {
  text-decoration: line-through underline;
}

/* Main viewport */

.viewport {
  position: fixed;
  inset: 0;
}

#stage-wrapper {
  position: relative;
  z-index: 1;
  width: 100%;
  height: 100%;
  overflow: hidden;
  cursor: grab;
  user-select: none;
  -webkit-user-select: none;
  transition: filter 0.3s ease;
}

#stage-wrapper.is-dragging {
  cursor: grabbing;
}

/*
  The virtual canvas: intentionally larger than the viewport
  so that panning reveals more whitespace and objects.
*/

#stage {
  position: absolute;
  top: 0;
  left: 0;
  width: 9000px;
  height: 6500px;
  transform: translate3d(0, 0, 0) scale(1);
  transform-origin: 0 0;
  will-change: transform;
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1);
}

#stage.is-interacting {
  transition: none;
}

/* Media items scattered across the stage */

.media-item {
  position: absolute;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin: 0;
  background: transparent;
  box-shadow: 0 var(--shadow-blur, 30px) calc(var(--shadow-blur, 30px) * 2) var(--shadow-color, rgba(0,0,0,0.06));
  border-radius: var(--media-border-radius, 0px);
  overflow: hidden;
  cursor: grab;
  transition: box-shadow 0.15s ease-out;
  will-change: left, top;
  mix-blend-mode: var(--image-blend-mode, normal);
}

.media-item.is-dragging {
  cursor: grabbing;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.16);
  transition: none;
}

/* Media items are dragged, not keyboard-navigated — no focus ring needed */
.media-item:focus {
  outline: none;
}

.media-item img,
.media-item video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.media-item video {
  background: #000;
  border: none;
  outline: none;
}

/* Loading & error states to avoid "empty frames" */

.media-item::before {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(247, 245, 240, 0.8);
  opacity: 0;
  transition: opacity 0.2s ease-out;
  pointer-events: none;
}

.media-item.loading::before {
  opacity: 1;
}

.media-item.loading img,
.media-item.loading video {
  opacity: 0;
}

.media-item.has-error {
  background: #0047ff; /* solid blue block for failed media */
}

.media-item.has-error::before {
  opacity: 0;
}

.reload-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  padding: 0;
  margin: 0;
  cursor: pointer;
  letter-spacing: 0.16em;
  font-size: 14px;
  text-transform: var(--text-transform, uppercase);
  color: inherit;
  mix-blend-mode: var(--text-blend-mode, normal);
}

.reload-badge:hover {
  opacity: 0.8;
}

/* Embedded video placeholder with play overlay */

.media-item.video-embed .video-placeholder {
  position: relative;
  display: block;
  width: 100%;
  height: 100%;
  overflow: hidden;
  padding: 0;
  border: none;
  background: transparent;
  cursor: pointer;
}

.media-item.video-embed .video-placeholder img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-item.video-embed .video-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.5); /* 50% black overlay */
  z-index: 1;
  pointer-events: none;
  transition: background 0.2s ease;
}

.media-item.video-embed .play-badge {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
  pointer-events: none;
}

.media-item.video-embed .play-badge-text {
  color: inherit;
  mix-blend-mode: var(--text-blend-mode, normal);
  font-size: 14px;
  letter-spacing: 0.16em;
  text-align: center;
}

.media-item.video-embed:hover .video-overlay {
  background: rgba(0, 0, 0, 0.7);
}

/* When iframe replaces placeholder */

.media-item.video-embed iframe {
  border: none;
  width: 100%;
  height: 100%;
  display: block;
}

/* Hide thumbnail placeholder while YT iframe is active */
.media-item.video-embed.is-playing .video-placeholder {
  display: none;
}

/* [x] reset button — returns the embed to its draggable thumbnail state */
.yt-reset-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 10;
  background: transparent;
  border: none;
  color: inherit;
  mix-blend-mode: var(--text-blend-mode, normal);
  font-family: inherit;
  font-size: 14px;
  letter-spacing: 0.1em;
  cursor: pointer;
  padding: 4px 6px;
  pointer-events: auto;
  line-height: 1;
}

.yt-reset-btn:hover {
  opacity: 0.7;
}



/* Small helper for subtle debug text (if needed) */

.debug-label {
  position: fixed;
  left: 16px;
  bottom: 52px;
  font-size: 10px;
  opacity: 0.4;
  pointer-events: none;
}

/* Visually hidden but readable by screen readers */
#a11y-announcer {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ── Info Overlay ───────────────────────────────────────────────────────────── */

/* Phase 8: Info Overlay Canvas Effects */
body.info-open.info-blur-bg #stage-wrapper {
  filter: blur(6px);
}
body.info-open.info-darken #stage-wrapper {
  filter: brightness(0.6);
}
body.info-colour-overlay::after {
  content: '';
  position: fixed;
  inset: 0;
  background-color: var(--info-overlay-color, #000000);
  mix-blend-mode: var(--info-overlay-blend-mode, normal);
  pointer-events: none;
  z-index: 899;
  opacity: 0;
  transition: opacity 0.3s ease;
}
body.info-open.info-colour-overlay::after {
  opacity: var(--info-overlay-opacity, 0.75);
}

@media (prefers-reduced-motion: reduce) {
  #stage-wrapper,
  body.info-colour-overlay::after {
    transition: none !important;
  }
}

#info-overlay {
  position: fixed;
  top: 64px;    /* clear nav */
  left: 0;
  right: 0;
  bottom: 48px; /* clear footer */
  z-index: 900; /* below nav (1000) */
  background: transparent; /* canvas items visible behind */
  display: none;
  padding: 48px 64px;
  overflow: hidden;
  /* blend-mode on container: yellow text -> blue against off-white, same as nav */
  mix-blend-mode: var(--text-blend-mode, normal);
  /* Let mouse events pass through to the canvas so panning still works */
  pointer-events: none;
}

#info-overlay.is-visible {
  display: block;
}

#info-text {
  text-align: left;
  hyphens: auto;
  word-break: break-word;
  -webkit-hyphens: auto;
  font-family: inherit;
  font-weight: inherit;
  font-stretch: inherit;
  text-transform: var(--text-transform, uppercase);
  color: inherit;
  line-height: 1.15;
  letter-spacing: 0.04em;
  /* font-size controlled by JS autoscaler */
  /* Allow clicking links and selecting text within the text block itself */
  pointer-events: auto;
  user-select: text;
  -webkit-user-select: text;
}

#info-text a {
  color: inherit;
  text-decoration: underline;
  pointer-events: auto; /* links are clickable even though overlay passes events through */
}

#info-text a:hover {
  opacity: 0.7;
}

#info-text strong {
  font-weight: bolder;
}

#info-text em {
  font-style: italic;
  text-transform: inherit;
}

/* ── Preloader ───────────────────────────────────────────────────────────── */

#preloader {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 2000;
  pointer-events: none;
  mix-blend-mode: var(--text-blend-mode, normal);
  color: inherit;
  font-family: var(--font-family);
  font-size: 14px;
  line-height: 1;
}

#preloader-bar {
  display: block;
  white-space: pre;
  overflow: hidden;
  width: 100%;
  letter-spacing: 0;
}

#preloader-counter {
  position: fixed;
  bottom: calc(56px + env(safe-area-inset-bottom)); /* clears footer + iOS home indicator */
  left: 32px;
  font-size: 14px;
  letter-spacing: 0.08em;
  text-transform: var(--text-transform, uppercase);
}

/* Mobile adjustments */
@media (max-width: 768px) {
  :root {
    --ui-text-size: 14px;
  }
  #layout-panel { display: none; }

  .nav {
    padding: 16px 20px;
    padding-top: calc(16px + env(safe-area-inset-top));
    height: auto;
    min-height: 48px;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .nav-left {
    font-size: var(--ui-text-size, 18px);
    padding-top: 0;
    padding-bottom: 0;
  }

  /* Stack nav-right items vertically, top-left (aligned with nav-left) */
  .nav-right {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  /* Hide pipe separators on mobile — each item sits on its own line */
  .nav-sep {
    display: none;
  }

  .nav-btn {
    font-size: var(--ui-text-size, 18px);
  }

  .footer {
    padding: 0 16px;
    padding-bottom: env(safe-area-inset-bottom);
    height: auto;
    min-height: 48px;
    justify-content: flex-end; /* zoom controls bottom-right */
  }

  /* Zoom buttons same size as nav — no discrepancy */
  .zoom-btn {
    font-size: var(--ui-text-size, 18px);
  }

  /* Info Overlay Mobile Tweaks */
  #info-overlay {
    top: 0; /* Cover more area on mobile */
    bottom: env(safe-area-inset-bottom); /* clear iOS home indicator */
    padding: 100px 20px 40px 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    pointer-events: none; /* Allow background scrolling/panning */
  }

  #info-text {
    width: 100%;
    max-width: none;
    font-size: 7vw; /* Fluid font for brutalist feel, but limited */
    line-height: 1.1;
  }
}

/* ── Category Panel ─────────────────────────────────────────────────────────── */
/* Position is now handled by .zone-* containers injected by JS.
   These rules only set the visual / display properties. */

#category-panel {
  z-index: 1000;
  pointer-events: none;
  mix-blend-mode: var(--text-blend-mode, normal);
  color: inherit;
  font-family: inherit;
  font-size: var(--ui-text-size, 18px);
  text-transform: var(--text-transform, uppercase);
  letter-spacing: 0.08em;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

/* ── Layout Panel ───────────────────────────────────────────────────────────── */
/* Position is now handled by .zone-* containers injected by JS. */

#layout-panel {
  z-index: 1000;
  pointer-events: none;
  mix-blend-mode: var(--text-blend-mode, normal);
  color: inherit;
  font-family: inherit;
  font-size: var(--ui-text-size, 18px);
  text-transform: var(--text-transform, uppercase);
  letter-spacing: 0.08em;
  /* flex-direction and align-items are set dynamically by buildLayoutPanel() */
  display: flex;
}

.layout-option {
  background: transparent;
  border: none;
  color: inherit;
  font-family: inherit;
  font-size: var(--ui-text-size, 18px);
  font-weight: inherit;
  font-stretch: inherit;
  text-transform: var(--text-transform, uppercase);
  letter-spacing: 0.08em;
  text-decoration: line-through; /* default: struck = inactive */
  padding: 0;
  cursor: pointer;
  pointer-events: auto;
  white-space: nowrap;
}

.layout-option.is-active {
  text-decoration: none; /* active mode = no strikethrough */
}

.layout-option:hover {
  text-decoration: underline;
}

/* ── Config: No Blend Mode ──────────────────────────────────────────────────── */



body.no-shadow .media-item {
  box-shadow: none;
}

/* ── 8-Zone Container System ────────────────────────────────────────────────── */
/* Injected by buildZoneContainers() in main.js.
   Each zone is a fixed-positioned flex column.
   pointer-events: none on container; pointer-events: auto re-enabled on children. */

.zone-container {
  position: fixed;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 4px;
  pointer-events: none;
  mix-blend-mode: var(--text-blend-mode, normal);
  color: inherit;
  font-family: inherit;
  font-size: var(--ui-text-size, 18px);
  text-transform: var(--text-transform, uppercase);
  letter-spacing: 0.08em;
  /* Ensure children can still get pointer events */
}

/* Horizontal alignment per zone column */
.zone-top-left,
.zone-middle-left,
.zone-bottom-left    { align-items: flex-start; }

.zone-top-center,
.zone-middle-center,
.zone-bottom-center  { align-items: center; }

.zone-top-right,
.zone-middle-right,
.zone-bottom-right   { align-items: flex-end; }

/* Positioning per zone */
.zone-top-left     { top: var(--zone-edge, 32px); left: var(--zone-edge, 32px); }
.zone-top-center   { top: var(--zone-edge, 32px); left: 50%; transform: translateX(-50%); }
.zone-top-right    { top: var(--zone-edge, 32px); right: var(--zone-edge, 32px); }
.zone-middle-left  { top: 50%; left: var(--zone-edge, 32px); transform: translateY(-50%); }
.zone-middle-center{ top: 50%; left: 50%; transform: translate(-50%, -50%); }
.zone-middle-right { top: 50%; right: var(--zone-edge, 32px); transform: translateY(-50%); }
.zone-bottom-left  { bottom: var(--zone-edge, 32px); left: var(--zone-edge, 32px); }
.zone-bottom-center{ bottom: var(--zone-edge, 32px); left: 50%; transform: translateX(-50%); }
.zone-bottom-right { bottom: var(--zone-edge, 32px); right: var(--zone-edge, 32px); }

/* Mobile: hide all zone containers (the legacy <nav> handles mobile layout) */
@media (max-width: 768px) {
  .zone-container { display: none !important; }
}

.layout-option.is-active:hover {
  text-decoration: underline;
}

/* ── Background Effect System ────────────────────────────────────────────────── */
/* Five body classes, all toggled by applyTheme() from config.theme.backgroundEffect */

/* Default: solid (body background is just --bg-colour, set in html,body above) */
body.bg-solid {
  background: var(--bg-colour);
}

/* Two-colour static gradient */
body.bg-gradient-static {
  background: linear-gradient(135deg, var(--bg-from, var(--bg-colour)), var(--bg-to, #e0e0e0));
}

/* Slow animated gradient */
body.bg-gradient-animated {
  background: linear-gradient(135deg, var(--bg-from, var(--bg-colour)), var(--bg-to, #e0e0e0), var(--bg-from, var(--bg-colour)));
  background-size: 400% 400%;
  animation: bg-shift 30s ease infinite;
}

@keyframes bg-shift {
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}


/* Noise/grain overlay — injected by JS as a real DOM element inside .viewport.
   Stacking order: background (body) → grain (#grain-overlay, z:0) → images (#stage-wrapper, z:1) → text (nav z:1000) */
#grain-overlay {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  filter: url(#grain);
  opacity: var(--noise-opacity, 0);
  will-change: opacity;
}

/* ── Text Animation System ───────────────────────────────────────────────────── */
/* Applied as class on the .zone-container and .nav elements */

body.text-fx-color-cycle .zone-container,
body.text-fx-color-cycle .nav,
body.text-fx-color-cycle .footer,
body.text-fx-color-cycle #info-overlay,
body.text-fx-color-cycle #preloader ,
body.text-fx-color-cycle .lightbox-close,
body.text-fx-color-cycle .lightbox-nav {
  animation: text-color-cycle var(--text-cycle-speed, 8s) linear infinite;
}

@keyframes text-color-cycle {
  0%   { color: var(--text-cycle-1, var(--text-colour)); }
  33%  { color: var(--text-cycle-2, hsl(60, 100%, 70%)); }
  66%  { color: var(--text-cycle-3, hsl(30, 100%, 70%)); }
  100% { color: var(--text-cycle-1, var(--text-colour)); }
}

body.text-fx-gradient .zone-container *,
body.text-fx-gradient .nav *,
body.text-fx-gradient .footer *,
body.text-fx-gradient #info-overlay *,
body.text-fx-gradient #preloader * ,
body.text-fx-gradient .lightbox-close,
body.text-fx-gradient .lightbox-nav {
  background: linear-gradient(90deg, var(--text-gradient-1, var(--text-colour)), var(--text-gradient-2, hsl(30, 100%, 70%)), var(--text-gradient-1, var(--text-colour)));
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: text-gradient-shift var(--text-gradient-speed, 5s) linear infinite;
}

@keyframes text-gradient-shift {
  from { background-position: 0% center; }
  to   { background-position: 200% center; }
}

/* hue-rotate: works best in Chromium. Graceful fallback = no animation. */
body.text-fx-hue-rotate .zone-container,
body.text-fx-hue-rotate .nav,
body.text-fx-hue-rotate .footer,
body.text-fx-hue-rotate #info-overlay,
body.text-fx-hue-rotate #preloader ,
body.text-fx-hue-rotate .lightbox-close,
body.text-fx-hue-rotate .lightbox-nav {
  animation: text-hue-rotate var(--text-hue-speed, 6s) linear infinite;
}

@keyframes text-hue-rotate {
  from { filter: hue-rotate(0deg); color: var(--text-hue-base, var(--text-colour)); }
  to   { filter: hue-rotate(360deg); color: var(--text-hue-base, var(--text-colour)); }
}

/* ── Text Animation: Hover-Only Trigger (Phase 12.5 Bug 5) ──────────────────── */
/* When body.text-anim-hover is present, animations only activate on :hover */

body.text-anim-hover.text-fx-color-cycle .zone-container,
body.text-anim-hover.text-fx-color-cycle .nav,
body.text-anim-hover.text-fx-color-cycle .footer,
body.text-anim-hover.text-fx-color-cycle #info-overlay,
body.text-anim-hover.text-fx-color-cycle #preloader ,
body.text-anim-hover.text-fx-color-cycle .lightbox-close,
body.text-anim-hover.text-fx-color-cycle .lightbox-nav {
  animation: none;
}
body.text-anim-hover.text-fx-color-cycle .zone-container:hover,
body.text-anim-hover.text-fx-color-cycle .nav:hover,
body.text-anim-hover.text-fx-color-cycle .footer:hover,
body.text-anim-hover.text-fx-color-cycle #info-overlay:hover,
body.text-anim-hover.text-fx-color-cycle #preloader:hover ,
body.text-anim-hover.text-fx-color-cycle .lightbox-close:hover,
body.text-anim-hover.text-fx-color-cycle .lightbox-nav:hover {
  animation: text-color-cycle var(--text-cycle-speed, 8s) linear infinite;
}

body.text-anim-hover.text-fx-gradient .zone-container *,
body.text-anim-hover.text-fx-gradient .nav *,
body.text-anim-hover.text-fx-gradient .footer *,
body.text-anim-hover.text-fx-gradient #info-overlay *,
body.text-anim-hover.text-fx-gradient #preloader * ,
body.text-anim-hover.text-fx-gradient .lightbox-close,
body.text-anim-hover.text-fx-gradient .lightbox-nav {
  background: none;
  -webkit-background-clip: unset;
  -webkit-text-fill-color: unset;
  background-clip: unset;
  animation: none;
}
body.text-anim-hover.text-fx-gradient .zone-container:hover *,
body.text-anim-hover.text-fx-gradient .nav:hover *,
body.text-anim-hover.text-fx-gradient .footer:hover *,
body.text-anim-hover.text-fx-gradient #info-overlay:hover *,
body.text-anim-hover.text-fx-gradient #preloader:hover * ,
body.text-anim-hover.text-fx-gradient .lightbox-close:hover,
body.text-anim-hover.text-fx-gradient .lightbox-nav:hover {
  background: linear-gradient(90deg, var(--text-gradient-1, var(--text-colour)), var(--text-gradient-2, hsl(30, 100%, 70%)), var(--text-gradient-1, var(--text-colour)));
  background-size: 200% auto;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  animation: text-gradient-shift var(--text-gradient-speed, 5s) linear infinite;
}

body.text-anim-hover.text-fx-hue-rotate .zone-container,
body.text-anim-hover.text-fx-hue-rotate .nav,
body.text-anim-hover.text-fx-hue-rotate .footer,
body.text-anim-hover.text-fx-hue-rotate #info-overlay,
body.text-anim-hover.text-fx-hue-rotate #preloader ,
body.text-anim-hover.text-fx-hue-rotate .lightbox-close,
body.text-anim-hover.text-fx-hue-rotate .lightbox-nav {
  animation: none;
  filter: none;
}
body.text-anim-hover.text-fx-hue-rotate .zone-container:hover,
body.text-anim-hover.text-fx-hue-rotate .nav:hover,
body.text-anim-hover.text-fx-hue-rotate .footer:hover,
body.text-anim-hover.text-fx-hue-rotate #info-overlay:hover,
body.text-anim-hover.text-fx-hue-rotate #preloader:hover ,
body.text-anim-hover.text-fx-hue-rotate .lightbox-close:hover,
body.text-anim-hover.text-fx-hue-rotate .lightbox-nav:hover {
  animation: text-hue-rotate var(--text-hue-speed, 6s) linear infinite;
}

/* ── Accessibility: Reduced Motion ───────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  body.bg-gradient-animated {
    animation: none;
  }

  body.text-fx-color-cycle .zone-container,
  body.text-fx-color-cycle .nav,
  body.text-fx-color-cycle .footer,
  body.text-fx-color-cycle #info-overlay,
  body.text-fx-color-cycle #preloader,
  body.text-fx-gradient .zone-container *,
  body.text-fx-gradient .nav *,
  body.text-fx-gradient .footer *,
  body.text-fx-gradient #info-overlay *,
  body.text-fx-gradient #preloader *,
  body.text-fx-hue-rotate .zone-container,
  body.text-fx-hue-rotate .nav,
  body.text-fx-hue-rotate .footer,
  body.text-fx-hue-rotate #info-overlay,
  body.text-fx-hue-rotate #preloader ,
  body.text-fx-hue-rotate .lightbox-close,
  body.text-fx-hue-rotate .lightbox-nav {
    animation: none;
    filter: none;
    -webkit-text-fill-color: unset;
    background-clip: unset;
    -webkit-background-clip: unset;
    background: transparent;
  }
}

/* ── Image Effects System ────────────────────────────────────────────────────── */
/* Toggled by applyImageEffects() in Phase 5; CSS hooks defined here. */

body.fx-desaturated .media-item img,
body.fx-desaturated .media-item video {
  filter: grayscale(1);
  transition: filter 0.4s ease;
}

body.fx-duotone .media-item img,
body.fx-duotone .media-item video {
  filter: url(#duotone-filter);
  transition: filter 0.4s ease;
}

body.fx-blurred .media-item img,
body.fx-blurred .media-item video {
  filter: blur(6px);
  transition: filter 0.4s ease;
}

/* Hover reveal: show full colour on hover / drag */
body.fx-hover-normal.fx-desaturated .media-item:hover img,
body.fx-hover-normal.fx-desaturated .media-item:hover video,
body.fx-hover-normal.fx-desaturated .media-item.is-dragging img,
body.fx-hover-normal.fx-desaturated .media-item.is-dragging video,
body.fx-hover-normal.fx-duotone .media-item:hover img,
body.fx-hover-normal.fx-duotone .media-item:hover video,
body.fx-hover-normal.fx-duotone .media-item.is-dragging img,
body.fx-hover-normal.fx-duotone .media-item.is-dragging video,
body.fx-hover-normal.fx-blurred .media-item:hover img,
body.fx-hover-normal.fx-blurred .media-item:hover video,
body.fx-hover-normal.fx-blurred .media-item.is-dragging img,
body.fx-hover-normal.fx-blurred .media-item.is-dragging video {
  filter: none !important;
}

/* Enlarge scale effects */
body.fx-hover-enlarge .media-item {
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), box-shadow 0.15s ease-out, filter 0.4s ease;
}
body.fx-hover-enlarge .media-item:hover,
body.fx-hover-enlarge .media-item.is-dragging {
  transform: scale(1.02);
}
body.fx-hover-enlarge .media-item.is-dragging {
  transition: transform 0.4s cubic-bezier(0.16, 1, 0.3, 1), filter 0.4s ease; /* preserve scale animation but remove box-shadow delay during drag */
}

/* Legacy hover reveal support */
body.fx-hover-reveal.fx-desaturated .media-item:hover img,
body.fx-hover-reveal.fx-desaturated .media-item:hover video,
body.fx-hover-reveal.fx-duotone .media-item:hover img,
body.fx-hover-reveal.fx-duotone .media-item:hover video {
  filter: none;
}

/* Click-sticky: is-coloured = item shown in full colour */
body[class*="fx-"] .media-item.is-coloured img,
body[class*="fx-"] .media-item.is-coloured video {
  filter: none !important;
}

/* Phase 14: Touch-reveal on mobile (tap to colour) */
body[class*="fx-"] .media-item.is-touch-coloured img,
body[class*="fx-"] .media-item.is-touch-coloured video {
  filter: none;
}

/* Blur others on click */
.media-item.is-blurred img,
.media-item.is-blurred video {
  filter: blur(6px) opacity(0.4);
  transition: filter 0.3s ease;
}

/* Phase 7: Focus on category blur effect */
.media-item.is-focus-blurred img,
.media-item.is-focus-blurred video {
  filter: blur(8px) opacity(0.3);
  transition: filter 0.4s ease;
}

@media (prefers-reduced-motion: reduce) {
  body.fx-desaturated .media-item img,
  body.fx-desaturated .media-item video,
  body.fx-duotone .media-item img,
  body.fx-duotone .media-item video,
  .media-item.is-blurred img,
  .media-item.is-blurred video,
  .media-item.is-focus-blurred img,
  .media-item.is-focus-blurred video {
    transition: none;
  }
  /* Phase 14: also disable canvas-level animated transitions */
  .stage-animating #stage,
  .media-item.is-layouting {
    transition: none !important;
  }
}

/* Brutalist linear transition for layout changes — no easing */
.media-item.is-layouting {
  transition: left 0.4s linear, top 0.4s linear, width 0.4s linear !important;
}

/* =========================================================================
   Mobile Slideshow Mode
   ========================================================================= */

body.is-slideshow #stage-wrapper {
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  cursor: auto;
  -webkit-overflow-scrolling: touch;
}

body.is-slideshow #stage {
  position: relative;
  width: 100%;
  height: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6vh; /* M7: tighter than original 10vh */
  padding: 12vh 5vw calc(20vh + env(safe-area-inset-bottom)); /* M7: extra bottom clears mode-switcher */
  transform: none !important;
  will-change: auto;
}

body.is-slideshow .media-item {
  position: relative !important;
  display: flex !important;
  left: auto !important;
  top: auto !important;
  transform: none !important;
  width: 90vw !important; /* M7: was 94vw — slightly narrower, next item peeks at bottom */
  height: auto !important;
  aspect-ratio: auto !important;
  max-height: 75vh; /* M7: was 80vh */
  scroll-snap-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
  will-change: auto;
  margin-bottom: 0;
}

body.is-slideshow .media-item img,
body.is-slideshow .media-item video {
  width: 100% !important;
  height: auto !important;
  max-height: 75vh !important;
  object-fit: contain;
}

/* M5: Scroll-driven fade-in for slideshow and masonry items ─────────────── */
body.is-slideshow .media-item,
body.is-masonry .media-item {
  opacity: 0;
  transform: translateY(20px) !important;
  transition: opacity 0.5s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.5s cubic-bezier(0.16, 1, 0.3, 1) !important;
}

body.is-slideshow .media-item.slide-visible,
body.is-masonry .media-item.slide-visible {
  opacity: 1;
  transform: translateY(0) !important;
}

@media (prefers-reduced-motion: reduce) {
  body.is-slideshow .media-item,
  body.is-masonry .media-item {
    opacity: 1;
    transform: none !important;
    transition: none !important;
  }
}

/* M6: Scroll progress bar ───────────────────────────────────────────────── */
#mobile-scroll-bar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 0%;
  height: 2px;
  background: currentColor;
  mix-blend-mode: var(--text-blend-mode, normal);
  z-index: 1200;
  pointer-events: none;
  transition: width 0.1s linear;
}

@media (max-width: 768px) {
  body.is-slideshow #mobile-scroll-bar,
  body.is-masonry #mobile-scroll-bar {
    display: block;
  }
}

/* =========================================================================
   M10: Mobile Masonry Strip Mode
   ========================================================================= */

body.is-masonry #stage-wrapper {
  overflow-y: auto;
  overflow-x: hidden;
  cursor: auto;
  -webkit-overflow-scrolling: touch;
}

body.is-masonry #stage {
  position: relative !important;
  width: 100% !important;
  height: auto !important;
  /* CSS column-based masonry — no JS layout engine */
  columns: 2;
  column-gap: 8px;
  padding: 80px 8px calc(60px + env(safe-area-inset-bottom));
  transform: none !important;
  will-change: auto;
  display: block !important; /* override any flex from slideshow */
}

body.is-masonry .media-item {
  position: relative !important;
  display: block !important;
  left: auto !important;
  top: auto !important;
  transform: translateY(20px) !important; /* reset by slide-visible — keep the fade-in above */
  width: 100% !important;
  height: auto !important;
  aspect-ratio: auto !important;
  margin-bottom: 8px;
  break-inside: avoid; /* prevents single item splitting across columns */
  scroll-snap-align: unset;
  will-change: auto;
}

body.is-masonry .media-item img,
body.is-masonry .media-item video {
  width: 100% !important;
  height: auto !important;
  max-height: none !important;
  object-fit: cover;
}
/* ── Mobile Mode Switcher ────────────────────────────────────────────────── */

#mode-switcher {
  position: fixed;
  left: 32px; /* fallback */
  bottom: 16px;
  z-index: 1100;
  mix-blend-mode: var(--text-blend-mode, normal);
  color: inherit;
background: transparent;
  border: none;
  font-family: inherit;
  font-size: var(--ui-text-size, 18px);
  font-weight: 400;
  text-transform: var(--text-transform, uppercase);
  letter-spacing: 0.08em;
  padding: 0;
  cursor: pointer;
  display: none;
  pointer-events: auto;
}

#mode-switcher:hover {
  text-decoration: underline;
}

@media (max-width: 768px) {
  #mode-switcher {
    display: block;
    left: 20px; /* matching .nav padding-left */
    bottom: 16px; /* fallback */
    bottom: calc(16px + env(safe-area-inset-bottom));
  }

  /* Hide layout panel on all mobile modes; hide category panel on canvas mode only */
  body #layout-panel {
    display: none !important;
  }
  /* Category panel stays hidden unless a future option enables it */
  body:not(.is-slideshow):not(.is-masonry) #category-panel {
    display: none !important;
  }
}

/* ── Lightbox Dialog (Phase 6) ────────────────────────────────────────────── */
dialog.lightbox-dialog {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  width: 100vw;
  height: 100vh;
  max-width: 100vw;
  max-height: 100vh;
  outline: none;
  overflow: hidden;
  box-sizing: border-box;
  position: fixed;
  inset: 0;
  z-index: 9999;
}
dialog.lightbox-dialog.backdrop-blur {
  backdrop-filter: blur(12px);
}
.lightbox-overlay {
  position: fixed;
  inset: 0;
  background-color: var(--lightbox-overlay-color, rgba(0, 0, 0, 0.75));
  opacity: 0;
  mix-blend-mode: var(--lightbox-overlay-blend-mode, normal);
  z-index: 9998;
  pointer-events: auto;
  transition: opacity 0.4s ease, display 0.4s allow-discrete;
  transition-behavior: allow-discrete;
  display: none;
}
.lightbox-overlay.is-open {
  display: block;
  opacity: var(--lightbox-overlay-opacity, 0.75);
  @starting-style {
    opacity: 0;
  }
}
.lightbox-content {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
  position: relative;
  z-index: 2;
}
.lightbox-media-container {
  opacity: 0;
  transform: scale(0.92);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.16, 1, 0.3, 1);
  display: flex;
  justify-content: center;
  align-items: center;
  max-width: 90vw;
  max-height: 90vh;
}
.lightbox-image,
.lightbox-video {
  max-width: 90vw;
  max-height: 90vh;
  object-fit: contain;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.lightbox-close {
  position: fixed;
  top: 32px;
  right: 32px;
  background: transparent;
  border: none;
  color: var(--text-colour, #111111);
  mix-blend-mode: var(--text-blend-mode, normal);
  font-family: inherit;
  font-size: 24px;
  cursor: pointer;
  z-index: 9100;
  padding: 0;
  text-transform: var(--text-transform, uppercase);
}
.lightbox-nav {
  position: fixed;
  top: 50%;
  transform: translateY(-50%);
  background: transparent;
  border: none;
  color: var(--text-colour, #111111);
  mix-blend-mode: var(--text-blend-mode, normal);
  font-family: inherit;
  font-size: 32px;
  cursor: pointer;
  z-index: 9100;
  padding: 16px;
  transition: opacity 0.2s ease;
}
.lightbox-prev {
  left: 32px;
}
.lightbox-next {
  right: 32px;
}
.lightbox-nav:hover,
.lightbox-close:hover {
  text-decoration: none !important;
  opacity: 0.8;
}
dialog.lightbox-dialog {
  opacity: 0;
  transition: opacity 0.4s ease, display 0.4s allow-discrete, overlay 0.4s allow-discrete;
  transition-behavior: allow-discrete;
}
dialog.lightbox-dialog[open] {
  opacity: 1;
  transition: opacity 0.4s ease, display 0.4s allow-discrete, overlay 0.4s allow-discrete;
  transition-behavior: allow-discrete;
  @starting-style {
    opacity: 0;
  }
}
dialog.lightbox-dialog[open] .lightbox-media-container {
  opacity: 1;
  transform: scale(1);
}
#stage.stage-animating {
  transition: transform 0.6s cubic-bezier(0.16, 1, 0.3, 1) !important;
}
@media (max-width: 768px) {
  .lightbox-close {
    top: 16px;
    right: 16px;
  }
  .lightbox-nav {
    display: none;
  }
}
@media (prefers-reduced-motion: reduce) {
  dialog.lightbox-dialog {
    transform: none !important;
    transition-duration: 0.1s !important;
  }
  dialog.lightbox-dialog[open] {
    @starting-style {
      transform: none !important;
    }
  }
}


.is-expanded-physical {
  transform: scale(2);
  z-index: 900 !important;
  transition: transform 0.4s ease;
}

/* Infinite grid managed cells — not individually draggable */
.ig-cell {
  cursor: default !important;
  transition: none !important;
  will-change: transform;
}

.ig-cell:hover {
  cursor: pointer !important; /* lightbox/click still works */
}
