/* Fair Split — styles. Come Alone family tokens; dark via prefers-color-scheme. */
:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #efebe4;
  --text: #1d1a22;
  --muted: #625d69;
  --line: rgba(29,26,34,.12);
  --accent: #2fb3a6;
  --accent-ink: #10201e;
  --pink: #ff5c8a;
  --pos: #12806a;
  --neg: #c8324f;
  --warn-bg: #fff3d6;
  --warn-ink: #6b4a00;
  --shadow: 0 10px 30px rgba(29,26,34,.08);
  --radius: 20px;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15131a;
    --surface: #201d27;
    --surface-2: #2a2633;
    --text: #f3f0f7;
    --muted: #a8a2b1;
    --line: rgba(243,240,247,.12);
    --pos: #4fd1b0;
    --neg: #ff7a93;
    --warn-bg: #3a2f14;
    --warn-ink: #ffd88a;
    --shadow: 0 10px 30px rgba(0,0,0,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; font-family: var(--font); font-weight: 500; background: var(--bg); color: var(--text);
  line-height: 1.45; min-height: 100dvh; display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.15; font-weight: 900; letter-spacing: -.01em; }
p { margin: 0; }
ul, ol { margin: 0; padding: 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--accent); color: var(--accent-ink); padding: 8px 14px; border-radius: 10px; font-weight: 800; z-index: 10; }
.skip:focus { left: 8px; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
main:focus, h1:focus { outline: none; }

/* Header */
.top { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; max-width: 720px; width: 100%; margin: 0 auto; }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; font-weight: 900; font-size: 1.15rem; }
.brand-mark { width: 32px; height: 32px; color: var(--accent); }
.lang-wrap select { font-weight: 700; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 999px; padding: 8px 14px; cursor: pointer; }

/* Main */
.app { flex: 1; width: 100%; max-width: 720px; margin: 0 auto; padding: 8px 16px 32px; }
.screen { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

.hero { padding: 12px 0 16px; }
.hero h1 { font-size: clamp(2rem, 7vw, 2.8rem); }
.hero p { color: var(--muted); margin-top: 8px; font-size: 1.05rem; }
.how { list-style: none; margin-top: 14px; display: grid; gap: 8px; counter-reset: how; }
.how li { counter-increment: how; display: flex; gap: 10px; align-items: baseline; font-weight: 700; }
.how li::before { content: counter(how); flex: 0 0 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-ink); display: grid; place-items: center; font-weight: 900; font-size: .85rem; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); margin-top: 12px; }
.panel h2 { font-size: 1.15rem; display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.panel h2 small { color: var(--muted); font-weight: 700; font-size: .9rem; }
.panel h1 { font-size: 1.4rem; }
.lead { color: var(--muted); margin-top: 8px; font-size: 1.05rem; }
.hint { color: var(--muted); font-size: .92rem; margin-top: 6px; }
.hint.pad { padding: 12px 4px 0; }
.center { text-align: center; }
.err { color: var(--neg); font-weight: 800; margin-top: 10px; }
.err:empty { display: none; }
.warn { background: var(--warn-bg); color: var(--warn-ink); border-radius: 14px; padding: 12px 14px; font-weight: 700; margin-top: 12px; }
.warn a { font-weight: 900; }
.ok-line { margin-top: 10px; font-weight: 800; color: var(--pos); }

/* Groups list */
.glist { list-style: none; margin-top: 10px; display: grid; gap: 10px; }
.gcard { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; text-decoration: none; background: var(--surface-2); border-radius: 16px; padding: 14px 16px; }
.gname { font-weight: 900; font-size: 1.1rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.gmeta { color: var(--muted); font-size: .9rem; grid-column: 1; }
.gtotal { grid-column: 2; grid-row: 1 / span 2; align-self: center; font-weight: 900; }

/* Forms */
.field { margin-top: 14px; min-width: 0; }
.field label { display: block; font-weight: 700; font-size: .9rem; color: var(--muted); margin-bottom: 6px; }
.field input, .field select, .add-row input, .share-out input, .copybox {
  width: 100%; font-weight: 700; padding: 12px 14px; border-radius: 14px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); min-width: 0; min-height: 48px;
}
.copybox { margin-top: 12px; font-family: ui-monospace, monospace; font-size: .85rem; font-weight: 500; }
.cur-in { text-transform: uppercase; }
.two { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 420px) { .two { grid-template-columns: 1.4fr 1fr; } }
.add-row { display: flex; gap: 8px; margin-top: 12px; }
.add-row input { flex: 1; }

.chips { list-style: none; display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.chip { display: inline-flex; align-items: center; gap: 4px; background: var(--surface-2); border-radius: 999px; padding: 6px 6px 6px 14px; font-weight: 700; max-width: 100%; }
.chip button { border: 0; background: transparent; width: 32px; height: 32px; border-radius: 50%; cursor: pointer; color: var(--muted); font-size: 1.2rem; line-height: 1; display: grid; place-items: center; }
.chip button:hover { background: var(--line); color: var(--text); }

.seg { display: flex; background: var(--surface-2); border-radius: 14px; padding: 4px; gap: 4px; margin-top: 10px; }
.seg button, .seg a { flex: 1; border: 0; background: transparent; border-radius: 11px; padding: 10px 6px; font-weight: 800; cursor: pointer; color: var(--muted); text-align: center; text-decoration: none; font-size: .95rem; min-height: 44px; display: grid; place-items: center; }
.seg .on { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.tabs { margin-top: 0; position: sticky; top: 0; z-index: 2; box-shadow: 0 6px 14px var(--bg); }

.among-head { display: flex; justify-content: space-between; align-items: center; margin-top: 16px; }
.among-head .hint { margin: 0; font-weight: 700; }
.link { border: 0; background: none; color: var(--text); font-weight: 800; text-decoration: underline; cursor: pointer; padding: 8px; }
.among { margin-top: 6px; display: grid; gap: 6px; }
.among-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px; border-radius: 12px; background: var(--surface-2); min-height: 52px; }
.among-row:not(.on) { opacity: .7; }
.among-row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: 0 0 22px; margin: 0; }
.among-row label { flex: 1; font-weight: 800; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 8px 0; }
.mini { width: 110px; flex: 0 0 110px; font-weight: 800; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--bg); color: var(--text); text-align: right; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 0; border-radius: 16px;
  padding: 14px 20px; font-weight: 900; font-size: 1.05rem; cursor: pointer; background: var(--surface-2); color: var(--text);
  text-decoration: none; transition: transform .12s ease; min-height: 48px; text-align: center;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; border: 1px solid var(--neg); color: var(--neg); }
