:root {
  --accent: #F2762E; --accent-soft: rgba(242, 118, 46, .14);
  --bg: #F2F2F7; --card: #FFFFFF; --ink: #111114; --muted: #8A8A93; --line: rgba(60, 60, 67, .12);
  --field: #F2F2F7; --green: #1F9D55; --red: #D93A2B; --blue: #3478F6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .04), 0 8px 24px rgba(0, 0, 0, .05);
  color-scheme: light;
}
:root.dark {
  --bg: #000000; --card: #1C1C1E; --ink: #F5F5F7; --muted: #8E8E93; --line: rgba(84, 84, 88, .45);
  --field: #2C2C2E; --green: #32D74B; --red: #FF5F52; --blue: #4C8DFF; --accent-soft: rgba(242, 118, 46, .22);
  --shadow: none;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif; -webkit-font-smoothing: antialiased; }
[hidden] { display: none !important; }

.top {
  position: sticky; top: 0; z-index: 5; display: flex; justify-content: space-between; align-items: flex-end;
  padding: calc(env(safe-area-inset-top) + 12px) 20px 10px; background: var(--bg);
}
.top h1 { margin: 0; font-size: 32px; font-weight: 800; letter-spacing: -.02em; }
.subtitle { font-size: 15px; color: var(--muted); font-weight: 600; }
.icon-btn { width: 36px; height: 36px; border-radius: 18px; border: 0; background: var(--card); color: var(--ink); box-shadow: var(--shadow); font-size: 16px; }

main { padding: 4px 16px calc(env(safe-area-inset-bottom) + 96px); max-width: 600px; margin: 0 auto; }
section { display: none; animation: fade .18s ease; } section.on { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card { background: var(--card); border-radius: 20px; padding: 16px; margin-bottom: 14px; box-shadow: var(--shadow); }
.card h2 { font-size: 17px; margin: 0 0 10px; }
.hero .big { font-size: 34px; font-weight: 800; letter-spacing: -.02em; margin: 2px 0; }
.hero .row .big { font-size: clamp(18px, 5.5vw, 28px); white-space: nowrap; }
.big { font-size: 24px; font-weight: 800; letter-spacing: -.01em; }
.muted { color: var(--muted); font-size: 14px; } .small { font-size: 12px; margin-top: 8px; }
.hint { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }
.pos { color: var(--green); } .neg { color: var(--red); }
.empty { text-align: center; color: var(--muted); padding: 40px 0; }

label { display: block; font-size: 13px; color: var(--muted); margin: 14px 0 6px; font-weight: 500; }
input, select {
  width: 100%; font: inherit; font-size: 17px; padding: 12px 14px; border: 0; border-radius: 12px;
  background: var(--field); color: var(--ink); outline: none; -webkit-appearance: none; appearance: none;
}
input:focus, select:focus { box-shadow: 0 0 0 2px var(--accent); }
input[type=date] { min-height: 46px; }
select { background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 18px) 52%, calc(100% - 13px) 52%; background-size: 5px 5px; background-repeat: no-repeat; padding-right: 34px; }
.row { display: flex; gap: 10px; } .row > * { flex: 1; min-width: 0; }

.amount { display: flex; align-items: center; gap: 6px; margin: 18px 0 4px; }
.amount span { font-size: 30px; font-weight: 700; color: var(--muted); }
.amount input { font-size: 38px; font-weight: 800; background: transparent; padding: 0; letter-spacing: -.02em; }
.amount input:focus { box-shadow: none; }

