:root {
  --pine: #143d31;
  --pine-deep: #0e2c24;
  --leaf: #1f7a4d;
  --paper: #f3f6f2;
  --card: #ffffff;
  --ink: #18221c;
  --muted: #5e6d64;
  --line: #d7e4dc;
  --danger: #9d2c2c;
  --shadow: 0 10px 30px rgba(20, 45, 34, 0.08);
  --radius: 18px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #101613;
    --card: #1a2420;
    --ink: #e7f0ea;
    --muted: #a3b5aa;
    --line: #2c3d34;
    --danger: #ffb4ab;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100dvh;
  background: #d5e2da;
  color: var(--ink);
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.4;
}

@media (prefers-color-scheme: dark) {
  body { background: #0b100e; }
}

button, input, select {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

a { color: var(--leaf); }

code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.92em;
}

.app {
  width: min(480px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--paper);
}

.screen[hidden],
.overlay[hidden],
[hidden] { display: none !important; }

.screen-plain {
  padding: calc(28px + env(safe-area-inset-top)) 16px 32px;
}

.brand { margin-bottom: 18px; }

.logo {
  display: block;
  width: 48px;
  height: 48px;
  margin-bottom: 14px;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.eyebrow.light { color: rgba(244, 250, 246, 0.72); }

h1, h2, h3, p { margin: 0; }

h1 { font-size: 1.8rem; line-height: 1.15; }

.lede, .prose p, .hint {
  color: var(--muted);
}

.lede { margin-top: 8px; }

.card, .summary, .expense, .category-list li {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.card { padding: 16px; }

.prose ol {
  margin: 12px 0;
  padding-left: 1.2rem;
}

.prose li { margin: 8px 0; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field span {
  font-size: 0.85rem;
  color: var(--muted);
}

input, select {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
}

.primary, .secondary, .danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
}

.primary {
  background: var(--pine);
  color: #f4faf6;
  font-weight: 600;
}

.primary.compact {
  width: auto;
  min-height: 48px;
  white-space: nowrap;
}

.secondary {
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}

.secondary.narrow {
  width: calc(100% - 32px);
  margin: 0 16px 12px;
}

.danger {
  margin-top: 8px;
  background: transparent;
  color: var(--danger);
  border: 1px solid var(--line);
}

.text-btn {
  border: 0;
  background: transparent;
  min-height: 44px;
  padding: 8px;
  color: inherit;
}

.text-btn.dark { color: var(--leaf); width: 100%; }

.icon-btn {
  width: 44px;
  height: 44px;
  flex: 0 0 44px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.28);
  background: transparent;
  color: inherit;
  font-size: 1.6rem;
  line-height: 1;
}

.linkish {
  border: 0;
  background: transparent;
  color: rgba(244, 250, 246, 0.86);
  text-decoration: underline;
  padding: 4px;
  min-height: 32px;
}

.hero {
  padding: calc(18px + env(safe-area-inset-top)) 16px 22px;
  background:
    radial-gradient(120% 90% at 100% 0%, rgba(255, 255, 255, 0.16), transparent 46%),
    var(--pine);
  color: #f4faf6;
}

.hero h1 { font-size: 1.35rem; }

.hero-top, .month-bar, .sheet-head, .inline-add, .expense-top, .cat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.top-actions { display: flex; }

.user-email {
  margin-top: 2px;
  color: rgba(244, 250, 246, 0.72);
  font-size: 0.82rem;
  word-break: break-all;
}

.month-bar { margin-top: 16px; }

.month-copy { flex: 1; text-align: center; }

.month-copy h2 {
  font-size: 1.15rem;
  font-weight: 600;
  text-transform: capitalize;
}

.total-label, .count {
  text-align: center;
  color: rgba(244, 250, 246, 0.78);
}

.total-label { margin-top: 14px; font-size: 0.85rem; }

.total {
  margin-top: 2px;
  text-align: center;
  font-size: clamp(2rem, 9vw, 2.7rem);
  font-weight: 700;
  letter-spacing: -0.03em;
}

.count { margin-top: 2px; font-size: 0.92rem; }

.summary {
  margin: -14px 16px 0;
  padding: 6px;
  position: relative;
}

.cat-row {
  width: 100%;
  text-align: left;
  border: 0;
  background: transparent;
  border-radius: 12px;
  padding: 10px;
  min-height: 44px;
}

.cat-row[aria-pressed="true"] { background: rgba(31, 122, 77, 0.12); }

.cat-name { flex: 1; }

.cat-sum {
  font-variant-numeric: tabular-nums;
  color: var(--muted);
}

.cat-bar {
  display: block;
  height: 4px;
  margin: 0 10px 8px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.cat-bar span {
  display: block;
  height: 100%;
  background: var(--leaf);
}

.pad { padding: 12px 16px; }

.status { color: var(--muted); font-size: 0.92rem; }

.status:empty, .error:empty { display: none; }

.error {
  color: var(--danger);
  margin: 8px 0;
}

.list { padding-bottom: 8px; }

.day-title {
  margin: 18px 16px 8px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
}

.expense {
  display: block;
  width: calc(100% - 32px);
  margin: 0 16px 8px;
  padding: 12px 14px;
  text-align: left;
  box-shadow: none;
}

.expense-note {
  font-weight: 600;
  min-width: 0;
  overflow-wrap: anywhere;
}

.expense-amount {
  flex: 0 0 auto;
  margin-left: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.expense-cat {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.85rem;
}

.empty {
  margin: 28px 16px;
  color: var(--muted);
  text-align: center;
}

.add-bar {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: min(480px, 100%);
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, var(--paper) 70%, transparent);
}

#screen-main { padding-bottom: calc(88px + env(safe-area-inset-bottom)); }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(12, 24, 18, 0.48);
}

.sheet {
  width: min(480px, 100%);
  max-height: min(92dvh, 760px);
  overflow: auto;
  padding: 8px 16px calc(16px + env(safe-area-inset-bottom));
  background: var(--card);
  border-radius: 22px 22px 0 0;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  margin: 6px auto 10px;
  border-radius: 99px;
  background: var(--line);
}

.sheet-head { margin-bottom: 8px; }

.sheet-head h2 {
  flex: 1 0 auto;
  font-size: 1.25rem;
  white-space: nowrap;
}

.inline-add { align-items: flex-end; }

.inline-add .field { margin-bottom: 0; }

.grow { flex: 1; }

.category-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
}

.category-list li {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
  padding: 8px 8px 8px 12px;
  box-shadow: none;
}

.category-list .name {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.category-list input.name-input { flex: 1; min-height: 40px; }

.mini {
  width: auto;
  min-height: 40px;
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: transparent;
}

.mini.danger { color: var(--danger); }

:focus-visible {
  outline: 2px solid var(--leaf);
  outline-offset: 2px;
}

@media (min-width: 640px) {
  body { padding: 24px 0; }

  .app {
    min-height: calc(100dvh - 48px);
    border-radius: 28px;
    overflow: hidden;
    box-shadow: var(--shadow);
  }

  .overlay { align-items: center; }

  .sheet {
    border-radius: 22px;
    margin: 16px;
  }
}
