/* Gift List — quiet, warm-neutral product UI.
   One accent (pine) for actions, selection and state; everything else is neutral.
   Light and dark follow the device setting (prefers-color-scheme). */

:root {
  color-scheme: light dark;

  --page: #faf8f5;          /* content surface */
  --rail: #f3f0eb;          /* second neutral layer: sidebar, chips */
  --field: #ffffff;         /* inputs, cards */
  --ink: #23221f;
  --ink-2: #5f5a52;         /* secondary text, 6.3:1 on --page */
  --ink-3: #736d64;         /* placeholders / meta, 4.8:1 on --page */
  --line: #e6e1d9;
  --line-strong: #d6d0c6;
  --line-hover: #c4bdb1;
  --hover: #ece8e1;

  --accent: #2f5d4a;
  --accent-hover: #24493a;
  --on-accent: #ffffff;
  --accent-ink: #24493a;    /* accent-coloured text on --accent-tint */
  --accent-tint: #e4ece7;
  --amber-ink: #6e4c12;
  --amber-tint: #f4ebda;
  --danger: #a3322a;
  --danger-tint: #f6e4e1;

  --img-bg: #ffffff;        /* product photos are shot on white */
  --img-filter: none;
  --shadow: 0 4px 16px rgb(35 34 31 / 0.14);
  /* avatar = tinted disc + same-hue initials */
  --av-l: 93%;  --av-c: 0.035; --av-ink-l: 42%; --av-ink-c: 0.09;

  --r-sm: 6px;
  --r: 8px;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, sans-serif;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --ease: cubic-bezier(0.25, 1, 0.5, 1);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    /* Warm charcoal, not black: same hue family as the light theme. */
    --page: #1c1b19;
    --rail: #232220;
    --field: #2a2826;
    --ink: #ece8e1;
    --ink-2: #bdb6ab;       /* 9.6:1 on --page */
    --ink-3: #9d968b;       /* 6.3:1 on --page */
    --line: #35332f;
    --line-strong: #47443f;
    --line-hover: #5a5650;
    --hover: #302e2b;

    --accent: #8cc2a7;
    --accent-hover: #a3d0b9;
    --on-accent: #10241b;
    --accent-ink: #a9d6bf;
    --accent-tint: #223a2f;
    --amber-ink: #e6c48d;
    --amber-tint: #3b301d;
    --danger: #e8928a;
    --danger-tint: #3e2421;

    --img-bg: #f2efea;
    --img-filter: brightness(0.92);
    --shadow: 0 4px 16px rgb(0 0 0 / 0.4);
    --av-l: 33%;  --av-c: 0.045; --av-ink-l: 86%; --av-ink-c: 0.07;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  height: 100dvh;
  font: 15px/1.5 var(--sans);
  color: var(--ink);
  background: var(--page);
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  caret-color: var(--accent);
  accent-color: var(--accent);
}
::selection { background: var(--accent-tint); color: var(--accent-ink); }
button, input, textarea, select { font: inherit; color: inherit; }
button { touch-action: manipulation; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: var(--r-sm); }
svg.i { width: 16px; height: 16px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 24px;
  padding: calc(12px + var(--safe-t)) calc(24px + var(--safe-r)) 12px calc(24px + var(--safe-l));
  border-bottom: 1px solid var(--line);
  background: var(--page);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark { color: var(--accent); display: grid; }
.brand-mark svg.i { width: 22px; height: 22px; }
.brand h1 { font: 600 19px/1.2 var(--serif); margin: 0; letter-spacing: -0.01em; }
.countdown { margin: 0; font-size: 13px; color: var(--ink-3); }
.stats { display: flex; flex-wrap: wrap; gap: 4px 28px; font-size: 13px; color: var(--ink-2); }
.stat { display: flex; align-items: baseline; gap: 6px; }
.stat b { font-weight: 600; color: var(--ink); font-variant-numeric: tabular-nums; font-size: 15px; }

/* ---------- layout ---------- */
.layout { flex: 1; display: grid; grid-template-columns: 280px 1fr; min-height: 0; }
.sidebar { background: var(--rail); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { display: grid; gap: 8px; padding: 16px 12px 8px; }
.search { position: relative; }
.search svg.i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); pointer-events: none; }
.search input[type="search"] { padding-left: 32px; }
.new-person { display: flex; gap: 6px; padding: 0 12px 8px; }
.new-person[hidden] { display: none; }
.new-person input { flex: 1; min-width: 0; }