.segmented { display: flex; background: var(--field); border-radius: 12px; padding: 3px; }
.segmented button { flex: 1; border: 0; background: transparent; color: var(--ink); padding: 9px 0; border-radius: 10px; font: inherit; font-weight: 600; font-size: 15px; }
.segmented button.on { background: var(--card); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
:root.dark .segmented button.on { background: #48484A; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button { border: 0; background: var(--field); color: var(--ink); padding: 9px 14px; border-radius: 20px; font: inherit; font-size: 15px; font-weight: 600; }
.chips button.on { background: var(--accent); color: #fff; }
.chips input { flex-basis: 100%; }

.primary, .secondary { width: 100%; margin-top: 18px; padding: 15px; border: 0; border-radius: 14px; font: inherit; font-size: 17px; font-weight: 700; }
.primary { background: var(--accent); color: #fff; }
.primary:active, .secondary:active { opacity: .7; }
.secondary { background: var(--card); color: var(--accent); box-shadow: var(--shadow); margin: 0 0 14px; }

details summary { font-weight: 700; font-size: 17px; list-style: none; display: flex; justify-content: space-between; }
details summary::after { content: "›"; color: var(--muted); transform: rotate(90deg); transition: .2s; }
details[open] summary::after { transform: rotate(-90deg); }
details summary::-webkit-details-marker { display: none; }

.line { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 0; }
.line + .line { border-top: 1px solid var(--line); }
.grp { padding: 10px 0; } .grp + .grp { border-top: 1px solid var(--line); }
.grp-top { display: flex; justify-content: space-between; gap: 10px; font-size: 15px; }
.bar { height: 6px; background: var(--field); border-radius: 3px; overflow: hidden; margin-top: 8px; position: relative; }
.bar i { display: block; height: 100%; background: var(--accent); border-radius: 3px; }
.bar i.over { background: var(--red); }
.bar b { position: absolute; top: 0; bottom: 0; width: 2px; background: var(--ink); opacity: .6; }

.gain { font-weight: 700; font-size: 16px; }
.stats { display: flex; gap: 8px; margin-top: 14px; }
.stats div { flex: 1; background: var(--field); border-radius: 12px; padding: 10px; display: flex; flex-direction: column; gap: 2px; }
.stats span { font-size: 12px; } .stats b { font-size: 16px; }

.years .line b { font-variant-numeric: tabular-nums; }
.ptable { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; margin-top: 6px; }
.ptable th { font-size: 12px; color: var(--muted); font-weight: 600; text-align: right; padding: 6px 0; }
.ptable td { text-align: right; padding: 9px 0 9px 8px; border-top: 1px solid var(--line); font-size: 14px; white-space: nowrap; }
.ptable th:first-child, .ptable td:first-child { text-align: left; }
input[type=range] { padding: 0; height: 28px; background: transparent; accent-color: var(--accent); -webkit-appearance: auto; appearance: auto; }

svg.chart { width: 100%; height: auto; display: block; }
svg.chart text { fill: var(--muted); font-size: 11px; }
.legend { display: flex; gap: 14px; font-size: 13px; color: var(--muted); margin-top: 6px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 5px; margin-right: 5px; vertical-align: -1px; }

.tx-top { display: flex; justify-content: space-between; gap: 10px; font-weight: 600; }
.chk { display: flex; align-items: center; gap: 10px; margin-top: 14px; font-size: 15px; color: var(--ink); }
.chk input { width: 22px; height: 22px; padding: 0; accent-color: var(--accent); -webkit-appearance: checkbox; appearance: checkbox; }

.tabs {
  position: fixed; left: 12px; right: 12px; bottom: calc(env(safe-area-inset-bottom) + 8px); z-index: 10;
  display: flex; max-width: 576px; margin: 0 auto; padding: 6px; border-radius: 26px;
  background: color-mix(in srgb, var(--card) 82%, transparent); backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%); box-shadow: 0 8px 30px rgba(0, 0, 0, .12); border: 1px solid var(--line);
}
.tabs button { flex: 1; border: 0; background: none; color: var(--muted); font: inherit; font-size: 10.5px; font-weight: 600;
  display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 6px 0; border-radius: 20px; position: relative; }
.tabs button svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.tabs button.on { color: var(--accent); background: var(--accent-soft); }
.tabs i { position: absolute; top: 2px; right: calc(50% - 22px); background: var(--red); color: #fff; font-style: normal;
  font-size: 10px; min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px; line-height: 16px; }
.tabs i:empty { display: none; }

.login { min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px; text-align: center; }
.login img { border-radius: 20px; box-shadow: var(--shadow); }
.login h1 { margin: 16px 0 4px; font-size: 30px; }
.login .primary { max-width: 320px; }

#toast { position: fixed; left: 50%; bottom: calc(env(safe-area-inset-bottom) + 92px); transform: translateX(-50%) translateY(10px);
  background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 20px; font-size: 15px; font-weight: 600;
  opacity: 0; transition: .2s; pointer-events: none; z-index: 20; white-space: nowrap; }
#toast.on { opacity: 1; transform: translateX(-50%); }
.loading main { opacity: .5; pointer-events: none; }
#ptr { position: fixed; left: 50%; top: calc(env(safe-area-inset-top) + 8px); z-index: 10; width: 34px; height: 34px; margin-left: -17px;
  border-radius: 17px; background: var(--card); box-shadow: var(--shadow); display: grid; place-items: center; opacity: 0;
  transform: translateY(-60px); pointer-events: none; }
#ptr i { width: 16px; height: 16px; border-radius: 50%; border: 2px solid var(--accent); border-top-color: transparent; }
#ptr.go i { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
