:root {
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);

  --paper:    #E7ECEF;
  --paper-fade: rgba(231,236,239,.86);
  --surface:  #FBFCFC;
  --ink:      #16212B;
  --muted:    #5E717E;
  --rule:     #C6D0D6;
  --rule-soft:#DCE3E7;
  --accent:   #1F6F5C;
  --accent-ink:#FFFFFF;
  --danger:   #A33B2A;

  --c1:#2D6A8E; --c2:#B4593E; --c3:#6E5A9C; --c4:#1F6F5C;
  --c5:#B5842B; --c6:#9C4F6C; --c7:#6F7F33; --c8:#5A6B7A;

  --shadow: 0 1px 0 rgba(22,33,43,.06), 0 14px 30px -20px rgba(22,33,43,.45);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper:#0F1720; --paper-fade: rgba(15,23,32,.86); --surface:#18222C;
    --ink:#E7EEF3; --muted:#93A7B4; --rule:#2C3B48; --rule-soft:#233140;
    --accent:#4FA98F; --accent-ink:#06130F; --danger:#E08272;
    --c1:#6BA8CB; --c2:#E08A6C; --c3:#A996D6; --c4:#5FBBA0;
    --c5:#E0B463; --c6:#D690AB; --c7:#A9BC64; --c8:#93A7B4;
    --shadow: 0 1px 0 rgba(0,0,0,.3), 0 16px 32px -22px rgba(0,0,0,.9);
  }
}
:root[data-theme="dark"] {
  --paper:#0F1720; --paper-fade: rgba(15,23,32,.86); --surface:#18222C;
  --ink:#E7EEF3; --muted:#93A7B4; --rule:#2C3B48; --rule-soft:#233140;
  --accent:#4FA98F; --accent-ink:#06130F; --danger:#E08272;
  --c1:#6BA8CB; --c2:#E08A6C; --c3:#A996D6; --c4:#5FBBA0;
  --c5:#E0B463; --c6:#D690AB; --c7:#A9BC64; --c8:#93A7B4;
  --shadow: 0 1px 0 rgba(0,0,0,.3), 0 16px 32px -22px rgba(0,0,0,.9);
}

*, *::before, *::after { box-sizing: inherit; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(64px + env(safe-area-inset-top, 0px)); }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: "Archivo", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-variation-settings: "wdth" 100;
  font-size: 16px; line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------------------------- sign in ---------------------------- */
.gate { min-height: 100svh; display: grid; place-items: center; padding: 24px; }
.gate[hidden] { display: none; }
.gate-card {
  width: 100%; max-width: 360px; background: var(--surface);
  border: 1px solid var(--rule-soft); border-radius: 12px; padding: 24px; box-shadow: var(--shadow);
}
.gate-card h1 {
  margin: 0 0 6px; font-size: 24px; letter-spacing: -.03em; line-height: 1.1;
  font-variation-settings: "wdth" 92, "wght" 700;
}
.gate-card p { margin: 0 0 18px; color: var(--muted); font-size: 14.5px; }
.gate-card .txt { margin-bottom: 12px; }
.gate-err { color: var(--danger); font-size: 14px; margin: -4px 0 12px !important; }

/* ---------------------------- sticky bar ---------------------------- */
.bar {
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 20;
  background: var(--paper-fade);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid transparent;
}
.bar.stuck { border-bottom-color: var(--rule-soft); }
.bar-in {
  max-width: 1060px; margin: 0 auto; padding: 8px 14px;
  display: flex; align-items: center; gap: 2px; min-height: 52px;
}
.offline {
  background: var(--ink); color: var(--paper); font-size: 13px;
  text-align: center; padding: 5px 12px;
}
.arrow {
  background: none; border: none; width: 40px; height: 40px; border-radius: 50%;
  color: var(--muted); display: grid; place-items: center; padding: 0; font-size: 22px; line-height: 1;
}
.arrow:hover:not(:disabled) { background: var(--rule-soft); color: var(--ink); }
.arrow:disabled { opacity: .28; cursor: default; }
.bar .mon { font-size: 16px; font-variation-settings: "wght" 650; letter-spacing: -.01em; padding: 0 4px; }
.bar .spacer { flex: 1 1 auto; }
.bar .peek {
  font-size: 16px; font-variation-settings: "wght" 650; letter-spacing: -.015em;
  opacity: 0; transform: translateY(3px); transition: opacity .18s ease, transform .18s ease;
  margin-right: 6px; pointer-events: none;
}
.bar.stuck .peek { opacity: 1; transform: none; }
select.cur {
  -webkit-appearance: none; appearance: none;
  background: transparent; border: 1px solid var(--rule); border-radius: 999px;
  padding: 7px 26px 7px 12px; font-size: 14px; color: var(--muted);
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: right 12px center, right 7px center; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat;
}

