/*
  Evenly styles.
  Direction: flat color, thick black outlines, hard offset shadows, square corners.
  One loud color (lemon) on a warm grey page; the settle-up card is a lemon thermal slip.
*/
:root {
  --paper: #f3f1ec;
  --card: #ffffff;
  --ink: #111111;
  --muted: #5b5a55;
  --soft: #d6d2c8;
  --lemon: #ffd84d;
  --on-lemon: #111111;
  --good: #0a7d4b;
  --owe: #d42a1e;
  --shadow: #111111;
  --font-display: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Archivo", "Helvetica Neue", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --bw: 2px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #141414; --card: #1f1f1f; --ink: #f3f1ec; --muted: #a8a59b; --soft: #3a3833;
    --good: #4fd49a; --owe: #ff7a6b; --shadow: #f3f1ec;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #141414; --card: #1f1f1f; --ink: #f3f1ec; --muted: #a8a59b; --soft: #3a3833;
  --good: #4fd49a; --owe: #ff7a6b; --shadow: #f3f1ec;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--paper); color: var(--ink);
  font-family: var(--font-body); font-size: 16px; line-height: 1.5; font-weight: 450;
  -webkit-text-size-adjust: 100%;
}
h1, h2, h3 { font-family: var(--font-display); line-height: 1.1; margin: 0; text-wrap: balance; font-weight: 800; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
[hidden] { display: none !important; }

.wrap { max-width: 1080px; margin: 0 auto; padding: 20px 16px 72px; }

/* Buttons */
.btn {
  min-height: 46px; padding: 0 18px; border: var(--bw) solid var(--ink); border-radius: 4px; background: var(--card);
  font-weight: 700; cursor: pointer; box-shadow: 3px 3px 0 var(--shadow);
  transition: transform .08s ease, box-shadow .08s ease;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--shadow); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--shadow); }
.btn.primary { background: var(--lemon); color: var(--on-lemon); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 0.92rem; }
.btn.big { min-height: 56px; padding: 0 26px; font-size: 1.05rem; }
.btn.ghost { background: transparent; box-shadow: none; }
.btn.ghost:hover { transform: none; background: var(--card); }
.btn[data-armed] { background: var(--owe); color: #fff; }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; transform: none; }
.link { background: none; border: 0; padding: 10px; color: var(--muted); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }
.link:hover { color: var(--ink); }
@media (prefers-reduced-motion: reduce) { .btn { transition: none; } }

/* Header */
.top { display: flex; flex-direction: column; gap: 14px; margin-bottom: 22px; }
.brand { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.brand h1, .ob-brand {
  display: inline-block; margin: 0; padding: 3px 12px; background: var(--lemon); color: var(--on-lemon);
  border: var(--bw) solid var(--ink); font-size: 1.15rem; font-weight: 900; font-stretch: 125%;
  text-transform: uppercase; letter-spacing: 0.02em; transform: rotate(-1.5deg);
}
.brand p { margin: 0; color: var(--muted); font-size: 0.92rem; flex: 1 1 220px; }
input.group-name, input[type="text"].group-name {
  width: 100%; min-height: 0; border: 0; border-bottom: 3px solid var(--ink); background: transparent; border-radius: 0; padding-left: 0; padding-right: 0;
  font-family: var(--font-display); font-weight: 900; font-size: clamp(2rem, 8vw, 3.4rem); letter-spacing: -0.035em; line-height: 1.05; padding: 2px 0 6px;
}
.group-name::placeholder { color: var(--soft); }
input.group-name:focus-visible { outline: none; background: color-mix(in srgb, var(--lemon) 35%, transparent); }
[tabindex="-1"]:focus { outline: none; }
.people-bar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.person {
  display: inline-flex; align-items: center; gap: 2px; background: var(--card); border: var(--bw) solid var(--ink);
  border-radius: 4px; padding: 2px 2px 2px 12px; font-weight: 700;
}
.person button { width: 32px; height: 32px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 1.2rem; line-height: 1; display: grid; place-items: center; }
.person button:hover { color: var(--owe); }
.add-person { display: inline-flex; gap: 6px; }
.add-person input { height: 42px; width: 150px; border: var(--bw) dashed var(--muted); background: transparent; border-radius: 4px; padding: 0 12px; }
.add-person input:focus-visible { border-style: solid; border-color: var(--ink); }
.add-person button { height: 42px; }

/* Layout */
.grid { display: grid; gap: 22px; grid-template-columns: minmax(0, 1fr); align-items: start; grid-template-areas: "form" "side" "history"; }
.area-form { grid-area: form; } .area-side { grid-area: side; } .area-history { grid-area: history; }
@media (min-width: 900px) {
  .grid { grid-template-columns: minmax(0, 1fr) 380px; grid-template-areas: "form side" "history side"; gap: 28px; }
  .area-side { position: sticky; top: 16px; }
}
.card { background: var(--card); border: var(--bw) solid var(--ink); border-radius: 4px; padding: 20px; box-shadow: 5px 5px 0 var(--shadow); }
.card h2 { font-size: 1rem; font-stretch: 112%; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 16px; padding-bottom: 10px; border-bottom: var(--bw) solid var(--ink); }

.banner {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--lemon); color: var(--on-lemon); border: var(--bw) solid var(--ink); border-radius: 4px; padding: 10px 14px; margin-bottom: 22px; font-weight: 600;
}
.banner .btn { background: var(--card); color: var(--ink); }

/* Form */
.field { display: flex; flex-direction: column; gap: 6px; margin: 0 0 16px; border: 0; padding: 0; min-width: 0; }
.field label, .field legend { font-size: 0.78rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink); padding: 0; }
.row2 { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 16px; }
@media (min-width: 520px) { .row2 { grid-template-columns: minmax(0, 1fr) 170px; } }
input[type="text"], input.plain, select, .money {
  width: 100%; min-height: 46px; border: var(--bw) solid var(--ink); border-radius: 4px; background: var(--card); padding: 0 12px;
}
select { cursor: pointer; }
input[type="text"]:focus-visible, select:focus-visible { outline: 3px solid var(--ink); outline-offset: 2px; background: color-mix(in srgb, var(--lemon) 25%, var(--card)); }
.money { display: flex; align-items: center; gap: 6px; }
.money:focus-within { outline: 3px solid var(--ink); outline-offset: 2px; background: color-mix(in srgb, var(--lemon) 25%, var(--card)); }
.money span { color: var(--muted); font-family: var(--font-mono); font-weight: 600; }
.money input { border: 0; background: transparent; width: 100%; min-height: 42px; padding: 0; font-family: var(--font-mono); font-weight: 500; outline: none; }

