/* Liat's Budget — warm paper in the calm state; the whole app turns
   orange, then deep red, when spending runs ahead of the month. */

/* ---------- tokens: calm, light ---------- */
:root {
  --serif: Georgia, 'Noto Serif', 'Times New Roman', serif;
  --sans: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --paper: #faf1e6;
  --card: #fffcf5;
  --line: #eadfc9;
  --ink: #2e2a22;
  --ink-2: #6e6354;
  --accent: #3e6b4d;
  --accent-deep: #2e5239;
  --accent-ink: #f4faf2;
  --accent-tint: #e4eee3;
  --meter-track: #ece1cb;
  --meter-fill: #3e6b4d;
  --danger: #a33325;
  --danger-ink: #fff3ec;
  --focus: #1e5aa8;
  --banner-bg: #2e2a22;
  --banner-ink: #faf1e6;
  --shadow: 0 1px 2px rgba(60, 48, 30, .06), 0 6px 18px rgba(60, 48, 30, .08);
  --radius: 18px;
}

/* ---------- tokens: calm, dark ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --paper: #201c15;
    --card: #2a251c;
    --line: #3b3426;
    --ink: #f2ead9;
    --ink-2: #b3a78c;
    --accent: #8cbb95;
    --accent-deep: #a7d1af;
    --accent-ink: #15241a;
    --accent-tint: #32402f;
    --meter-track: #3b3426;
    --meter-fill: #8cbb95;
    --danger: #e08571;
    --danger-ink: #2b0f08;
    --focus: #8ab8f2;
    --banner-bg: #f2ead9;
    --banner-ink: #201c15;
    --shadow: 0 1px 2px rgba(0, 0, 0, .25), 0 6px 18px rgba(0, 0, 0, .3);
  }
}

/* ---------- state: orange (same look in light and dark — orange means orange) ---------- */
body[data-state="orange"] {
  --paper: #e68a1c;
  --card: #f6d8a6;
  --line: rgba(51, 32, 10, .22);
  --ink: #33200a;
  --ink-2: #5c431f;
  --accent: #5b3a06;
  --accent-deep: #442b03;
  --accent-ink: #ffe9c8;
  --accent-tint: #efc27c;
  --meter-track: rgba(51, 32, 10, .18);
  --meter-fill: #7a4e05;
  --danger: #8e2b22;
  --danger-ink: #ffe9e0;
  --focus: #1d3f8f;
  --banner-bg: #442b03;
  --banner-ink: #ffe9c8;
  --shadow: 0 1px 2px rgba(68, 43, 3, .12), 0 6px 18px rgba(68, 43, 3, .14);
}

/* ---------- state: red ---------- */
body[data-state="red"] {
  --paper: #771310;
  --card: #8e2a20;
  --line: rgba(255, 233, 224, .26);
  --ink: #ffede4;
  --ink-2: #f0c7b8;
  --accent: #ffd9c8;
  --accent-deep: #ffc9b2;
  --accent-ink: #5c0f08;
  --accent-tint: #9c3a2e;
  --meter-track: rgba(255, 233, 224, .22);
  --meter-fill: #ffc4ab;
  --danger: #ffd9c8;
  --danger-ink: #5c0f08;
  --focus: #ffe9a8;
  --banner-bg: #3f0401;
  --banner-ink: #ffe3d6;
  --shadow: 0 1px 2px rgba(0, 0, 0, .2), 0 6px 18px rgba(0, 0, 0, .25);
}

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

[hidden] { display: none !important; }

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

body {
  font-family: var(--sans);
  font-size: 17px;
  line-height: 1.45;
  color: var(--ink);
  background-color: var(--paper);
  min-height: 100vh;
  transition: background-color .6s ease, color .6s ease;
  touch-action: manipulation;
}

body[data-state="red"] {
  animation: redpulse 4s ease-in-out infinite alternate;
}
@keyframes redpulse {
  from { background-color: #771310; }
  to   { background-color: #5c0a07; }
}
/* darker vignette at the edges in the red state */
body[data-state="red"]::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center, transparent 50%, rgba(0, 0, 0, .45) 100%);
  z-index: 0;
}

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

main {
  position: relative;
  z-index: 1;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 16px calc(120px + env(safe-area-inset-bottom));
}

button, input, select {
  font: inherit;
  color: inherit;
}

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

.num { font-variant-numeric: tabular-nums; font-feature-settings: "tnum", "lnum"; }
.muted { color: var(--ink-2); }
.small { font-size: 15px; }

/* ---------- screens ---------- */
.screen { display: none; }
.screen.on { display: block; }

.home-head { margin: 8px 4px 16px; }
.eyebrow {
  text-transform: uppercase;
  letter-spacing: .12em;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
}
.app-title {
  font-family: var(--serif);
  font-size: 30px;
  font-weight: 700;
  line-height: 1.15;
}

