:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --tile: #ecece8;
  --text: #121212;
  --muted: #85857f;
  --line: #e4e4df;
  --accent: #121212;
  --on-accent: #ffffff;
  --ok: #2f8f5b;
  --danger: #c6453a;
  --radius: 18px;
  --shadow: 0 24px 60px -20px rgba(0, 0, 0, .25);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d0d0d;
    --surface: #171717;
    --tile: #1c1c1c;
    --text: #f1f1ee;
    --muted: #8b8b86;
    --line: #272727;
    --accent: #f1f1ee;
    --on-accent: #0d0d0d;
    --ok: #5cc48a;
    --danger: #ef6f63;
    --shadow: 0 24px 60px -20px rgba(0, 0, 0, .8);
  }
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
}

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

.page {
  max-width: 1120px;
  margin: 0 auto;
  padding: clamp(28px, 7vw, 88px) clamp(16px, 4vw, 40px) 96px;
}

/* ---------- шапка ---------- */

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  flex-wrap: wrap;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 6.4vw, 64px);
  line-height: 1.02;
  font-weight: 600;
  letter-spacing: -.035em;
  text-wrap: balance;
}

.subtitle {
  margin: 14px 0 0;
  max-width: 46ch;
  color: var(--muted);
  font-size: 17px;
}

.owner-tools { display: flex; gap: 8px; }

/* ---------- кнопки ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 40px;
  padding: 0 16px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  font-weight: 500;
  font-size: 14px;
  white-space: nowrap;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s, transform .1s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .45; cursor: default; }
.btn:focus-visible, input:focus-visible, textarea:focus-visible, .tab:focus-visible, .card-edit:focus-visible {
  outline: 2px solid var(--text);
  outline-offset: 2px;
}

.btn.primary { background: var(--accent); color: var(--on-accent); }
.btn.primary:hover:not(:disabled) { opacity: .85; }
.btn.ghost { border-color: var(--line); }
.btn.ghost:hover:not(:disabled) { border-color: var(--muted); }
.btn.ghost[aria-pressed="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.text { padding: 0 8px; color: var(--muted); }
.btn.text:hover { color: var(--text); }
.btn.danger { color: var(--danger); }
.btn.icon { width: 40px; padding: 0; }
.btn.small { height: 34px; padding: 0 13px; font-size: 13px; }
.btn.wide { flex: 1; }

/* ---------- добавление ---------- */

.add {
  display: flex;
  gap: 8px;
  margin-top: 40px;
  padding: 6px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 999px;
  transition: border-color .15s;
}
.add:focus-within { border-color: var(--muted); }
.add input {
  flex: 1;
  min-width: 0;
  padding: 0 14px;
  border: 0;
  background: none;
  outline: none;
  font-size: 15px;
}
.add input::placeholder { color: var(--muted); }
.add.loading { pointer-events: none; }
.add.loading .btn { opacity: .6; }

/* ---------- фильтр ---------- */

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: 44px 0 20px;
}
.tabs { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 7px 13px;
  border: 0;
  border-radius: 999px;
  background: none;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { background: var(--tile); color: var(--text); }
.count { color: var(--muted); font-size: 13px; white-space: nowrap; font-variant-numeric: tabular-nums; }

/* ---------- сетка ---------- */

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

.card { display: flex; flex-direction: column; min-width: 0; animation: rise .35s ease both; }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }

.card-media {
  position: relative;
  display: block;
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: var(--tile);
  overflow: hidden;
}
.card-media img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform .5s cubic-bezier(.2, .7, .2, 1), opacity .2s;
}
a.card-media:hover img { transform: scale(1.035); }
.card-media .ph {
  position: absolute; inset: 0;
  display: grid; place-items: center;
  color: var(--muted);
  font-size: 44px; font-weight: 600; letter-spacing: -.04em;
  text-transform: uppercase;
}

