:root {
    --bg: #fff5ea;
    --card: #ffffff;
    --text: #2e2119;
    --muted: #8f7869;
    --line: #f3e3d3;
    --accent: #ff7a45;
    --accent-soft: #ffe7da;
    --gold: #ffb84d;
    --gold-soft: #fff0d6;
    --blue: #3b8cf0;
    --blue-soft: #e3efff;
    --danger: #e5484d;
    --shadow: 0 4px 16px rgba(140, 70, 20, .10);
    --radius: 18px;
    /* в полноэкранном режиме Telegram рисует свои кнопки поверх страницы */
    --safe-top: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px));
    color-scheme: light;
}

:root[data-theme="dark"] {
    --bg: #19130f;
    --card: #261d17;
    --text: #f7ece2;
    --muted: #a8968a;
    --line: #3a2d24;
    --accent: #ff8a57;
    --accent-soft: #48291b;
    --gold: #ffc266;
    --gold-soft: #45351c;
    --blue: #6aa8ff;
    --blue-soft: #1f2e45;
    --danger: #ff6b6f;
    --shadow: 0 4px 16px rgba(0, 0, 0, .35);
    color-scheme: dark;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.4 "Nunito", system-ui, -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
    -webkit-text-size-adjust: 100%;
}

button, input, textarea { font: inherit; color: inherit; }
h1, h2 { margin: 0; line-height: 1.2; }

.app {
    max-width: 560px;
    margin: 0 auto;
    padding: calc(var(--safe-top) + 16px) 16px calc(env(safe-area-inset-bottom, 0px) + 24px);
}

.muted { margin: 0; color: var(--muted); }
.small { font-size: 14px; }

/* шапка каталога, загрузка, экран вне Telegram */
.hero { display: grid; justify-items: center; gap: 10px; padding: 32px 8px 8px; text-align: center; }
.hero h1 { font-size: 28px; font-weight: 800; }
.hero--small { padding-top: 12px; }
.hero-gift { font-size: 64px; line-height: 1; animation: bob 3s ease-in-out infinite; }
.hero--small .hero-gift { font-size: 48px; }
.center { display: grid; place-items: center; align-content: center; gap: 12px; min-height: 60vh; text-align: center; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-4deg); } }
@media (prefers-reduced-motion: reduce) { .hero-gift { animation: none; } }

.section-title {
    margin: 24px 4px 10px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
    letter-spacing: .06em;
    text-transform: uppercase;
}

/* каталог */
.users { display: grid; gap: 8px; }
.user {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px;
    border: 0;
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
    text-align: left;
    cursor: pointer;
    transition: transform .1s;
}
.user-text { display: grid; flex: 1; min-width: 0; }
.user-name { overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--muted); font-size: 24px; }

.avatar {
    display: grid;
    flex: none;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--gold), var(--accent));
    color: #fff;
    font-size: 18px;
    font-weight: 800;
}
.avatar--big { width: 76px; height: 76px; font-size: 32px; box-shadow: var(--shadow); }

/* шапка списка */
.profile { display: grid; justify-items: center; gap: 6px; padding: 8px 0 4px; text-align: center; }
.profile-name { margin-top: 6px; font-size: 24px; font-weight: 800; }
.profile-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 10px; }