.btn.block { width: 100%; display: flex; }
.btn.big { padding: 16px 22px; font-size: 1.1rem; }
.btn.small { padding: 8px 12px; font-size: .9rem; min-height: 40px; border-radius: 12px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }
.row .btn { flex: 1 1 140px; }

/* Group head */
.g-head { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; }
.g-head .back { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; width: 44px; height: 44px; flex: 0 0 44px; display: grid; place-items: center; }
.g-head .back svg { width: 22px; height: 22px; }
.g-head h1 { font-size: 1.4rem; flex: 1; overflow-wrap: anywhere; }

/* Expenses */
.exp-list { list-style: none; margin-top: 8px; }
.exp-list li + li { border-top: 1px solid var(--line); }
.exp { display: flex; justify-content: space-between; gap: 12px; padding: 12px 4px; text-decoration: none; align-items: center; border-radius: 10px; }
.exp:hover { background: var(--surface-2); }
.exp-main { display: flex; flex-direction: column; min-width: 0; }
.exp-title { font-weight: 800; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.exp-meta { color: var(--muted); font-size: .85rem; }
.exp-amt { text-align: right; display: flex; flex-direction: column; flex: 0 0 auto; }
.exp-amt small { color: var(--muted); font-size: .8rem; }
.exp.is-transfer .exp-title { color: var(--muted); }

/* Settle */
.total { display: flex; justify-content: space-between; align-items: center; }
.total .hint { margin: 0; font-weight: 700; }
.big-num { font-size: 1.6rem; font-weight: 900; }
.bal { list-style: none; margin-top: 8px; }
.bal li { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap; }
.bal li:first-child { border-top: 0; }
.bal li span { font-weight: 800; }
.bal li b { color: var(--muted); font-weight: 800; }
.bal li.pos b { color: var(--pos); }
.bal li.neg b { color: var(--neg); }
.transfers { list-style: none; margin-top: 8px; display: grid; gap: 8px; }
.transfers li { display: grid; grid-template-columns: 1fr auto; gap: 8px 12px; align-items: center; background: var(--surface-2); border-radius: 14px; padding: 12px 14px; }
.tr-who { overflow-wrap: anywhere; }
.tr-amt { font-weight: 900; font-size: 1.1rem; }
.transfers .btn { grid-column: 1 / -1; justify-self: start; }
@media (min-width: 520px) { .transfers li { grid-template-columns: 1fr auto auto; } .transfers .btn { grid-column: auto; } }

/* Share */
.share-out { margin-top: 12px; }
.share-out input { font-family: ui-monospace, monospace; font-size: .85rem; font-weight: 500; }
.qr { margin: 16px auto 0; width: min(100%, 320px); background: #fff; border-radius: 16px; padding: 8px; }
.qr svg { display: block; width: 100%; height: auto; }

/* Toast */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom)); transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 12px 18px; border-radius: 14px; font-weight: 800; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100% - 32px); z-index: 20; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* Footer */
.foot { max-width: 720px; width: 100%; margin: 0 auto; padding: 20px 16px 36px; color: var(--muted); font-size: .92rem; text-align: center; border-top: 1px solid var(--line); }
.foot-line + .foot-line { margin-top: 8px; }
.foot-line a { color: var(--text); font-weight: 700; }
.foot-line.small { font-size: .85rem; }
.foot .mm { margin-top: 14px; }

@media (prefers-reduced-motion: reduce) { .screen { animation: none; } .btn, .toast { transition: none; } }
