:root {
  --plum: #6E4B69;
  --plum-deep: #4F3350;
  --plum-soft: #EFE6EC;
  --teal: #356B67;
  --teal-deep: #1F4A47;
  --teal-soft: #E1EEEC;
  --sand: #D9C29C;
  --sand-soft: #F4ECDD;
  --red: #A9443A;
  --red-soft: #F7E3DF;
  --bg: #FBF8F2;
  --card: #FFFFFF;
  --ink: #2A2229;
  --ink-2: #6A5F68;
  --line: #E8E0E4;
  --shadow: 0 1px 2px rgba(42, 34, 41, .06), 0 4px 16px rgba(42, 34, 41, .05);
  --radius: 16px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --plum: #C79BC0; --plum-deep: #E2C3DB; --plum-soft: #3A2B38;
    --teal: #7FBDB6; --teal-deep: #A8D8D2; --teal-soft: #1F3533;
    --sand: #8C7A5B; --sand-soft: #34302A;
    --red: #EA8F83; --red-soft: #432723;
    --bg: #171316; --card: #221C21; --ink: #F2ECF0; --ink-2: #B3A7B0; --line: #3A3139;
    --shadow: none;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  padding-bottom: calc(76px + env(safe-area-inset-bottom));
  min-height: 100vh;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--plum); }
.wrap { max-width: 640px; margin: 0 auto; padding: 0 16px; }

