:root {
  --bg: #f7f3ec;
  --surface: #fffdf9;
  --surface-2: #f1ebe1;
  --ink: #1d211f;
  --ink-2: #5b605c;
  --ink-3: #8a8e89;
  --line: #e4ddd1;
  --accent: #a8322d;          /* per-occasion, set via [data-occasion] */
  --accent-ink: #fff;
  --accent-soft: #f6e4e1;
  --good: #1e6b4f;
  --good-soft: #e1f0e8;
  --warn: #9a5b00;
  --warn-soft: #fbeed5;
  --radius: 14px;
  --shadow: 0 1px 2px rgb(40 30 20 / 6%), 0 4px 14px rgb(40 30 20 / 6%);
  --serif: ui-serif, 'Iowan Old Style', 'Palatino Linotype', Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: light dark;
}
[data-occasion='christmas'] { --accent: #a8322d; --accent-soft: #f6e4e1; --accent-2: #1e6b4f; }
[data-occasion='birthday']  { --accent: #6a3fd1; --accent-soft: #ece5fb; --accent-2: #d4467e; }
[data-occasion='other']     { --accent: #17707a; --accent-soft: #dff0f1; --accent-2: #c8963e; }

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141615; --surface: #1c1f1d; --surface-2: #252926; --ink: #ecebe6; --ink-2: #b2b5ae; --ink-3: #82867f;
    --line: #313531; --good: #6fcf9f; --good-soft: #1d3329; --warn: #f0b75a; --warn-soft: #3a2e17;
    --shadow: 0 1px 2px rgb(0 0 0 / 30%), 0 4px 14px rgb(0 0 0 / 25%);
  }
  [data-occasion='christmas'] { --accent: #e0625b; --accent-soft: #3b2120; }
  [data-occasion='birthday']  { --accent: #a98bff; --accent-soft: #2c2445; }
  [data-occasion='other']     { --accent: #4fc0c9; --accent-soft: #183236; }
  :root { --accent-ink: #141615; }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.5 var(--sans);
  min-height: 100vh;
}
h1, h2, h3 { font-family: var(--serif); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }
[hidden] { display: none !important; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ── Buttons & inputs ───────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--surface);
  padding: 7px 13px; border-radius: 999px; cursor: pointer; font-weight: 500; font-size: 14px; text-decoration: none;
  white-space: nowrap; transition: background .15s, border-color .15s, transform .05s;
}
.btn:hover { border-color: var(--ink-3); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { color: #c0362c; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.icon-btn { width: 36px; height: 36px; padding: 0; justify-content: center; }

input[type='text'], input[type='url'], input[type='number'], input[type='password'], input[type='date'], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
  outline: none; transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 70px; }
label.field { display: grid; gap: 4px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
label.field > span.hint { font-weight: 400; color: var(--ink-3); }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ── Layout ─────────────────────────────────────────────────────── */
.top {
  position: sticky; top: 0; z-index: 20; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.top-inner { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; gap: 12px; padding: 10px 20px; }
.brand { font-family: var(--serif); font-weight: 700; font-size: 20px; text-decoration: none; display: flex; gap: 8px; align-items: center; }
.tabs { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; padding: 2px; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  border: 1px solid transparent; background: transparent; padding: 6px 12px; border-radius: 999px; cursor: pointer;
  white-space: nowrap; color: var(--ink-2); font-weight: 500;
}
.tab:hover { background: var(--surface-2); }
.tab[aria-selected='true'] { background: var(--surface); border-color: var(--line); color: var(--ink); box-shadow: var(--shadow); }
.tab .count { color: var(--ink-3); font-size: 12px; margin-left: 4px; }

main { max-width: 1180px; margin: 0 auto; padding: 24px 20px 80px; }

.list-head { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 12px 20px; margin-bottom: 18px; }
.list-head h1 { font-size: clamp(26px, 4vw, 36px); line-height: 1.1; }
.list-head .sub { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--ink-2); margin-top: 6px; font-size: 14px; }
.list-head .sub b { color: var(--accent); font-weight: 600; }
.list-head .actions { margin-left: auto; display: flex; gap: 6px; flex-wrap: wrap; }

.add {
  display: flex; gap: 8px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 8px;
  box-shadow: var(--shadow); margin-bottom: 14px;
}
.add input { border: none; box-shadow: none !important; font-size: 16px; background: transparent; }
.add .btn { padding: 9px 18px; }
.add-hint { color: var(--ink-3); font-size: 13px; margin: -6px 4px 18px; }
.add-hint a { color: var(--ink-2); }

.toolbar { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: center; margin-bottom: 16px; color: var(--ink-2); font-size: 14px; }
.toolbar select { width: auto; padding: 5px 30px 5px 10px; border-radius: 999px; font-size: 14px; }
.toolbar .spacer { flex: 1; }

/* ── Item cards ─────────────────────────────────────────────────── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column; box-shadow: var(--shadow); position: relative; transition: transform .15s, box-shadow .15s;
}
.card.clickable { cursor: pointer; }
.card.clickable:hover { transform: translateY(-2px); box-shadow: 0 2px 4px rgb(40 30 20 / 8%), 0 10px 24px rgb(40 30 20 / 10%); }
.card .media {
  aspect-ratio: 4 / 3; background: #fff; display: grid; place-items: center; overflow: hidden; position: relative;
  border-bottom: 1px solid var(--line);
}
.card .media img { width: 100%; height: 100%; object-fit: contain; padding: 14px; }
.ph { font-size: 40px; display: grid; place-items: center; width: 100%; height: 100%; background: var(--surface-2); }
.card .flags { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; gap: 6px; flex-wrap: wrap; pointer-events: none; }
.card.loading .media::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(100deg, transparent 30%, rgb(255 255 255 / 55%) 50%, transparent 70%) var(--surface-2);
  background-size: 200% 100%; animation: shimmer 1.2s infinite linear;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }
.card .body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.card .store { font-size: 12px; color: var(--ink-3); text-transform: uppercase; letter-spacing: .05em; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card h3 { font-size: 16px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .options { font-size: 13px; color: var(--ink-2); }
.price-row { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.price { font-size: 20px; font-weight: 700; letter-spacing: -0.01em; font-variant-numeric: tabular-nums; }
.price.none { font-size: 14px; font-weight: 500; color: var(--ink-3); }
.was { color: var(--ink-3); text-decoration: line-through; font-size: 14px; }
.qty { color: var(--ink-2); font-size: 13px; }
.trend { font-size: 13px; font-weight: 600; }
.trend.down { color: var(--good); }
.trend.up { color: #c0362c; }
.trend.low { color: var(--ink-3); font-weight: 500; }

.badge {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px; font-weight: 700; padding: 3px 8px; border-radius: 999px;
  background: var(--surface); border: 1px solid var(--line); color: var(--ink-2); box-shadow: var(--shadow); line-height: 1.3;
}
.badge.sale { background: #c0362c; border-color: #c0362c; color: #fff; }
.badge.p1 { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.badge.got { background: var(--good); border-color: var(--good); color: #fff; }
.badge.oos { background: var(--warn-soft); color: var(--warn); border-color: transparent; }

.promos { display: flex; flex-direction: column; gap: 4px; margin: 2px 0; padding: 0; list-style: none; }
.promo {
  font-size: 12.5px; line-height: 1.35; background: var(--warn-soft); color: var(--warn); border-radius: 8px; padding: 5px 8px;
  display: flex; gap: 6px; align-items: flex-start;
}
.promo .code {
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-weight: 700; border: 1px dashed currentColor;
  border-radius: 6px; padding: 0 6px; background: transparent; color: inherit; cursor: pointer;
}
.promo.good { background: var(--good-soft); color: var(--good); }
.notes { font-size: 14px; color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.notes::before { content: '“'; }
.notes::after { content: '”'; }
.private { font-size: 13px; color: var(--ink-3); font-style: italic; overflow-wrap: anywhere;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.card .foot { margin-top: auto; padding-top: 8px; display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }
.card .foot .grow { flex: 1; }
.card .fetch-note { font-size: 12px; color: var(--ink-3); }
.claimed-by { font-size: 13px; background: var(--good-soft); color: var(--good); border-radius: 8px; padding: 6px 9px; font-weight: 600; }
.card.received { opacity: .7; }
.card.received:hover { opacity: 1; }

.empty { text-align: center; padding: 56px 20px; color: var(--ink-2); border: 2px dashed var(--line); border-radius: 18px; }
.empty .big { font-size: 46px; }
.empty h2 { margin: 10px 0 6px; color: var(--ink); }

.section-title { margin: 36px 0 14px; font-size: 20px; display: flex; align-items: center; gap: 10px; }
.section-title button { font-family: var(--sans); }

/* ── Dialogs ────────────────────────────────────────────────────── */
dialog {
  border: none; border-radius: 18px; padding: 0; background: var(--surface); color: var(--ink); box-shadow: 0 20px 60px rgb(0 0 0 / 30%);
  width: min(680px, calc(100vw - 24px)); max-height: calc(100vh - 32px);
}
dialog::backdrop { background: rgb(20 18 15 / 45%); backdrop-filter: blur(2px); }
dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 32px); }
.dlg-head { display: flex; align-items: center; gap: 10px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.dlg-head h2 { font-size: 20px; flex: 1; }
.dlg-body { padding: 18px 20px; overflow-y: auto; display: grid; gap: 14px; }
.dlg-foot { display: flex; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); align-items: center; flex-wrap: wrap; }
.dlg-foot .grow { flex: 1; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
.item-top { display: grid; grid-template-columns: 120px 1fr; gap: 16px; align-items: start; }
.item-top .pic { width: 120px; aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--line); background: #fff; overflow: hidden; display: grid; place-items: center; }
.item-top .pic img { width: 100%; height: 100%; object-fit: contain; padding: 8px; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 999px; padding: 3px; gap: 2px; background: var(--surface-2); flex-wrap: wrap; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: inline-block; padding: 5px 12px; border-radius: 999px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }
.detected { display: flex; flex-direction: column; gap: 6px; }
.detected .promo { justify-content: space-between; align-items: center; }
.detected .promo button { border: none; background: none; color: inherit; cursor: pointer; font-size: 16px; line-height: 1; padding: 0 2px; }
.history { font-size: 13px; border-collapse: collapse; width: 100%; }
.history td { padding: 4px 8px 4px 0; border-bottom: 1px solid var(--line); font-variant-numeric: tabular-nums; }
.history td:first-child { color: var(--ink-2); }
details.more > summary { cursor: pointer; color: var(--ink-2); font-weight: 600; font-size: 14px; }
details.more[open] > summary { margin-bottom: 12px; }
.callout { background: var(--surface-2); border-radius: 12px; padding: 12px 14px; font-size: 14px; }
.callout.warn { background: var(--warn-soft); color: var(--warn); }
.bookmarklet {
  display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 999px; background: var(--accent);
  color: var(--accent-ink); font-weight: 700; text-decoration: none; cursor: grab; box-shadow: var(--shadow);
}

/* ── Menu ───────────────────────────────────────────────────────── */
.menu { position: relative; }
.menu-pop {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 10px 30px rgb(0 0 0 / 15%); padding: 6px; min-width: 200px; display: grid; z-index: 30;
}
.menu-pop button, .menu-pop a { text-align: left; border: none; background: none; padding: 8px 10px; border-radius: 8px; cursor: pointer; text-decoration: none; font-size: 14px; }
.menu-pop button:hover, .menu-pop a:hover { background: var(--surface-2); }

/* ── Toast ──────────────────────────────────────────────────────── */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--ink); color: var(--bg);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 100;
  max-width: calc(100vw - 32px); box-shadow: 0 8px 24px rgb(0 0 0 / 25%);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: #b3261e; color: #fff; }

/* ── Auth / small centered pages ────────────────────────────────── */
.center-page { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 20px; box-shadow: var(--shadow); padding: 28px; width: min(420px, 100%); }
.panel h1 { font-size: 28px; margin-bottom: 6px; }
.panel form { display: grid; gap: 14px; margin-top: 18px; }
.error { color: #c0362c; font-size: 14px; min-height: 1em; }

/* ── Share page ─────────────────────────────────────────────────── */
.hero { text-align: center; padding: 44px 20px 28px; }
.hero .emoji { font-size: 42px; }
.hero h1 { font-size: clamp(30px, 5vw, 44px); margin-top: 6px; }
.hero .when { color: var(--accent); font-weight: 700; margin-top: 6px; }
.hero p { color: var(--ink-2); max-width: 560px; margin: 12px auto 0; }
.claim-row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.card.taken .media { filter: grayscale(.8); opacity: .6; }

/* ── Add (bookmarklet) page ─────────────────────────────────────── */
#form.panel { display: grid; gap: 14px; }
.add-page { max-width: 560px; margin: 0 auto; padding: 20px; }
.add-page .preview { display: grid; grid-template-columns: 110px 1fr; gap: 14px; align-items: start; }
.add-page .preview .pic { width: 110px; aspect-ratio: 1; border-radius: 12px; overflow: hidden; background: #fff; border: 1px solid var(--line); display: grid; place-items: center; }
.add-page .preview .pic img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }

@media (max-width: 640px) {
  .top-inner { padding: 8px 12px; gap: 8px; }
  .brand span.word { display: none; }
  main { padding: 16px 12px 80px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
  .card .body { padding: 10px; }
  .card h3 { font-size: 14.5px; }
  .price { font-size: 17px; }
  .list-head .actions { margin-left: 0; }
  .item-top { grid-template-columns: 80px 1fr; }
  .item-top .pic { width: 80px; }
}
