:root {
  --bg: #fff8ef; --card: #ffffff; --ink: #2b2140; --muted: #7a6f92; --line: #efe2d0;
  --pink: #ff4d8d; --yellow: #ffd23f; --mint: #20c9a6; --red: #ef476f;
  --pos: #0f9d7a; --neg: #d93a63; --radius: 18px; --tab-h: 72px;
  font-family: ui-rounded, "SF Pro Rounded", "Nunito", "Segoe UI", system-ui, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1c1530; --card: #2a2145; --ink: #fff4e3; --muted: #aa9fc8; --line: #3a2f5c;
    --pos: #3ee0b8; --neg: #ff7a9c;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { min-height: 100vh; font-size: 18px; line-height: 1.35; }
#app { max-width: 640px; margin: 0 auto; padding: 0 16px calc(var(--tab-h) + 28px + env(safe-area-inset-bottom)); }
h1, h2, h3 { margin: 0; font-weight: 900; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select { font: inherit; color: var(--ink); }
a { color: var(--pink); font-weight: 700; }
svg { display: block; fill: currentColor; }

.topbar { display: flex; align-items: center; gap: 8px; padding: calc(10px + env(safe-area-inset-top)) 0 8px; min-height: 64px; }
.topbar h1 { flex: 1; font-size: 1.45rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { display: flex; align-items: center; gap: 10px; font-size: 1.6rem; font-weight: 900; color: var(--pink); }
.logo img { width: 36px; height: 36px; border-radius: 10px; }
.iconbtn { width: 48px; height: 48px; border-radius: 14px; border: 0; background: transparent; display: grid; place-items: center; flex: none; }
.iconbtn svg { width: 26px; height: 26px; }

.btn { border: 0; border-radius: 16px; min-height: 56px; padding: 0 20px; font-weight: 800; background: var(--pink); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:active { filter: brightness(.92); }
.btn.alt { background: var(--yellow); color: #2b2140; }
.btn.ghost { background: var(--card); color: var(--ink); border: 2px solid var(--line); }
.btn.danger { background: var(--red); }
.btn.small { min-height: 44px; padding: 0 16px; border-radius: 14px; font-size: .95rem; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; }

.card { background: var(--card); border-radius: var(--radius); padding: 16px; border: 2px solid var(--line); }
.stack { display: flex; flex-direction: column; gap: 12px; }
.row { display: flex; align-items: center; gap: 10px; }
.grow { flex: 1; min-width: 0; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.pos { color: var(--pos); } .neg { color: var(--neg); }
.empty { text-align: center; color: var(--muted); padding: 32px 8px; }
.section { margin: 26px 0 10px; font-size: 1rem; color: var(--muted); text-transform: none; }
.section.first { margin-top: 6px; }
.chip { display: inline-block; border-radius: 99px; padding: 3px 10px; font-size: .8rem; font-weight: 800; background: var(--line); width: fit-content; }

/* login */
.hero { text-align: center; padding: 14vh 0 24px; }
.hero img { width: 96px; height: 96px; border-radius: 26px; }
.hero h1 { font-size: 2.6rem; color: var(--pink); margin: 14px 0 6px; }
.hero p { color: var(--muted); max-width: 22em; margin: 0 auto 28px; }
.error { background: #ffe3ea; color: #a1163d; border-radius: 14px; padding: 12px 14px; margin: 0 auto 16px; max-width: 24em; font-weight: 700; }
.gbtn { display: inline-flex; gap: 12px; align-items: center; min-height: 56px; background: #fff; color: #2b2140; border: 2px solid #2b2140; border-radius: 16px; padding: 0 22px; font-weight: 800; text-decoration: none; }

/* spaces */
.spaces { display: flex; flex-direction: column; gap: 12px; }
.space { text-align: left; display: flex; align-items: center; gap: 14px; width: 100%; min-height: 84px; padding: 14px 16px; border-radius: var(--radius); border: 2px solid var(--line); background: var(--card); }
.space .icon { width: 56px; display: grid; place-items: center; flex: none; }
.space b { font-size: 1.2rem; display: block; }
.space .meta { color: var(--muted); font-size: .9rem; }
.space .chip.pos { background: #bff3e4; color: #046c52; } .space .chip.neg { background: #ffd0dc; color: #a1163d; }
.space.new { justify-content: center; border-style: dashed; background: transparent; color: var(--muted); font-weight: 800; }

/* tabs */
.tabs { position: fixed; left: 0; right: 0; bottom: 0; z-index: 5; display: flex; background: var(--card); border-top: 2px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
.tabs button { flex: 1; height: var(--tab-h); border: 0; background: transparent; color: var(--muted); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: .78rem; font-weight: 800; }
.tabs svg { width: 28px; height: 28px; }
.tabs button.on { color: var(--pink); }

/* shopping list */
.pills { display: flex; gap: 8px; overflow-x: auto; padding: 2px 0 10px; scrollbar-width: none; }
.pill { flex: none; min-height: 40px; border: 2px solid var(--line); background: var(--card); border-radius: 99px; padding: 0 16px; font-weight: 800; }
.pill.on { background: var(--ink); border-color: var(--ink); color: var(--bg); }
.addbar { position: sticky; top: 0; z-index: 4; background: var(--bg); padding: 6px 0 12px; }
.addform { display: flex; gap: 8px; }
.addform input { flex: 1; min-width: 0; height: 56px; border: 2px solid var(--line); background: var(--card); border-radius: 16px; padding: 0 16px; }
.addform input:focus { outline: none; border-color: var(--pink); }
.addform .btn { width: 56px; padding: 0; font-size: 1.8rem; }
.suggest { position: absolute; left: 0; right: 0; top: 70px; background: var(--card); border: 2px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: 0 10px 24px rgba(43, 33, 64, .18); }
.suggest button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); background: transparent; min-height: 52px; padding: 0 16px; font-weight: 700; }
.suggest button:last-child { border-bottom: 0; }
.items { display: flex; flex-direction: column; gap: 8px; }
.item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 60px; text-align: left; background: var(--card); border: 2px solid var(--line); border-radius: 16px; padding: 8px 16px; font-weight: 700; overflow-wrap: anywhere; }
.item:active { background: var(--line); }
.item .ring { width: 28px; height: 28px; border-radius: 50%; border: 3px solid var(--pink); flex: none; }
.recent { display: flex; flex-wrap: wrap; gap: 8px; }
.recent .chipbtn { min-height: 46px; display: inline-flex; align-items: center; gap: 8px; border: 2px solid var(--line); background: var(--card); border-radius: 99px; padding: 0 16px; font-weight: 700; }
.recent .chipbtn.edit { border-color: var(--red); }
.linkbtn { border: 0; background: transparent; color: var(--muted); font-weight: 800; font-size: .9rem; padding: 6px 0; }

/* pot */
.balance { text-align: center; padding: 22px 16px; background: var(--yellow); color: #2b2140; border-color: transparent; }
.balance .lbl { font-weight: 800; }
.balance .amt { font-size: 2.8rem; font-weight: 900; line-height: 1.15; }
.balance.plus { background: #bff3e4; } .balance.minus { background: #ffd0dc; }
.person { display: flex; align-items: center; gap: 12px; min-height: 48px; }
.avatar { border-radius: 50%; display: grid; place-items: center; font-weight: 900; color: #2b2140; flex: none; object-fit: cover; }
.feed { display: flex; flex-direction: column; gap: 8px; }
.entry { display: flex; gap: 12px; align-items: center; background: var(--card); border: 2px solid var(--line); border-radius: 16px; min-height: 64px; padding: 8px 14px; text-align: left; width: 100%; }
.entry .amt { font-weight: 900; white-space: nowrap; }

/* sheets, toast */
.scrim { position: fixed; inset: 0; background: rgba(43, 33, 64, .55); z-index: 20; display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--bg); width: 100%; max-width: 640px; border-radius: 26px 26px 0 0; padding: 20px 16px calc(20px + env(safe-area-inset-bottom)); max-height: 92vh; overflow: auto; }
@media (min-width: 700px) { .scrim { align-items: center; } .sheet { border-radius: 26px; } }
.sheet h2 { margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-weight: 800; font-size: .9rem; }
.field input, .field select { height: 56px; border: 2px solid var(--line); background: var(--card); border-radius: 14px; padding: 0 14px; font-weight: 600; width: 100%; }
.field input:focus, .field select:focus { outline: none; border-color: var(--pink); }
.emojis { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.emojis button { font-size: 1.6rem; width: 50px; height: 50px; border-radius: 14px; border: 2px solid var(--line); background: var(--card); }
.emojis button.on { border-color: var(--pink); background: #ffe0ec; }
.toast { position: fixed; left: 50%; bottom: calc(var(--tab-h) + 16px + env(safe-area-inset-bottom)); transform: translateX(-50%); background: #2b2140; color: #fff; padding: 6px 8px 6px 18px; border-radius: 99px; font-weight: 700; z-index: 30; max-width: 92vw; display: flex; align-items: center; gap: 12px; min-height: 48px; }
.toast button { border: 0; background: transparent; color: var(--yellow); font-weight: 900; min-height: 44px; padding: 0 12px; }
.link { word-break: break-all; font-size: .85rem; background: var(--bg); border: 2px dashed var(--line); border-radius: 12px; padding: 10px 12px; }
.row.head { margin: 26px 0 10px; }
.row.head h3 { font-size: 1rem; color: var(--muted); }
.toast { white-space: normal; text-align: center; }
.spaceimg { border-radius: 22%; object-fit: cover; display: block; }
.spaceemoji { line-height: 1; }
.topbar .icon { display: grid; place-items: center; flex: none; }
.bigrow { display: flex; align-items: center; justify-content: center; gap: 6px; margin: 4px 0 6px; }
.bigrow span { font-size: 2.4rem; font-weight: 900; color: var(--muted); }
.bigamt { width: 7em; max-width: 60%; height: 76px; border: 0; background: transparent; text-align: right; font-size: 2.8rem; font-weight: 900; padding: 0; }
.bigamt:focus, .titlein:focus { outline: none; }
.titlein { width: 100%; height: 56px; border: 2px solid var(--line); background: var(--card); border-radius: 16px; padding: 0 16px; }
.titlein:focus { border-color: var(--pink); }
.pchips { display: flex; flex-wrap: wrap; gap: 8px; }
.pchip { width: 76px; display: flex; flex-direction: column; align-items: center; gap: 4px; border: 2px solid transparent; border-radius: 16px; padding: 8px 2px; background: transparent; font-size: .78rem; font-weight: 700; opacity: .4; }
.pchip.on { opacity: 1; border-color: var(--pink); background: var(--card); }
.pchip span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn { white-space: nowrap; }
/* An app, not a document: tapping a heading must not select the word (Chrome would offer a Google search). */
body { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
input, select, .link, .allow-select { -webkit-user-select: text; user-select: text; }
.searchbox input { width: 100%; height: 52px; border: 2px solid var(--line); background: var(--card); border-radius: 16px; padding: 0 16px; margin-bottom: 12px; }
.searchbox input:focus { outline: none; border-color: var(--pink); }
.switch { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 52px; border: 0; background: transparent; padding: 0; text-align: left; font-weight: 700; }
.knob { width: 54px; height: 32px; border-radius: 99px; background: var(--line); position: relative; flex: none; transition: background .15s; }
.knob::after { content: ""; position: absolute; top: 4px; left: 4px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .15s; }
.knob.on { background: var(--pink); }
.knob.on::after { transform: translateX(22px); }
html { touch-action: manipulation; }
.zoomable { border: 0; background: none; padding: 0; display: block; line-height: 0; border-radius: 22%; flex: none; }
.zoomable.round { border-radius: 50%; }
.lightbox { position: fixed; inset: 0; z-index: 40; background: rgba(0, 0, 0, .93); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 16px; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 140px); border-radius: 14px; object-fit: contain; }
.lightbox .cap { color: #fff; font-weight: 800; }
.lightbox .x { position: absolute; top: calc(10px + env(safe-area-inset-top)); right: 10px; width: 48px; height: 48px; border: 0; border-radius: 14px; background: rgba(255, 255, 255, .15); color: #fff; font-size: 1.4rem; }
.offline { position: sticky; top: 0; z-index: 6; margin: 0 -16px; padding: calc(8px + env(safe-area-inset-top)) 12px 8px; background: #2b2140; color: #fff; text-align: center; font-weight: 700; font-size: .9rem; }
.isoffline .addbar { top: calc(38px + env(safe-area-inset-top)); }
.entry.pending { border-style: dashed; }
.entry .right { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; text-align: right; flex: none; }
.entry .eff { font-size: .85rem; font-weight: 800; white-space: nowrap; }
