:root {
  --bg: #f3efe6;
  --ink: #1a1814;
  --muted: #5e584e;
  --line: #ddd4c4;
  --card: #fffdf8;
  --accent: #0c6b52;
  --accent-deep: #084838;
  --accent-ink: #f4fff9;
  --danger: #8a3d32;
  --real: #9a5b16;
  --shadow: 0 10px 30px rgba(26, 24, 20, 0.06);
  --sans: "Segoe UI", system-ui, sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 480px at 50% -180px, rgba(12, 107, 82, 0.16), transparent 60%),
    var(--bg);
}

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

.app {
  width: min(40rem, calc(100% - 1.5rem));
  margin: 0 auto;
  padding:
    calc(1rem + env(safe-area-inset-top))
    0
    calc(1.5rem + env(safe-area-inset-bottom));
}

.top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.85rem 1rem 1rem;
  border-radius: 1.25rem;
  background: linear-gradient(160deg, var(--accent) 0%, var(--accent-deep) 100%);
  color: var(--accent-ink);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 0.15rem;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  opacity: 0.8;
}

h1 {
  margin: 0;
  font-size: 1.85rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.install {
  border: 1px solid rgba(244, 255, 249, 0.45);
  background: transparent;
  color: var(--accent-ink);
  border-radius: 999px;
  padding: 0.45rem 0.85rem;
  cursor: pointer;
}

.install:hover,
.install:focus-visible {
  background: rgba(255, 255, 255, 0.12);
}

.tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 0.35rem;
  margin: 0.9rem 0 0.35rem;
  padding: 0.3rem;
  background: rgba(255, 253, 248, 0.72);
  border: 1px solid var(--line);
  border-radius: 999px;
}

.tab {
  border: 0;
  background: transparent;
  border-radius: 999px;
  padding: 0.55rem 0.2rem;
  color: var(--muted);
  cursor: pointer;
  min-width: 0;
}

.tab[aria-selected="true"] {
  background: var(--ink);
  color: #f7f3ea;
}

.tab:focus-visible,
input:focus-visible,
select:focus-visible,
.ghost:focus-visible,
.install:focus-visible,
.help:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

main {
  margin-top: 0.85rem;
  padding: 1rem 1rem 1.1rem;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
}

.blurb {
  margin: 0 0 0.9rem;
  color: var(--muted);
  line-height: 1.45;
}

.app.wide {
  width: min(56rem, calc(100% - 1.5rem));
}

.fields {
  display: grid;
  gap: 0.75rem;
}

.fields + .fields {
  margin-top: 0.75rem;
}

.fields.row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1.15rem 1.5rem;
  align-items: start;
}

.column {
  margin: 0;
  padding: 0;
  border: 0;
  min-width: 0;
  display: grid;
  gap: 0.75rem;
  align-content: start;
}

.column legend {
  padding: 0;
  font-size: 1.02rem;
  font-weight: 650;
}

.split .column + .column {
  padding-left: 1.5rem;
  border-left: 1px solid var(--line);
}

.fields.shared {
  margin-top: 0.95rem;
  padding-top: 0.95rem;
  border-top: 1px solid var(--line);
  grid-template-columns: 1fr 1fr;
}

.fields.shared .check-row {
  grid-column: 1 / -1;
}

.field {
  display: grid;
  gap: 0.3rem;
}

.label-line,
.check-row {
  display: flex;
  align-items: flex-start;
}

.label-line label,
.field span,
.check span,
.choices legend {
  font-size: 0.92rem;
}

.help {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 0.95rem;
  height: 0.95rem;
  margin-left: 0.22rem;
  padding: 0;
  border: 1px solid currentColor;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  vertical-align: super;
  cursor: help;
  line-height: 1;
  position: relative;
  top: -0.05em;
}

.help sup {
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 0;
}

.help:hover,
.help:focus-visible {
  color: var(--accent-deep);
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.tip {
  position: fixed;
  z-index: 30;
  width: max-content;
  max-width: min(16.5rem, calc(100vw - 1.5rem));
  padding: 0.6rem 0.75rem;
  border-radius: 0.75rem;
  background: var(--ink);
  color: #f6f1e6;
  font-size: 0.84rem;
  line-height: 1.45;
  pointer-events: none;
  box-shadow: 0 12px 28px rgba(26, 24, 20, 0.18);
}

.tip[hidden] {
  display: none;
}

.col-label {
  display: inline-flex;
  align-items: flex-start;
  gap: 0.05rem;
}

.control {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-height: 2.75rem;
  padding: 0 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  background: #fff;
}

.control input,
.control select {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0.65rem 0;
  font-size: 1rem;
}

.control input:not([type="date"]) {
  appearance: textfield;
}

.control input::-webkit-outer-spin-button,
.control input::-webkit-inner-spin-button {
  appearance: none;
  margin: 0;
}

.control input:focus,
.control select:focus {
  outline: none;
}

.affix {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.choices {
  margin: 0;
  padding: 0;
  border: 0;
  display: grid;
  gap: 0.35rem;
}

.choices legend {
  padding: 0;
}

.choice-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.35rem;
  padding: 0.3rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
}

.choice-row label {
  position: relative;
  display: block;
  text-align: center;
  border-radius: 999px;
  padding: 0.55rem 0.4rem;
  color: var(--muted);
  cursor: pointer;
}

.choice-row input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
}

.choice-row label:has(input:checked) {
  background: var(--ink);
  color: #f7f3ea;
}

