:root {
  color-scheme: light dark;
  --bg: #fbf5ea; --card: #fffdf8; --text: #2a1f14; --muted: #6e5f4c;
  --gold: #d4a537; --gold-soft: #ecd9a6; --thumb: #f6ecd4; --line: #ecd9a6;
  --ok: #1e6b3a; --total: #e7f3e9; --shadow: 0 6px 18px rgba(120,90,40,.10);
  --accent: #b3261e; --accent-text: #fff; --soft: #fdecea;
  --warn: #8a5300; --warn-soft: #fff1d6; --bad: #b3261e; --bad-soft: #fdecea;
  --field: #fbf5ea;
  --hdr: #1f5f3a; --hdr-gold: #c9971f;
  --hero: #9e1f1a; --hero-text: #fff8ec; --hero-gold: #e6c66a; --hero-kicker: #f2d78a;
  --radius: 22px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f2a1d; --card: #173a2a; --text: #f6efe2; --muted: #c9bda6;
    --gold: #d4a537; --gold-soft: #5f6b3e; --thumb: #21503a; --line: #5f6b3e;
    --ok: #9be0b0; --total: #1e4a35; --shadow: 0 0 0 transparent;
    --accent: #e5554c; --accent-text: #fff; --soft: #4a1d1a;
    --warn: #ffd27a; --warn-soft: #3d3414; --bad: #ff9d94; --bad-soft: #4a1d1a;
    --field: #0f2a1d;
    --hdr: #2f7a4f; --hdr-gold: #e8bd4f;
    --hero: #8c1c17;
  }
}
* { box-sizing: border-box; }
html { font-size: 19px; }
body { margin: 0; background: var(--bg); color: var(--text); font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; line-height: 1.5; }
h1, h2, .big-name { font-family: Lora, Georgia, serif; }

/* Шапка (не меняем) */
.top { padding: 14px 16px; background: var(--hdr); border-bottom: 4px solid var(--hdr-gold); position: relative; z-index: 2;
  background-image: repeating-linear-gradient(135deg, rgba(255,255,255,.05) 0 12px, transparent 12px 24px); }
