:root {
  color-scheme: light;
  --ink: #17202a;
  --muted: #617083;
  --page: #f5f7fa;
  --card: #ffffff;
  --line: #dbe3ec;
  --blue: #e8f2ff;
  --blue-strong: #1f6fd1;
  --green: #e8f8ef;
  --green-strong: #167349;
  --orange: #fff2dd;
  --red: #ffe7e4;
  --shadow: 0 16px 36px rgba(26, 36, 52, 0.1);
}

* { box-sizing: border-box; }
main, .section, .card, .result-card, .scenario-grid { min-width: 0; }

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

html { scroll-behavior: smooth; overflow-x: hidden; }

body {
  margin: 0;
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--page);
  color: var(--ink);
  overflow-x: hidden;
}

button, input { font: inherit; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  width: min(440px, 100%);
  margin: 0 auto;
  padding: 9px 22px 9px 14px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.96), rgba(245, 247, 250, 0.94)),
    radial-gradient(circle at 86% 50%, rgba(22, 115, 73, 0.1), transparent 35%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
  overflow: hidden;
}

h1, h2, h3, p { margin: 0; }
summary { list-style: none; }
summary::-webkit-details-marker { display: none; }

h1 {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: 0;
  min-width: 0;
  width: auto;
  justify-self: start;
  font-size: clamp(1.7rem, 7vw, 2.8rem);
  line-height: 0.84;
  text-align: left;
  white-space: nowrap;
  font-family: "Bebas Neue", "Inter", ui-sans-serif, system-ui, sans-serif;
  letter-spacing: 0.025em;
  animation: titleRise 260ms ease-out both;
}

h1 span {
  display: block;
  max-width: max-content;
  overflow: hidden;
  white-space: nowrap;
  border-right: 2px solid rgba(23, 32, 42, 0.72);
}

h1 span:first-child {
  color: #101820;
  font-weight: 900;
  animation:
    titleType 620ms steps(12, end) 130ms both,
    cursorBlink 620ms step-end 130ms 2 forwards,
    cursorOff 1ms linear 1450ms forwards;
}

h1 span:last-child:not(:first-child) {
  color: #526170;
  font-weight: 900;
  animation:
    titleType 520ms steps(10, end) 760ms both,
    cursorBlink 620ms step-end 760ms 2 forwards,
    cursorOff 1ms linear 1980ms forwards;
}

h1 span + span::before {
  content: "";
  margin: 0;
}
h2 { font-size: 1.12rem; line-height: 1.15; }
h3 { font-size: 0.95rem; }

.subtitle, .summary-card p, .info-section p {
  color: var(--muted);
  line-height: 1.42;
}

.eyebrow {
  color: var(--blue-strong);
  font-size: 0.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
  margin-bottom: 6px;
}

.top-nav {
  display: grid;
  grid-template-columns: repeat(3, auto);
  gap: 4px;
  flex-shrink: 0;
}

.top-nav a {
  color: var(--ink);
  text-decoration: none;
  font-size: 0.78rem;
  font-weight: 700;
  padding: 6px 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  min-width: 34px;
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

main {
  width: min(440px, 100%);
  margin: 0 auto;
  padding: 10px;
}

.section {
  display: grid;
  gap: 10px;
  padding: 10px 0;
  scroll-margin-top: 58px;
}

.summary-card {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
}

.summary-card summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 30px;
  cursor: pointer;
}

.summary-card summary .eyebrow { margin-bottom: 0; }

.summary-card summary i {
  transition: transform 160ms ease;
}

.summary-card[open] summary i {
  transform: rotate(180deg);
}

.button-row { display: flex; gap: 8px; flex-wrap: wrap; }

.primary-button, .secondary-button, .icon-button, .help-button, .reset-button, .chevron-button {
  border: 0;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 38px;
  border-radius: 8px;
  font-weight: 800;
}

.primary-button {
  width: fit-content;
  color: #fff;
  background: var(--blue-strong);
  padding: 0 12px;
  text-decoration: none;
}

.secondary-button {
  color: var(--ink);
  background: #edf1f6;
  padding: 0 12px;
}

.compact-button {
  min-height: 38px;
  font-size: 0.82rem;
}

.icon-button, .help-button {
  width: 38px;
  color: #7a8491;
  background: #fff;
  border: 1px solid rgba(219, 227, 236, 0.78);
  border-radius: 999px;
  box-shadow: 0 6px 14px rgba(23, 32, 42, 0.12);
  flex-shrink: 0;
}

