:root {
  --paper: #fff3e2;
  --paper2: #ffe9cc;
  --card: #fffdf8;
  --ink: #2a1840;
  --muted: #8a7a92;
  --tomato: #ff5a36;
  --sun: #ffc531;
  --sea: #12b3ad;
  --pink: #ff6fae;
  --cobalt: #3d5afe;
  --leaf: #2fbf71;
  --violet: #8f5cff;
  --line: #2a1840;
  --shadow: 4px 4px 0 var(--line);
  --r: 20px;
  --display: "Unbounded", "Arial Black", system-ui, sans-serif;
  --body: "Nunito", "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { background: var(--paper); }
body {
  margin: 0; color: var(--ink); font: 500 16px/1.4 var(--body);
  background:
    radial-gradient(circle at 12% 8%, #ffd9e8 0 120px, transparent 121px),
    radial-gradient(circle at 92% 22%, #c9f2ee 0 90px, transparent 91px),
    radial-gradient(circle at 80% 92%, #fff0b3 0 140px, transparent 141px),
    radial-gradient(#e9cfa9 1px, transparent 1.4px) 0 0 / 18px 18px,
    var(--paper);
  background-attachment: fixed;
  min-height: 100vh;
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -.01em; }
.muted { color: var(--muted); }
.err { color: var(--tomato); font-weight: 800; min-height: 1.2em; margin: 6px 0 0; }

/* ---------- login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.login-card {
  width: min(380px, 100%); background: var(--card); border: 3px solid var(--line);
  border-radius: 28px; box-shadow: 8px 8px 0 var(--line); padding: 32px 24px; text-align: center;
  animation: pop .5s cubic-bezier(.2, 1.4, .4, 1);
}
.login-pig { font-size: 64px; animation: wiggle 2.5s ease-in-out infinite; }
.login h1 { font-size: 30px; line-height: 1.05; margin-top: 8px; }
.login h1 span { color: var(--tomato); }
.login form { display: grid; gap: 10px; margin-top: 18px; }

/* ---------- inputs & buttons */
input, select, textarea {
  width: 100%; padding: 13px 14px; border: 2.5px solid var(--line); border-radius: 14px;
  background: #fff; outline: none; font-weight: 700;
}
input:focus, select:focus, textarea:focus { box-shadow: 0 0 0 4px #ffc53166; }
textarea { min-height: 70px; resize: vertical; }
label.f { display: grid; gap: 6px; font-weight: 800; font-size: 14px; }
.btn {
  border: 2.5px solid var(--line); background: var(--tomato); color: #fff; font-weight: 800;
  border-radius: 14px; padding: 12px 16px; box-shadow: 3px 3px 0 var(--line);
  transition: transform .08s, box-shadow .08s;
}
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--line); }
.btn-big { font-family: var(--display); font-size: 16px; padding: 15px; }
.btn.ghost { background: #fff; color: var(--ink); }
.btn.danger { background: #fff; color: var(--tomato); }
.btn.small { padding: 7px 12px; font-size: 14px; border-radius: 11px; }

/* ---------- layout */
#main { max-width: 640px; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom, 0px)); }
.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 0 10px;
}
.brand { display: flex; align-items: baseline; gap: 6px; font-family: var(--display); }
.brand b { font-size: 20px; }
.brand i { font-style: normal; font-weight: 500; font-size: 13px; color: var(--tomato); }
.brand-pig { font-size: 26px; align-self: center; }
.me-btn {
  width: 44px; height: 44px; border-radius: 50%; border: 2.5px solid var(--line);
  font-size: 22px; box-shadow: 2px 2px 0 var(--line); display: grid; place-items: center;
}
.tabs {
  position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(10px + env(safe-area-inset-bottom, 0px));
  width: min(608px, calc(100% - 24px)); display: grid; grid-template-columns: repeat(4, 1fr);
  background: var(--ink); border-radius: 22px; padding: 6px; gap: 4px; z-index: 5;
  box-shadow: 0 10px 30px #2a184055;
}
.tabs button {
  border: 0; background: transparent; color: #fff9; border-radius: 16px; padding: 7px 2px 6px;
  font-size: 12px; font-weight: 800; display: grid; justify-items: center; gap: 1px;
}
.tabs button span { font-size: 21px; filter: grayscale(.6); transition: transform .2s; }
.tabs button.on { background: var(--sun); color: var(--ink); }
.tabs button.on span { filter: none; transform: scale(1.12) rotate(-6deg); }

.view { display: grid; gap: 18px; animation: rise .35s ease-out; }
.view > * { animation: rise .45s ease-out both; }
.view > *:nth-child(2) { animation-delay: .05s; }
.view > *:nth-child(3) { animation-delay: .1s; }
.view > *:nth-child(4) { animation-delay: .15s; }
.view > *:nth-child(5) { animation-delay: .2s; }
.sec-title { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.sec-title h2 { font-size: 18px; }
.card {
  background: var(--card); border: 2.5px solid var(--line); border-radius: var(--r);
  box-shadow: var(--shadow); padding: 16px;
}

/* ---------- hero (balance) */
.hero {
  position: relative; overflow: hidden; color: #fff; background: var(--tomato);
  border: 3px solid var(--line); border-radius: 26px; box-shadow: 6px 6px 0 var(--line); padding: 20px 18px 18px;
}
.hero::before, .hero::after {
  content: ""; position: absolute; border-radius: 50%; pointer-events: none;
}
.hero::before { width: 220px; height: 220px; right: -70px; top: -90px; background: var(--sun); opacity: .9; }
.hero::after { width: 120px; height: 120px; right: 70px; bottom: -70px; background: var(--pink); }
.hero > * { position: relative; z-index: 1; }
.hero .lbl { font-weight: 800; opacity: .9; font-size: 14px; }
.hero .total { font-family: var(--display); font-weight: 900; font-size: clamp(32px, 9vw, 46px); line-height: 1.05; margin: 4px 0 2px; }
.hero .rates { font-size: 12px; opacity: .85; font-weight: 700; }
.coins { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.coin {
  display: inline-flex; align-items: center; gap: 6px; background: #fff; color: var(--ink);
  border: 2px solid var(--line); border-radius: 999px; padding: 5px 11px 5px 5px; font-weight: 800; font-size: 14px;
}
.coin i {
  font-style: normal; width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center;
  font-size: 12px; font-weight: 900; color: #fff; border: 2px solid var(--line);
}
.coin.neg { background: #ffe1d9; }

/* ---------- quick actions */
.quick { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.qa {
  border: 2.5px solid var(--line); border-radius: 18px; padding: 12px 4px 10px; background: var(--c, #fff);
  box-shadow: 3px 3px 0 var(--line); display: grid; justify-items: center; gap: 4px; font-weight: 800; font-size: 12.5px;
  line-height: 1.1; text-align: center; transition: transform .1s;
}
.qa span { font-size: 26px; }
.qa:active { transform: translate(3px, 3px); box-shadow: none; }

/* ---------- people month */
.people { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.person {
  background: var(--card); border: 2.5px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow);
  padding: 14px 12px; text-align: center; position: relative;
}
.ring { width: 92px; height: 92px; margin: 0 auto 6px; position: relative; }
.ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.ring .face {
  position: absolute; inset: 0; display: grid; place-items: center; font-size: 34px;
}
.person b { font-family: var(--display); font-size: 15px; display: block; }
.person .sum { font-weight: 800; font-size: 14px; margin-top: 2px; }
.person .st { font-size: 12.5px; font-weight: 800; margin-top: 6px; border-radius: 999px; padding: 3px 8px; display: inline-block; }
.st.ok { background: #d6f5e3; color: #137a44; }
.st.wait { background: #fff0c2; color: #8a5a00; }
.stamp {
  position: absolute; right: -8px; top: -10px; transform: rotate(14deg); font-family: var(--display);
  font-size: 11px; font-weight: 900; color: var(--leaf); border: 2.5px solid var(--leaf); border-radius: 8px;
  padding: 3px 6px; background: var(--card);
}

/* ---------- debts */
.debt {
  display: flex; align-items: center; gap: 12px; padding: 12px; border: 2.5px dashed var(--tomato);
  border-radius: 16px; background: #fff4f0;
}
.debt + .debt { margin-top: 10px; }
.debt .av { font-size: 28px; }
.debt .tx { flex: 1; font-weight: 700; }
.debt .tx b { color: var(--tomato); }

/* ---------- goal */
.goal { background: var(--sea); color: #fff; }
.goal .row { display: flex; align-items: center; gap: 12px; }
.goal h3 { font-size: 17px; }
.bar { height: 16px; border-radius: 99px; border: 2.5px solid var(--line); background: #fff; overflow: hidden; margin-top: 12px; }
.bar > div { height: 100%; background: repeating-linear-gradient(-45deg, var(--sun) 0 10px, #ffd866 10px 20px); border-right: 2.5px solid var(--line); transition: width .8s cubic-bezier(.2, .9, .3, 1); }
.goal .meta { display: flex; justify-content: space-between; font-weight: 800; font-size: 13px; margin-top: 6px; }

/* ---------- flags */
.flag {
  width: 46px; height: 46px; border-radius: 50%; border: 2.5px solid var(--line); overflow: hidden;
  flex: none; background: #eee center / cover no-repeat; display: grid; place-items: center; font-size: 22px;
}
.flag.big { width: 58px; height: 58px; }

/* ---------- months table */
.months { display: grid; gap: 10px; }
.mrow {
  display: grid; grid-template-columns: 92px 1fr 1fr; gap: 8px; align-items: center;
  background: var(--card); border: 2.5px solid var(--line); border-radius: 16px; padding: 10px 12px;
}
.mrow.now { background: #fff6cc; }
.mrow .mname { font-family: var(--display); font-size: 13px; line-height: 1.15; }
.mrow .mname small { display: block; font-family: var(--body); color: var(--muted); font-weight: 700; }
.mcell { border-radius: 12px; padding: 6px 8px; font-weight: 800; font-size: 13.5px; text-align: center; border: 2px solid transparent; }
.mcell.full { background: #d6f5e3; border-color: #2fbf7155; }
.mcell.part { background: #fff0c2; border-color: #ffc53188; }
.mcell.none { background: #ffe4dd; border-color: #ff5a3644; color: #b3341a; }
.mcell.future { background: #f2ece4; color: var(--muted); }
.mhead { display: grid; grid-template-columns: 92px 1fr 1fr; gap: 8px; padding: 0 12px; text-align: center; font-weight: 800; }
.totals { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.totals .card { text-align: center; }
.totals .big { font-family: var(--display); font-size: 20px; margin-top: 4px; }

/* ---------- segmented & chips */
.seg { display: flex; gap: 6px; background: var(--paper2); border: 2.5px solid var(--line); border-radius: 16px; padding: 4px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 11px; padding: 8px 4px; font-weight: 800; font-size: 14px; }
.seg button.on { background: var(--ink); color: #fff; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 800; font-size: 14px;
}
.chip.on { background: var(--c, var(--sun)); color: var(--fg, var(--ink)); }

/* ---------- trips */
.trip { display: flex; gap: 12px; align-items: center; cursor: pointer; }
.trip .info { flex: 1; min-width: 0; }
.trip h3 { font-size: 16px; }
.trip .sub { color: var(--muted); font-weight: 700; font-size: 13.5px; }
.trip .spent { font-weight: 800; font-size: 13.5px; margin-top: 4px; }
.trips { display: grid; gap: 12px; }
.trips .card:nth-child(3n+1) { rotate: -.6deg; }
.trips .card:nth-child(3n+2) { rotate: .5deg; }
.passport {
  background: var(--cobalt); color: #fff; display: flex; gap: 14px; align-items: center;
}
.passport .n { font-family: var(--display); font-weight: 900; font-size: 44px; line-height: 1; }
.stickers { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.stickers .flag { width: 34px; height: 34px; border-width: 2px; box-shadow: 2px 2px 0 #0004; }
.stickers .flag:nth-child(odd) { rotate: -8deg; }
.stickers .flag:nth-child(even) { rotate: 7deg; }
.empty { text-align: center; padding: 26px 16px; color: var(--muted); font-weight: 700; }
.empty .e { font-size: 44px; display: block; margin-bottom: 6px; }

/* ---------- history */
.hgroup h3 { font-size: 14px; margin: 6px 4px 8px; color: var(--muted); font-family: var(--body); font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.hlist { background: var(--card); border: 2.5px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow); overflow: hidden; }
.hitem { display: flex; gap: 12px; align-items: center; padding: 12px 14px; width: 100%; border: 0; background: none; text-align: left; }
.hitem + .hitem { border-top: 2px dashed #2a184022; }
.hicon { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-size: 21px; border: 2px solid var(--line); flex: none; }
.hitem .mid { flex: 1; min-width: 0; }
.hitem .t { font-weight: 800; }
.hitem .s { font-size: 13px; color: var(--muted); font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hitem .amt { font-weight: 900; text-align: right; white-space: nowrap; }
.amt.plus { color: #138a4d; }
.amt.minus { color: var(--tomato); }

/* ---------- sheet */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: grid; align-items: end; justify-items: center; }
.sheet-bg { position: absolute; inset: 0; background: #2a184066; backdrop-filter: blur(2px); animation: fade .2s; }
.sheet {
  position: relative; width: min(640px, 100%); max-height: 92vh; overflow: auto; background: var(--paper);
  border: 3px solid var(--line); border-bottom: 0; border-radius: 28px 28px 0 0;
  padding: 10px 18px calc(22px + env(safe-area-inset-bottom, 0px)); animation: up .3s cubic-bezier(.2, 1.1, .4, 1);
}
.sheet .grab { width: 48px; height: 5px; border-radius: 9px; background: #2a184033; margin: 0 auto 12px; }
.sheet h2 { font-size: 20px; margin-bottom: 14px; display: flex; justify-content: space-between; align-items: center; }
.sheet h2 button { border: 0; background: none; font-size: 26px; line-height: 1; }
.form { display: grid; gap: 14px; }
.kinds { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.kind {
  border: 2.5px solid var(--line); border-radius: 14px; background: #fff; padding: 9px 4px; font-weight: 800; font-size: 13px;
  display: grid; justify-items: center; gap: 2px; line-height: 1.1;
}
.kind span { font-size: 22px; }
.kind.on { background: var(--c); box-shadow: 3px 3px 0 var(--line); transform: translate(-1px, -1px); }
.who { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.who button { border: 2.5px solid var(--line); background: #fff; border-radius: 14px; padding: 10px; font-weight: 800; display: flex; gap: 8px; align-items: center; justify-content: center; }
.who button.on { background: var(--c); color: #fff; box-shadow: 3px 3px 0 var(--line); }
.amount-row { display: grid; grid-template-columns: 1fr; gap: 8px; }
.amount-row input { font-family: var(--display); font-size: 26px; padding: 12px 14px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actions { display: flex; gap: 10px; }
.actions .btn { flex: 1; }
.hint { font-size: 13px; color: var(--muted); font-weight: 700; margin-top: -6px; }
.country-list { max-height: 260px; overflow: auto; border: 2.5px solid var(--line); border-radius: 14px; background: #fff; }
.country-list button { display: flex; gap: 10px; align-items: center; width: 100%; padding: 8px 12px; border: 0; background: none; font-weight: 700; text-align: left; }
.country-list button:hover, .country-list button.on { background: #fff0c2; }
.country-list .flag { width: 28px; height: 28px; border-width: 2px; }
.picked { display: flex; gap: 10px; align-items: center; font-weight: 800; }
.palette { display: flex; gap: 8px; flex-wrap: wrap; }
.palette button { width: 34px; height: 34px; border-radius: 50%; border: 2.5px solid var(--line); }
.palette button.on { outline: 3px solid var(--ink); outline-offset: 2px; }
.ucard { display: grid; gap: 10px; }

.toast {
  position: fixed; left: 50%; bottom: calc(100px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 999px; font-weight: 800; z-index: 30;
  animation: up .25s; max-width: calc(100% - 32px); text-align: center;
}

/* ---------- confetti */
.confetti { position: fixed; top: -20px; width: 10px; height: 14px; z-index: 40; pointer-events: none; animation: fall linear forwards; }

@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }
@keyframes wiggle { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg) translateY(-4px); } }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

@media (max-width: 380px) {
  .quick { gap: 6px; }
  .mrow, .mhead { grid-template-columns: 74px 1fr 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* не даём длинным строкам распирать сетку */
.form > *, .row2 > *, .card, .hlist, .hitem { min-width: 0; }
input { min-width: 0; }
.sheet { overflow-x: hidden; }

/* ---------- телефон */
.link { border: 0; background: none; font-weight: 800; color: var(--tomato); font-size: 14px; padding: 8px 0; white-space: nowrap; }
.chip { min-height: 40px; }
.sheet { max-height: 92vh; max-height: 92dvh; overscroll-behavior: contain; }
.actions.sticky {
  position: sticky; bottom: calc(-22px - env(safe-area-inset-bottom, 0px)); z-index: 2;
  margin: 0 -18px; padding: 12px 18px calc(14px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(transparent, var(--paper) 18px);
}
.totals .big { font-size: clamp(16px, 5.2vw, 20px); white-space: nowrap; }
.hero .total { white-space: nowrap; }
.coin { font-size: 15px; }
body { -webkit-text-size-adjust: 100%; overscroll-behavior-y: none; }
input, select, textarea { font-size: 16px; } /* iOS не зумит поля от 16px */
.amount-row input { font-size: 26px; }
@media (max-width: 380px) {
  .sec-title h2 { font-size: 16px; }
  .person { padding: 12px 8px; }
  .ring { width: 78px; height: 78px; }
  .ring .face { font-size: 28px; }
}
.view > *, .hgroup, .people > *, .trips > * { min-width: 0; }
html, body { overflow-x: hidden; }
.hitem .s { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -16px; padding: 2px 16px 6px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.chips.scroll .chip { flex: none; }
.prof { display: flex; align-items: center; gap: 12px; }
.prof b { font-family: var(--display); font-size: 16px; }
.prof-av { width: 56px; height: 56px; border-radius: 50%; border: 2.5px solid var(--line); display: grid; place-items: center; font-size: 30px; box-shadow: 2px 2px 0 var(--line); }
.emojis { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; max-height: 196px; overflow-y: auto; padding: 2px; }
.emojis button { height: 44px; border: 2px solid transparent; background: #fff; border-radius: 12px; font-size: 24px; }
.emojis button.on { border-color: var(--line); background: var(--sun); }
.cur-more { display: grid; gap: 8px; }

/* ---------- компактный телефон: лента прижата к низу, главный экран помещается над ней */
@media (max-width: 520px) {
  #main { padding-bottom: calc(76px + env(safe-area-inset-bottom, 0px)); }
  .tabs {
    left: 0; right: 0; bottom: 0; transform: none; width: 100%;
    border-radius: 20px 20px 0 0; padding: 5px 8px calc(5px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -4px 20px #2a184033;
  }
  .tabs button { padding: 5px 2px 4px; font-size: 11px; border-radius: 14px; }
  .tabs button span { font-size: 19px; }
  .top { padding-bottom: 6px; }
  .view { gap: 14px; }
  .hero { padding: 14px 16px; border-radius: 22px; box-shadow: 5px 5px 0 var(--line); }
  .hero .total { font-size: clamp(30px, 9vw, 40px); }
  .coins { margin-top: 10px; gap: 6px; }
  .coin { font-size: 14px; padding: 4px 10px 4px 4px; }
  .quick { grid-template-columns: repeat(4, 1fr); }
  .qa { padding: 8px 2px 7px; font-size: 11.5px; border-radius: 15px; gap: 2px; }
  .qa span { font-size: 22px; }
  .people { margin-top: 8px !important; gap: 10px; }
  .person { padding: 10px 8px 12px; }
  .ring { width: 68px; height: 68px; margin-bottom: 4px; }
  .ring .face { font-size: 26px; }
  .person b { font-size: 14px; }
  .person .sum { font-size: 13px; }
  .person .st { margin-top: 4px; font-size: 12px; }
  .stamp { font-size: 10px; }
  .hero .lbl { font-size: 13px; }
  .hero .rates { font-size: 11px; }
  .coins { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .coin { font-size: 12.5px; padding: 3px 6px 3px 3px; gap: 4px; min-width: 0; white-space: nowrap; overflow: hidden; }
  .coin i { width: 21px; height: 21px; font-size: 10.5px; flex: none; }
  .sec-title h2 { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
}
.coin-empty { grid-column: 1 / -1; justify-self: start; }
.kinds .kind:last-child:nth-child(3n+1) { grid-column: 1 / -1; display: flex; justify-content: center; gap: 8px; align-items: center; }
.spent + .spent { margin-top: 2px; }
@media (max-width: 520px) { .seg button { font-size: 12.5px; padding: 8px 2px; white-space: nowrap; } }
