:root {
  color-scheme: light;
  --bg: #ffffff;
  --text: #111111;
  --muted: #666666;
  --line: rgba(0, 0, 0, 0.16);
  --panel: rgba(243, 234, 220, 0.9);
  --bar-height: 4.5rem;
  --cell-size: 8.75rem;
}

* {
  box-sizing: border-box;
}

html {
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input {
  font: inherit;
}

button,
a {
  color: inherit;
}

button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.site-nav {
  position: fixed;
  top: 1rem;
  left: 1.25rem;
  z-index: 30;
  display: flex;
  gap: 1rem;
}

.site-nav a,
.details-copy a {
  color: var(--muted);
  text-underline-offset: 0.18em;
}

.site-nav a:hover,
.details-copy a:hover {
  color: var(--text);
}

.demo-shell {
  min-height: 100vh;
  padding: 4rem 1rem calc(var(--bar-height) + 1.5rem);
}

.demo-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  width: min(88rem, 100%);
  margin: 0 auto 1.25rem;
  padding: 0 0.25rem;
}

.demo-header h1,
.shelf-heading h2,
.details-copy h2 {
  margin: 0;
  font-size: 1rem;
  font-weight: 500;
}

.demo-header p,
.shelf-heading p,
.details-copy p {
  margin: 0.2rem 0 0;
  color: var(--muted);
}

.view-label {
  flex: 0 0 auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.loading {
  display: grid;
  min-height: 55vh;
  place-items: center;
  color: var(--muted);
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(var(--cell-size), 42vw), 1fr));
  gap: 3px;
  width: min(88rem, 100%);
  margin: 0 auto;
}

.photo {
  position: relative;
  min-width: 0;
  aspect-ratio: 1;
  overflow: hidden;
  background: var(--soft-strong);
}

.photo-select {
  display: block;
  width: 100%;
  height: 100%;
  padding: 0;
}

.photo img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: filter 140ms ease, transform 180ms ease;
}

.photo-select:hover img {
  transform: scale(1.015);
}

.photo.selected img {
  filter: brightness(0.58);
}

.photo.selected::after {
  content: "✓";
  position: absolute;
  top: 0.55rem;
  left: 0.65rem;
  color: white;
  font-size: 1rem;
  pointer-events: none;
}

.photo-info {
  position: absolute;
  right: 0.35rem;
  bottom: 0.35rem;
  z-index: 2;
  width: 1.8rem;
  height: 1.8rem;
  border-radius: 50%;
  background: rgba(20, 18, 15, 0.66);
  color: white;
  opacity: 0;
  transition: opacity 120ms ease;
}

.photo:hover .photo-info,
.photo:focus-within .photo-info {
  opacity: 1;
}

.action-bar {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(var(--bar-height) + env(safe-area-inset-bottom));
  gap: 1.7rem;
  padding: 0.7rem 1.25rem calc(0.7rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(18px);
}

.action-bar button {
  padding: 0.45rem 0;
}

.action-bar button:hover {
  text-decoration: underline;
  text-underline-offset: 0.2em;
}

.action-count {
  min-width: 3rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.muted-button {
  color: var(--muted);
}

.shelf-view {
  width: min(88rem, 100%);
  margin: 0 auto;
}

.shelf-heading {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 2rem;
  padding: 0.25rem 0.25rem 2.5rem;
}

.tightness {
  display: grid;
  grid-template-columns: auto minmax(7rem, 12rem) auto;
  align-items: center;
  gap: 0.65rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.tightness input {
  accent-color: var(--text);
}

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr));
  gap: 3rem 1.75rem;
}

.pile {
  min-width: 0;
  padding: 0;
  text-align: left;
}

.pile-fan {
  position: relative;
  width: 7.7rem;
  height: 8rem;
  margin: 0 auto 0.65rem;
}

.pile-photo {
  position: absolute;
  top: 0.35rem;
  left: 0.5rem;
  width: 6.6rem;
  height: 7rem;
  border: 3px solid var(--bg);
  border-radius: 2px;
  object-fit: cover;
  box-shadow: 0 0.4rem 1.2rem rgba(0, 0, 0, 0.18);
  transition: transform 160ms ease;
}

.pile-photo:nth-child(1) {
  transform: rotate(-7deg);
}

.pile-photo:nth-child(2) {
  transform: rotate(6deg);
}

.pile-photo:nth-child(3) {
  transform: rotate(-1deg);
}

.pile:hover .pile-photo:nth-child(1) {
  transform: rotate(-10deg) translateX(-0.2rem);
}

.pile:hover .pile-photo:nth-child(2) {
  transform: rotate(9deg) translateX(0.2rem);
}

.pile-name,
.pile-count {
  display: block;
  text-align: center;
}

.pile-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pile-count {
  color: var(--muted);
  font-size: 0.82rem;
}

.pile.custom .pile-name::after {
  content: " · kept";
  color: var(--muted);
}

.shelf-empty {
  grid-column: 1 / -1;
  padding: 4rem 0;
  color: var(--muted);
  text-align: center;
}

.details-dialog {
  width: min(34rem, calc(100vw - 2rem));
  max-height: calc(100vh - 2rem);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 3px;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  box-shadow: 0 2rem 6rem rgba(0, 0, 0, 0.35);
}

.details-dialog::backdrop {
  background: rgba(0, 0, 0, 0.38);
  backdrop-filter: blur(3px);
}

.details-dialog img {
  display: block;
  width: 100%;
  max-height: 60vh;
  object-fit: contain;
  background: var(--soft-strong);
}

.details-copy {
  padding: 1.1rem 1.25rem 1.35rem;
}

.details-copy p {
  overflow-wrap: anywhere;
}

.dialog-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 1;
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  background: rgba(20, 18, 15, 0.66);
  color: white;
  font-size: 1.2rem;
}

@media (max-width: 700px) {
  :root {
    --cell-size: 6.6rem;
  }

  .demo-shell {
    padding-right: 3px;
    padding-left: 3px;
  }

  .demo-header,
  .shelf-heading {
    padding-right: 0.8rem;
    padding-left: 0.8rem;
  }

  .demo-header {
    align-items: start;
  }

  .photo-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .demo-header p {
    max-width: 15rem;
  }

  .shelf-heading {
    align-items: start;
    flex-direction: column;
    gap: 1rem;
  }

  .shelf {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 0 0.8rem;
  }

  .photo-info {
    opacity: 0.72;
  }

  .action-bar {
    justify-content: space-evenly;
    gap: 0.5rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition: none !important;
  }
}