.choice-row label:focus-within {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.section-break {
  margin-top: 0.25rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}

.check {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  margin-top: 0.15rem;
}

.check input {
  width: 1.05rem;
  height: 1.05rem;
  accent-color: var(--accent);
}

.actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.35rem;
}

.ghost {
  border: 0;
  background: transparent;
  color: var(--accent-deep);
  padding: 0.35rem 0.1rem;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}

.error {
  margin: 0.8rem 0 0;
  color: var(--danger);
}

.results {
  display: grid;
  gap: 0.65rem;
  margin-top: 1rem;
}

.payouts {
  display: grid;
  gap: 0.75rem;
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}

.payouts h2 {
  margin: 0;
  font-size: 1.02rem;
  font-weight: 650;
}

.results:empty {
  margin-top: 0;
}

.result-paths .column {
  gap: 0.65rem;
}

.stat-row {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 0 1.5rem;
  align-items: start;
}

.stat-row > .stat + .stat,
.stat-row > .stat-stack {
  padding-left: 1.5rem;
  border-left: 1px solid var(--line);
}

.stat-row.pairs {
  grid-template-rows: auto auto;
  grid-template-columns: 1fr 1fr;
}

.stat-row.pairs > .stat + .stat {
  padding-left: 0;
  border-left: 0;
}

.stat-row.pairs > .stat:nth-child(n + 3) {
  padding-left: 1.5rem;
  border-left: 1px solid var(--line);
}

.stat-stack {
  display: grid;
  gap: 0.65rem;
  align-content: start;
  min-width: 0;
}

.stat {
  padding-top: 0.7rem;
  border-top: 1px solid var(--line);
}

.stat p,
.schedule summary,
.note {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.stat strong {
  display: block;
  margin-top: 0.12rem;
  font-size: 1.7rem;
  font-weight: 650;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat.compact strong {
  font-size: 1.15rem;
}

.stat strong.positive {
  color: var(--accent-deep);
}

.stat strong.negative {
  color: var(--danger);
}

.chart {
  margin: 0.15rem 0 0;
  padding-top: 0.85rem;
  border-top: 1px solid var(--line);
}

.chart figcaption {
  margin: 0 0 0.35rem;
  font-size: 0.92rem;
}

.chart svg {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
}

.chart-grid {
  stroke: var(--line);
  stroke-width: 1;
}

.chart-label {
  fill: var(--muted);
  font-size: 12px;
  font-family: var(--sans);
}

.chart-area {
  fill: rgba(12, 107, 82, 0.14);
}

.chart-balance,
.chart-real,
.chart-contributed,
.chart-cursor {
  fill: none;
  vector-effect: non-scaling-stroke;
}

.chart-balance {
  stroke: var(--accent);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-real {
  stroke: var(--real);
  stroke-width: 2.5;
  stroke-linejoin: round;
  stroke-linecap: round;
}

.chart-contributed {
  stroke: var(--muted);
  stroke-width: 1.5;
  stroke-dasharray: 4 4;
}

.chart-cursor {
  stroke: var(--ink);
  stroke-width: 1;
}

.chart-plot {
  fill: transparent;
  cursor: crosshair;
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.85rem 1.1rem;
  margin-top: 0.2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.legend .check {
  margin-top: 0;
  gap: 0.4rem;
  cursor: pointer;
}

.legend .check .swatch {
  margin-right: 0;
}

.swatch {
  display: inline-block;
  width: 1.1rem;
  margin-right: 0.35rem;
  vertical-align: middle;
  border-top: 2px solid var(--muted);
}

.swatch.balance {
  border-top: 3px solid var(--accent);
}

.swatch.real {
  border-top: 3px solid var(--real);
}

.swatch.contributed {
  border-top: 2px dashed var(--muted);
}

.chart-readout {
  margin: 0.3rem 0 0;
  min-height: 1.2em;
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.schedule {
  margin-top: 0.2rem;
}

.schedule summary {
  cursor: pointer;
  color: var(--accent-deep);
}

.table-wrap {
  max-height: 18rem;
  overflow: auto;
  margin-top: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 0.4rem 0.55rem;
  text-align: right;
  white-space: nowrap;
}

th:first-child,
td:first-child {
  text-align: left;
}

thead th {
  position: sticky;
  top: 0;
  background: #f7f3ea;
  color: var(--muted);
  font-weight: 600;
}

tbody tr:nth-child(even) {
  background: rgba(243, 239, 230, 0.55);
}

.foot {
  margin: 0.85rem 0.2rem 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

@media (max-width: 42rem) {
  .fields.shared,
  .fields.row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 28rem) {
  .split {
    grid-template-columns: 1fr;
  }

  .split .column + .column {
    padding-top: 0.95rem;
    padding-left: 0;
    border-top: 1px solid var(--line);
    border-left: 0;
  }

  .tabs {
    border-radius: 1rem;
  }

  .tab {
    font-size: 0.72rem;
    padding-inline: 0.1rem;
  }

  .stat strong {
    font-size: 1.45rem;
  }

  .stat-row {
    grid-auto-flow: row;
    grid-template-columns: 1fr;
    gap: 0.65rem 0;
  }

  .stat-row > .stat + .stat,
  .stat-row > .stat-stack,
  .stat-row.pairs > .stat:nth-child(n + 3) {
    padding-left: 0;
    border-left: 0;
  }

  .stat-row.pairs {
    grid-template-columns: 1fr;
    grid-template-rows: none;
    grid-auto-flow: row;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    scroll-behavior: auto;
  }
}
