:root {
  --bg: #f7f5f2;
  --surface: #ffffff;
  --text: #1f1d1a;
  --muted: #6b665f;
  --border: #e4dfd8;
  --accent: #1f5f4a;
  --accent-text: #ffffff;
  --sale: #b3261e;
  --chip: #ece8e2;
  --radius: 12px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161514;
    --surface: #211f1d;
    --text: #f1eee9;
    --muted: #a8a29a;
    --border: #36332f;
    --accent: #4fae8c;
    --accent-text: #0d1f18;
    --sale: #ff8a80;
    --chip: #2c2a27;
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  line-height: 1.45;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 0;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

a {
  color: var(--accent);
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 16px;
}

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

.small {
  font-size: 0.875rem;
}

.center {
  text-align: center;
}

/* ---------- header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-top: 12px;
  padding-bottom: 12px;
}

.site-header h1 {
  font-size: 1.25rem;
}

.site-header p {
  margin: 2px 0 0;
  font-size: 0.875rem;
}

.cart-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  font-weight: 600;
  white-space: nowrap;
}

.badge {
  min-width: 1.5em;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-text);
  font-size: 0.8rem;
  text-align: center;
}

/* ---------- page ---------- */

.notice {
  margin: 16px 0 0;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: var(--chip);
}

.perks {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 16px 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.9rem;
  color: var(--muted);
}

.perks strong {
  color: var(--text);
}

/* Stripe's wordmark, in Stripe's brand color (white on dark backgrounds). */
.stripe-logo {
  height: 1.15em;
  width: auto;
  margin-left: 2px;
  vertical-align: -0.28em;
  color: #635bff;
}

@media (prefers-color-scheme: dark) {
  .stripe-logo {
    color: #ffffff;
  }
}

.toolbar {
  display: grid;
  gap: 12px;
  margin: 16px 0;
}

#search {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}

/* Fades and arrows show only when more filters are hidden off the edge, so phone users can tell the row scrolls. */
.chips-wrap {
  position: relative;
  min-width: 0;
}

.chips-wrap::before,
.chips-wrap::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 4px;
  width: 56px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
}

.chips-wrap::before {
  left: 0;
  background: linear-gradient(to right, var(--bg) 30%, transparent);
}

.chips-wrap::after {
  right: 0;
  background: linear-gradient(to left, var(--bg) 30%, transparent);
}

.chips-wrap.can-left::before,
.chips-wrap.can-right::after {
  opacity: 1;
}

.chips-arrow {
  position: absolute;
  top: calc(50% - 2px);
  z-index: 1;
  display: none;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0 0 3px;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  color: var(--text);
  font-size: 1.4rem;
  line-height: 1;
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.15);
  transform: translateY(-50%);
  cursor: pointer;
}

.chips-arrow.left {
  left: 0;
}

.chips-arrow.right {
  right: 0;
}

.chips-wrap.can-left .chips-arrow.left,
.chips-wrap.can-right .chips-arrow.right {
  display: grid;
}

.chip {
  flex: none;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--chip);
  font-size: 0.875rem;
  white-space: nowrap;
}

.chip.active {
  background: var(--accent);
  color: var(--accent-text);
}

/* ---------- grid ---------- */

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 160px), 1fr));
  gap: 12px;
  padding-bottom: 32px;
}

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.card-photo {
  display: block;
  padding: 0;
  border: 0;
  background: var(--chip);
  aspect-ratio: 4 / 3;
}

.photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.placeholder {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 120px;
  background: var(--chip);
  color: var(--muted);
  font-size: 0.875rem;
}

.card-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 6px;
  padding: 12px;
}

.card-body h3 {
  font-size: 1rem;
}

.card-body .primary {
  margin-top: auto;
}

.card-body p {
  margin: 0;
}

.link {
  padding: 0;
  border: 0;
  background: none;
  text-align: left;
  font-weight: inherit;
}

.price-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
}

.price {
  font-size: 1.25rem;
  font-weight: 700;
}

.retail {
  color: var(--muted);
  font-size: 0.875rem;
  text-decoration: line-through;
}

.save {
  color: var(--sale);
  font-size: 0.875rem;
  font-weight: 600;
}

/* ---------- buttons ---------- */

.primary {
  padding: 12px 16px;
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}

.secondary {
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 600;
}

.wide {
  width: 100%;
}

/* ---------- dialogs ---------- */