/* ---------------------------- layout ---------------------------- */
.wrap { max-width: 1060px; margin: 0 auto; padding: 6px 14px 40px; }
.grid { display: grid; gap: 22px; }
@media (min-width: 880px) {
  .wrap { padding: 12px 20px 60px; }
  .grid {
    grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
    grid-template-areas: "hero add" "cats add" "ents add";
    column-gap: 36px; row-gap: 24px; align-items: start;
  }
  #hero { grid-area: hero; }
  #add  { grid-area: add; position: sticky; top: calc(76px + env(safe-area-inset-top, 0px)); }
  #cats { grid-area: cats; }
  #ents { grid-area: ents; }
}

/* ---------------------------- hero ---------------------------- */
.total {
  font-size: clamp(50px, 16vw, 84px); line-height: .9; letter-spacing: -.045em;
  font-variation-settings: "wdth" 86, "wght" 700; margin: 10px 0 6px;
}
.total .sym {
  font-size: .42em; vertical-align: .38em; margin-right: .08em; color: var(--muted);
  font-variation-settings: "wdth" 100, "wght" 500; letter-spacing: 0;
}
.readout { color: var(--muted); font-size: 14.5px; margin: 0 0 16px; max-width: 46ch; }
.readout b { color: var(--ink); font-variation-settings: "wght" 650; }
.delta.up { color: var(--danger); }
.delta.down { color: var(--accent); }

.band { display: flex; height: 48px; border-radius: 5px; overflow: hidden; background: var(--rule-soft); }
.band .seg { border: none; padding: 0; min-width: 4px; transition: filter .12s ease, opacity .12s ease; }
.band .seg.on { filter: brightness(1.14) saturate(1.1); }
.band .seg.dim { opacity: .28; }
.band.empty {
  background: none; border: 1.5px dashed var(--rule); display: grid; place-items: center;
  color: var(--muted); font-size: 14px; text-align: center; padding: 0 12px;
}
.today { margin-top: 10px; font-size: 13.5px; color: var(--muted); display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.today b { color: var(--ink); font-variation-settings: "wght" 650; }

/* ---------------------------- add ---------------------------- */
.panel { background: var(--surface); border: 1px solid var(--rule-soft); border-radius: 10px; padding: 16px; box-shadow: var(--shadow); }
.panel h2 { margin: 0 0 12px; font-size: 15px; font-variation-settings: "wght" 650; letter-spacing: -.01em; }
.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.amt { display: flex; align-items: center; border: 1.5px solid var(--rule); border-radius: 8px; background: var(--paper); overflow: hidden; }
.amt span { padding: 0 8px 0 12px; color: var(--muted); font-size: 19px; }
.amt input { flex: 1; min-width: 0; border: none; background: none; padding: 14px 12px 14px 0; font-size: 28px; letter-spacing: -.02em; }
.amt input:focus { outline: none; }
.amt:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent); }
input.txt, input.dt {
  width: 100%; border: 1px solid var(--rule); border-radius: 8px; background: var(--paper);
  padding: 12px; font-size: 16px; min-height: 46px;
}
input.txt:focus, input.dt:focus { outline: none; border-color: var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 7px; }
.chip {
  border: 1px solid var(--rule); background: var(--paper); border-radius: 999px;
  padding: 9px 14px 9px 11px; font-size: 14px; display: inline-flex; align-items: center; gap: 7px; min-height: 40px;
}
.chip i { width: 9px; height: 9px; border-radius: 2.5px; display: block; flex: none; }
.chip.on { border-color: transparent; background: var(--ink); color: var(--paper); }
.row3 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row3 > :first-child { grid-column: 1 / -1; }
.save {
  width: 100%; background: var(--accent); color: var(--accent-ink); border: none;
  border-radius: 8px; padding: 15px; font-size: 16px; font-variation-settings: "wght" 700;
  margin-top: 4px; min-height: 52px;
}
.save:active { filter: brightness(.94); }
.save:disabled { opacity: .6; cursor: default; }

