/* ---------------------------------------------------------------- tokens */

:root {
  color-scheme: light;
  --bg: #F6F5F2;
  --bg-blur: rgba(246, 245, 242, .86);
  --surface: #FFFFFF;
  --surface-2: #FAF9F6;
  --line: #E8E5DF;
  --ink: #17171A;
  --ink-2: #6E6E73;
  --ink-3: #A1A1A6;
  --egg: #C9822B;
  --egg-soft: #F7ECDD;
  --water: #3C7E9E;
  --water-soft: #E4EFF4;
  --skin: #A96A78;
  --skin-soft: #F4E8EA;
  --ok: #4E7A56;
  --danger: #A94B42;
  --heat-0: #F0EEE9;
  --heat-1: #E3E9DF;
  --heat-2: #CBD9C5;
  --heat-3: #AFC4A8;
  --heat-4: #8FAA88;
  --radius: 20px;
  --radius-sm: 14px;
  --radius-xs: 10px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --tab-h: 52px;
  --ease: cubic-bezier(.2, .8, .2, 1);
  --spring: cubic-bezier(.34, 1.56, .64, 1);
}

[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0C0D0E;
  --bg-blur: rgba(12, 13, 14, .86);
  --surface: #16181A;
  --surface-2: #1D2022;
  --line: #2A2D30;
  --ink: #F0EFEC;
  --ink-2: #9A9C9E;
  --ink-3: #7C7F81;
  --egg: #D99A4E;
  --egg-soft: #2B2118;
  --water: #5FA3BE;
  --water-soft: #16272E;
  --skin: #C0808D;
  --skin-soft: #2B1E21;
  --ok: #7FA487;
  --danger: #C86B60;
  --heat-0: #171A1B;
  --heat-1: #1F2A22;
  --heat-2: #2A3A2F;
  --heat-3: #3A4E3F;
  --heat-4: #4E6652;
}

/* ---------------------------------------------------------------- base */

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

[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC",
    "Helvetica Neue", Arial, sans-serif;
  font-size: 17px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overflow-x: hidden;
  transition: background-color .28s var(--ease), color .28s var(--ease);
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  touch-action: manipulation;
}

input {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  margin: 0;
}

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

:focus-visible {
  outline: 2px solid var(--ink-2);
  outline-offset: 2px;
  border-radius: 8px;
}

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

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

/* ---------------------------------------------------------------- shell */

.shell {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(var(--safe-t) + 10px) 20px 6px;
  min-height: calc(46px + var(--safe-t));
}

.topbar__date {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}

.topbar__actions { display: flex; align-items: center; gap: 2px; }

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--ink-2);
  transition: background-color .18s var(--ease), color .18s var(--ease),
    transform .09s var(--ease);
}

.icon-btn:active { transform: scale(.94); background: var(--surface-2); }
.icon-btn .icon { width: 19px; height: 19px; }

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2);
  color: var(--ink);
  font-size: 15px;
  font-weight: 600;
  line-height: 1;
  user-select: none;
}

.avatar--sm { width: 30px; height: 30px; font-size: 13px; }

.main {
  flex: 1;
  padding: 2px 20px calc(var(--tab-h) + var(--safe-b) + 30px);
}

.page { animation: pageIn .2s var(--ease) both; }
.page[hidden] { display: none; }

@keyframes pageIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

/* ---------------------------------------------------------------- today */

.daystrip {
  display: flex;
  gap: 6px;
  margin: 8px 0 14px;
}

.daystrip__chip {
  flex: 1;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: 11px;
  border: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 13px;
  transition: background-color .18s var(--ease), color .18s var(--ease),
    border-color .18s var(--ease), transform .09s var(--ease);
}

.daystrip__chip:active { transform: scale(.97); }

.daystrip__chip.is-active {
  background: var(--surface);
  border-color: transparent;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .05);
}

[data-theme="dark"] .daystrip__chip.is-active {
  box-shadow: none;
  border-color: var(--line);
}

.summary {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 16px;
  padding: 0 2px;
  min-height: 22px;
  font-size: 15px;
  color: var(--ink-2);
  transition: color .2s var(--ease);
}

.summary.is-done { color: var(--ok); }

.tag {
  flex: none;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font-size: 11px;
  line-height: 1.4;
  color: var(--ink-3);
}