header.top {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) 0 10px;
}
header.top .wrap { display: flex; align-items: center; gap: 12px; }
header.top h1 { font-size: 22px; margin: 0; flex: 1; letter-spacing: -.01em; }
.month-nav { display: flex; align-items: center; gap: 4px; }
.month-nav span { min-width: 88px; text-align: center; font-weight: 600; font-size: 15px; }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; margin: 12px 0; border: 1px solid var(--line); }
.card h2 { font-size: 15px; margin: 0 0 10px; color: var(--ink-2); font-weight: 600; }
.muted { color: var(--ink-2); }
.small { font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.row .grow { flex: 1; min-width: 0; }
.spread { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.in { color: var(--teal); }
.over { color: var(--red); }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.big { font-size: 34px; font-weight: 700; letter-spacing: -.02em; }
.hero { background: var(--plum); color: #fff; border: 0; }
.hero .muted { color: rgba(255,255,255,.75); }
@media (prefers-color-scheme: dark) { .hero { background: var(--plum-soft); color: var(--ink); } .hero .muted { color: var(--ink-2); } }
.hero .lines { margin-top: 12px; border-top: 1px solid rgba(255,255,255,.2); padding-top: 10px; display: grid; gap: 6px; }

.btn {
  appearance: none; border: 0; border-radius: 12px; padding: 12px 16px; font-weight: 600; cursor: pointer;
  background: var(--plum); color: #fff; min-height: 44px;
}
.btn:disabled { opacity: .5; }
.btn.ghost { background: transparent; color: var(--plum); border: 1px solid var(--line); }
.btn.soft { background: var(--plum-soft); color: var(--plum-deep); }
.btn.teal { background: var(--teal); }
.btn.danger { background: transparent; color: var(--red); border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.sm { padding: 8px 12px; min-height: 36px; font-size: 14px; border-radius: 10px; }
.icon-btn { appearance: none; border: 0; background: transparent; width: 40px; height: 40px; border-radius: 20px; cursor: pointer; font-size: 20px; color: var(--ink-2); }
.icon-btn:active { background: var(--line); }

.alert { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 12px; background: var(--sand-soft); margin: 12px 0; cursor: pointer; border: 0; width: 100%; text-align: left; }
.alert b { flex: 1; font-weight: 600; }

label.field { display: block; margin: 12px 0; }
label.field > span { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 4px; font-weight: 600; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], input[inputmode], select, textarea {
  width: 100%; padding: 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--card); min-height: 46px; font-size: 16px;
}
textarea { min-height: 70px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--plum); outline-offset: 0; border-color: transparent; }
.amount-input { font-size: 40px !important; font-weight: 700; text-align: center; border: 0 !important; background: transparent !important; padding: 8px !important; }
.check { display: flex; align-items: center; gap: 10px; margin: 10px 0; }
.check input { width: 22px; height: 22px; accent-color: var(--plum); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 8px 12px; font-size: 14px; cursor: pointer; min-height: 36px; }
.chip.on { background: var(--plum); color: #fff; border-color: var(--plum); }
.seg { display: flex; background: var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 8px; font-weight: 600; font-size: 14px; cursor: pointer; }
.seg button.on { background: var(--card); box-shadow: var(--shadow); }

.list { margin: 0; padding: 0; list-style: none; }
.list > li { padding: 12px 0; border-bottom: 1px solid var(--line); }
.list > li:last-child { border-bottom: 0; }
.list > li.tap { cursor: pointer; }
.day { font-size: 13px; font-weight: 700; color: var(--ink-2); margin: 16px 0 0; text-transform: uppercase; letter-spacing: .04em; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; background: var(--sand-soft); color: var(--ink-2); vertical-align: 1px; }
.badge.teal { background: var(--teal-soft); color: var(--teal-deep); }
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.plum { background: var(--plum-soft); color: var(--plum-deep); }
.avatar { width: 32px; height: 32px; border-radius: 16px; display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; background: var(--sand-soft); color: var(--ink-2); }
.avatar.u1 { background: var(--plum-soft); color: var(--plum-deep); }
.avatar.u2 { background: var(--teal-soft); color: var(--teal-deep); }

.bar { height: 8px; border-radius: 4px; background: var(--line); overflow: hidden; margin-top: 6px; }
.bar > i { display: block; height: 100%; background: var(--teal); border-radius: 4px; }
.bar > i.warn { background: var(--sand); }
.bar > i.over { background: var(--red); }

.group-head { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 4px 0; }
.group-head h3 { margin: 0; font-size: 16px; flex: 1; }
.cat-row { padding: 10px 0; border-top: 1px solid var(--line); cursor: pointer; }
.cols { display: grid; grid-template-columns: minmax(0,1fr) 66px 66px 70px; gap: 6px; align-items: baseline; }
.cols .num.small { font-size: 12.5px; }
.cols > :not(:first-child) { text-align: right; }
.cols.head { font-size: 12px; color: var(--ink-2); font-weight: 600; }

nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10; background: var(--card); border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
nav.tabs .wrap { display: grid; grid-template-columns: repeat(5, 1fr); padding: 0 4px; }
nav.tabs a, nav.tabs button {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 6px; font-size: 11px; font-weight: 600;
  color: var(--ink-2); text-decoration: none; border: 0; background: none; cursor: pointer; position: relative;
}
nav.tabs svg { width: 24px; height: 24px; }
nav.tabs .on { color: var(--plum); }
nav.tabs .add span.plus { width: 48px; height: 48px; margin-top: -18px; border-radius: 24px; background: var(--plum); color: #fff; display: grid; place-items: center; box-shadow: 0 4px 12px rgba(110,75,105,.35); }
nav.tabs .dot { position: absolute; top: 4px; right: calc(50% - 18px); min-width: 16px; height: 16px; border-radius: 8px; background: var(--red); color: #fff; font-size: 10px; display: grid; place-items: center; padding: 0 4px; }

.sheet-bg { position: fixed; inset: 0; background: rgba(20, 14, 19, .45); z-index: 20; display: flex; align-items: flex-end; justify-content: center; animation: fade .15s; }
.sheet {
  background: var(--bg); width: 100%; max-width: 640px; max-height: 92vh; overflow: auto; border-radius: 20px 20px 0 0;
  padding: 8px 16px calc(20px + env(safe-area-inset-bottom)); animation: up .2s ease-out;
}
.sheet .grab { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 4px auto 8px; }
.sheet h2 { margin: 4px 0 8px; font-size: 20px; }
@media (min-width: 700px) { .sheet-bg { align-items: center; } .sheet { border-radius: 20px; } }
@keyframes up { from { transform: translateY(30px); opacity: .6; } }
@keyframes fade { from { opacity: 0; } }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(90px + env(safe-area-inset-bottom)); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 12px; z-index: 30; font-size: 14px; max-width: 90vw; }
.error { color: var(--red); font-size: 14px; margin: 8px 0; }
.empty { text-align: center; color: var(--ink-2); padding: 24px 8px; }
.reactions { display: flex; gap: 6px; flex-wrap: wrap; }
.reactions button { border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 6px 10px; font-size: 18px; cursor: pointer; }
.reactions button.on { border-color: var(--plum); background: var(--plum-soft); }
.comment { padding: 8px 0; }
.comment .who { font-size: 13px; font-weight: 700; }
.keybox { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 15px; padding: 12px; background: var(--sand-soft); border-radius: 12px; word-break: break-all; user-select: all; }
.temp { font-size: 26px; font-weight: 700; text-align: center; padding: 16px; background: var(--sand-soft); border-radius: 12px; letter-spacing: .02em; user-select: all; }

.signin { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }
.signin .box { width: 100%; max-width: 380px; }
.signin .mark { width: 64px; height: 64px; margin: 0 auto 12px; display: block; }
.signin h1 { text-align: center; margin: 0 0 4px; font-size: 26px; }
body.bare { padding-bottom: 0; }
.review-line { padding: 14px 0; border-top: 1px solid var(--line); }
.review-line:first-child { border-top: 0; }
.review-line .raw { font-size: 12px; color: var(--ink-2); font-family: ui-monospace, Menlo, Consolas, monospace; word-break: break-word; }
.stack > * + * { margin-top: 8px; }
details > summary { cursor: pointer; font-weight: 600; padding: 6px 0; }
hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
