:root {
  --ink: #17140f;
  --paper: #fffaf0;
  --yellow: #ffd84d;
  --pink: #ff5c8a;
  --green: #2ecc71;
  --green-soft: #d8f8e4;
  --orange-soft: #ffe7c7;
  --muted: #6b6458;
  --line: 2.5px solid var(--ink);
  --shadow: 4px 4px 0 var(--ink);
  --radius: 16px;
  --display: 'Bricolage Grotesque', system-ui, sans-serif;
  --body: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--body);
  color: var(--ink);
  background: var(--paper);
  background-image: radial-gradient(#e9dfc9 1px, transparent 1px);
  background-size: 18px 18px;
  min-height: 100vh;
  padding-bottom: 96px;
}
button { font: inherit; color: inherit; cursor: pointer; }
h1, h2 { font-family: var(--display); margin: 0; }

/* ---------- Hero ---------- */
.hero {
  background: var(--yellow);
  border-bottom: var(--line);
  padding: 28px 16px 22px;
}
.hero-inner { max-width: 720px; margin: 0 auto; }
.hero h1 {
  font-size: clamp(2.6rem, 11vw, 4.2rem);
  line-height: .9;
  font-weight: 800;
  letter-spacing: -.03em;
}
.hero h1 span:first-of-type { color: var(--pink); -webkit-text-stroke: 2px var(--ink); }
.wiggle { display: inline-block; animation: wiggle 2.4s ease-in-out infinite; -webkit-text-stroke: 0 !important; }
@keyframes wiggle { 0%,100% { transform: rotate(-8deg); } 50% { transform: rotate(10deg) scale(1.08); } }

.frase {
  display: block;
  margin: 14px 0 16px;
  padding: 10px 14px;
  background: #fff;
  border: var(--line);
  border-radius: 14px 14px 14px 4px;
  box-shadow: var(--shadow);
  font-weight: 600;
  font-size: 1.02rem;
  text-align: left;
  width: 100%;
  transition: transform .15s;
}
.frase:active { transform: translate(2px, 2px); box-shadow: 2px 2px 0 var(--ink); }
.frase { transition: transform .15s, opacity .25s, filter .25s; }
.frase.trocando { opacity: 0; filter: blur(3px); }

.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat {
  background: #fff; border: var(--line); border-radius: 12px; padding: 10px 8px; text-align: center;
}
.stat b { display: block; font-family: var(--display); font-size: clamp(1rem, 4.6vw, 1.4rem); white-space: nowrap; }
.stat small { color: var(--muted); font-weight: 600; font-size: .78rem; }

