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

:root {
  --brand:        #4f46e5;
  --brand-light:  #818cf8;
  --brand-dark:   #3730a3;
  --surface:      #ffffff;
  --bg:           #f0f4ff;
  --text-primary: #111827;
  --text-muted:   #6b7280;
  --border:       #e5e7eb;
  --success:      #10b981;
  --radius:       14px;
  --shadow:       0 8px 40px rgba(79,70,229,.12);
  --transition:   .25s ease;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 32px 16px 60px;
}

/* ── CJK font override ──────────────────────────────── */
html[lang="zh"] body {
  font-family: 'Noto Sans SC', 'Inter', sans-serif;
}

html[lang="zh"] h1 {
  letter-spacing: 0;
}

/* ── Language Switcher ──────────────────────────────── */
.lang-switcher {
  display: flex;
  justify-content: flex-end;
  width: 100%;
  max-width: 600px;
  margin-bottom: 24px;
}

.lang-switcher .select-wrap {
  min-width: 170px;
}

.lang-switcher select {
  font-size: .85rem;
  font-weight: 500;
  padding: 7px 32px 7px 12px;
  color: var(--text-muted);
}

/* ── Hero header ────────────────────────────────────── */
header {
  text-align: center;
  margin-bottom: 36px;
  max-width: 600px;
}

header .eyebrow {
  display: inline-block;
  background: linear-gradient(135deg, var(--brand) 0%, #7c3aed 100%);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .12em;
  text-transform: uppercase;
  padding: 4px 14px;
  border-radius: 99px;
  margin-bottom: 18px;
}

header h1 {
  font-size: clamp(1.9rem, 5vw, 2.7rem);
  font-weight: 800;
  line-height: 1.18;
  letter-spacing: -.02em;
  background: linear-gradient(135deg, var(--brand-dark) 0%, #7c3aed 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 14px;
}

header p {
  color: var(--text-muted);
  font-size: 1.05rem;
  line-height: 1.6;
}

/* ── Card ───────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 560px;
  padding: 40px 44px;
  border: 1px solid rgba(79,70,229,.08);
}

/* ── Form ───────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px 24px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}

input, select {
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-family: inherit;
  font-size: .97rem;
  color: var(--text-primary);
  background: #fafafa;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
  background: #fff;
}

/* Custom select arrow */
.select-wrap {
  position: relative;
}

.select-wrap::after {
  content: '';
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  width: 0;
  height: 0;
  border-left: 5px solid transparent;
  border-right: 5px solid transparent;
  border-top: 6px solid var(--text-muted);
  pointer-events: none;
}

/* Currency symbol prefix */
.input-prefix {
  position: relative;
}

.input-prefix .prefix {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: .95rem;
  color: var(--text-muted);
  font-weight: 500;
  pointer-events: none;
  user-select: none;
}

.input-prefix input {
  padding-left: 30px;
}

/* ── Number stepper ──────────────────────────────────── */
.stepper {
  display: flex;
  align-items: center;
  align-self: center;      /* center the widget horizontally within its field column */
  width: fit-content;      /* shrink to − number + content, don't stretch full-width */
  border: 1.5px solid var(--border);
  border-radius: 9px;
  overflow: hidden;
  background: #fafafa;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.stepper:focus-within {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(79,70,229,.15);
  background: #fff;
}

.stepper button {
  background: none;
  border: none;
  width: 38px;
  height: 42px;
  cursor: pointer;
  font-size: 1.2rem;
  color: var(--brand);
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
  flex-shrink: 0;
}

.stepper button:hover {
  background: rgba(79,70,229,.07);
}

.stepper input {
  border: none;
  border-radius: 0;
  text-align: center;
  width: 50px;
  padding: 11px 4px;
  background: transparent;
  font-weight: 600;
}

.stepper input:focus {
  box-shadow: none;
}

/* ── Divider ─────────────────────────────────────────── */
.divider {
  height: 1px;
  background: var(--border);
  margin: 28px 0;
}

/* ── CTA Button ──────────────────────────────────────── */
.btn-calculate {
  width: 100%;
  padding: 16px;
  background: linear-gradient(135deg, var(--brand) 0%, #7c3aed 100%);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-family: inherit;
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: .02em;
  cursor: pointer;
  transition: transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 20px rgba(79,70,229,.35);
  position: relative;
  overflow: hidden;
}

.btn-calculate::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(rgba(255,255,255,.1), rgba(255,255,255,0));
}

.btn-calculate:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 28px rgba(79,70,229,.45);
}

.btn-calculate:active {
  transform: translateY(0);
  box-shadow: 0 4px 14px rgba(79,70,229,.3);
}

/* ── Result panel ────────────────────────────────────── */
#result {
  margin-top: 32px;
  opacity: 0;
  transform: translateY(14px);
  transition: opacity .45s ease, transform .45s ease;
  pointer-events: none;
}

#result.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.result-headline {
  text-align: center;
  margin-bottom: 24px;
}

.result-headline .label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .08em;
  margin-bottom: 8px;
}

