@font-face {
  font-family: 'Fraunces';
  src: url('/fonts/fraunces.woff2') format('woff2');
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: 'Instrument Sans';
  src: url('/fonts/instrument-sans.woff2') format('woff2');
  font-weight: 400 700;
  font-display: swap;
}

:root {
  color-scheme: light dark;
  --paper: #f3ede2;
  --card: #fbf8f1;
  --ink: #1d1a15;
  --muted: #7b7366;
  --line: #d9d0bf;
  --red: #c8452c;
  --green: #2f7d5b;
  --hero-bg: #1d1a15;
  --hero-ink: #f6f0e4;
  --display: 'Fraunces', Georgia, serif;
  --body: 'Instrument Sans', system-ui, sans-serif;
  --tabs-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #16140f;
    --card: #201d17;
    --ink: #f1eadc;
    --muted: #9a917f;
    --line: #37322a;
    --red: #ec6a4f;
    --green: #5fbf93;
    --hero-bg: #f1eadc;
    --hero-ink: #1d1a15;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.4 var(--body);
  font-variant-numeric: tabular-nums;
  overscroll-behavior-y: none;
}
body.sheet-open { overflow: hidden; }
button, input, select { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; touch-action: manipulation; }
h1, h2, h3, p, ul { margin: 0; padding: 0; }
ul { list-style: none; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

#app { max-width: 560px; margin: 0 auto; min-height: 100dvh; }

/* ---------- chrome ---------- */

.top {
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 14px) 20px 6px;
}
.brand { font: 600 22px/1 var(--display); letter-spacing: -0.02em; }
.brand em { color: var(--red); font-style: italic; }
.brand.xl { font-size: 54px; }
.avatar {
  width: 40px; height: 40px; border-radius: 50%;
  border: 1.5px solid var(--ink); font: 600 16px/1 var(--display);
}

