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;
}

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;
}

.tiles-grid {
  --tile-gap: clamp(12px, 1.5vw, 18px);
  --grid-row-size: clamp(12px, 1vw, 16px);
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  grid-auto-rows: var(--grid-row-size);
  grid-auto-flow: dense;
  align-content: start;
  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 0.24s ease, transform 0.24s 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(18px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.tile {
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  min-width: 0;
  min-height: 0;
  grid-column: span var(--tile-col-span, 4);
  grid-row: span var(--tile-row-span, 24);
  border-radius: 22px;
  box-shadow: 0 22px 55px rgba(0, 0, 0, 0.35);
  position: relative;
  overflow: hidden;
  opacity: 0;
  transform: translateY(18px) scale(0.98);
  transition: transform 0.35s ease, box-shadow 0.35s ease;
  animation: tileReveal 0.9s var(--ease-apple-soft, ease) forwards;
  animation-delay: var(--tile-delay, 0s);
  background: rgba(255, 255, 255, 0.06);
}

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

.tile:hover {
  transform: translateY(-6px);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

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

@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;
  }
}

@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 {
    grid-template-columns: repeat(8, minmax(0, 1fr));
    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 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    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 {
    grid-template-columns: 1fr;
    gap: 10px;
  }

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

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

  .tile img {
    transition: none;
  }

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

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