/* ---------------------------- categories ---------------------------- */
.cats { border-top: 1px solid var(--rule-soft); }
.sechead { margin: 0 0 6px; font-size: 15px; font-variation-settings: "wght" 650; }
.cat {
  display: grid; grid-template-columns: 11px 1fr auto auto; gap: 12px; align-items: center;
  width: 100%; text-align: left; background: none; border: none; border-bottom: 1px solid var(--rule-soft);
  padding: 13px 4px; color: inherit; min-height: 50px;
}
.cat.on { background: var(--surface); box-shadow: inset 2px 0 0 var(--ink); }
.dot { width: 11px; height: 11px; border-radius: 3px; }
.cat .nm { font-size: 15px; }
.cat .pc { color: var(--muted); font-size: 13.5px; width: 42px; text-align: right; }
.cat .am { font-size: 15.5px; font-variation-settings: "wght" 650; width: 96px; text-align: right; }

/* ---------------------------- entries ---------------------------- */
.hint { color: var(--muted); font-size: 13.5px; margin: 0 0 6px; }
.hint button { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }
.daygroup { margin-top: 4px; }
.daylabel {
  display: flex; justify-content: space-between; align-items: baseline;
  font-size: 12.5px; color: var(--muted); padding: 14px 2px 5px; border-bottom: 1px solid var(--rule-soft);
}
.ent {
  display: grid; grid-template-columns: 11px 1fr auto 40px; gap: 11px; align-items: center;
  padding: 12px 0 12px 2px; border-bottom: 1px solid var(--rule-soft); min-height: 52px;
}
.ent.pending { opacity: .55; }
.ent .w { font-size: 15px; overflow-wrap: anywhere; line-height: 1.25; }
.ent .w em { font-style: normal; color: var(--muted); font-size: 13px; display: block; }
.ent .a { font-size: 15.5px; font-variation-settings: "wght" 650; }
.ent .x {
  background: none; border: none; color: var(--muted); padding: 0; font-size: 20px; line-height: 1;
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; justify-self: end;
}
.ent .x:hover { color: var(--danger); background: var(--rule-soft); }
.none { color: var(--muted); font-size: 14.5px; padding: 16px 0; }

.foot {
  margin-top: 26px; padding-top: 14px; border-top: 1px solid var(--rule-soft);
  display: flex; gap: 14px; flex-wrap: wrap; color: var(--muted); font-size: 13px; align-items: center;
}
.foot button { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 6px 0; font-size: 13px; }
.foot button:hover { color: var(--ink); }
.foot button[hidden] { display: none; }

/* ---------------------------- install tip ---------------------------- */
.tip {
  margin-top: 18px; border: 1px dashed var(--rule); border-radius: 10px; padding: 14px 14px 12px;
  font-size: 14px; color: var(--muted); display: none;
}
.tip.show { display: block; }
.tip b { color: var(--ink); font-variation-settings: "wght" 650; }
.tip p { margin: 0 0 8px; }
.tip button { background: none; border: none; color: var(--accent); text-decoration: underline; padding: 6px 0; font-size: 13.5px; }

/* ---------------------------- flash ---------------------------- */
#flash {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  background: var(--ink); color: var(--paper); padding: 10px 14px 10px 18px; border-radius: 999px;
  font-size: 14.5px; box-shadow: var(--shadow); z-index: 60; max-width: calc(100vw - 28px);
  display: flex; align-items: center; gap: 14px;
}
#flash[hidden] { display: none; }
#flash button {
  background: none; border: none; color: var(--paper); text-decoration: underline;
  font-size: 14.5px; font-variation-settings: "wght" 650; padding: 4px 2px;
}

/* ---------------------------- jump to add ---------------------------- */
.fab {
  position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  z-index: 40; border: none; border-radius: 999px; padding: 14px 20px;
  background: var(--ink); color: var(--paper); font-size: 15px; font-variation-settings: "wght" 650;
  box-shadow: var(--shadow); opacity: 0; pointer-events: none; transition: opacity .18s ease;
}
.fab.show { opacity: 1; pointer-events: auto; }
@media (min-width: 880px) { .fab { display: none; } }
