:root {
  --bg: #fbf4ec;
  --paper: #fffaf4;
  --ink: #2e1714;
  --muted: #806c66;
  --line: #ead7cd;
  --accent: #a3202b;
  --accent-dark: #7f151f;
  --accent-soft: #fae4e7;
  --marigold: #d89018;
  --marigold-soft: #fff0c6;
  --blush: #f6d8d8;
  --rose-paper: #fff5f3;
  --shadow: 0 18px 44px rgba(88, 36, 29, 0.18);
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Nunito Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  text-rendering: optimizeLegibility;
}

body.sheet-open,
body.lightbox-open {
  overflow: hidden;
}

button {
  font: inherit;
}

button:focus-visible {
  outline: 3px solid rgba(216, 144, 24, 0.35);
  outline-offset: 2px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 12px 10px;
  background: rgba(255, 250, 244, 0.94);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.brand-block {
  min-width: 0;
}

.app-header h1 {
  margin: 0;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: 24px;
  font-weight: 700;
  line-height: 0.98;
  letter-spacing: 0;
}

.app-header p,
.sidebar-head span,
.sheet-head span {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.header-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  gap: 8px;
}

.pill-button,
.ghost-button,
.text-button,
.icon-button,
.find-button,
.bar-button {
  border: 0;
  cursor: pointer;
}

.pill-button,
.find-button {
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-weight: 750;
  box-shadow: 0 8px 18px rgba(163, 32, 43, 0.22);
}

.pill-button {
  padding: 10px 14px;
}

.ghost-button {
  border: 1px solid rgba(163, 32, 43, 0.24);
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.78);
  color: var(--accent-dark);
  font-weight: 760;
  padding: 9px 12px;
}

.find-top-button {
  display: none;
}

.text-button {
  background: transparent;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 760;
  padding: 7px 0;
}

.text-button:disabled {
  color: #a8afb3;
  cursor: default;
}

.app-shell {
  display: block;
}

.people-sidebar {
  display: none;
}

.gallery-panel {
  min-width: 0;
}

.chip-row {
  display: flex;
  gap: 8px;
  min-height: 44px;
  overflow-x: auto;
  padding: 9px 8px 2px;
  scrollbar-width: none;
}

.chip-row:empty {
  display: none;
}

.chip-row::-webkit-scrollbar {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
  border: 1px solid rgba(216, 144, 24, 0.42);
  border-radius: 999px;
  background: var(--marigold-soft);
  color: #74400a;
  padding: 7px 10px;
  font-size: 13px;
  font-weight: 720;
}

.chip button {
  width: 20px;
  height: 20px;
  border: 0;
  border-radius: 999px;
  background: rgba(216, 144, 24, 0.18);
  color: #74400a;
  cursor: pointer;
}

.photo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  padding: 8px 8px 84px;
}

