:root {
  --paper: #f5f3ec;
  --card: #fffefa;
  --ink: #17231d;
  --muted: #68736c;
  --line: #e2dfd3;
  --pitch: #0d5c3f;
  --pitch-tint: #dcefe4;
  --owed: #0d7a50;
  --owes: #c8352a;
  --display: "Barlow Condensed", "Arial Narrow", sans-serif;
  --body: "Barlow", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--paper); color: var(--ink); font: 500 17px/1.35 var(--body); }
h1, h2, p { margin: 0; }
ul { list-style: none; margin: 0; padding: 0; }
a { color: inherit; }
button { font: inherit; cursor: pointer; }
.app { width: 100%; max-width: 30rem; margin: 0 auto; padding: 0 16px calc(96px + env(safe-area-inset-bottom)); }

header { padding: 18px 0 10px; }
header h1 { font: 700 30px/1.1 var(--display); letter-spacing: .01em; text-transform: uppercase; }
nav { display: flex; gap: 22px; margin-top: 10px; border-bottom: 1px solid var(--line); }
.tab { display: flex; align-items: center; min-height: 44px; color: var(--muted); font-weight: 600; text-decoration: none; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tab.active { color: var(--ink); border-color: var(--pitch); }
.back { display: inline-flex; align-items: center; min-height: 44px; color: var(--muted); text-decoration: none; font-weight: 600; }

.hero { margin: 14px 0; padding: 18px 20px; border-radius: 14px; background: var(--pitch); color: #fff; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; opacity: .8; }
.hero-name { font: 700 52px/1 var(--display); margin-top: 4px; }
.hero-sub { font-size: 18px; opacity: .9; }

.list { display: grid; gap: 6px; margin-top: 12px; }
.row, .card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.row { display: flex; align-items: center; gap: 12px; padding: 10px 14px; min-height: 60px; }
.who { flex: 1; min-width: 0; color: var(--muted); }
.who strong { color: var(--ink); }
.amount { font: 700 24px/1 var(--display); font-variant-numeric: tabular-nums; }
.owes .amount { color: var(--owes); }
.owed .amount { color: var(--owed); }
.square .amount { color: var(--muted); }

.avatar { display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: 50%; font: 700 22px/1 var(--display); color: oklch(36% .09 var(--hue)); background: oklch(90% .05 var(--hue)); }

.card summary { display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 14px; min-height: 60px; cursor: pointer; list-style: none; }
.card summary::-webkit-details-marker { display: none; }
.card .who strong, .sub { display: block; }
.sub { color: var(--muted); font-size: 14px; }
.right { text-align: right; }
.shares { padding: 0 14px; border-top: 1px solid var(--line); }
.shares li { display: flex; justify-content: space-between; padding: 8px 0; font-variant-numeric: tabular-nums; }
.card form { padding: 0 14px 6px; }
.card.deleted summary strong { text-decoration: line-through; color: var(--muted); }
.note { padding: 14px; color: var(--muted); font-size: 15px; background: transparent; border-style: dashed; }

.link { background: none; border: 0; padding: 0 2px; min-height: 44px; color: var(--pitch); font-weight: 700; }
.link.danger { color: var(--owes); }
.link.quiet { color: var(--muted); font-weight: 600; }

.fab { position: fixed; left: max(16px, calc(50vw - 15rem + 16px)); right: max(16px, calc(50vw - 15rem + 16px)); bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; align-items: center; justify-content: center; min-height: 54px; border-radius: 27px; background: var(--pitch); color: #fff; font-weight: 700; text-decoration: none; box-shadow: 0 6px 18px rgb(13 92 63 / .35); }
.banner { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 12px; padding: 4px 14px; border-radius: 12px; background: var(--pitch-tint); }

.section-title { display: block; font: 700 19px/1.2 var(--display); letter-spacing: .04em; text-transform: uppercase; margin: 20px 0 8px; }
.amount-field { display: flex; align-items: baseline; padding: 4px 14px; font: 700 54px/1.1 var(--display); background: var(--card); border: 1px solid var(--line); border-radius: 12px; color: var(--pitch); }
.amount-field:focus-within { outline: 2px solid var(--pitch); }
.amount-field input { flex: 1; min-width: 0; width: 100%; border: 0; outline: 0; background: none; font: inherit; color: inherit; }

.grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 6px; }
.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 2px 8px; min-height: 84px; border: 2px solid var(--line); border-radius: 12px; background: var(--card); cursor: pointer; -webkit-tap-highlight-color: transparent; user-select: none; }
.tile input { position: absolute; opacity: 0; pointer-events: none; }
.tile .name { max-width: 100%; padding: 0 4px; font-size: 15px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile:has(input:checked) { border-color: var(--pitch); background: var(--pitch-tint); }
.tile:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 1px; }
#payer-grid .tile:has(input:checked) { background: var(--pitch); color: #fff; }
#played-grid .tile:not(:has(input:checked)) .avatar { filter: grayscale(1); opacity: .55; }
#played-grid .tile:not(:has(input:checked)) .name { color: var(--muted); }
#played-grid .tile:has(input:checked)::after { content: "✓"; position: absolute; top: 3px; right: 7px; color: var(--pitch); font-weight: 700; font-size: 14px; }
.tag { position: absolute; top: -8px; padding: 0 6px; border-radius: 8px; background: var(--ink); color: #fff; font-size: 11px; font-weight: 700; line-height: 16px; white-space: nowrap; }

.savebar { position: fixed; left: 0; right: 0; bottom: 0; display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 10px max(16px, calc(50vw - 15rem + 16px)) calc(10px + env(safe-area-inset-bottom)); background: var(--card); border-top: 1px solid var(--line); }
.summary { display: flex; flex-direction: column; line-height: 1.2; font-variant-numeric: tabular-nums; }
.summary span { color: var(--muted); }
.primary { min-height: 50px; padding: 0 24px; border: 0; border-radius: 25px; background: var(--pitch); color: #fff; font-weight: 700; }
.primary:disabled { background: var(--line); color: var(--muted); cursor: default; }
.error { color: var(--owes); font-weight: 600; }
.error:empty { display: none; }
main > .error { margin-top: 8px; }

dialog { width: min(22rem, calc(100vw - 32px)); padding: 18px; border: 0; border-radius: 14px; background: var(--card); color: var(--ink); }
dialog::backdrop { background: rgb(23 35 29 / .5); }
dialog h2 { font: 700 24px/1.1 var(--display); text-transform: uppercase; }
dialog input { width: 100%; min-height: 48px; margin: 12px 0 6px; padding: 0 12px; font: inherit; font-size: 18px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
.dialog-actions { display: flex; justify-content: flex-end; align-items: center; gap: 16px; margin-top: 8px; }
