/* Mondrian portfolio grid. Sits under the site header, hero, and footer. */

.page-content.mondrian-portfolio {
  --mondrian-gutter: 8px;
  --mondrian-expand-inset: 6px;
  --mondrian-ground: #fff;
  padding: 0;
  background: var(--mondrian-ground);
}

html.dark-mode .page-content.mondrian-portfolio {
  --mondrian-ground: #1c1c1c;
}

.mondrian-tools {
  --mondrian-tool-size: 32px;
  --mondrian-tool-gap: 8px;
  position: sticky;
  top: var(--nav-height);
  z-index: 40;
  display: flex;
  align-items: flex-start;
  justify-content: flex-end;
  gap: var(--mondrian-tool-gap);
  width: max-content;
  height: 0;
  margin: 0 calc(var(--mondrian-gutter) + var(--mondrian-expand-inset) + var(--mondrian-tool-size) + var(--mondrian-tool-gap)) 0 auto;
  pointer-events: none;
}

.mondrian-tools .tool-btn {
  margin-top: calc(var(--mondrian-gutter) + var(--mondrian-expand-inset));
  pointer-events: auto;
}

.mondrian-stage {
  position: relative;
}

.mondrian-stage #webgpu-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 4;
  mix-blend-mode: overlay;
  opacity: 0.35;
  /* Opt out of the page color-scheme. On a phone the canvas backing is
     otherwise an opaque white square, and the overlay blend washes the
     card colours. Desktop, and a phone asked to show the desktop layout,
     keep a transparent backing, so the same palette stays true. */
  color-scheme: normal;
  background: transparent;
  background-color: transparent;
}

.mondrian-grid {
  display: grid;
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 100%;
  background-color: var(--mondrian-ground);
  gap: var(--mondrian-gutter);
  padding: var(--mondrian-gutter);
  box-sizing: border-box;
  align-items: stretch;
  justify-items: stretch;
}

.mondrian-tile {
  position: relative;
  min-width: 0;
  min-height: 260px;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--mondrian-ground);
  border: 0;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.tile-media,
.shutter-cover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  box-sizing: border-box;
}

.tile-media {
  background: var(--mondrian-ground);
  z-index: 0;
}

.tile-photo {
  position: absolute !important;
  inset: -1px !important;
  width: calc(100% + 2px) !important;
  height: calc(100% + 2px) !important;
  max-width: none !important;
  object-fit: cover;
  object-position: center;
  filter: grayscale(1);
  transition: filter 0.7s ease, transform 0.7s ease;
}

@media (hover: hover) and (pointer: fine) {
  .mondrian-tile:hover .tile-photo {
    filter: none;
    transform: scale(1.05);
  }
}

@media (hover: none) and (min-width: 768px),
       (pointer: coarse) and (min-width: 768px) {
  .tile-photo {
    filter: none;
  }
}

.tile-photo-next {
  opacity: 0;
  transition: filter 0.7s ease, transform 0.7s ease, opacity 0.45s cubic-bezier(0.77, 0, 0.175, 1);
}

@media (hover: hover) and (pointer: fine) {
  .mondrian-tile:hover .tile-photo-next {
    animation: tile-photo-loop 5.6s cubic-bezier(0.77, 0, 0.175, 1) infinite;
  }
}

@keyframes tile-photo-loop {
  0%, 15% { opacity: 0; }
  40%, 65% { opacity: 1; }
  90%, 100% { opacity: 0; }
}

.tile-shade {
  position: absolute;
  inset: 0;
  z-index: 1;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.62) 22%, rgba(0, 0, 0, 0.18) 48%, transparent 70%);
  pointer-events: none;
}

.tile-caption {
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 16px;
  z-index: 2;
  color: #fff;
  pointer-events: none;
}

.tile-caption h3,
.shutter-body h3 {
  margin: 0;
  font-family: "DIN Next LT Arabic", "Inter";
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.tile-caption h3,
.tile-caption p {
  color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.7);
}

.tile-caption h3 {
  font-size: clamp(1.05rem, 1.6vw, 1.35rem);
}

.tile-subtitle,
.shutter-subtitle {
  margin: 6px 0 0;
  line-height: 1.35;
}

