:root {
  --ink: #172326;
  --muted: #5f6c70;
  --line: #d8e0dc;
  --paper: #fbfcf8;
  --panel: #ffffff;
  --green: #184f52;
  --green-dark: #0d3140;
  --saffron: #d96941;
  --gold: #f2c16b;
  --blue: #236192;
  --danger: #9c2f2f;
  --shadow: 0 24px 70px rgba(23, 35, 38, 0.12);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-width: 320px;
  background:
    linear-gradient(180deg, rgba(217, 105, 65, 0.08), transparent 340px),
    #f5f7f3;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

a {
  color: var(--blue);
}

button,
input,
select {
  font: inherit;
}

.app-header,
.layout,
.rule-strip,
.sources {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  align-items: center;
  gap: 28px;
  padding: 34px 0 24px;
}

.header-copy {
  max-width: 760px;
}

.header-art {
  width: 180px;
  height: auto;
  border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(13, 49, 64, 0.12);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--saffron);
  font-size: 0.76rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  max-width: 820px;
  margin-bottom: 14px;
  font-size: clamp(2rem, 4vw, 4rem);
  line-height: 1.02;
  letter-spacing: 0;
}

.intro {
  max-width: 720px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.06rem;
  line-height: 1.65;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1.22fr) minmax(340px, 0.78fr);
  gap: 22px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.input-panel,
.result-panel {
  padding: 24px;
}

.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 20px;
}

.section-heading.narrow {
  margin-bottom: 16px;
}

.section-heading h2,
.formula-box h2,
.sources h2 {
  margin-bottom: 0;
  font-size: 1.15rem;
  line-height: 1.25;
}

.icon-button,
.print-button {
  min-height: 42px;
  border: 1px solid var(--green);
  background: var(--green);
  color: #fff;
  cursor: pointer;
  font-weight: 800;
}

.icon-button {
  min-width: 82px;
  padding: 0 16px;
}

.print-button {
  width: 100%;
  margin-top: 18px;
  padding: 0 18px;
}

.icon-button:hover,
.print-button:hover {
  background: var(--green-dark);
}

form {
  display: grid;
  gap: 18px;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 10px;
  font-weight: 850;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 5px;
  background: #edf2ee;
  border: 1px solid var(--line);
}

.segmented label {
  position: relative;
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  min-height: 42px;
  place-items: center;
  padding: 8px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
  text-align: center;
  cursor: pointer;
}

.segmented input:checked + span {
  background: var(--green);
  color: #fff;
}

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

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.field,
.switch {
  display: grid;
  gap: 7px;
}

.field span,
.switch span {
  color: #314144;
  font-size: 0.9rem;
  font-weight: 760;
}

.field input,
.field select {
  width: 100%;
  min-height: 44px;
  border: 1px solid #c9d4cf;
  background: var(--paper);
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

.field input:focus,
.field select:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(35, 97, 146, 0.14);
}

.switch-row {
  margin-top: 12px;
}

.switch {
  grid-template-columns: 20px minmax(0, 1fr);
  align-items: center;
}

.switch input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.advanced {
  margin-top: 12px;
  border-top: 1px solid var(--line);
  padding-top: 12px;
}

.advanced summary {
  color: var(--blue);
  cursor: pointer;
  font-weight: 800;
}

.nested-fields,
.nested-field {
  margin-top: 12px;
}

.is-hidden {
  display: none;
}

.result-panel {
  position: sticky;
  top: 16px;
  background: linear-gradient(180deg, #ffffff, #f7faf7);
}

.amount {
  display: block;
  min-height: 72px;
  margin: 2px 0 8px;
  color: var(--green-dark);
  font-size: clamp(2.2rem, 5vw, 3.6rem);
  font-weight: 900;
  line-height: 1;
  overflow-wrap: anywhere;
}

.result-subtitle {
  margin-bottom: 18px;
  color: var(--muted);
  line-height: 1.5;
}

.result-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin: 0;
}

.result-grid div {
  min-height: 78px;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.result-grid dt {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.result-grid dd {
  margin: 0;
  color: var(--ink);
  font-weight: 850;
  overflow-wrap: anywhere;
}

.formula-box {
  margin-top: 16px;
  padding: 15px;
  border-left: 4px solid var(--gold);
  background: #fff8e7;
}

.formula-box p {
  margin: 8px 0 0;
  color: #4d4537;
  line-height: 1.55;
}

.warnings {
  display: grid;
  gap: 8px;
  margin: 14px 0 0;
  padding: 0;
  list-style: none;
}

.warnings li {
  padding: 10px 12px;
  border: 1px solid rgba(156, 47, 47, 0.22);
  background: rgba(156, 47, 47, 0.07);
  color: #6f2424;
  font-size: 0.9rem;
  line-height: 1.45;
}

.rule-strip {
  padding: 30px 0 18px;
}

.rule-list {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.rule-list article {
  min-height: 170px;
  padding: 18px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.rule-list h3 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.rule-list p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.93rem;
  line-height: 1.55;
}

.sources {
  margin-bottom: 36px;
  padding: 22px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.sources ul {
  display: grid;
  gap: 8px;
  margin: 14px 0;
  padding-left: 20px;
}

.sources li {
  line-height: 1.45;
}

.disclaimer {
  margin: 16px 0 0;
  color: var(--muted);
  font-size: 0.94rem;
  line-height: 1.6;
}

@media (max-width: 980px) {
  .app-header,
  .layout {
    grid-template-columns: 1fr;
  }

  .header-art {
    width: 150px;
  }

  .result-panel {
    position: static;
  }

  .rule-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 680px) {
  .app-header,
  .layout,
  .rule-strip,
  .sources {
    width: min(100% - 22px, 1180px);
  }

  .app-header {
    padding-top: 22px;
  }

  .header-art {
    width: 128px;
  }

  .input-panel,
  .result-panel,
  .sources {
    padding: 16px;
  }

  .section-heading {
    display: grid;
  }

  .icon-button {
    width: 100%;
  }

  .field-grid.two,
  .field-grid.three,
  .result-grid,
  .rule-list {
    grid-template-columns: 1fr;
  }

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

  .amount {
    min-height: auto;
  }
}

@media print {
  body {
    background: #fff;
  }

  .app-header,
  .input-panel,
  .rule-strip,
  .sources,
  .print-button {
    display: none;
  }

  .layout {
    width: 100%;
    display: block;
  }

  .result-panel {
    box-shadow: none;
    border: 0;
  }
}
