:root {
  --bg: #0f0e0c;
  --bg2: #17150f;
  --card: rgba(255, 248, 230, 0.045);
  --card-border: rgba(255, 236, 190, 0.09);
  --text: #f4ecdc;
  --muted: #a99f8b;
  --gold: #e3bd6a;
  --gold-2: #c8963e;
  --gold-soft: rgba(227, 189, 106, 0.14);
  --good: #8fd6a4;
  --bad: #f09a8a;
  --radius: 20px;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 15% -10%, rgba(227, 189, 106, 0.10), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(120, 140, 200, 0.06), transparent 60%),
    linear-gradient(var(--bg), var(--bg2));
  background-attachment: fixed;
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.wrap { max-width: 760px; margin: 0 auto; padding: 24px 16px 64px; }

.top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--serif); font-size: 22px; letter-spacing: .02em; }
.today { color: var(--muted); font-size: 14px; }

h1, h2, h3 { font-family: var(--serif); font-weight: 600; margin: 0; }
h2 { font-size: 22px; }
h3 { font-size: 21px; margin-bottom: 12px; }

.muted { color: var(--muted); margin: 6px 0 14px; font-size: 15px; }

/* ---------- hero ---------- */
.hero {
  position: relative;
  border-radius: 28px;
  overflow: hidden;
  border: 1px solid var(--card-border);
  background: linear-gradient(160deg, #221d13, #14120e 70%);
  box-shadow: 0 30px 80px -30px rgba(0, 0, 0, .8), inset 0 1px 0 rgba(255, 240, 200, .06);
  margin-bottom: 20px;
}
.hero-bg {
  position: absolute; inset: 0;
  background-size: cover; background-position: center;
  opacity: 0; transition: opacity .6s ease;
}
.hero-bg.on { opacity: 1; }
.hero-bg::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(180deg, rgba(12, 11, 9, .35) 0%, rgba(12, 11, 9, .82) 55%, rgba(12, 11, 9, .96) 100%);
}
.hero-inner { position: relative; padding: 36px 28px 30px; }
.reached {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  margin-bottom: 22px; padding: 12px 14px 12px 16px; border-radius: 16px;
  background: var(--gold-soft); border: 1px solid rgba(227, 189, 106, .45);
  box-shadow: 0 0 30px rgba(227, 189, 106, .15);
}
.reached[hidden] { display: none; }
.reached strong { color: var(--gold); }
.eyebrow { text-transform: uppercase; letter-spacing: .16em; font-size: 12px; color: var(--gold); }
.goal-name { font-size: clamp(26px, 5vw, 36px); margin-top: 6px; line-height: 1.15; overflow-wrap: anywhere; }
.goal-name:empty { display: none; }

.counter {
  font-family: var(--serif);
  font-variant-numeric: tabular-nums lining-nums;
  font-size: clamp(54px, 13vw, 92px);
  line-height: 1;
  margin: 22px 0 10px;
  letter-spacing: -.01em;
  background: linear-gradient(180deg, #fff3d4 10%, var(--gold) 60%, var(--gold-2));
  -webkit-background-clip: text; background-clip: text; color: transparent;
  white-space: nowrap;
}
.counter .cur { font-size: .5em; margin-right: .12em; vertical-align: .55em; }
.counter .cents { font-size: .55em; }
.counter.bump #cents { animation: bump .5s ease; display: inline-block; }
@keyframes bump { 0% { transform: translateY(-.15em); opacity: .4; } 100% { transform: none; opacity: 1; } }

.tick { height: 8px; width: 100%; background: rgba(255, 255, 255, .07); border-radius: 8px; overflow: hidden; margin-bottom: 22px; }
.tick-fill { height: 100%; width: 0; background: var(--gold); opacity: .7; }

.progress { height: 12px; border-radius: 12px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.progress-fill {
  height: 100%; width: 0; border-radius: 12px;
  background: linear-gradient(90deg, var(--gold-2), var(--gold), #fbe3a6);
  box-shadow: 0 0 18px rgba(227, 189, 106, .45);
  transition: width .8s ease;
}
.shop-link { color: var(--gold); text-decoration: none; font-size: 14px; }
.shop-link:hover { text-decoration: underline; }
.goal-name + .shop-link { display: inline-block; margin-top: 6px; }
.shop-link[hidden] { display: none; }

.progress-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 14px; margin-top: 8px; font-variant-numeric: tabular-nums; }
.eta { margin: 16px 0 0; font-size: 17px; white-space: nowrap; overflow: hidden; }
.eta strong { color: var(--gold); font-weight: 600; }
.hero-actions { display: flex; gap: 10px; margin-top: 18px; flex-wrap: wrap; }
.hero-actions:empty { display: none; }
.hero.ready { border-color: rgba(227, 189, 106, .45); box-shadow: 0 0 0 1px rgba(227, 189, 106, .2), 0 30px 90px -30px rgba(227, 189, 106, .35); }

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 22px 22px;
  margin-bottom: 16px;
  backdrop-filter: blur(8px);
}
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row.end { justify-content: flex-end; margin-top: 14px; }
.grow { flex: 1 1 120px; }
.grow2 { flex: 2 1 200px; }

.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.field.file { margin-top: 12px; }
input {
  font: inherit; color: var(--text);
  background: rgba(0, 0, 0, .28);
  border: 1px solid rgba(255, 236, 190, .14);
  border-radius: 12px;
  padding: 11px 13px;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
  width: 100%;
}
input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); }
input[type=file] { padding: 8px; font-size: 14px; color: var(--muted); }
input[type=file]::file-selector-button {
  font: inherit; color: var(--text); background: rgba(255, 255, 255, .08);
  border: 0; border-radius: 8px; padding: 6px 12px; margin-right: 10px; cursor: pointer;
}