.photo-card {
  position: relative;
  display: block;
  min-width: 0;
  overflow: hidden;
  border: 0;
  border-radius: 0;
  background: #f0dfd4;
  cursor: pointer;
  aspect-ratio: 3 / 4;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

.photo-card:nth-child(5n + 2),
.photo-card:nth-child(7n + 4) {
  aspect-ratio: 1;
}

.photo-card:nth-child(9n + 3) {
  aspect-ratio: 4 / 5;
}

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

.photo-card.is-loading::before {
  position: absolute;
  inset: 0;
  content: "";
  background: linear-gradient(105deg, #f0dfd4 0%, #fff2e5 42%, #f0dfd4 78%);
  background-size: 220% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
}

.photo-card.is-loaded::before {
  display: none;
}

.photo-card:active img {
  transform: scale(1.02);
}

.download-button,
.select-check {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  border: 0;
  background: rgba(255, 250, 244, 0.92);
  color: var(--ink);
  backdrop-filter: blur(10px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.18);
}

.download-button {
  right: 7px;
  bottom: 7px;
  width: 34px;
  height: 34px;
  border-radius: 999px;
}

.select-check {
  left: 7px;
  top: 7px;
  width: 27px;
  height: 27px;
  border-radius: 8px;
  color: transparent;
}

.photo-card.is-selected .select-check {
  background: var(--accent);
  color: white;
}

.photo-card.is-selected::after {
  position: absolute;
  inset: 0;
  z-index: 1;
  border: 3px solid var(--accent);
  content: "";
  pointer-events: none;
}

body:not(.select-mode) .select-check {
  display: none;
}

body:not(.select-mode) .photo-card.is-selected::after {
  display: none;
}

.find-button {
  position: fixed;
  left: 50%;
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 18;
  transform: translateX(-50%);
  padding: 16px 26px;
  min-width: 264px;
  min-height: 59px;
  font-size: 17px;
  letter-spacing: 0.01em;
  box-shadow: 0 14px 28px rgba(163, 32, 43, 0.26);
  animation: findButtonIntro 560ms ease-out 1, findButtonNudge 1400ms ease-in-out 1 1200ms;
}

.find-button::before {
  content: "";
  position: absolute;
  inset: -10px -14px;
  border-radius: 999px;
  background: rgba(163, 32, 43, 0.12);
  z-index: -1;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 50;
}

.sheet[hidden] {
  display: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(49, 19, 16, 0.36);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  max-height: min(82vh, 720px);
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px 22px 0 0;
  background: var(--paper);
  box-shadow: var(--shadow);
}

.sheet-grabber {
  width: 42px;
  height: 5px;
  flex: 0 0 auto;
  align-self: center;
  margin-top: 8px;
  border-radius: 999px;
  background: #e3b7ad;
}

.sheet-head,
.sidebar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.sheet-head {
  padding-top: 10px;
}

.sheet-head strong,
.sidebar-head strong {
  display: block;
  font-size: 16px;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.94);
  color: var(--ink);
  line-height: 0;
}

.icon-button svg,
.download-button svg {
  display: block;
  width: 18px;
  height: 18px;
}

.download-button svg {
  width: 16px;
  height: 16px;
}

.sheet-tools {
  display: flex;
  justify-content: flex-end;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.people-grid,
.people-list {
  overflow-y: auto;
  padding: 12px;
}

.people-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.person-button {
  position: relative;
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--rose-paper);
  padding: 6px;
  text-align: left;
  cursor: pointer;
  min-height: 66px;
}

.person-button img {
  display: block;
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  border-radius: 10px;
  object-fit: cover;
  object-position: 50% 32%;
  background: #f0dfd4;
}

.person-button.is-selected {
  border-color: var(--accent);
  background: var(--accent-soft);
  box-shadow: 0 0 0 2px rgba(163, 32, 43, 0.14);
}

.person-button.is-selected::after {
  position: absolute;
  left: 42px;
  top: 2px;
  display: grid;
  width: 22px;
  height: 22px;
  place-items: center;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  content: "✓";
  font-size: 13px;
  font-weight: 800;
}

.person-button.is-hidden {
  display: none;
}

@media (max-width: 819px) {
  .people-grid .person-button {
    justify-content: center;
    gap: 0;
  }
}

.sheet-footer {
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 250, 244, 0.96);
}

.sheet-done {
  width: 100%;
  min-height: 46px;
}

.empty-state {
  display: grid;
  min-height: 45vh;
  place-items: center;
  padding: 32px;
  text-align: center;
  color: var(--muted);
}

.empty-state[hidden] {
  display: none;
}

.empty-state strong {
  display: block;
  margin-bottom: 5px;
  color: var(--ink);
}

.download-bar {
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 35;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-radius: 16px;
  background: #4a1b1b;
  color: #fff;
  padding: 10px;
  box-shadow: var(--shadow);
}

.download-bar[hidden] {
  display: none;
}

.download-bar span {
  padding-left: 4px;
  font-size: 13px;
  font-weight: 680;
}

.download-bar div {
  display: flex;
  gap: 8px;
}

