:root {
  --bg: #dce0e8;
  --paper: #f5f6f8;
  --ink: #12141a;
  --muted: #6d7380;
  --line: rgba(18, 20, 26, 0.08);
  --accent: #3a4fd8;
  --accent-soft: rgba(58, 79, 216, 0.1);
  --warn: #b45309;
  --bad: #c2413b;
  --field: #ffffff;
  --primary-ink: #f7f8fc;
  --tap: 52px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #08090c;
  --paper: #111318;
  --ink: #eef0f4;
  --muted: #8b92a0;
  --line: rgba(238, 240, 244, 0.1);
  --accent: #8b9bff;
  --accent-soft: rgba(139, 155, 255, 0.14);
  --warn: #e8b86d;
  --bad: #f08a80;
  --field: #1a1d24;
  --primary-ink: #111318;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI Variable", "Segoe UI", "Helvetica Neue", system-ui, sans-serif;
}

.is-hidden { display: none !important; }

.shell {
  height: 100dvh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

.phone {
  position: relative;
  width: 100%;
  max-width: 430px;
  height: 100dvh;
  min-height: 100dvh;
  max-height: 100dvh;
  background: var(--paper);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 0 0 1px var(--line);
}

.flow {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 8px;
  min-height: 56px;
  flex-shrink: 0;
}

.app-nav { align-items: flex-start; }

.back, .nav-spacer {
  width: 44px;
  height: 44px;
  border: 0;
  background: none;
  color: var(--ink);
  font-size: 22px;
  line-height: 1;
}

.dots {
  display: flex;
  gap: 8px;
}

.dots span {
  width: 7px;
  height: 7px;
  border-radius: 99px;
  background: var(--line);
}

.dots span.is-on { background: var(--accent); width: 18px; }

.pages {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.page {
  flex: 1;
  min-height: 0;
}

.scroll {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 24px;
  -webkit-overflow-scrolling: touch;
}

.eyebrow {
  margin: 0 0 8px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--muted);
}

h1 {
  margin: 0 0 10px;
  font-weight: 550;
  font-size: 30px;
  letter-spacing: -0.04em;
  line-height: 1.15;
}

.app-title { font-size: 26px; margin-bottom: 0; }

.hello {
  margin: 0 0 2px;
  font-size: 13px;
  color: var(--muted);
}

.lead {
  margin: 0 0 28px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.45;
}

.lead.compact {
  margin: 0 0 12px;
  font-size: 14px;
}

.badge {
  margin: 0 0 10px;
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--warn);
}

.field, .mini {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field span, .mini span {
  font-size: 13px;
  color: var(--muted);
}

.field-hint {
  font-size: 12px;
  color: var(--muted);
}

input, select, button {
  font: inherit;
}

input, select {
  width: 100%;
  min-height: 48px;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  border-radius: 14px;
  padding: 12px 14px;
  font-size: 16px;
}

.name-input, input.amount {
  min-height: 64px;
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

input[data-date] {
  direction: ltr;
  unicode-bidi: isolate;
  text-align: left;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.hero {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(112px, 0.85fr);
  gap: 10px;
  margin-top: 4px;
  align-items: end;
}

.hero .amount {
  min-height: 56px;
  font-size: 24px;
}

.hero .date-field input {
  min-height: 56px;
  padding: 12px 10px;
}

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 16px 0 0;
}

.actions.secondary { margin-top: 8px; }
.actions.single { grid-template-columns: 1fr; }

.btn {
  min-height: var(--tap);
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  border-radius: 16px;
  padding: 12px 14px;
  cursor: pointer;
  transition: transform 140ms var(--ease), background 160ms ease, border-color 160ms ease;
}

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--primary-ink);
  font-weight: 600;
}

.btn.ghost { background: transparent; }

.btn:active { transform: scale(0.99); }

.text-btn {
  border: 0;
  background: none;
  color: var(--accent);
  min-height: 44px;
  padding: 0 4px;
  font-size: 15px;
}