.people { list-style: none; margin: 0; padding: 4px 8px 16px; overflow-y: auto; flex: 1; }
.people li + li { margin-top: 1px; }
.people li button {
  width: 100%; display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  border: 0; background: none; border-radius: var(--r); cursor: pointer; text-align: left;
  transition: background-color 150ms var(--ease);
}
.people li button:hover { background: var(--hover); }
.people li button[aria-current="true"] { background: var(--field); box-shadow: 0 0 0 1px var(--line); }
.people .meta { flex: 1; min-width: 0; }
.people .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.people .sub { font-size: 13px; color: var(--ink-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.people .empty { padding: 16px 10px; color: var(--ink-3); font-size: 14px; }

.avatar {
  --av-h: 155;
  flex: none; width: 32px; height: 32px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 600; font-size: 13px;
  background: oklch(var(--av-l) var(--av-c) var(--av-h));
  color: oklch(var(--av-ink-l) var(--av-ink-c) var(--av-h));
}
.avatar.lg { width: 48px; height: 48px; font-size: 18px; }

.dot { width: 7px; height: 7px; border-radius: 50%; flex: none; background: var(--line-strong); }
.dot.done { background: var(--accent); }

.detail { overflow-y: auto; }
.detail-inner { max-width: 1080px; padding: 32px 40px 80px; }
.btn.back { display: none; }

/* ---------- controls ---------- */
input[type="text"], input[type="search"], input[type="url"], textarea, select {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line-strong); border-radius: var(--r-sm);
  background: var(--field); transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:hover, textarea:hover, select:hover { border-color: var(--line-hover); }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
textarea { resize: vertical; min-height: 64px; }
label.field, .field { display: block; }
.field-label { display: block; font-size: 13px; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line-strong); background: var(--field); padding: 7px 12px; border-radius: var(--r-sm);
  cursor: pointer; font-weight: 500; white-space: nowrap; line-height: 1.4;
  transition: background-color 150ms var(--ease), border-color 150ms var(--ease), color 150ms var(--ease);
}
.btn:hover { background: var(--hover); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: default; transform: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-ghost { border-color: transparent; background: none; color: var(--ink-2); }
.btn-ghost:hover { background: var(--hover); color: var(--ink); }
.btn-danger:hover { color: var(--danger); background: var(--danger-tint); }
.btn-icon { padding: 6px; }
.btn-block { width: 100%; }

/* ---------- person detail ---------- */
.person-head { display: flex; align-items: center; gap: 14px; margin-bottom: 36px; }
.person-head .grow { flex: 1; min-width: 0; }
.name-input {
  display: block; width: 100%; font: 600 26px/1.25 var(--serif); letter-spacing: -0.01em;
  border: 1px solid transparent; border-radius: var(--r-sm); background: transparent; padding: 0 6px; margin-left: -7px;
}
.name-input:hover { border-color: var(--line); }
.name-input:focus { border-color: var(--accent); background: var(--field); }
.saved { font-size: 13px; color: var(--ink-3); min-width: 56px; text-align: right; }

.section { padding-top: 28px; margin-top: 28px; border-top: 1px solid var(--line); }
.section:first-of-type { margin-top: 0; }
.section-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 16px; }
.section h2 { font-size: 16px; font-weight: 600; margin: 0; }
.section .count { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px 20px; }
.grid-3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 12px; }
.stack { display: grid; gap: 18px; }

