/* ============================================================== tokens ==== */
:root {
  color-scheme: light dark;

  --paper: #f6f2ea;
  --paper-raised: #fffdf8;
  --paper-sunken: #ece6da;
  --ink: #1b1813;
  --ink-2: #5d564a;
  --ink-3: #928a7b;
  --rule: #ded5c4;
  --rule-strong: #1b1813;

  /* One accent, used only for money that needs attention. */
  --hot: #a83b22;
  --calm: #3a6b4c;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;

  --radius: 10px;
  --tap: 44px;

  --dur-press: 120ms;
  --dur-state: 180ms;
  --dur-sheet: 260ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #14120f;
    --paper-raised: #1e1b16;
    --paper-sunken: #0d0c0a;
    --ink: #f2ede3;
    --ink-2: #b0a795;
    --ink-3: #7c7364;
    --rule: #332e26;
    --rule-strong: #f2ede3;
    --hot: #e8714f;
    --calm: #6fae84;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}

body {
  padding-bottom: env(safe-area-inset-bottom);
  min-height: 100dvh;
}

.num {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

/* ============================================================== shell ==== */
.shell {
  max-width: 560px;
  margin: 0 auto;
  padding: 0 var(--space-4);
}

.masthead {
  padding: calc(env(safe-area-inset-top) + var(--space-5)) 0 var(--space-4);
  border-bottom: 2px solid var(--rule-strong);
}

.masthead-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: var(--space-3);
}

.masthead-label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.masthead-figure {
  font-size: 34px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1;
}

.masthead-sub {
  margin-top: var(--space-2);
  font-size: 13px;
  color: var(--ink-2);
}

/* Tabs are a ruled strip, not pills, to stay in the ledger language. */
.tabs {
  display: flex;
  gap: var(--space-4);
  margin-top: var(--space-4);
}

.tab {
  appearance: none;
  background: none;
  border: 0;
  padding: var(--space-2) 0;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  color: var(--ink-3);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
}

.tab[aria-current="page"] {
  color: var(--ink);
  border-bottom-color: var(--rule-strong);
}

.tab-count {
  margin-left: var(--space-2);
  font-size: 12px;
  font-weight: 650;
  color: var(--paper);
  background: var(--hot);
  border-radius: 999px;
  padding: 1px 7px;
}

/* =============================================================== rows ==== */
.ledger { list-style: none; margin: 0; padding: 0; }

.row {
  border-bottom: 1px solid var(--rule);
  transition: opacity var(--dur-state) var(--ease-in),
              transform var(--dur-state) var(--ease-in);
}

.row[data-leaving="true"] {
  opacity: 0;
  transform: translateX(12px);
}

.row-main {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-2) var(--space-3);
  align-items: baseline;
  width: 100%;
  min-height: var(--tap);
  padding: var(--space-4) 0;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.row-main:active { transform: scale(0.995); }
.row-main { transition: transform var(--dur-press) var(--ease-out); }

.row-payee {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.row-amount {
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.row-meta {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  font-size: 12px;
  color: var(--ink-3);
}

.row-meta-dot::before { content: "·"; margin-right: var(--space-2); }

.alert-mark {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--hot);
  vertical-align: 1px;
  margin-right: 6px;
}

/* ============================================================== chips ==== */
.picker {
  display: none;
  padding: 0 0 var(--space-4);
}

.row[aria-expanded="true"] .picker { display: block; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.chip {
  appearance: none;
  font: inherit;
  font-size: 14px;
  font-weight: 550;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: 0 var(--space-3);
  min-height: var(--tap);
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out),
              background var(--dur-press) var(--ease-out);
}

.chip:active { transform: scale(0.96); }
.chip[data-role="more"] { background: none; border-style: dashed; color: var(--ink-2); }
.chip[data-busy="true"] { opacity: 0.5; pointer-events: none; }

.chip-group {
  display: block;
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ============================================================== sheet ==== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgb(0 0 0 / 0.4);
  opacity: 0;
  transition: opacity var(--dur-sheet) var(--ease-out);
  z-index: 10;
}

.sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 11;
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  border-top: 2px solid var(--rule-strong);
  border-radius: 14px 14px 0 0;
  transform: translateY(100%);
  transition: transform var(--dur-sheet) var(--ease-out);
  padding-bottom: env(safe-area-inset-bottom);
}

.sheet[data-open="true"] { transform: translateY(0); }
.sheet-backdrop[data-open="true"] { opacity: 1; }

/* `.sheet` sets display:flex, which beats the UA stylesheet's
   `[hidden] { display: none }`. Without this the closed sheet stays in the
   accessibility tree: its search box is tabbable and aria-modal is always on. */
.sheet[hidden],
.sheet-backdrop[hidden] { display: none; }

.sheet-head {
  padding: var(--space-4);
  border-bottom: 1px solid var(--rule);
}

.sheet-search {
  width: 100%;
  font: inherit;
  font-size: 16px; /* 16px avoids iOS zoom-on-focus */
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  padding: var(--space-3);
  min-height: var(--tap);
}

.sheet-list {
  overflow-y: auto;
  padding: var(--space-2) var(--space-4) var(--space-5);
  list-style: none;
  margin: 0;
}

.sheet-item {
  display: block;
  width: 100%;
  text-align: left;
  font: inherit;
  font-size: 15px;
  color: inherit;
  background: none;
  border: 0;
  border-bottom: 1px solid var(--rule);
  padding: var(--space-3) 0;
  min-height: var(--tap);
  cursor: pointer;
}

/* ============================================================== tally ==== */
.tally-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: var(--space-3);
  align-items: baseline;
  padding: var(--space-3) 0;
  border-bottom: 1px solid var(--rule);
}

