: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: 3.25rem;
  --cell-size: 9rem;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 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;
}

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

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

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

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

.demo-shell {
  min-height: 100vh;
  padding: 3.5rem 0 calc(var(--bar-height) + 0.75rem);
}

.demo-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  width: min(100rem, 100%);
  margin: 0 auto 0.75rem;
  padding: 0 1rem;
}

.demo-header > div:first-child {
  display: flex;
  align-items: baseline;
  min-width: 0;
  gap: 0.75rem;
}

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

.demo-header p,
.shelf-heading p,
.details-copy p {
  margin: 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: 1px;
  width: min(100rem, 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 120ms ease, opacity 120ms ease;
}

.photo-select:hover img {
  opacity: 0.92;
}

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

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

.photo-info {
  position: absolute;
  right: 0.2rem;
  bottom: 0.2rem;
  z-index: 2;
  width: 1.5rem;
  height: 1.5rem;
  background: rgba(20, 18, 15, 0.5);
  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.5rem;
  padding: 0.45rem 1rem calc(0.45rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--bg);
}

.action-bar button {
  padding: 0.25rem 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(100rem, 100%);
  margin: 0 auto;
}

.shelf-heading {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  min-height: 2rem;
  padding: 0 1rem 1.25rem;
}

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

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

.shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(7.25rem, 1fr));
  gap: 1rem 0.5rem;
  padding: 0 0.5rem;
}

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

.pile-fan {
  position: relative;
  display: block;
  width: 6.5rem;
  height: calc(6rem + var(--stack-depth, 2px));
  margin: 0 auto;
}

.pile-photo {
  position: absolute;
  top: 0;
  left: 0;
  width: 6rem;
  height: 6rem;
  border: 1px solid var(--bg);
  object-fit: cover;
  transform: translate(var(--layer-x, 0), var(--layer-y, 0));
  z-index: var(--layer-order, 1);
  transition: opacity 120ms ease;
}

.pile:hover .pile-photo:last-child {
  opacity: 0.88;
}

.pile-name {
  display: none;
}

.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);
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

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

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

.details-copy {
  padding: 1rem;
}

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

.dialog-close {
  position: absolute;
  top: 0.65rem;
  right: 0.65rem;
  z-index: 1;
  width: 2rem;
  height: 2rem;
  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-top: 3.25rem;
  }

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

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

  .shelf-heading {
    justify-content: center;
  }

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

  .pile-fan {
    width: 5.6rem;
    height: calc(5.2rem + var(--stack-depth, 2px));
  }

  .pile-photo {
    width: 5.2rem;
    height: 5.2rem;
  }

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