.seg { display: inline-grid; grid-template-columns: 1fr 1fr; border: var(--bw) solid var(--ink); border-radius: 4px; overflow: hidden; background: var(--card); }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { text-align: center; padding: 8px 18px; cursor: pointer; font-weight: 700; font-size: 0.92rem; min-height: 40px; display: grid; place-items: center; text-transform: none; letter-spacing: 0; }
.seg label + input + label { border-left: var(--bw) solid var(--ink); }
.seg input:checked + label { background: var(--ink); color: var(--paper); }
.seg input:focus-visible + label { outline: 3px solid var(--ink); outline-offset: -5px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip span { display: inline-flex; align-items: center; gap: 8px; min-height: 42px; padding: 0 14px; border: var(--bw) solid var(--ink); border-radius: 4px; background: var(--card); cursor: pointer; font-weight: 700; }
.chip span::before { content: ""; width: 16px; height: 16px; border: var(--bw) solid var(--ink); background: var(--card); }
.chip input:checked + span { background: var(--lemon); color: var(--on-lemon); }
.chip input:checked + span::before { background: var(--ink); box-shadow: inset 0 0 0 2px var(--lemon); }
.chip input:focus-visible + span { outline: 3px solid var(--ink); outline-offset: 3px; }

.exact { display: grid; gap: 8px; }
.exact-row { display: grid; grid-template-columns: minmax(0, 1fr) 150px; align-items: center; gap: 10px; }
.exact-row label { font-weight: 700; font-size: 1rem; text-transform: none; letter-spacing: 0; overflow-wrap: anywhere; }

.hint { margin: 8px 0 0; font-size: 0.9rem; color: var(--muted); min-height: 1.4em; }
.hint.ok { color: var(--good); font-weight: 600; } .hint.bad { color: var(--owe); font-weight: 600; }
.error { margin: 0 0 12px; color: var(--owe); font-weight: 700; }
.error:empty { display: none; }
#expForm .btn.primary { width: 100%; }
@media (min-width: 520px) { #expForm .btn.primary { width: auto; min-width: 200px; } }

/* Receipt scan */
.scan { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px; border: var(--bw) dashed var(--ink); border-radius: 4px; margin-bottom: 18px; }
.scan-note { font-size: 0.88rem; color: var(--muted); flex: 1 1 180px; }
.scan .hint { flex-basis: 100%; margin: 0; min-height: 0; }
.scan .hint:empty { display: none; }

/* History */
.hist { list-style: none; margin: 0; padding: 0; }
.hist li { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 2px 12px; align-items: center; padding: 14px 0; border-top: 1px solid var(--soft); }
.hist li:first-child { border-top: 0; padding-top: 0; }
.hist .what { font-weight: 800; overflow-wrap: anywhere; }
.hist .meta { color: var(--muted); font-size: 0.88rem; grid-column: 1; overflow-wrap: anywhere; }
.hist .amt { grid-row: 1 / span 2; grid-column: 2; font-weight: 600; text-align: right; }
.hist .del { grid-row: 1 / span 2; grid-column: 3; width: 38px; height: 38px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-size: 1.3rem; }
.hist .del:hover { color: var(--owe); }
.tag { display: inline-block; font-size: 0.68rem; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; padding: 1px 6px; border: var(--bw) solid var(--ink); background: var(--lemon); color: var(--on-lemon); margin-left: 8px; vertical-align: middle; }
.empty { color: var(--muted); margin: 0; }

/* Settle-up slip */
.receipt {
  position: relative; background: var(--lemon); color: var(--on-lemon); padding: 22px 20px 20px; margin-bottom: 28px; font-family: var(--font-mono);
  border: var(--bw) solid var(--ink); border-radius: 4px; box-shadow: 6px 6px 0 var(--shadow);
}
.receipt h2 { font-family: var(--font-display); font-size: 1.5rem; font-weight: 900; letter-spacing: -0.02em; border: 0; padding: 0; margin: 0; text-transform: none; font-stretch: 100%; }
.receipt .kicker { font-size: 0.72rem; font-weight: 600; letter-spacing: .16em; text-transform: uppercase; margin: 0 0 6px; }
.receipt .rule { border: 0; border-top: 2px dashed #111; margin: 14px 0; }
.receipt .line { display: flex; justify-content: space-between; gap: 12px; font-size: 0.92rem; }
.receipt .xfer { padding: 12px 0; border-top: 1px dashed #111; }
.receipt .xfer:first-of-type { border-top: 0; }
.receipt .who { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 0.95rem; }
.receipt .who strong { font-weight: 600; }
.receipt .amount { font-size: 1.5rem; font-weight: 600; }
.receipt .xrow { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-top: 6px; }
.receipt .btn { background: #fff; color: #111; border-color: #111; font-family: var(--font-body); box-shadow: 2px 2px 0 #111; }
.receipt .btn:hover { box-shadow: 3px 3px 0 #111; }
.receipt .square { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; margin: 6px 0 0; }
.receipt-actions { display: flex; gap: 8px; margin-top: 16px; }
.receipt-actions .btn { flex: 1; }

.balances { margin-top: 0; }
.bal { list-style: none; margin: 0; padding: 0; display: grid; gap: 16px; }
.bal li { display: grid; gap: 6px; }
.bal .head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.bal .name { font-weight: 800; overflow-wrap: anywhere; }
.bal .val { font-weight: 600; }
.bal .val.pos { color: var(--good); } .bal .val.neg { color: var(--owe); } .bal .val.zero { color: var(--muted); }
.bal .state { font-size: 0.85rem; color: var(--muted); }
.bar { position: relative; height: 12px; background: var(--card); border: var(--bw) solid var(--ink); }
.bar::before { content: ""; position: absolute; left: 50%; top: -6px; bottom: -6px; width: 2px; background: var(--ink); }
.bar i { position: absolute; top: 0; bottom: 0; }
.bar i.pos { left: 50%; background: var(--good); } .bar i.neg { right: 50%; background: var(--owe); }

/* Toast */
#toast { position: fixed; left: 16px; right: 16px; bottom: 16px; display: flex; justify-content: center; pointer-events: none; z-index: 10; }
.toast-box {
  pointer-events: auto; display: flex; align-items: center; gap: 14px; background: var(--ink); color: var(--paper); border: var(--bw) solid var(--ink);
  padding: 12px 14px 12px 18px; border-radius: 4px; box-shadow: 4px 4px 0 var(--lemon); max-width: 480px; font-weight: 600; animation: rise .16s ease-out;
}
.toast-box button { background: var(--lemon); color: var(--on-lemon); border: 0; border-radius: 2px; padding: 6px 12px; cursor: pointer; font-weight: 800; white-space: nowrap; }
@keyframes rise { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .toast-box { animation: none; } }

/* Guided setup */
.onboard { max-width: 560px; min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; padding-top: 28px; }
.ob-brand { align-self: flex-start; }
.step { display: flex; flex-direction: column; gap: 20px; padding: 20px 0 24px; flex: 1; justify-content: center; }
.ob-title { font-size: clamp(2.3rem, 10vw, 3.6rem); font-weight: 900; letter-spacing: -0.04em; line-height: 1; }
.ob-lead { margin: 0; font-size: 1.1rem; color: var(--muted); max-width: 44ch; }
.ob-progress { display: flex; align-items: center; gap: 12px; margin: 0; font-size: 0.8rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; }
.dots { display: inline-flex; gap: 4px; }
.dots i { width: 26px; height: 10px; border: var(--bw) solid var(--ink); background: var(--card); }
.dots i.on { background: var(--ink); }
.ob-how { list-style: none; margin: 4px 0; padding: 0; display: grid; gap: 14px; }
.ob-how li { display: flex; gap: 14px; align-items: center; }
.ob-how .n { width: 38px; height: 38px; flex: none; background: var(--lemon); color: var(--on-lemon); border: var(--bw) solid var(--ink); display: grid; place-items: center; font-family: var(--font-mono); font-weight: 600; }
.ob-how b { display: block; font-weight: 800; }
.ob-how div span { color: var(--muted); font-size: 0.92rem; }
.ob-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 6px; }
.ob-actions .btn.primary { flex: 1 1 200px; }
.ob-add { display: flex; gap: 8px; }
.ob-add input { flex: 1; min-width: 0; }
.ob-row { display: grid; gap: 0 16px; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
@media (max-width: 460px) { .ob-row { grid-template-columns: minmax(0, 1fr); } }
.ob-suggest { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 14px; }
.sugg { min-height: 40px; padding: 0 14px; border: var(--bw) solid var(--ink); border-radius: 4px; background: var(--card); cursor: pointer; font-weight: 700; }
.sugg:hover { background: var(--lemon); color: var(--on-lemon); }
.ob-skip { margin: 0; text-align: center; }
.mini-receipt {
  align-self: flex-start; width: min(320px, 100%); background: var(--lemon); color: var(--on-lemon); border: var(--bw) solid var(--ink);
  padding: 16px 18px; font-family: var(--font-mono); font-size: 0.88rem; transform: rotate(-2deg); box-shadow: 5px 5px 0 var(--shadow);
}
.mr-kicker { display: block; font-size: 0.68rem; font-weight: 600; letter-spacing: 0.16em; text-transform: uppercase; margin-bottom: 8px; }
.mr-line { display: flex; justify-content: space-between; gap: 12px; padding: 4px 0; border-top: 1px dashed #111; }
.mr-line:first-of-type { border-top: 0; }

/* Share dialog */
dialog#shareDlg {
  width: calc(100% - 32px); max-width: 680px; max-height: calc(100% - 32px); padding: 0; border: var(--bw) solid var(--ink);
  border-radius: 4px; background: var(--card); color: var(--ink); overflow: hidden; box-shadow: 8px 8px 0 var(--shadow);
}
dialog#shareDlg[open] { display: flex; flex-direction: column; }
dialog#shareDlg::backdrop { background: rgba(10, 10, 10, .6); }
.dlg-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 20px; border-bottom: var(--bw) solid var(--ink); background: var(--lemon); color: var(--on-lemon); }
.dlg-head h2 { font-size: 1rem; text-transform: uppercase; letter-spacing: 0.03em; font-stretch: 112%; }
.dlg-close { width: 40px; height: 40px; border: var(--bw) solid var(--ink); border-radius: 4px; background: #fff; color: #111; cursor: pointer; font-size: 1.4rem; line-height: 1; }
.dlg-body { overflow: auto; padding: 16px 20px; background: var(--paper); flex: 1 1 auto; }
.dlg-foot { padding: 14px 20px 16px; border-top: var(--bw) solid var(--ink); display: grid; gap: 10px; }
.dlg-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.dlg-actions .btn { flex: 1 1 150px; }
.dlg-note { margin: 0; font-size: 0.88rem; color: var(--muted); }
#dlStatus { margin: 0; font-size: 0.92rem; font-weight: 700; min-height: 1.4em; color: var(--good); }
#dlStatus.bad { color: var(--owe); }