.screen-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 8px 0 16px;
  flex-wrap: wrap;
}
.screen-title {
  font-family: var(--serif);
  font-size: 26px;
  font-weight: 700;
}

/* ---------- cards ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 14px;
  transition: background-color .6s ease, border-color .6s ease;
}
.card-title {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 700;
  color: var(--ink-2);
  margin-bottom: 10px;
}
.card-label {
  font-size: 16px;
  color: var(--ink-2);
}
.row-between {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
}

.hero { text-align: center; padding: 22px 16px; }
.hero-amount {
  font-family: var(--serif);
  font-size: clamp(40px, 14vw, 74px);
  font-weight: 700;
  line-height: 1.05;
  margin: 6px 0 4px;
  letter-spacing: -.01em;
}

/* ---------- banners ---------- */
.banner {
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 14px;
  font-size: 17px;
}
.banner-state {
  background: var(--banner-bg);
  color: var(--banner-ink);
  font-weight: 700;
  font-size: 18px;
  line-height: 1.4;
}
.banner-example {
  background: var(--accent-tint);
  color: var(--ink);
  border: 1px dashed var(--accent);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* ---------- meter ---------- */
.meter { position: relative; margin: 20px 0 26px; }
.meter-track {
  height: 14px;
  border-radius: 7px;
  background: var(--meter-track);
  overflow: hidden;
}
.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 7px;
  background: var(--meter-fill);
  transition: width .5s ease, background-color .6s ease;
}
.meter-marker {
  position: absolute;
  top: -5px;
  bottom: -5px;
  width: 3px;
  border-radius: 2px;
  background: var(--ink);
  transform: translateX(-1.5px);
}
.meter-marker-label {
  position: absolute;
  top: -22px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-2);
  white-space: nowrap;
}
.meter-foot { font-size: 15px; }

/* ---------- key/value rows, pills, lists ---------- */
.kv {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 12px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}
.kv:last-of-type { border-bottom: 0; }

.pill {
  display: inline-block;
  margin-top: 8px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--ink);
  font-weight: 600;
  font-size: 15px;
}
.pill-bad { background: var(--danger); color: var(--danger-ink); }
.pill-check { background: var(--banner-bg); color: var(--banner-ink); margin-bottom: 8px; }

.afford-amount {
  font-family: var(--serif);
  font-size: 34px;
  font-weight: 700;
  margin: 2px 0 4px;
}
.how { margin-top: 10px; }
.how summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-2);
  min-height: 32px;
}
.how .kv { font-size: 15px; padding: 5px 0; }

.plain-list { list-style: none; }
.plain-list > li { border-bottom: 1px solid var(--line); }
.plain-list > li:last-child { border-bottom: 0; }

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 9px 2px;
  background: none;
  border: 0;
  text-align: left;
  font-size: 17px;
}
button.row { cursor: pointer; border-radius: 10px; }
button.row:active { background: var(--accent-tint); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow-wrap: anywhere; }
.row-sub { font-size: 15px; color: var(--ink-2); overflow-wrap: anywhere; }
.row-amount { font-weight: 600; white-space: nowrap; }
.row-amount.in { color: var(--accent-deep); }

.tag {
  display: inline-block;
  font-size: 12.5px;
  font-weight: 700;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--accent-tint);
  color: var(--ink);
  margin-left: 6px;
  vertical-align: 2px;
  white-space: nowrap;
}
.tag-check { background: var(--banner-bg); color: var(--banner-ink); }

.empty-note { padding: 12px 2px; color: var(--ink-2); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 18px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .6s ease;
}
.btn:active { filter: brightness(.95); }
.btn-block { display: flex; width: 100%; margin-bottom: 10px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-size: 19px; min-height: 56px; }
.btn-secondary { background: var(--accent-tint); border-color: var(--accent-tint); color: var(--ink); }
.btn-quiet { background: none; border: 0; color: var(--ink); padding: 10px 12px; }
.btn-small { min-height: 42px; padding: 6px 14px; font-size: 15px; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: var(--danger-ink); }
.btn-danger-outline { background: none; border: 2px solid var(--danger); color: var(--danger); }
.btn svg { width: 22px; height: 22px; flex: none; }
.btn[disabled] { opacity: .45; cursor: default; }
.back { margin-left: -12px; }

.file-btn { position: relative; }

/* ---------- inline confirm (no browser pop-ups) ---------- */
.confirm {
  background: var(--accent-tint);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  margin: 10px 0;
  font-weight: 600;
}
.confirm-actions { display: flex; gap: 10px; margin-top: 10px; }
.confirm-actions .btn { flex: 1; }

