/* flows — a cash-flow budget on your phone, set like bdbd's terminal app: one monospaced face
   (Iosevka Fixed), square boxes whose titles sit on their borders, and no color at all.
   Meaning comes from type instead: money in and out by its sign, "watch it" underlined,
   below zero in reverse video, the what-if hatched. */

/* ── Type ────────────────────────────────────────────────────────────────── */

@font-face {
  font-family: "Iosevka Fixed";
  src: url("../fonts/iosevka-fixed-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: "Iosevka Fixed";
  src: url("../fonts/iosevka-fixed-500.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: block;
}

@font-face {
  font-family: "Iosevka Fixed";
  src: url("../fonts/iosevka-fixed-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: block;
}

/* ── Tokens ──────────────────────────────────────────────────────────────── */

:root {
  color-scheme: light;
  --bg: #f2f2f2;
  --fg: #121212;
  --ink-2: #3b3b3b;
  --muted: #696969;
  --faint: #949494;
  --line: #c9c9c9;
  --line-2: #dedede;
  --hover: #e6e6e6;
  --hatch: rgba(0, 0, 0, 0.13);
  --scrim: rgba(18, 18, 18, 0.34);

  --mono: "Iosevka Fixed", ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
  --gutter: 16px;
  --tabbar-h: 54px;
  --topbar-h: 52px;
  --label-w: 11ch;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0e0e0e;
    --fg: #e9e9e9;
    --ink-2: #c2c2c2;
    --muted: #8d8d8d;
    --faint: #5f5f5f;
    --line: #353535;
    --line-2: #242424;
    --hover: #1b1b1b;
    --hatch: rgba(255, 255, 255, 0.14);
    --scrim: rgba(0, 0, 0, 0.62);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e0e0e;
  --fg: #e9e9e9;
  --ink-2: #c2c2c2;
  --muted: #8d8d8d;
  --faint: #5f5f5f;
  --line: #353535;
  --line-2: #242424;
  --hover: #1b1b1b;
  --hatch: rgba(255, 255, 255, 0.14);
  --scrim: rgba(0, 0, 0, 0.62);
}

/* ── Base ────────────────────────────────────────────────────────────────── */

*,
*::before,
*::after {
  box-sizing: border-box;
  border-radius: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font: 400 15px/1.45 var(--mono);
  font-variant-ligatures: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
  letter-spacing: inherit;
}

button {
  cursor: pointer;
  border: 0;
  background: none;
  padding: 0;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
}

h1,
h2,
h3 {
  font-weight: 700;
}

b,
strong {
  font-weight: 700;
}

:focus-visible {
  outline: 1px solid var(--fg);
  outline-offset: 2px;
}

::selection {
  background: var(--fg);
  color: var(--bg);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

svg.icon {
  width: 20px;
  height: 20px;
  flex: none;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.5;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

/* money and moods, in ink: the sign says in or out; "watch it" is underlined; below zero is
   reverse video; the rest is ink, grey, or faint */
.green,
.accent,
.purple,
.fg {
  color: var(--fg);
}

.amber {
  color: var(--fg);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 0.22em;
}

.red {
  color: var(--bg);
  background: var(--fg);
  padding: 0 0.3ch;
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
}

:is(p, div).amber,
:is(p, div).red {
  text-decoration: none;
  background: none;
  color: var(--fg);
  padding: 0;
}

:is(p, div).amber::before,
:is(p, div).red::before {
  content: "! ";
  font-weight: 700;
}

.muted { color: var(--muted); }
.dim { color: var(--faint); }
.bold { font-weight: 700; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.num { white-space: nowrap; }
.muted-inline { color: var(--muted); }
.debt-mark { font-size: 0.8em; margin-left: 0.4ch; }
.whatif-mark { margin-right: 0.5ch; }

/* ── The shell ───────────────────────────────────────────────────────────── */

.app {
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 12px;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) calc(var(--gutter) + var(--safe-right)) 0 calc(var(--gutter) + var(--safe-left));
  background: var(--bg);
  border-bottom: 1px solid transparent;
}

.topbar.-scrolled {
  border-bottom-color: var(--line);
}

.brand {
  flex: none;
  font: 700 13px/1 var(--mono);
  letter-spacing: 0.04em;
  color: var(--bg);
  background: var(--fg);
  padding: 5px 7px 6px;
  text-decoration: none;
}

.topbar__title {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}

.topbar__title h1 {
  margin: 0;
  font-size: 17px;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar__title .date {
  font-size: 12px;
  line-height: 1.3;
  color: var(--muted);
  white-space: nowrap;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 0;
  margin-right: -8px;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  color: var(--fg);
}

.icon-btn:active {
  background: var(--fg);
  color: var(--bg);
}

.icon-btn[disabled] {
  opacity: 0.3;
  pointer-events: none;
}

.tabs {
  display: none;
}

/* the bottom tab bar: four views and More */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 30;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  background: var(--bg);
  border-top: 1px solid var(--fg);
}

.tabbar > a,
.tabbar > button {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  height: var(--tabbar-h);
  padding: 0 2px;
  color: var(--muted);
  text-decoration: none;
  font-size: 12.5px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
}

.tabbar > * + * {
  border-left: 1px solid var(--line);
}

.tabbar > [aria-current="page"],
.tabbar > [aria-expanded="true"] {
  color: var(--bg);
  background: var(--fg);
  font-weight: 700;
  border-left-color: var(--fg);
}

.tabbar > [aria-current="page"] + *,
.tabbar > [aria-expanded="true"] + * {
  border-left-color: var(--fg);
}

/* the More menu, a box above its tab */
.menu {
  position: fixed;
  right: calc(8px + var(--safe-right));
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px);
  z-index: 40;
  min-width: 200px;
  background: var(--bg);
  border: 1px solid var(--fg);
  padding: 4px 0;
  box-shadow: 6px 6px 0 var(--hatch);
}

.menu[hidden] {
  display: none;
}

.menu a {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 16px;
  color: var(--fg);
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
}

.menu a[aria-current="page"] {
  background: var(--fg);
  color: var(--bg);
}

.menu a .x {
  font-size: 12px;
  font-weight: 400;
  color: var(--muted);
}

.menu a[aria-current="page"] .x {
  color: inherit;
}

.view {
  padding: 12px calc(var(--gutter) + var(--safe-right)) calc(var(--tabbar-h) + var(--safe-bottom) + 84px) calc(var(--gutter) + var(--safe-left));
  max-width: 1240px;
  margin: 0 auto;
  outline: none;
}

/* the add button */
.fab {
  position: fixed;
  right: calc(16px + var(--safe-right));
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 29;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 52px;
  height: 52px;
  background: var(--fg);
  color: var(--bg);
  box-shadow: 5px 5px 0 var(--hatch);
  transition: transform 0.2s var(--ease), opacity 0.15s;
}

.fab svg.icon {
  width: 24px;
  height: 24px;
  stroke-width: 2;
}

.fab span {
  display: none;
}

.fab:active {
  transform: translate(2px, 2px);
  box-shadow: 3px 3px 0 var(--hatch);
}

.fab[hidden] {
  display: none;
}

/* the add button steps aside while you scroll down a list */
.fab.-tucked {
  transform: translateY(calc(100% + 28px));
  opacity: 0;
  pointer-events: none;
}

/* the what-if banner: hatched, like everything that isn't real yet */
.banner {
  position: sticky;
  top: calc(var(--topbar-h) + var(--safe-top));
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px calc(var(--gutter) + var(--safe-right)) 7px calc(var(--gutter) + var(--safe-left));
  background: repeating-linear-gradient(-45deg, var(--hatch) 0 1px, transparent 1px 7px), var(--bg);
  border-top: 1px solid var(--fg);
  border-bottom: 1px solid var(--fg);
  font-size: 13px;
}

.banner[hidden] {
  display: none;
}

.banner__text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  cursor: pointer;
  font-weight: 500;
}

.banner.-warn {
  border-style: dashed none;
}

.banner .btn {
  flex: none;
  background: var(--bg);
}

.badge {
  display: inline-block;
  flex: none;
  font: 700 11px/1 var(--mono);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--bg);
  background: var(--fg);
  border: 1px solid var(--fg);
  padding: 3px 5px;
  white-space: nowrap;
  vertical-align: 1px;
}

.badge.-amber {
  color: var(--fg);
  background: var(--bg);
  border-style: dashed;
}

.badge.-dim {
  color: var(--muted);
  background: transparent;
  border-color: var(--line);
}

/* ── Panels: the title sits on the border ────────────────────────────────── */

.panel {
  position: relative;
  border: 1px solid var(--line);
  padding: 20px 16px 16px;
  margin: 22px 0 0;
  min-width: 0;
  background: var(--bg);
}

.panel:first-child {
  margin-top: 10px;
}

.panel.-accent,
.panel.-green,
.panel.-purple {
  border-color: var(--fg);
}

.panel.-amber {
  border: 1px dashed var(--fg);
}

.panel.-flush {
  padding-left: 0;
  padding-right: 0;
}

.panel__title {
  position: absolute;
  top: 0;
  left: 10px;
  right: 10px;
  transform: translateY(-50%);
  display: flex;
  flex-wrap: wrap; /* one line: an extra that doesn't fit wraps out of sight, whole */
  align-items: baseline;
  height: 1.3em;
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  pointer-events: none;
}

.panel__title > * {
  pointer-events: auto;
}

.panel__title .t {
  background: var(--bg);
  padding: 0 1ch;
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.panel__title .x {
  background: var(--bg);
  color: var(--muted);
  font-weight: 400;
  padding-right: 1ch;
  flex: none;
}

.panel__title .x::before {
  content: "· ";
}

.panel__corner {
  position: absolute;
  top: 0;
  right: 10px;
  transform: translateY(-50%);
  background: var(--bg);
  padding: 0 4px;
  display: flex;
  gap: 4px;
  z-index: 1;
}

.panel__foot {
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}

.panel__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: -4px 0 12px;
  flex-wrap: wrap;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  margin: 18px 0 8px;
  display: flex;
  align-items: baseline;
  gap: 1ch;
}

.section-title .x {
  color: var(--muted);
  font-weight: 400;
}

/* ── Headline numbers ────────────────────────────────────────────────────── */

.hero {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.hero__label,
.stat__label {
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero__value {
  font-size: 36px;
  font-weight: 400;
  line-height: 1.15;
  white-space: nowrap;
}

.hero__value.-sm {
  font-size: 30px;
}

.hero__value.red,
.stat__value.red {
  align-self: flex-start;
  padding: 0 0.25ch;
}

.hero__note {
  font-size: 12.5px;
  color: var(--muted);
}

.hero__note .link {
  color: var(--fg);
  text-decoration: underline;
  cursor: pointer;
}

.stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
  margin-top: 16px;
  border-top: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.stat {
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 10px 12px 11px;
  min-width: 0;
}

.stat__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat__value {
  display: inline-block;
  max-width: 100%;
  font-size: 19px;
  font-weight: 500;
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stat__note {
  font-size: 12px;
  color: var(--muted);
  margin-top: 2px;
  line-height: 1.35;
}

.stat__delta {
  font-size: 12px;
  margin-top: 2px;
}

.stat[data-act],
.hero[data-act] {
  cursor: pointer;
}

.stat[data-act]:active {
  background: var(--hover);
}

.stats.-four {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

/* label …… value, with a note under; the dots lead the eye across like a ledger */
.figs {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 1ch;
  row-gap: 6px;
  align-items: baseline;
  font-size: 14.5px;
}

.figs .l {
  display: flex;
  align-items: baseline;
  gap: 1ch;
  min-width: 0;
  color: var(--ink-2);
}

.figs .l::after {
  content: "";
  flex: 1;
  min-width: 2ch;
  border-bottom: 1px dotted var(--faint);
  transform: translateY(-0.3em);
}

.figs .v {
  text-align: right;
  font-weight: 500;
  white-space: nowrap;
}

.figs .v b {
  font-weight: 500;
}

.figs .n {
  grid-column: 1 / -1;
  margin-top: -4px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.35;
}

.figs .n:empty {
  display: none;
}

.figs .sep {
  grid-column: 1 / -1;
  height: 4px;
}

.figs .h {
  grid-column: 1 / -1;
  font-weight: 700;
  margin-top: 8px;
  font-size: 13px;
}

.monthly-line {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.6;
}

.monthly-line b {
  color: var(--fg);
  font-weight: 500;
}

/* ── Buttons, pickers, keys ──────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 1ch;
  height: 36px;
  padding: 0 12px;
  border: 1px solid var(--fg);
  background: var(--bg);
  color: var(--fg);
  font-weight: 500;
  font-size: 13.5px;
  white-space: nowrap;
  text-decoration: none;
}

.btn:active,
.btn[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
}

.btn svg.icon {
  width: 16px;
  height: 16px;
}

.btn.-primary {
  background: var(--fg);
  color: var(--bg);
  font-weight: 700;
}

.btn.-primary:active {
  background: var(--ink-2);
}

.btn.-danger {
  border-style: dashed;
}

.btn.-danger.-solid {
  border-style: solid;
  background: var(--fg);
  color: var(--bg);
}

.btn.-ghost {
  border-color: transparent;
  background: transparent;
  padding: 0 4px;
  text-decoration: underline;
  text-underline-offset: 0.25em;
  height: auto;
  min-height: 28px;
}

.btn.-ghost:active {
  background: var(--fg);
  color: var(--bg);
}

.btn.-sm {
  height: 30px;
  padding: 0 9px;
  font-size: 12.5px;
}

.btn.-block {
  width: 100%;
}

.btn[disabled] {
  opacity: 0.4;
  pointer-events: none;
}

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.picker {
  display: inline-flex;
  max-width: 100%;
  border: 1px solid var(--fg);
  overflow-x: auto;
  scrollbar-width: none;
}

.picker::-webkit-scrollbar {
  display: none;
}

.picker button {
  height: 30px;
  padding: 0 1.2ch;
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  white-space: nowrap;
}

.picker button + button {
  border-left: 1px solid var(--line);
}

.picker button[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
  font-weight: 700;
}

.picker button[aria-pressed="true"] + button {
  border-left-color: var(--fg);
}

.picker.-block {
  display: flex;
  width: 100%;
}

.picker.-block button {
  flex: 1;
}

kbd,
.key {
  font: 500 12px/1 var(--mono);
}

kbd {
  display: inline-block;
  padding: 2px 5px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  min-width: 2.2ch;
  text-align: center;
}

code {
  font-family: var(--mono);
  font-size: 0.95em;
  background: var(--hover);
  padding: 0 0.4ch;
}

/* ── Lists ───────────────────────────────────────────────────────────────── */

.list {
  margin: 0 -8px;
}

.row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 1px 12px;
  padding: 8px 8px;
  min-height: 48px;
  width: 100%;
  text-align: left;
  position: relative;
}

button.row,
a.row,
.row[data-act] {
  cursor: pointer;
}

button.row:active,
.row[data-act]:active {
  background: var(--hover);
}

.row.-selected {
  background: var(--fg);
  color: var(--bg);
}

.row.-selected :is(.row__sub, .muted, .dim) {
  color: color-mix(in srgb, var(--bg) 72%, var(--fg));
}

.row.-selected :is(.green, .accent, .purple, .fg, .amber) {
  color: inherit;
}

.row.-selected .red {
  background: var(--bg);
  color: var(--fg);
}

.row.-selected .switch {
  border-color: var(--bg);
}

.row.-selected .bar {
  background: color-mix(in srgb, var(--bg) 30%, var(--fg));
}

.row.-selected .bar > i {
  background: var(--bg);
}

.row__main {
  min-width: 0;
}

.row button.row__main {
  padding: 0;
  text-align: left;
}

.row__name {
  font-size: 15px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row__sub {
  font-size: 12.5px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.row__end {
  text-align: right;
  white-space: nowrap;
}

.row__amount {
  font-size: 15px;
  font-weight: 500;
}

.row__after {
  font-size: 12.5px;
  margin-top: 1px;
}

.row.-past .row__name,
.row.-past .row__amount,
.row.-paused .row__name {
  color: var(--muted);
}

.panel .list .row:last-child {
  margin-bottom: -4px;
}

.list-sep {
  height: 0;
  border-top: 1px dashed var(--line);
  margin: 6px 8px;
}

.group-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 8px 4px;
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.group-head:first-child {
  padding-top: 2px;
}

.group-head b {
  font-size: 11px;
  font-weight: 700;
  color: var(--fg);
}

.group-head .muted {
  font-weight: 400;
}

.empty-line {
  padding: 14px 8px;
  color: var(--muted);
  font-size: 13.5px;
}

.bar {
  display: inline-block;
  width: 10ch;
  height: 7px;
  background: var(--line-2);
  overflow: hidden;
  vertical-align: middle;
}

.bar > i {
  display: block;
  height: 100%;
  background: var(--fg);
}

/* ── Charts ──────────────────────────────────────────────────────────────── */

.chart {
  position: relative;
  width: 100%;
  touch-action: pan-y;
  user-select: none;
  -webkit-user-select: none;
}

.chart svg {
  display: block;
  width: 100%;
  overflow: visible;
}

.chart .axis {
  font: 400 11px var(--mono);
  fill: var(--muted);
}

.chart .axis.-lit {
  fill: var(--fg);
  font-weight: 700;
}

.chart .ink {
  fill: var(--fg);
}

.chart .hatch-line {
  stroke: var(--fg);
  stroke-width: 1;
}

.chart .zero {
  stroke: var(--fg);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart .floor {
  stroke: var(--fg);
  stroke-dasharray: 2 3;
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart .guide {
  stroke: var(--fg);
  stroke-width: 1;
  shape-rendering: crispEdges;
}

.chart__tip {
  position: absolute;
  top: -6px;
  transform: translate(-50%, -100%);
  background: var(--fg);
  color: var(--bg);
  padding: 4px 8px;
  font-size: 12px;
  line-height: 1.3;
  white-space: nowrap;
  pointer-events: none;
  z-index: 3;
}

.chart__tip b {
  font-weight: 700;
}

.chart__tip .red,
.chart__tip .amber {
  background: var(--bg);
  color: var(--fg);
  text-decoration: none;
}

.chart__tip[hidden] {
  display: none;
}

.chart-legend {
  display: flex;
  gap: 2ch;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
}

.chart-legend i {
  display: inline-block;
  width: 9px;
  height: 9px;
  margin-right: 0.8ch;
  vertical-align: -0.5px;
  background: var(--fg);
}

.chart-legend i.-hatch {
  background: repeating-linear-gradient(-45deg, var(--fg) 0 1px, transparent 1px 3px);
  outline: 1px solid var(--fg);
  outline-offset: -1px;
}

.chart-legend i.-light {
  background: var(--faint);
}

.chart-caption {
  font-size: 12px;
  color: var(--muted);
  margin-top: 6px;
  min-height: 1.3em;
}

/* ── Empty states and notes ──────────────────────────────────────────────── */

.empty {
  text-align: left;
  padding: 32px 4px 24px;
  max-width: 520px;
  margin: 0 auto;
}

.empty h2 {
  font-size: 17px;
  margin: 0 0 10px;
  line-height: 1.35;
}

.empty p {
  color: var(--muted);
  margin: 0 0 6px;
  line-height: 1.5;
  font-size: 14px;
}

.empty .btn-row {
  margin-top: 18px;
}

.warnings {
  margin-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.warning {
  display: flex;
  gap: 1ch;
  font-size: 12.5px;
  color: var(--ink-2);
  line-height: 1.45;
}

.warning::before {
  content: "!";
  font-weight: 700;
  color: var(--fg);
  flex: none;
}

.note {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
}

/* ── Sheets and dialogs ──────────────────────────────────────────────────── */

.layer {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.layer__scrim {
  position: absolute;
  inset: 0;
  background: var(--scrim);
  animation: fade-in 0.16s ease;
}

.layer.-closing .layer__scrim {
  animation: fade-out 0.16s ease forwards;
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes fade-out {
  to { opacity: 0; }
}

.sheet {
  position: relative;
  width: 100%;
  max-height: calc(100% - var(--safe-top) - 24px);
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-top: 1px solid var(--fg);
  animation: sheet-in 0.24s var(--ease);
  padding-bottom: var(--safe-bottom);
  outline: none;
}

.layer.-closing .sheet {
  animation: sheet-out 0.18s ease forwards;
}

@keyframes sheet-in {
  from { transform: translateY(100%); }
}

@keyframes sheet-out {
  to { transform: translateY(100%); }
}

.sheet__grip {
  display: none;
}

.sheet__head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 8px 8px var(--gutter);
  flex: none;
  border-bottom: 1px solid var(--line);
  touch-action: none;
}

.sheet__head h2 {
  flex: 1;
  margin: 0;
  font-size: 15px;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sheet__body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px var(--gutter) 16px;
  flex: 1;
  -webkit-overflow-scrolling: touch;
}

.sheet__foot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px var(--gutter) 12px;
  border-top: 1px solid var(--line);
  flex: none;
  background: var(--bg);
}

.sheet__foot .summary {
  flex: 1;
  min-width: 0;
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.4;
}

@media (max-width: 599.98px) {
  /* on a phone the consequence gets its own line over the buttons */
  .sheet__foot {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .sheet__foot .summary {
    flex: 1 1 100%;
  }

  .sheet__foot .summary:empty {
    display: none;
  }
}

.sheet__foot .summary.-error {
  color: var(--fg);
  font-weight: 500;
}

.sheet__foot .btn {
  height: 40px;
  padding: 0 14px;
  font-size: 14px;
}

.sheet.-small .sheet__body {
  padding-bottom: 8px;
}

html.-sheet-open body {
  overflow: hidden;
}

/* ── Forms: one row per field, a label and its box, and a preview line under ─ */

.form {
  display: flex;
  flex-direction: column;
}

.field {
  display: grid;
  grid-template-columns: var(--label-w) minmax(0, 1fr);
  column-gap: 1ch;
  align-items: center;
  padding: 5px 0 0;
}

.field__label {
  grid-column: 1;
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.field:focus-within .field__label {
  color: var(--fg);
}

.field__input,
.field .seg,
.field .switch {
  grid-column: 2;
}

.field__input {
  display: block;
  width: 100%;
  height: 40px;
  padding: 0 1ch;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 16px; /* no zoom on iOS */
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.field__input::placeholder {
  color: var(--faint);
}

.field__input:focus {
  border-color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--fg);
}

select.field__input {
  padding-right: 3ch;
  background-image: linear-gradient(45deg, transparent 50%, var(--fg) 50%), linear-gradient(135deg, var(--fg) 50%, transparent 50%);
  background-position: calc(100% - 15px) 50%, calc(100% - 10px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

textarea.field__input {
  height: auto;
  min-height: 96px;
  padding: 8px 1ch;
  resize: vertical;
  font-size: 13px;
  line-height: 1.4;
}

.field.-bad.-touched .field__input {
  border-style: dashed;
  border-color: var(--fg);
}

.field__preview,
.field__suggest {
  grid-column: 2;
}

.field__preview {
  min-height: 1.4em;
  padding: 3px 0 2px;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
  white-space: pre-line;
}

.field.-bad:not(.-touched) .field__preview {
  visibility: hidden;
}

.field:not(.-text) .field__preview:empty {
  display: none;
}

.field.-bad.-touched .field__preview {
  color: var(--fg);
}

.field.-bad.-touched .field__preview::before {
  content: "! ";
  font-weight: 700;
}

.field__suggest {
  display: flex;
  gap: 0 2ch;
  flex-wrap: wrap;
  padding-top: 5px;
}

.field__suggest:empty {
  display: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  font-size: 13px;
  color: var(--ink-2);
  text-decoration: underline dotted;
  text-underline-offset: 0.25em;
  white-space: nowrap;
}

.chip:active {
  background: var(--fg);
  color: var(--bg);
}

/* a choice: cells in a box, the chosen one in reverse */
.seg {
  display: flex;
  flex-wrap: wrap;
  border: 1px solid var(--fg);
  background: var(--line);
  gap: 1px;
}

.seg button {
  flex: 1 1 auto;
  min-height: 36px;
  padding: 4px 0.6ch;
  background: var(--bg);
  font-size: 13px;
  font-weight: 500;
  color: var(--ink-2);
  line-height: 1.2;
}

.seg button[aria-pressed="true"] {
  background: var(--fg);
  color: var(--bg);
  font-weight: 700;
}

.seg button:focus-visible {
  outline-offset: -3px;
  outline-color: var(--bg);
}

.switch-row {
  display: contents;
}

.switch-row .field__label {
  margin: 0;
}

/* a switch: a square box with a square knob */
.switch {
  position: relative;
  justify-self: start;
  width: 42px;
  height: 24px;
  border: 1px solid var(--fg);
  background: var(--bg);
  flex: none;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  background: var(--faint);
  transition: transform 0.14s var(--ease);
}

.switch[aria-checked="true"] {
  background: var(--fg);
}

.switch[aria-checked="true"]::after {
  transform: translateX(18px);
  background: var(--bg);
}

.form-note {
  font-size: 12.5px;
  color: var(--muted);
  line-height: 1.5;
  margin: 8px 0 4px;
}

.form-note b {
  color: var(--fg);
  font-weight: 500;
}

.form-heading {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 18px 0 4px;
  display: flex;
  align-items: center;
  gap: 1ch;
}

.form-heading::after {
  content: "";
  flex: 1;
  border-top: 1px solid var(--line);
}

.form-group {
  border-top: 1px solid var(--line);
  margin-top: 14px;
  padding-top: 4px;
}

.form-custom:empty {
  display: none;
}

.form-group-wrap[hidden],
.field[hidden],
.form-note[hidden],
.form-custom[hidden] {
  display: none;
}

.disclosure {
  display: inline-flex;
  align-items: center;
  gap: 1ch;
  margin: 12px 0 2px;
  font-weight: 500;
  font-size: 13.5px;
  text-decoration: underline;
  text-underline-offset: 0.25em;
}

.disclosure svg.icon {
  width: 14px;
  height: 14px;
  transition: transform 0.15s;
}

.disclosure[aria-expanded="true"] svg.icon {
  transform: rotate(90deg);
}

/* ── Cards (a flow's details) ────────────────────────────────────────────── */

.card-status {
  font-size: 14px;
  margin-bottom: 10px;
  line-height: 1.5;
}

.card-status .muted {
  display: block;
  font-size: 12.5px;
}

.kv {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  column-gap: 2ch;
  row-gap: 7px;
  font-size: 14px;
  align-items: baseline;
}

.kv .l {
  color: var(--muted);
  white-space: nowrap;
}

.kv .l small {
  color: var(--faint);
  font-size: 12px;
}

.kv .v {
  text-align: right;
  min-width: 0;
}

.kv .v.-text {
  text-align: left;
  line-height: 1.45;
}

.kv .v .muted {
  font-size: 12.5px;
}

.kv .sep {
  grid-column: 1 / -1;
  height: 6px;
}

.kv .h {
  grid-column: 1 / -1;
  font-weight: 700;
  margin-top: 6px;
}

.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(0, 1fr));
  gap: 0;
  margin-top: 18px;
  border: 1px solid var(--fg);
  background: var(--line);
  column-gap: 1px;
}

.action-grid .btn {
  flex-direction: column;
  height: auto;
  padding: 10px 2px;
  gap: 6px;
  font-size: 12px;
  border: 0;
}

.action-grid .btn svg.icon {
  width: 19px;
  height: 19px;
}

/* ── Toasts ──────────────────────────────────────────────────────────────── */

.toasts {
  position: fixed;
  left: calc(10px + var(--safe-left));
  right: calc(10px + var(--safe-right));
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 12px);
  z-index: 80;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 2ch;
  max-width: 560px;
  width: 100%;
  padding: 10px 10px 10px 12px;
  background: var(--fg);
  color: var(--bg);
  font-size: 13px;
  line-height: 1.4;
  animation: toast-in 0.2s var(--ease);
}

.toast.-error {
  outline: 1px dashed var(--bg);
  outline-offset: -4px;
}

.toast.-error .toast__text::before {
  content: "! ";
  font-weight: 700;
}

.toast.-leaving {
  animation: toast-out 0.16s ease forwards;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
}

@keyframes toast-out {
  to { opacity: 0; }
}

.toast__text {
  flex: 1;
  min-width: 0;
}

.toast .btn {
  flex: none;
  height: 28px;
  background: transparent;
  color: var(--bg);
  border-color: var(--bg);
  padding: 0 8px;
}

/* ── Command palette ─────────────────────────────────────────────────────── */

.palette-input {
  width: 100%;
  height: 46px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: transparent;
  padding: 0 var(--gutter);
  font-size: 16px;
  outline: none;
}

.palette-list {
  padding: 4px 0 10px;
}

.palette-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  text-align: left;
  padding: 8px var(--gutter);
}

.palette-item.-active,
.palette-item:active {
  background: var(--fg);
  color: var(--bg);
}

.palette-item .muted {
  font-size: 12px;
}

.palette-item.-active .muted {
  color: inherit;
  opacity: 0.75;
}

.palette-item mark {
  background: none;
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
}

/* ── Views ───────────────────────────────────────────────────────────────── */

/* the calendar: a ruled grid */
.cal-head {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 2px 0 10px;
}

.cal-head h2 {
  flex: 1;
  margin: 0;
  font-size: 18px;
}

.cal-head h2 small {
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 400;
  margin-left: 1ch;
}

.cal-caption {
  font-size: 12px;
  color: var(--muted);
  margin: -6px 0 10px;
}

.cal-weekdays,
.cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.cal-weekdays {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  margin-bottom: 4px;
  text-align: center;
}

.cal-weekdays .-we {
  color: var(--faint);
}

.cal-grid {
  touch-action: pan-y;
  gap: 1px;
  background: var(--line);
  border: 1px solid var(--line);
}

.day {
  position: relative;
  display: flex;
  flex-direction: column;
  min-height: 60px;
  padding: 4px 3px 3px;
  background: var(--bg);
  text-align: left;
  overflow: hidden;
  min-width: 0;
  font-size: 11px;
  line-height: 1.2;
  container-type: inline-size;
}

.day:active {
  background: var(--hover);
}

.day.-outside {
  background: var(--bg);
  pointer-events: none;
}

.day.-outside .day__num {
  color: var(--faint);
}

.day.-selected {
  box-shadow: inset 0 0 0 2px var(--fg);
  z-index: 1;
}

.day__top {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 2px;
}

.day__num {
  font-weight: 700;
  font-size: 12px;
}

.day.-past .day__num,
.day.-we .day__num {
  color: var(--muted);
  font-weight: 400;
}

.day.-today .day__num {
  background: var(--fg);
  color: var(--bg);
  font-weight: 700;
  padding: 0 3px;
  margin: -1px 0 0 -1px;
}

.day.-past .day__net,
.day.-past .day__bal {
  color: var(--muted);
}

.day__net {
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
}

.day__items {
  display: none;
  flex-direction: column;
  gap: 1px;
  margin-top: 3px;
  min-height: 0;
  overflow: hidden;
}

.day__item {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 10.5px;
}

.day__dots {
  display: flex;
  gap: 2px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.day__dots i {
  width: 5px;
  height: 5px;
  background: var(--fg);
}

.day__dots i.-in {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--fg);
}

.day__dots i.-debt {
  transform: rotate(45deg) scale(0.85);
}

.day.-past .day__dots i {
  opacity: 0.35;
}

.day__bal {
  margin-top: auto;
  text-align: right;
  font-size: 10.5px;
  white-space: nowrap;
  overflow: hidden;
  padding-top: 2px;
}

.day .compact {
  display: none;
}

@container (max-width: 60px) {
  .day .full { display: none; }
  .day .compact { display: inline; }
  .day__top {
    flex-direction: column;
    align-items: flex-start;
    gap: 1px;
  }
  .day__net,
  .day__bal {
    font-size: 10px;
  }
}

@container (min-width: 68px) {
  .day__items { display: flex; }
  .day__dots { display: none; }
}

/* paydays */
.cycle-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  margin: -2px 0 10px;
}

.cycle-nav .when {
  font-size: 12.5px;
  color: var(--muted);
  text-align: center;
  flex: 1;
  min-width: 0;
}

/* the what-if */
.change-row {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
}

.change-dot {
  width: 8px;
  height: 8px;
  background: var(--fg);
  flex: none;
}

.change-dot.-off {
  background: transparent;
  box-shadow: inset 0 0 0 1px var(--faint);
}

.change-dot.-bad {
  background: repeating-linear-gradient(-45deg, var(--fg) 0 1px, transparent 1px 3px);
  box-shadow: inset 0 0 0 1px var(--fg);
}

.change-row .switch,
.row > .switch {
  transform: scale(0.86);
  transform-origin: right center;
}

.verdict {
  display: flex;
  align-items: center;
  gap: 1ch 1.5ch;
  flex-wrap: wrap;
  font-size: 14.5px;
  margin-bottom: 14px;
}

.verdict b {
  font-weight: 700;
}

.strip {
  display: flex;
  height: 16px;
  overflow: hidden;
  gap: 1px;
}

.strip i {
  flex: 1;
  min-width: 1px;
}

.timeline-row {
  display: grid;
  grid-template-columns: 12ch minmax(0, 1fr);
  gap: 1ch;
  align-items: center;
  font-size: 12.5px;
  margin: 6px 0;
}

.timeline-row .name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timeline-track {
  position: relative;
  height: 8px;
}

.timeline-track .solid,
.timeline-track .dotted {
  position: absolute;
  top: 0;
  height: 8px;
}

.timeline-track .solid {
  background: var(--fg);
}

.timeline-track .solid.-never {
  background: repeating-linear-gradient(-45deg, var(--fg) 0 1px, transparent 1px 4px);
  box-shadow: inset 0 0 0 1px var(--fg);
}

.timeline-track .dotted {
  background: repeating-linear-gradient(90deg, var(--faint) 0 2px, transparent 2px 5px);
  height: 2px;
  top: 3px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: right;
  font-weight: 500;
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 4px 1ch 6px;
  white-space: nowrap;
  border-bottom: 1px solid var(--fg);
}

.table th:first-child,
.table td:first-child {
  text-align: left;
  padding-left: 0;
}

.table td {
  text-align: right;
  padding: 6px 1ch;
  border-top: 1px solid var(--line-2);
  white-space: nowrap;
}

.table td:last-child,
.table th:last-child {
  padding-right: 0;
}

.table tr.-lit td {
  background: var(--hover);
  font-weight: 700;
}

.table-scroll {
  overflow-x: auto;
  margin: 0 -16px;
  padding: 0 16px;
}

.search {
  position: relative;
  margin: 4px 0 6px;
}

.search svg.icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
}

.search input {
  width: 100%;
  height: 40px;
  border: 1px solid var(--line);
  background: var(--bg);
  padding: 0 1ch 0 34px;
  font-size: 16px;
  outline: none;
}

.search input:focus {
  border-color: var(--fg);
  box-shadow: inset 0 0 0 1px var(--fg);
}

/* the welcome screen */
.welcome {
  min-height: calc(100dvh - 180px);
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 4px 40px;
  max-width: 520px;
  margin: 0 auto;
}

.welcome__mark {
  width: 72px;
  height: 72px;
  margin: 0 0 22px;
}

.welcome__mark svg {
  width: 100%;
  height: 100%;
  display: block;
}

.welcome h2 {
  font-size: 22px;
  line-height: 1.3;
  margin: 0 0 12px;
}

.welcome p {
  color: var(--muted);
  line-height: 1.55;
  margin: 0 0 8px;
  font-size: 14px;
}

.welcome .btn-row {
  flex-direction: column;
  align-items: stretch;
  max-width: 340px;
  margin: 24px 0 0;
}

.welcome .btn {
  height: 46px;
  font-size: 15px;
  justify-content: flex-start;
  padding: 0 14px;
}

.help-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 8px 2ch;
  font-size: 13.5px;
  line-height: 1.45;
}

.help-grid dt {
  font-weight: 700;
  white-space: nowrap;
}

.help-grid dd {
  margin: 0;
  color: var(--muted);
}

/* ── Wider screens ───────────────────────────────────────────────────────── */

@media (max-width: 599.98px) {
  .stats > .stat:nth-child(odd):last-child {
    grid-column: 1 / -1;
  }

  .table .-wide {
    display: none;
  }
}

@media (min-width: 600px) {
  :root {
    --gutter: 22px;
    --label-w: 14ch;
  }

  .stats {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  }

  .stats.-four {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .hero__value {
    font-size: 42px;
  }

  .day {
    min-height: 76px;
    padding: 5px 5px 4px;
  }

  .day__num {
    font-size: 13px;
  }

  .layer {
    align-items: center;
    padding: 24px;
  }

  .sheet {
    max-width: 640px;
    border: 1px solid var(--fg);
    box-shadow: 8px 8px 0 var(--hatch);
    margin-bottom: max(16px, var(--safe-bottom));
    padding-bottom: 0;
  }

  @keyframes sheet-in {
    from { transform: translateY(12px); opacity: 0; }
  }

  @keyframes sheet-out {
    to { transform: translateY(8px); opacity: 0; }
  }

  .toasts {
    left: auto;
    right: calc(22px + var(--safe-right));
    align-items: flex-end;
    width: 460px;
  }
}

/* ── A book-sized screen and up: the terminal's arrangement ─────────────────
   From 600px wide (a foldable opened up, a tablet, a laptop) flows is laid out the way bdbd
   is in a terminal: the seven views as numbered tabs across the top, and a key bar along the
   bottom with what you can do from anywhere. The phone's tab bar, More and add button give
   way to them. */

.keybar {
  display: none;
}

@media (min-width: 600px) {
  :root {
    --tabbar-h: 0px;
    --topbar-h: 48px;
    --keybar-h: 44px;
  }

  .tabbar,
  .menu,
  .fab {
    display: none !important;
  }

  .topbar {
    gap: 14px;
    border-bottom: 1px solid var(--fg);
  }

  .topbar.-scrolled {
    border-bottom-color: var(--fg);
  }

  .topbar__title {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
  }

  .topbar__actions {
    display: none;
  }

  .tabs {
    display: flex;
    align-items: stretch;
    align-self: stretch;
    flex: 1;
    min-width: 0;
  }

  .tabs a {
    flex: 1 1 auto;
    max-width: 13em;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.7ch;
    padding: 0 0.6ch;
    color: var(--ink-2);
    text-decoration: none;
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
  }

  .tabs a .key {
    color: var(--faint);
  }

  .tabs a[aria-current="page"] {
    color: var(--bg);
    background: var(--fg);
    font-weight: 700;
  }

  .tabs a[aria-current="page"] .key {
    color: inherit;
    opacity: 0.6;
  }

  .banner {
    top: calc(var(--topbar-h) + var(--safe-top));
    border-top: 0;
  }

  /* the key bar: bdbd's footer, where every key is also a button */
  .keybar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 30;
    display: flex;
    align-items: stretch;
    height: calc(var(--keybar-h) + var(--safe-bottom));
    padding: 0 calc(var(--gutter) - 1ch + var(--safe-right)) var(--safe-bottom) calc(var(--gutter) - 1ch + var(--safe-left));
    background: var(--bg);
    border-top: 1px solid var(--fg);
    font-size: 12.5px;
    overflow: hidden;
  }

  .keybar button {
    display: inline-flex;
    align-items: center;
    gap: 0.8ch;
    padding: 0 1ch;
    color: var(--ink-2);
    font-weight: 500;
    white-space: nowrap;
  }

  .keybar kbd {
    border: 0;
    min-width: 0;
    padding: 2px 0.6ch;
    background: var(--fg);
    color: var(--bg);
    font-size: 11.5px;
    font-weight: 700;
  }

  .keybar button:active,
  .keybar button[aria-pressed="true"] {
    background: var(--fg);
    color: var(--bg);
  }

  .keybar button:active kbd,
  .keybar button[aria-pressed="true"] kbd {
    background: var(--bg);
    color: var(--fg);
  }

  .keybar__date {
    margin-left: auto;
    align-self: center;
    padding: 0 1ch;
    color: var(--muted);
    white-space: nowrap;
  }

  .view {
    padding-bottom: calc(var(--keybar-h) + var(--safe-bottom) + 40px);
  }

  .toasts {
    bottom: calc(var(--keybar-h) + var(--safe-bottom) + 12px);
  }

  /* on a page (a book held upright), two panels that belong together sit side by side */
  .pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0 16px;
    align-items: start;
  }

  .pair > .panel {
    margin-top: 22px;
  }

  /* a bigger month: every day has room for what's on it */
  .day {
    min-height: 92px;
  }
}

@media (min-width: 600px) and (max-width: 719.98px) {
  .tabs a {
    font-size: 12.5px;
  }

  .keybar .-help {
    display: none;
  }
}

/* ── Held open: two pages meeting at the fold ────────────────────────────────
   Landscape and wide enough (a foldable opened like a book, a tablet on its side, a laptop),
   each view is a spread: two panes split at the middle, where the fold is, each scrolling on
   its own, between tabs and a key bar that stay put. Where the browser can see the hinge
   (viewport segments), the panes meet exactly at it. */

@media (min-width: 820px) and (min-aspect-ratio: 6/5), (horizontal-viewport-segments: 2) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
  }

  .topbar,
  .banner,
  .keybar {
    position: relative;
    top: auto;
    flex: none;
  }

  .view {
    flex: 1;
    min-height: 0;
    width: 100%;
    max-width: none;
    margin: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding-bottom: 40px;
  }

  .view:has(> .spread) {
    overflow: hidden;
    padding: 0;
  }

  .spread {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    height: 100%;
    max-width: 1560px;
    margin: 0 auto;
  }

  .pane {
    min-height: 0;
    overflow-y: auto;
    overscroll-behavior: contain;
    padding: 8px var(--gutter) 16px;
  }

  .pane .panel {
    margin-top: 20px;
    padding: 18px 14px 14px;
  }

  .pane .panel:first-child {
    margin-top: 10px;
  }

  .pane .hero__value {
    font-size: 36px;
  }

  .pane .stats {
    margin-top: 12px;
  }

  .pane .stat {
    padding: 8px 10px 9px;
  }

  .pane .stats:not(.-four) > .stat:nth-child(odd):last-child {
    grid-column: 1 / -1;
  }

  .pane .panel__foot {
    margin-top: 10px;
    padding-top: 9px;
    line-height: 1.45;
  }

  .pane .row {
    min-height: 44px;
    padding-top: 6px;
    padding-bottom: 6px;
  }

  .pane:first-child {
    padding-left: calc(var(--gutter) + var(--safe-left));
  }

  .pane:last-child {
    padding-right: calc(var(--gutter) + var(--safe-right));
    border-left: 1px solid var(--line);
  }

  .pane .stats.-four {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  /* a page's last panel with a chart in it grows to the bottom of the page, and the chart
     with it (down to a floor, below which the page scrolls instead) */
  .pane {
    display: flex;
    flex-direction: column;
  }

  .pane > * {
    flex: none;
  }

  .pane > .panel.-grow {
    flex: 1 0 auto;
    display: flex;
    flex-direction: column;
  }

  .pane > .panel.-grow .chart.-fill {
    flex: 1 1 auto;
    min-height: 150px;
  }

  /* pinned at the top of its page while what's under it scrolls */
  .pane > .pin {
    position: sticky;
    top: -8px;
    z-index: 3;
    margin-top: -8px;
    padding: 8px 0 6px;
    background: var(--bg);
  }

  .pane > .pin > .panel:first-child {
    margin-top: 10px;
  }

  /* drawn to the chart's size, never setting it: it can shrink again (the banner appears) */
  .chart.-fill svg {
    position: absolute;
    top: 0;
    left: 0;
  }

  /* the calendar's month fills its page, however tall */
  .pane.-cal .cal-grid {
    flex: 1;
    grid-auto-rows: minmax(54px, 1fr);
  }

  .pane.-cal .day {
    min-height: 0;
  }
}

@media (horizontal-viewport-segments: 2) {
  .spread {
    max-width: none;
    grid-template-columns: env(viewport-segment-width 0 0) env(viewport-segment-width 1 0);
    column-gap: calc(env(viewport-segment-left 1 0) - env(viewport-segment-right 0 0));
  }

  .pane:last-child {
    border-left: 0;
  }
}

/* ── A mouse ─────────────────────────────────────────────────────────────── */

@media (hover: hover) and (pointer: fine) {
  .tabs a:hover:not([aria-current="page"]),
  .keybar button:hover:not([aria-pressed="true"]),
  .icon-btn:hover {
    background: var(--hover);
    color: var(--fg);
  }

  .btn:hover {
    background: var(--fg);
    color: var(--bg);
  }

  .btn.-primary:hover {
    background: var(--ink-2);
  }

  .btn.-ghost:hover {
    background: var(--fg);
    color: var(--bg);
  }

  .picker button:hover:not([aria-pressed="true"]),
  .seg button:hover:not([aria-pressed="true"]) {
    background: var(--hover);
    color: var(--fg);
  }

  button.row:hover,
  .row[data-act]:hover,
  .stat[data-act]:hover,
  .day:hover {
    background: var(--hover);
  }

  .row.-selected:hover {
    background: var(--fg);
  }

  .chip:hover {
    color: var(--fg);
    text-decoration-style: solid;
  }

  .row {
    min-height: 42px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
