:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --ink: #1d1d1f;
  --secondary: #6e6e73;
  --tertiary: #aeaeb2;
  --line: rgba(0, 0, 0, 0.08);
  --fill: rgba(0, 0, 0, 0.05);
  --blue: #0071e3;
  --red: #ff3b30;
  --green: #248a3d;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --digit-dur: 500ms;
  --digit-distance: 8px;
  --digit-stagger: 70ms;
  --digit-blur: 2px;
  --digit-ease: cubic-bezier(0.34, 1.45, 0.64, 1);
  --digit-dir-x: 0;
  --digit-dir-y: 1;
  --toast-open: 350ms;
  --toast-close: 220ms;
  --toast-distance: 12px;
  --toast-blur: 2px;
  --toast-scale: 0.97;
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Helvetica Neue", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: #ececef;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
input, select, textarea { font-size: 17px; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; }

#stage { min-height: 100%; display: flex; justify-content: center; }
#app {
  width: min(100%, 430px);
  height: 100dvh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
}
#screen {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  padding-top: env(safe-area-inset-top);
  padding-bottom: 18px;
}

.large-title {
  font-size: 32px;
  line-height: 1.12;
  font-weight: 650;
  letter-spacing: -0.4px;
  margin: 14px 22px 0;
}
.subtitle {
  margin: 4px 22px 18px;
  color: var(--secondary);
  font-size: 15px;
}
.section-label {
  margin: 22px 22px 8px;
  color: var(--secondary);
  font-size: 13px;
}
.footer-note {
  margin: 8px 22px 16px;
  color: var(--secondary);
  font-size: 13px;
  line-height: 1.45;
}

.eyebrow {
  margin: 16px 22px 0;
  color: var(--secondary);
  font-size: 13px;
}
.hero { margin: 2px 22px 0; padding: 0; }
.hero .kicker { font-size: 13px; color: var(--secondary); }
.hero .figure {
  margin-top: 2px;
  font-size: 44px;
  line-height: 1.05;
  font-weight: 600;
  letter-spacing: -1.2px;
  font-variant-numeric: tabular-nums;
}
.hero .aside { margin-top: 10px; font-size: 15px; color: var(--secondary); }
.money-out { color: var(--red); }
.money-in { color: var(--green); }
.money-profit { color: var(--blue); }
.money { font-variant-numeric: tabular-nums; letter-spacing: -0.3px; }