/* ---------- Buttons ---------- */
.btn {
  border: var(--line); border-radius: 12px; padding: 12px 16px; font-weight: 700;
  background: #fff; box-shadow: var(--shadow); transition: transform .1s, box-shadow .1s;
}
.btn:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--ink); }
.btn-primary { background: var(--pink); color: #fff; width: 100%; font-size: 1.08rem; font-family: var(--display); }
.btn-ghost { width: 100%; background: #fff; }
.btn-small { padding: 8px 12px; box-shadow: 2px 2px 0 var(--ink); font-size: .9rem; }
.btn[disabled] { opacity: .6; pointer-events: none; }
.link { background: none; border: 0; padding: 0; text-decoration: underline; font-weight: 600; color: var(--muted); }

.fab {
  position: fixed; right: 16px; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 5;
  background: var(--ink); color: var(--yellow); border: 0; border-radius: 999px;
  padding: 16px 22px; font-family: var(--display); font-weight: 800; font-size: 1.08rem;
  box-shadow: 4px 4px 0 var(--pink);
}
.fab:active { transform: translate(3px, 3px); box-shadow: 1px 1px 0 var(--pink); }

/* ---------- Layout ---------- */
main { max-width: 720px; margin: 0 auto; padding: 20px 16px; display: grid; gap: 24px; }
.card { background: #fff; border: var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }
h2 { font-size: 1.45rem; font-weight: 800; }

.filters { display: flex; gap: 6px; }
.chip-filter { border: 2px solid var(--ink); background: #fff; border-radius: 999px; padding: 6px 12px; font-weight: 600; font-size: .88rem; }
.chip-filter.active { background: var(--ink); color: #fff; }

/* ---------- Ranking ---------- */
.ranking h2 { margin-bottom: 10px; }
.rank-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.rank-list li {
  display: grid; grid-template-columns: 34px 1fr auto; align-items: center; gap: 8px;
  padding: 8px 10px; border-radius: 10px; background: #faf6ec;
}
.rank-list li.top { background: #ffe1ea; border: 2px solid var(--ink); }
.rank-pos { font-family: var(--display); font-weight: 800; font-size: 1.15rem; text-align: center; }
.rank-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rank-name small { display: block; font-weight: 500; color: var(--muted); font-size: .76rem; }
.rank-val { font-family: var(--display); font-weight: 800; white-space: nowrap; }
.rank-list li.clean .rank-val { color: #1e9e57; font-family: var(--body); font-weight: 600; font-size: .88rem; }
.empty { color: var(--muted); text-align: center; padding: 16px 8px; font-weight: 500; }

/* ---------- Compras ---------- */
.compras { display: grid; gap: 16px; }
.compra { position: relative; overflow: hidden; }
.compra-top { display: grid; grid-template-columns: 48px 1fr auto; gap: 12px; align-items: start; }
.compra-emoji { font-size: 2rem; width: 48px; height: 48px; display: grid; place-items: center; background: var(--yellow); border: 2px solid var(--ink); border-radius: 12px; }
.compra-titulo { font-family: var(--display); font-weight: 800; font-size: 1.2rem; line-height: 1.15; word-break: break-word; }
.compra-meta { color: var(--muted); font-size: .84rem; margin-top: 3px; }
.compra-total { font-family: var(--display); font-weight: 800; font-size: 1.15rem; white-space: nowrap; text-align: right; }
.compra-total small { display: block; font-family: var(--body); font-weight: 500; font-size: .76rem; color: var(--muted); }

.progress { height: 10px; background: #eee6d4; border-radius: 999px; margin: 14px 0 10px; overflow: hidden; border: 2px solid var(--ink); }
.progress > i { display: block; height: 100%; background: var(--green); transition: width .4s; }
.progress-label { font-size: .84rem; font-weight: 600; margin-bottom: 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  border: 2px solid var(--ink); border-radius: 999px; padding: 5px 10px;
  font-size: .86rem; font-weight: 600; background: var(--orange-soft);
  max-width: 100%;
}
.chip .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
.chip.pago { background: var(--green-soft); }
.chip.pago .nm { text-decoration: line-through; text-decoration-thickness: 2px; opacity: .7; }
button.chip { transition: transform .1s; }
button.chip:active { transform: scale(.94); }
.owner-hint { font-size: .78rem; color: var(--muted); margin-top: 8px; }

.zoeira { margin-top: 12px; padding: 8px 12px; border-radius: 10px; background: #fff3f6; border: 2px dashed var(--pink); font-weight: 600; font-size: .9rem; }
.compra-acoes { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.compra-acoes .btn { flex: 1 1 auto; }
.btn-danger { background: #fff; color: #c0193f; }
.btn-danger.confirm { background: #c0193f; color: #fff; }

.carimbo {
  position: absolute; top: 14px; right: -38px; transform: rotate(32deg);
  background: var(--green); color: #fff; font-family: var(--display); font-weight: 800;
  padding: 4px 44px; border: 2px solid var(--ink); font-size: .8rem; letter-spacing: .06em;
}
.compra.quitada .compra-total { margin-right: 26px; }

/* ---------- Modal ---------- */
dialog {
  border: var(--line); border-radius: 20px; padding: 0; width: min(520px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px); background: var(--paper); color: var(--ink); box-shadow: 6px 6px 0 var(--ink);
}
dialog::backdrop { background: rgba(23, 20, 15, .55); backdrop-filter: blur(2px); }
dialog form { padding: 18px 16px 20px; display: grid; gap: 14px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.x { border: 2px solid var(--ink); background: #fff; border-radius: 10px; width: 36px; height: 36px; font-weight: 700; }
.field { display: grid; gap: 6px; font-weight: 700; font-size: .95rem; }
.field small { font-weight: 500; color: var(--muted); }
.field input, .field select, .add-colega input {
  font: inherit; font-weight: 500; font-size: 16px; padding: 11px 12px; border: 2px solid var(--ink);
  border-radius: 10px; background: #fff; width: 100%; color: var(--ink);
}
.field input:focus, .field select:focus, .add-colega input:focus { outline: 3px solid var(--yellow); outline-offset: 1px; }
.money { display: flex; align-items: center; border: 2px solid var(--ink); border-radius: 10px; background: #fff; }
.money span { padding-left: 12px; font-weight: 700; }
.money input { border: 0 !important; outline: none !important; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.mini-actions { font-size: .85rem; color: var(--muted); }
.chips .opt { background: #fff; }
.chips .opt[aria-pressed="true"] { background: var(--yellow); }
.add-colega { display: flex; gap: 8px; margin-top: 6px; }
.add-colega .btn { white-space: nowrap; }
.preview { background: var(--ink); color: var(--yellow); border-radius: 12px; padding: 12px 14px; font-weight: 700; font-family: var(--display); font-size: 1.05rem; }
.erro { color: #c0193f; font-weight: 600; margin: 0; min-height: 0; }
.erro:empty { display: none; }
.muted { color: var(--muted); margin: 0; }
.msg-preview {
  margin: 0; white-space: pre-wrap; word-break: break-word; font-family: var(--body); font-size: .9rem;
  background: #e7fbe9; border: 2px solid var(--ink); border-radius: 12px 12px 12px 4px; padding: 12px;
  max-height: 40vh; overflow: auto;
}
#cobrarModal .btn { width: 100%; }

/* ---------- Toast, confete, footer ---------- */
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--ink); color: #fff; padding: 12px 16px; border-radius: 12px; font-weight: 600;
  width: max-content; max-width: calc(100vw - 32px); transition: .25s; z-index: 30; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
#confete { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }
footer { text-align: center; color: var(--muted); font-size: .8rem; padding: 8px 16px 24px; }

@media (prefers-reduced-motion: reduce) { .wiggle { animation: none; } }
