/* ============================================================
   Cycling Savings — styles.css
   Mobile-first personal tool. Light + dark themes.
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Bricolage+Grotesque:opsz,wght@12..96,500;12..96,600;12..96,700;12..96,800&family=Space+Grotesk:wght@400;500;600;700&display=swap');

/* ---------- Theme tokens ---------- */
:root {
  --font-display: 'Bricolage Grotesque', system-ui, sans-serif;
  --font-ui: 'Space Grotesk', system-ui, sans-serif;

  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 26px;
  --r-xl: 34px;

  --ease: cubic-bezier(.2, .8, .2, 1);
  --ease-back: cubic-bezier(.34, 1.56, .64, 1);
}

/* DARK (default) */
:root,
[data-theme="dark"] {
  --bg: #0a130f;
  --bg-glow: #0f5c40;
  --surface: #111d17;
  --surface-2: #16271f;
  --surface-press: #1c3328;
  --border: rgba(255, 255, 255, .07);
  --border-strong: rgba(255, 255, 255, .12);
  --text: #eaf3ee;
  --muted: #87a195;
  --faint: #5d756a;
  --accent: #34d399;
  --accent-2: #10b981;
  --accent-ink: #04241b;
  --accent-soft: rgba(52, 211, 153, .14);
  --danger: #f87171;
  --danger-soft: rgba(248, 113, 113, .12);
  --shadow-app: 0 40px 90px -30px rgba(0, 0, 0, .8);
  --shadow-btn: 0 14px 30px -12px rgba(16, 185, 129, .55);
  --hero-glow: 0 0 60px rgba(52, 211, 153, .35);
  color-scheme: dark;
}

/* LIGHT */
[data-theme="light"] {
  --bg: #e8efe9;
  --bg-glow: #b6e7d2;
  --surface: #ffffff;
  --surface-2: #f3f8f5;
  --surface-press: #e7f1ec;
  --border: rgba(10, 40, 28, .08);
  --border-strong: rgba(10, 40, 28, .14);
  --text: #0e1c15;
  --muted: #5a7065;
  --faint: #8aa093;
  --accent: #0fa978;
  --accent-2: #0c8d63;
  --accent-ink: #ffffff;
  --accent-soft: rgba(15, 169, 120, .12);
  --danger: #dc2626;
  --danger-soft: rgba(220, 38, 38, .08);
  --shadow-app: 0 40px 90px -40px rgba(13, 60, 42, .35);
  --shadow-btn: 0 16px 30px -12px rgba(12, 141, 99, .45);
  --hero-glow: 0 0 0 rgba(0, 0, 0, 0);
  color-scheme: light;
}

/* ---------- Reset ---------- */
* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: var(--font-ui);
  color: var(--text);
  background:
    radial-gradient(120% 80% at 50% -10%, color-mix(in oklab, var(--bg-glow) 26%, var(--bg)) 0%, var(--bg) 55%),
    var(--bg);
  background-attachment: fixed;
  display: grid;
  place-items: center;
  min-height: 100svh;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  transition: background .5s var(--ease), color .5s var(--ease);
  overflow-x: hidden;
}

button { font: inherit; color: inherit; cursor: pointer; border: none; background: none; }
a { color: inherit; }

/* ---------- Phone shell ---------- */
.phone {
  position: relative;
  width: 100%;
  max-width: 440px;
  min-height: 100svh;
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  isolation: isolate;
}

@media (min-width: 540px) {
  body { padding: 32px; }
  .phone {
    min-height: 0;
    height: min(900px, calc(100svh - 64px));
    border-radius: 44px;
    border: 1px solid var(--border-strong);
    box-shadow: var(--shadow-app);
  }
}

