html,
body {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
}

body {
  background: #0b0b0d;
  color: #f5f5f7;
  font-family: "SF Pro Text", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  position: relative;
}

body.page-tiles {
  overflow-x: hidden;
  /* Per-page signature accent (overridden in tiles-<page>.css) */
  --accent-rgb: 120, 170, 255;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 12, 0.5);
  backdrop-filter: blur(2px);
  z-index: 0;
}

.tiles-page {
  min-height: 100vh;
  min-height: 100dvh;
  width: 100%;
  max-width: 1920px;
  margin: 0 auto;
  padding-top: calc(120px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(50px + env(safe-area-inset-bottom, 0px));
  padding-left: calc(clamp(20px, 4vw, 40px) + env(safe-area-inset-left, 0px));
  padding-right: calc(clamp(20px, 4vw, 40px) + env(safe-area-inset-right, 0px));
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: clamp(18px, 2vw, 24px);
  overflow-x: clip;
}

.tiles-title {
  margin: 0;
  font-size: clamp(38px, 4.8vw, 58px);
  letter-spacing: -0.6px;
  max-width: 18ch;
  line-height: 1.05;
  color: #f5f5f7;
  filter: drop-shadow(0 6px 26px rgba(var(--accent-rgb), 0.26));
  animation: tilesTitleIn 0.85s var(--ease-apple-soft, ease) both;
}

@supports (
    (-webkit-background-clip: text) or (background-clip: text)
  ) {
  .tiles-title {
    background: linear-gradient(180deg, #ffffff 0%, rgba(231, 231, 238, 0.72) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
  }
}

.tiles-title::after {
  content: "";
  display: block;
  margin-top: 14px;
  width: clamp(56px, 7vw, 96px);
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(var(--accent-rgb), 0.95),
    rgba(var(--accent-rgb), 0)
  );
  transform-origin: left center;
  animation: tilesAccentIn 0.9s var(--ease-apple-soft, ease) 0.15s both;
}

@keyframes tilesTitleIn {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes tilesAccentIn {
  from {
    opacity: 0;
    transform: scaleX(0);
  }
  to {
    opacity: 1;
    transform: scaleX(1);
  }
}

.tiles-grid {
  --tile-gap: clamp(12px, 1.5vw, 18px);
  display: flex;
  flex-direction: column;
  gap: var(--tile-gap);
  flex: 1 1 auto;
  min-height: max(420px, calc(100dvh - 220px));
}

.tiles-grid.is-empty {
  display: flex;
  align-items: center;
  justify-content: center;
}

.tiles-status {
  margin: 0;
  padding: 18px 20px;
  border-radius: 20px;
  background: rgba(12, 12, 16, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.08);
  color: rgba(245, 245, 247, 0.82);
  text-align: center;
  max-width: 520px;
}

.tiles-status-error {
  color: #ffd1c6;
}

.tiles-scroll-hint {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(12, 12, 16, 0.78);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(12px);
  color: rgba(245, 245, 247, 0.92);
  cursor: pointer;
  z-index: 8;
  opacity: 1;
  transition: opacity var(--dur-quick, 0.28s) var(--ease-apple, ease),
    transform var(--dur-quick, 0.28s) var(--ease-apple, ease);
}

.tiles-scroll-hint-arrow {
  width: 12px;
  height: 12px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-1px);
  animation: tilesScrollHintFloat 1.7s ease-in-out infinite;
}

.tiles-scroll-hint.is-hidden {
  opacity: 0;
  pointer-events: none;
  transform: translateX(-50%) translateY(10px);
}

@keyframes tilesScrollHintFloat {
  0%,
  100% {
    transform: translateX(-50%) translateY(0);
  }
  50% {
    transform: translateX(-50%) translateY(6px);
  }
}

@keyframes tileReveal {
  from {
    opacity: 0;
    transform: translateY(22px) scale(0.965);
    filter: saturate(0.82);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
    filter: saturate(1);
  }
}

.tile {
  display: block;
  width: var(--tile-width, 100%);
  height: var(--tile-height, auto);
  flex: 0 0 var(--tile-width, 100%);
  margin: 0;
  border-radius: 22px;
  box-shadow: 0 22px 55px rgba(0, 0, 0, 0.38);
  position: relative;
  overflow: hidden;
  isolation: isolate;
  opacity: 0;
  transform: translateY(18px) scale(0.98);
  transition: transform 0.45s var(--ease-apple-soft, ease),
    box-shadow 0.45s var(--ease-apple-soft, ease);
  animation: tileReveal 0.9s var(--ease-apple-soft, ease) forwards;
  animation-delay: var(--tile-delay, 0s);
  background: rgba(255, 255, 255, 0.06);
  cursor: pointer;
}

.tile:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.92);
  outline-offset: 4px;
}