.mix {
  display: flex;
  height: 4px;
  margin-top: 14px;
  border-radius: 99px;
  overflow: hidden;
  background: var(--fill);
}
.mix i { display: block; height: 100%; }
.mix-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin-top: 8px;
  color: var(--secondary);
  font-size: 12px;
}
.mix-legend span { display: inline-flex; align-items: center; gap: 6px; }
.mix-legend i { width: 6px; height: 6px; border-radius: 99px; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  margin: 18px 16px 0;
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
}
.stats button {
  min-height: 74px;
  padding: 14px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-right: 0.5px solid var(--line);
  transition: background-color 160ms var(--ease);
}
.stats button:last-child { border-right: 0; }
.stats button:active { background: #f6f6f8; }
.stats span { font-size: 12px; color: var(--secondary); }
.stats strong {
  font-size: 16px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.3px;
}
.alert-line { margin: 10px 22px 0; color: var(--red); font-size: 13px; }
.actions {
  display: flex;
  margin: 12px 16px 4px;
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
}
.actions button {
  flex: 1;
  min-height: 44px;
  font-size: 15px;
  border-right: 0.5px solid var(--line);
  transition: background-color 160ms var(--ease);
}
.actions button:last-child { border-right: 0; }
.actions button:active { background: #f6f6f8; }
.section-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 18px;
}
.section-row .section-label { margin-bottom: 8px; }
.text-btn { color: var(--blue); font-size: 15px; min-height: 32px; }
.sheet-total { font-variant-numeric: tabular-nums; letter-spacing: -1px; }
.book {
  margin: 0 16px 16px;
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
}
.book-line {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  text-align: left;
  background: var(--card);
  border-bottom: 0.5px solid var(--line);
  transition: background-color 160ms var(--ease);
}
.book > :last-child { border-bottom: 0; }
.book-line:active { background: #f6f6f8; }
.book-line .stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.book-line .title, .book-line .meta {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.book-line .title { font-size: 16px; }
.book-line .meta { color: var(--secondary); font-size: 13px; }
.book-line .money { flex: none; }
.day-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  padding: 14px 16px 4px;
  color: var(--secondary);
  font-size: 13px;
}
.book .person {
  margin: 0;
  border-radius: 0;
  border-bottom: 0.5px solid var(--line);
}
.book .person:last-child { border-bottom: 0; }

.meter {
  display: block;
  height: 3px;
  margin-top: 8px;
  border-radius: 99px;
  background: var(--fill);
  overflow: hidden;
}
.meter i {
  display: block;
  height: 100%;
  background: var(--ink);
  border-radius: 99px;
  transition: width 420ms var(--ease);
}

.group {
  margin: 0 16px 8px;
  background: var(--card);
  border-radius: 16px;
  overflow: hidden;
}
.row, .form-row, .link-row {
  width: 100%;
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 16px;
  text-align: left;
  background: var(--card);
  border-bottom: 0.5px solid var(--line);
  transition: background-color 160ms var(--ease);
}
.group > :last-child { border-bottom: 0; }
.link-row:active, .row:active { background: #f3f3f5; }
.row .grow, .link-row .grow { flex: 1; min-width: 0; }
.row .title, .link-row .title { font-size: 17px; }
.row .meta, .link-row .meta, .muted { color: var(--secondary); font-size: 13px; }
.row .stack, .link-row .stack { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.dot {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: var(--red);
  flex: none;
  animation: pop 420ms var(--ease) both;
}
.chevron {
  width: 7px;
  height: 7px;
  border-right: 1.5px solid var(--tertiary);
  border-top: 1.5px solid var(--tertiary);
  transform: rotate(45deg);
  flex: none;
  transition: transform 250ms var(--ease);
}

.nav {
  display: grid;
  grid-template-columns: 72px 1fr 72px;
  align-items: center;
  min-height: 48px;
  padding: 6px 8px 4px;
  position: sticky;
  top: 0;
  z-index: 2;
  background: rgba(245, 245, 247, 0.86);
  backdrop-filter: saturate(180%) blur(18px);
}
.nav h1 { margin: 0; text-align: center; font-size: 17px; font-weight: 600; }
.nav-btn {
  color: var(--blue);
  font-size: 17px;
  min-height: 44px;
  padding: 0 8px;
  transition: transform 160ms var(--ease), opacity 160ms var(--ease);
}
.nav-btn:active { transform: scale(0.96); }
.nav-btn.right { justify-self: end; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 0 16px 12px;
}
.chip {
  border-radius: 999px;
  background: var(--fill);
  min-height: 34px;
  padding: 0 14px;
  font-size: 14px;
  color: var(--ink);
  white-space: nowrap;
  transition: transform 160ms var(--ease), background-color 160ms var(--ease);
}
.chip:active { transform: scale(0.96); }
.chip.primary, .primary-btn { background: var(--ink); color: white; }

.t-tabs {
  position: relative;
  display: flex;
  margin: 4px 16px 14px;
  padding: 3px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 11px;
}
.t-tabs-pill {
  position: absolute;
  top: 3px;
  left: 0;
  height: calc(100% - 6px);
  border-radius: 8px;
  background: white;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08);
  transition: transform 250ms var(--ease), width 250ms var(--ease);
  z-index: 0;
}
.t-tab {
  position: relative;
  z-index: 1;
  flex: 1;
  min-height: 32px;
  border-radius: 8px;
  color: var(--secondary);
  font-size: 15px;
  transition: color 200ms var(--ease);
}
.t-tab[aria-selected="true"] { color: var(--ink); font-weight: 600; }

.search {
  margin: 0 16px 12px;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 12px;
  min-height: 40px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  transition: background-color 200ms var(--ease), box-shadow 200ms var(--ease);
}
.search:focus-within {
  background: white;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.08);
}
.search input {
  width: 100%;
  border: 0;
  background: transparent;
  outline: none;
  min-height: 40px;
}

.person {
  margin: 0 16px 10px;
  background: white;
  border-radius: 16px;
  overflow: hidden;
}
.person-head {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  text-align: left;
}
.person-head strong { font-size: 17px; font-weight: 600; }
.person-head:active { background: #f6f6f8; }
.person-chevron { transform: rotate(135deg); }
.person[data-open="true"] .person-chevron { transform: rotate(-45deg); }
.person-panel {
  display: grid;
  grid-template-rows: 0fr;
  transition: grid-template-rows 250ms var(--ease);
}
.person[data-open="true"] .person-panel { grid-template-rows: 1fr; }
.person-panel-inner { overflow: hidden; }
.person-body { padding: 0 16px 14px; }
.mini-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mini-grid label, .full-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  color: var(--secondary);
}
.mini-grid input, .mini-grid select, .full-field input, .full-field select, .full-field textarea {
  border: 0;
  background: #f5f5f7;
  border-radius: 10px;
  min-height: 38px;
  padding: 6px 10px;
  transition: box-shadow 160ms var(--ease);
}
.mini-grid input:focus, .full-field input:focus, .full-field select:focus {
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.16);
  outline: none;
}
.full-field { margin-top: 8px; }
.switch-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 40px;
  margin-bottom: 8px;
  font-size: 15px;
}

