:root {
  --bg: #e6ddd0;
  --glow: #f0d2c8;
  --card: #faf6f0;
  --field: #fffdf9;
  --ink: #1c1612;
  --muted: #5c534c;
  --line: #e0d4c6;
  --readonly: #f3ece3;
  --red: #b23a2b;
  --red-ink: #8d2416;
  --mark: #b23a2b;
  --green: #145c38;
  --green-wash: #e3f2e8;
  --amber: #7a4e06;
  --amber-wash: #f8efd8;
  --crit-wash: #f8e4de;
  --open: #1d4e6e;
  --open-wash: #e4eef5;
  --shadow: 0 22px 50px rgba(62, 38, 18, 0.07);
  --ease: cubic-bezier(0.2, 0.8, 0.2, 1);
  color-scheme: light;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12100e;
    --glow: #3a1c16;
    --card: #1c1916;
    --field: #26211c;
    --ink: #f4efe8;
    --muted: #c2b6a6;
    --line: #3d362f;
    --readonly: #221e1b;
    --red: #ff8a7a;
    --red-ink: #ffb0a4;
    --mark: #b23a2b;
    --green: #8ed4a6;
    --green-wash: #1a3328;
    --amber: #e7c078;
    --amber-wash: #3a2e18;
    --crit-wash: #3d221c;
    --open: #b7d4ee;
    --open-wash: #1a2c3a;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100dvh;
  background:
    radial-gradient(880px 360px at 100% -12%, var(--glow), transparent 64%),
    var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.5;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.045;
  mix-blend-mode: multiply;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='140' height='140'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

@media (prefers-color-scheme: dark) {
  body::before { opacity: 0.06; mix-blend-mode: overlay; }
}

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

button, .file, .choice label { cursor: pointer; touch-action: manipulation; }

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

::selection {
  background: color-mix(in srgb, var(--mark) 28%, transparent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip {
  position: absolute;
  left: 12px;
  top: -48px;
  background: var(--ink);
  color: var(--bg);
  padding: 8px 12px;
  border-radius: 8px;
  z-index: 5;
}

.skip:focus { top: 12px; }

.wrap {
  position: relative;
  z-index: 2;
  max-width: 1080px;
  margin: 0 auto;
  padding: 36px 24px 72px;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 20px 32px;
  align-items: flex-end;
  flex-wrap: wrap;
}

h1, h2, .lede, #runway-detail, .empty-row, .fine {
  text-wrap: pretty;
}

h1 {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-family: Newsreader, Georgia, serif;
  font-weight: 500;
  font-size: clamp(2.5rem, 6vw, 3.5rem);
  letter-spacing: -0.035em;
  line-height: 0.92;
}

.mark { width: 34px; height: 34px; flex: none; }
.mark-tile { fill: var(--mark); }
.mark-drop { fill: #fffaf4; }

.lede {
  margin: 10px 0 0;
  max-width: 42ch;
  color: var(--muted);
  line-height: 1.5;
}

.tools { display: flex; flex-wrap: wrap; gap: 6px; }

.tools button, .file, button.remove, dialog button, #fresh {
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--ink);
  transition: background-color 200ms var(--ease), border-color 200ms var(--ease), transform 200ms var(--ease);
}

.tools button:hover, .file:hover, button.remove:hover, dialog button:hover, #fresh:hover {
  background: color-mix(in srgb, var(--ink) 6%, transparent);
}

#sample {
  border-color: var(--line);
  background: var(--card);
}

#sample:hover { background: var(--field); }

#clear { color: var(--red-ink); }

button:active { transform: scale(0.98); }

.file { display: inline-flex; align-items: center; cursor: pointer; }