.logo { font-weight: 800; font-size: 1.2rem; color: #fff; text-decoration: none; letter-spacing: .01em; }

main { max-width: 680px; margin: 0 auto; padding: 20px 16px 80px; position: relative; z-index: 1; }
h1 { font-size: 1.8rem; font-weight: 700; line-height: 1.2; margin: 8px 0 14px; }
h2 { font-size: 1.3rem; font-weight: 600; line-height: 1.25; margin: 0 0 14px; }
h3 { font-size: 1.1rem; margin: 22px 0 4px; padding-top: 16px; border-top: 1px dashed var(--line); }
p { margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.okmsg { color: var(--ok); }

/* Карточки-«открытки»: двойная золотая рамка */
.card { background: var(--card); border-radius: var(--radius); padding: 24px 22px; margin: 0 0 20px;
  box-shadow: inset 0 0 0 1px var(--gold), inset 0 0 0 5px var(--card), inset 0 0 0 6px var(--gold-soft), var(--shadow); }
.card > h2 { display: flex; align-items: center; gap: 12px; text-align: center; justify-content: center; }
.card > h2::before, .card > h2::after { content: ''; flex: 1 1 24px; height: 1px; background: var(--gold-soft); }
.card.ok { background: var(--total); }

/* Главная карточка: красная открытка */
.card.hero { background: var(--hero); color: var(--hero-text); position: relative; overflow: hidden;
  box-shadow: inset 0 0 0 3px var(--hero), inset 0 0 0 5px var(--hero-gold), var(--shadow); }
.card.hero > h2::before, .card.hero > h2::after { background: var(--hero-gold); opacity: .6; }
.hero .muted { color: var(--hero-kicker); opacity: .9; }
.hero a, .hero .wish-link { color: var(--hero-text); }
.hero .price { color: var(--hero-kicker); }
.hero .wish-note { color: var(--hero-text); opacity: .8; }
.hero ul.list li { border-bottom-color: rgba(230,198,106,.45); }
.hero .thumb { border-color: var(--hero-gold); }
.hero .thumb.empty { background: rgba(255,255,255,.1); }
.hero input { background: rgba(0,0,0,.18); border-color: var(--hero-gold); color: var(--hero-text); }
.hero button:not(.giftbox):not(.link) { background: var(--hero-kicker); border-color: var(--hero-kicker); color: #5a1410; }
.hero .total { background: rgba(255,255,255,.12); color: var(--hero-text); }
.hero .total.ok .total-hint { color: var(--hero-kicker); }
.hero .total.over { background: #f2d78a; color: #5a3a00; } .hero .total.over b, .hero .total.over .total-hint { color: #5a3a00; }
.hero .total.warn { background: #fff8ec; color: #7a1712; } .hero .total.warn .total-hint { color: #9e1f1a; }
.kicker { text-transform: uppercase; letter-spacing: .14em; font-size: .8rem; font-weight: 700; color: var(--hero-kicker); text-align: center; margin: 4px 0 6px; }
.big-name { font-size: 40px; font-weight: 700; line-height: 1.15; text-align: center; margin: 0 0 14px; color: var(--hero-text); }
.hero .budget-line { text-align: center; }

/* Поля и кнопки */
label { display: block; font-weight: 600; margin: 14px 0 6px; }
label .muted { font-weight: 400; }
input, textarea, select { width: 100%; font: inherit; color: var(--text); background: var(--field); border: 2px solid var(--gold-soft); border-radius: 12px; padding: 12px 14px; }
input:focus, textarea:focus, select:focus { outline: none; border-color: var(--gold); }
textarea { min-height: 90px; resize: vertical; }
input, select { min-height: 54px; height: 3rem; }
input[type=date], input[type=datetime-local] { -webkit-appearance: none; appearance: none; display: block; min-width: 0; max-width: 100%; text-align: left; }
input::-webkit-date-and-time-value { text-align: left; margin: 0; }
input::-webkit-datetime-edit { padding: 0; }
select { width: auto; flex: 0 0 auto; -webkit-appearance: none; appearance: none; padding-right: 38px; cursor: pointer; line-height: 1.2;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%23b08a3a' stroke-width='2'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; }
button, .btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-weight: 600; min-height: 52px; padding: 10px 20px; border-radius: 14px; border: 2px solid var(--accent); background: var(--accent); color: var(--accent-text); cursor: pointer; text-decoration: none; }
button.secondary, .btn.secondary { background: transparent; color: var(--text); border-color: var(--gold); }
button.link { background: none; border: none; color: var(--muted); min-height: 40px; padding: 4px 8px; font-weight: 500; text-decoration: underline; text-decoration-color: var(--gold-soft); text-underline-offset: 3px; }
button:disabled { opacity: .5; cursor: default; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 16px; }
.row > * { flex: 1 1 auto; }
.money { display: flex; gap: 8px; align-items: stretch; }
.money input { flex: 1; min-width: 0; }
.money input, .money select { margin: 0; }
.money .cur { font-weight: 700; font-size: 1.1rem; min-width: 1.5em; align-self: center; }
.copy { display: flex; gap: 8px; }
.copy input { flex: 1; min-width: 0; font-size: .85rem; }
.copy button { flex: 0 0 auto; }

/* Факты и списки */
.facts { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; font-weight: 600; }
.rules { white-space: pre-wrap; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--gold-soft); }
ul.list { list-style: none; padding: 0; margin: 0; }
ul.list li { padding: 12px 0; border-bottom: 1px dashed var(--gold-soft); display: flex; gap: 12px; align-items: flex-start; }
ul.list li:last-child { border-bottom: none; }
ul.list .grow { flex: 1; min-width: 0; }
.wish-title { font-weight: 600; overflow-wrap: anywhere; }
a.wish-title { color: var(--text); text-decoration-color: var(--gold); text-underline-offset: 3px; }
.wish-note { color: var(--muted); font-size: .9rem; overflow-wrap: anywhere; }
.wish-link { font-size: .9rem; overflow-wrap: anywhere; color: var(--accent); }
.wish-actions { display: flex; gap: 4px; margin-left: -8px; }
.badge { display: inline-block; font-size: .75rem; padding: 2px 8px; border-radius: 999px; background: var(--thumb); color: var(--muted); margin-left: 6px; vertical-align: middle; }
.err { color: var(--bad); font-weight: 600; margin-top: 10px; }
#toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 12px 20px; border-radius: 12px; opacity: 0; transition: opacity .2s; pointer-events: none; max-width: calc(100% - 32px); z-index: 5; }
#toast.show { opacity: 1; }
details summary { cursor: pointer; font-weight: 600; min-height: 40px; display: flex; align-items: center; }

/* Подарки */
.thumb { width: 72px; height: 72px; flex: 0 0 72px; object-fit: contain; border-radius: 12px; background: var(--thumb); border: 1px solid var(--gold-soft); }
.thumb.empty { display: grid; place-items: center; font-size: 1.8rem; }
.thumb.big { width: 120px; height: 120px; }
.price { font-weight: 700; color: var(--ok); }
.photo { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px; }
.photo:empty { display: none; }
.filebtn { position: relative; overflow: hidden; }
.filebtn input { position: absolute; inset: 0; opacity: 0; cursor: pointer; height: 100%; min-height: 0; }
.total { margin-top: 14px; padding: 12px 16px; border-radius: 14px; background: var(--total); }
.total-row { display: flex; justify-content: space-between; font-size: 1.1rem; }
.total-hint { font-size: .9rem; margin-top: 2px; }
.total.ok .total-hint { color: var(--ok); }
.total.over { background: var(--warn-soft); box-shadow: inset 0 0 0 2px var(--gold); } .total.over b, .total.over .total-hint { color: var(--warn); }
.total.warn { background: var(--bad-soft); box-shadow: inset 0 0 0 2px var(--bad); } .total.warn .total-hint { color: var(--bad); font-weight: 600; font-size: 1rem; margin-top: 6px; }

/* Открытие результата */
.reveal { text-align: center; }
.giftbox { position: relative; width: 150px; height: 150px; margin: 10px auto 14px; background: none; border: none; padding: 0; display: block; animation: wobble 2.4s ease-in-out infinite; }
.giftbox .box { position: absolute; left: 15px; right: 15px; bottom: 0; height: 95px; border-radius: 8px; background: linear-gradient(90deg, transparent 44%, var(--gold) 44% 56%, transparent 56%), var(--box, var(--accent)); }
.giftbox .lid { position: absolute; left: 5px; right: 5px; top: 30px; height: 30px; border-radius: 6px; z-index: 1; background: linear-gradient(90deg, transparent 44%, var(--gold) 44% 56%, transparent 56%), var(--lid, #8e1c16); transition: transform .7s cubic-bezier(.3,1.6,.5,1), opacity .7s; }
.giftbox .bow { position: absolute; left: 0; right: 0; top: -6px; font-size: 44px; z-index: 2; transition: transform .7s, opacity .7s; }
.giftbox:focus-visible { outline: 3px solid var(--gold); outline-offset: 6px; border-radius: 12px; }
.opening .giftbox { animation: none; }
.opening .giftbox .lid { transform: translateY(-110px) rotate(-25deg); opacity: 0; }
.opening .giftbox .bow { transform: translateY(-130px) rotate(30deg); opacity: 0; }
@keyframes wobble { 0%, 80%, 100% { transform: rotate(0); } 85% { transform: rotate(-6deg); } 90% { transform: rotate(6deg); } 95% { transform: rotate(-3deg); } }
.confetti { position: absolute; left: 50%; top: 45%; width: 9px; height: 14px; border-radius: 2px; pointer-events: none; animation: burst 1.2s cubic-bezier(.2,.8,.3,1) forwards; }
@keyframes burst { to { transform: translate(var(--x), var(--y)) rotate(var(--r)); opacity: 0; } }
.big-name { animation: pop .6s cubic-bezier(.3,1.6,.5,1); }
@keyframes pop { from { transform: scale(.4); opacity: 0; } }

/* Снег */
.snow { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.snow i { position: absolute; top: -10px; border-radius: 50%; background: #b9c9d6; animation-name: fall, sway; animation-timing-function: linear, ease-in-out; animation-iteration-count: infinite; animation-direction: normal, alternate; }
@media (prefers-color-scheme: dark) { .snow i { background: #fff; } }
@keyframes fall { to { top: 105vh; } }
@keyframes sway { from { margin-left: -12px; } to { margin-left: 12px; } }
@media (prefers-reduced-motion: reduce) { .giftbox, .big-name { animation: none; } .snow { display: none; } }
.hero { --box: #fff3dc; --lid: #f2dfb4; }
.hero .giftbox .box, .hero .giftbox .lid { box-shadow: 0 2px 0 rgba(0,0,0,.15); }