/* ---------- Screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 0;
  opacity: 0;
  visibility: hidden;
  transform: translateY(8px);
  transition: opacity .4s var(--ease), transform .4s var(--ease), visibility .4s;
  pointer-events: none;
}
.screen.is-active {
  opacity: 1;
  visibility: visible;
  transform: none;
  pointer-events: auto;
}

/* ---------- Top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 24px 6px;
  flex: none;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
}
.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  display: grid; place-items: center;
  box-shadow: var(--shadow-btn);
  flex: none;
}
.brand-mark::after {
  content: "";
  width: 13px; height: 13px;
  border-radius: 50%;
  border: 2.5px solid var(--accent-ink);
}
.brand-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.02em;
}

/* theme toggle */
.theme-toggle {
  width: 38px; height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-2);
  display: grid; place-items: center;
  color: var(--muted);
  transition: transform .3s var(--ease-back), color .2s, background .2s;
}
.theme-toggle:active { transform: scale(.9); }
.theme-toggle svg { width: 18px; height: 18px; display: block; }
.theme-toggle .i-moon { display: none; }
[data-theme="light"] .theme-toggle .i-moon { display: block; }
[data-theme="light"] .theme-toggle .i-sun { display: none; }

/* ============================================================
   LOGIN
   ============================================================ */
#login { padding: 0; }
.login-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 24px 28px 40px;
  gap: 26px;
}
.login-hero { text-align: left; }
.login-kicker {
  font-size: 12.5px;
  letter-spacing: .16em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 14px;
}
.login-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 38px;
  line-height: 1.02;
  letter-spacing: -.035em;
}
.login-sub {
  margin-top: 14px;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.5;
  max-width: 30ch;
}

.form { display: flex; flex-direction: column; gap: 14px; }
.field { position: relative; display: flex; flex-direction: column; gap: 7px; }
.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .01em;
  padding-left: 2px;
}
.field input {
  width: 100%;
  padding: 15px 16px;
  font-size: 16px;
  font-family: var(--font-ui);
  color: var(--text);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  transition: border-color .2s, background .2s, box-shadow .2s;
}
.field input::placeholder { color: var(--faint); }
.field input:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.error {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 20px;
  font-size: 13.5px;
  color: var(--danger);
  padding: 0 2px;
  opacity: 0;
  transform: translateY(-3px);
  transition: opacity .25s, transform .25s;
}
.error.show { opacity: 1; transform: none; }
.error::before {
  content: "!";
  flex: none;
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--danger);
  color: #fff;
  font-size: 12px; font-weight: 700;
  display: grid; place-items: center;
}
.error:not(.show)::before { display: none; }

.btn-primary {
  margin-top: 4px;
  width: 100%;
  padding: 17px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -.01em;
  color: var(--accent-ink);
  background: linear-gradient(140deg, var(--accent), var(--accent-2));
  border-radius: var(--r-md);
  box-shadow: var(--shadow-btn);
  transition: transform .15s var(--ease-back), box-shadow .2s, filter .2s;
}
.btn-primary:hover { filter: brightness(1.04); }
.btn-primary:active { transform: scale(.975); }

.login-foot {
  text-align: center;
  font-size: 12.5px;
  color: var(--faint);
  margin-top: 2px;
}
.login-foot b { color: var(--muted); font-weight: 600; }

/* ============================================================
   MAIN APP
   ============================================================ */
.app-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.app-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  padding: 8px 22px 14px;
  overflow-y: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.app-scroll::-webkit-scrollbar { display: none; }
.app-footer {
  flex: none;
  padding: 0 22px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -14px 26px -18px rgba(0, 0, 0, .45);
}

/* hero */
.hero {
  text-align: center;
  padding: 26px 8px 22px;
}
.hero-label {
  font-size: 13px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: .01em;
}
.hero-amount {
  font-family: var(--font-display);
  font-weight: 800;
  letter-spacing: -.045em;
  line-height: .95;
  font-size: clamp(64px, 24vw, 88px);
  margin: 8px 0 6px;
  color: var(--accent);
  text-shadow: var(--hero-glow);
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: flex-start;
}
.hero-amount .cur {
  font-size: .46em;
  font-weight: 700;
  margin-top: .18em;
  margin-right: .04em;
  color: var(--accent);
  opacity: .9;
}
.hero-amount.pop { animation: heroPop .55s var(--ease-back); }
@keyframes heroPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.07); }
  100% { transform: scale(1); }
}
.hero-meta {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  flex-wrap: wrap;
  justify-content: center;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px 6px 10px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.chip .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--muted);
}

/* ---------- goal card ---------- */
.goal {
  display: block;
  width: 100%;
  text-align: left;
  margin-top: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 16px 18px;
  position: relative;
  -webkit-tap-highlight-color: transparent;
  transition: transform .14s var(--ease-back), border-color .2s, background .2s;
}
.goal:active { transform: scale(.985); background: var(--surface-press); }

