:root {
  --bg-sheet: #F6F8FA;
  --bg-paper: #FFFFFF;
  --bg-subtle: #EFF3F7;
  --ink-primary: #0F1E2E;
  --ink-secondary: #475569;
  --ink-muted: #64748B;
  --rule-hairline: #D0D7DE;
  --rule-strong: #94A3B8;
  --cobalt: #1D4ED8;
  --cobalt-hover: #1E40AF;
  --cobalt-tint: #EFF6FF;
  --emerald: #047857;
  --emerald-tint: #ECFDF5;
  --fee-red: #B91C1C;
  --fee-red-tint: #FEF2F2;
  --amber-mor: #B45309;
  --font-sans: "IBM Plex Sans", "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --radius-sm: 2px;
  --radius-md: 4px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  background-color: var(--bg-sheet);
  color: var(--ink-primary);
  font-family: var(--font-sans);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg-sheet);
  color: var(--ink-primary);
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--ink-primary);
  color: var(--bg-paper);
  padding: 8px 12px;
  z-index: 100;
}

.skip-link:focus {
  left: 12px;
  top: 12px;
}

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

.num-col,
.num-cell,
.summary-figure,
input[type="number"],
.preset-btn,
.unit-badge {
  font-variant-numeric: tabular-nums;
}

/* Masthead */
.masthead {
  background: var(--bg-paper);
  border-bottom: 1px solid var(--rule-hairline);
}

.masthead-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 6px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
}

.brand-mark {
  flex-shrink: 0;
  display: block;
}

.brand-titles h1 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.015em;
  color: var(--ink-primary);
  line-height: 1.15;
}

.brand-sub {
  margin: 1px 0 0;
  font-size: 0.8rem;
  color: var(--ink-secondary);
  line-height: 1.2;
}

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

.btn {
  appearance: none;
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius-md);
  padding: 7px 12px;
  font-family: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  line-height: 1.2;
  cursor: pointer;
  background: var(--bg-paper);
  color: var(--ink-primary);
  transition: background-color 120ms ease, border-color 120ms ease;
}

.btn-secondary:hover {
  background: var(--bg-subtle);
  border-color: var(--rule-strong);
}

.btn-primary {
  background: var(--cobalt);
  border-color: var(--cobalt);
  color: #FFFFFF;
}

.btn-primary:hover {
  background: var(--cobalt-hover);
  border-color: var(--cobalt-hover);
}

/* Workspace Layout */
.workspace {
  max-width: 1360px;
  margin: 0 auto;
  padding: 8px 20px 44px;
}

.ledger-grid {
  display: grid;
  grid-template-columns: 326px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

/* Control Rail */
.control-pane {
  background: var(--bg-paper);
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius-md);
  padding: 14px 16px;
}

.pane-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--rule-hairline);
}

.pane-header h2 {
  margin: 0;
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink-primary);
}

.text-action {
  background: none;
  border: none;
  padding: 2px 4px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--cobalt);
  cursor: pointer;
}

.text-action:hover {
  text-decoration: underline;
}

.field-group {
  margin-bottom: 11px;
}

.field-group:last-child {
  margin-bottom: 0;
}

.field-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-secondary);
  margin-bottom: 4px;
}

.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-md);
  overflow: hidden;
  background: var(--bg-subtle);
}

.mode-btn {
  appearance: none;
  border: none;
  background: transparent;
  padding: 7px 6px;
  font-family: inherit;
  font-size: 0.77rem;
  font-weight: 600;
  color: var(--ink-secondary);
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
}

.mode-btn + .mode-btn {
  border-left: 1px solid var(--rule-hairline);
}

.mode-btn.is-active {
  background: var(--cobalt);
  color: #FFFFFF;
}

.field-hint {
  margin: 5px 0 0;
  font-size: 0.74rem;
  color: var(--ink-muted);
  line-height: 1.3;
}

.currency-input-wrap,
.compact-num-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-md);
  background: var(--bg-paper);
}

.currency-input-wrap:focus-within,
.compact-num-wrap:focus-within,
select:focus,
input[type="number"]:focus {
  border-color: var(--cobalt);
}

.currency-prefix,
.prefix,
.suffix {
  padding: 0 9px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-secondary);
  user-select: none;
}

input[type="number"],
select {
  width: 100%;
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-md);
  padding: 6px 8px;
  font-family: inherit;
  font-size: 0.82rem;
  color: var(--ink-primary);
  background: var(--bg-paper);
}

.currency-input-wrap input {
  width: 100%;
  border: none;
  padding: 6px 10px 6px 2px;
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink-primary);
  background: transparent;
}

.compact-num-wrap input {
  border: none;
  padding: 6px 4px;
  width: 100%;
  min-width: 0;
  background: transparent;
}

.currency-input-wrap input:focus,
.compact-num-wrap input:focus {
  outline: none;
}

.preset-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  margin-top: 6px;
}