.chip { display: inline-block; margin: 0; padding: 4px 12px; border-radius: 999px; background: var(--line); font-size: 14px; font-weight: 700; }
.chip--gold { background: var(--gold-soft); }
.chip--blue { background: var(--blue-soft); color: var(--blue); }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: 40px;
    padding: 8px 16px;
    border: 0;
    border-radius: 999px;
    background: var(--card);
    box-shadow: var(--shadow);
    color: var(--text);
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
    transition: transform .1s;
}
.btn--accent { background: var(--accent); color: #fff; }
.btn--soft { background: var(--accent-soft); box-shadow: none; color: var(--accent); }
.btn--danger { background: transparent; box-shadow: none; color: var(--danger); }
.btn--big { min-height: 50px; padding: 12px 28px; font-size: 17px; }
.btn--wide { width: 100%; }
.btn:active, .user:active, .tile:active { transform: scale(.97); }

.seg { display: flex; gap: 4px; margin: 20px 0 12px; padding: 4px; border-radius: 999px; background: var(--line); }
.seg-btn {
    flex: 1;
    padding: 7px 4px;
    border: 0;
    border-radius: 999px;
    background: transparent;
    color: var(--muted);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}
.seg-btn.is-on { background: var(--card); box-shadow: 0 1px 4px rgba(0, 0, 0, .08); color: var(--text); }

/* плитка желаний */
.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; margin-top: 16px; }
.seg + .grid { margin-top: 0; }
.tile {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 0 0 12px;
    overflow: hidden;
    border: 0;
    border-radius: var(--radius);
    background: var(--card);
    box-shadow: var(--shadow);
    text-align: left;
    cursor: pointer;
    transition: transform .1s;
}
.tile-img, .detail-img {
    position: relative;
    display: grid;
    place-items: center;
    overflow: hidden;
    background: linear-gradient(135deg, var(--gold-soft), var(--accent-soft));
}
.tile-img { aspect-ratio: 1; margin-bottom: 8px; }
.tile-img img, .detail-img img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.tile-ph { font-size: 44px; }
.tile-title {
    display: -webkit-box;
    overflow: hidden;
    padding: 0 12px;
    font-size: 15px;
    font-weight: 700;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}
.tile-price { padding: 0 12px; color: var(--accent); font-size: 15px; font-weight: 800; }
.tile.is-done { opacity: .55; }
.tile.is-done .tile-img { filter: grayscale(1); }

.badge {
    position: absolute;
    top: 8px;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .92);
    color: #2e2119;
    font-size: 12px;
    font-weight: 800;
}
.badge--star { left: 8px; color: #e08a00; }
.badge--res { right: 8px; }
.badge--res.is-mine { background: var(--blue); color: #fff; }

.empty { display: grid; justify-items: center; gap: 8px; padding: 32px 16px; text-align: center; }
.empty-gift { font-size: 48px; opacity: .8; }

.done { margin-top: 24px; }
.done summary { padding: 8px 4px; color: var(--muted); font-weight: 700; list-style: none; cursor: pointer; }
.done summary::-webkit-details-marker { display: none; }
.done summary::before { content: "▸ "; }
.done[open] summary::before { content: "▾ "; }
.done .grid { margin-top: 8px; }

/* карточка желания: картинка во всю ширину, уходит под шапку Telegram */
.detail-img { aspect-ratio: 1; max-height: 55vh; margin: calc(-16px - var(--safe-top)) -16px 0; }
.detail-img .tile-ph { font-size: 96px; }
.detail {
    position: relative;
    display: grid;
    justify-items: start;
    gap: 10px;
    margin-top: -20px;
    padding: 20px 16px;
    border-radius: 24px;
    background: var(--card);
    box-shadow: var(--shadow);
}
.detail-title { font-size: 22px; font-weight: 800; }
.detail-price { margin: 0; color: var(--accent); font-size: 22px; font-weight: 800; }
.detail-note { margin: 0; color: var(--muted); white-space: pre-wrap; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; width: 100%; }

/* формы */
.page-title { margin: 8px 0 16px; font-size: 24px; font-weight: 800; }
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 6px; min-width: 0; }
.field-label { padding-left: 4px; color: var(--muted); font-size: 13px; font-weight: 700; }
.input {
    width: 100%;
    padding: 12px 14px;
    border: 2px solid transparent;
    border-radius: 14px;
    outline: none;
    background: var(--card);
    box-shadow: var(--shadow);
}
.input:focus { border-color: var(--accent); }
textarea.input { min-height: 72px; resize: vertical; }
.row { display: grid; grid-template-columns: 1fr 96px; gap: 10px; }
.switch {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-radius: 14px;
    background: var(--card);
    box-shadow: var(--shadow);
    font-weight: 700;
    cursor: pointer;
}
.switch input { width: 20px; height: 20px; accent-color: var(--accent); }
.danger-zone { margin-top: 32px; padding-top: 16px; border-top: 1px solid var(--line); text-align: center; }
.form [role="status"]:empty { display: none; }