.help-button:hover {
  color: #4f5b68;
  background: #fff;
}

.help-button i {
  width: 20px;
  height: 20px;
}

.chevron-button {
  width: 38px;
  color: var(--ink);
  background: transparent;
  flex-shrink: 0;
}

.chevron-button i {
  transition: transform 160ms ease;
}

.chevron-button.collapsed i {
  transform: rotate(180deg);
}

.reset-button {
  color: var(--ink);
  background: #edf1f6;
  padding: 0 10px;
  font-size: 0.84rem;
  flex-shrink: 0;
}

i[data-lucide] {
  width: 19px;
  height: 19px;
  stroke-width: 2.3;
}

.section-title-row, .card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-logo {
  display: block;
  flex-shrink: 0;
  width: clamp(106px, 27vw, 150px);
  height: auto;
  max-height: 82px;
  object-fit: contain;
  filter: drop-shadow(0 7px 11px rgba(23, 32, 42, 0.14));
}

.card, .result-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 8px 20px rgba(26, 36, 52, 0.06);
}

.primary-result {
  position: sticky;
  top: 47px;
  z-index: 5;
  background: var(--green);
  border-color: #bfe8d0;
  box-shadow: 0 12px 28px rgba(22, 115, 73, 0.12);
}

.pill {
  display: flex;
  justify-content: center;
  width: 100%;
  margin-left: 0;
  padding: 0;
  border-radius: 0;
  font-size: 0.75rem;
  font-weight: 400;
  margin-top: 4px;
  white-space: nowrap;
}

.pill.good { color: var(--muted); background: transparent; }
.pill.warn { color: #965900; background: var(--orange); }
.pill.danger { color: #a12a1d; background: var(--red); }

.pay-line {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 12px;
}

.monthly-result { min-width: 0; }

.monthly-result p, .metric span, label span, .scenario-card span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 700;
}

.monthly-result strong {
  display: block;
  margin-top: 3px;
  color: var(--green-strong);
  font-size: clamp(1.55rem, 9vw, 2.3rem);
  line-height: 1;
}

.annual-result {
  color: var(--muted);
  font-size: 0.9rem;
  white-space: nowrap;
  padding-bottom: 4px;
}

.annual-result strong {
  color: var(--green-strong);
  font-size: 1rem;
}

.input-card { background: #fbfdff; }

.settings-divider {
  height: 1px;
  margin: 14px 0 12px;
  background: var(--line);
}

.nested-heading h3 {
  color: var(--blue-strong);
  font-size: 0.9rem;
}

.pay-settings-card summary {
  cursor: pointer;
}

.pay-settings-card summary > .heading-actions > i {
  transition: transform 160ms ease;
}

.pay-settings-card[open] summary > .heading-actions > i {
  transform: rotate(180deg);
}

label {
  display: grid;
  grid-template-columns: minmax(144px, 1.08fr) minmax(0, 0.92fr);
  gap: 9px;
  align-items: center;
  margin-top: 9px;
}

label input { grid-column: 1; grid-row: 1; }
label .rate-stepper { grid-column: 1; grid-row: 1; }
label .spend-inputs { grid-column: 1; grid-row: 1; }
label span { grid-column: 2; grid-row: 1; }

label span small {
  display: block;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
  line-height: 1.15;
}

input {
  width: 100%;
  min-height: 42px;
  border: 1px solid #b9d6f5;
  border-radius: 8px;
  background: var(--blue);
  color: var(--ink);
  padding: 9px 10px;
  font-size: 0.98rem;
  font-weight: 800;
}

input:focus {
  outline: 3px solid rgba(31, 111, 209, 0.22);
  border-color: var(--blue-strong);
}

.rate-stepper {
  display: grid;
  grid-template-columns: 30px minmax(52px, 1fr) 16px 30px;
  align-items: center;
  gap: 4px;
  min-width: 0;
}

.rate-stepper input {
  grid-column: 2;
  grid-row: 1;
  min-height: 42px;
  text-align: center;
  padding: 8px 6px;
}

.rate-suffix {
  grid-column: 3;
  grid-row: 1;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.step-button {
  width: 30px;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: #edf1f6;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.spend-inputs {
  display: grid;
  grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
  gap: 6px;
  min-width: 0;
}

.spend-field {
  display: block;
  align-items: center;
  min-width: 0;
  border: 1px solid #cfd8e3;
  border-radius: 8px;
  background: #eef2f6;
  padding-left: 0;
}

.spend-field input {
  min-height: 40px;
  border: 0;
  background: transparent;
  padding: 8px 8px;
  width: 100%;
  min-width: 0;
}

.spend-field.active {
  border-color: #b9d6f5;
  background: var(--blue);
}

.spend-field.active small {
  color: var(--blue-strong);
}

.spend-field.calculated {
  color: var(--muted);
}

.spend-field.calculated input {
  color: #6d7d8d;
  font-weight: 700;
}

.breakdown-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: 1fr;
}

.breakdown-details {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.breakdown-details summary {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  min-height: 38px;
  padding: 0 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.62);
  color: var(--green-strong);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 900;
}

.breakdown-details summary i {
  transition: transform 160ms ease;
}

.breakdown-details[open] summary i {
  transform: rotate(180deg);
}

.breakdown-details .breakdown-grid {
  margin-top: 8px;
}

.metric {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
  padding: 10px;
  border-radius: 8px;
  background: var(--green);
  border: 1px solid #c7ecd7;
}

.metric strong {
  color: #101820;
  font-size: 0.98rem;
  text-align: right;
}

.metric strong.empty-value {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
}

.ladder-list {
  display: grid;
  gap: 5px;
  margin-top: 6px;
}

.ladder-column-labels {
  display: grid;
  grid-template-columns: 1fr minmax(86px, 0.42fr);
  gap: 8px;
  margin-top: 10px;
  padding: 0 7px;
}

.ladder-column-labels span {
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
  line-height: 1.15;
}

.ladder-column-labels span:last-child {
  text-align: center;
}

.ladder-list.collapsed {
  max-height: none;
  overflow-y: hidden;
  padding-right: 2px;
}

.ladder-list.collapsed .ladder-row {
  display: none;
}

.ladder-list.collapsed .ladder-row.selected {
  display: grid;
}

.heading-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.ladder-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) minmax(76px, 0.35fr);
  gap: 6px;
  align-items: center;
  padding: 5px;
  border: 1px solid transparent;
  border-radius: 8px;
  scroll-snap-align: center;
}

