:root {
  --bg: #faf8f5;
  --ink: #2a2622;
  --ink-soft: #6b6560;
  --line: #e4ddd3;
  --accent: #3a3530;
  --chip-bg: #f0ebe2;
  --chip-active-bg: #2a2622;
  --chip-active-ink: #faf8f5;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  padding-top: env(safe-area-inset-top, 0px);
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  transition: transform 0.2s ease;
  will-change: transform;
}

.toolbar.is-hidden {
  transform: translateY(calc(-100% + env(safe-area-inset-top, 0px)));
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 48px;
  padding: 6px calc(env(safe-area-inset-right, 0px) + 12px) 6px
           calc(env(safe-area-inset-left, 0px) + 12px);
}

.toolbar-row[hidden] {
  display: none;
}

.icon-btn {
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 50%;
  background: var(--chip-bg);
  color: var(--ink);
  cursor: pointer;
}

.quick-chips {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  gap: 6px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  -webkit-mask-image: linear-gradient(to right, #000 calc(100% - 20px), transparent);
  mask-image: linear-gradient(to right, #000 calc(100% - 20px), transparent);
  padding-right: 20px;
}

.quick-chips::-webkit-scrollbar {
  display: none;
}

.quick-chips .chip {
  flex: 0 0 auto;
  padding: 7px 12px;
}

.filter-btn {
  position: relative;
  flex: 0 0 auto;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 0.85rem;
  cursor: pointer;
}

.badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--chip-active-bg);
  color: var(--chip-active-ink);
  font-size: 0.68rem;
  line-height: 18px;
  text-align: center;
}

.badge[hidden] {
  display: none;
}

.text-btn {
  flex: 0 0 auto;
  padding: 8px 4px;
  border: none;
  background: none;
  color: var(--ink);
  font-size: 0.95rem;
  cursor: pointer;
}

.result-count {
  margin: 0;
  padding: 10px 16px 0;
  font-size: 0.78rem;
  color: var(--ink-soft);
}

.search-input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  font-size: 16px;
  color: var(--ink);
  outline: none;
}

.search-input:focus {
  border-color: var(--accent);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  padding: 5px 12px;
  border-radius: 999px;
  background: var(--chip-bg);
  color: var(--ink);
  font-size: 0.8rem;
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.chip.active {
  background: var(--chip-active-bg);
  color: var(--chip-active-ink);
}

.grid {
  --columns: 2;
  --gap: 10px;
  position: relative;
  padding: 6px 12px 40px;
}

@media (min-width: 640px) {
  .grid { --columns: 3; }
}
@media (min-width: 900px) {
  .grid { --columns: 4; }
}
@media (min-width: 1200px) {
  .grid { --columns: 5; }
}

.card {
  position: absolute;
  margin: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
  border: 1px solid var(--line);
  cursor: pointer;
}

.card img {
  width: 100%;
  display: block;
  background: #eee;
}

.card .no-image {
  width: 100%;
  aspect-ratio: 3 / 4;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-soft);
  font-size: 0.75rem;
  background: #f1ece3;
}

.card-info {
  padding: 8px 10px 10px;
}

.card-name {
  font-size: 0.85rem;
  font-weight: 500;
  line-height: 1.3;
  margin: 0 0 4px;
}

.card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  font-size: 0.68rem;
  color: var(--ink-soft);
}

.card-meta .tag {
  background: var(--chip-bg);
  padding: 2px 7px;
  border-radius: 999px;
}

.card.gone {
  opacity: 0.5;
}

.empty {
  text-align: center;
  color: var(--ink-soft);
  padding: 40px 20px;
}

/* Filter sheet */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
}

.sheet[hidden] {
  display: none;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 18, 16, 0.45);
}

.sheet-card {
  position: relative;
  z-index: 1;
  width: 100%;
  max-height: 85%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 18px calc(env(safe-area-inset-bottom, 0px) + 16px);
  background: var(--bg);
  border-radius: 16px 16px 0 0;
}

@media (min-width: 640px) {
  .sheet {
    align-items: center;
    justify-content: center;
  }
  .sheet-card {
    width: 420px;
    border-radius: 16px;
  }
}

.sheet-handle {
  width: 36px;
  height: 5px;
  margin: 0 auto 10px;
  border-radius: 999px;
  background: var(--line);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.sheet-section {
  padding: 14px 0;
  border-bottom: 1px solid var(--line);
}

.sheet-section h3 {
  margin: 0 0 4px;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-soft);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.95rem;
}

.switch-row small {
  display: block;
  margin-top: 2px;
  font-size: 0.75rem;
  color: var(--ink-soft);
}

.primary-btn {
  width: 100%;
  margin-top: 16px;
  padding: 13px;
  border: none;
  border-radius: 12px;
  background: var(--chip-active-bg);
  color: var(--chip-active-ink);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: flex-end;
  padding-top: 12px;
  padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
}

.modal[hidden] {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(20, 18, 16, 0.55);
}

.modal-card {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-height: 100%;
  overflow: hidden;
  background: var(--bg);
  border-radius: 16px 16px 0 0;
}

.modal-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom, 16px);
}

@media (min-width: 640px) {
  .modal {
    align-items: center;
    justify-content: center;
    padding-top: 0;
  }
  .modal-card {
    width: 520px;
    max-height: 85vh;
    border-radius: 16px;
  }
}

.modal-close {
  position: absolute;
  top: 10px;
  right: calc(env(safe-area-inset-right, 0px) + 10px);
  z-index: 3;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(42, 38, 34, 0.12);
  background: rgba(255, 255, 255, 0.94);
  color: var(--ink);
  box-shadow: 0 3px 12px rgba(20, 18, 16, 0.2);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
}

.modal-gallery {
  position: relative;
}

.modal-images {
  display: flex;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
}

.modal-image-hint {
  position: absolute;
  left: 50%;
  bottom: 12px;
  z-index: 2;
  max-width: calc(100% - 24px);
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(20, 18, 16, 0.68);
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.2;
  white-space: nowrap;
  pointer-events: none;
  transform: translateX(-50%);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.modal-image-hint[hidden] {
  display: none;
}

.modal-images img {
  width: 100%;
  flex: 0 0 100%;
  scroll-snap-align: start;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  background: #eee;
}

.modal-body {
  padding: 16px 18px 8px;
}

.modal-body h2 {
  margin: 0 0 8px;
  font-size: 1.1rem;
}

.modal-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}

.modal-tags .tag {
  background: var(--chip-bg);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.75rem;
}

.modal-fields {
  display: grid;
  grid-template-columns: auto 1fr;
  column-gap: 12px;
  row-gap: 6px;
  font-size: 0.85rem;
  margin: 0 0 10px;
}

.modal-fields dt {
  color: var(--ink-soft);
}

.modal-fields dd {
  margin: 0;
}

.modal-notes {
  font-size: 0.85rem;
  color: var(--ink-soft);
  white-space: pre-wrap;
}

.modal-airtable-link {
  display: inline-flex;
  align-items: center;
  margin-top: 14px;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.modal-airtable-link[hidden] {
  display: none;
}