input[type="checkbox"] {
  appearance: none;
  width: 51px;
  height: 31px;
  border-radius: 16px;
  background: #e5e5ea;
  position: relative;
  flex: none;
  margin-left: auto;
  transition: background-color 220ms var(--ease);
}
input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.18);
  transition: transform 250ms var(--ease);
}
input[type="checkbox"]:checked { background: #34c759; }
input[type="checkbox"]:checked::after { transform: translateX(20px); }

.check {
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 1.5px solid #c7c7cc;
  flex: none;
  position: relative;
  transition: background-color 180ms var(--ease), border-color 180ms var(--ease);
}
.check::after {
  content: "";
  position: absolute;
  left: 7px;
  top: 3px;
  width: 5px;
  height: 9px;
  border: solid white;
  border-width: 0 1.6px 1.6px 0;
  transform: rotate(45deg) scale(0.5);
  opacity: 0;
  transition: transform 180ms var(--ease), opacity 180ms var(--ease);
}
.check.on { background: var(--ink); border-color: var(--ink); }
.check.on::after { opacity: 1; transform: rotate(45deg) scale(1); }

.form-row span.label { width: 92px; flex: none; font-size: 17px; }
.form-row input, .form-row select, .form-row textarea {
  flex: 1;
  border: 0;
  background: transparent;
  text-align: right;
  min-width: 0;
  outline: none;
}
.form-row input[type="checkbox"] { flex: none; }
.form-row textarea { text-align: left; min-height: 72px; }

#tabbar {
  flex: none;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  min-height: 49px;
  padding-bottom: env(safe-area-inset-bottom);
  background: rgba(249, 249, 249, 0.9);
  border-top: 0.5px solid var(--line);
  backdrop-filter: saturate(180%) blur(20px);
}
#tabbar[hidden] { display: none; }
.tab {
  min-height: 49px;
  color: #8e8e93;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 10px;
  transition: color 200ms var(--ease), transform 160ms var(--ease);
}
.tab svg {
  width: 23px;
  height: 23px;
  stroke-width: 1.6;
  transition: transform 250ms var(--ease);
}
.tab.on { color: var(--ink); }
.tab.on svg { transform: translateY(-1px); }
.tab:active { transform: scale(0.96); }

#overlay { position: absolute; inset: 0; pointer-events: none; z-index: 5; }
#overlay .backdrop, #overlay .sheet, #overlay .alert { pointer-events: auto; }
.backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.32);
  opacity: 0;
  transition: opacity 250ms var(--ease);
}
.backdrop.is-open { opacity: 1; }
.backdrop.is-closing { opacity: 0; transition-duration: 160ms; }
.sheet {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  max-height: 88%;
  overflow: auto;
  background: var(--bg);
  border-radius: 18px 18px 0 0;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 340ms var(--ease);
}
.sheet.is-open { transform: translateY(0); }
.sheet.is-closing { transform: translateY(110%); transition-duration: 180ms; }
.sheet h2 { margin: 6px 20px 12px; font-size: 22px; font-weight: 650; letter-spacing: -0.3px; }
.grab {
  width: 36px;
  height: 5px;
  border-radius: 99px;
  background: #d1d1d6;
  margin: 8px auto 6px;
}
.alert {
  position: absolute;
  left: 42px;
  right: 42px;
  top: 30%;
  background: rgba(255, 255, 255, 0.96);
  border-radius: 16px;
  overflow: hidden;
  text-align: center;
  opacity: 0;
  transform: scale(0.96);
  transition: transform 250ms var(--ease), opacity 250ms var(--ease);
}
.alert.is-open { opacity: 1; transform: none; }
.alert.is-closing { opacity: 0; transform: scale(0.96); transition-duration: 150ms; }
.alert p { margin: 0; padding: 20px 16px 16px; font-size: 17px; line-height: 1.4; }
.alert-actions { display: flex; border-top: 0.5px solid var(--line); }
.alert-actions button {
  flex: 1;
  min-height: 46px;
  color: var(--blue);
  font-size: 17px;
}
.alert-actions button + button { border-left: 0.5px solid var(--line); font-weight: 600; }
.alert-actions .danger { color: var(--red); }

