:root {
  --bg: #f2f2f7;
  --bg-card: #ffffff;
  --text: #1c1c1e;
  --text-secondary: #8e8e93;
  --separator: #c6c6c8;
  --accent: #007aff;
  /* iOS app emerald: Color(red: 0.020, green: 0.588, blue: 0.412) */
  --emerald: #059669;
  --emerald-bg: rgba(5, 150, 105, 0.12);
  /* iOS app cardBlue: Color(red: 0.235, green: 0.392, blue: 0.855) */
  --card-blue: #3c64da;
  --card-blue-bg: rgba(60, 100, 218, 0.12);
  --red: #ff3b30;
  --red-text: #ff3b30;
  --gradient-a: rgba(5, 150, 105, 0.15);
  --gradient-b: rgba(60, 100, 218, 0.15);
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-card: #1c1c1e;
    --text: #f2f2f7;
    --text-secondary: #8e8e93;
    --separator: #38383a;
    --emerald: #34d399;
    --emerald-bg: rgba(5, 150, 105, 0.15);
    --card-blue: #6b8cef;
    --card-blue-bg: rgba(60, 100, 218, 0.15);
    --red-text: #ff453a;
    --gradient-a: rgba(52, 211, 153, 0.2);
    --gradient-b: rgba(107, 140, 239, 0.2);
  }
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 80% 50% at 0% 0%, var(--gradient-b) 0%, transparent 100%),
    radial-gradient(ellipse 80% 50% at 100% 100%, var(--gradient-a) 0%, transparent 100%);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

header {
  background: transparent;
  border-bottom: 0.5px solid var(--separator);
  padding: 8px 0 4px;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
}

.header-content {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

#settings-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  display: flex;
  align-items: center;
}

main {
  max-width: 480px;
  margin: 0 auto;
  padding: 8px 16px 32px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* iOS-style grouped form */
.calculator {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 0;
  display: flex;
  flex-direction: column;
}

.section-title {
  font-size: 0.8125rem;
  font-weight: 400;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.02em;
  padding: 16px 16px 6px;
}

.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 16px;
  border-bottom: 0.5px solid var(--separator);
  min-height: 44px;
}

.form-row:last-of-type {
  border-bottom: none;
}

.form-row label {
  font-size: 1rem;
  color: var(--text);
  flex-shrink: 0;
}

.row-input {
  display: flex;
  align-items: center;
  gap: 4px;
}

.row-input input {
  background: none;
  border: none;
  outline: none;
  font-size: 1rem;
  color: var(--text);
  text-align: right;
  width: 100px;
  padding: 0;
  font-family: inherit;
}

.row-input input::placeholder {
  color: var(--text-secondary);
  opacity: 0.6;
}

.row-input .suffix {
  font-size: 1rem;
  color: var(--text-secondary);
  white-space: nowrap;
}

.separator {
  height: 0;
  margin: 8px 0;
}

/* Calcular button — matches iOS .listRowBackground(Color.accentColor) */
.btn-calcular {
  display: block;
  width: 100%;
  margin: 0;
  padding: 11px 16px;
  background: var(--accent);
  color: #ffffff;
  border: none;
  border-radius: 0 0 var(--radius) var(--radius);
  font-size: 1.0625rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
  transition: filter 0.1s;
}

.btn-calcular:active {
  filter: brightness(0.85);
}

/* Error message */
.error-msg {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--red-text);
  font-size: 0.9375rem;
}

.error-msg.hidden {
  display: none;
}

/* Result section */
.result {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
}

.result.hidden {
  display: none;
}

.verdict-banner {
  margin: 0;
  padding: 20px 16px;
  font-size: 1.25rem;
  font-weight: 700;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  letter-spacing: -0.01em;
}

.verdict-banner .verdict-emoji {
  font-size: 1.75rem;
}

.verdict-banner.parcele {
  background: linear-gradient(135deg, var(--card-blue-bg), transparent);
  color: var(--card-blue);
  border-bottom: 2px solid var(--card-blue);
}

.verdict-banner.pague-vista {
  background: linear-gradient(135deg, var(--emerald-bg), transparent);
  color: var(--emerald);
  border-bottom: 2px solid var(--emerald);
}

.result-grid {
  padding: 0;
  display: flex;
  flex-direction: column;
}

.result-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 11px 16px;
  border-bottom: 0.5px solid var(--separator);
}

.result-item:last-child {
  border-bottom: none;
}

.result-label {
  font-size: 1rem;
  color: var(--text);
}

.result-value {
  font-size: 1rem;
  font-weight: 600;
}

.result-value.positive {
  color: var(--emerald);
}

.result-value.negative {
  color: var(--red-text);
}

.result-value.secondary {
  color: var(--text-secondary);
}

/* Modal — iOS sheet style */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.overlay.hidden {
  display: none;
}

.modal {
  background: var(--bg-card);
  border-radius: 12px 12px 0 0;
  width: 100%;
  max-width: 480px;
  max-height: 90dvh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 0.5px solid var(--separator);
}

.modal-header h2 {
  font-size: 1.0625rem;
  font-weight: 600;
}

.modal-action {
  background: none;
  border: none;
  font-size: 1rem;
  color: var(--accent);
  cursor: pointer;
  padding: 4px 0;
  font-family: inherit;
  min-width: 70px;
}

.modal-action-primary {
  font-weight: 600;
  text-align: right;
}

.modal-action:first-child {
  text-align: left;
}

.modal-body {
  padding: 0 0 20px;
  display: flex;
  flex-direction: column;
}

.modal-body .section-title {
  padding: 16px 16px 6px;
}

.modal-body .form-row {
  padding: 11px 16px;
}

.ir-brackets {
  display: flex;
  flex-direction: column;
}

.btn-reset {
  display: block;
  width: calc(100% - 32px);
  margin: 20px 16px 0;
  padding: 12px;
  background: none;
  color: var(--red-text);
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  cursor: pointer;
  font-family: inherit;
  text-align: center;
}

.btn-reset:active {
  opacity: 0.6;
}

/* Remove number input spinners */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

input[type="number"] {
  -moz-appearance: textfield;
}

@media (min-width: 640px) {
  .modal {
    border-radius: 12px;
    margin-bottom: 10vh;
  }

  .overlay {
    align-items: center;
  }
}