.chips { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 5px 6px; min-height: 40px; border: 1px solid var(--line-strong); border-radius: var(--r-sm); background: var(--field); cursor: text; transition: border-color 150ms var(--ease), box-shadow 150ms var(--ease); }
.chips:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-tint); }
.chip { display: inline-flex; align-items: center; gap: 2px; background: var(--rail); border: 1px solid var(--line); padding: 2px 4px 2px 10px; border-radius: 999px; font-size: 14px; }
.chip button { position: relative; display: grid; place-items: center; border: 0; background: none; cursor: pointer; padding: 3px; border-radius: 50%; color: var(--ink-3); }
.chip button:hover { color: var(--ink); background: var(--hover); }
.chip svg.i { width: 12px; height: 12px; stroke-width: 2; }
.chips input { flex: 1; min-width: 160px; border: 0; padding: 4px; outline: none; box-shadow: none; background: transparent; }
.chips input:focus { box-shadow: none; }

.budget-bar { height: 4px; border-radius: 99px; background: var(--line); overflow: hidden; margin-top: 10px; }
.budget-bar > div { height: 100%; background: var(--accent); transition: width 250ms var(--ease); }
.budget-bar.over > div { background: var(--danger); }
.budget-note { font-size: 13px; color: var(--ink-3); margin-top: 6px; font-variant-numeric: tabular-nums; }
.budget-note.over { color: var(--danger); }

/* ---------- add link ---------- */
.add-link { display: flex; gap: 8px; }
.add-link input { flex: 1; min-width: 0; }
.preview { margin-top: 16px; display: grid; grid-template-columns: 132px 1fr; gap: 20px; padding: 16px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--field); }
.preview .thumb { width: 132px; height: 132px; }
.preview-actions { display: flex; gap: 8px; justify-content: flex-end; }
.hint { font-size: 14px; color: var(--ink-3); margin: 12px 0 0; }
.notice { margin: 0; font-size: 14px; color: var(--amber-ink); background: var(--amber-tint); padding: 8px 12px; border-radius: var(--r-sm); }

/* ---------- gift cards ---------- */
.gifts { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-top: 20px; }
.gift { background: var(--field); border: 1px solid var(--line); border-radius: var(--r); overflow: hidden; display: flex; flex-direction: column; transition: border-color 150ms var(--ease); }
.gift:hover { border-color: var(--line-strong); }
.gift .thumb { width: 100%; aspect-ratio: 4 / 3; border: 0; border-radius: 0; border-bottom: 1px solid var(--line); }
.gift-body { padding: 12px 14px 4px; display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 0; }
.gift-site { font-size: 12.5px; color: var(--ink-3); }
.gift-title { font-weight: 500; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; text-wrap: pretty; }
.gift-title a { color: inherit; text-decoration: none; }
.gift-title a:hover { text-decoration: underline; text-underline-offset: 3px; text-decoration-color: var(--line-strong); }
.gift-price { font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.gift-notes { font-size: 13.5px; color: var(--ink-2); white-space: pre-wrap; }
.gift-foot { display: flex; gap: 4px; align-items: center; padding: 6px 8px 10px 14px; }

.gift-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-width: 0; min-height: 22px; }
.gift-meta .gift-site { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { flex: none; font-size: 12px; font-weight: 500; line-height: 1.5; padding: 1px 8px; border-radius: 999px; background: var(--rail); color: var(--ink-2); }
.badge.s-bought { background: var(--amber-tint); color: var(--amber-ink); }
.badge.s-wrapped, .badge.s-given { background: var(--accent-tint); color: var(--accent-ink); }

.btn-step { flex: 1; min-width: 0; background: var(--accent-tint); border-color: transparent; color: var(--accent-ink); }
.btn-step:hover { background: color-mix(in srgb, var(--accent-tint), var(--accent) 14%); }
.step-done { flex: 1; display: flex; align-items: center; gap: 6px; padding-left: 2px; font-size: 14px; font-weight: 500; color: var(--accent-ink); }

/* action menu (popover, top layer) */
.menu {
  position: fixed; inset: auto; margin: 0; min-width: 210px; padding: 4px;
  background: var(--field); color: var(--ink); border: 1px solid var(--line-strong); border-radius: var(--r);
  box-shadow: var(--shadow);
}
.menu:popover-open { animation: menu-in 140ms var(--ease); }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } }
.menu-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 10px;
  border: 0; border-radius: var(--r-sm); background: none; cursor: pointer; text-align: left; font-size: 14px;
}
.menu-item:hover, .menu-item:focus-visible { background: var(--hover); outline: none; }
.menu-item:disabled { cursor: default; background: none; color: var(--ink-2); font-weight: 500; }
.menu-item.danger { color: var(--danger); }
.menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--danger-tint); }
.menu-label { flex: 1; }
.menu-gap { width: 16px; flex: none; }
.menu-item svg.i:last-child:not(:first-child) { color: var(--accent); }
.menu-heading { padding: 8px 10px 4px; font-size: 12px; font-weight: 500; color: var(--ink-3); }
.menu-sep { height: 1px; margin: 4px 0; background: var(--line); }