/* Diagonal light-sweep that streaks across the photo on hover. */
.tile::before {
  content: "";
  position: absolute;
  top: -10%;
  bottom: -10%;
  left: -75%;
  width: 55%;
  z-index: 2;
  pointer-events: none;
  opacity: 0;
  transform: skewX(-14deg);
  background: linear-gradient(
    100deg,
    transparent 0%,
    rgba(255, 255, 255, 0.22) 50%,
    transparent 100%
  );
}

/* Glassy edge highlight + always-on top sheen. */
.tile::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  border-radius: inherit;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  background: linear-gradient(
    180deg,
    rgba(255, 255, 255, 0.12),
    rgba(255, 255, 255, 0) 24%
  );
  transition: box-shadow 0.45s var(--ease-apple-soft, ease);
}

@keyframes tileSheen {
  0% {
    left: -75%;
    opacity: 0;
  }
  18% {
    opacity: 1;
  }
  100% {
    left: 130%;
    opacity: 0;
  }
}

.tiles-row {
  display: flex;
  align-items: stretch;
  width: 100%;
  gap: var(--tile-gap);
}

.tile img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.35s var(--ease-apple-soft, ease),
    filter 0.35s var(--ease-apple-soft, ease);
}

.tile:hover {
  transform: translateY(-8px) scale(1.012);
  z-index: 4;
  box-shadow: 0 34px 72px rgba(0, 0, 0, 0.5),
    0 14px 40px -10px rgba(var(--accent-rgb), 0.5);
}

.tile:hover img {
  transform: scale(1.06);
  filter: saturate(1.12) brightness(1.06) contrast(1.03);
}

.tile:hover::after {
  box-shadow: inset 0 0 0 1px rgba(var(--accent-rgb), 0.38);
}

.tile:hover::before {
  animation: tileSheen 0.9s var(--ease-apple-soft, ease);
}

body.gallery-viewer-open {
  overflow: hidden;
}

.gallery-viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: calc(72px + env(safe-area-inset-top, 0px))
    calc(70px + env(safe-area-inset-right, 0px))
    calc(72px + env(safe-area-inset-bottom, 0px))
    calc(70px + env(safe-area-inset-left, 0px));
  background: rgba(5, 5, 7, 0.9);
  backdrop-filter: blur(18px) saturate(0.85);
  -webkit-backdrop-filter: blur(18px) saturate(0.85);
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-exit, 0.34s) var(--ease-apple, ease),
    visibility 0s linear var(--dur-exit, 0.34s);
}

.gallery-viewer[hidden] {
  display: none;
}

.gallery-viewer.is-open {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur-enter, 0.52s) var(--ease-apple, ease);
}

.gallery-viewer-stage {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: inherit;
  touch-action: pan-y;
}

.gallery-viewer-image {
  display: block;
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: clamp(10px, 1.2vw, 18px);
  box-shadow: 0 30px 90px rgba(0, 0, 0, 0.48);
  opacity: 0;
  transform: scale(0.975);
  transition: opacity var(--dur-enter, 0.52s) var(--ease-apple, ease),
    transform var(--dur-enter, 0.52s) var(--ease-apple, ease);
  user-select: none;
  -webkit-user-drag: none;
}

.gallery-viewer.is-open .gallery-viewer-image {
  opacity: 1;
  transform: scale(1);
}

.gallery-viewer-close,
.gallery-viewer-nav {
  position: absolute;
  z-index: 2;
  width: 44px;
  height: 44px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 999px;
  background: rgba(38, 38, 42, 0.68);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.24);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  color: #fff;
  cursor: pointer;
  transition: transform var(--dur-quick, 0.28s) var(--ease-apple, ease),
    background-color var(--dur-quick, 0.28s) ease;
}

.gallery-viewer-close {
  top: calc(18px + env(safe-area-inset-top, 0px));
  right: calc(18px + env(safe-area-inset-right, 0px));
}

