:root {
  --bg: #f7f5f2;
  --paper: #fcfbf9;
  --ink: #17171c;
  --muted: #5f5f66;
  --soft: #77777f;
  --line: #dedbd6;
  --line-dark: #c9c5bf;
  --positive: #235f4a;
  --negative: #a14b45;
  --radius: 0px;
  --shadow: 0 12px 36px rgba(23, 23, 28, 0.05);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "DM Sans", Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}
button, input { font: inherit; }
button { color: inherit; }

.app-shell {
  width: 100%;
  min-height: 100vh;
  min-height: 100dvh;
  padding: clamp(14px, 1.6vw, 24px) clamp(18px, 2.4vw, 38px) clamp(14px, 1.6vw, 24px);
  display: flex;
  flex-direction: column;
  gap: clamp(12px, 1.4vh, 18px);
}

.topbar {
  min-height: 64px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 24px;
  position: relative;
  border-bottom: 1px solid var(--line);
  padding: 0 2px clamp(10px, 1.2vh, 16px);
}
.brand {
  font-weight: 700;
  letter-spacing: -0.055em;
  font-size: clamp(19px, 1.35vw, 23px);
  white-space: nowrap;
}
.title-wrap {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  width: min(560px, 46vw);
}
.title-wrap h1 {
  margin: 0;
  font-size: clamp(24px, 1.8vw, 32px);
  line-height: 1;
  letter-spacing: -0.045em;
}
.title-wrap p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: clamp(12px, 0.82vw, 14px);
}
.top-actions { display: flex; align-items: center; gap: 10px; grid-column: 2; justify-self: end; }
.roi-chip {
  min-width: 142px;
  padding: 8px 12px;
  border: 1px solid var(--line-dark);
  border-radius: 0;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  background: rgba(255,255,255,.38);
}
.roi-chip span { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; }
.roi-chip strong { font-size: 16px; }
.reset-btn, .scenario-preset {
  border: 1px solid var(--ink);
  background: var(--ink);
  color: #fff;
  border-radius: 0;
  cursor: pointer;
  transition: transform .15s ease, opacity .15s ease;
}
.reset-btn { padding: 10px 17px; font-size: 13px; font-weight: 600; }
.reset-btn:hover, .scenario-preset:hover { opacity: .9; }
.reset-btn:active, .scenario-preset:active { transform: translateY(1px); }

.calculator-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(430px, 0.88fr) minmax(560px, 1.12fr);
  gap: clamp(14px, 1.6vw, 24px);
}
.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-height: 0;
  overflow: hidden;
}
.input-panel {
  padding: clamp(16px, 1.5vw, 22px) clamp(18px, 1.7vw, 26px);
  display: flex;
  flex-direction: column;
}
.results-panel {
  padding: clamp(16px, 1.5vw, 22px) clamp(18px, 1.7vw, 26px) clamp(12px, 1.1vw, 16px);
  display: flex;
  flex-direction: column;
  gap: clamp(8px, 1.1vh, 12px);
}
.panel-heading {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  padding-bottom: clamp(10px, 1.2vh, 16px);
  border-bottom: 1px solid var(--line);
}
.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .13em;
}
.panel-heading h2, .scenario-heading h3 {
  margin: 0;
  letter-spacing: -0.045em;
}
.panel-heading h2 { font-size: clamp(23px, 1.8vw, 31px); line-height: 1.05; }
.panel-note { margin: 0; color: var(--muted); font-size: 12px; text-align: right; max-width: 145px; }

.input-list {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-rows: repeat(6, minmax(0, 1fr));
}
.control {
  min-height: 0;
  padding: clamp(8px, 1.1vh, 13px) 0 clamp(6px, .8vh, 10px);
  border-bottom: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.control:last-child { border-bottom: 0; }
.control-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.control label { font-size: clamp(14px, .96vw, 16px); font-weight: 650; letter-spacing: -.02em; }
.control label span { color: var(--muted); font-size: .88em; font-weight: 500; }
.number-box {
  min-width: 102px;
  height: 35px;
  padding: 0 9px;
  border: 1px solid var(--line-dark);
  border-radius: 0;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 2px;
}
.number-box:focus-within { outline: 2px solid rgba(23,23,28,.14); outline-offset: 1px; }
.number-box.currency { justify-content: flex-start; }
.number-box em { font-style: normal; color: var(--muted); font-size: 12px; margin-left: 2px; }
.number-box span { font-size: 13px; color: var(--muted); }
.number-input {
  width: 70px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  text-align: right;
  font-size: 14px;
  font-weight: 700;
  padding: 0;
  appearance: textfield;
  -moz-appearance: textfield;
}
.number-input::-webkit-inner-spin-button, .number-input::-webkit-outer-spin-button,
.scenario-rate input::-webkit-inner-spin-button, .scenario-rate input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }

.range-input {
  --fill: 0%;
  width: 100%;
  height: 18px;
  margin: 4px 0 -1px;
  background: transparent;
  appearance: none;
  -webkit-appearance: none;
  cursor: pointer;
}
.range-input::-webkit-slider-runnable-track {
  height: 3px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--ink) 0 var(--fill), var(--line-dark) var(--fill) 100%);
}
.range-input::-moz-range-track { height: 3px; border-radius: 999px; background: var(--line-dark); }
.range-input::-moz-range-progress { height: 3px; border-radius: 999px; background: var(--ink); }
.range-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 13px;
  height: 13px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--paper);
  border: 2px solid var(--ink);
  box-shadow: 0 0 0 2px rgba(255,255,255,.8);
}
.range-input::-moz-range-thumb {
  width: 10px; height: 10px; border-radius: 50%; background: var(--paper); border: 2px solid var(--ink);
}
.range-labels { display: flex; justify-content: space-between; color: var(--muted); font-size: 11px; line-height: 1; }

.results-top { display: flex; flex-direction: column; gap: clamp(8px, 1vh, 11px); }
.results-heading { padding-bottom: clamp(8px, .9vh, 12px); }
.profit-hero {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 20px;
  align-items: center;
  padding: clamp(10px, 1.4vh, 16px) clamp(14px, 1.3vw, 20px);
  border-radius: 0;
  background: var(--ink);
  color: white;
}
.profit-hero p { margin: 0 0 2px; color: rgba(255,255,255,.74); font-size: 12px; text-transform: uppercase; letter-spacing: .09em; font-weight: 600; }
.profit-hero strong { display: block; font-size: clamp(31px, 3.2vw, 52px); line-height: .98; letter-spacing: -.055em; }
.hero-secondary { min-width: 118px; border-left: 1px solid rgba(255,255,255,.18); padding-left: 18px; text-align: right; }
.hero-secondary span { display: block; color: rgba(255,255,255,.70); font-size: 11px; text-transform: uppercase; letter-spacing: .09em; }
.hero-secondary b { display: block; margin-top: 4px; font-size: clamp(18px, 1.8vw, 29px); letter-spacing: -.04em; }

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  border: 1px solid var(--line);
  border-radius: 0;
  overflow: hidden;
}
.metric { padding: clamp(7px, .9vh, 10px) 12px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); background: rgba(255,255,255,.34); }
.metric:nth-child(3n) { border-right: 0; }
.metric:nth-child(n+4) { border-bottom: 0; }
.metric span { display: block; color: var(--muted); font-size: 11.5px; line-height: 1.2; }
.metric strong { display: block; margin-top: 4px; font-size: clamp(16px, 1.25vw, 20px); letter-spacing: -.03em; }
.metric.cost strong { color: var(--negative); }
.breakeven-row {
  display: flex; justify-content: space-between; align-items: center; gap: 18px;
  padding: clamp(8px, 1vh, 11px) 12px;
  border-radius: 0;
  background: #efede9;
}
.breakeven-row span { display: block; font-size: 12px; font-weight: 650; }
.breakeven-row small { display: block; color: var(--muted); font-size: 11px; margin-top: 2px; }
.breakeven-row strong { font-size: clamp(18px, 1.45vw, 23px); letter-spacing: -.035em; }