.people { display: flex; flex-direction: column; gap: 12px; }

.person {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 6px;
}

.person__head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

.avatar-wrap {
  position: relative;
  width: 52px;
  height: 52px;
  flex: none;
  display: grid;
  place-items: center;
}

.ring {
  position: absolute;
  inset: 0;
  width: 52px;
  height: 52px;
  transform: rotate(-90deg);
}

.ring__track { fill: none; stroke: var(--line); stroke-width: 2; }

.ring__value {
  fill: none;
  stroke: var(--ok);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-dasharray: 150.8;
  stroke-dashoffset: 150.8;
  transition: stroke-dashoffset .32s var(--ease);
}

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

.person__name {
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -.01em;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.person__meta {
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.3;
  font-variant-numeric: tabular-nums;
}

.habits { list-style: none; margin: 0; padding: 0; }

.habit {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 54px;
  border-top: 1px solid var(--line);
  transition: opacity .2s var(--ease);
}

.habit:first-child { border-top: 0; }
.habit.is-done { opacity: .55; }

.habit__icon {
  width: 30px;
  height: 30px;
  border-radius: 9px;
  flex: none;
  display: grid;
  place-items: center;
  background: var(--tint);
  color: var(--accent);
}

.habit__icon .icon { width: 17px; height: 17px; }

.habit__name { flex: 1; min-width: 0; font-size: 15px; }

.habit__count {
  display: flex;
  align-items: baseline;
  gap: 2px;
  margin-right: 2px;
  font-variant-numeric: tabular-nums;
}

.habit__num {
  display: inline-block;
  font-size: 17px;
  font-weight: 600;
  transform-origin: center;
}

.habit.is-done .habit__num { color: var(--ok); }

.habit__den { font-size: 13px; color: var(--ink-3); }

.habit__num.is-bump { animation: bump .28s var(--spring); }

@keyframes bump {
  0% { transform: scale(1); }
  38% { transform: scale(1.16); }
  100% { transform: scale(1); }
}

.step {
  position: relative;
  width: 40px;
  height: 40px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--line);
  color: var(--ink-2);
  -webkit-touch-callout: none;
  user-select: none;
  transition: transform .09s var(--ease), background-color .18s var(--ease),
    border-color .18s var(--ease), color .18s var(--ease);
}

.step::after { content: ""; position: absolute; inset: -4px; }

.step .icon { width: 17px; height: 17px; }

.step:active { transform: scale(.9); background: var(--surface-2); }

.step.is-done {
  border-color: transparent;
  background: transparent;
  color: var(--ok);
}

.step:disabled { opacity: .3; }

.person--partner .step:not(.is-done) { visibility: hidden; }

.person__foot {
  position: relative;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 2px;
  padding: 6px 0 4px;
  border-top: 1px solid var(--line);
}

.like {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 10px;
  border-radius: 999px;
  color: var(--ink-3);
  font-size: 13px;
  transition: color .18s var(--ease), background-color .18s var(--ease),
    transform .09s var(--ease);
}

.like:active { transform: scale(.95); background: var(--surface-2); }
.like .icon { width: 16px; height: 16px; }
.like.is-set { color: var(--skin); }
.like__emoji { font-size: 16px; line-height: 1; }
.like.is-set .like__emoji { animation: pop .26s var(--spring); }

@keyframes pop {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.emoji-pop {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  z-index: 10;
  display: flex;
  gap: 2px;
  padding: 6px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .1);
  opacity: 0;
  transform: translateY(6px) scale(.98);
  pointer-events: none;
  transition: opacity .2s var(--ease), transform .24s var(--spring);
}

[data-theme="dark"] .emoji-pop { box-shadow: 0 8px 32px rgba(0, 0, 0, .45); }

.emoji-pop.is-open {
  opacity: 1;
  transform: none;
  pointer-events: auto;
}

.emoji-pop button {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  font-size: 19px;
  transition: background-color .15s var(--ease), transform .09s var(--ease);
}

.emoji-pop button:active { transform: scale(.92); background: var(--surface-2); }

/* ---------------------------------------------------------------- stats */

.segmented {
  position: relative;
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  background: var(--surface-2);
  border-radius: 12px;
  padding: 3px;
}