.tile-subtitle {
  font-size: 12px;
}

.shutter-subtitle {
  font-size: 13px;
}

.line-clamp-2,
.line-clamp-3 {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.line-clamp-2 {
  -webkit-line-clamp: 2;
}

.line-clamp-3 {
  -webkit-line-clamp: 3;
}

.shutter-cover {
  z-index: 3;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: 20px;
  transition: transform 0.75s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.5s ease;
}

.page-content.mondrian-portfolio.is-shutter-motion .shutter-cover {
  transition: none;
}

.shutter-slide-up { transform: translate3d(0, calc(-100% - 1px), 0); }
.shutter-slide-down { transform: translate3d(0, calc(100% + 1px), 0); }
.shutter-slide-left { transform: translate3d(calc(-100% - 1px), 0, 0); }
.shutter-slide-right { transform: translate3d(calc(100% + 1px), 0, 0); }

.shutter-body h3 {
  font-size: clamp(1.25rem, 2vw, 1.75rem);
}

html.dark-mode .page-content.mondrian-portfolio .tile-caption h3,
html.dark-mode .page-content.mondrian-portfolio .tile-caption p,
html.dark-mode .page-content.mondrian-portfolio .shutter-cover h3,
html.dark-mode .page-content.mondrian-portfolio .shutter-cover p,
html.dark-mode .page-content.mondrian-portfolio .mondrian-lightbox-panel p {
  color: inherit !important;
}

html.dark-mode .page-content.mondrian-portfolio .lightbox-copy h2 {
  color: #f9f9f9 !important;
}

.shutter-mark {
  margin-bottom: 12px;
  border: 4px solid currentColor;
  box-sizing: border-box;
}

.shutter-mark.is-circle {
  width: 40px;
  height: 40px;
  border-radius: 50%;
}

.shutter-mark.is-square {
  width: 40px;
  height: 40px;
}

.shutter-mark.is-triangle {
  width: 40px;
  height: 34.641px;
  border: 0;
  background: none;
  line-height: 0;
}

.shutter-mark.is-triangle svg {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

.shutter-mark.is-bar {
  width: 56px;
  height: 6px;
  border: 0;
  background: currentColor;
}

/* Desktop: expand disc appears only while the pointer is over the card. */
@media (hover: hover) and (pointer: fine) {
  .mondrian-portfolio .img-expand-btn {
    opacity: 0;
  }

  .mondrian-portfolio .img-expand-wrap:hover .img-expand-btn,
  .mondrian-portfolio .img-expand-btn:focus-visible {
    opacity: 1;
  }
}

.tool-btn {
  position: relative;
  width: 32px;
  height: 32px;
  padding: 0;
  margin: 0;
  border: 0;
  outline: none;
  box-shadow: none;
  border-radius: 0;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  display: grid;
  place-items: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.tool-btn:focus,
.tool-btn:focus-visible,
.tool-btn:active {
  outline: none;
  box-shadow: none;
  border: 0;
}

.tool-btn::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 0;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  pointer-events: none;
}

html.dark-mode .tool-btn::before {
  background: rgba(0, 0, 0, 0.6);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

.tool-btn img {
  position: relative;
  z-index: 1;
  width: 22px;
  height: 22px;
  max-width: none;
  object-fit: contain;
  display: block;
  pointer-events: none;
  filter: none;
}

html.dark-mode .tool-btn img {
  filter: invert(1);
}

.audio-slash,
.shutter-slash {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 22px;
  height: 22px;
  transform: translate(-50%, -50%);
  z-index: 2;
  pointer-events: none;
  overflow: visible;
}

.audio-slash line,
.shutter-slash line {
  fill: none;
  stroke: #121212;
  stroke-width: 2.25;
  stroke-linecap: round;
  stroke-dasharray: 26;
  stroke-dashoffset: 26;
  transition: stroke-dashoffset 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

#toggle-audio-btn.is-muted .audio-slash line,
#toggle-shutters-btn.is-off .shutter-slash line {
  stroke-dashoffset: 0;
}

html.dark-mode .audio-slash line,
html.dark-mode .shutter-slash line {
  stroke: #ffffff;
}

.mondrian-lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.8);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.mondrian-lightbox.is-open {
  opacity: 1;
  pointer-events: auto;
}

.mondrian-lightbox-panel {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(896px, 100%);
  max-height: 90vh;
  overflow: hidden;
  background-color: transparent;
  background-clip: padding-box;
  border: 8px solid transparent;
  gap: 4px;
  transform: scale(0.95);
  transition: transform 0.3s ease;
}

.mondrian-lightbox-panel > .img-lightbox-close {
  z-index: 5;
  opacity: 1;
}

.mondrian-lightbox-panel > .img-lightbox-close::before {
  background: rgba(255, 255, 255, 0.6);
  -webkit-backdrop-filter: blur(4px);
  backdrop-filter: blur(4px);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.mondrian-lightbox-panel > .img-lightbox-close img {
  filter: none;
}

html.dark-mode .mondrian-lightbox-panel > .img-lightbox-close::before {
  background: rgba(0, 0, 0, 0.6);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.2);
}

html.dark-mode .mondrian-lightbox-panel > .img-lightbox-close img {
  filter: invert(1);
}

.mondrian-lightbox.is-open .mondrian-lightbox-panel {
  transform: scale(1);
}

.lightbox-media {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 220px;
  overflow: hidden;
  background: #000;
  border: 0;
}

.lightbox-media img {
  width: 100%;
  height: 100%;
  max-width: none;
  object-fit: cover;
}

.lightbox-img-next {
  position: absolute;
  inset: 0;
  opacity: 0;
  animation: tile-photo-loop 5.6s cubic-bezier(0.77, 0, 0.175, 1) infinite;
}

.lightbox-img-next[hidden] {
  display: none;
}

.lightbox-copy {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 24px;
  box-sizing: border-box;
  width: 100%;
  padding: 24px;
  overflow-y: auto;
  background: #ffffff;
  color: #121212;
}

.lightbox-copy h2 {
  margin: 0 0 12px;
  color: #5a5a5a;
  font-size: clamp(1.5rem, 3vw, 2rem);
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.lightbox-copy p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

.lightbox-link {
  display: block;
  width: 100%;
  box-sizing: border-box;
  padding: 12px 18px;
  border: 1px solid #5a5a5a;
  border-radius: 6px;
  background: #ffffff;
  color: #5a5a5a;
  text-align: center;
  text-decoration: none;
  font-family: "DIN Next LT Arabic", "Inter";
  font-size: 16px;
  line-height: 1.2;
}

.lightbox-link-arrow {
  font-family: "Noto Sans", "DejaVu Sans", "Segoe UI", sans-serif;
  font-weight: 400;
  font-synthesis: weight;
}

.lightbox-link:hover,
.lightbox-link:active {
  font-weight: 700;
  opacity: 1;
  background: #ffffff;
  color: #5a5a5a;
  border-color: #5a5a5a;
}

.lightbox-link:hover .lightbox-link-arrow,
.lightbox-link:active .lightbox-link-arrow {
  font-weight: 700;
  -webkit-text-stroke: 0.45px currentColor;
  paint-order: stroke fill;
}

html.dark-mode .mondrian-lightbox-panel {
  background-color: transparent;
  background-clip: padding-box;
  border-color: transparent;
}

html.dark-mode .lightbox-media {
  background-color: #1c1c1c;
}

html.dark-mode .lightbox-copy {
  background: #1c1c1c;
  color: #ffffff;
}

html.dark-mode #lightbox-link {
  border-color: #ffffff;
  background: #1c1c1c;
  color: #ffffff !important;
}

html.dark-mode #lightbox-link:hover,
html.dark-mode #lightbox-link:active {
  font-weight: 700;
  opacity: 1;
  background: #1c1c1c;
  color: #ffffff !important;
  border-color: #ffffff;
}

.lightbox-link[hidden] {
  display: none;
}

@media (min-width: 768px) {
  .mondrian-lightbox {
    padding: 40px;
  }

  .mondrian-lightbox-panel {
    flex-direction: row;
  }

  .lightbox-media {
    width: 60%;
  }

  .lightbox-copy {
    width: 40%;
  }
}

html[dir="rtl"] .mondrian-tools {
  margin-right: auto;
  margin-left: calc(var(--mondrian-gutter) + var(--mondrian-expand-inset) + var(--mondrian-tool-size) + var(--mondrian-tool-gap));
}

html[dir="rtl"] .mondrian-portfolio .img-expand-btn,
html[dir="rtl"] .mondrian-lightbox-panel > .img-lightbox-close {
  left: 6px;
  right: auto;
}

@media (max-width: 767px) {
  .page-content.mondrian-portfolio .tile-photo {
    filter: grayscale(1);
  }

  .page-content.mondrian-portfolio .mondrian-tile:hover .tile-photo,
  .page-content.mondrian-portfolio .mondrian-tile.is-color .tile-photo,
  .page-content.mondrian-portfolio .mondrian-tile:active .tile-photo {
    filter: none;
    transform: scale(1.05);
  }

  .page-content.mondrian-portfolio .mondrian-tile:hover .tile-photo-next,
  .page-content.mondrian-portfolio .mondrian-tile.is-color .tile-photo-next {
    animation: tile-photo-loop 5.6s cubic-bezier(0.77, 0, 0.175, 1) infinite;
  }

  .mondrian-tile {
    min-height: 0;
  }

  .tile-caption {
    left: 10px;
    right: 10px;
    bottom: 10px;
  }

  .tile-caption h3,
  .shutter-body h3 {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    font-size: 15px;
  }

  .tile-subtitle {
    font-size: 11px;
  }

  .shutter-cover {
    padding: 12px;
  }

  .shutter-mark.is-circle,
  .shutter-mark.is-square {
    width: 28px;
    height: 28px;
  }

  .shutter-mark.is-triangle {
    width: 28px;
    height: 24.249px;
  }

  .mondrian-lightbox {
    align-items: stretch;
    padding:
      max(10px, env(safe-area-inset-top))
      max(10px, env(safe-area-inset-right))
      max(10px, env(safe-area-inset-bottom))
      max(10px, env(safe-area-inset-left));
  }

  .mondrian-lightbox-panel {
    width: 100%;
    height: 100%;
    max-height: none;
    border-width: 6px;
  }

  .lightbox-media {
    flex: 0 0 auto;
    height: min(42dvh, 320px);
    min-height: 168px;
  }

  .lightbox-copy {
    flex: 1 1 auto;
    min-height: 0;
    gap: 16px;
    padding: 16px 16px 18px;
    overscroll-behavior: contain;
  }

  .lightbox-copy h2 {
    font-size: 1.35rem;
  }

  .tool-btn,
  .mondrian-portfolio .img-expand-btn,
  .mondrian-lightbox-panel > .img-lightbox-close,
  .lightbox-link {
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
  }
}

@media (prefers-reduced-motion: reduce) {
  .shutter-cover,
  .tile-photo,
  .mondrian-lightbox,
  .mondrian-lightbox-panel,
  .audio-slash line,
  .shutter-slash line {
    transition: none;
  }

  .mondrian-tile:hover .tile-photo-next,
  .mondrian-tile.is-color .tile-photo-next,
  .lightbox-img-next {
    animation: none;
    opacity: 1;
    transition: opacity 0.45s cubic-bezier(0.77, 0, 0.175, 1);
  }
}

.tile-motion,
.lightbox-motion {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.tile-motion {
  z-index: 0;
}

.lightbox-motion {
  z-index: 1;
}

.page-content.mondrian-portfolio.is-gpu-motion .mondrian-tile.is-gpu-photo .tile-photo {
  opacity: 0;
  animation: none;
  transition: none;
  filter: none;
  transform: none;
}

.page-content.mondrian-portfolio.is-gpu-motion .shutter-cover,
.page-content.mondrian-portfolio.is-gpu-motion .mondrian-lightbox,
.page-content.mondrian-portfolio.is-gpu-motion .mondrian-lightbox-panel {
  transition: none;
}

.page-content.mondrian-portfolio.is-gpu-motion .shutter-cover {
  will-change: transform;
}

.page-content.mondrian-portfolio.is-gpu-motion .lightbox-media.is-gpu-loop > img {
  opacity: 0;
}
