/* Schibsted Grotesk (SIL Open Font License 1.1), self-hosted */
@font-face {
  font-family: "Grotesk";
  src: url("/fonts/grotesk-latin.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Grotesk";
  src: url("/fonts/grotesk-latin-ext.woff2") format("woff2");
  font-weight: 400 900;
  font-display: swap;
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

:root {
  color-scheme: light;
  --bg: #E9ECE6;
  --surface: #F6F8F4;
  --ink: #1F2A24;
  --muted: #66726B;
  --line: #D3D9D1;
  --track: #D6DCD3;
  --accent: #3047D6;
  --accent-ink: #FFFFFF;
  --over: #B83A2E;
  --backdrop: rgba(31, 42, 36, 0.32);

  --font: "Grotesk", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --step--1: 0.8125rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --hero: clamp(4rem, 21vw, 7rem);

  --radius-sheet: 22px;
  --radius-control: 12px;
  --pad: clamp(20px, 5vw, 32px);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #141815;
    --surface: #1C211D;
    --ink: #E4E9E3;
    --muted: #8E9A92;
    --line: #2B322D;
    --track: #2A312C;
    --accent: #8D9DFF;
    --accent-ink: #0F1430;
    --over: #F07B6C;
    --backdrop: rgba(0, 0, 0, 0.55);
  }
}

/* Picked by hand in settings (theme.js sets data-theme). */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #141815;
  --surface: #1C211D;
  --ink: #E4E9E3;
  --muted: #8E9A92;
  --line: #2B322D;
  --track: #2A312C;
  --accent: #8D9DFF;
  --accent-ink: #0F1430;
  --over: #F07B6C;
  --backdrop: rgba(0, 0, 0, 0.55);
}

*, *::before, *::after { box-sizing: border-box; }

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  scroll-padding-top: env(safe-area-inset-top, 0px);
}

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  line-height: 1.45;
  font-variant-numeric: proportional-nums;
  -webkit-font-smoothing: antialiased;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }

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

[hidden] { display: none !important; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: 8px var(--pad) 120px;
}

/* ---------- top bar ---------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 4px;
  margin: 0 -10px;
  padding: 8px 0;
}

.month-label {
  margin: 0;
  font-size: var(--step-0);
  font-weight: 560;
  min-width: 9.5em;
  text-align: center;
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: transparent;
}
.icon-btn svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn:hover { background: var(--track); }
.icon-btn:disabled { opacity: 0.3; cursor: default; background: transparent; }
.settings-btn { margin-left: auto; }

/* ---------- hero: what's left ---------- */

.hero { padding: 28px 0 40px; }

.hero-figure {
  margin: 0;
  font-size: var(--hero);
  font-weight: 640;
  line-height: 0.9;
  letter-spacing: -0.055em;
  white-space: nowrap;
}
.hero-figure .cents {
  font-size: 0.36em;
  font-weight: 500;
  letter-spacing: -0.02em;
  vertical-align: 0.95em;
  margin-left: 0.06em;
  color: var(--muted);
}
.hero-figure .symbol {
  font-size: 0.5em;
  font-weight: 560;
  letter-spacing: -0.02em;
  color: var(--muted);
}
.hero.is-over .hero-figure,
.hero.is-over .hero-figure .cents,
.hero.is-over .hero-figure .symbol { color: var(--over); }

.hero-caption {
  margin: 14px 0 0;
  font-size: var(--step-1);
  color: var(--muted);
}

.pace {
  position: relative;
  height: 10px;
  margin: 32px 0 12px;
  border-radius: 5px;
  background: var(--track);
}
.pace-fill {
  position: absolute;
  inset: 0 auto 0 0;
  border-radius: 5px;
  background: var(--accent);
  transition: width 0.5s cubic-bezier(0.2, 0.7, 0.2, 1);
}
.hero.is-over .pace-fill { background: var(--over); }
.pace-today {
  position: absolute;
  top: -6px;
  bottom: -6px;
  width: 2px;
  margin-left: -1px;
  border-radius: 1px;
  background: var(--ink);
}