.thumb { background: var(--rail); border: 1px solid var(--line); border-radius: var(--r-sm); display: grid; place-items: center; overflow: hidden; color: var(--line-strong); }
.thumb svg.i { width: 36px; height: 36px; stroke-width: 1.25; }
.thumb img { width: 100%; height: 100%; object-fit: contain; background: var(--img-bg); filter: var(--img-filter); }

/* ---------- empty state ---------- */
.empty-state { max-width: 420px; padding: 96px 40px; }
.empty-state .mark { color: var(--accent); margin-bottom: 16px; }
.empty-state .mark svg.i { width: 32px; height: 32px; stroke-width: 1.5; }
.empty-state h2 { font: 600 22px/1.3 var(--serif); margin: 0 0 8px; text-wrap: balance; }
.empty-state p { color: var(--ink-2); margin: 0 0 20px; }

.spinner { display: inline-block; width: 13px; height: 13px; border: 1.75px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.toast {
  position: fixed; bottom: calc(20px + var(--safe-b)); left: 50%; transform: translate(-50%, 8px);
  max-width: calc(100vw - 32px); background: var(--ink); color: var(--page);
  padding: 9px 14px; border-radius: var(--r); opacity: 0; pointer-events: none;
  transition: opacity 200ms var(--ease), transform 200ms var(--ease); font-size: 14px; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- accounts, lists, sharing ---------- */
[hidden] { display: none !important; }
body.no-lists .layout { grid-template-columns: 1fr; }
body.no-lists .sidebar { display: none; }
body.no-lists main.detail { display: block; } /* also on phones, where the list screen hides it */
body.no-lists .topbar .stats { visibility: hidden; }
.stats { margin-left: auto; }
.account-btn { max-width: 200px; }
.account-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.signed-out .topbar .stats, body.signed-out .topbar .account, body.signed-out .layout { display: none; }

.list-bar { display: flex; align-items: center; gap: 6px; padding: 14px 8px 0 12px; }
.list-title { flex: 1; min-width: 0; display: grid; gap: 1px; }
.list-name { font: 600 16px/1.3 var(--serif); padding: 4px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-picker { font: 600 16px/1.3 var(--serif); padding: 4px 6px; margin-left: -7px; border-color: transparent; background: transparent; width: calc(100% + 7px); }
.list-picker:hover { border-color: var(--line-strong); }
.list-role { font-size: 12px; color: var(--ink-3); }

.field-help { display: block; margin-top: 6px; font-size: 13px; color: var(--ink-3); text-wrap: pretty; }
.readonly-note { display: flex; align-items: center; gap: 8px; margin: -8px 0 0; font-size: 14px; color: var(--ink-2); }
input[readonly], textarea[readonly] { background: transparent; border-color: var(--line); }
input[readonly]:focus, textarea[readonly]:focus { box-shadow: none; border-color: var(--line-strong); }
.name-input[readonly] { border-color: transparent; }
.chips.readonly { background: transparent; border-color: var(--line); cursor: default; }
.chips-empty { padding: 3px 6px; font-size: 14px; color: var(--ink-3); }
.first-list { display: flex; gap: 8px; }

.claim, .claim-btn { display: inline-flex; align-items: center; gap: 6px; margin-top: 4px; font-size: 13px; color: var(--ink-2); }
.claim.mine { color: var(--accent-ink); }
.gift-body:last-child { padding-bottom: 14px; }
.claim-btn { align-self: flex-start; padding: 3px 8px 3px 6px; margin-left: -6px; border: 1px dashed var(--line-strong); border-radius: var(--r-sm); background: none; color: var(--ink-2); cursor: pointer; font: inherit; font-size: 13px; }
.claim-btn:hover { border-style: solid; color: var(--ink); background: var(--hover); }
.claim-undo { border: 0; background: none; padding: 0 2px; font: inherit; color: var(--ink-3); text-decoration: underline; cursor: pointer; }
.claim-undo:hover { color: var(--ink); }

.share-dialog { width: min(520px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); padding: 0; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--page); color: var(--ink); box-shadow: var(--shadow); }
.share-dialog::backdrop { background: rgb(20 19 17 / 0.35); }
.share-dialog > * { margin-left: 20px; margin-right: 20px; }
.share-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 14px 12px 0 20px; }
.share-head h2 { margin: 0; font: 600 19px/1.3 var(--serif); }
.share-intro { margin-top: 6px; font-size: 14px; color: var(--ink-2); text-wrap: pretty; }
.share-dialog h3 { margin-top: 18px; margin-bottom: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); }
.share-members { list-style: none; padding: 0; border: 1px solid var(--line); border-radius: var(--r-sm); }
.share-members li { display: flex; align-items: center; gap: 10px; padding: 8px 8px 8px 12px; border-bottom: 1px solid var(--line); min-height: 44px; }
.share-members li:last-child { border-bottom: 0; }
.share-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.share-role { font-size: 13px; color: var(--ink-3); }
.share-empty { color: var(--ink-3); font-size: 14px; }
.btn-sm { padding: 4px 8px; font-size: 13px; }
.share-invite { display: grid; gap: 10px; }
.share-row { display: grid; grid-template-columns: auto 1fr; gap: 8px; }
.share-result { margin-bottom: 20px; font-size: 14px; color: var(--ink-2); }
.share-result:empty { margin-bottom: 20px; }
.share-result p { margin: 12px 0 8px; }
.share-link { display: flex; gap: 8px; }
.share-link input { font: 13px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; }