.segmented[data-count="2"] { --count: 2; }
.segmented[data-count="3"] { --count: 3; }
.segmented[data-count="1"] { --count: 1; }

.segmented button {
  position: relative;
  z-index: 1;
  height: 34px;
  border-radius: 9px;
  font-size: 13px;
  color: var(--ink-3);
  transition: color .18s var(--ease);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.segmented button.is-active { color: var(--ink); }

.segmented__pill {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc((100% - 6px) / var(--count, 2));
  border-radius: 9px;
  background: var(--surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, .06);
  transition: transform .22s var(--ease);
  z-index: 0;
}

[data-theme="dark"] .segmented__pill {
  background: var(--line);
  box-shadow: none;
  border: 0;
}

.segmented--people { margin-top: 8px; }

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  margin: 24px 0 18px;
}

.metric { display: flex; flex-direction: column; gap: 2px; padding-left: 2px; }

.metric + .metric {
  border-left: 1px solid var(--line);
  padding-left: 20px;
}

.metric__num {
  font-size: 34px;
  font-weight: 600;
  letter-spacing: -.03em;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
}

.metric__num i {
  font-style: normal;
  font-size: 18px;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--ink-3);
  margin-left: 1px;
}

.metric__label { font-size: 13px; color: var(--ink-3); }

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.heat-card { padding: 16px 16px 12px; }

.heat-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 10px;
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.heat-months {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  gap: 4px;
  height: 15px;
  margin-bottom: 6px;
}

.heat-months span {
  font-size: 11px;
  line-height: 15px;
  color: var(--ink-3);
  white-space: nowrap;
}

.heat {
  display: grid;
  grid-template-columns: repeat(13, 1fr);
  grid-template-rows: repeat(7, 1fr);
  grid-auto-flow: column;
  gap: 4px;
}

.heat__cell {
  aspect-ratio: 1;
  border-radius: 3px;
  background: var(--heat-0);
  position: relative;
  animation: heatIn .18s var(--ease) both;
  animation-delay: calc(var(--i, 0) * 10ms);
}

.heat__cell.l1 { background: var(--heat-1); }
.heat__cell.l2 { background: var(--heat-2); }
.heat__cell.l3 { background: var(--heat-3); }
.heat__cell.l4 { background: var(--heat-4); }

.heat__cell .dot {
  position: absolute;
  top: 2px;
  right: 2px;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--egg);
}

@keyframes heatIn {
  from { opacity: 0; transform: scale(.9); }
  to { opacity: 1; transform: none; }
}

.heat-legend {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 12px;
  font-size: 11px;
  color: var(--ink-3);
}

.heat-legend .heat__cell {
  width: 10px;
  height: 10px;
  aspect-ratio: auto;
  animation: none;
}

/* ---------------------------------------------------------------- settle */

.group { margin-top: 22px; }
.group:first-child { margin-top: 6px; }

.group__label {
  padding: 0 4px 8px;
  font-size: 13px;
  color: var(--ink-3);
}

.live-card { padding: 18px 16px 16px; }

.live-card .ledger { display: flex; flex-direction: column; }

.ledger__row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 5px 0;
  font-size: 15px;
}

.ledger__row .money { font-variant-numeric: tabular-nums; }
.ledger__row.is-debtor .money { color: var(--danger); }
.ledger__row.is-creditor .money { color: var(--ok); }

