:root {
  --ink: #183134;
  --muted: #617476;
  --primary: #087f78;
  --primary-dark: #05655f;
  --soft: #e9f7f5;
  --page: #f4f8f7;
  --surface: #fff;
  --line: #dce7e6;
  --danger: #a63232;
  --danger-soft: #fff1f1;
  --warning: #72540f;
  --warning-soft: #fff8e3;
  --good: #17724f;
  --good-soft: #eef9f3;
  --neutral: #496366;
  --shadow: 0 18px 50px rgba(20, 55, 55, 0.09);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

button,
input,
select {
  font: inherit;
}

button {
  touch-action: manipulation;
}

a {
  color: var(--primary-dark);
}

[hidden] {
  display: none !important;
}

.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;
}

.page-shell {
  width: min(1120px, calc(100% - 32px));
  margin: auto;
  padding: 48px 0 72px;
}

.hero {
  max-width: 850px;
  margin: 0 auto 32px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--primary);
  font-size: 0.76rem;
  font-weight: 850;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-size: clamp(2.1rem, 5.5vw, 3.5rem);
  line-height: 1.08;
  letter-spacing: -0.035em;
}

.subtitle {
  max-width: 760px;
  margin: 16px auto 0;
  color: #40595b;
  font-size: 1.08rem;
}

.hero-note {
  max-width: 720px;
  margin: 12px auto 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.panel,
.result-card,
.education {
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}

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

.steps-column {
  display: grid;
  gap: 18px;
}

.panel {
  padding: clamp(20px, 3vw, 28px);
}

.section-heading {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 18px;
}

.section-heading h2 {
  margin: 0;
  font-size: 1.25rem;
  line-height: 1.25;
}

.section-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.86rem;
}

.step {
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: var(--primary);
  color: #fff;
  font-size: 0.88rem;
  font-weight: 900;
}

.field-grid,
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.field {
  min-width: 0;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: #284346;
  font-size: 0.88rem;
  font-weight: 800;
}

.optional {
  color: var(--muted);
  font-weight: 600;
}

.field input {
  width: 100%;
  min-width: 0;
  min-height: 50px;
  padding: 11px 13px;
  border: 1px solid #bfcfcd;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
  outline: 0;
}

.field input:focus,
.button:focus-visible,
.text-button:focus-visible,
.profile-pill:focus-visible {
  border-color: var(--primary);
  outline: 3px solid rgba(8, 127, 120, 0.18);
  outline-offset: 2px;
}

.field input[aria-invalid="true"] {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.input-affix {
  overflow: hidden;
  border: 1px solid #bfcfcd;
  border-radius: 10px;
  display: flex;
  align-items: center;
  background: #fff;
  transition: border-color 0.16s, box-shadow 0.16s;
}

.input-affix:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 127, 120, 0.14);
}

.input-affix:has(input[aria-invalid="true"]) {
  border-color: var(--danger);
  background: var(--danger-soft);
}

.input-affix span {
  padding-left: 13px;
  color: #567073;
  font-weight: 800;
}

.input-affix.suffix span {
  padding: 0 13px 0 6px;
}

.input-affix input {
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none !important;
  outline: 0 !important;
}

.input-affix:not(.suffix) input {
  padding-left: 7px;
}

.helper,
.error {
  display: block;
  margin-top: 6px;
  font-size: 0.77rem;
  line-height: 1.45;
}

.helper {
  color: var(--muted);
}

.error {
  min-height: 1.1em;
  color: var(--danger);
  font-weight: 750;
}

/* Profiles Selector */
.profiles-group {
  margin-bottom: 16px;
}

.profiles-group label {
  display: block;
  margin-bottom: 8px;
  color: #284346;
  font-size: 0.85rem;
  font-weight: 800;
}

.profile-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.profile-pill {
  padding: 8px 12px;
  border: 1px solid #c2d4d2;
  border-radius: 9px;
  background: #fff;
  color: #315254;
  font-size: 0.8rem;
  font-weight: 750;
  cursor: pointer;
  transition: all 0.15s ease;
}

.profile-pill:hover {
  border-color: var(--primary);
  background: var(--soft);
  color: var(--primary-dark);
}

.profile-pill.active {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
  box-shadow: 0 2px 8px rgba(8, 127, 120, 0.25);
}

.profile-desc {
  margin: 8px 0 0;
  padding: 8px 12px;
  border-radius: 8px;
  background: #f7faf9;
  color: #496366;
  font-size: 0.78rem;
  line-height: 1.4;
}

.running-total {
  margin: 18px 0 0;
  padding: 13px 15px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 15px;
  background: var(--soft);
  color: #315254;
  font-size: 0.9rem;
}