main { padding: 8px 20px calc(var(--tabs-h) + var(--safe-b) + 40px); display: grid; gap: 22px; align-content: start; }
main > * { min-width: 0; }
h1 { font: 500 34px/1.05 var(--display); letter-spacing: -0.02em; margin-top: 6px; }
h2 { font: 600 12px/1 var(--body); letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.sec-head { display: flex; align-items: baseline; justify-content: space-between; padding-bottom: 8px; border-bottom: 1.5px solid var(--ink); }
.link { font-size: 14px; text-decoration: underline; text-underline-offset: 3px; padding: 6px 0; }
.fine { font-size: 13px; color: var(--muted); }
.muted { color: var(--muted); }
.pos { color: var(--green); }
.neg { color: var(--red); }

.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  max-width: 560px; margin: 0 auto;
  height: calc(var(--tabs-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: color-mix(in srgb, var(--paper) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1.5px solid var(--ink);
}
.tabs button { display: grid; justify-items: center; gap: 3px; height: var(--tabs-h); align-content: center; font-size: 11px; color: var(--muted); }
.tabs button[aria-current='page'] { color: var(--ink); font-weight: 600; }
.tabs .fab {
  width: 58px; height: 58px; border-radius: 50%; justify-self: center; align-self: start;
  margin-top: -20px; background: var(--red); color: #fff;
  box-shadow: 0 0 0 5px var(--paper), 0 8px 18px rgb(0 0 0 / 0.22);
  transition: transform 0.15s;
}
.tabs .fab:active { transform: scale(0.93); }
.tabs .fab svg { width: 26px; height: 26px; stroke-width: 2.2; }

/* ---------- home ---------- */

.hero {
  position: relative; overflow: hidden;
  background: var(--hero-bg); color: var(--hero-ink);
  border-radius: 6px; padding: 24px 22px 22px;
  animation: rise 0.45s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
/* a torn-receipt edge along the bottom of the balance card */
.hero::after {
  content: ''; position: absolute; left: 0; right: 0; bottom: -1px; height: 8px;
  background: linear-gradient(-45deg, var(--paper) 4px, transparent 0) 0 0 / 12px 8px repeat-x,
    linear-gradient(45deg, var(--paper) 4px, transparent 0) 0 0 / 12px 8px repeat-x;
}
.hero-label { font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; opacity: 0.7; }
.hero-amount { font: 400 clamp(46px, 15vw, 68px)/1 var(--display); letter-spacing: -0.035em; margin: 10px 0 12px; overflow-wrap: anywhere; }
.hero.owing .hero-amount { color: #f08a70; }
.hero.owed .hero-amount { color: #86d3ad; }
.hero.even .hero-amount { font-style: italic; }
.hero-sub { font-size: 15px; opacity: 0.8; padding-bottom: 6px; }
.hero-btn {
  margin: 12px 0 8px; padding: 12px 20px; border-radius: 99px;
  background: var(--hero-ink); color: var(--hero-bg); font-weight: 600; font-size: 15px;
}
@media (prefers-color-scheme: dark) {
  .hero.owing .hero-amount { color: #c8452c; }
  .hero.owed .hero-amount { color: #2f7d5b; }
}

.strip { display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 12px; }
.strip div { display: grid; gap: 3px; border-left: 1.5px solid var(--ink); padding-left: 10px; min-width: 0; }
.strip small { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.strip b { font: 500 18px/1.1 var(--display); overflow-wrap: anywhere; }

.notice { background: var(--card); border: 1.5px dashed var(--red); border-radius: 6px; padding: 12px 14px; font-size: 14px; }
code { font-size: 0.9em; word-break: break-all; }

/* ---------- lists ---------- */

.list li + li { border-top: 1px dashed var(--line); }
.row { display: grid; grid-template-columns: 38px 1fr auto; gap: 12px; align-items: center; width: 100%; padding: 12px 0; text-align: left; min-height: 62px; }
.row:active { opacity: 0.6; }
.badge {
  width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center;
  color: var(--c); border: 1.5px solid var(--c); font: 600 16px/1 var(--display);
  background: color-mix(in srgb, var(--c) 12%, transparent);
}
.badge.transfer { --c: var(--ink); border-style: dashed; }
.badge svg { width: 18px; height: 18px; }
.row-main { display: grid; gap: 2px; min-width: 0; }
.row-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tick { font-style: normal; color: var(--muted); margin-left: 6px; font-weight: 400; }
.row-meta { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-side { display: grid; justify-items: end; gap: 2px; }
.row-side b { font: 500 17px/1.1 var(--display); }
.row-side small { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; }
.row-side small.neg { color: var(--red); }

.empty { text-align: center; color: var(--muted); padding: 34px 10px; font: italic 400 18px/1.4 var(--display); }
.empty b { color: var(--red); font-style: normal; }

.month-head { display: flex; justify-content: space-between; align-items: baseline; margin-top: 22px; padding-bottom: 8px; border-bottom: 1.5px solid var(--ink); }
.month-head h3 { font: 500 20px/1 var(--display); }
.month-head span { font: 500 16px/1 var(--display); color: var(--muted); }
.summary { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 13px; color: var(--muted); }
.summary b { color: var(--ink); }
#hist { margin-top: -6px; }

/* ---------- filters ---------- */

.search, .field input, .field select, .login input, .range input {
  width: 100%; min-height: 48px; padding: 10px 14px;
  background: var(--card); border: 1.5px solid var(--line); border-radius: 6px;
  appearance: none; -webkit-appearance: none;
}
.search:focus, .field input:focus, .field select:focus, .login input:focus, .range input:focus { border-color: var(--ink); outline: none; }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips.scroll { flex-wrap: nowrap; overflow-x: auto; margin: 0 -20px; padding: 2px 20px; scrollbar-width: none; }
.chips.scroll::-webkit-scrollbar { display: none; }
.view-history { gap: 12px; }
.chip {
  flex: none; padding: 8px 14px; min-height: 38px; border-radius: 99px;
  border: 1.5px solid var(--line); font-size: 14px; white-space: nowrap;
}
.chip[aria-pressed='true'] { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.chip.tag::before { content: ''; display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--c); margin-right: 7px; }
.range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.range label { display: grid; gap: 4px; font-size: 12px; color: var(--muted); min-width: 0; }

/* ---------- insights ---------- */

.card { background: var(--card); border: 1.5px solid var(--ink); border-radius: 6px; padding: 18px; }
.totals { display: grid; gap: 10px; }
.totals small { font-size: 12px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--muted); }
.big { font: 400 44px/1 var(--display); letter-spacing: -0.03em; overflow-wrap: anywhere; }
.sharebar { height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.sharebar i { display: block; height: 100%; background: var(--red); border-right: 2px solid var(--card); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 18px; font-size: 14px; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: var(--line); margin-right: 6px; }
.dot.me { background: var(--red); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1.5px solid var(--ink); border-radius: 6px; overflow: hidden; }
.seg button { min-height: 46px; padding: 6px 6px; font-size: 14px; font-weight: 500; line-height: 1.15; }
.seg button + button { border-left: 1.5px solid var(--ink); }
.seg button[aria-pressed='true'] { background: var(--ink); color: var(--paper); }
.seg.small button { min-height: 40px; }

.bars { display: grid; gap: 4px; margin-top: 6px; }
.bars button { display: grid; gap: 6px; width: 100%; text-align: left; padding: 9px 0; }
.bar-top { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.bar-top small { color: var(--muted); display: inline-block; min-width: 2.6em; text-align: right; }
.bar { height: 8px; border-radius: 99px; background: color-mix(in srgb, var(--line) 60%, transparent); overflow: hidden; }
.bar i { display: block; height: 100%; border-radius: 99px; animation: grow 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both; transform-origin: left; }

.cols { display: grid; grid-template-columns: repeat(12, 1fr); gap: 4px; height: 170px; margin-top: 12px; }
.cols button { display: grid; grid-template-rows: 14px 1fr 18px; gap: 4px; justify-items: stretch; min-width: 0; }
.cols small { font-size: 9px; color: var(--muted); text-align: center; white-space: nowrap; letter-spacing: -0.03em; }
.cols i { align-self: end; background: var(--ink); border-radius: 3px 3px 0 0; min-height: 2px; animation: growY 0.5s cubic-bezier(0.2, 0.8, 0.2, 1) both; transform-origin: bottom; }
.cols button:last-child i { background: var(--red); }
.cols span { font-size: 11px; color: var(--muted); text-align: center; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; text-decoration: none;
  min-height: 52px; padding: 12px 20px; border-radius: 6px;
  background: var(--ink); color: var(--paper); font-weight: 600; border: 1.5px solid var(--ink);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.5; }
.btn.ghost { background: transparent; color: var(--ink); }
.btn.danger { background: transparent; color: var(--red); border-color: var(--red); }
.btn.wide { width: 100%; }
.btn.grow { flex: 1; }
.icon-btn { width: 44px; height: 44px; display: grid; place-items: center; margin-right: -10px; }

/* ---------- sheet ---------- */

.backdrop { position: fixed; inset: 0; z-index: 10; background: rgb(0 0 0 / 0.45); opacity: 0; transition: opacity 0.2s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-width: 560px; margin: 0 auto; max-height: 94dvh;
  display: grid; grid-template-rows: auto 1fr;
  background: var(--paper); border-radius: 14px 14px 0 0; border-top: 1.5px solid var(--ink);
  transform: translateY(102%); transition: transform 0.24s cubic-bezier(0.2, 0.8, 0.2, 1);
}
#sheet-root.open .backdrop { opacity: 1; }
#sheet-root.open .sheet { transform: none; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px 4px; }
.sheet-head h2 { font: 500 22px/1 var(--display); letter-spacing: -0.01em; text-transform: none; color: var(--ink); }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 8px 20px calc(var(--safe-b) + 20px); display: grid; gap: 16px; }
.sheet-body > * { min-width: 0; }
#entry, .stack { display: grid; gap: 16px; }
#entry > *, .field { min-width: 0; }
.stack h3 { font: 500 18px/1 var(--display); margin-top: 8px; }

.amount { display: flex; align-items: baseline; gap: 8px; border-bottom: 1.5px solid var(--ink); padding: 2px 0 4px; }
.amount span { font: 400 30px/1 var(--display); color: var(--muted); }
.amount input { flex: 1; min-width: 0; border: 0; background: none; outline: none; font: 400 52px/1.1 var(--display); letter-spacing: -0.03em; padding: 0; }
.amount input::placeholder { color: var(--line); }

.field { display: grid; gap: 6px; }
.field > span { font-size: 12px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.field .chips { margin-top: 4px; }
.field select { background-image: linear-gradient(45deg, transparent 50%, var(--ink) 50%), linear-gradient(135deg, var(--ink) 50%, transparent 50%); background-position: calc(100% - 19px) 21px, calc(100% - 14px) 21px; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.field.check { justify-items: start; }
.field.check input { appearance: auto; -webkit-appearance: checkbox; width: 28px; min-height: 28px; height: 28px; margin: 10px 0; accent-color: var(--red); }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pair > :only-child, .pair:has(> [hidden]) > * { grid-column: 1 / -1; }

.custom { display: grid; gap: 10px; margin-top: 8px; }
.custom input[type='range'] {
  width: 100%; height: 34px; min-height: 0; padding: 0; border: 0; background: none;
  appearance: auto; -webkit-appearance: auto; accent-color: var(--red);
}
.shares { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.shares label { display: grid; gap: 6px; font-size: 14px; min-width: 0; }
.shares b { font-weight: 600; color: var(--red); }
.outcome { font: italic 400 17px/1.3 var(--display); min-height: 22px; margin-top: 4px; }
.actions { display: flex; gap: 12px; position: sticky; bottom: 0; padding: 10px 0 2px; background: linear-gradient(transparent, var(--paper) 30%); }
.who { font-size: 15px; }

/* ---------- login & toast ---------- */

.login { min-height: 100dvh; align-content: center; padding-bottom: 60px; gap: 6px; }
.tagline { font: italic 400 19px/1.3 var(--display); color: var(--muted); margin-bottom: 26px; }
.login form { display: grid; gap: 14px; }
.login label { display: grid; gap: 6px; font-size: 12px; font-weight: 600; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); }
.login input { font-size: 16px; letter-spacing: 0; text-transform: none; font-weight: 400; color: var(--ink); }
.error { color: var(--red); min-height: 22px; font-size: 14px; }

#toast {
  position: fixed; left: 16px; right: 16px; bottom: calc(var(--tabs-h) + var(--safe-b) + 22px); z-index: 20;
  max-width: 528px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 14px;
  background: var(--ink); color: var(--paper); border-radius: 6px; padding: 13px 16px; font-size: 14px;
  opacity: 0; transform: translateY(12px); pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
#toast.show { opacity: 1; transform: none; pointer-events: auto; }
#toast button { color: #f08a70; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; font-size: 13px; padding: 4px; }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }
@keyframes grow { from { transform: scaleX(0); } }
@keyframes growY { from { transform: scaleY(0); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
.row-meta.wrap { white-space: normal; }