.bar-button {
  border-radius: 999px;
  background: #fffaf4;
  color: var(--ink);
  padding: 9px 12px;
  font-weight: 760;
}

.bar-button.secondary {
  background: rgba(255, 240, 198, 0.16);
  color: #fff;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  place-items: center;
  background: rgba(33, 11, 12, 0.94);
  touch-action: none;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: 100vw;
  max-height: 100dvh;
  object-fit: contain;
}

.lightbox-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 10px 10px;
  color: white;
  background: linear-gradient(rgba(33, 11, 12, 0.62), transparent);
}

.lightbox-top strong,
.lightbox-top span {
  display: block;
}

.lightbox-top span {
  margin-top: 2px;
  color: rgba(255, 255, 255, 0.72);
  font-size: 12px;
}

.lightbox-actions {
  display: flex;
  gap: 8px;
}

.nav-button {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: grid;
  place-items: center;
  width: 44px;
  height: 56px;
  transform: translateY(-50%);
  border: 0;
  border-radius: 999px;
  background: rgba(255, 250, 244, 0.16);
  color: white;
  font-size: 42px;
  line-height: 1;
  cursor: pointer;
}

.nav-button.prev {
  left: 8px;
}

.nav-button.next {
  right: 8px;
}

@media (min-width: 820px) {
  .app-header {
    padding: 14px 22px;
  }

  .app-header h1 {
    font-size: 30px;
  }

  .app-shell {
    display: grid;
    grid-template-columns: 300px minmax(0, 1fr);
    min-height: calc(100vh - 69px);
  }

  .people-sidebar {
    position: sticky;
    top: 69px;
    display: flex;
    height: calc(100vh - 69px);
    flex-direction: column;
    border-right: 1px solid var(--line);
    background: #f7e9dd;
  }

  .people-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-content: start;
    gap: 8px;
  }

  .people-list .person-button {
    justify-content: center;
    min-height: 92px;
  }

  .people-list .person-button img {
    width: 72px;
    height: 72px;
  }

  .people-list .person-button.is-selected::after {
    left: calc(50% + 18px);
    top: 8px;
  }

  .gallery-panel {
    min-width: 0;
  }

  .photo-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    padding: 16px 16px 96px;
  }

  .photo-card {
    border-radius: 6px;
  }

  .photo-card:hover img {
    transform: scale(1.025);
  }

  .download-button {
    opacity: 0;
    transition: opacity 140ms ease;
  }

  .photo-card:hover .download-button,
  .photo-card:focus-visible .download-button {
    opacity: 1;
  }

  .find-button,
  .sheet {
    display: none;
  }

  .download-bar {
    left: auto;
    width: 380px;
  }

  .nav-button {
    width: 54px;
    height: 72px;
  }
}

@media (min-width: 1220px) {
  .app-shell {
    grid-template-columns: 330px minmax(0, 1fr);
  }

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

@media (min-width: 1560px) {
  .photo-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }

  .photo-card img,
  .download-button {
    transition: none;
  }

  .photo-card.is-loading::before {
    animation: none;
  }
}

@keyframes shimmer {
  from {
    background-position: 120% 0;
  }

  to {
    background-position: -120% 0;
  }
}

@keyframes findButtonIntro {
  from {
    opacity: 0;
    transform: translateX(-50%) translateY(10px) scale(0.98);
  }

  to {
    opacity: 1;
    transform: translateX(-50%) translateY(0) scale(1);
  }
}

@keyframes findButtonNudge {
  0%,
  100% {
    transform: translateX(-50%) translateY(0) scale(1);
  }

  20% {
    transform: translateX(-50%) translateY(-6px) scale(1.04);
  }

  40% {
    transform: translateX(-50%) translateY(0) scale(1);
  }

  60% {
    transform: translateX(-50%) translateY(-4px) scale(1.025);
  }

  80% {
    transform: translateX(-50%) translateY(0) scale(1);
  }
}
