:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #eceae5;
  --text: #1c1b19;
  --muted: #6b6860;
  --border: #dcd9d2;
  --accent: #b8442b;
  --accent-text: #ffffff;
  --danger: #a3281c;
  --radius: 10px;
  --gutter: clamp(16px, 3vw, 32px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141412;
    --surface: #1e1d1b;
    --surface-2: #2a2926;
    --text: #ebe9e4;
    --muted: #a09c93;
    --border: #35332f;
    --accent: #e8734f;
    --accent-text: #1a0d08;
    --danger: #f08a7c;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* --- top bar --- */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  padding: 16px var(--gutter) 10px;
}

.topbar h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.stats {
  margin: 0;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  flex: 1 1 160px;
}

.topbar input {
  flex: 1 1 220px;
  max-width: 320px;
  min-width: 0;
  padding: 7px 11px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

.add { display: contents; }

/* --- notices --- */

.notice {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  margin: 0 var(--gutter) 10px;
  padding: 10px 14px;
  background: var(--surface-2);
  border-radius: var(--radius);
}

.notice[hidden] { display: none; }
.notice.error { color: var(--danger); }
.notice input { padding: 5px 9px; background: var(--surface); border: 1px solid var(--border); border-radius: 6px; }
.notice button { padding: 5px 12px; background: var(--accent); color: var(--accent-text); border: 0; border-radius: 6px; }

.hint { margin: 0 var(--gutter) 8px; color: var(--muted); font-size: 13px; }

/* --- controls --- */

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
  padding: 4px var(--gutter) 14px;
}

.segmented {
  display: flex;
  max-width: 100%;
  overflow-x: auto;
  padding: 3px;
  background: var(--surface-2);
  border-radius: 9px;
}

.segmented button {
  padding: 4px 11px;
  white-space: nowrap;
  color: var(--muted);
  background: none;
  border: 0;
  border-radius: 7px;
  font-size: 13.5px;
}

.segmented button[aria-pressed="true"] {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 2px rgb(0 0 0 / 0.15);
}

/* --- groups --- */

main { padding: 0 var(--gutter) 48px; }

.group { margin-bottom: 22px; }

.group-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  width: 100%;
  padding: 6px 0;
  text-align: left;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--border);
}

.group-header::before {
  content: "▾";
  width: 12px;
  color: var(--muted);
  font-size: 12px;
}

.group[data-collapsed] .group-header::before { content: "▸"; }
.group[data-collapsed] .cards { display: none; }

.group-name { font-size: 16px; font-weight: 650; }
.group-meta { color: var(--muted); font-size: 13px; font-variant-numeric: tabular-nums; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 16px 14px;
  padding-top: 12px;
}

/* --- card --- */

.card { min-width: 0; }

.thumb {
  position: relative;
  display: block;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: var(--surface-2);
  border-radius: var(--radius);
  text-decoration: none;
}

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

/* Product photos are shot on white; show them whole rather than cropped. */
.thumb img.contain { object-fit: contain; background: #fff; }

.tile {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 12px;
  color: var(--muted);
  font-size: 14px;
  text-align: center;
  overflow-wrap: anywhere;
}

.badge {
  position: absolute;
  right: 6px;
  bottom: 8px;
  padding: 1px 5px;
  color: #fff;
  background: rgb(0 0 0 / 0.78);
  border-radius: 4px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.progress { position: absolute; inset: auto 0 0 0; height: 4px; background: rgb(255 255 255 / 0.3); }
.progress i { display: block; height: 100%; background: var(--accent); }

.title {
  display: -webkit-box;
  margin-top: 7px;
  overflow: hidden;
  color: inherit;
  font-weight: 600;
  line-height: 1.3;
  text-decoration: none;
  overflow-wrap: anywhere;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}

.title:hover { text-decoration: underline; }

.sub {
  margin-top: 2px;
  overflow: hidden;
  color: var(--muted);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-actions { display: flex; align-items: center; gap: 4px; margin-top: 6px; }

.chip {
  min-width: 0;
  max-width: 100%;
  padding: 2px 9px;
  overflow: hidden;
  color: var(--muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 12.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chip:hover { color: var(--text); border-color: var(--muted); }

.spacer { flex: 1; }

.icon {
  flex: none;
  width: 30px;
  height: 28px;
  color: var(--muted);
  background: none;
  border: 1px solid transparent;
  border-radius: 7px;
}

.icon:hover { color: var(--text); background: var(--surface-2); }

.retry { color: var(--danger); border: 0; background: none; padding: 0; font-size: 12.5px; text-decoration: underline; }

.empty { padding: 56px 0; color: var(--muted); text-align: center; }
.empty code { padding: 1px 5px; background: var(--surface-2); border-radius: 4px; }

/* --- theme dialog --- */

dialog {
  width: min(420px, calc(100vw - 32px));
  padding: 20px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
}

dialog::backdrop { background: rgb(0 0 0 / 0.45); }
dialog h2 { margin: 0 0 4px; font-size: 17px; }
.dialog-item { margin: 0 0 12px; color: var(--muted); font-size: 13.5px; overflow-wrap: anywhere; }

dialog input:not([type="radio"]) {
  width: 100%;
  padding: 8px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
}

dialog fieldset { display: grid; gap: 6px; margin: 12px 0 16px; padding: 0; border: 0; }
dialog menu { display: flex; gap: 8px; margin: 0; padding: 0; }
dialog menu button { padding: 6px 13px; border: 1px solid var(--border); border-radius: 8px; background: none; }
dialog menu .primary { color: var(--accent-text); background: var(--accent); border-color: var(--accent); }
dialog menu .quiet { color: var(--muted); }
