:root {
  --bg: #f7f6f3;
  --surface: #ffffff;
  --surface-2: #f1efeb;
  --text: #1d1b20;
  --muted: #6b6670;
  --border: #e5e2dd;
  --accent: #7c3aed;
  --accent-text: #ffffff;
  --danger: #c2253f;
  --p-omg: #d61f4f;
  --p-love: #8b3fd9;
  --p-nice: #0f8a7e;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 4px 16px rgb(0 0 0 / 0.05);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #141316;
    --surface: #1e1c21;
    --surface-2: #27242b;
    --text: #f1eef4;
    --muted: #a39dab;
    --border: #322e37;
    --accent: #b794f6;
    --accent-text: #1a1320;
    --danger: #ff7a8f;
    --p-omg: #ff6f91;
    --p-love: #c69cff;
    --p-nice: #3fd1bf;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #141316;
  --surface: #1e1c21;
  --surface-2: #27242b;
  --text: #f1eef4;
  --muted: #a39dab;
  --border: #322e37;
  --accent: #b794f6;
  --accent-text: #1a1320;
  --danger: #ff7a8f;
  --p-omg: #ff6f91;
  --p-love: #c69cff;
  --p-nice: #3fd1bf;
  --shadow: 0 1px 2px rgb(0 0 0 / 0.3), 0 4px 16px rgb(0 0 0 / 0.25);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 400 16px/1.5 "DM Sans", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }

.site-header, main, .site-footer {
  max-width: 1100px;
  margin: 0 auto;
  padding-inline: 16px;
}

/* Header */
.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 40px;
  padding-bottom: 8px;
}
h1 {
  margin: 0;
  font: 600 clamp(2rem, 5vw, 2.75rem)/1.1 "Fraunces", Georgia, serif;
  letter-spacing: -0.01em;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
}
.icon-button:hover { border-color: var(--muted); }
.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
/* Show the moon in light mode (switch to dark) and the sun in dark mode. */
.icon-sun { display: none; }
:root[data-theme="dark"] .icon-sun { display: block; }
:root[data-theme="dark"] .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: block; }
  :root:not([data-theme="light"]) .icon-moon { display: none; }
}

/* Notice & toolbars */
.notice {
  margin: 20px 0 0;
  padding: 14px 18px;
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
  white-space: pre-line;
}

.admin-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 20px;
}
.admin-bar[hidden] { display: none; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  margin: 28px 0 8px;
  color: var(--muted);
  font-size: 0.9rem;
}
.count { margin: 0; }
.sort { display: flex; align-items: center; gap: 8px; }
.sort select {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

/* Groups & cards */
.group { margin-top: 28px; }
.group h2 {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 14px;
  font-size: 1rem;
  font-weight: 500;
  color: var(--muted);
}
.group h2 .badge { font-size: 0.85rem; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 18px;
}

.card {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover { transform: translateY(-2px); }

.thumb {
  display: block;
  aspect-ratio: 4 / 3;
  background: var(--surface-2);
  overflow: hidden;
}
.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.thumb .placeholder {
  display: grid;
  place-items: center;
  height: 100%;
  font: 600 2.5rem "Fraunces", Georgia, serif;
  color: var(--muted);
  text-transform: uppercase;
}

.card-body {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
  padding: 14px 16px 16px;
}
.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--muted);
}
.site { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card h3 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 500;
  line-height: 1.35;
}
.card h3 a { text-decoration: none; }
.card h3 a:hover { text-decoration: underline; }
.price { margin: 0; font-weight: 700; }
.notes {
  margin: 2px 0 0;
  font-size: 0.9rem;
  color: var(--muted);
  white-space: pre-line;
}
.card-actions {
  display: flex;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
}

.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
  color: var(--c);
  background: color-mix(in srgb, var(--c) 14%, transparent);
}
.p-omg { --c: var(--p-omg); letter-spacing: 0.03em; }
.p-love { --c: var(--p-love); }
.p-nice { --c: var(--p-nice); }
.grouped .card .badge { display: none; }

.empty {
  margin: 48px 0;
  text-align: center;
  color: var(--muted);
}

/* Footer */
.site-footer {
  padding-top: 56px;
  padding-bottom: 32px;
  text-align: center;
}
.link-button {
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.8rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

/* Buttons */
.button {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}
.button:hover { border-color: var(--muted); }
.button.primary {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}
.button.primary:hover { filter: brightness(1.08); }
.button.danger { color: var(--danger); }
.button.small { padding: 4px 10px; font-size: 0.8rem; }
.button:disabled { opacity: 0.6; cursor: wait; }

/* Dialogs */
dialog {
  width: min(480px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 20px 60px rgb(0 0 0 / 0.3);
}
dialog::backdrop { background: rgb(10 8 14 / 0.5); }
dialog h2 { margin: 0 0 16px; font: 600 1.4rem "Fraunces", Georgia, serif; }
dialog form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; }
.field > span, .field legend { font-size: 0.85rem; font-weight: 500; padding: 0; }
.field small { font-weight: 400; color: var(--muted); }
.field input, .field textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--bg);
}
.field input:focus, .field textarea:focus, .sort select:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}
details.field summary { cursor: pointer; font-size: 0.85rem; color: var(--muted); }
details.field[open] summary { margin-bottom: 8px; }

.priority-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.priority-picker label { cursor: pointer; }
.priority-picker input { position: absolute; opacity: 0; pointer-events: none; }
.priority-picker .badge {
  padding: 6px 12px;
  font-size: 0.85rem;
  border: 1.5px solid transparent;
  opacity: 0.55;
}
.priority-picker input:checked + .badge { border-color: var(--c); opacity: 1; }
.priority-picker input:focus-visible + .badge { outline: 2px solid var(--accent); outline-offset: 2px; }

.lookup {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border-radius: 10px;
  background: var(--surface-2);
  font-size: 0.85rem;
  color: var(--muted);
}
.lookup[hidden] { display: none; }
.lookup img { width: 56px; height: 56px; border-radius: 8px; object-fit: cover; flex: none; }
.lookup img:not([src]), .lookup img[src=""] { display: none; }
.lookup p { margin: 0; }

.help { margin: 0; font-size: 0.88rem; color: var(--muted); }
.help ol { margin: 8px 0 0; padding-left: 20px; }
.help li { margin-bottom: 4px; }
.help summary { cursor: pointer; }
.error { margin: 0; font-size: 0.88rem; color: var(--danger); }
.error[hidden] { display: none; }

.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.spacer { flex: 1; }
[hidden] { display: none !important; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--text);
  color: var(--bg);
  font-size: 0.9rem;
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 520px) {
  .site-header { padding-top: 24px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
  .card-body { padding: 10px 12px 12px; }
  .card h3 { font-size: 0.95rem; }
  dialog { padding: 18px; }
}
