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

:root {
  --primary: #18181b;
  --primary-dark: #09090b;
  --primary-light: #f4f4f5;
  --secondary: #64748b;
  --success: #16a34a;
  --error-color: #dc2626;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --bg: #f8fafc;
  --card-bg: #ffffff;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 4px 16px rgba(0,0,0,0.06);
  --shadow-lg: 0 4px 6px rgba(0,0,0,0.07), 0 10px 40px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  padding: 2rem 1rem;
  line-height: 1.5;
}

.container {
  max-width: 560px;
  margin: 0 auto;
}

header {
  text-align: center;
  margin-bottom: 2rem;
  position: relative;
}

.back-home {
  position: absolute;
  left: 0;
  top: 50%;
  transform: translateY(-50%);
  display: block;
  opacity: 0.85;
  transition: opacity 0.2s;
}

.back-home:hover {
  opacity: 1;
}

.site-logo {
  height: 40px;
  width: auto;
  display: block;
  filter: invert(1);
}

header h1 {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}

header .subtitle {
  color: var(--text-muted);
  margin-top: 0.4rem;
  font-size: 1rem;
}

/* Progress bar */
.progress-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 2rem;
  gap: 0;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.step-circle {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background 0.3s, color 0.3s;
}

.step.active .step-circle {
  background: var(--primary);
  color: white;
}

.step.completed .step-circle {
  background: var(--primary);
  color: white;
}

.step span {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.step.active span {
  color: var(--primary);
  font-weight: 600;
}

.step-line {
  flex: 1;
  height: 2px;
  background: var(--border);
  margin: 0 8px;
  margin-bottom: 18px;
  min-width: 32px;
  transition: background 0.3s;
}

.step-line.completed {
  background: var(--primary);
}

/* Form */
#calculator-form {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 2rem;
  position: relative;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  background: var(--card-bg);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  z-index: 20;
}

.spinner {
  width: 48px;
  height: 48px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.75s linear infinite;
}

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

.loading-message {
  color: var(--text-muted);
  font-size: 0.95rem;
  font-weight: 500;
  text-align: center;
  min-height: 1.4rem;
}

.form-step {
  display: none;
}

.form-step.active {
  display: block;
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.form-step h2 {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
  color: var(--text);
}

.step-description {
  color: var(--text-muted);
  margin-top: -1rem;
  margin-bottom: 1.25rem;
  font-size: 0.9rem;
}

/* Fields */
.field-group {
  margin-bottom: 1.25rem;
}

.field-group label:first-child {
  display: block;
  font-weight: 600;
  font-size: 0.875rem;
  margin-bottom: 0.4rem;
  color: var(--text);
}

input[type="text"],
input[type="email"],
input[type="number"] {
  width: 100%;
  padding: 0.65rem 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s;
  background: white;
  appearance: none;
  -moz-appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  opacity: 1;
}

input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.1);
}

input.invalid {
  border-color: var(--error-color);
}

.error {
  display: block;
  color: var(--error-color);
  font-size: 0.8rem;
  margin-top: 0.3rem;
  min-height: 1rem;
}

/* Radio cards (sex) */
.radio-group {
  display: flex;
  gap: 0.75rem;
}

.radio-card {
  flex: 1;
  cursor: pointer;
}

.radio-card input[type="radio"] {
  display: none;
}

.radio-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.875rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.2s, background 0.2s;
  font-weight: 500;
}

.radio-icon {
  font-size: 1.5rem;
}

.radio-card input:checked + .radio-content {
  border-color: var(--primary);
  background: var(--primary-light);
  color: var(--primary);
}

/* Global unit system toggle */
.system-toggle-row {
  display: flex;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 10px;
  padding: 3px;
  gap: 3px;
  margin-bottom: 1.5rem;
}

.system-btn {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border: none;
  border-radius: 7px;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, color 0.2s, box-shadow 0.2s;
}

.system-btn.active {
  background: white;
  color: var(--primary);
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Dual input (ft/in) */
.dual-input {
  display: flex;
  gap: 0.75rem;
}

.dual-input > div {
  flex: 1;
  position: relative;
}

.dual-input input {
  padding-right: 2.5rem;
}

.input-with-unit {
  position: relative;
}

.input-with-unit input {
  padding-right: 3rem;
}

.unit-label {
  position: absolute;
  right: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  pointer-events: none;
}

.dual-input .unit-label {
  top: 50%;
  right: 0.75rem;
}

.hidden {
  display: none;
}

/* Activity cards */
.activity-cards {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  margin-bottom: 1rem;
}

.activity-card {
  cursor: pointer;
}

.activity-card input[type="radio"] {
  display: none;
}

.activity-content {
  padding: 0.875rem 1rem;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  transition: border-color 0.2s, background 0.2s;
}

.activity-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.2rem;
}

