/* ============================================================
   Financial Freedom Tracker — brand design system
   Palette (only these six):
   Paper #FBFCF5 · Pale #EDF3E7 · Light #D1E5BE
   Gold #E7BF34 · Emerald #005C50 · Forest #032D27
   ============================================================ */

:root {
  --paper: #FBFCF5;
  --pale: #EDF3E7;
  --light: #D1E5BE;
  --gold: #E7BF34;
  --emerald: #005C50;
  --forest: #032D27;

  --font-head: "Fraunces", Georgia, serif;
  --font-sub: "Archivo", "Arial Narrow", sans-serif;
  --font-body: "Mulish", -apple-system, "Segoe UI", sans-serif;

  --shadow: 0 18px 40px -18px rgba(3, 45, 39, 0.22);
  --radius: 20px;
  --tabbar-h: 76px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

[hidden] { display: none !important; }

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

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--forest);
  font-size: 16px;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, select { font: inherit; color: var(--forest); }

:focus-visible { outline: 3px solid var(--emerald); outline-offset: 2px; border-radius: 6px; }

.muted { color: rgba(3, 45, 39, 0.55); font-weight: 400; }

/* ---------- layout ---------- */

#screen {
  max-width: 520px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 16px) 20px calc(var(--tabbar-h) + 32px);
  outline: none;
}

.screen-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin: 8px 0 18px;
}

h1.screen-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 30px;
  letter-spacing: -0.01em;
  line-height: 1.15;
}

.screen-sub {
  font-family: var(--font-sub);
  font-stretch: 118%;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--emerald);
}

/* ---------- cards ---------- */

.card {
  background: var(--pale);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.card.card-deep { background: var(--forest); color: var(--paper); }
.card.card-deep .muted { color: rgba(251, 252, 245, 0.6); }
.card.card-plain { box-shadow: none; }

.card-label {
  font-family: var(--font-sub);
  font-stretch: 118%;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--emerald);
  margin-bottom: 8px;
}
.card-deep .card-label { color: var(--light); }

.hero-number {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 64px;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.hero-number.gold { color: var(--gold); }
.hero-number small { font-size: 0.45em; font-weight: 600; }

.hero-read { margin-top: 10px; font-size: 15px; }

.big-number {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 36px;
  line-height: 1.1;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.delta-up { color: var(--emerald); font-weight: 700; }
.card-deep .delta-up { color: var(--light); }
.delta-down { color: var(--gold); font-weight: 700; }

/* ---------- buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 12px 22px;
  border-radius: 999px;
  font-family: var(--font-sub);
  font-stretch: 112%;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: 0.02em;
  transition: transform 0.12s ease, opacity 0.12s ease;
}
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--emerald); color: var(--paper); }
.btn-gold { background: var(--gold); color: var(--forest); }
.btn-ghost { background: transparent; color: var(--emerald); box-shadow: inset 0 0 0 2px var(--emerald); }
.btn-big { width: 100%; min-height: 56px; font-size: 17px; }
.btn-small { min-height: 38px; padding: 6px 16px; font-size: 13px; }

.btn-row { display: flex; gap: 10px; flex-wrap: wrap; }

/* ---------- tab bar ---------- */

#tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--paper);
  border-top: 1px solid var(--pale);
  display: flex;
  justify-content: space-around;
  align-items: stretch;
  z-index: 40;
  max-width: 100%;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  font-family: var(--font-sub);
  font-stretch: 112%;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: rgba(3, 45, 39, 0.5);
  min-width: 56px;
}
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; }
.tab[data-nav="home"] svg { fill: currentColor; stroke: none; }
.tab.active { color: var(--emerald); }

.tab-add { position: relative; }
.tab-add svg {
  width: 52px; height: 52px;
  background: var(--emerald);
  color: var(--paper);
  border-radius: 999px;
  padding: 13px;
  margin-top: -22px;
  box-shadow: var(--shadow);
}
.tab-add span { color: var(--emerald); }

/* ---------- add sheet ---------- */

#sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(3, 45, 39, 0.45);
  z-index: 50;
}

#add-sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--paper);
  border-radius: 24px 24px 0 0;
  padding: 14px 24px calc(24px + env(safe-area-inset-bottom));
  z-index: 51;
  max-width: 520px;
  margin: 0 auto;
  box-shadow: 0 -12px 40px rgba(3, 45, 39, 0.25);
  animation: sheet-up 0.22s ease;
}
@keyframes sheet-up { from { transform: translateY(40%); opacity: 0.5; } to { transform: none; opacity: 1; } }