.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 999px; padding: 11px 20px;
  border: 1px solid rgba(255, 236, 190, .18);
  background: rgba(255, 255, 255, .06); color: var(--text);
  transition: transform .12s, background .2s, border-color .2s;
}
.btn:hover { background: rgba(255, 255, 255, .1); }
.btn:active { transform: scale(.97); }
.btn.small { padding: 8px 15px; font-size: 14px; }
.btn.gold { background: linear-gradient(180deg, #f1cf7f, var(--gold-2)); color: #1d170c; border-color: transparent; }
.btn.gold:hover { filter: brightness(1.06); }
.btn.ghost { background: transparent; border-color: var(--gold); color: var(--gold); }
.btn.subtle { background: transparent; }
.btn.danger { color: var(--bad); border-color: rgba(240, 154, 138, .4); background: transparent; }
.icon-btn {
  font: inherit; cursor: pointer; width: 34px; height: 34px; border-radius: 10px;
  border: 1px solid rgba(255, 236, 190, .1); background: rgba(255, 255, 255, .04); color: var(--muted);
  display: inline-grid; place-items: center; font-size: 15px;
}
.icon-btn:hover { color: var(--text); background: rgba(255, 255, 255, .09); }
.icon-btn:disabled { opacity: .3; cursor: default; }


/* ---------- wishes ---------- */
.add-form { margin: 16px 0 6px; padding: 16px; border-radius: 14px; background: rgba(0, 0, 0, .2); }
.wishes { list-style: none; padding: 0; margin: 14px 0 0; display: grid; gap: 10px; }
.wish {
  display: grid; grid-template-columns: 58px 1fr auto; gap: 14px; align-items: center;
  padding: 10px; border-radius: 16px; background: rgba(255, 255, 255, .03);
  border: 1px solid transparent;
}
.wish.active { border-color: rgba(227, 189, 106, .35); background: var(--gold-soft); }
.thumb {
  width: 58px; height: 58px; border-radius: 12px; object-fit: cover;
  background: linear-gradient(135deg, #2b2416, #1a1611); display: grid; place-items: center;
  font-family: var(--serif); color: var(--gold); font-size: 24px;
}
.wish-name { font-weight: 600; overflow-wrap: anywhere; }
.wish-meta { color: var(--muted); font-size: 14px; }
.badge { display: inline-block; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: #1d170c; background: var(--gold); border-radius: 999px; padding: 1px 8px; margin-left: 6px; vertical-align: 2px; }
.wish-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; max-width: 210px; }
.empty { margin-top: 14px; }


/* ---------- folds ---------- */
.fold summary { cursor: pointer; font-family: var(--serif); font-size: 20px; list-style: none; display: flex; justify-content: space-between; }
.fold summary::-webkit-details-marker { display: none; }
.fold summary::after { content: "+"; color: var(--muted); }
.fold[open] summary::after { content: "–"; }
.fold[open] summary { margin-bottom: 14px; }
.fold form + .muted { margin-top: 8px; }
.fold form { margin-bottom: 8px; }

/* ---------- savings slider ---------- */
.keep { margin-top: 18px; padding: 18px; border-radius: 16px; background: rgba(0, 0, 0, .2); border: 1px solid rgba(255, 236, 190, .06); }
.keep-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; color: var(--muted); font-size: 14px; }
.keep-amount { font-family: var(--serif); font-size: 30px; font-weight: 600; color: var(--gold); white-space: nowrap; cursor: text; }
.keep-amount input {
  font: inherit; color: inherit; font-variant-numeric: tabular-nums; text-align: right;
  width: 6ch; padding: 0 4px; background: transparent;
  border: 1px solid transparent; border-radius: 8px; box-shadow: none;
}
.keep-amount input:hover { border-color: rgba(255, 236, 190, .18); }
.keep-amount input:focus { border-color: var(--gold); box-shadow: 0 0 0 3px var(--gold-soft); background: rgba(0, 0, 0, .28); }
.keep-scale { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; margin-top: 4px; }
.keep-split { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 16px; }
.keep-split > div { display: flex; flex-direction: column; gap: 2px; padding: 12px 14px; border-radius: 12px; background: rgba(255, 255, 255, .03); }
.keep-split strong { font-size: 17px; font-variant-numeric: tabular-nums; }
.muted-label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.muted-small { color: var(--muted); font-size: 13px; }

input[type=range] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 28px; margin: 12px 0 0; padding: 0;
  background: transparent; border: 0; box-shadow: none; cursor: pointer;
  --fill: 0%;
}
input[type=range]:focus { box-shadow: none; }
input[type=range]::-webkit-slider-runnable-track {
  height: 10px; border-radius: 10px;
  background: linear-gradient(90deg, var(--gold-2), var(--gold) var(--fill), rgba(255, 255, 255, .08) var(--fill));
}
input[type=range]::-moz-range-track { height: 10px; border-radius: 10px; background: rgba(255, 255, 255, .08); }
input[type=range]::-moz-range-progress { height: 10px; border-radius: 10px; background: linear-gradient(90deg, var(--gold-2), var(--gold)); }
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 26px; height: 26px; margin-top: -8px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3d4, var(--gold) 55%, var(--gold-2));
  border: 2px solid #1b1812; box-shadow: 0 0 0 1px rgba(227, 189, 106, .5), 0 4px 14px rgba(0, 0, 0, .5);
  transition: transform .12s;
}
input[type=range]::-moz-range-thumb {
  width: 22px; height: 22px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff3d4, var(--gold) 55%, var(--gold-2));
  border: 2px solid #1b1812; box-shadow: 0 0 0 1px rgba(227, 189, 106, .5), 0 4px 14px rgba(0, 0, 0, .5);
}
input[type=range]:active::-webkit-slider-thumb { transform: scale(1.12); }
input[type=range]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--gold-soft), 0 4px 14px rgba(0, 0, 0, .5); }