.tally-name { font-size: 15px; font-weight: 550; }
.tally-week { font-size: 15px; font-weight: 700; }

.tally-pace {
  font-size: 12px;
  font-weight: 650;
  min-width: 52px;
  text-align: right;
}

.pace-hot { color: var(--hot); }
.pace-calm { color: var(--calm); }
.pace-none { color: var(--ink-3); }

/* Pace must read without relying on colour alone, so over- and under-pace
   differ by fill as well: solid for over, hollow for under. */
.tally-pace::after {
  content: "";
  display: inline-block;
  width: 7px;
  height: 7px;
  margin-left: 6px;
  border-radius: 2px;
  border: 1.5px solid currentColor;
  vertical-align: 0;
}

.pace-hot::after { background: currentColor; }
.pace-none::after { display: none; }

.section-rule {
  margin: var(--space-6) 0 var(--space-2);
  padding-bottom: var(--space-2);
  border-bottom: 2px solid var(--rule-strong);
  font-size: 11px;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* =============================================================== lock ==== */
.lock {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: var(--space-5);
  padding: var(--space-6) var(--space-4);
}

.pin-dots { display: flex; gap: var(--space-3); }

.pin-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1.5px solid var(--ink-3);
  transition: background var(--dur-press) var(--ease-out),
              border-color var(--dur-press) var(--ease-out);
}

.pin-dot[data-filled="true"] { background: var(--ink); border-color: var(--ink); }

.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-3);
  width: min(280px, 100%);
}

.key {
  appearance: none;
  font: inherit;
  font-size: 22px;
  font-weight: 550;
  color: var(--ink);
  background: var(--paper-raised);
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  height: 60px;
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out);
}

.key:active { transform: scale(0.94); }
.key[data-role="blank"] { visibility: hidden; }
.key[data-role="del"] { font-size: 16px; }

.lock[data-shake="true"] .pin-dots { animation: shake 320ms var(--ease-out); }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  75% { transform: translateX(7px); }
}

/* ============================================================= common ==== */
.notice {
  margin: var(--space-4) 0;
  padding: var(--space-3);
  border-left: 3px solid var(--hot);
  background: var(--paper-raised);
  font-size: 14px;
  color: var(--ink-2);
}

.button {
  appearance: none;
  font: inherit;
  font-size: 15px;
  font-weight: 600;
  color: var(--paper);
  background: var(--ink);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  padding: 0 var(--space-4);
  min-height: var(--tap);
  cursor: pointer;
  transition: transform var(--dur-press) var(--ease-out);
}

.button:active { transform: scale(0.97); }
.button[data-variant="quiet"] { background: none; color: var(--ink); border-color: var(--rule); }
.button[disabled] { opacity: 0.45; cursor: default; }

.stack { display: flex; flex-direction: column; gap: var(--space-3); align-items: flex-start; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + var(--space-5));
  transform: translate(-50%, 16px);
  z-index: 20;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  font-weight: 550;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-state) var(--ease-out),
              transform var(--dur-state) var(--ease-out);
}

.toast[data-open="true"] { opacity: 1; transform: translate(-50%, 0); }

:where(button, a, input):focus-visible {
  outline: 2px solid var(--hot);
  outline-offset: 2px;
}

.empty {
  padding: var(--space-6) 0;
  font-size: 15px;
  color: var(--ink-2);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
  .row[data-leaving="true"] { transform: none; }
}
