:root {
  --bg: #fff6e0;
  --surface: #ffffff;
  --ink: #141414;
  --muted: #5c5650;
  --line: #141414;
  --accent: #ffd400;
  --accent-ink: #141414;
  --no: #ff3d2e;
  --no-soft: #ffe1dc;
  --yes: #16b26a;
  --yes-soft: #d9f7e7;
  --track: #f1e8d2;
  --shadow: 5px 5px 0 var(--line);
  --radius: 14px;
  --display: "Archivo Black", "Arial Black", Impact, sans-serif;
  --body: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #151412;
    --surface: #211f1c;
    --ink: #f6f1e7;
    --muted: #b3aa9c;
    --line: #f6f1e7;
    --track: #34302a;
    --no-soft: #4a1f1a;
    --yes-soft: #163b2a;
    --shadow: 5px 5px 0 #000;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--body);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100vh;
}

h1, h2 { font-family: var(--display); font-weight: 400; margin: 0; letter-spacing: -0.01em; }
h1 { font-size: clamp(2rem, 6vw, 3.2rem); line-height: 1.02; }
h2 { font-size: 1.25rem; margin-bottom: 14px; }
small { color: var(--muted); font-weight: 400; }

.hidden { display: none !important; }

/* ---------- Top bar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px;
  max-width: 1100px; margin: 0 auto;
}
.brand { display: flex; align-items: center; gap: 10px; }
.brand-mark {
  display: grid; place-items: center;
  width: 36px; height: 36px;
  background: var(--accent); color: var(--accent-ink);
  border: 3px solid var(--line); border-radius: 10px;
  font-family: var(--display); font-size: 1.2rem;
  transform: rotate(-8deg);
}
.brand-name { font-family: var(--display); font-size: 1.15rem; }

main { max-width: 1100px; margin: 0 auto; padding: 8px 16px 64px; }

.view { animation: rise .35s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

#view-profile, #view-budget { max-width: 640px; margin: 0 auto; }

.step-tag {
  display: inline-block; margin: 12px 0 10px;
  font-weight: 700; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em;
  background: var(--ink); color: var(--bg); padding: 4px 10px; border-radius: 999px;
}
.lede { color: var(--muted); font-size: 1.1rem; margin: 10px 0 22px; }

/* ---------- Cards & forms ---------- */
.card {
  background: var(--surface);
  border: 3px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.form { display: flex; flex-direction: column; gap: 16px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.row-3 { grid-template-columns: 2fr 1fr 1.3fr; }

.field { display: flex; flex-direction: column; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 700; font-size: .95rem; padding: 0; margin-bottom: 6px; }
fieldset.field > legend { margin-bottom: 8px; }

input[type="text"], input[type="number"], select {
  width: 100%;
  font: inherit; color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  min-height: 46px;
}
input:focus-visible, select:focus-visible, .btn:focus-visible, .chips label:focus-within, .segmented label:focus-within {
  outline: 3px solid var(--accent); outline-offset: 2px;
}

.money-input { position: relative; }
.money-input > span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); font-weight: 700; color: var(--muted); }
.money-input input { padding-left: 26px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label {
  cursor: pointer; user-select: none;
  border: 2px solid var(--line); border-radius: 999px;
  padding: 7px 12px; font-weight: 500; font-size: .92rem;
  transition: background .15s, transform .1s;
}
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips label:has(input:checked) { background: var(--accent); color: var(--accent-ink); }
.chips label:active { transform: scale(.97); }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented label { cursor: pointer; }
.segmented span {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  border: 2px solid var(--line); border-radius: 10px; padding: 10px 6px;
  font-weight: 700;
}
.segmented label:has(input:checked) span { background: var(--ink); color: var(--bg); }
.segmented label:has(input:checked) small { color: inherit; opacity: .75; }
.segmented .no-mercy:has(input:checked) span { background: var(--no); border-color: var(--line); color: #fff; }
.segmented label:has(input:disabled) { cursor: not-allowed; opacity: .4; }

.form-error { color: var(--no); font-weight: 700; margin: 0; }
.hint { margin: 0; padding: 10px 12px; border-radius: 10px; background: var(--track); font-size: .92rem; }

.actions { display: flex; justify-content: space-between; gap: 12px; }

/* ---------- Buttons ---------- */
.btn {
  font: inherit; font-weight: 700;
  cursor: pointer;
  color: var(--ink); background: var(--surface);
  border: 2px solid var(--line); border-radius: 10px;
  padding: 10px 16px; min-height: 44px;
  box-shadow: 3px 3px 0 var(--line);
  transition: transform .08s, box-shadow .08s;
}
.btn:hover { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--line); }
.btn:active { transform: translate(3px, 3px); box-shadow: 0 0 0 var(--line); }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-danger { background: var(--no); color: #fff; }
.btn-ghost { box-shadow: none; background: transparent; }
.btn-ghost:hover { box-shadow: none; transform: none; background: var(--track); }
.btn-big { font-family: var(--display); font-weight: 400; font-size: 1.25rem; padding: 14px; letter-spacing: .02em; }
.btn-small { padding: 6px 12px; min-height: 36px; font-size: .9rem; }

/* ---------- Dashboard ---------- */
.greeting { font-size: clamp(1.6rem, 4.5vw, 2.4rem); margin: 8px 0 20px; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  align-items: start;
}
.check-card { grid-row: span 2; }
.history-card { grid-column: 1 / -1; }

.card-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-head h2 { margin: 0; }

/* Meter */
.meter-track {
  height: 26px; border: 2px solid var(--line); border-radius: 999px;
  background: var(--track); overflow: hidden;
}
.meter-fill {
  height: 100%; width: 0;
  background: var(--yes);
  border-right: 2px solid var(--line);
  transition: width .6s cubic-bezier(.2,.8,.2,1), background .3s;
}
.meter-fill[data-level="warn"] { background: var(--accent); }
.meter-fill[data-level="over"] { background: var(--no); }
.meter-fill[data-empty] { border-right: 0; }
.meter-labels { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; font-size: .95rem; }
.meter-spent { font-weight: 700; }
.meter-left { color: var(--muted); text-align: right; }
.meter-left.over { color: var(--no); font-weight: 700; }

/* Week chart */
.days {
  position: relative;
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px;
  height: 150px; margin-top: 22px; padding-top: 6px;
  border-bottom: 2px solid var(--line);
}
.day { display: flex; flex-direction: column; justify-content: flex-end; align-items: center; height: 100%; position: relative; }
.day-bar {
  width: 100%; max-width: 34px; min-height: 2px;
  background: var(--ink); border-radius: 6px 6px 0 0;
  transition: height .5s cubic-bezier(.2,.8,.2,1);
}
.day-bar.over { background: var(--no); }
.day.today .day-bar { background: var(--accent); border: 2px solid var(--line); border-bottom: 0; }
.day.today .day-bar.over { background: var(--no); }
.day-amt { font-size: .72rem; font-weight: 700; margin-bottom: 4px; white-space: nowrap; }
.day-labels { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; text-align: center; font-size: .8rem; color: var(--muted); margin-top: 6px; }
.day-labels .today { color: var(--ink); font-weight: 700; }
.pace-line {
  position: absolute; left: 0; right: 0; height: 0;
  border-top: 2px dashed var(--muted);
  pointer-events: none;
}
.chart-note { display: flex; align-items: center; gap: 8px; font-size: .82rem; color: var(--muted); margin: 10px 0 0; }
.pace-swatch { width: 22px; border-top: 2px dashed var(--muted); }

/* Stats */
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 20px; }
.stat { border: 2px solid var(--line); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; }
.stat-value { font-family: var(--display); font-size: 1.4rem; line-height: 1.1; font-variant-numeric: tabular-nums; }
.stat-label { font-size: .82rem; color: var(--muted); }

/* Verdict */
.verdict {
  margin-top: 20px;
  border: 3px solid var(--line); border-radius: var(--radius);
  padding: 18px;
  animation: slam .35s cubic-bezier(.2,1.6,.4,1);
}
@keyframes slam { from { transform: scale(.85) rotate(-2deg); opacity: 0; } to { transform: none; opacity: 1; } }
.verdict.no { background: var(--no-soft); }
.verdict.yes { background: var(--yes-soft); }
.verdict-headline { font-family: var(--display); font-size: clamp(2.2rem, 7vw, 3.4rem); line-height: 1; margin: 0 0 10px; }
.verdict.no .verdict-headline { color: var(--no); }
.verdict.yes .verdict-headline { color: var(--yes); }
.verdict.no.shake { animation: slam .35s cubic-bezier(.2,1.6,.4,1), shake .4s .35s; }
@keyframes shake { 0%,100% { transform: none; } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.verdict-roast { font-size: 1.2rem; font-weight: 700; margin: 0 0 12px; }
.verdict-roast.caps { text-transform: uppercase; font-family: var(--display); font-weight: 400; letter-spacing: .01em; }
.verdict-facts { margin: 0 0 14px; padding-left: 18px; color: var(--muted); font-size: .95rem; }
.verdict-actions { display: flex; flex-wrap: wrap; gap: 10px; }

/* History */
.log-form { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 2px dashed var(--line); }
.history { list-style: none; margin: 0; padding: 0; }
.history li {
  display: grid; grid-template-columns: auto 1fr auto auto; align-items: center; gap: 12px;
  padding: 10px 0; border-bottom: 1px solid var(--track);
}
.history li:last-child { border-bottom: 0; }
.h-emoji { font-size: 1.3rem; }
.h-main { min-width: 0; }
.h-item { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-meta { font-size: .82rem; color: var(--muted); }
.h-tag { display: inline-block; margin-left: 6px; padding: 0 6px; border-radius: 4px; background: var(--no); color: #fff; font-size: .72rem; font-weight: 700; vertical-align: 1px; }
.h-cost { font-weight: 700; font-variant-numeric: tabular-nums; }
.h-del { background: none; border: 0; color: var(--muted); cursor: pointer; font-size: 1.1rem; padding: 6px 8px; border-radius: 8px; }
.h-del:hover { color: var(--no); background: var(--track); }
.empty { color: var(--muted); margin: 0; }

/* Dialog */
.dialog { width: min(92vw, 380px); color: var(--ink); }
.dialog::backdrop { background: rgba(0,0,0,.45); }
.dialog-actions { display: flex; flex-direction: column; gap: 10px; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .check-card { grid-row: auto; }
}
@media (max-width: 520px) {
  .row, .row-3 { grid-template-columns: 1fr; }
  .segmented { grid-template-columns: repeat(2, 1fr); }
  .card { padding: 16px; }
  .days { gap: 4px; }
  .day-labels { gap: 4px; }
  .day-amt { font-size: .62rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