.preset-btn {
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius-sm);
  background: var(--bg-sheet);
  color: var(--ink-secondary);
  padding: 4px 2px;
  font-family: inherit;
  font-size: 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.preset-btn:hover {
  border-color: var(--cobalt);
  color: var(--cobalt);
}

.preset-btn.is-active {
  background: var(--cobalt-tint);
  border-color: var(--cobalt);
  color: var(--cobalt);
}

.split-fields {
  display: grid;
  grid-template-columns: 112px 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.split-fields .field-group {
  margin-bottom: 0;
}

.label-with-value {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.unit-badge {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.range-pair {
  display: grid;
  grid-template-columns: 1fr 68px;
  gap: 8px;
  align-items: center;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--cobalt);
  cursor: pointer;
}

.divider-rule {
  height: 1px;
  background: var(--rule-hairline);
  margin: 12px 0;
}

.print-meta {
  display: none;
}

/* Right Ledger Pane */
.ledger-pane {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

/* Asymmetric Summary Strip */
.summary-strip {
  display: grid;
  grid-template-columns: 1.25fr 1fr 1fr;
  background: var(--bg-paper);
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius-md);
}

.summary-cell {
  padding: 6px 12px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

.summary-cell + .summary-cell {
  border-left: 1px solid var(--rule-hairline);
}

.summary-best {
  border-left: 3px solid var(--emerald);
  background: linear-gradient(90deg, rgba(4, 120, 87, 0.04) 0%, #FFFFFF 48%);
}

.summary-label {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--ink-secondary);
}

.summary-main {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.summary-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--ink-primary);
}

.summary-figure {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--ink-primary);
  line-height: 1.2;
}

.summary-note {
  font-size: 0.72rem;
  color: var(--ink-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.net-value {
  color: var(--emerald);
}

.fee-value {
  color: var(--fee-red);
}

/* Waterfall Table Card */
.table-card {
  background: var(--bg-paper);
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.table-header-bar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 12px;
  border-bottom: 1px solid var(--rule-hairline);
  background: var(--bg-paper);
}

.table-header-bar h2 {
  margin: 0;
  font-size: 0.89rem;
  font-weight: 700;
}

.table-subtitle {
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.table-scroll {
  width: 100%;
  overflow-x: auto;
}

.ledger-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.ledger-table th {
  text-align: left;
  font-size: 0.71rem;
  font-weight: 600;
  color: var(--ink-secondary);
  background: var(--bg-sheet);
  padding: 5px 10px;
  border-bottom: 1px solid var(--rule-hairline);
  white-space: nowrap;
}

.ledger-table th.num-col,
.ledger-table td.num-cell {
  text-align: right;
  white-space: nowrap;
}

.ledger-table td {
  padding: 2.5px 10px;
  border-bottom: 1px solid #EAEEF2;
  vertical-align: middle;
  line-height: 1.15;
}

.ledger-table tbody tr:last-child td {
  border-bottom: none;
}

.ledger-table tbody tr.is-winner {
  background: #F4FBF8;
}

.ledger-table tbody tr:hover {
  background: #F8FAFC;
}

.ledger-table tbody tr.is-winner:hover {
  background: #ECFDF5;
}

.rail-head {
  display: flex;
  align-items: center;
  gap: 6px;
}

.rail-name {
  font-weight: 700;
  color: var(--ink-primary);
}

.mor-tag {
  display: inline-block;
  padding: 1px 5px;
  font-size: 0.67rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  border: 1px solid var(--rule-hairline);
  color: var(--ink-secondary);
  background: var(--bg-sheet);
}

.mor-tag.is-mor {
  border-color: #CBD5E1;
  background: #FEF3C7;
  color: #92400E;
}

.mor-tag.is-best {
  border-color: #A7F3D0;
  background: var(--emerald-tint);
  color: var(--emerald);
}

.rail-formula {
  font-size: 0.68rem;
  color: var(--ink-muted);
  margin-top: 0;
}

.stack-track {
  display: flex;
  height: 2px;
  width: 100%;
  max-width: 150px;
  background: #E2E8F0;
  margin-top: 2px;
  overflow: hidden;
  border-radius: 1px;
}

.stack-seg-net {
  background: var(--emerald);
  height: 100%;
}

.stack-seg-fee {
  background: var(--fee-red);
  height: 100%;
}

.stack-seg-tax {
  background: #64748B;
  height: 100%;
}

.sub-pct {
  display: inline-block;
  margin-left: 4px;
  font-size: 0.68rem;
  font-weight: 500;
  color: var(--ink-muted);
}

.net-strong {
  font-weight: 700;
  font-size: 0.85rem;
  color: var(--emerald);
}

.gross-strong {
  font-weight: 700;
  color: var(--ink-primary);
}

/* Interactive Pure-SVG Break-Even Panel */
.chart-panel {
  background: var(--bg-paper);
  border: 1px solid var(--rule-hairline);
  border-radius: var(--radius-md);
  padding: 6px 12px 4px;
}

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.chart-header h2 {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
}

.chart-subtitle {
  margin: 1px 0 0;
  font-size: 0.72rem;
  color: var(--ink-secondary);
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
  font-size: 0.72rem;
  color: var(--ink-secondary);
  white-space: nowrap;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.swatch {
  display: inline-block;
  width: 10px;
  height: 3px;
}

.swatch-stripe {
  background: var(--cobalt);
}

.swatch-lemon {
  background: var(--amber-mor);
}

.swatch-gumroad {
  background: var(--fee-red);
}

.chart-readout {
  margin: 4px 0 2px;
  padding: 3px 8px;
  background: var(--bg-sheet);
  border: 1px solid #E2E8F0;
  border-radius: var(--radius-sm);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-primary);
}

.svg-wrap {
  width: 100%;
  overflow: hidden;
}

#breakeven-svg {
  display: block;
  width: 100%;
  height: auto;
  font-family: var(--font-sans);
}

/* AI-SEO Reference Section */
.reference-section {
  margin-top: 28px;
  padding-top: 24px;
  border-top: 1px solid var(--rule-hairline);
}

.ref-intro {
  max-width: 78ch;
  margin-bottom: 14px;
}

.ref-intro h2 {
  margin: 0 0 8px;
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--ink-primary);
}

.answer-block {
  margin: 0;
  font-size: 0.92rem;
  color: var(--ink-secondary);
  line-height: 1.55;
}

.ref-table-card {
  margin-bottom: 22px;
}

.faq-columns {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px 28px;
}

.faq-item {
  border-top: 1px solid var(--rule-hairline);
  padding-top: 12px;
}

.faq-item h3 {
  margin: 0 0 6px;
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink-primary);
}

.faq-item p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--ink-secondary);
  line-height: 1.52;
  max-width: 68ch;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--rule-hairline);
  background: var(--bg-paper);
}