.running-total strong {
  color: var(--primary-dark);
  font-size: 1rem;
}

.text-button {
  margin: 12px 0 0;
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--primary-dark);
  font-size: 0.85rem;
  font-weight: 850;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

.detailed-box {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f9fcfb;
}

.calculator-actions {
  padding: 4px 2px 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.calculator-actions p {
  flex: 1 0 100%;
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.button {
  min-height: 48px;
  padding: 11px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font-size: 0.88rem;
  font-weight: 850;
  cursor: pointer;
  transition: all 0.15s ease;
}

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

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

.button.secondary {
  border-color: #b9ccca;
  background: #fff;
  color: #365456;
}

.button.secondary:hover {
  background: var(--soft);
}

/* Result Card */
.result-card {
  position: sticky;
  top: 18px;
  padding: clamp(24px, 3vw, 34px);
  overflow: hidden;
}

.result-card::before {
  position: absolute;
  inset: 0 0 auto;
  height: 5px;
  background: var(--primary);
  content: "";
}

.result-card h2 {
  margin: 0;
  font-size: 1.35rem;
}

.main-result {
  display: block;
  margin: 12px 0 4px;
  color: var(--primary-dark);
  font-size: clamp(2.35rem, 5vw, 3.65rem);
  line-height: 1.05;
  letter-spacing: -0.045em;
  overflow-wrap: anywhere;
}

.effective-rate-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 4px 0 14px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--soft);
  color: var(--primary-dark);
  font-size: 0.82rem;
  font-weight: 800;
}

.result-status {
  min-height: 1.45em;
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.86rem;
}

.result-status.error-state {
  padding: 10px 12px;
  border-radius: 9px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 750;
}

.result-list {
  margin: 0;
  border-top: 1px solid var(--line);
}

.result-list div {
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 14px;
}

.result-list dt {
  color: var(--muted);
}

.result-list dd {
  margin: 0;
  color: var(--ink);
  font-weight: 850;
  text-align: right;
}

.credit-alert {
  margin: 16px 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--good-soft);
  border: 1px solid #b7dec9;
  color: var(--good);
  font-size: 0.8rem;
  line-height: 1.4;
}

.credit-alert.warning {
  background: var(--warning-soft);
  border-color: #ecd79b;
  color: var(--warning);
}

/* Composition / Credit Offset Bar */
.composition {
  margin-top: 18px;
}

.composition h3 {
  margin: 0 0 10px;
  font-size: 0.96rem;
}

.composition-bar {
  width: 100%;
  height: 24px;
  overflow: hidden;
  border-radius: 8px;
  display: flex;
  background: #edf2f1;
}

.composition-bar span {
  width: 0;
  min-width: 0;
  transition: width 0.25s ease;
}

.debit-segment {
  background: var(--primary);
}

.credit-segment {
  background: #25a176;
}

.composition-legend {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.composition-legend p {
  margin: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 3px 6px;
  color: var(--muted);
  font-size: 0.72rem;
}

.composition-legend strong {
  grid-column: 2;
  color: var(--ink);
  font-size: 0.85rem;
}

.legend-marker {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  grid-row: 1/3;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 0.6rem;
  font-weight: 900;
}

.debit-marker {
  background: var(--primary);
}

.credit-marker {
  background: #25a176;
}

/* Comparative Section */
.comparison-panel {
  margin-top: 22px;
  display: grid;
  grid-template-columns: 0.9fr 1.1fr;
  align-items: center;
  gap: 22px;
}

.comparison-copy h2 {
  margin: 0;
  font-size: 1.4rem;
}

.comparison-copy p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.comparison-result {
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #f8fbfa;
}

.comparison-result.good {
  border-color: #aad5c1;
  background: var(--good-soft);
}

.comparison-result.good .state-badge {
  background: #d7f1e3;
  color: var(--good);
}

.comparison-result.warning {
  border-color: #e3ce91;
  background: var(--warning-soft);
}

.comparison-result.warning .state-badge {
  background: #f7eabf;
  color: var(--warning);
}

.comparison-result.neutral {
  border-color: var(--line);
  background: #f8fbfa;
}

.state-badge {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 6px;
  background: #e9efee;
  color: var(--neutral);
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.comparison-result p.comparison-msg {
  margin: 8px 0 14px;
  color: #405d60;
  font-size: 0.85rem;
  line-height: 1.45;
}

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

.comparison-grid div {
  padding: 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.85);
  border: 1px solid rgba(220, 231, 230, 0.6);
}

.comparison-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
}

.comparison-grid dd {
  margin: 2px 0 0;
  font-size: 0.95rem;
  font-weight: 850;
}

