:root {
  --bg: #faf6f1;
  --card: #ffffff;
  --text: #2b2420;
  --muted: #8a7f76;
  --line: #ece4da;
  --accent: #e0674b;
  --accent-soft: #fbe6df;
  --ok: #3f9a6b;
  --ok-soft: #e1f2e8;
  --shadow: 0 1px 2px rgba(60, 40, 20, .06), 0 8px 24px rgba(60, 40, 20, .06);
  --radius: 20px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1a1715;
    --card: #24201d;
    --text: #f1ebe5;
    --muted: #a39790;
    --line: #37302b;
    --accent: #f07c5f;
    --accent-soft: #3d2620;
    --ok: #5cc28d;
    --ok-soft: #1f3529;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
  }
}
* { box-sizing: border-box; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
[hidden] { display: none !important; }

/* навигация */
.nav {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 12px 24px; background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; color: var(--text); text-decoration: none; font-size: 1.1rem; }
.nav-links { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-links a {
  color: var(--text); text-decoration: none; padding: 6px 12px; border-radius: 10px; font-weight: 500;
}
.nav-links a.active { background: var(--accent-soft); color: var(--accent); }
.mobile-only { display: none; }

/* бургер (виден только на узких экранах) */
.burger { display: none; background: transparent; width: 44px; height: 44px; padding: 0; border-radius: 12px; }
.burger span {
  display: block; width: 22px; height: 2px; margin: 5px auto; border-radius: 2px;
  background: var(--text); transition: transform .2s, opacity .2s;
}
.nav.open .burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.nav.open .burger span:nth-child(2) { opacity: 0; }
.nav.open .burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 40px 24px 60px; flex: 1; }
.footer { text-align: center; color: var(--muted); font-size: .82rem; padding: 24px; line-height: 1.8; }
.footer a { color: var(--muted); }

header.page { text-align: center; margin-bottom: 36px; }
h1 { font-size: clamp(1.8rem, 5vw, 2.8rem); letter-spacing: -.02em; margin: 0 0 8px; }
h2 { font-size: 1.3rem; margin: 0 0 16px; }
.subtitle { color: var(--muted); margin: 0 0 24px; }
.muted { color: var(--muted); }

/* статистика */
.stats {
  display: inline-flex; flex-direction: column; gap: 12px; width: min(520px, 100%);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px 24px; text-align: left;
}
.stats-row { display: flex; justify-content: space-between; align-items: baseline; gap: 16px; }
.stats-big { font-size: 1.6rem; font-weight: 700; }
.stats-big small { font-size: 1rem; font-weight: 500; color: var(--muted); }
.stats-sum { color: var(--muted); font-size: .95rem; text-align: right; }
.bar { height: 10px; background: var(--line); border-radius: 99px; overflow: hidden; }
.bar > div {
  height: 100%; background: linear-gradient(90deg, var(--accent), #f2a65a);
  border-radius: inherit; transition: width .6s cubic-bezier(.2, .8, .2, 1);
}

/* карточки */
.grid { display: grid; gap: 24px; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.card {
  display: flex; flex-direction: column; background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  transition: transform .2s, box-shadow .2s, opacity .3s;
}
.card.done { opacity: .55; }
.img { position: relative; display: block; aspect-ratio: 4 / 3; background: var(--line); overflow: hidden; }
.img img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform .4s; }
.placeholder { display: grid; place-items: center; height: 100%; font-size: 3rem; }
.badge {
  position: absolute; top: 12px; left: 12px; background: var(--card); color: var(--text);
  font-size: .8rem; font-weight: 600; padding: 4px 10px; border-radius: 99px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
}
.badge.mine { background: var(--ok); color: #fff; }
.body { padding: 18px 20px 20px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.title { font-weight: 650; font-size: 1.08rem; line-height: 1.3; margin: 0; }
.title a { color: inherit; text-decoration: none; }
.title a:hover { color: var(--accent); }
.note, .who { color: var(--muted); font-size: .9rem; margin: 0; }
.meta { display: flex; justify-content: space-between; align-items: center; margin-top: auto; padding-top: 12px; }
.price { font-weight: 700; font-size: 1.15rem; }
.dots { display: flex; gap: 5px; }
.dots span { width: 9px; height: 9px; border-radius: 50%; background: var(--line); }
.dots span.on { background: var(--accent); }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.actions:has(> :nth-child(3)) > :first-child { flex: 1 1 100%; }

/* переключатель вида */
.toolbar { display: flex; justify-content: flex-end; margin: -16px 0 18px; }
.view-switch { display: inline-flex; gap: 2px; padding: 3px; background: var(--line); border-radius: 12px; }
.view-switch button {
  display: flex; align-items: center; gap: 6px; padding: 7px 12px; font-size: .85rem;
  background: transparent; color: var(--muted); border-radius: 9px;
}
.view-switch button.on { background: var(--card); color: var(--accent); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.view-switch svg { width: 16px; height: 16px; fill: currentColor; }

/* вид «мелко» */
.grid.view-small { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.view-small .body { padding: 12px 14px 14px; gap: 4px; }
.view-small .title { font-size: .95rem; }
.view-small .note, .view-small .who { font-size: .8rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.view-small .meta { padding-top: 8px; }
.view-small .price { font-size: 1rem; }
.view-small .badge { top: 8px; left: 8px; font-size: .72rem; padding: 3px 8px; }
.view-small .actions { flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.view-small .actions > button, .view-small .actions > .btn { padding: 9px 10px; font-size: .85rem; }

/* вид «список» */
.grid.view-list { grid-template-columns: 1fr; gap: 12px; max-width: 860px; margin: 0 auto; }
.view-list .card { flex-direction: row; }
.view-list .img { flex: 0 0 150px; aspect-ratio: auto; min-height: 130px; }
.view-list .body { padding: 14px 16px; min-width: 0; }
.view-list .placeholder { font-size: 2rem; }
.view-list .badge { top: 8px; left: 8px; font-size: .72rem; padding: 3px 8px; }
.view-list .actions { margin-top: 10px; flex-wrap: wrap; }
.view-list .actions > button { flex: 0 1 auto; }

@media (hover: hover) {
  .card:hover { transform: translateY(-3px); }
  .card:hover .img img { transform: scale(1.04); }
  .person:hover { transform: translateY(-3px); }
  .mine-btn:hover .t-default { display: none; }
  .mine-btn:hover .t-hover { display: inline; }
}
/* на сенсорных экранах наведения нет — сразу пишем, что кнопка снимает отметку */
@media (hover: none) {
  .mine-btn .t-default::after { content: "нажми, чтобы отменить"; display: block; font-size: .72rem; font-weight: 500; opacity: .75; }
  .view-small .mine-btn .t-default::after { content: "отменить"; }
}

/* кнопки и формы */
button, .btn {
  border: 0; cursor: pointer; font: inherit; font-weight: 600; font-size: .95rem;
  padding: 11px 16px; border-radius: 12px; text-align: center; text-decoration: none;
  background: var(--line); color: var(--text); transition: background .15s, transform .1s, color .15s;
}
button:active, .btn:active { transform: scale(.97); }
button:disabled { opacity: .6; cursor: wait; }
.actions > button { flex: 1; }
.primary { background: var(--accent); color: #fff; }
.primary:hover { filter: brightness(1.06); }
.ghost:hover { background: var(--accent-soft); color: var(--accent); }
.danger { background: transparent; color: #c0392b; border: 1px solid currentColor; }
.mine-btn { background: var(--ok-soft); color: var(--ok); }
.mine-btn:hover { background: var(--accent-soft); color: var(--accent); }
.mine-btn .t-hover { display: none; }
.gone { color: var(--muted); cursor: default; }
.icon-btn { flex: 0 0 auto !important; }

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px; margin: 0 auto 24px; max-width: 640px;
}
.panel.narrow { max-width: 420px; }
form { display: flex; flex-direction: column; gap: 14px; }
label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: .95rem; }
label.check { flex-direction: row; align-items: flex-start; gap: 10px; font-weight: 400; }
label.check input { margin-top: 4px; width: 18px; height: 18px; flex: 0 0 auto; }
input, textarea {
  font: inherit; padding: 11px 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); width: 100%;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; min-height: 70px; }
.row { display: flex; gap: 12px; }
.row > * { flex: 1; }
.hint { color: var(--muted); font-size: .85rem; font-weight: 400; }
.error { color: #c0392b; font-size: .9rem; min-height: 1em; margin: 0; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 500; font-size: .95rem; }
.image-picker { display: flex; align-items: center; gap: 14px; }
.image-buttons { display: flex; flex-direction: column; gap: 8px; }
.file-btn { cursor: pointer; display: inline-block; }
.preview { width: 120px; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; background: var(--line); }

/* люди на главной */
.people { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.person {
  display: flex; align-items: center; gap: 14px; padding: 18px 20px; text-decoration: none; color: var(--text);
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  transition: transform .2s;
}
.person.me { border-color: var(--accent); }
.avatar {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; flex: 0 0 auto;
  background: var(--accent-soft); color: var(--accent); font-weight: 700; font-size: 1.2rem;
}
img.avatar { object-fit: cover; display: block; background: var(--line); }
.page-avatar { display: flex; justify-content: center; margin-bottom: 12px; }
.page-avatar .avatar { box-shadow: var(--shadow); border: 3px solid var(--card); }
.avatar-actions { display: flex; justify-content: center; gap: 8px; margin: -2px 0 14px; }
.avatar-actions .btn, .avatar-actions button { padding: 7px 12px; font-size: .85rem; }
.person b { display: block; }
.person span { color: var(--muted); font-size: .9rem; }

/* списки в профиле */
.list { display: flex; flex-direction: column; gap: 10px; margin: 0; padding: 0; list-style: none; }
.list li { display: flex; align-items: center; gap: 12px; padding: 10px; border-radius: 12px; background: var(--bg); }
.list img, .list .thumb { width: 56px; height: 42px; object-fit: cover; border-radius: 8px; flex: 0 0 auto; background: var(--line); display: grid; place-items: center; }
.list .grow { flex: 1; min-width: 0; }
.list .grow a { color: var(--text); font-weight: 600; text-decoration: none; }
.list .grow small { display: block; color: var(--muted); }
.list button { padding: 7px 12px; font-size: .85rem; }
.group-title { margin: 18px 0 8px; font-weight: 600; }
.group-title:first-child { margin-top: 0; }
code.invite { word-break: break-all; font-size: .85rem; }

/* модалка и тост */
.modal {
  position: fixed; inset: 0; z-index: 20; background: rgba(20, 15, 10, .5);
  display: grid; place-items: center; padding: 16px; overflow-y: auto;
}
.modal-box {
  background: var(--card); border-radius: var(--radius); padding: 28px; width: min(560px, 100%);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3); max-height: calc(100vh - 32px); overflow-y: auto;
}
/* кадрирование — поверх формы подарка */
.crop-layer { z-index: 25; }
.crop-box { width: min(520px, 100%); }
.crop-stage {
  position: relative; width: 100%; overflow: hidden; border-radius: 14px;
  background: #fff; touch-action: none; user-select: none; -webkit-user-select: none; cursor: grab;
}
.crop-stage:active { cursor: grabbing; }
.crop-img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; pointer-events: none; }
.crop-mask {
  position: absolute; inset: 0; pointer-events: none; border-radius: inherit;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .85), inset 0 0 0 3px rgba(0, 0, 0, .15);
  background:
    linear-gradient(to right, transparent calc(33.33% - .5px), rgba(255, 255, 255, .5) 0 calc(33.33% + .5px), transparent 0 calc(66.66% - .5px), rgba(255, 255, 255, .5) 0 calc(66.66% + .5px), transparent 0),
    linear-gradient(to bottom, transparent calc(33.33% - .5px), rgba(255, 255, 255, .5) 0 calc(33.33% + .5px), transparent 0 calc(66.66% - .5px), rgba(255, 255, 255, .5) 0 calc(66.66% + .5px), transparent 0);
}
.crop-stage.round { border-radius: 14px; }
.crop-stage.round .crop-mask { inset: 0; border-radius: 50%; background: none; box-shadow: 0 0 0 9999px rgba(20, 15, 10, .55), inset 0 0 0 2px rgba(255, 255, 255, .85); }
.crop-zoom { width: 100%; margin: 16px 0 4px; accent-color: var(--accent); }
.crop-hint { text-align: center; margin: 0 0 14px; }
.crop-buttons { flex-wrap: wrap; }
.crop-buttons [data-crop="fit"] { flex: 1 1 100%; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 120px); z-index: 30;
  background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 12px; font-weight: 500;
  opacity: 0; visibility: hidden; pointer-events: none;
  transition: transform .3s cubic-bezier(.2, .8, .2, 1), opacity .3s, visibility .3s;
}
.toast.show { transform: translate(-50%, 0); opacity: 1; visibility: visible; }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

@media (max-width: 640px) {
  .burger { display: block; }
  .mobile-only { display: block; }
  .nav-links {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; gap: 2px; padding: 8px 12px 14px;
    background: var(--card); border-bottom: 1px solid var(--line); box-shadow: var(--shadow);
  }
  .nav.open .nav-links { display: flex; }
  .nav-links a { padding: 13px 14px; font-size: 1.05rem; }
}

@media (max-width: 600px) {
  .nav { padding: 8px 10px 8px 16px; padding-top: max(8px, env(safe-area-inset-top)); }
  .wrap { padding: 24px 14px 36px; }
  header.page { margin-bottom: 24px; }
  .subtitle { margin-bottom: 18px; font-size: .95rem; }
  .panel { padding: 20px 18px; }
  .stats { padding: 16px 18px; }
  .stats-big { font-size: 1.35rem; }
  .toolbar { margin: -8px 0 14px; justify-content: center; }
  .view-switch .lbl { display: none; }
  .view-switch button { padding: 8px 16px; }
  .view-switch svg { width: 18px; height: 18px; }

  .grid { gap: 14px; }
  .grid.view-large { grid-template-columns: 1fr; }
  .grid.view-small { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .view-small .body { padding: 10px 11px 12px; }
  .view-small .title { font-size: .9rem; }
  .view-small .dots span { width: 7px; height: 7px; }
  .view-list .img { flex-basis: 104px; min-height: 104px; }
  .view-list .body { padding: 10px 12px; }
  .view-list .title { font-size: .95rem; }
  .view-list .actions > button, .view-list .actions > .btn { padding: 9px 12px; font-size: .85rem; }

  .people { grid-template-columns: 1fr; gap: 10px; }
  .stack-mobile { flex-direction: column; }
  .stack-mobile > * { width: 100%; }
  .list li { flex-wrap: wrap; }
  .list li .grow { flex: 1 1 calc(100% - 70px); }
  .list li:has(> img, > .thumb) > button { margin-left: 68px; }
  .person { padding: 14px 16px; }

  /* форма подарка — снизу, как в приложениях */
  .modal { place-items: end center; padding: 0; }
  .modal-box {
    width: 100%; max-height: 92vh; border-radius: 20px 20px 0 0;
    padding: 22px 18px calc(22px + env(safe-area-inset-bottom));
  }
  .toast { bottom: calc(16px + env(safe-area-inset-bottom)); max-width: calc(100% - 32px); text-align: center; }
  .footer { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
}