.theme-toggle {
  flex-shrink: 0;
  min-width: 72px;
  text-align: right;
}

.add-custom { margin: 8px 0 0; }

.restart {
  display: block;
  margin: 8px auto 0;
}

.channel-note {
  margin: 28px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.channel-note a,
.channel-link {
  color: var(--accent);
  text-decoration: none;
}

.channel-link {
  display: inline-block;
  margin-top: 4px;
  font-size: 15px;
}

.dock {
  padding: 12px 20px calc(16px + env(safe-area-inset-bottom));
  background: var(--paper);
  box-shadow: 0 -12px 24px rgba(28, 23, 18, 0.04);
}

.dock .btn { width: 100%; }

.dock.split {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 8px;
}

.form-error {
  min-height: 20px;
  margin: 0 20px 4px;
  color: var(--bad);
  font-size: 13px;
}

.status {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 13px;
  min-height: 0;
}

.status:empty { display: none; }

.status.error { color: var(--bad); }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.chip-btn {
  min-height: 40px;
  border: 1px solid var(--line);
  background: var(--field);
  border-radius: 999px;
  padding: 8px 14px;
  color: var(--ink);
}

.chip-btn.is-on {
  background: var(--accent-soft);
  border-color: var(--accent);
}

.stack, .rows { display: grid; gap: 10px; }

.card, .row, .pick {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  background: var(--field);
}

.pick {
  display: grid;
  gap: 10px;
  text-align: left;
  width: 100%;
  cursor: pointer;
}

.pick.is-on { border-color: var(--accent); background: var(--accent-soft); }

.pick-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.pick b { font-size: 17px; font-weight: 600; }
.pick p { margin: 4px 0 0; color: var(--muted); font-size: 13px; }
.check { color: var(--accent); font-size: 18px; }

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}

.card-head input {
  flex: 1;
  min-width: 0;
}

.grid-2, .grid-3 {
  display: grid;
  gap: 8px;
}

.grid-2 { grid-template-columns: 1fr 1fr; }
.grid-3 { grid-template-columns: 1fr 1fr; }

.block { margin-top: 28px; }
.block.first { margin-top: 8px; }
.block-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.block-head h2 { margin: 0; }

h2, h3 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.progress {
  height: 4px;
  margin-top: 10px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
}

.empty {
  color: var(--muted);
  padding: 8px 0 4px;
}

.result-panel { margin-top: 18px; }

.result-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 12px;
}

.result-head h2 {
  font-size: 22px;
  font-weight: 550;
  text-transform: none;
  letter-spacing: -0.03em;
  color: var(--ink);
}

.result-note {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.why-toggle {
  margin-top: 14px;
}

.why-toggle summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 13px;
  list-style: none;
}

.why-toggle summary::-webkit-details-marker { display: none; }

.alloc { display: grid; gap: 14px; }
.alloc-row { display: grid; gap: 6px; }
.alloc-meta {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  font-size: 15px;
}

.alloc-why {
  margin: 2px 0 0;
  font-size: 13px;
  line-height: 1.4;
  color: var(--muted);
}

.bar {
  height: 8px;
  background: var(--line);
  border-radius: 99px;
  overflow: hidden;
}

.bar > span { display: block; height: 100%; background: var(--accent); }
.bar.obligation > span { background: var(--warn); }
.bar.free > span { background: var(--muted); }

.risk {
  font-size: 12px;
  letter-spacing: 0.02em;
  color: var(--muted);
}

.risk.high, .risk.critical { color: var(--bad); }
.risk.medium { color: var(--warn); }

.forecast {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 12px 0 16px;
}

.chip {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: var(--accent-soft);
}

.chip b { display: block; font-size: 11px; color: var(--muted); font-weight: 500; }

