:root {
  --bg: #f6f5f2;
  --card: #fffefb;
  --ink: #1a1a18;
  --muted: #6b6a64;
  --line: #e2e0d8;
  --accent: #1f6f4a;
  --accent-ink: #ffffff;
  --danger: #a3341f;
  --radius: 14px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14140f;
    --card: #1d1d18;
    --ink: #ecebe4;
    --muted: #9a988e;
    --line: #33322a;
    --accent: #4fbe86;
    --accent-ink: #10231a;
    --danger: #e0785f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-text-size-adjust: 100%;
}

main { max-width: 46rem; margin: 0 auto; padding: 1rem 1rem 5rem; }

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  max-width: 46rem; margin: 0 auto; padding: 1rem;
}
.brand {
  font-weight: 700; letter-spacing: -0.02em; text-decoration: none; color: var(--ink);
  font-size: 1.1rem;
}
.brand::before { content: "🧾 "; }

h1 { font-size: 1.5rem; letter-spacing: -0.02em; margin: 0 0 .25rem; }
h2 { font-size: 1rem; letter-spacing: .02em; text-transform: uppercase; color: var(--muted);
     margin: 1.75rem 0 .5rem; font-weight: 600; }
h2 .muted { text-transform: none; letter-spacing: 0; font-weight: 400; }

.muted { color: var(--muted); }
.error { color: var(--danger); font-weight: 500; }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 1.25rem;
}
.card.narrow { max-width: 24rem; margin: 3rem auto; }

.stack { display: flex; flex-direction: column; gap: .35rem; margin-top: .75rem; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
@media (max-width: 30rem) { .grid3 { grid-template-columns: 1fr; } .grid2 { grid-template-columns: 1fr; } }

label { font-size: .85rem; color: var(--muted); }

input, textarea, select {
  font: inherit; color: inherit; background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem .7rem; width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; }

button {
  font: inherit; cursor: pointer; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); color: var(--ink); padding: .6rem 1rem;
}
button.primary {
  background: var(--accent); color: var(--accent-ink); border-color: var(--accent);
  font-weight: 600; width: 100%; margin-top: 1.25rem; padding: .8rem 1rem;
}
button.ghost { background: transparent; color: var(--muted); margin-top: .5rem; }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0; }
button:disabled { opacity: .45; cursor: not-allowed; }

a.button {
  display: inline-block; text-decoration: none; margin-top: 1rem;
  border: 1px solid var(--line); border-radius: 10px; padding: .6rem 1rem; color: var(--ink);
}

.rows { display: flex; flex-direction: column; gap: .5rem; }
.row { display: grid; grid-template-columns: 1fr 6rem 4rem 2rem; gap: .5rem; align-items: center; }
@media (max-width: 30rem) { .row { grid-template-columns: 1fr 5rem 3.5rem 2rem; } }
.row button { padding: .4rem .5rem; color: var(--muted); }

/* participant picker */
.picker { display: flex; flex-direction: column; gap: .5rem; }
.picker button {
  text-align: left; padding: .85rem 1rem; display: flex; justify-content: space-between; gap: 1rem;
}
.picker button.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }

/* item lists */
.items { display: flex; flex-direction: column; gap: .25rem; }
.item {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding: .7rem .25rem; border-bottom: 1px solid var(--line);
}
.item:last-child { border-bottom: none; }
.item .name { font-weight: 500; }
.item .sub { font-size: .82rem; color: var(--muted); }
.item .amount { font-variant-numeric: tabular-nums; white-space: nowrap; }

.stepper { display: flex; align-items: center; gap: .5rem; }
.stepper button { width: 2.2rem; height: 2.2rem; padding: 0; font-size: 1.1rem; line-height: 1; }
.stepper .count { min-width: 1.5rem; text-align: center; font-variant-numeric: tabular-nums; }

.totals { margin-top: 1rem; }
.totals .line {
  display: flex; justify-content: space-between; padding: .25rem 0; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.totals .line.grand {
  color: var(--ink); font-size: 1.4rem; font-weight: 700; border-top: 1px solid var(--line);
  margin-top: .5rem; padding-top: .75rem;
}

.warn {
  background: color-mix(in srgb, var(--danger) 12%, var(--card));
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line));
  border-radius: 10px; padding: .7rem .85rem; margin-top: 1rem; font-size: .9rem;
}

.covering { font-size: .85rem; color: var(--muted); margin-top: .25rem; }

.qr { margin-top: 1rem; display: flex; justify-content: center; }
.qr svg { width: min(220px, 60vw); height: auto; background: #fff; padding: 8px; border-radius: 8px; }

.result { margin-top: 1.5rem; border-top: 1px solid var(--line); padding-top: 1rem; }

.toast {
  position: fixed; left: 50%; bottom: 1.25rem; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: .6rem 1rem; border-radius: 999px;
  font-size: .9rem; max-width: 90vw;
}