/* ---------- form elements ---------- */
.field { display: block; margin-bottom: 14px; }
.field > span, .field-label {
  display: block;
  font-size: 15px;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 6px;
}
.field input, .field select, .field-input {
  width: 100%;
  min-height: 52px;
  padding: 10px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--card);
  font-size: 19px;
}
.field-input { margin-bottom: 10px; }
.money-field { position: relative; }
.money-field input { padding-left: 34px; }
.money-field::after {
  content: "$";
  position: absolute;
  left: 14px;
  bottom: 13px;
  font-size: 19px;
  color: var(--ink-2);
  pointer-events: none;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  margin-bottom: 8px;
  font-size: 17px;
}
.check-row input { width: 26px; height: 26px; accent-color: var(--accent); flex: none; }

.add-row { display: flex; gap: 10px; margin-top: 10px; }
.add-row input {
  flex: 1;
  min-height: 48px;
  padding: 8px 14px;
  border-radius: 14px;
  border: 1.5px solid var(--line);
  background: var(--card);
  min-width: 0;
}

/* ---------- amount display + keypad ---------- */
.amount-display {
  font-family: var(--serif);
  font-size: clamp(48px, 15vw, 64px);
  font-weight: 700;
  text-align: center;
  margin: 4px 0 10px;
  line-height: 1.1;
}
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 18px;
}
.keypad button {
  min-height: 60px;
  font-size: 26px;
  font-weight: 600;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: var(--card);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.keypad button:active { background: var(--accent-tint); }
.keypad svg { width: 30px; height: 30px; }

/* ---------- segmented toggle ---------- */
.seg {
  display: flex;
  background: var(--meter-track);
  border-radius: 14px;
  padding: 4px;
  margin-bottom: 16px;
}
.seg-btn {
  flex: 1;
  min-height: 48px;
  border: 0;
  border-radius: 11px;
  background: none;
  font-size: 17px;
  font-weight: 600;
  color: var(--ink-2);
  cursor: pointer;
}
.seg-btn.on { background: var(--accent); color: var(--accent-ink); }

/* ---------- category chips ---------- */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
}
.chip {
  min-height: 48px;
  padding: 10px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: var(--card);
  font-size: 17px;
  font-weight: 600;
  cursor: pointer;
}
.chip.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.bill-note { margin-bottom: 14px; font-weight: 600; }

/* ---------- history ---------- */
.month-card { width: 100%; cursor: pointer; text-align: left; display: block; }
.month-card h3 {
  font-family: var(--serif);
  font-size: 21px;
  margin-bottom: 8px;
}
.group-head {
  font-size: 15px;
  text-transform: uppercase;
  letter-spacing: .1em;
  font-weight: 700;
  color: var(--ink-2);
  margin: 4px 0 2px;
}
.cat-head {
  display: flex;
  justify-content: space-between;
  font-weight: 700;
  padding: 8px 2px 2px;
}

/* ---------- FAB + bottom bar ---------- */
.fab {
  display: none;
  position: fixed;
  right: calc(18px + env(safe-area-inset-right));
  bottom: calc(88px + env(safe-area-inset-bottom));
  width: 66px;
  height: 66px;
  border-radius: 50%;
  border: 0;
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  cursor: pointer;
  align-items: center;
  justify-content: center;
  z-index: 5;
  transition: background-color .6s ease;
}
.fab svg { width: 32px; height: 32px; }
body[data-screen="home"] .fab { display: flex; }

.bottombar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  justify-content: center;
  gap: 4px;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  z-index: 4;
  transition: background-color .6s ease;
}
.tab {
  flex: 1;
  max-width: 170px;
  min-height: 56px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  border: 0;
  border-radius: 12px;
  background: none;
  color: var(--ink-2);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
}
.tab svg { width: 24px; height: 24px; }
.tab.on { color: var(--ink); background: var(--accent-tint); }

/* ---------- toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: var(--banner-bg);
  color: var(--banner-ink);
  padding: 12px 22px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 16px;
  box-shadow: var(--shadow);
  z-index: 10;
  max-width: 90vw;
  text-align: center;
}

/* ---------- settings ---------- */
.card-danger { border-color: var(--danger); }
.about { text-align: center; margin: 18px 0; }

.cat-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
}
.cat-row input[type="text"] {
  flex: 1;
  min-width: 0;
  min-height: 48px;
  padding: 8px 12px;
  border-radius: 12px;
  border: 1.5px solid var(--line);
  background: var(--card);
}
.chip-toggle {
  min-height: 48px;
  padding: 6px 12px;
  border-radius: 999px;
  border: 1.5px solid var(--line);
  background: none;
  font-size: 14px;
  font-weight: 700;
  color: var(--ink-2);
  cursor: pointer;
  white-space: nowrap;
}
.chip-toggle.on {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

/* laptop: keep the phone column, just centered with breathing room */
@media (min-width: 700px) {
  body { padding-top: 16px; }
  .bottombar { max-width: 520px; left: 50%; transform: translateX(-50%); border-radius: 18px 18px 0 0; border: 1px solid var(--line); border-bottom: 0; }
  .fab { right: calc(50% - 260px + 18px); }
}