.why {
  margin: 14px 0 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.why li {
  list-style: none;
  font-size: 13px;
  color: var(--muted);
  line-height: 1.45;
}

.day-card {
  border-top: 1px solid var(--line);
  padding-top: 16px;
  margin-top: 18px;
}

.remove {
  border: 0;
  background: none;
  color: var(--muted);
  min-width: 44px;
  min-height: 44px;
}

.tabbar {
  flex-shrink: 0;
  display: grid;
  grid-template-columns: 1fr 1fr 1fr 1fr;
  gap: 4px;
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: var(--paper);
  z-index: 20;
}

.tab {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: 56px;
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 14px;
  padding: 6px 4px 4px;
  font-size: 10px;
  font-weight: 600;
  line-height: 1.1;
  transition: background 180ms ease, color 180ms ease;
}

.tab svg {
  width: 22px;
  height: 22px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.tab svg .mark {
  fill: currentColor;
  stroke: none;
}

.tab span { display: block; }

.tab.is-on {
  background: var(--accent-soft);
  color: var(--accent);
}

.panel {
  margin-top: 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--field);
}

.panel.first { margin-top: 8px; }

.panel.warm {
  background: color-mix(in srgb, var(--warn) 7%, var(--field));
}

.panel .lead.compact { margin-bottom: 12px; }

.panel .block-head { align-items: flex-start; }

.stats-board { display: grid; gap: 8px; margin-top: 4px; }

.grain-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 18px;
  margin-top: 2px;
}

.grain-row.compact { gap: 4px 14px; }

.grain {
  margin: 0;
  padding: 0;
  min-height: 36px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 15px;
}

.grain.is-on { color: var(--ink); }

.period-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin: 2px 0 10px;
}

.period-shift {
  width: 40px;
  height: 40px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
}

.period-nav p {
  margin: 0;
  flex: 1;
  text-align: center;
  font-size: 13px;
  color: var(--muted);
}