.pace-legend {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  margin: 0;
  font-size: var(--step--1);
  color: var(--muted);
}
.pace-legend span:last-child { text-align: right; }

.hero-action { margin-top: 24px; }

/* ---------- category breakdown ---------- */

.breakdown:empty { display: none; }
.breakdown { padding-bottom: 36px; }

.breakdown-row {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: baseline;
  gap: 4px 16px;
  padding: 8px 0;
}
.breakdown-row .name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.breakdown-row .amount { font-weight: 560; }
.breakdown-row .share {
  grid-column: 1 / -1;
  height: 3px;
  border-radius: 2px;
  background: var(--track);
  overflow: hidden;
}
.breakdown-row .share i { display: block; height: 100%; border-radius: 2px; }
.breakdown-row .amount.is-over { color: var(--over); }
.breakdown-row .of {
  grid-column: 1 / -1;
  margin-top: -2px;
  font-size: var(--step--1);
  color: var(--muted);
}

.dot {
  flex: none;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--muted);
}

.pie-wrap {
  position: relative;
  width: min(220px, 60vw);
  margin: 0 auto 28px;
}
.pie { width: 100%; height: auto; overflow: visible; }
.pie circle { fill: none; stroke-width: 5.5; }
.pie-track { stroke: var(--track); }
.pie-slice { transition: stroke-width 0.15s; }
.pie-slice:hover { stroke-width: 7; }
.pie-centre {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
}
.pie-centre strong { font-size: 1.75rem; font-weight: 640; letter-spacing: -0.03em; line-height: 1.1; }
.pie-centre span { font-size: var(--step--1); color: var(--muted); }

/* ---------- expense list ---------- */

.day { margin-bottom: 28px; }
.day-head {
  display: flex;
  justify-content: space-between;
  margin: 0 0 4px;
  font-size: var(--step--1);
  font-weight: 500;
  color: var(--muted);
}

.expense {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 -12px;
  width: calc(100% + 24px);
  padding: 11px 12px;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  text-align: left;
}
.expense:hover { background: var(--surface); }
.expense .text { flex: 1; min-width: 0; }
.expense .title,
.expense .sub { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.expense .sub { font-size: var(--step--1); color: var(--muted); }
.expense .amount { font-weight: 560; }

.empty {
  margin: 0;
  max-width: 28ch;
  color: var(--muted);
}

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

.fab {
  position: fixed;
  right: max(var(--pad), calc((100vw - 560px) / 2 + var(--pad)));
  bottom: calc(24px + env(safe-area-inset-bottom, 0px));
  display: grid;
  place-items: center;
  width: 60px;
  height: 60px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
}
.fab svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
}
.fab:active { transform: scale(0.95); }

.primary-btn {
  min-height: 48px;
  padding: 0 22px;
  border: 0;
  border-radius: var(--radius-control);
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 600;
}
.primary-btn.small { min-height: 44px; padding: 0 16px; white-space: nowrap; }
.primary-btn:disabled { opacity: 0.5; cursor: default; }

.text-btn {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font-weight: 560;
  text-decoration: none;
}
.text-btn.danger { color: var(--over); }

/* ---------- sheets ---------- */

.sheet {
  width: 100%;
  max-width: 560px;
  max-height: calc(100dvh - 40px);
  margin: auto auto 0;
  padding: 20px var(--pad) calc(24px + env(safe-area-inset-bottom, 0px));
  border: 0;
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  background: var(--surface);
  color: var(--ink);
  overflow-y: auto;
}
.sheet.tall { min-height: 70dvh; }
.sheet::backdrop { background: var(--backdrop); }
.sheet[open] { animation: sheet-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1); }