.file input {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.file:focus-within {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
}

.banner {
  margin: 18px 0 0;
  padding: 12px 14px;
  border-radius: 12px;
  background: var(--amber-wash);
  color: var(--amber);
  line-height: 1.5;
}

.banner p { margin: 0 0 10px; }

.banner.warn {
  background: var(--crit-wash);
  color: var(--red-ink);
}

.status {
  min-height: 0;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.status:empty { display: none; }

.layout {
  display: grid;
  gap: 0;
  margin-top: 22px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: rise 520ms var(--ease) both;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

section {
  background: transparent;
  border: 0;
  border-radius: 0;
  border-top: 1px solid var(--line);
  padding: 26px 28px 30px;
  min-width: 0;
}

h2 {
  margin: 0 0 16px;
  font-family: Newsreader, Georgia, serif;
  font-size: clamp(1.55rem, 2vw, 1.85rem);
  font-weight: 500;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.section-head h2 { margin: 0; }

.section-head p, #alloc-pool, #expense-total {
  margin: 0;
  color: var(--ink);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.runway, .books { border-top: 0; }

@media (max-width: 859px) {
  .books { border-top: 1px solid var(--line); }
}

.runway { display: flex; flex-direction: column; }

.kicker {
  margin: 0 0 14px;
  font-variant: small-caps;
  letter-spacing: 0.14em;
  font-size: 0.84rem;
  font-weight: 500;
  color: var(--muted);
}

.figure {
  margin: 0;
  font-family: Newsreader, Georgia, serif;
  font-weight: 600;
  font-size: clamp(4.6rem, 8vw, 7.2rem);
  line-height: 0.84;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums lining-nums;
  transition: color 220ms var(--ease);
}

.runway.empty .figure,
.runway.invalid .figure {
  font-size: clamp(2.6rem, 5vw, 3.5rem);
  font-weight: 500;
  letter-spacing: 0;
  line-height: 1;
  color: color-mix(in srgb, var(--muted) 72%, var(--line));
}

.figure span:last-child {
  position: relative;
  top: -0.08em;
  font-family: "IBM Plex Sans", "Segoe UI", sans-serif;
  font-size: 0.26em;
  letter-spacing: 0;
  font-weight: 500;
  color: var(--muted);
}

.runway.healthy .figure { color: var(--green); }
.runway.watch .figure { color: var(--amber); }
.runway.critical .figure { color: var(--red); }
.runway.open .figure { color: var(--open); }

#runway-detail {
  margin: 16px 0 0;
  max-width: 36ch;
  line-height: 1.5;
  font-size: 1.05rem;
}

.band {
  display: inline-block;
  align-self: flex-start;
  margin: 16px 0 0;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.88rem;
  font-weight: 500;
}

.band.healthy { background: var(--green-wash); color: var(--green); }
.band.watch { background: var(--amber-wash); color: var(--amber); }
.band.critical { background: var(--crit-wash); color: var(--red-ink); }
.band.open { background: var(--open-wash); color: var(--open); }

.hint, .fine {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.hint { margin: auto 0 0; padding-top: 28px; max-width: 38ch; }

.field { display: grid; gap: 6px; min-width: 0; }

.field label, .choice legend, .field > span, .colhead {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

input[type="text"] {
  width: 100%;
  min-height: 44px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
  transition: border-color 200ms var(--ease), background-color 200ms var(--ease);
}

input[type="text"]:hover { border-color: color-mix(in srgb, var(--ink) 28%, var(--line)); }

::placeholder { color: var(--muted); opacity: 1; }

input[readonly] {
  background: var(--readonly);
  color: var(--ink);
}

input.bad { border-color: var(--red); }
input.bad:focus-visible { outline-color: var(--red); }

#fresh { color: inherit; border-color: currentColor; }

.err {
  min-height: 1.2em;
  margin: 6px 0 0;
  color: var(--red-ink);
  font-size: 0.85rem;
}

.err:empty { min-height: 0; margin: 0; }

.hint-inline {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.choice {
  display: flex;
  flex-wrap: wrap;
  align-items: stretch;
  gap: 8px 0;
  border: 0;
  margin: 16px 0;
  padding: 0;
}

.choice legend {
  flex: 1 0 100%;
  padding: 0;
  margin-bottom: 2px;
}

.choice label {
  position: relative;
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 6px 14px;
  border: 1px solid var(--line);
  background: var(--field);
  color: var(--ink);
  font-size: 0.95rem;
  transition: background-color 200ms var(--ease), color 200ms var(--ease), border-color 200ms var(--ease);
}

.choice label:first-of-type { border-radius: 9px 0 0 9px; }
.choice label:last-of-type { border-radius: 0 9px 9px 0; margin-left: -1px; }

.choice label:hover { background: color-mix(in srgb, var(--ink) 5%, var(--field)); }

.choice label:has(input:checked) {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
  z-index: 1;
}

.choice label:has(input:checked):hover { background: var(--ink); }

.choice input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.choice input:focus-visible,
.file input:focus-visible { outline: none; }

.choice label:focus-within {
  outline: 2px solid var(--ink);
  outline-offset: 3px;
  z-index: 1;
}

.stack { display: grid; gap: 12px; }

#raise-gap, #alloc-summary {
  margin: 14px 0 0;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

.meter {
  height: 10px;
  margin-top: 14px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.meter.idle { display: none; }

.meter span, .fill {
  display: block;
  height: 100%;
  width: 100%;
  background: var(--ink);
  border-radius: 99px;
  transform: scaleX(0);
  transform-origin: left center;
  transition: transform 240ms var(--ease);
}

.meter.met span { background: var(--green); }

.rows {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  gap: 0;
}

.colhead {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(7rem, 0.7fr) auto;
  gap: 8px;
  align-items: end;
  padding: 0 0 6px;
}

.rows.alloc .colhead {
  grid-template-columns: minmax(0, 1.3fr) 6.5rem minmax(5.5rem, 0.6fr) auto;
}

.rows.alloc .colhead span:nth-child(3) { text-align: right; }

.rows li:not(.empty-row):not(.colhead) {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(7rem, 0.7fr) auto;
  grid-template-areas: "name amt remove";
  gap: 8px;
  align-items: end;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.rows.alloc li:not(.empty-row):not(.colhead) {
  grid-template-columns: minmax(0, 1.3fr) 6.5rem minmax(5.5rem, 0.6fr) auto;
  grid-template-areas:
    "name amt share remove"
    "bar bar bar bar";
}

.rows .name-field { grid-area: name; }
.rows .amt-field { grid-area: amt; }
.rows .remove { grid-area: remove; }

@media (min-width: 641px) {
  .rows .field > span {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
  }
}

.share {
  grid-area: share;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  font-weight: 500;
}

.bar {
  grid-area: bar;
  height: 8px;
  margin-top: 2px;
  border-radius: 99px;
  background: var(--line);
  overflow: hidden;
}

.empty-row {
  color: var(--muted);
  line-height: 1.5;
  margin: 0 0 4px;
  padding: 14px 16px;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: color-mix(in srgb, var(--bg) 55%, var(--card));
}

.add {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(7rem, 0.7fr) auto;
  gap: 8px;
  align-items: end;
}

button.primary {
  min-height: 44px;
  padding: 8px 16px;
  border: 0;
  border-radius: 8px;
  background: var(--ink);
  color: var(--bg);
  font-weight: 500;
  transition: background-color 200ms var(--ease), transform 200ms var(--ease);
}

button.primary:hover { background: color-mix(in srgb, var(--ink) 86%, var(--bg)); }

button.primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.fine { margin: 18px 4px 0; max-width: 62ch; }

dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--card);
  color: var(--ink);
  padding: 24px;
  max-width: min(440px, calc(100vw - 32px));
  box-shadow: var(--shadow);
}

dialog::backdrop { background: rgba(28, 22, 18, 0.46); }

dialog p { margin: 0; line-height: 1.5; }

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

.noscript {
  margin: 16px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}

body.blocked .layout,
body.blocked .tools,
body.blocked #sample-banner { display: none; }

@media (min-width: 860px) {
  .layout { grid-template-columns: 1.35fr 0.85fr; align-items: stretch; }
  .runway { grid-column: 1; grid-row: 1; }
  .books { grid-column: 2; grid-row: 1; border-left: 1px solid var(--line); }
  .raise .stack { grid-template-columns: 1.1fr 1fr 1fr; align-items: start; }
  .expenses, .allocation, .raise { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .wrap { padding: 22px 16px max(48px, env(safe-area-inset-bottom)); }
  section { padding: 20px 16px 22px; }
  .tools { width: 100%; display: grid; grid-template-columns: 1fr 1fr; }
  .tools button, .file {
    justify-content: center;
    border-color: var(--line);
    background: var(--card);
  }
  .rows li:not(.empty-row):not(.colhead),
  .rows.alloc li:not(.empty-row):not(.colhead),
  .add {
    grid-template-columns: minmax(0, 1fr) auto;
    grid-template-areas:
      "name remove"
      "amt amt"
      "share share"
      "bar bar";
  }
  .colhead { display: none; }
  .add { grid-template-areas: "name name" "amt amt" "submit submit"; }
  .add .name-field { grid-area: name; }
  .add .amt-field { grid-area: amt; }
  .add .primary { grid-area: submit; width: 100%; }
  .share { justify-content: flex-start; min-height: 0; padding-top: 2px; }
  .dialog-actions { flex-direction: column-reverse; }
  .dialog-actions button { width: 100%; }
}

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