.history { list-style: none; padding: 0; margin: 0; display: grid; gap: 6px; font-size: 14px; }
.history li { display: grid; grid-template-columns: 110px 1fr auto; gap: 10px; color: var(--muted); }
.history .h-text { color: var(--text); overflow-wrap: anywhere; }
.history .neg { color: var(--bad); }
.history .pos { color: var(--good); }

.foot { text-align: center; color: var(--muted); font-size: 13px; margin-top: 26px; }

/* ---------- dialog / toast ---------- */
dialog {
  border: 1px solid var(--card-border); border-radius: 22px; padding: 24px;
  background: #1b1812; color: var(--text); width: min(440px, calc(100vw - 32px));
  box-shadow: 0 40px 100px rgba(0, 0, 0, .7);
}
dialog::backdrop { background: rgba(5, 4, 3, .65); backdrop-filter: blur(3px); }
dialog .field { margin-top: 10px; }
dialog p { margin: 0 0 6px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #2a2418; border: 1px solid rgba(227, 189, 106, .35); color: var(--text);
  padding: 12px 18px; border-radius: 14px; box-shadow: 0 20px 50px rgba(0, 0, 0, .6);
  max-width: calc(100vw - 32px); z-index: 10;
}
.toast.err { border-color: rgba(240, 154, 138, .5); }

/* ---------- login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; }
.login { width: min(380px, 100%); display: grid; gap: 16px; justify-items: center; padding: 34px 26px; }
.login h1 { font-size: 30px; }
.login .field { width: 100%; }
.login .btn { width: 100%; }
.login-error { color: var(--bad); margin: 0; font-size: 15px; text-align: center; }
.logout { background: none; border: 0; color: var(--muted); font: inherit; font-size: 13px; cursor: pointer; text-decoration: underline; padding: 0; }
.logout:hover { color: var(--text); }

@media (max-width: 520px) {
  .hero-inner { padding: 28px 20px 24px; }
  .card { padding: 18px 16px; }
  .wish { grid-template-columns: 48px 1fr; }
  .thumb { width: 48px; height: 48px; }
  .wish-actions { grid-column: 1 / -1; max-width: none; justify-content: flex-start; }
  .history li { grid-template-columns: 1fr auto; }
  .history .h-date { grid-column: 1 / -1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

.reset-row { margin-top: 22px; padding-top: 16px; border-top: 1px solid rgba(255, 236, 190, .07); }
