:root {
  color-scheme: light;
  --bg: #f4f6f3;
  --panel: rgba(255, 255, 255, 0.96);
  --control: #ffffff;
  --subtle-panel: #fbfcfb;
  --ink: #1e2420;
  --muted: #66706a;
  --line: #d9dfd7;
  --line-strong: #bfc8bd;
  --green: #14724e;
  --red: #b93f3a;
  --gold: #a06b08;
  --focus: #2f6fed;
  --meter-bg: #e8ece7;
  --shadow: 0 18px 45px rgba(39, 48, 42, 0.09);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #111713;
  --panel: rgba(24, 31, 27, 0.97);
  --control: #101511;
  --subtle-panel: #151d18;
  --ink: #eef4ef;
  --muted: #aab8ae;
  --line: #2f3d34;
  --line-strong: #536258;
  --green: #58c78f;
  --red: #ef746d;
  --gold: #d8a33d;
  --focus: #7aa8ff;
  --meter-bg: #263229;
  --shadow: 0 20px 54px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background: var(--bg);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  width: min(1160px, calc(100% - 32px));
  margin: 0 auto;
  padding: 40px 0;
}

.intro {
  margin-bottom: 24px;
}

.intro-top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-start;
}

.intro-top > div {
  max-width: 780px;
}

.theme-switch {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 800;
  white-space: nowrap;
  cursor: pointer;
}

.theme-switch input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}

.switch-track {
  position: relative;
  width: 46px;
  height: 26px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--subtle-panel);
  transition:
    background 160ms ease,
    border-color 160ms ease;
}

.switch-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  background: var(--ink);
  transition: transform 160ms ease;
}

.theme-switch input:checked + .switch-track {
  border-color: var(--focus);
  background: rgba(122, 168, 255, 0.18);
}

.theme-switch input:checked + .switch-track .switch-thumb {
  transform: translateX(20px);
}

.theme-switch:focus-within .switch-track {
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.16);
}

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

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

h1 {
  max-width: 760px;
  margin-bottom: 12px;
  font-size: 4rem;
  line-height: 0.98;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
  letter-spacing: 0;
}

.lede {
  max-width: 640px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1.08rem;
  line-height: 1.55;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(300px, 0.78fr) minmax(420px, 1.22fr);
  gap: 16px;
  align-items: stretch;
}

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

.controls {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.field {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.money-input,
select {
  width: 100%;
  min-height: 52px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--control);
  color: var(--ink);
}

.money-input {
  display: grid;
  grid-template-columns: 26px 1fr;
  align-items: center;
  padding: 0 14px;
}

.money-input span {
  color: var(--muted);
}

input,
select {
  min-width: 0;
  border: 0;
  outline: 0;
}

input {
  width: 100%;
  padding: 14px 0;
  color: var(--ink);
  background: transparent;
}

select {
  padding: 0 14px;
}

.money-input:focus-within,
select:focus {
  border-color: var(--focus);
  box-shadow: 0 0 0 3px rgba(47, 111, 237, 0.16);
}

.result-panel {
  display: grid;
  gap: 18px;
  padding: 22px;
}

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

.metric {
  display: grid;
  min-height: 158px;
  align-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.metric span,
.detail-grid span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.metric strong {
  display: block;
  font-size: 2.35rem;
  line-height: 1;
  letter-spacing: 0;
}

.metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 800;
}

.metric-win strong {
  color: var(--green);
}

.metric-loss strong {
  color: var(--red);
}

.meter {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--meter-bg);
}

.meter span {
  display: block;
  width: 0%;
  height: 100%;
  transition: width 160ms ease;
}

.metric-win .meter span {
  background: var(--green);
}

.metric-loss .meter span {
  background: var(--red);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.detail-grid div {
  display: grid;
  gap: 8px;
  min-height: 92px;
  padding: 15px;
  border-right: 1px solid var(--line);
  background: var(--subtle-panel);
}

.detail-grid div:last-child {
  border-right: 0;
}

.detail-grid strong {
  font-size: 1.12rem;
}

.calculation-status {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--muted);
  background: var(--subtle-panel);
  font-size: 0.92rem;
  font-weight: 700;
}

.calculation-status[hidden] {
  display: none;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--focus);
  border-radius: 999px;
  animation: spin 800ms linear infinite;
  flex: 0 0 auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.assumption {
  margin: 0;
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.5;
}

.ladder-panel {
  margin-top: 16px;
  overflow: hidden;
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  padding: 22px;
  border-bottom: 1px solid var(--line);
}

.section-heading p:last-child {
  margin: 0;
  color: var(--muted);
  font-size: 0.94rem;
  font-weight: 700;
  text-align: right;
}

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

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
}

th,
td {
  padding: 15px 22px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  background: var(--subtle-panel);
  font-size: 0.78rem;
  letter-spacing: 0;
  text-transform: uppercase;
}

td {
  font-weight: 700;
}

tbody tr:last-child td {
  border-bottom: 0;
}

.empty-row td {
  color: var(--muted);
  font-weight: 600;
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100% - 24px, 680px);
    padding: 24px 0;
  }

  h1 {
    font-size: 2.55rem;
  }

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

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

  .detail-grid div:nth-child(2) {
    border-right: 0;
  }

  .detail-grid div:nth-child(-n + 2) {
    border-bottom: 1px solid var(--line);
  }
}

@media (max-width: 540px) {
  .app-shell {
    width: min(100% - 32px, 520px);
    padding: 18px 0;
  }

  .intro {
    position: relative;
    margin-bottom: 16px;
  }

  .intro-top {
    display: grid;
    gap: 14px;
  }

  .theme-switch {
    position: absolute;
    top: 0;
    right: 0;
    margin-top: 0;
  }

  .theme-switch > span:first-child {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  h1 {
    font-size: 2.15rem;
    line-height: 1.03;
  }

  .lede {
    font-size: 0.98rem;
  }

  .controls,
  .result-panel,
  .section-heading {
    padding: 16px;
  }

  .result-grid,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .metric {
    min-height: 132px;
  }

  .metric strong {
    font-size: 2rem;
  }

  .detail-grid div,
  .detail-grid div:nth-child(2) {
    min-height: 80px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .detail-grid div:last-child {
    border-bottom: 0;
  }

  .section-heading {
    display: grid;
  }

  .section-heading p:last-child {
    text-align: left;
  }
}