/* Unit Price Section */
.unit-simulator {
  margin-top: 22px;
}

.unit-simulator h2 {
  margin: 0 0 6px;
  font-size: 1.35rem;
}

.unit-simulator p.unit-desc {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 0.86rem;
}

.unit-calc-box {
  padding: 20px;
  border: 1px solid #b7d8d4;
  border-radius: 14px;
  background: var(--soft);
  display: grid;
  grid-template-columns: 1fr 1.2fr;
  align-items: center;
  gap: 20px;
}

.unit-calc-box .field label {
  color: #315456;
}

.unit-result-summary strong {
  display: block;
  color: var(--primary-dark);
  font-size: 1.8rem;
  line-height: 1.1;
  margin: 4px 0;
}

.unit-result-summary p {
  margin: 0;
  color: #496568;
  font-size: 0.78rem;
}

/* Timeline / Transition Table */
.timeline-card {
  margin-top: 22px;
  padding: clamp(20px, 3vw, 28px);
  border: 1px solid var(--line);
  border-radius: 18px;
  background: #fff;
}

.timeline-card h2 {
  margin: 0 0 6px;
  font-size: 1.35rem;
}

.timeline-card p.timeline-desc {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.86rem;
}

.timeline-table-wrap {
  overflow-x: auto;
}

.timeline-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 0.85rem;
}

.timeline-table th,
.timeline-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
}

.timeline-table th {
  background: #f8fbfa;
  color: #315254;
  font-weight: 850;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.timeline-table tr:last-child td {
  border-bottom: 0;
}

.timeline-table .year-badge {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 6px;
  background: var(--soft);
  color: var(--primary-dark);
  font-weight: 850;
  font-size: 0.8rem;
}

/* Quick Guide */
.quick-guide {
  margin-top: 22px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.quick-guide article {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 13px;
  background: #fff;
}

.quick-guide h2 {
  margin: 0;
  font-size: 0.92rem;
  line-height: 1.3;
}

.quick-guide p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.77rem;
}

.ad-space {
  min-height: 120px;
  margin: 35px 0;
  overflow: hidden;
  display: grid;
  place-items: center;
}

.education {
  padding: clamp(24px, 5vw, 46px);
}

.education > h2 {
  margin: 30px 0 7px;
  font-size: 1.45rem;
}

.education > .eyebrow + h2 {
  margin-top: 0;
}

.education > p:not(.eyebrow) {
  max-width: 850px;
  color: #496366;
}

.related {
  margin-top: 35px;
  padding-top: 25px;
  border-top: 1px solid var(--line);
}

.related h2 {
  margin: 0 0 14px;
  font-size: 1.25rem;
}

.related-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.related-grid a {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  color: var(--ink);
  text-decoration: none;
}

.related-grid a:hover {
  border-color: #9ccdc8;
  background: var(--soft);
}

.related-grid span {
  color: var(--muted);
  font-size: 0.8rem;
}

.related-grid strong {
  color: var(--primary-dark);
  font-size: 0.82rem;
}

.disclaimer {
  margin-top: 28px;
  padding: 16px;
  border-left: 4px solid var(--primary);
  border-radius: 0 10px 10px 0;
  background: var(--soft);
  color: #405d60;
  font-size: 0.8rem;
}

.notice {
  padding: 13px;
  border-radius: 10px;
}

.notice.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

@media (max-width: 950px) {
  .calculator-layout {
    grid-template-columns: 1fr;
  }
  .result-card {
    position: static;
  }
  .comparison-panel {
    grid-template-columns: 1fr;
  }
  .unit-calc-box {
    grid-template-columns: 1fr;
  }
  .quick-guide {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (max-width: 680px) {
  .page-shell {
    width: min(100% - 20px, 1120px);
    padding-top: 34px;
  }
  .hero {
    margin-bottom: 25px;
  }
  .field-grid,
  .detail-grid,
  .related-grid {
    grid-template-columns: 1fr;
  }
  .calculator-actions .button {
    width: 100%;
  }
  .quick-guide {
    grid-template-columns: 1fr;
  }
  .composition-legend {
    grid-template-columns: 1fr;
  }
  .result-list div {
    font-size: 0.9rem;
  }
}

@media (max-width: 420px) {
  .page-shell {
    width: min(100% - 16px, 1120px);
  }
  .panel,
  .result-card,
  .timeline-card {
    border-radius: 14px;
  }
  .comparison-grid {
    grid-template-columns: 1fr;
  }
  .main-result {
    font-size: 2.2rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  html {
    scroll-behavior: auto;
  }
  .composition-bar span {
    transition: none;
  }
}