/* empty state */
.goal.empty {
  display: flex;
  align-items: center;
  gap: 13px;
  border-style: dashed;
  border-color: var(--border-strong);
}
.goal .add-ico {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
}
.goal .add-ico svg { width: 22px; height: 22px; }
.goal .add-text .t { font-weight: 700; font-size: 15px; font-family: var(--font-display); letter-spacing: -.01em; }
.goal .add-text .s { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.goal.empty .goal-filled { display: none; }
.goal:not(.empty) .goal-empty { display: none; }

/* filled state */
.goal-empty { display: flex; align-items: center; gap: 13px; }
.goal-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 11px;
}
.goal-for {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.goal-edit {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.goal-edit svg { width: 13px; height: 13px; }
.goal-name {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 22px;
  letter-spacing: -.03em;
  line-height: 1.05;
  margin-bottom: 13px;
}
.goal-bar {
  height: 12px;
  border-radius: 999px;
  background: var(--surface-press);
  overflow: hidden;
  position: relative;
}
.goal-bar > i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
  transition: width .7s var(--ease-back);
}
.goal-foot {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin-top: 11px;
}
.goal-prog {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -.01em;
  font-variant-numeric: tabular-nums;
}
.goal-prog b { color: var(--accent); }
.goal-left { font-size: 13px; font-weight: 600; color: var(--muted); font-variant-numeric: tabular-nums; }

/* reached */
.goal.reached {
  background: var(--accent-soft);
  border-color: color-mix(in oklab, var(--accent) 40%, transparent);
}
.goal.reached .goal-left { color: var(--accent); }
.goal.reached .goal-name::after {
  content: " 🎉";
}

/* ---------- goal stack ---------- */
.goal-stack {
  margin-top: 6px;
  display: flex;
  flex-direction: column;
}
.goal-stack .goal { margin-top: 0; }

.goal-expand-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 8px 0 2px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: none;
  border: none;
  cursor: pointer;
}
.goal-expand-btn:active { opacity: .7; }

.goal-others {
  display: none;
  flex-direction: column;
  gap: 6px;
  margin-top: 6px;
}
.goal-others.open { display: flex; }

.goal-add-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 6px;
  padding: 10px 14px;
  background: none;
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-md);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background .15s, border-color .15s;
}
.goal-add-btn:active { background: var(--accent-soft); }
.goal-add-btn svg { width: 16px; height: 16px; flex-shrink: 0; }

.goal-hist-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 12px 16px;
}
.goal-hist-name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 14px;
  letter-spacing: -.02em;
  margin-bottom: 8px;
}
.goal-hist-bar {
  height: 6px;
  border-radius: 999px;
  background: var(--surface-press);
  overflow: hidden;
  margin-bottom: 6px;
}
.goal-hist-bar i {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent));
}
.goal-hist-foot {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
}

/* ---------- bottom sheet ---------- */
.sheet-backdrop {
  position: absolute;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, .5);
  backdrop-filter: blur(2px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s var(--ease), visibility .3s;
  display: flex;
  align-items: flex-end;
}
.sheet-backdrop.show { opacity: 1; visibility: visible; }
.sheet {
  width: 100%;
  background: var(--surface);
  border-top-left-radius: var(--r-xl);
  border-top-right-radius: var(--r-xl);
  border-top: 1px solid var(--border-strong);
  padding: 10px 24px calc(26px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform .38s var(--ease-back);
  box-shadow: 0 -20px 50px -20px rgba(0, 0, 0, .5);
}
.sheet-backdrop.show .sheet { transform: none; }
.sheet-grip {
  width: 40px; height: 4px;
  border-radius: 999px;
  background: var(--border-strong);
  margin: 0 auto 18px;
}
.sheet h3 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 21px;
  letter-spacing: -.02em;
  margin-bottom: 4px;
}
.sheet .sheet-sub { font-size: 13.5px; color: var(--muted); margin-bottom: 20px; }
.sheet .field { margin-bottom: 16px; }
.sheet .field-amount input { padding-left: 30px; }
.sheet .field-amount { position: relative; }
.sheet .field-amount .pound {
  position: absolute;
  left: 16px; bottom: 15px;
  color: var(--muted);
  font-size: 16px;
  pointer-events: none;
}
.sheet-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 22px; }
.sheet .btn-primary { margin-top: 0; }
.btn-ghost {
  width: 100%;
  padding: 14px;
  font-weight: 600;
  font-size: 14.5px;
  color: var(--muted);
  border-radius: var(--r-md);
  transition: background .2s, color .2s;
}
.btn-ghost.danger { color: var(--danger); }
.btn-ghost.danger:hover { background: var(--danger-soft); }
.btn-ghost:hover { background: var(--surface-2); }