.diff {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.diff__label { font-size: 13px; color: var(--ink-2); }

.diff__amount {
  font-size: 28px;
  font-weight: 600;
  letter-spacing: -.03em;
  font-variant-numeric: tabular-nums;
}

.diff__amount.is-zero { color: var(--ink-3); }

.receipts { display: flex; flex-direction: column; gap: 10px; }

.receipt {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.receipt__top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.receipt__week {
  font-size: 13px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.receipt__status {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11px;
  color: var(--ink-3);
}

.receipt__status.is-revised { color: var(--egg); }

.receipt__rows { display: flex; flex-direction: column; gap: 6px; }

.receipt__row {
  display: flex;
  justify-content: space-between;
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.receipt__row span:first-child { color: var(--ink-2); }

.receipt__total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.receipt__total .label { font-size: 13px; color: var(--ink-2); }

.receipt__total .amount {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
}

.ghost {
  width: 100%;
  height: 38px;
  margin-top: 14px;
  border-radius: 11px;
  border: 1px solid var(--line);
  color: var(--ink-2);
  font-size: 13px;
  transition: background-color .18s var(--ease), transform .09s var(--ease);
}

.ghost:active { transform: scale(.99); background: var(--surface-2); }

.empty {
  padding: 28px 0;
  text-align: center;
  font-size: 13px;
  color: var(--ink-3);
}

/* ---------------------------------------------------------------- settings */

.list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
}

.field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 8px 14px;
}

.field + .field { border-top: 1px solid var(--line); }
.field > span:first-child { font-size: 15px; }

.field__value {
  font-size: 13px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.field__input {
  flex: 1;
  min-width: 0;
  padding: 6px 0;
  text-align: right;
  font-size: 16px;
}

.field__input::placeholder { color: var(--ink-3); }
.field__input--short { max-width: 72px; }

.stepper {
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border-radius: 10px;
  padding: 2px;
}

.stepper button {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: var(--ink-2);
  font-size: 17px;
  transition: background-color .15s var(--ease), transform .09s var(--ease);
}

.stepper button:active { transform: scale(.92); background: var(--surface); }

.stepper__value {
  min-width: 54px;
  text-align: center;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}

.switch-user {
  width: 100%;
  height: 46px;
  margin: 28px 0 8px;
  border-radius: 14px;
  color: var(--ink-2);
  font-size: 15px;
  transition: background-color .18s var(--ease);
}

.switch-user:active { background: var(--surface-2); }

/* ---------------------------------------------------------------- tabbar */

.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  background: var(--bg-blur);
  -webkit-backdrop-filter: blur(18px) saturate(1.4);
  backdrop-filter: blur(18px) saturate(1.4);
  border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b);
  transition: background-color .28s var(--ease);
}

.tabbar__inner {
  position: relative;
  max-width: 480px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: var(--tab-h);
}

.tabbar__indicator {
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--ink);
  transform: translateX(0);
  transition: transform .22s var(--ease);
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  color: var(--ink-3);
  font-size: 10px;
  transition: color .18s var(--ease);
}

.tab .icon { width: 20px; height: 20px; }
.tab.is-active { color: var(--ink); }

/* ---------------------------------------------------------------- login */

.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px calc(40px + var(--safe-b));
}

.login__inner { width: 100%; max-width: 340px; }

.brand-mark {
  display: block;
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  fill: none;
  stroke: var(--ink);
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login__title {
  margin: 0 0 6px;
  text-align: center;
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -.02em;
}

.login__hint {
  margin: 0 0 22px;
  text-align: center;
  font-size: 13px;
  color: var(--ink-3);
}

.identity { display: flex; flex-direction: column; gap: 10px; }

.identity__btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  height: 60px;
  padding: 0 14px 0 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  text-align: left;
  transition: transform .09s var(--ease), border-color .18s var(--ease);
}

.identity__btn:active { transform: scale(.985); border-color: var(--ink-3); }
.identity__btn:disabled { opacity: .55; }

.identity__avatar {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  flex: none;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface-2);
  font-size: 15px;
  font-weight: 600;
}

.identity__name { font-size: 16px; font-weight: 600; }

.identity__btn .icon {
  width: 18px;
  height: 18px;
  margin-left: auto;
  color: var(--ink-3);
}

/* ---------------------------------------------------------------- toast / boot */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tab-h) + var(--safe-b) + 18px);
  z-index: 40;
  max-width: 80vw;
  padding: 9px 14px;
  border-radius: 999px;
  background: var(--ink);
  color: var(--bg);
  font-size: 13px;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity .2s var(--ease), transform .24s var(--spring);
}

.toast.is-visible { opacity: 1; transform: translate(-50%, 0); }

.boot {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg);
  transition: opacity .25s var(--ease);
}

.boot.is-hidden { opacity: 0; pointer-events: none; }

.boot__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink-3);
  animation: bootPulse 1s var(--ease) infinite;
}

.boot__dot:nth-child(2) { animation-delay: .12s; }
.boot__dot:nth-child(3) { animation-delay: .24s; }

@keyframes bootPulse {
  0%, 100% { opacity: .25; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-2px); }
}

/* ---------------------------------------------------------------- motion pref */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
}