.ladder-row.selected {
  border-color: #526170;
  background: #f4f6f8;
  box-shadow: inset 0 0 0 1px rgba(82, 97, 112, 0.14);
}

.ladder-choice {
  display: flex;
  align-items: center;
  min-height: 32px;
  border-radius: 8px;
  background: #edf1f6;
  color: var(--ink);
  padding: 6px 8px;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.15;
}

.ladder-row.selected .ladder-choice {
  background: #e8edf2;
  color: #263442;
}

.set-benchmark-button {
  min-height: 32px;
  border: 0;
  border-radius: 8px;
  background: #edf1f6;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

.ladder-row.selected .set-benchmark-button {
  background: #526170;
  color: #fff;
}

.set-benchmark-button.checked {
  cursor: default;
}

.set-benchmark-button.checked i {
  width: 17px;
  height: 17px;
}

.ladder-row input {
  min-height: 34px;
  padding: 6px 8px;
  text-align: right;
}

.ladder-row.boost input {
  color: var(--green-strong);
  border-color: #bfe8d0;
  background: #edf9f2;
}

.ladder-row.trim input {
  color: #a94b43;
  border-color: #f2c8c4;
  background: #fff1ef;
}

.ladder-row.selected input {
  color: #263442;
  border-color: #526170;
  background: #fff;
}

.scenario-wrap {
  position: relative;
  margin-top: 8px;
}

.scenario-grid {
  display: flex;
  gap: 8px;
  margin: 0;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0 calc((100% - min(82%, 270px)) / 2) 2px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  width: 100%;
  max-width: 100%;
}

.scenario-grid::-webkit-scrollbar {
  display: none;
}

.primary-result .pill {
  width: auto;
  font-size: 0.68rem;
  white-space: nowrap;
}

.scenario-tools {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  margin-top: 7px;
}

.center-current-button {
  min-height: 28px;
  border: 0;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  color: var(--green-strong);
  cursor: pointer;
  padding: 0 8px;
  font-size: 0.72rem;
  font-weight: 900;
  white-space: nowrap;
}

.center-current-button.icon-only-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  border-radius: 999px;
  background: #fff;
  color: #7a8491;
  border: 1px solid rgba(219, 227, 236, 0.78);
  box-shadow: 0 6px 14px rgba(23, 32, 42, 0.12);
}

.center-current-button.icon-only-button i {
  width: 19px;
  height: 19px;
}