.badge {
  position: absolute;
  left: 10px; bottom: 10px;
  max-width: calc(100% - 20px);
  padding: 5px 11px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.badge.mine { background: var(--accent); color: var(--on-accent); }

.card-edit {
  position: absolute;
  top: 10px; right: 10px;
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 0; border-radius: 50%;
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  cursor: pointer;
  opacity: 0;
  transition: opacity .15s;
}
.card:hover .card-edit, .card-edit:focus-visible { opacity: 1; }
@media (hover: none) { .card-edit { opacity: 1; } }

.card-body { padding: 14px 2px 0; display: flex; flex-direction: column; flex: 1; }
.shop {
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.card-title {
  margin: 5px 0 0;
  font-size: 15px;
  font-weight: 500;
  line-height: 1.35;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.card-title a { text-decoration: none; }
.card-title a:hover { text-decoration: underline; text-underline-offset: 3px; }
.note { margin: 4px 0 0; color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.price {
  margin-top: 8px;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.price.none { color: var(--muted); font-weight: 400; font-size: 14px; }

.pool-line { margin-top: 12px; }
.progress { height: 4px; border-radius: 4px; background: var(--tile); overflow: hidden; }
.progress i { display: block; height: 100%; border-radius: 4px; background: var(--text); transition: width .4s ease; }
.progress.full i { background: var(--ok); }
.pool-text { margin-top: 6px; color: var(--muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }

.actions { display: flex; gap: 8px; margin-top: auto; padding-top: 14px; }
.actions .btn { height: 42px; padding: 0 14px; font-size: 14px; }

.card.dim .card-media img, .card.dim .card-media .ph { opacity: .4; filter: grayscale(1); }
.card.dim .card-title, .card.dim .price { color: var(--muted); }

.skeleton .card-media, .skeleton .line {
  background: linear-gradient(100deg, var(--tile) 40%, var(--line) 50%, var(--tile) 60%) 0 0 / 300% 100%;
  animation: shimmer 1.2s linear infinite;
}
.skeleton .line { height: 12px; border-radius: 6px; margin-top: 10px; }
@keyframes shimmer { to { background-position: -150% 0; } }

.empty {
  padding: 72px 0;
  text-align: center;
  color: var(--muted);
}
.empty b { display: block; margin-bottom: 6px; color: var(--text); font-size: 19px; font-weight: 600; letter-spacing: -.01em; }

/* ---------- диалог ---------- */

.dlg {
  width: min(480px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 0;
  border: 0;
  border-radius: 24px;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  overflow: auto;
}
.dlg::backdrop { background: rgba(0, 0, 0, .38); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.dlg[open] { animation: pop .2s cubic-bezier(.2, .8, .2, 1); }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }

#dlg-body { padding: 26px; }
.dlg h2 { margin: 0 0 4px; font-size: 21px; font-weight: 600; letter-spacing: -.02em; }
.dlg .lead { margin: 0 0 20px; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }

.field { display: block; margin-top: 14px; }
.field > span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12.5px; }
.field input, .field textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
}
.field textarea { resize: vertical; min-height: 44px; }
.field input:focus, .field textarea:focus { border-color: var(--muted); }
.row { display: flex; gap: 10px; }
.row > * { flex: 1; min-width: 0; }
.row > .narrow { flex: 0 0 84px; }

.preview {
  display: flex; gap: 14px; align-items: center;
  margin-bottom: 6px;
}
.preview .thumb {
  flex: 0 0 76px; height: 76px;
  border-radius: 14px;
  background: var(--tile) center / cover no-repeat;
}
.preview .meta { min-width: 0; }
.preview .meta .shop { display: block; }
.preview .meta a { color: var(--muted); font-size: 13px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.warn {
  margin: 14px 0 0;
  padding: 10px 13px;
  border-radius: 12px;
  background: var(--tile);
  color: var(--muted);
  font-size: 13px;
}

.dlg-actions { display: flex; gap: 8px; margin-top: 24px; align-items: center; }
.dlg-actions .spacer { flex: 1; }
.dlg-extra { display: flex; flex-wrap: wrap; gap: 4px; margin: 18px -8px -8px; padding-top: 10px; border-top: 1px solid var(--line); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: none;
  font-size: 13px;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
.chip:hover { border-color: var(--muted); }

.people { list-style: none; margin: 16px 0 0; padding: 0; }
.people li {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.people li span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.people li.me span:first-child::after { content: " · это ты"; color: var(--muted); }

.big-sum { font-size: 28px; font-weight: 600; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.big-sum small { color: var(--muted); font-size: 15px; font-weight: 400; letter-spacing: 0; }

.bookmarklet {
  display: inline-flex; align-items: center; height: 38px; padding: 0 16px;
  border: 1px dashed var(--muted); border-radius: 999px;
  font-weight: 500; font-size: 14px; text-decoration: none; cursor: grab;
}
.steps { margin: 14px 0 0; padding-left: 18px; color: var(--muted); font-size: 13.5px; }
.steps li { margin-top: 4px; }
.section { margin-top: 26px; padding-top: 22px; border-top: 1px solid var(--line); }
.section h3 { margin: 0 0 4px; font-size: 15px; font-weight: 600; }
.section p { margin: 0 0 14px; color: var(--muted); font-size: 13.5px; }

/* ---------- тост ---------- */

.toast {
  position: fixed;
  left: 50%; bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  padding: 11px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: pop .2s ease;
  z-index: 10;
}

@media (max-width: 560px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 28px 12px; }
  .subtitle { font-size: 16px; }
  .add { margin-top: 28px; }
  .bar { margin-top: 32px; }
  .count { display: none; }
  .actions { flex-direction: column; padding-top: 16px; }
  .actions .btn { flex: none; width: 100%; height: 48px; font-size: 16px; }
  .dlg .btn { height: 50px; padding: 0 20px; font-size: 16px; }
  .dlg .btn.small { height: 40px; font-size: 14px; }
  .chip { padding: 10px 15px; font-size: 15px; }
  /* 16px — чтобы айфон не зумил страницу при фокусе на поле */
  .field input, .field textarea, .add input { font-size: 16px; }
  .card-title { font-size: 14px; }
  .price { font-size: 16px; }
  #dlg-body { padding: 22px 20px; }
  .add input::placeholder { font-size: 14px; }
}

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