:root {
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #6b7280;
  --line: #dfe5ee;
  --line-soft: #edf1f6;
  --blue: #0877ff;
  --blue-deep: #065cdf;
  --green: #149947;
  --green-bg: #f0fff5;
  --green-line: #97e3ae;
  --shadow: 0 14px 36px rgba(15, 23, 42, .08);
  --radius: 18px;
  --field-h: 68px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { overscroll-behavior-y: none; }
button, input { font: inherit; }
button { -webkit-appearance: none; appearance: none; padding: 0; line-height: 1; }

.app-shell {
  width: 100%;
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(10px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom));
}

.calculator-card {
  width: min(100%, 430px);
  min-height: min(100svh - 20px, 812px);
  max-height: 860px;
  padding: 14px 14px 12px;
  border-radius: 30px;
  background: linear-gradient(180deg, #fff 0%, #fbfdff 100%);
  box-shadow: var(--shadow);
  border: 1px solid rgba(226, 232, 240, .85);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.title-row {
  position: relative;
  min-height: 38px;
  display: grid;
  place-items: center;
}
h1 {
  margin: 2px 42px 0;
  text-align: center;
  font-size: clamp(23px, 6.1vw, 30px);
  line-height: 1.06;
  letter-spacing: -.04em;
  font-weight: 850;
}
.clear-btn {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  aspect-ratio: 1 / 1;
  flex: 0 0 38px;
  min-width: 38px;
  min-height: 38px;
  border: 1px solid #dbe4ef;
  border-radius: 999px;
  background: #fff;
  color: #64748b;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .04);
  cursor: pointer;
}
.clear-btn:active { transform: translateY(-50%) scale(.96); background: #f8fafc; }
.clear-btn svg { display: block; width: 20px; height: 20px; flex: 0 0 20px; }


.market-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 52px;
  padding: 4px;
  border-radius: 16px;
  border: 1px solid #d5dce8;
  background: #fff;
}
.market-btn {
  border: 0;
  border-radius: 13px;
  background: transparent;
  color: #111827;
  font-weight: 700;
  font-size: 16px;
}
.market-btn.active {
  background: linear-gradient(180deg, #1688ff 0%, #0668ec 100%);
  color: white;
  box-shadow: 0 8px 18px rgba(8,119,255,.26);
}

.compact-grid { display: grid; gap: 9px; }
.four-cols { grid-template-columns: repeat(4, 1fr); }
.two-cols { grid-template-columns: repeat(2, minmax(0, 1fr)); }

.field, .toggle-field {
  position: relative;
  height: var(--field-h);
  border-radius: 14px;
  background: rgba(255,255,255,.96);
  border: 1px solid var(--line);
  box-shadow: 0 4px 12px rgba(15, 23, 42, .035);
}
.field.mini { height: 68px; }
.field span {
  position: absolute;
  top: 10px;
  left: 14px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1;
  font-weight: 600;
}
.field input {
  width: 100%;
  height: 100%;
  padding: 28px 13px 8px;
  border: 0;
  outline: 0;
  background: transparent;
  color: #0b1220;
  font-size: 24px;
  line-height: 1;
  font-weight: 650;
  letter-spacing: -.02em;
}
.field.mini input { font-size: 23px; }
.field input:focus { caret-color: var(--blue); }
.field:focus-within { border-color: rgba(8,119,255,.42); box-shadow: 0 0 0 4px rgba(8,119,255,.08); }

.tier-strip {
  min-height: 50px;
  padding: 0 14px;
  border: 1px solid var(--line-soft);
  border-radius: 15px;
  background: #fff;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .035);
  display: grid;
  grid-template-columns: minmax(0, 1.02fr) 1px minmax(82px, .78fr) 1px minmax(0, .82fr);
  align-items: center;
  column-gap: 7px;
  color: #26364d;
  font-size: 13.5px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.tier-strip i { display: block; width: 1px; height: 22px; background: #dfe6ef; }
.tier-strip span { min-width: 0; overflow: hidden; text-overflow: ellipsis; text-align: center; }
.tier-strip #fbaFee { display: inline-block; max-width: 100%; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.tier-strip span:first-child { text-align: left; }
.tier-strip span:last-child { text-align: right; }
.tier-strip strong { color: #172033; }
.tier-strip .blue { color: var(--blue); }

.toggle-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 13px;
  cursor: pointer;
}
.toggle-field span { font-size: 17px; font-weight: 750; color: #172033; white-space: nowrap; }
.toggle-field input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.toggle-field b {
  width: 56px;
  height: 32px;
  border-radius: 999px;
  background: #d9e1ec;
  position: relative;
  transition: .18s ease;
  flex: 0 0 auto;
}
.toggle-field b::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(15, 23, 42, .24);
  transition: .18s ease;
}
.toggle-field input:checked + b { background: linear-gradient(180deg, #1688ff, #086bff); }
.toggle-field input:checked + b::after { transform: translateX(24px); }

.profit-card {
  border-radius: 17px;
  border: 1px solid var(--green-line);
  background: linear-gradient(180deg, #f7fff9 0%, #effff5 100%);
  padding: 18px 12px 14px;
  min-height: 150px;
  display: grid;
  grid-template-columns: minmax(0, .96fr) minmax(0, .86fr) minmax(0, 1.18fr);
  grid-template-rows: 1fr auto;
  align-items: center;
  column-gap: 0;
  overflow: hidden;
}
.profit-col {
  text-align: center;
  min-width: 0;
  padding: 0 4px;
  border-right: 1px solid #bfebc9;
}
.profit-col:last-of-type { border-right: 0; }
.profit-col span { display: block; font-size: 16px; font-weight: 700; color: #24324a; margin-bottom: 8px; }
.profit-col strong {
  display: block;
  font-size: clamp(22px, 6.2vw, 31px);
  line-height: 1;
  font-weight: 850;
  color: var(--green);
  letter-spacing: -.05em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: clip;
}
.profit-col strong.currency-value { font-size: clamp(18px, 5.2vw, 24px); letter-spacing: -.06em; }
#totalProfit.currency-value { font-size: clamp(17px, 4.8vw, 22px); }
.status-pill {
  grid-column: 1 / -1;
  justify-self: center;
  margin-top: 14px;
  padding: 8px 18px;
  border-radius: 999px;
  background: #e8fff0;
  border: 1px solid #a4e6b6;
  color: var(--green);
  font-size: 16px;
  font-weight: 800;
}
.status-pill::before { content: "✓"; display: inline-grid; place-items: center; margin-right: 8px; width: 22px; height: 22px; border-radius: 50%; background: var(--green); color: #fff; font-size: 14px; }
.status-pill.rmb {
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.status-pill.rmb::before { content: "¥"; font-size: 13px; font-weight: 900; }
.status-pill.rmb.negative { background: #fff1f2; border-color: #fecdd3; color: #be123c; }
.status-pill.rmb.negative::before { background: #e11d48; content: "¥"; }
.status-pill.warn { background: #fff8e6; border-color: #ffd482; color: #b46600; }
.status-pill.warn::before { background: #f59e0b; }
.status-pill.bad { background: #fff1f2; border-color: #fecdd3; color: #be123c; }
.status-pill.bad::before { content: "!"; background: #e11d48; }
.status-pill.muted { background: #f6f8fb; border-color: #e5ebf2; color: #64748b; }
.status-pill.muted::before { content: ""; width: 0; height: 0; margin: 0; }

.fee-detail {
  border-radius: 17px;
  border: 1px solid var(--line-soft);
  background: #fff;
  box-shadow: 0 4px 12px rgba(15, 23, 42, .035);
  padding: 13px 14px;
  display: grid;
  gap: 10px;
  min-height: 86px;
}
.fee-detail div {
  display: grid;
  align-items: center;
  justify-content: stretch;
  gap: 0;
  min-width: 0;
}
.fee-detail div:first-child { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.fee-detail div:last-child { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.fee-detail div + div { border-top: 1px solid #e6edf5; padding-top: 10px; }
.fee-detail span {
  color: #172033;
  font-size: clamp(13px, 3.7vw, 16px);
  line-height: 1.1;
  font-weight: 750;
  white-space: nowrap;
  padding: 0 8px;
  border-right: 1px solid #d5dee9;
  text-align: center;
  min-width: 0;
  overflow: hidden;
  text-overflow: clip;
}
.fee-detail span:last-child { border-right: 0; }
.fee-detail strong { font-weight: 750; }

@media (max-width: 430px) and (min-width: 381px) {
  .clear-btn { width: 40px; height: 40px; min-width: 40px; min-height: 40px; flex-basis: 40px; }
  .clear-btn svg { width: 20px; height: 20px; }
  .tier-strip { font-size: 13px; padding: 0 10px; column-gap: 6px; grid-template-columns: minmax(0, 1.02fr) 1px minmax(78px, .78fr) 1px minmax(0, .82fr); }
  .profit-card { padding-left: 10px; padding-right: 10px; }
  .profit-col span { font-size: 15px; }
  .profit-col strong.currency-value { font-size: clamp(18px, 5vw, 23px); }
  #totalProfit.currency-value { font-size: clamp(17px, 4.6vw, 21px); }
  .fee-detail span { font-size: 14px; padding-left: 6px; padding-right: 6px; }
}

@media (max-width: 380px) {
  :root { --field-h: 62px; }
  .app-shell { padding-left: 7px; padding-right: 7px; }
  .calculator-card { border-radius: 24px; padding: 10px; gap: 8px; min-height: auto; }
  h1 { font-size: 22px; margin-left: 38px; margin-right: 38px; }
  .title-row { min-height: 34px; }
  .clear-btn { width: 34px; height: 34px; min-width: 34px; min-height: 34px; flex-basis: 34px; }
  .clear-btn svg { width: 18px; height: 18px; }
  .market-toggle { height: 46px; }
  .market-btn { font-size: 14px; }
  .field.mini, .field { height: 61px; }
  .field span { top: 9px; left: 10px; font-size: 12px; }
  .field input { font-size: 20px; padding-left: 10px; padding-right: 10px; }
  .tier-strip { font-size: 11.5px; padding: 0 8px; min-height: 42px; column-gap: 5px; grid-template-columns: minmax(0, 1fr) 1px minmax(70px, .78fr) 1px minmax(0, .82fr); }
  .toggle-field span { font-size: 14px; }
  .toggle-field b { width: 50px; height: 29px; }
  .toggle-field b::after { width: 23px; height: 23px; }
  .toggle-field input:checked + b::after { transform: translateX(21px); }
  .profit-card { min-height: 125px; padding: 13px 8px 11px; }
  .profit-col span { font-size: 13px; margin-bottom: 6px; }
  .profit-col { padding: 0 2px; }
  .profit-col strong { font-size: 22px; }
  .profit-col strong.currency-value { font-size: 18px; }
  #totalProfit.currency-value { font-size: 17px; }
  .status-pill { margin-top: 10px; font-size: 14px; padding: 6px 14px; }
  .status-pill.rmb { font-size: 13.5px; padding-left: 12px; padding-right: 12px; }
  .fee-detail { min-height: 76px; padding: 10px; }
  .fee-detail span { font-size: 12.5px; padding: 0 5px; }
}

@media (min-height: 760px) and (min-width: 390px) {
  .calculator-card { gap: 13px; padding-top: 18px; }
}