.scenario-section { margin-top: auto; border-top: 1px solid var(--line); padding-top: clamp(9px, 1.1vh, 13px); }
.scenario-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: clamp(7px, .8vh, 10px); }
.scenario-heading h3 { font-size: clamp(17px, 1.25vw, 21px); }
.scenario-preset { font-size: 11px; font-weight: 600; padding: 7px 10px; }
.scenario-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; }
.scenario-card { border: 1px solid var(--line-dark); border-radius: 0; padding: clamp(8px, .9vw, 12px); background: #faf9f7; min-width: 0; }
.scenario-card.expected { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); background: #fff; }
.scenario-title-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.scenario-title-row > span { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 700; }
.scenario-rate { display: flex; align-items: center; gap: 1px; background: #efede9; border-radius: 0; padding: 3px 6px; }
.scenario-rate input { width: 42px; border: 0; outline: 0; background: transparent; text-align: right; font-size: 12px; font-weight: 700; appearance: textfield; -moz-appearance: textfield; padding: 0; }
.scenario-rate span { color: var(--muted); font-size: 11px; }
.scenario-profit { margin-top: clamp(5px, .7vh, 8px); font-size: clamp(23px, 2vw, 33px); font-weight: 700; letter-spacing: -.045em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.scenario-detail { margin-top: 5px; display: flex; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; }
.disclaimer { margin: 0; padding-top: 5px; text-align: center; color: #5f5f66; font-size: clamp(12px, .75vw, 14px); line-height: 1.35; }

@media (min-width: 901px) and (min-height: 680px) {
  body { overflow: hidden; }
  .app-shell { height: 100vh; height: 100dvh; }
}

@media (max-height: 760px) and (min-width: 901px) {
  .app-shell { padding-top: 10px; padding-bottom: 10px; gap: 9px; }
  .topbar { min-height: 45px; padding-bottom: 8px; }
  .title-wrap p { display: none; }
  .input-panel, .results-panel { padding-top: 12px; padding-bottom: 10px; }
  .panel-heading { padding-bottom: 8px; }
  .control { padding-top: 5px; padding-bottom: 4px; }
  .number-box { height: 27px; }
  .range-input { margin-top: 1px; height: 15px; }
  .profit-hero { padding-top: 9px; padding-bottom: 9px; }
  .metrics-grid .metric { padding-top: 6px; padding-bottom: 6px; }
  .breakeven-row { padding-top: 6px; padding-bottom: 6px; }
  .scenario-section { padding-top: 7px; }
  .scenario-heading { margin-bottom: 6px; }
  .scenario-card { padding-top: 7px; padding-bottom: 7px; }
  .scenario-profit { margin-top: 4px; }
}

@media (max-width: 1100px) and (min-width: 901px) {
  .calculator-grid { grid-template-columns: minmax(390px, .9fr) minmax(470px, 1.1fr); }
  .topbar { grid-template-columns: 1fr auto; gap: 16px; }
  .panel-note { display: none; }
  .metric { padding-left: 8px; padding-right: 8px; }
}

@media (max-width: 900px) {
  .app-shell { padding: 14px; }
  .topbar { grid-template-columns: 1fr auto; gap: 10px; min-height: auto; }
  .title-wrap { position: static; transform: none; width: auto; text-align: left; grid-column: 1 / -1; grid-row: 2; padding-bottom: 4px; }
  .top-actions { grid-column: 2; grid-row: 1; }
  .roi-chip { display: none; }
  .calculator-grid { grid-template-columns: 1fr; }
  .input-panel, .results-panel { padding: 17px; }
  .input-list { display: block; }
  .control { padding: 13px 0 10px; }
  .panel-note { display: none; }
}

@media (max-width: 620px) {
  .metrics-grid { grid-template-columns: repeat(2, 1fr); }
  .metric:nth-child(3n) { border-right: 1px solid var(--line); }
  .metric:nth-child(2n) { border-right: 0; }
  .metric:nth-child(n+4) { border-bottom: 1px solid var(--line); }
  .metric:nth-child(n+5) { border-bottom: 0; }
  .scenario-grid { grid-template-columns: 1fr; }
  .profit-hero { grid-template-columns: 1fr; }
  .hero-secondary { border-left: 0; border-top: 1px solid rgba(255,255,255,.18); padding: 9px 0 0; text-align: left; }
  .scenario-detail { font-size: 10.5px; }
  .control label span { display: block; margin-top: 1px; }
}