.dialog {
  width: min(560px, calc(100% - 24px));
  max-height: calc(100% - 24px);
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
}

.dialog::backdrop {
  background: rgb(0 0 0 / 0.55);
}

.dialog-body {
  display: grid;
  gap: 12px;
  padding: 20px;
}

.dialog-body p {
  margin: 0;
}

.close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 1;
  width: 40px;
  height: 40px;
  border: 0;
  border-radius: 999px;
  background: var(--chip);
  font-size: 1.5rem;
  line-height: 1;
}

.detail-photo {
  overflow: hidden;
  margin: -20px -20px 0;
  aspect-ratio: 4 / 3;
  background: var(--chip);
}

.thumbs {
  display: flex;
  gap: 8px;
  overflow-x: auto;
}

.thumb {
  flex: none;
  width: 64px;
  height: 64px;
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--chip);
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.description {
  white-space: pre-line;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.detail-actions .primary {
  flex: 1;
}

.qty {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.qty button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 1.1rem;
}

.qty-value {
  min-width: 2ch;
  text-align: center;
  font-weight: 600;
}

/* ---------- cart ---------- */

.cart-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.cart-line {
  display: grid;
  grid-template-columns: 64px 1fr auto;
  gap: 12px;
  align-items: start;
}

.cart-thumb {
  width: 64px;
  height: 64px;
  overflow: hidden;
  border-radius: 8px;
  background: var(--chip);
}

.cart-thumb .placeholder {
  min-height: 0;
  font-size: 0.6rem;
  text-align: center;
}

.cart-info {
  display: grid;
  gap: 4px;
}

.small-qty button {
  width: 32px;
  height: 32px;
}

.qty .remove {
  width: auto;
  height: auto;
  margin-left: 8px;
  border: 0;
  background: none;
  color: var(--muted);
  text-decoration: underline;
}

.fulfillment {
  display: grid;
  gap: 8px;
  margin: 8px 0 0;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.fulfillment legend {
  padding: 0 4px;
  font-weight: 600;
}

.totals {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px;
  margin: 0;
}

.totals dd {
  margin: 0;
  text-align: right;
}

.totals .total {
  font-size: 1.1rem;
  font-weight: 700;
}

.error {
  color: var(--sale);
  font-weight: 600;
}

/* ---------- footer ---------- */

.site-footer {
  padding: 24px 0 40px;
  border-top: 1px solid var(--border);
  font-size: 0.875rem;
}

.site-footer p {
  margin: 4px 0;
}

@media (min-width: 720px) {
  .grid {
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
  }
}

@media (max-width: 420px) {
  .card-body {
    padding: 10px;
  }

  .card-body h3 {
    font-size: 0.95rem;
  }

  .price {
    font-size: 1.1rem;
  }

  .card-body .primary {
    padding: 10px 8px;
  }
}

#cart-footer:not([hidden]) {
  display: grid;
  gap: 12px;
}

/* ---------- success page ---------- */

.success {
  max-width: 560px;
  margin: 48px auto;
  padding: 28px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  text-align: center;
}

.success h1 {
  margin-bottom: 12px;
}

.success .primary {
  display: inline-block;
  margin-top: 16px;
  text-decoration: none;
}

/* ---------- delivery address and date ---------- */

.delivery-details:not([hidden]) {
  display: grid;
  gap: 10px;
  margin-top: 4px;
  padding: 12px;
  border-radius: 10px;
  background: var(--bg);
}

.field {
  display: grid;
  gap: 4px;
  font-size: 0.875rem;
  font-weight: 600;
}

.field input,
.field select {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 400;
}

.field-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 7.5rem;
  gap: 10px;
}

.delivery-status {
  margin: 0;
  color: var(--muted);
}

.delivery-status.ok {
  color: var(--accent);
  font-weight: 600;
}

.delivery-status.bad {
  color: var(--sale);
  font-weight: 600;
}

/* ---------- condition badge and product link ---------- */

.card-photo {
  position: relative;
}

.condition-badge {
  justify-self: start;
  width: fit-content;
  padding: 3px 10px;
  border-radius: 999px;
  background: var(--chip);
  color: var(--text);
  font-size: 0.75rem;
  font-weight: 700;
}

.condition-badge.new {
  background: var(--accent);
  color: var(--accent-text);
}

.card-photo .condition-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  box-shadow: 0 1px 3px rgb(0 0 0 / 0.2);
}

.product-link {
  justify-self: start;
  font-weight: 600;
}