.sheet-handle { width: 44px; height: 5px; border-radius: 3px; background: var(--light); margin: 0 auto 14px; }
.sheet-title { font-family: var(--font-head); font-size: 22px; margin-bottom: 14px; }

.field-label {
  display: block;
  font-family: var(--font-sub);
  font-stretch: 112%;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--emerald);
  margin: 14px 0 6px;
}

.amount-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--pale);
  border-radius: 16px;
  padding: 6px 18px;
}
.amount-cur { font-family: var(--font-head); font-size: 34px; font-weight: 600; color: var(--emerald); }
#add-amount {
  flex: 1;
  border: none;
  background: transparent;
  font-family: var(--font-head);
  font-size: 44px;
  font-weight: 700;
  width: 100%;
  min-width: 0;
  color: var(--forest);
}
#add-amount:focus { outline: none; }

#add-note, .text-input, .date-input, select.select-input {
  width: 100%;
  border: none;
  background: var(--pale);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 16px;
}
.date-input { margin-top: 12px; color: rgba(3,45,39,0.7); }

#add-form .btn-big { margin-top: 18px; }

/* ---------- lists ---------- */

.entry-list { list-style: none; }
.entry-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 4px;
  border-bottom: 1px solid var(--pale);
}
.entry-note { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entry-date { font-size: 12px; color: rgba(3,45,39,0.5); min-width: 52px; }
.entry-amt { font-weight: 700; font-variant-numeric: tabular-nums; }
.entry-del {
  color: rgba(3,45,39,0.35);
  font-size: 20px;
  line-height: 1;
  padding: 8px;
  min-width: 40px; min-height: 40px;
  border-radius: 10px;
}
.entry-del:hover { color: var(--emerald); background: var(--pale); }

/* ---------- rings ---------- */

.ring-wrap { display: flex; align-items: center; gap: 20px; }
.ring { transform: rotate(-90deg); }
.ring .track { stroke: rgba(3, 45, 39, 0.12); }
.card-deep .ring .track { stroke: rgba(251, 252, 245, 0.18); }
.ring .bar { stroke: var(--gold); transition: stroke-dashoffset 0.8s ease; }
.ring-center {
  position: absolute; inset: 0;
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.ring-box { position: relative; }

/* ---------- progress bar ---------- */

.bar-track { height: 10px; border-radius: 6px; background: rgba(3,45,39,0.12); overflow: hidden; }
.card-deep .bar-track { background: rgba(251,252,245,0.18); }
.bar-fill { height: 100%; border-radius: 6px; background: var(--gold); transition: width 0.6s ease; }

/* ---------- milestones ---------- */

.milestone-row { display: flex; gap: 14px; padding: 14px 0; border-bottom: 1px solid rgba(3,45,39,0.08); align-items: flex-start; }
.milestone-row:last-child { border-bottom: none; }
.milestone-dot {
  width: 34px; height: 34px; flex: none;
  border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-sub); font-weight: 700; font-size: 14px;
  background: var(--pale); color: rgba(3,45,39,0.45);
  box-shadow: inset 0 0 0 2px rgba(3,45,39,0.12);
}
.milestone-row.done .milestone-dot { background: var(--gold); color: var(--forest); box-shadow: none; }
.milestone-row.current .milestone-dot { background: var(--emerald); color: var(--paper); box-shadow: none; }
.milestone-name { font-weight: 700; }
.milestone-row.done .milestone-name::after { content: " ✓"; color: var(--emerald); }
.milestone-desc { font-size: 13.5px; color: rgba(3,45,39,0.6); }

/* ---------- streak ---------- */

.streak-pill {
  display: inline-flex; align-items: center; gap: 7px;
  background: var(--light);
  color: var(--forest);
  border-radius: 999px;
  padding: 7px 14px;
  font-family: var(--font-sub);
  font-stretch: 112%;
  font-weight: 700;
  font-size: 13px;
}
.streak-pill .flame { width: 14px; height: 14px; border-radius: 50% 50% 50% 0; background: var(--gold); transform: rotate(-45deg); }

/* ---------- tables ---------- */

.nw-group { margin-bottom: 6px; }
.nw-group-head {
  display: flex; justify-content: space-between; align-items: baseline;
  padding: 10px 0 4px;
  font-family: var(--font-sub); font-stretch: 112%;
  font-size: 12px; font-weight: 700; letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--emerald);
}
.nw-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--pale); }
.nw-row input { width: 130px; text-align: right; background: var(--pale); border: none; border-radius: 10px; padding: 10px 12px; font-variant-numeric: tabular-nums; font-weight: 600; }
.nw-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; }

