:root {
  color-scheme: light;
  --page: #f4f6fb;
  --surface: #ffffff;
  --surface-soft: #f7f8fc;
  --text: #172033;
  --muted: #667085;
  --line: #dfe3eb;
  --line-strong: #c9d0dc;
  --primary: #2854c5;
  --primary-dark: #1d3f99;
  --primary-soft: #eaf0ff;
  --positive: #18794e;
  --negative: #b42318;
  --shadow: 0 18px 50px rgba(22, 32, 51, 0.09);
  --radius-lg: 22px;
  --radius-md: 14px;
  --radius-sm: 10px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--page);
  scroll-behavior: smooth;
}

body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 10% 4%, rgba(40, 84, 197, 0.08), transparent 28rem),
    var(--page);
  line-height: 1.55;
}

button,
input,
select {
  font: inherit;
}

button,
a,
input,
select {
  -webkit-tap-highlight-color: transparent;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(223, 227, 235, 0.9);
  background: rgba(244, 246, 251, 0.9);
  backdrop-filter: blur(14px);
}

.header-inner {
  width: min(1180px, calc(100% - 40px));
  min-height: 68px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.github-button,
.button {
  min-height: 42px;
  border-radius: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 15px;
  border: 1px solid transparent;
  text-decoration: none;
  font-weight: 700;
  transition: transform 140ms ease, border-color 140ms ease, background 140ms ease;
}

.github-button {
  color: var(--text);
  background: var(--surface);
  border-color: var(--line);
}

.github-button svg {
  width: 19px;
  height: 19px;
}

.github-button:hover,
.button:hover,
.add-person-button:hover {
  transform: translateY(-1px);
}

.hero {
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  padding: 52px 0 64px;
}

.hero-copy {
  max-width: 790px;
  margin-bottom: 28px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 12px;
  font-size: clamp(2rem, 4.5vw, 3.5rem);
  line-height: 1.08;
  letter-spacing: -0.045em;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.35rem, 2vw, 1.8rem);
  line-height: 1.2;
  letter-spacing: -0.025em;
}

h3 {
  margin-bottom: 0;
  font-size: 1rem;
}

.hero-copy p,
.content-section p,
.comparison-block p {
  color: var(--muted);
}

.hero-copy p {
  max-width: 720px;
  margin-bottom: 0;
  font-size: 1.05rem;
}

.calculator-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(390px, 0.95fr);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.input-panel,
.result-panel,
.shared-view {
  padding: clamp(22px, 3vw, 34px);
}

.input-panel {
  border-right: 1px solid var(--line);
}

.result-panel {
  background: var(--surface-soft);
}

.panel-heading,
.shared-heading,
.people-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.panel-heading {
  margin-bottom: 24px;
}

.eyebrow {
  margin-bottom: 5px;
  color: var(--primary);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.text-button {
  border: 0;
  padding: 4px;
  color: var(--muted);
  background: transparent;
  font-weight: 700;
}

.text-button:hover {
  color: var(--primary);
}

.field-grid {
  display: grid;
  gap: 14px;
}

.field-grid-main {
  grid-template-columns: minmax(0, 1.6fr) minmax(140px, 0.8fr);
}

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

.field > span,
.basis-fieldset legend {
  color: #344054;
  font-size: 0.86rem;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease;
}

input {
  padding: 0 13px;
}

select {
  padding: 0 36px 0 13px;
}

input:focus,
select:focus,
button:focus-visible,
a:focus-visible {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(40, 84, 197, 0.14);
  outline: none;
}

input[aria-invalid="true"] {
  border-color: var(--negative);
  box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.11);
}

.input-with-prefix {
  position: relative;
}

.input-with-prefix > span {
  position: absolute;
  inset: 0 auto 0 13px;
  display: flex;
  align-items: center;
  color: var(--muted);
  font-weight: 700;
  pointer-events: none;
}

.input-with-prefix input {
  padding-left: 36px;
}

.basis-fieldset {
  margin: 19px 0 24px;
  padding: 0;
  border: 0;
}

.basis-fieldset legend {
  margin-bottom: 8px;
}

.segmented-control {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 12px;
  background: #e9ecf3;
}

.segmented-control label {
  position: relative;
}

.segmented-control input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.segmented-control span {
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 750;
  cursor: pointer;
}

.segmented-control input:checked + span {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 2px 6px rgba(22, 32, 51, 0.08);
}

.segmented-control input:focus-visible + span {
  box-shadow: 0 0 0 3px rgba(40, 84, 197, 0.2);
}

.people-heading {
  align-items: baseline;
  margin-bottom: 10px;
}

.people-heading span {
  color: var(--muted);
  font-size: 0.78rem;
}

.participants-container {
  display: grid;
  gap: 10px;
}

.participant-row {
  display: grid;
  grid-template-columns: minmax(100px, 0.9fr) minmax(110px, 1.1fr) minmax(112px, 0.75fr) 34px;
  gap: 8px;
  align-items: end;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface-soft);
}

.participant-row .field > span {
  font-size: 0.74rem;
}