.activity-icon {
  font-size: 1.1rem;
}

.activity-content p {
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-left: 1.6rem;
}

.activity-card input:checked + .activity-content {
  border-color: var(--primary);
  background: var(--primary-light);
}

.activity-card input:checked + .activity-content p {
  color: var(--primary);
}

.activity-card.recommended .activity-content {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.08), 0 2px 8px rgba(0, 0, 0, 0.08);
}

.activity-tip {
  margin-left: auto;
  position: relative;
  font-size: 1rem;
  cursor: help;
  outline: none;
  flex-shrink: 0;
}

.tip-text {
  position: absolute;
  bottom: calc(100% + 8px);
  right: 0;
  background: var(--text);
  color: white;
  font-size: 0.72rem;
  font-weight: 400;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  width: 200px;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 10;
}

.tip-text::after {
  content: '';
  position: absolute;
  top: 100%;
  right: 8px;
  border: 5px solid transparent;
  border-top-color: var(--text);
}

.activity-tip:hover .tip-text,
.activity-tip:focus .tip-text {
  opacity: 1;
}

/* Buttons */
.button-row {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.75rem;
  justify-content: flex-end;
}

.btn {
  padding: 0.7rem 1.5rem;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--border);
  color: var(--text-muted);
}

.btn-secondary:hover {
  background: #cbd5e1;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  border: 1.5px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg);
}

.gain-card {
  border-color: #d1fae5;
  background: #f0fdf4;
}

.gain-card .result-value {
  color: var(--success);
}

/* Results */
.results-name {
  color: var(--text-muted);
  margin-top: -1rem;
  margin-bottom: 1.25rem;
}

.results-card {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
  margin-bottom: 0.75rem;
}

.results-card.main-result {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.result-label {
  font-size: 0.8rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.8;
  margin-bottom: 0.25rem;
}

.result-value {
  font-size: 3rem;
  font-weight: 800;
  line-height: 1;
  margin-bottom: 0.15rem;
}

.results-card:not(.main-result) .result-value {
  color: var(--text);
}

.result-unit {
  font-size: 0.85rem;
  font-weight: 500;
  opacity: 0.75;
}

.result-description {
  font-size: 0.8rem;
  margin-top: 0.5rem;
  opacity: 0.75;
}

.results-card:not(.main-result) .result-description {
  color: var(--text-muted);
}

.privacy-note {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin-top: 0.5rem;
}

/* Maintenance override */
.override-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  margin-bottom: 0.75rem;
}

.toggle-label {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text);
}

.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 24px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.toggle-switch input:checked + .toggle-slider {
  background: var(--primary);
}

.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

.override-input-row {
  background: var(--primary-light);
  border: 1.5px solid var(--border);
  border-radius: 8px;
  padding: 0.875rem 1rem;
  margin-bottom: 0.75rem;
}

.override-input-row label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  margin-bottom: 0.4rem;
  color: var(--text);
}

.override-hint {
  font-size: 0.75rem;
  color: var(--primary);
  margin-top: 0.4rem;
}

.loss-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}

.results-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.results-grid .result-value {
  font-size: 1.6rem;
}

.bmr-detail {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg);
  border-radius: 8px;
  padding: 0.75rem 1rem;
  margin-bottom: 0.5rem;
}

.formula-note {
  font-style: italic;
  font-size: 0.75rem;
}

.not-sure-row {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
  cursor: pointer;
}

.not-sure-row input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
  accent-color: var(--primary);
}

.not-sure-row span {
  font-size: 0.82rem;
  color: var(--primary);
  font-weight: 500;
}

.bf-pct {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 400;
}

.radio-card input:checked + .radio-content .bf-pct {
  color: var(--primary);
}

@media (max-width: 480px) {
  body {
    padding: 1rem 0.75rem;
  }

  #calculator-form {
    padding: 1.5rem 1rem;
  }

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

  .results-grid .result-value {
    font-size: 1.35rem;
  }

  .result-value {
    font-size: 2.5rem;
  }
}