.result-headline .rank {
  font-size: clamp(1.5rem, 4vw, 2.1rem);
  font-weight: 800;
  line-height: 1.25;
  color: var(--brand-dark);
  letter-spacing: -.02em;
}

.result-headline .rank #percentileVal {
  color: var(--brand);
}

.result-headline .sub {
  margin-top: 6px;
  color: var(--text-muted);
  font-size: .92rem;
}

/* ── Gauge bar ───────────────────────────────────────── */
.gauge-wrap {
  margin-bottom: 24px;
}

.gauge-labels {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--text-muted);
  font-weight: 500;
  margin-bottom: 6px;
}

.gauge-track {
  height: 12px;
  background: #e5e7eb;
  border-radius: 99px;
  overflow: hidden;
}

.gauge-fill {
  height: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--success) 0%, var(--brand-light) 60%, var(--brand) 100%);
  width: 0;
  transition: width 1.1s cubic-bezier(.22,1,.36,1);
}

/* ── Breakdown stats ─────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.stat-box {
  background: var(--bg);
  border-radius: 10px;
  padding: 14px 10px;
  text-align: center;
  border: 1px solid rgba(79,70,229,.08);
}

.stat-box .val {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--brand-dark);
  margin-bottom: 3px;
}

.stat-box .key {
  font-size: .72rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── Context note ────────────────────────────────────── */
.context-note {
  background: linear-gradient(135deg, rgba(79,70,229,.06) 0%, rgba(124,58,237,.06) 100%);
  border-left: 3px solid var(--brand);
  border-radius: 0 8px 8px 0;
  padding: 14px 16px;
  font-size: .88rem;
  color: var(--text-muted);
  line-height: 1.55;
}

.context-note strong {
  color: var(--brand-dark);
}

/* ── Error message ───────────────────────────────────── */
.error-msg {
  color: #dc2626;
  font-size: .84rem;
  font-weight: 500;
  margin-top: 10px;
  text-align: center;
  min-height: 20px;
}

/* ── How it works card ───────────────────────────────── */
.how-card {
  width: 100%;
  max-width: 560px;
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid rgba(79,70,229,.08);
  box-shadow: 0 4px 20px rgba(79,70,229,.06);
  margin-top: 16px;
}

.how-card summary {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 15px 24px;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 700;
  color: var(--brand-dark);
  list-style: none;
  user-select: none;
  border-radius: var(--radius);
  transition: background var(--transition);
}

.how-card summary::-webkit-details-marker { display: none; }

.how-card summary:hover {
  background: rgba(79,70,229,.04);
}

.how-card[open] summary {
  border-bottom: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
}

.how-toggle-icon {
  color: var(--brand);
  font-size: .78rem;
  transition: transform .2s ease;
  flex-shrink: 0;
}

.how-card[open] .how-toggle-icon {
  transform: rotate(90deg);
}

.how-body {
  padding: 20px 24px 24px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.how-step {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.how-step-header {
  display: flex;
  align-items: center;
  gap: 10px;
}

.how-step-num {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--brand);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  flex-shrink: 0;
}

.how-step strong {
  font-size: .88rem;
  font-weight: 700;
  color: var(--brand-dark);
}

.how-step > p {
  font-size: .84rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-left: 32px;
}

.how-table-wrap {
  margin-left: 32px;
  overflow-x: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.how-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .81rem;
}

.how-table th {
  padding: 8px 12px;
  text-align: left;
  font-size: .70rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  background: var(--bg);
  border-bottom: 1.5px solid var(--border);
  white-space: nowrap;
}

.how-table td {
  padding: 9px 12px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

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

.how-table tr.row-highlight td {
  background: rgba(79,70,229,.05);
  color: var(--brand-dark);
  font-weight: 600;
}

.how-table tr.row-highlight td:first-child {
  border-left: 3px solid var(--brand);
}

.how-note {
  margin-left: 32px;
  font-size: .82rem;
  color: var(--text-muted);
  background: linear-gradient(135deg, rgba(79,70,229,.05) 0%, rgba(124,58,237,.05) 100%);
  border-left: 3px solid var(--brand-light);
  border-radius: 0 6px 6px 0;
  padding: 10px 14px;
  line-height: 1.55;
}

/* ── International Dollar card overrides ────────────── */
.intl-intro {
  font-size: .88rem;
  color: var(--text-muted);
  line-height: 1.6;
}

.intl-card .how-step > p,
.intl-card .how-table-wrap,
.intl-card .how-note {
  margin-left: 0;
}

/* ── Footer ──────────────────────────────────────────── */
footer {
  margin-top: 32px;
  font-size: .78rem;
  color: var(--text-muted);
  text-align: center;
  line-height: 1.6;
  max-width: 560px;
}

footer a {
  color: var(--brand);
  text-decoration: none;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 520px) {
  .card {
    padding: 28px 20px;
  }

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

  .field.full {
    grid-column: 1;
  }

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

  .stats-grid .stat-box:last-child {
    grid-column: 1 / -1;
  }
}