.footer-inner {
  max-width: 1360px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.footer-inner p {
  margin: 0;
}

.footer-links {
  display: flex;
  gap: 14px;
}

.footer-links a {
  color: var(--cobalt);
  text-decoration: none;
  font-weight: 600;
}

.footer-links a:hover {
  text-decoration: underline;
}

/* Pro Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 30, 46, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 50;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-sheet {
  width: 100%;
  max-width: 560px;
  background: var(--bg-paper);
  border: 1px solid var(--rule-strong);
  border-radius: var(--radius-md);
  box-shadow: 0 18px 40px rgba(15, 30, 46, 0.22);
  overflow: hidden;
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--rule-hairline);
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.modal-header h2 {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
}

.modal-subtitle {
  margin: 3px 0 0;
  font-size: 0.82rem;
  color: var(--ink-secondary);
}

.modal-close {
  border: 1px solid var(--rule-hairline);
  background: var(--bg-sheet);
  color: var(--ink-primary);
  border-radius: var(--radius-sm);
  padding: 5px 10px;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.modal-body {
  padding: 16px 20px;
  font-size: 0.87rem;
  color: var(--ink-secondary);
}

.modal-lead {
  margin: 0 0 12px;
}

.bundle-list {
  margin: 0 0 14px;
  padding-left: 18px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  color: var(--ink-primary);
}

.modal-callout {
  padding: 10px 12px;
  background: var(--bg-sheet);
  border-left: 3px solid var(--cobalt);
  font-size: 0.8rem;
  color: var(--ink-secondary);
}

.modal-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--rule-hairline);
  background: var(--bg-sheet);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Responsive Breakpoints */
@media (max-width: 1020px) {
  .ledger-grid {
    grid-template-columns: 1fr;
  }

  .summary-strip {
    grid-template-columns: 1fr;
  }

  .summary-cell + .summary-cell {
    border-left: none;
    border-top: 1px solid var(--rule-hairline);
  }
}

@media (max-width: 720px) {
  .masthead-inner {
    flex-direction: column;
    align-items: flex-start;
    padding: 12px 14px;
  }

  .workspace {
    padding: 12px 14px 36px;
  }

  .split-fields,
  .faq-columns {
    grid-template-columns: 1fr;
  }

  .masthead-actions {
    width: 100%;
  }

  .masthead-actions .btn {
    flex: 1 1 auto;
    text-align: center;
  }
}

/* Print Ledger Stylesheet */
@media print {
  @page {
    size: landscape;
    margin: 12mm;
  }

  body {
    background: #FFFFFF;
  }

  .masthead-actions,
  .control-pane .field-group,
  .control-pane .pane-header,
  .control-pane .divider-rule,
  .chart-readout,
  .reference-section,
  .site-footer,
  .modal-backdrop {
    display: none !important;
  }

  .workspace {
    padding: 0;
    max-width: none;
  }

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

  .control-pane {
    border: none;
    padding: 0 0 8px;
  }

  .print-meta {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--ink-primary);
    border-bottom: 1px solid var(--rule-strong);
    padding-bottom: 6px;
    margin-bottom: 8px;
  }

  .table-card,
  .chart-panel,
  .summary-strip {
    border-color: #94A3B8;
    break-inside: avoid;
  }
}