#toast {
  position: absolute;
  left: 20px;
  right: 20px;
  bottom: calc(68px + env(safe-area-inset-bottom));
  z-index: 6;
  background: rgba(29, 29, 31, 0.92);
  color: white;
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 15px;
  text-align: center;
  opacity: 0;
  transform: translateY(var(--toast-distance)) scale(var(--toast-scale));
  filter: blur(var(--toast-blur));
  pointer-events: none;
  transition:
    transform var(--toast-close) var(--ease),
    opacity var(--toast-close) var(--ease),
    filter var(--toast-close) var(--ease);
}
#toast.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  filter: blur(0);
  transition-duration: var(--toast-open);
}

.empty {
  margin: 36px 32px;
  text-align: center;
  color: var(--secondary);
  font-size: 15px;
  line-height: 1.5;
}
.empty strong { display: block; color: var(--ink); font-size: 17px; font-weight: 600; margin-bottom: 6px; }
.tag {
  font-size: 12px;
  color: var(--secondary);
  background: var(--fill);
  border-radius: 99px;
  padding: 2px 8px;
}
.tag.warn { color: var(--red); background: rgba(255, 59, 48, 0.1); }

@keyframes t-digit-pop-in {
  0% {
    transform: translate(calc(var(--digit-distance) * var(--digit-dir-x)), calc(var(--digit-distance) * var(--digit-dir-y)));
    opacity: 0;
    filter: blur(var(--digit-blur));
  }
  100% { transform: none; opacity: 1; filter: blur(0); }
}
.t-digit-group { display: inline-flex; align-items: baseline; }
.t-digit { display: inline-block; }
.t-digit-group.is-animating .t-digit {
  animation: t-digit-pop-in var(--digit-dur) var(--digit-ease) both;
}
.t-digit-group.is-animating .t-digit[data-stagger="1"] { animation-delay: var(--digit-stagger); }
.t-digit-group.is-animating .t-digit[data-stagger="2"] { animation-delay: calc(var(--digit-stagger) * 2); }
.t-digit-group.is-animating .t-digit[data-stagger="3"] { animation-delay: calc(var(--digit-stagger) * 3); }

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}
@keyframes slide-forward {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: none; }
}
@keyframes slide-back {
  from { opacity: 0; transform: translateX(-18px); }
  to { opacity: 1; transform: none; }
}
@keyframes pop {
  from { transform: scale(0.4); opacity: 0; }
  to { transform: none; opacity: 1; }
}
#screen.is-entering[data-dir="fade"] > * { animation: rise 420ms var(--ease) both; }
#screen.is-entering[data-dir="fade"] > *:nth-child(2) { animation-delay: 40ms; }
#screen.is-entering[data-dir="fade"] > *:nth-child(3) { animation-delay: 80ms; }
#screen.is-entering[data-dir="fade"] > *:nth-child(4) { animation-delay: 110ms; }
#screen.is-entering[data-dir="fade"] > *:nth-child(n+5) { animation-delay: 140ms; }
#screen.is-entering[data-dir="forward"] { animation: slide-forward 320ms var(--ease); }
#screen.is-entering[data-dir="back"] { animation: slide-back 320ms var(--ease); }

.gate { min-height: 100%; display: flex; flex-direction: column; justify-content: center; padding: 24px 0 64px; }
.gate .large-title { margin-top: 0; }

@media (min-width: 760px) {
  body { background: #1c1c1e; }
  #stage { align-items: center; padding: 28px 16px; }
  #app {
    height: min(932px, calc(100dvh - 56px));
    border-radius: 44px;
    border: 10px solid #0c0c0e;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28);
  }
  #tabbar { padding-bottom: 10px; }
  #toast { bottom: 74px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
