.tiles-page {
  min-height: 100vh;
  min-height: 100dvh;
  height: auto;
}

.tiles-header {
  position: sticky;
  top: 0;
  z-index: 20;
  height: clamp(80px, 9vw, 104px);
  background: var(--bg);
}

.tiles-header .corner-mark,
.tiles-header .back-link {
  position: absolute;
}

.tiles-page main {
  padding: 8px clamp(20px, 4vw, 64px) max(96px, 5vw);
}

.tile-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: clamp(6px, 0.8vw, 12px);
  width: min(100%, 1120px);
  margin: 0 auto;
  list-style: none;
}

.tile-cell {
  min-width: 0;
  aspect-ratio: 1;
}

.tile {
  --tilt-x: 0deg;
  --tilt-y: 0deg;
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: #e2e2e2;
  box-shadow: inset 0 3px 10px rgb(0 0 0 / 18%);
  perspective: 700px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
}

.tile-face {
  display: block;
  position: relative;
  width: 100%;
  height: 100%;
  transform: translateZ(0) rotateX(0deg) rotateY(0deg);
  box-shadow: 0 2px 5px rgb(0 0 0 / 8%);
  transition: transform 360ms var(--ease), box-shadow 360ms var(--ease);
  pointer-events: none;
}

.tile-face img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile-face::after {
  content: '';
  position: absolute;
  inset: 0;
  box-shadow: inset 0 4px 14px rgb(0 0 0 / 13%);
  opacity: 0;
  transition: opacity 360ms var(--ease);
}

@media (hover: hover) and (pointer: fine) {
  .tile:hover .tile-face {
    transform: translateZ(-24px) rotateX(var(--tilt-x)) rotateY(var(--tilt-y));
    box-shadow: 0 0 0 rgb(0 0 0 / 0%);
  }

  .tile:hover .tile-face::after {
    opacity: 1;
  }
}

.tile:focus-visible {
  z-index: 1;
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.tile:focus-visible .tile-face {
  transform: translateZ(-24px);
  box-shadow: none;
}

.tile:active .tile-face,
.tile.is-playing .tile-face {
  transform: translateZ(-38px) rotateX(var(--tilt-x)) rotateY(var(--tilt-y));
  transition-duration: 120ms;
  box-shadow: none;
}

.tile:active .tile-face::after,
.tile.is-playing .tile-face::after,
.tile:focus-visible .tile-face::after {
  opacity: 1;
}

.piano-credit,
.piano-status {
  width: min(100%, 1120px);
  margin: 20px auto 0;
  font-size: 11px;
  color: var(--mid);
}

.piano-credit a:hover {
  color: var(--ink);
}

.midi-record {
  position: fixed;
  right: clamp(20px, 4vw, 40px);
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 30;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 84px;
  min-height: 40px;
  padding: 10px 12px;
  border: 1px solid var(--hairline);
  border-radius: 0;
  background: var(--bg);
  color: var(--ink);
  font-size: 11px;
  cursor: pointer;
}

.midi-record::before {
  content: '';
  width: 7px;
  height: 7px;
  border: 1px solid currentColor;
  border-radius: 50%;
}

.midi-record.is-recording::before {
  border-color: #cf3232;
  border-radius: 0;
  background: #cf3232;
}

.midi-record:hover {
  border-color: var(--mid);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.secret-menu {
  width: min(320px, calc(100vw - 40px));
  margin: auto;
  padding: 56px 24px;
  border: 1px solid var(--hairline);
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 12px 64px rgb(0 0 0 / 12%);
  font: inherit;
  text-align: center;
}

.secret-menu::backdrop {
  background: rgb(0 0 0 / 20%);
  backdrop-filter: blur(2px);
}

.secret-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 32px;
  height: 32px;
  border: 0;
  background: transparent;
  color: var(--mid);
  font: inherit;
  font-size: 24px;
  cursor: pointer;
}

.secret-close:hover {
  color: var(--ink);
}

@media (max-width: 600px) {
  .tile-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  .tile .tile-face,
  .tile:hover .tile-face,
  .tile:focus-visible .tile-face,
  .tile.is-playing .tile-face,
  .tile:active .tile-face {
    transform: none;
    transition: none;
  }

  .tile-face::after {
    transition: none;
  }
}