.remove-person-button {
  width: 34px;
  height: 46px;
  border: 0;
  border-radius: 9px;
  color: var(--muted);
  background: transparent;
  font-size: 1.35rem;
}

.remove-person-button:hover {
  color: var(--negative);
  background: #fff0ee;
}

.remove-person-button:disabled {
  opacity: 0.25;
  cursor: default;
}

.add-person-button {
  width: 100%;
  min-height: 44px;
  margin-top: 10px;
  border: 1px dashed #9fa9ba;
  border-radius: 11px;
  color: var(--primary);
  background: transparent;
  font-weight: 800;
}

.form-error,
.status-message {
  min-height: 1.35em;
  margin: 10px 0 0;
  font-size: 0.84rem;
}

.form-error {
  color: var(--negative);
}

.status-message {
  color: var(--positive);
}

.allocation-check {
  padding: 5px 9px;
  border-radius: 8px;
  color: var(--positive);
  background: #eaf8f0;
  font-size: 0.77rem;
  font-weight: 800;
  white-space: nowrap;
}

.burden-summary {
  margin-bottom: 14px;
  padding: 14px 16px;
  border: 1px solid #cad7fa;
  border-radius: var(--radius-md);
  background: var(--primary-soft);
}

.burden-summary strong {
  display: block;
  margin-bottom: 2px;
  font-size: 1.08rem;
}

.burden-summary span {
  color: #3c4c74;
  font-size: 0.84rem;
}

.result-cards {
  display: grid;
  gap: 10px;
}

.result-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.result-card-top,
.result-card-meta {
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.result-card-top {
  align-items: start;
}

.result-card-name {
  overflow: hidden;
  font-weight: 800;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-card-amount {
  font-size: clamp(1.35rem, 3vw, 1.8rem);
  font-weight: 850;
  letter-spacing: -0.035em;
  white-space: nowrap;
}

.result-card-meta {
  margin-top: 7px;
  color: var(--muted);
  font-size: 0.8rem;
}

.share-track {
  height: 6px;
  margin-top: 12px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eaf0;
}

.share-track span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.comparison-block {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  background: var(--surface);
}

.comparison-block p {
  margin: 3px 0 12px;
  font-size: 0.82rem;
}

.comparison-list {
  display: grid;
  gap: 7px;
}

.comparison-item {
  display: flex;
  justify-content: space-between;
  gap: 15px;
  color: #344054;
  font-size: 0.88rem;
}

.comparison-item strong.more {
  color: var(--negative);
}

.comparison-item strong.less {
  color: var(--positive);
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
  margin-top: 14px;
}

.button-primary {
  color: white;
  background: var(--primary);
}

.button-primary:hover {
  background: var(--primary-dark);
}

.button-secondary {
  color: var(--text);
  border-color: var(--line-strong);
  background: var(--surface);
}

.result-empty {
  padding: 18px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-md);
  color: var(--muted);
  text-align: center;
}

.shared-view {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.shared-summary {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  margin-top: 22px;
}

.shared-total {
  grid-column: 1 / -1;
  padding: 15px;
  border-radius: var(--radius-md);
  background: var(--primary-soft);
}

.content-section {
  padding: 74px 20px;
  background: var(--surface);
}

.muted-section {
  background: #eef1f7;
}

.content-grid {
  width: min(1000px, 100%);
  margin: 0 auto;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: clamp(30px, 6vw, 80px);
  align-items: start;
}

.content-section h2 {
  margin-bottom: 14px;
}

.formula-card {
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface-soft);
}

.formula-card h3 {
  margin-bottom: 10px;
}

.formula-card p:last-child,
.content-section article p:last-child {
  margin-bottom: 0;
}

footer {
  padding: 28px 20px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  background: var(--surface);
  text-align: center;
  font-size: 0.84rem;
}

[hidden] {
  display: none !important;
}

@media (max-width: 920px) {
  .calculator-shell {
    grid-template-columns: 1fr;
  }

  .input-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 640px) {
  .header-inner,
  .hero {
    width: min(100% - 28px, 1180px);
  }

  .header-inner {
    min-height: 62px;
  }

  .brand span {
    display: none;
  }

  .hero {
    padding: 36px 0 48px;
  }

  .hero-copy {
    margin-bottom: 20px;
  }

  .calculator-shell,
  .shared-view {
    border-radius: 17px;
  }

  .input-panel,
  .result-panel,
  .shared-view {
    padding: 20px 16px;
  }

  .field-grid-main {
    grid-template-columns: 1fr;
  }

  .participant-row {
    grid-template-columns: 1fr 1fr 34px;
  }

  .participant-row .name-field {
    grid-column: 1 / -2;
  }

  .participant-row .remove-person-button {
    grid-column: 3;
    grid-row: 1;
  }

  .participant-row .income-field {
    grid-column: 1 / 2;
  }

  .participant-row .period-field {
    grid-column: 2 / 4;
  }

  .people-heading span,
  .allocation-check {
    display: none;
  }

  .result-card-meta {
    display: grid;
    gap: 2px;
  }

  .action-row {
    grid-template-columns: 1fr;
  }

  .shared-heading {
    display: grid;
  }

  .content-section {
    padding: 54px 20px;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }
}

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

  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }
}