.history-row { display: flex; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--pale); font-variant-numeric: tabular-nums; }
.history-row:last-child { border-bottom: none; }

/* ---------- chart ---------- */

.chart-card svg { width: 100%; height: auto; display: block; }

/* ---------- nudge banner ---------- */

.nudge {
  background: var(--light);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 12px;
  font-size: 14.5px;
}
.nudge .btn { flex: none; }

/* ---------- celebration ---------- */

#celebrate {
  position: fixed; inset: 0; z-index: 60;
  display: flex; align-items: center; justify-content: center;
  background: rgba(3, 45, 39, 0.55);
  padding: 24px;
}
.celebrate-card {
  background: var(--paper);
  border-radius: 28px;
  padding: 36px 28px 28px;
  max-width: 380px;
  width: 100%;
  text-align: center;
  animation: pop 0.35s cubic-bezier(0.2, 1.6, 0.45, 1);
}
@keyframes pop { from { transform: scale(0.7); opacity: 0; } to { transform: none; opacity: 1; } }

.celebrate-badge {
  width: 84px; height: 84px;
  margin: 0 auto 18px;
  border-radius: 999px;
  background: var(--gold);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-head); font-size: 38px; font-weight: 700; color: var(--forest);
}
.celebrate-card h2 { font-family: var(--font-head); font-size: 26px; margin-bottom: 8px; }
.celebrate-card p { margin-bottom: 22px; color: rgba(3,45,39,0.7); }

#confetti { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
.confetti-bit {
  position: absolute;
  top: -12px;
  width: 10px; height: 14px;
  border-radius: 2px;
  animation: fall linear forwards;
}
@keyframes fall {
  to { transform: translateY(110vh) rotate(720deg); opacity: 0.9; }
}
@media (prefers-reduced-motion: reduce) {
  .confetti-bit { display: none; }
  .celebrate-card { animation: none; }
  #add-sheet { animation: none; }
}

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

#toast {
  position: fixed;
  bottom: calc(var(--tabbar-h) + 18px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--forest);
  color: var(--paper);
  border-radius: 999px;
  padding: 12px 22px;
  font-size: 14px;
  font-weight: 600;
  z-index: 55;
  white-space: nowrap;
  animation: pop 0.25s ease;
}

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

.setting-row { display: flex; justify-content: space-between; align-items: center; gap: 14px; padding: 14px 0; border-bottom: 1px solid var(--pale); }
.setting-row:last-child { border-bottom: none; }
.setting-name { font-weight: 700; }
.setting-desc { font-size: 13px; color: rgba(3,45,39,0.55); }

.switch { position: relative; width: 52px; height: 30px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; cursor: pointer; z-index: 2; margin: 0; }
.switch .knob {
  position: absolute; inset: 0;
  background: rgba(3,45,39,0.18);
  border-radius: 999px;
  transition: background 0.15s ease;
}
.switch .knob::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--paper);
  transition: transform 0.15s ease;
  box-shadow: 0 1px 4px rgba(3,45,39,0.3);
}
.switch input:checked + .knob { background: var(--emerald); }
.switch input:checked + .knob::after { transform: translateX(22px); }
.switch input:focus-visible + .knob { outline: 3px solid var(--emerald); outline-offset: 2px; }

.gear-btn { min-width: 44px; min-height: 44px; display: flex; align-items: center; justify-content: center; color: var(--emerald); }
.gear-btn svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; }

/* ---------- month nav ---------- */

.month-nav { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 14px; }
.month-nav .month-label { font-family: var(--font-sub); font-stretch: 112%; font-weight: 700; font-size: 15px; }
.month-nav button { min-width: 44px; min-height: 44px; color: var(--emerald); font-size: 22px; font-weight: 700; border-radius: 12px; }
.month-nav button:disabled { color: rgba(3,45,39,0.2); }

/* ---------- misc ---------- */

.divider { height: 1px; background: var(--pale); margin: 16px 0; }
.center { text-align: center; }
.mt8 { margin-top: 8px; } .mt16 { margin-top: 16px; } .mt24 { margin-top: 24px; }

.empty-state { text-align: center; padding: 28px 12px; color: rgba(3,45,39,0.55); font-size: 15px; }
.empty-state .big { font-family: var(--font-head); font-size: 20px; color: var(--forest); margin-bottom: 6px; }

@media (min-width: 700px) {
  h1.screen-title { font-size: 36px; }
  .hero-number { font-size: 76px; }
}