.auth { min-height: 100dvh; display: grid; place-items: center; padding: 24px calc(16px + var(--safe-r)) calc(24px + var(--safe-b)) calc(16px + var(--safe-l)); }
.auth[hidden] { display: none; }
.auth-card { width: min(380px, 100%); }
.auth-brand { display: flex; align-items: center; gap: 8px; margin-bottom: 28px; color: var(--accent); font: 600 17px/1.2 var(--serif); }
.auth-brand svg.i { width: 22px; height: 22px; }
.auth h1 { margin: 0 0 6px; font: 600 26px/1.25 var(--serif); }
.auth-intro { margin: 0 0 22px; color: var(--ink-2); text-wrap: pretty; }
.auth .stack { gap: 14px; }
.auth .btn-block { justify-content: center; }
body.signed-out .topbar { display: none; }

/* ---------- AI suggestions ---------- */
.section-head:has(.btn-ai) { align-items: center; }
.section-head .btn-ai { margin-left: auto; }
.ai-panel { margin-bottom: 20px; border: 1px solid var(--line-strong); border-radius: var(--r); background: var(--field); overflow: hidden; }
.ai-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 10px 10px 10px 16px; border-bottom: 1px solid var(--line); }
.ai-head h3 { margin: 0; display: flex; align-items: center; gap: 8px; font-size: 15px; font-weight: 600; }
.ai-head h3 .i { color: var(--accent); }
.ai-ideas { list-style: none; margin: 0; padding: 0; }
.ai-idea { display: grid; grid-template-columns: 1fr auto; gap: 6px 16px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.ai-idea:last-child { border-bottom: 0; }
.ai-idea-title { font-weight: 600; }
.ai-idea-why { margin-top: 2px; font-size: 14px; color: var(--ink-2); text-wrap: pretty; }
.ai-idea-price { font-size: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; white-space: nowrap; }
.ai-idea-actions { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 6px; }
.ai-idea-actions .ai-dismiss { margin-left: auto; }
.ai-wide { grid-column: 1 / -1; }
.ai-products { list-style: none; margin: 6px 0 0; padding: 0; display: grid; gap: 8px; }
.ai-product { display: grid; grid-template-columns: 56px 1fr auto; align-items: center; gap: 12px; padding: 8px; border: 1px solid var(--line); border-radius: var(--r-sm); }
.ai-product .thumb { width: 56px; height: 56px; }
.ai-product-text { min-width: 0; }
.ai-product-title { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; color: var(--ink); font-size: 14px; font-weight: 500; text-decoration: none; }
.ai-product-title:hover { text-decoration: underline; }
.ai-product-meta, .ai-find-meta { font-size: 13px; color: var(--ink-3); }
.ai-find-meta { margin: 2px 0 0; }
.ai-unverified { color: var(--amber-ink); }
.ai-setup { padding: 16px; font-size: 14px; color: var(--ink-2); }
.ai-setup p { margin: 0 0 8px; }
.ai-setup ol { margin: 0 0 8px; padding-left: 20px; display: grid; gap: 4px; }
.ai-setup code, .ai-foot code { font: 13px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; background: var(--rail); padding: 1px 5px; border-radius: 4px; color: var(--ink); }
.ai-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; padding: 10px 16px; background: var(--rail); border-top: 1px solid var(--line); font-size: 13px; color: var(--ink-2); }
.ai-meta b { font-weight: 500; color: var(--ink-2); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.ai-model { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.ai-model label { color: var(--ink-2); }
.ai-model input { width: 240px; padding: 5px 8px; font: 13px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; }
.ai-model .btn { padding: 5px 10px; font-size: 13px; white-space: nowrap; }
.notice-error { color: var(--danger); background: var(--danger-tint); }
.ai-skel { gap: 8px; }
.skel { height: 12px; border-radius: 4px; background: var(--hover); animation: pulse 1.4s ease-in-out infinite; }
.skel:first-child { height: 15px; }
@keyframes pulse { 50% { opacity: 0.45; } }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

/* ---------- touch: finger-sized targets (44px) ---------- */
@media (max-width: 820px), (pointer: coarse) {
  .btn { min-height: 44px; padding: 9px 14px; }
  .btn-icon { min-width: 44px; padding: 0; }
  .menu-item { min-height: 44px; font-size: 15px; }
  .chip { padding: 2px 2px 2px 12px; min-height: 34px; }
  .chip button { width: 30px; height: 30px; padding: 0; }
  .chip button::after { content: ""; position: absolute; inset: -7px; } /* 44px hit area */
  .chips input { min-height: 34px; }
}

/* ---------- phone: one screen at a time ---------- */
@media (max-width: 820px) {
  html, body { height: auto; }
  body { display: block; min-height: 100dvh; }

  /* 16px stops iOS zooming into a field on tap */
  input[type="text"], input[type="search"], input[type="url"], textarea, select, .chips input { font-size: 16px; }
  input[type="text"], input[type="search"], input[type="url"], select { min-height: 44px; }

  .topbar { padding: calc(10px + var(--safe-t)) calc(16px + var(--safe-r)) 10px calc(16px + var(--safe-l)); }
  .stats { gap: 4px 16px; }

  /* the page scrolls, not inner panes, so the browser bars can collapse */
  .layout { display: block; }
  .sidebar { background: var(--page); border: 0; }
  .people, .detail { overflow: visible; }
  .sidebar-head { padding: 16px calc(16px + var(--safe-r)) 8px calc(16px + var(--safe-l)); }
  .new-person { padding: 0 calc(16px + var(--safe-r)) 8px calc(16px + var(--safe-l)); }
  .people { padding: 4px calc(12px + var(--safe-r)) calc(24px + var(--safe-b)) calc(12px + var(--safe-l)); }
  .people li button { min-height: 60px; padding: 10px 12px; }
  .people li button[aria-current="true"] { background: none; box-shadow: none; }
  .avatar { width: 38px; height: 38px; font-size: 14px; }

  body.viewing-person .sidebar { display: none; }
  body:not(.viewing-person) .detail { display: none; }

  .detail-inner { padding: 12px calc(16px + var(--safe-r)) calc(64px + var(--safe-b)) calc(16px + var(--safe-l)); }
  .btn.back { display: inline-flex; margin-left: -10px; color: var(--ink); }
  .person-head { gap: 10px; margin-bottom: 20px; }
  .person-head .avatar.lg { width: 40px; height: 40px; font-size: 16px; }
  .person-head .btn-label { display: none; }
  .name-input { font-size: 21px; min-height: 44px; }
  .saved { min-width: 0; }
  .section { padding-top: 24px; margin-top: 24px; }

  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .add-link { flex-wrap: wrap; }
  .add-link input { flex-basis: 100%; }
  .add-link .btn { flex: 1; }
  .preview { grid-template-columns: 1fr; gap: 14px; padding: 14px; }
  .preview .thumb { width: 96px; height: 96px; }
  .preview-actions .btn { flex: 1; }

  /* compact gift rows: small picture beside the text */
  .gifts { grid-template-columns: 1fr; gap: 12px; margin-top: 16px; }
  .gift { display: grid; grid-template-columns: 100px 1fr; grid-template-areas: "thumb body" "foot foot"; }
  .gift .thumb { grid-area: thumb; width: 88px; height: 88px; aspect-ratio: auto; margin: 12px 0 0 12px; border: 1px solid var(--line); border-radius: var(--r-sm); }
  .gift-body { grid-area: body; padding: 12px 12px 0; }
  .gift-foot { grid-area: foot; padding: 8px 8px 8px 12px; }

  .empty-state { padding: 48px 16px; }

  .list-bar { padding: 12px calc(8px + var(--safe-r)) 0 calc(16px + var(--safe-l)); }
  .share-row { grid-template-columns: 1fr; }
  .first-list { flex-direction: column; }
  .account-btn { max-width: 130px; }
  .section-head .btn-ai { padding: 7px 10px; }
  .ai-idea { padding: 14px; }
  .ai-idea-actions { flex-wrap: nowrap; gap: 6px; }
  .ai-idea-actions .btn:not(.ai-dismiss) { flex: 1; min-width: 0; padding: 7px 8px; white-space: nowrap; }
  .ai-product { grid-template-columns: 56px 1fr; }
  .ai-product .btn { grid-column: 1 / -1; }
  .ai-foot { padding: 12px 14px; }
  .ai-model { width: 100%; margin: 0; flex-wrap: wrap; }
  .ai-model input { flex: 1; width: auto; min-width: 0; font-size: 16px; }
}