/* "what that's worth" card */
.worth {
  margin-top: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 14px 16px 6px;
}
.worth-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .01em;
  margin-bottom: 4px;
}
.worth-row {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 10px 0;
}
.worth-row + .worth-row { border-top: 1px solid var(--border); }
.worth-ico {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid; place-items: center;
}
.worth-ico svg { width: 22px; height: 22px; }
.worth-count {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 26px;
  letter-spacing: -.04em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  min-width: 1.4ch;
  text-align: right;
  transition: transform .3s var(--ease-back);
}
.worth-count.bump { transform: scale(1.18); color: var(--accent); }
.worth-text { display: flex; flex-direction: column; gap: 2px; }
.worth-text .what { font-weight: 600; font-size: 15px; letter-spacing: -.01em; }
.worth-text .price { font-size: 12px; color: var(--faint); font-weight: 500; }

/* action buttons */
.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 0 8px;
}
.action {
  position: relative;
  min-height: 122px;
  border-radius: var(--r-lg);
  padding: 18px 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  text-align: left;
  background: var(--surface-2);
  border: 1.5px solid var(--border-strong);
  overflow: hidden;
  transition: transform .14s var(--ease-back), background .2s, border-color .2s, box-shadow .2s;
  -webkit-tap-highlight-color: transparent;
}
.action:active { transform: scale(.965); background: var(--surface-press); }
.action .ico {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: var(--accent-soft);
  display: grid; place-items: center;
  color: var(--accent);
}
.action .ico svg { width: 22px; height: 22px; }
.action .label {
  display: block;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -.02em;
}
.action .when { display: block; font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.action .gain {
  position: absolute;
  top: 16px; right: 16px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 8px;
  border-radius: 999px;
  opacity: 0;
  transform: translateY(4px) scale(.9);
  transition: opacity .2s, transform .2s var(--ease-back);
}
.action.flash { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.action.flash .gain { opacity: 1; transform: none; }
.action.flash .ico { background: var(--accent); color: var(--accent-ink); }

/* primary action accent (cycled in is the morning default — slightly stronger) */
.action.primary {
  background: linear-gradient(150deg, color-mix(in oklab, var(--accent) 16%, var(--surface-2)), var(--surface-2));
}

/* sign out */
.signout-row {
  display: flex;
  justify-content: center;
  padding: 2px 0 calc(12px + env(safe-area-inset-bottom));
}
.signout {
  font-size: 13px;
  font-weight: 600;
  color: var(--faint);
  padding: 8px 16px;
  border-radius: 999px;
  letter-spacing: .01em;
  transition: color .2s, background .2s;
}
.signout:hover { color: var(--danger); background: var(--danger-soft); }

/* ---------- Toast ---------- */
.toast {
  position: absolute;
  left: 50%;
  bottom: 210px;
  transform: translate(-50%, 12px);
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  font-size: 14px;
  padding: 11px 18px;
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  white-space: nowrap;
  box-shadow: 0 16px 40px -12px rgba(0, 0, 0, .5);
  opacity: 0;
  pointer-events: none;
  z-index: 30;
  transition: opacity .3s var(--ease), transform .35s var(--ease-back);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .tick {
  width: 18px; height: 18px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: grid; place-items: center;
  font-size: 12px;
  flex: none;
}

/* ---------- Confetti ---------- */
.confetti {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 25;
}
.confetti i {
  position: absolute;
  width: 9px; height: 14px;
  border-radius: 2px;
  will-change: transform, opacity;
  animation: confettiFall var(--dur, 1s) var(--ease) forwards;
}
@keyframes confettiFall {
  0% { transform: translate(0, 0) rotate(0deg); opacity: 1; }
  100% { transform: translate(var(--dx), var(--dy)) rotate(var(--dr)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .08s !important; }
}