.stats-hero b {
  display: block;
  font-size: 28px;
  font-weight: 550;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stats-hero span,
.stats-hero p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.stats-hero p.warn { color: var(--warn); }

.ledger-block { margin-top: 20px; padding-top: 8px; border-top: 1px solid var(--line); }

.ledger-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.ledger-actions .text-btn {
  font-size: 13px;
}

.ledger-month {
  margin: 16px 0 2px;
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.ledger-month:first-child { margin-top: 6px; }

.ledger-row {
  width: 100%;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  margin: 0;
  padding: 8px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.ledger-row:last-child { border-bottom: 0; }

.ledger-when {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.ledger-when b {
  width: 1.35em;
  font-size: 16px;
  font-weight: 550;
  font-variant-numeric: tabular-nums;
}

.ledger-when i {
  font-style: normal;
  font-size: 13px;
  color: var(--muted);
}

.ledger-sum {
  font-size: 15px;
  font-variant-numeric: tabular-nums;
}

.month-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.month-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: var(--paper);
}

.month-card b {
  display: block;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
}

.month-card span {
  color: var(--muted);
  font-size: 12px;
}

.pot-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.pot-tile {
  position: relative;
  aspect-ratio: auto;
  min-height: 124px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 4px;
  margin: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--paper);
  color: inherit;
  text-align: left;
  cursor: pointer;
  overflow: hidden;
  min-height: 0;
  animation: rise 380ms var(--ease) both;
  transition: transform 160ms var(--ease), border-color 160ms ease;
}

.pot-tile:nth-child(2) { animation-delay: 40ms; }
.pot-tile:nth-child(3) { animation-delay: 80ms; }
.pot-tile:nth-child(4) { animation-delay: 120ms; }
.pot-tile:nth-child(5) { animation-delay: 160ms; }
.pot-tile:nth-child(6) { animation-delay: 200ms; }

.pot-tile:active { transform: scale(0.98); }

.pot-tile .pot-fill {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 0;
  background: linear-gradient(180deg, transparent, var(--accent-soft));
  pointer-events: none;
  transition: height 400ms var(--ease);
}

.pot-tile .pot-pct {
  position: absolute;
  top: 10px;
  right: 12px;
  font-size: 11px;
  letter-spacing: 0.04em;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.pot-tile b {
  position: relative;
  font-size: 15px;
  font-weight: 650;
  line-height: 1.2;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.pot-tile .pot-sum,
.pot-tile .pot-meta {
  position: relative;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.pot-tile .pot-bar {
  position: relative;
  height: 5px;
  margin-top: 6px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.pot-tile .pot-bar > span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), color-mix(in srgb, var(--accent) 40%, white));
}

.pot-tile.is-obligation .pot-fill {
  background: linear-gradient(180deg, transparent, color-mix(in srgb, var(--warn) 28%, transparent));
}

.pot-tile.is-obligation .pot-bar > span {
  background: linear-gradient(90deg, var(--warn), color-mix(in srgb, var(--warn) 35%, white));
}

.switch-row {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 0 4px;
  border: 0;
  background: none;
  color: var(--ink);
  text-align: left;
}

.switch {
  width: 46px;
  height: 28px;
  border-radius: 99px;
  background: var(--line);
  position: relative;
  flex-shrink: 0;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 99px;
  background: var(--field);
  box-shadow: 0 1px 4px rgba(28, 23, 18, 0.18);
}

.switch-row[aria-checked="true"] .switch {
  background: var(--accent);
}

.switch-row[aria-checked="true"] .switch::after {
  left: 21px;
}

.range-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
}

.range-row input[type="range"] {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--accent);
}

.range-row b {
  min-width: 3ch;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.profile-pick {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-open {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  padding: 0;
  border: 0;
  background: none;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.profile-pick.is-on {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.sheet {
  position: absolute;
  inset: 0;
  z-index: 40;
  display: flex;
  align-items: flex-end;
}

.sheet.is-hidden { display: none; }

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(12, 14, 20, 0.36);
  animation: fade 220ms ease;
}

.sheet-card {
  position: relative;
  width: 100%;
  max-height: 86%;
  overflow-y: auto;
  padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
  background: var(--paper);
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -16px 40px rgba(12, 14, 20, 0.14);
  animation: sheet-up 320ms var(--ease);
}

.sheet-card h3 {
  margin: 0;
  font-size: 18px;
  text-transform: none;
  letter-spacing: -0.02em;
  color: var(--ink);
}

.splash {
  position: absolute;
  inset: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  background: var(--paper);
}

.splash-mark {
  width: 56px;
  height: 56px;
  border: 1.5px solid var(--ink);
  border-radius: 16px;
  display: grid;
  place-items: center;
  animation: mark-in 1.6s ease-in-out both;
}

.splash-mark i {
  display: block;
  width: 18px;
  height: 13px;
  border: 1.5px solid var(--ink);
  border-top-width: 4px;
  border-radius: 2px 2px 3px 3px;
}

.splash-name {
  margin: 0;
  font-size: 13px;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  color: var(--ink);
  animation: name-in 1.4s ease-in-out 0.45s both;
}

.splash.is-leaving {
  animation: splash-out 0.9s ease forwards;
}

.page:not(.is-hidden) {
  animation: rise 320ms var(--ease);
}

.switch::after {
  transition: left 180ms var(--ease);
}

@keyframes mark-in {
  from { opacity: 0; transform: scale(0.94); }
  to { opacity: 1; transform: scale(1); }
}

@keyframes name-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes splash-out {
  to { opacity: 0; visibility: hidden; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes fade {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes sheet-up {
  from { opacity: 0; transform: translateY(24px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  *:not(.splash):not(.splash-mark):not(.splash-name),
  *:not(.splash):not(.splash-mark):not(.splash-name)::before,
  *:not(.splash):not(.splash-mark):not(.splash-name)::after {
    animation: none !important;
    transition: none !important;
  }

  .splash-mark,
  .splash-name {
    animation: none;
    opacity: 1;
    transform: none;
  }
}

@media (min-width: 760px) {
  .phone {
    height: calc(100dvh - 32px);
    min-height: calc(100dvh - 32px);
    max-height: calc(100dvh - 32px);
    margin: 16px 0;
    border-radius: 28px;
    overflow: hidden;
  }
}