.gallery-viewer-close span::before,
.gallery-viewer-close span::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 17px;
  height: 1.5px;
  border-radius: 2px;
  background: currentColor;
}

.gallery-viewer-close span::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.gallery-viewer-close span::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.gallery-viewer-nav {
  top: 50%;
  transform: translateY(-50%);
}

.gallery-viewer-previous {
  left: 16px;
}

.gallery-viewer-next {
  right: 16px;
}

.gallery-viewer-nav span {
  position: absolute;
  top: 50%;
  left: 50%;
  width: 10px;
  height: 10px;
  border-top: 1.5px solid currentColor;
  border-right: 1.5px solid currentColor;
}

.gallery-viewer-previous span {
  transform: translate(-38%, -50%) rotate(-135deg);
}

.gallery-viewer-next span {
  transform: translate(-62%, -50%) rotate(45deg);
}

.gallery-viewer-close:hover,
.gallery-viewer-nav:hover {
  background: rgba(62, 62, 68, 0.82);
}

.gallery-viewer-close:active,
.gallery-viewer-nav:active {
  transform: scale(0.92);
}

.gallery-viewer-nav:active {
  transform: translateY(-50%) scale(0.92);
}

.gallery-viewer-close:focus-visible,
.gallery-viewer-nav:focus-visible {
  outline: 2px solid rgba(255, 255, 255, 0.92);
  outline-offset: 3px;
}

.gallery-viewer-counter {
  position: absolute;
  z-index: 2;
  left: 50%;
  bottom: calc(22px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  margin: 0;
  padding: 7px 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  background: rgba(38, 38, 42, 0.58);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  color: rgba(255, 255, 255, 0.76);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

@media (max-width: 700px) {
  .gallery-viewer {
    padding: calc(68px + env(safe-area-inset-top, 0px))
      calc(12px + env(safe-area-inset-right, 0px))
      calc(68px + env(safe-area-inset-bottom, 0px))
      calc(12px + env(safe-area-inset-left, 0px));
  }

  .gallery-viewer-image {
    border-radius: 12px;
  }

  .gallery-viewer-nav {
    display: none;
  }
}

@media (hover: none) {
  .tile:hover {
    transform: none;
    box-shadow: 0 22px 55px rgba(0, 0, 0, 0.35);
  }

  .tile:hover img {
    transform: none;
    filter: none;
  }

  .tile:hover::before {
    animation: none;
  }

  .tile:hover::after {
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.1);
  }
}

@media (max-height: 720px) {
  .tiles-page {
    padding-top: calc(100px + env(safe-area-inset-top, 0px));
  }

  .tiles-grid {
    min-height: 360px;
  }
}

@media (hover: none), (max-width: 1180px) {
  body.page-tiles {
    background-attachment: scroll;
  }
}

@media (max-width: 900px) {
  .tiles-page {
    padding-top: calc(118px + env(safe-area-inset-top, 0px));
    padding-bottom: calc(60px + env(safe-area-inset-bottom, 0px));
    padding-left: calc(20px + env(safe-area-inset-left, 0px));
    padding-right: calc(20px + env(safe-area-inset-right, 0px));
    gap: 18px;
  }

  .tiles-title {
    font-size: clamp(30px, 6vw, 42px);
  }

  .tiles-grid {
    min-height: 0;
  }

  .tile {
    border-radius: 20px;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.35);
  }
}

@media (max-width: 700px) {
  .tiles-page {
    padding-top: calc(110px + env(safe-area-inset-top, 0px));
  }

  .tiles-grid {
    gap: 12px;
  }

  .tiles-scroll-hint {
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 520px) {
  .tiles-page {
    padding-left: calc(14px + env(safe-area-inset-left, 0px));
    padding-right: calc(14px + env(safe-area-inset-right, 0px));
  }

  .tiles-grid {
    gap: 10px;
  }

  .tile {
    border-radius: 18px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile {
    opacity: 1;
    transform: none;
    animation: none;
  }

  .tile img {
    transition: none;
  }

  .tile:hover::before {
    animation: none;
  }

  .tiles-title,
  .tiles-title::after {
    opacity: 1;
    transform: none;
    animation: none;
  }

  .tiles-scroll-hint {
    animation: none;
  }

  .tiles-scroll-hint-arrow {
    animation: none;
  }
}