@keyframes sheet-in {
  from { transform: translateY(40px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

@media (min-width: 640px) {
  .sheet { margin: auto; border-radius: var(--radius-sheet); max-width: 480px; }
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.sheet-head h2 { margin: 0; font-size: var(--step-1); font-weight: 600; }

.amount-field {
  display: flex;
  align-items: baseline;
  gap: 6px;
  padding: 18px 0 22px;
  border-bottom: 1px solid var(--line);
}
.amount-field .currency { font-size: 2rem; color: var(--muted); }
.amount-field input {
  flex: 1;
  min-width: 0;
  padding: 0;
  border: 0;
  background: none;
  font-size: 3.25rem;
  font-weight: 620;
  letter-spacing: -0.04em;
  outline: none;
}
.amount-field:focus-within { border-bottom-color: var(--accent); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0;
  padding: 20px 0 8px;
  border: 0;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: transparent;
}
.chip[aria-pressed="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--surface);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
  font-size: var(--step--1);
  color: var(--muted);
}
.field input {
  min-height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--bg);
  color: var(--ink);
  font-size: var(--step-0);
}
.field input:focus { outline: none; border-color: var(--accent); }
.field.grow { flex: 1; margin-top: 0; }

.form-error {
  min-height: 1.45em;
  margin: 12px 0 0;
  font-size: var(--step--1);
  color: var(--over);
}

.sheet-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 16px;
  margin-top: 8px;
}
.sheet-actions .danger { margin-right: auto; }

/* ---------- cover sheet ---------- */

.cover-intro { margin: 4px 0 16px; color: var(--muted); }
.cover-intro strong { color: var(--ink); font-weight: 600; }
.cover-sources { display: flex; flex-direction: column; }
.cover-source {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 10px;
  padding: 8px 0;
  border-bottom: 1px solid var(--line);
}
.cover-source:last-child { border-bottom: 0; }
.cover-source .name { display: flex; flex-direction: column; min-width: 0; }
.cover-source .left { font-size: var(--step--1); color: var(--muted); }
.cover-source input {
  width: 6.5em;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  text-align: right;
}
.cover-source input:focus { outline: none; border-color: var(--accent); }
.fill-btn { font-size: var(--step--1); }
#cover-status.is-over { color: var(--over); }

.breakdown-row .of { display: flex; justify-content: space-between; align-items: center; }
.breakdown-row .cover-link { min-height: 32px; font-size: var(--step--1); }

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

.settings-block { padding: 22px 0; border-bottom: 1px solid var(--line); }
.settings-block:last-child { border-bottom: 0; }
.settings-block h3 { margin: 0 0 12px; font-size: var(--step-0); font-weight: 600; }

.inline-form { display: flex; gap: 10px; align-items: stretch; }

.hint { margin: 10px 0 0; font-size: var(--step--1); color: var(--muted); }
.account .hint { margin: 0; }

.split-heading {
  margin: 20px 0 4px;
  font-size: var(--step--1);
  font-weight: 600;
}
.split-heading span { font-weight: 400; color: var(--muted); }
.split-list { list-style: none; margin: 0; padding: 0; }
.split-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 3px 0;
}
.split-list .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.split-list input {
  width: 7.5em;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  text-align: right;
}
.split-list input:focus { outline: none; border-color: var(--accent); }
#split-left.is-over { color: var(--over); }

.category-list { list-style: none; margin: 0 0 12px; padding: 0; }
.category-list li { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.category-list input {
  flex: 1;
  min-width: 0;
  min-height: 44px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
}
.category-list input:hover { border-color: var(--line); }
.category-list input:focus { outline: none; border-color: var(--accent); background: var(--bg); }

.swatch {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
}
.swatch .dot { width: 16px; height: 16px; }
.remove svg {
  width: 18px;
  height: 18px;
  stroke: var(--muted);
}

.theme-chips { padding: 0; }

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

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(100px + env(safe-area-inset-bottom, 0px));
  max-width: calc(100vw - 40px);
  padding: 12px 18px;
  border-radius: var(--radius-control);
  background: var(--ink);
  color: var(--bg);
  font-size: var(--step--1);
  transform: translate(-50%, 12px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); pointer-events: auto; }
.toast button {
  margin-left: 12px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  font-weight: 600;
  text-decoration: underline;
}

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