:root {
  --bg: #f2f2f7;
  --card: #ffffff;
  --text: #1c1c1e;
  --muted: #6b6b70;
  --line: #e3e3e8;
  --accent: #0f766e;
  --accent-soft: #ccfbf1;
  --danger: #c0262d;
  --radius: 14px;
  --tab-h: 58px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --card: #1c1c1e;
    --text: #f2f2f7;
    --muted: #9a9aa0;
    --line: #2f2f33;
    --accent: #2dd4bf;
    --accent-soft: #134e4a;
    --danger: #ff6b6b;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  min-height: 100dvh;
}
[hidden] { display: none !important; }

h1 { font-size: 1.6rem; margin: 0; letter-spacing: -0.01em; }

.screen { padding-bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px); }
.bar {
  position: sticky; top: 0; z-index: 2;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
}
main { padding: 0 16px; }

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 16px;
  margin: 12px 0;
}

label { display: block; font-size: 0.85rem; color: var(--muted); margin: 14px 0 6px; font-weight: 500; }
label:first-child { margin-top: 0; }
#passcode-row label { margin-top: 14px; }

/* 16px+ font prevents iOS zoom-on-focus */
input {
  width: 100%;
  font: inherit; font-size: 17px;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
  min-height: 46px;
  -webkit-appearance: none; appearance: none;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
input[type="date"] { display: block; }

button {
  font: inherit; color: inherit; background: none; border: 0; cursor: pointer;
}
button.primary {
  display: block; width: 100%;
  margin-top: 20px; padding: 14px;
  border-radius: 12px;
  background: var(--accent); color: #fff;
  font-weight: 600; font-size: 17px;
}
@media (prefers-color-scheme: dark) { button.primary { color: #042f2e; } }
button:disabled { opacity: 0.5; }
button.link { color: var(--danger); padding: 8px 0; }

.error { color: var(--danger); min-height: 1.2em; margin: 10px 0 0; font-size: 0.9rem; }
.hint { color: var(--muted); font-size: 0.8rem; margin: 6px 0 0; }

/* Login */
.login-wrap {
  max-width: 420px; margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 48px) 16px 24px;
  text-align: center;
}
.login-wrap .card { text-align: left; margin-top: 24px; }
.login-logo { width: 72px; height: 72px; border-radius: 16px; margin-bottom: 12px; }

/* Amount */
.amount-field { position: relative; }
.amount-field span {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  font-size: 22px; color: var(--muted);
}
.amount-field input { font-size: 28px; font-weight: 600; padding-left: 34px; min-height: 58px; }

/* Category chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips button {
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--bg);
  font-size: 15px;
}
.chips button[aria-checked="true"] {
  background: var(--accent-soft); border-color: var(--accent); color: var(--text); font-weight: 600;
}

/* Summary */
.range { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.range label { margin: 0; }
.range input { margin-top: 4px; font-size: 16px; padding: 10px; }
.presets { display: flex; gap: 6px; margin-top: 12px; overflow-x: auto; scrollbar-width: none; }
.presets::-webkit-scrollbar { display: none; }
.presets button {
  flex: none; padding: 6px 12px; border-radius: 999px;
  background: var(--bg); border: 1px solid var(--line); font-size: 14px;
}

.grand { display: flex; justify-content: space-between; align-items: baseline; }
.grand span { color: var(--muted); }
.grand strong { font-size: 1.8rem; font-variant-numeric: tabular-nums; }
.by-cat { list-style: none; padding: 0; margin: 12px 0 0; }
.by-cat li { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; padding: 6px 0; font-size: 0.95rem; }
.by-cat .amt { font-variant-numeric: tabular-nums; }
.by-cat .meter { grid-column: 1 / -1; height: 4px; background: var(--line); border-radius: 2px; overflow: hidden; }
.by-cat .meter i { display: block; height: 100%; background: var(--accent); border-radius: 2px; }

.entries { list-style: none; padding: 0; margin: 0; background: var(--card); border-radius: var(--radius); overflow: hidden; }
.entries li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.entries li:last-child { border-bottom: 0; }
.entries .main { flex: 1; min-width: 0; }
.entries .cat { font-weight: 500; }
.entries .date { color: var(--muted); font-size: 0.85rem; }
.entries .amt { font-weight: 600; font-variant-numeric: tabular-nums; }
.entries .del { color: var(--muted); padding: 6px; font-size: 18px; line-height: 1; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

.account button:not(.link) {
  width: 100%; padding: 12px; border-radius: 12px;
  border: 1px solid var(--accent); color: var(--accent); font-weight: 600;
}

/* Bottom tab bar */
.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 3;
  display: flex;
  padding-bottom: env(safe-area-inset-bottom);
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--line);
}
.tabs button {
  flex: 1; height: var(--tab-h);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  font-size: 11px; color: var(--muted);
}
.tabs button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.tabs button[aria-current="page"] { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tab-h) + env(safe-area-inset-bottom) + 16px);
  transform: translate(-50%, 20px); opacity: 0;
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 999px; font-size: 15px;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 4;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