.scenario-nav {
  position: absolute;
  top: 50%;
  z-index: 3;
  width: 30px;
  height: 42px;
  transform: translateY(-50%);
  border: 0;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  color: #526170;
  box-shadow: 0 6px 14px rgba(23, 32, 42, 0.13);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.scenario-nav.left { left: 4px; }
.scenario-nav.right { right: 4px; }

.scenario-nav i {
  width: 18px;
  height: 18px;
}

.scenario-card {
  flex: 0 0 82%;
  max-width: 270px;
  display: grid;
  gap: 5px;
  padding: 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #f4f6f8;
  scroll-snap-align: center;
  opacity: 0.64;
}

.scenario-card.selected {
  border-color: var(--green-strong);
  background: linear-gradient(180deg, #ecfbf2, #e2f7eb);
  box-shadow: inset 0 0 0 2px rgba(22, 115, 73, 0.2), 0 10px 20px rgba(22, 115, 73, 0.12);
  opacity: 1;
  animation: selectedPayPulse 900ms ease-out both;
}

.scenario-card .pay-amount {
  display: block;
  color: var(--green-strong);
  font-size: 1.72rem;
  line-height: 1.05;
  letter-spacing: 0;
}

.scenario-card.muted-scenario .pay-amount {
  color: #5f6f7f;
  font-size: 1.38rem;
}

.scenario-card .scenario-kicker,
.scenario-card .year-note {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 400;
}

.scenario-card .sales-amount {
  color: #536677;
  font-size: 0.94rem;
  font-weight: 800;
  margin-top: 4px;
}

.scenario-card.selected .sales-amount {
  color: #415767;
  font-size: 0.96rem;
}

.scenario-card .sales-year {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 400;
}

.info-section .card {
  display: grid;
  gap: 10px;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: 16px;
  display: none;
  padding: 12px 14px;
  border-radius: 8px;
  background: #17202a;
  color: #fff;
  font-weight: 800;
  box-shadow: var(--shadow);
  z-index: 30;
}

.toast.show { display: block; }

.help-popover {
  position: fixed;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 40;
  display: none;
  padding: 13px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 0.94rem;
  font-weight: 400;
  line-height: 1.45;
}

.help-popover.show { display: block; }

.confirm-popover {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(16, 24, 32, 0.32);
}

.confirm-popover.show { display: flex; }

.confirm-card {
  width: min(330px, 100%);
  display: grid;
  gap: 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 16px;
}

.confirm-card h2 {
  font-size: 1.05rem;
}

.confirm-card p {
  color: var(--muted);
  line-height: 1.4;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@keyframes titleRise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes titleType {
  from { width: 0; }
  to { width: 100%; }
}

@keyframes cursorBlink {
  0%, 100% { border-color: rgba(23, 32, 42, 0.72); }
  50% { border-color: transparent; }
}

@keyframes cursorOff {
  to { border-color: transparent; }
}

@keyframes logoPop {
  from {
    opacity: 0;
    transform: translateX(18px) scale(0.9) rotate(3deg);
    filter: drop-shadow(0 0 0 rgba(23, 32, 42, 0));
  }
  65% {
    opacity: 1;
    transform: translateX(0) scale(1.04) rotate(-1deg);
  }
  to {
    opacity: 1;
    transform: translateX(0) scale(1) rotate(0);
    filter: drop-shadow(0 7px 11px rgba(23, 32, 42, 0.14));
  }
}

@keyframes selectedPayPulse {
  0% {
    box-shadow: inset 0 0 0 2px rgba(22, 115, 73, 0.08), 0 0 0 rgba(22, 115, 73, 0);
  }
  45% {
    box-shadow: inset 0 0 0 2px rgba(22, 115, 73, 0.24), 0 0 0 6px rgba(22, 115, 73, 0.08);
  }
  100% {
    box-shadow: inset 0 0 0 2px rgba(22, 115, 73, 0.2), 0 10px 20px rgba(22, 115, 73, 0.12);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

@media (min-width: 700px) {
  .app-header { padding: 10px 22px 10px 14px; }
  main { padding: 14px; }
  .scenario-card { flex-basis: 220px; }
}

@media (max-width: 420px) {
  .app-header {
    align-items: center;
    gap: 8px;
  }

  h1 { font-size: clamp(1.55rem, 7vw, 1.95rem); }
  .brand-logo { width: clamp(94px, 27vw, 112px); }

  .top-nav a { text-align: center; }
  .primary-result { top: 47px; }
}
